X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/380874900ca183ec2fdce91949d841328852d7a8..ebd3d6afa42948e3fb136583f12f9f72e7830ec5:/lib-src/fakemail.c diff --git a/lib-src/fakemail.c b/lib-src/fakemail.c index c8bfcfc093..f4d978b7d1 100644 --- a/lib-src/fakemail.c +++ b/lib-src/fakemail.c @@ -1,13 +1,16 @@ /* sendmail-like interface to /bin/mail for system V, - Copyright (C) 1985, 1994, 1999, 2002, 2003, 2004, - 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 1985, 1994, 1999, 2001, 2002, 2003, 2004, + 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. + +Author: Bill Rozas +(according to ack.texi) This file is part of GNU Emacs. -GNU Emacs is free software; you can redistribute it and/or modify +GNU Emacs is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -15,18 +18,16 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -Boston, MA 02110-1301, USA. */ +along with GNU Emacs. If not, see . */ + -#define NO_SHORTNAMES #define _XOPEN_SOURCE 500 /* for cuserid */ #ifdef HAVE_CONFIG_H #include #endif -#if defined (BSD_SYSTEM) && !defined (BSD4_1) && !defined (USE_FAKEMAIL) +#if defined (BSD_SYSTEM) && !defined (USE_FAKEMAIL) /* This program isnot used in BSD, so just avoid loader complaints. */ int main () @@ -70,6 +71,15 @@ main () #define true 1 #define false 0 +#define TM_YEAR_BASE 1900 + +/* Nonzero if TM_YEAR is a struct tm's tm_year value that causes + asctime to have well-defined behavior. */ +#ifndef TM_YEAR_IN_ASCTIME_RANGE +# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) \ + (1000 - TM_YEAR_BASE <= (tm_year) && (tm_year) <= 9999 - TM_YEAR_BASE) +#endif + /* Various lists */ struct line_record @@ -90,7 +100,7 @@ typedef struct header_record *header; struct stream_record { FILE *handle; - int (*action)(); + int (*action)(FILE *); struct stream_record *rest_streams; }; typedef struct stream_record *stream_list; @@ -137,8 +147,8 @@ static line_list file_preface; static stream_list the_streams; static boolean no_problems = true; -extern FILE *popen (); -extern int fclose (), pclose (); +extern FILE *popen (const char *, const char *); +extern int fclose (FILE *), pclose (FILE *); #ifdef CURRENT_USER extern struct passwd *getpwuid (); @@ -154,8 +164,7 @@ static struct passwd *my_entry; /* Print error message. `s1' is printf control string, `s2' is arg for it. */ static void -error (s1, s2) - char *s1, *s2; +error (char *s1, char *s2) { printf ("%s: ", my_name); printf (s1, s2); @@ -166,29 +175,25 @@ error (s1, s2) /* Print error message and exit. */ static void -fatal (s1, s2) - char *s1, *s2; +fatal (char *s1) { - error (s1, s2); + error ("%s", s1); exit (EXIT_FAILURE); } /* Like malloc but get fatal error if memory is exhausted. */ static long * -xmalloc (size) - int size; +xmalloc (int size) { long *result = (long *) malloc (((unsigned) size)); if (result == ((long *) NULL)) - fatal ("virtual memory exhausted", 0); + fatal ("virtual memory exhausted"); return result; } static long * -xrealloc (ptr, size) - long *ptr; - int size; +xrealloc (long int *ptr, int size) { long *result = (long *) realloc (ptr, ((unsigned) size)); if (result == ((long *) NULL)) @@ -199,8 +204,7 @@ xrealloc (ptr, size) /* Initialize a linebuffer for use */ void -init_linebuffer (linebuffer) - struct linebuffer *linebuffer; +init_linebuffer (struct linebuffer *linebuffer) { linebuffer->size = INITIAL_LINE_SIZE; linebuffer->buffer = ((char *) xmalloc (INITIAL_LINE_SIZE)); @@ -210,9 +214,7 @@ init_linebuffer (linebuffer) Return the length of the line. */ long -readline (linebuffer, stream) - struct linebuffer *linebuffer; - FILE *stream; +readline (struct linebuffer *linebuffer, FILE *stream) { char *buffer = linebuffer->buffer; char *p = linebuffer->buffer; @@ -247,9 +249,7 @@ readline (linebuffer, stream) If there is no keyword, return NULL and don't alter *REST. */ char * -get_keyword (field, rest) - register char *field; - char **rest; +get_keyword (register char *field, char **rest) { static char keyword[KEYWORD_SIZE]; register char *ptr; @@ -274,8 +274,7 @@ get_keyword (field, rest) /* Nonzero if the string FIELD starts with a colon-terminated keyword. */ boolean -has_keyword (field) - char *field; +has_keyword (char *field) { char *ignored; return (get_keyword (field, &ignored) != ((char *) NULL)); @@ -292,9 +291,7 @@ has_keyword (field) the caller has to make it big enough. */ char * -add_field (the_list, field, where) - line_list the_list; - register char *field, *where; +add_field (line_list the_list, register char *field, register char *where) { register char c; while (true) @@ -350,10 +347,11 @@ add_field (the_list, field, where) } line_list -make_file_preface () +make_file_preface (void) { char *the_string, *temp; long idiotic_interface; + struct tm *tm; long prefix_length; long user_length; long date_length; @@ -361,7 +359,13 @@ make_file_preface () prefix_length = strlen (FROM_PREFIX); time (&idiotic_interface); - the_date = ctime (&idiotic_interface); + /* Convert to a string, checking for out-of-range time stamps. + Don't use 'ctime', as that might dump core if the hardware clock + is set to a bizarre value. */ + tm = localtime (&idiotic_interface); + if (! (tm && TM_YEAR_IN_ASCTIME_RANGE (tm->tm_year) + && (the_date = asctime (tm)))) + fatal ("current time is out of range"); /* the_date has an unwanted newline at the end */ date_length = strlen (the_date) - 1; the_date[date_length] = '\0'; @@ -387,9 +391,7 @@ make_file_preface () } void -write_line_list (the_list, the_stream) - register line_list the_list; - FILE *the_stream; +write_line_list (register line_list the_list, FILE *the_stream) { for ( ; the_list != ((line_list) NULL) ; @@ -402,7 +404,7 @@ write_line_list (the_list, the_stream) } int -close_the_streams () +close_the_streams (void) { register stream_list rem; for (rem = the_streams; @@ -415,9 +417,7 @@ close_the_streams () } void -add_a_stream (the_stream, closing_action) - FILE *the_stream; - int (*closing_action)(); +add_a_stream (FILE *the_stream, int (*closing_action) (FILE *)) { stream_list old = the_streams; the_streams = new_stream (); @@ -428,8 +428,7 @@ add_a_stream (the_stream, closing_action) } int -my_fclose (the_file) - FILE *the_file; +my_fclose (FILE *the_file) { putc ('\n', the_file); fflush (the_file); @@ -437,8 +436,7 @@ my_fclose (the_file) } boolean -open_a_file (name) - char *name; +open_a_file (char *name) { FILE *the_stream = fopen (name, "a"); if (the_stream != ((FILE *) NULL)) @@ -453,8 +451,7 @@ open_a_file (name) } void -put_string (s) - char *s; +put_string (char *s) { register stream_list rem; for (rem = the_streams; @@ -465,8 +462,7 @@ put_string (s) } void -put_line (string) - char *string; +put_line (char *string) { register stream_list rem; for (rem = the_streams; @@ -526,9 +522,7 @@ put_line (string) Call open_a_file for each file. */ void -setup_files (the_list, field) - register line_list the_list; - register char *field; +setup_files (register line_list the_list, register char *field) { register char *start; register char c; @@ -564,8 +558,7 @@ setup_files (the_list, field) The result says how big to make the buffer to pass to parse_header. */ int -args_size (the_header) - header the_header; +args_size (header the_header) { register header old = the_header; register line_list rem; @@ -596,9 +589,7 @@ args_size (the_header) Also, if the header has any FCC fields, call setup_files for each one. */ void -parse_header (the_header, where) - header the_header; - register char *where; +parse_header (header the_header, register char *where) { register header old = the_header; do @@ -630,7 +621,7 @@ parse_header (the_header, where) Continuation lines are grouped in the headers they continue. */ header -read_header () +read_header (void) { register header the_header = ((header) NULL); register line_list *next_line = ((line_list *) NULL); @@ -678,12 +669,13 @@ read_header () } while (true); + if (! the_header) + fatal ("input message has no header"); return the_header->next; } void -write_header (the_header) - header the_header; +write_header (header the_header) { register header old = the_header; do @@ -700,9 +692,7 @@ write_header (the_header) } int -main (argc, argv) - int argc; - char **argv; +main (int argc, char **argv) { char *command_line; header the_header; @@ -712,7 +702,7 @@ main (argc, argv) register int size; FILE *the_pipe; - extern char *getenv (); + extern char *getenv (const char *); mail_program_name = getenv ("FAKEMAILER"); if (!(mail_program_name && *mail_program_name))