Mercurial > emacs
annotate lib-src/fakemail.c @ 69740:0c5f9763aa55
Bump version to 5.11.
author | Reiner Steib <Reiner.Steib@gmx.de> |
---|---|
date | Fri, 31 Mar 2006 17:12:53 +0000 |
parents | e112ec9aa49b |
children | 1e68e7f3b824 e6bf73e43cf4 |
rev | line source |
---|---|
18 | 1 /* sendmail-like interface to /bin/mail for system V, |
64769
6358e3c6075c
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64083
diff
changeset
|
2 Copyright (C) 1985, 1994, 1999, 2002, 2003, 2004, |
68647
3661e9b3c48f
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64769
diff
changeset
|
3 2005, 2006 Free Software Foundation, Inc. |
18 | 4 |
5 This file is part of GNU Emacs. | |
6 | |
37 | 7 GNU Emacs is free software; you can redistribute it and/or modify |
8 it under the terms of the GNU General Public License as published by | |
6109 | 9 the Free Software Foundation; either version 2, or (at your option) |
37 | 10 any later version. |
18 | 11 |
37 | 12 GNU Emacs is distributed in the hope that it will be useful, |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with GNU Emacs; see the file COPYING. If not, write to | |
64083 | 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 Boston, MA 02110-1301, USA. */ | |
18 | 21 |
22 #define NO_SHORTNAMES | |
42134
de525d9743c9
Include "config.h", not <../src/config.h>.
Dave Love <fx@gnu.org>
parents:
34951
diff
changeset
|
23 #define _XOPEN_SOURCE 500 /* for cuserid */ |
42181
358035cb58d9
Conditionally include config.h.
Pavel Janík <Pavel@Janik.cz>
parents:
42134
diff
changeset
|
24 |
358035cb58d9
Conditionally include config.h.
Pavel Janík <Pavel@Janik.cz>
parents:
42134
diff
changeset
|
25 #ifdef HAVE_CONFIG_H |
42469 | 26 #include <config.h> |
42181
358035cb58d9
Conditionally include config.h.
Pavel Janík <Pavel@Janik.cz>
parents:
42134
diff
changeset
|
27 #endif |
18 | 28 |
16218
32f82ca8b41f
Replaced all BSD with BSD_SYSTEM.
Karl Heuer <kwzh@gnu.org>
parents:
16121
diff
changeset
|
29 #if defined (BSD_SYSTEM) && !defined (BSD4_1) && !defined (USE_FAKEMAIL) |
18 | 30 /* This program isnot used in BSD, so just avoid loader complaints. */ |
15683 | 31 int |
18 | 32 main () |
33 { | |
16121 | 34 return 0; |
18 | 35 } |
36 #else /* not BSD 4.2 (or newer) */ | |
5447
6f0905b05218
(main) [MSDOS]: Dummy stub just to make the file compile.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
37 #ifdef MSDOS |
15683 | 38 int |
5447
6f0905b05218
(main) [MSDOS]: Dummy stub just to make the file compile.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
39 main () |
6f0905b05218
(main) [MSDOS]: Dummy stub just to make the file compile.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
40 { |
16121 | 41 return 0; |
5447
6f0905b05218
(main) [MSDOS]: Dummy stub just to make the file compile.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
42 } |
6f0905b05218
(main) [MSDOS]: Dummy stub just to make the file compile.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
43 #else /* not MSDOS */ |
18 | 44 /* This conditional contains all the rest of the file. */ |
45 | |
46 /* These are defined in config in some versions. */ | |
47 | |
48 #ifdef static | |
49 #undef static | |
50 #endif | |
51 | |
15099
857388330750
[WINDOWSNT]: Include ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
52 #ifdef WINDOWSNT |
857388330750
[WINDOWSNT]: Include ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
53 #include "ntlib.h" |
857388330750
[WINDOWSNT]: Include ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
54 #endif |
857388330750
[WINDOWSNT]: Include ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
55 |
69697
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
56 #include <limits.h> |
18 | 57 #include <stdio.h> |
58 #include <string.h> | |
59 #include <ctype.h> | |
60 #include <time.h> | |
61 #include <pwd.h> | |
18841
36704f455f32
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
62 |
36704f455f32
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
63 /* This is to declare cuserid. */ |
36704f455f32
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
64 #ifdef HAVE_UNISTD_H |
36704f455f32
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
65 #include <unistd.h> |
36704f455f32
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
66 #endif |
18 | 67 |
68 /* Type definitions */ | |
69 | |
70 #define boolean int | |
71 #define true 1 | |
72 #define false 0 | |
73 | |
69697
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
74 /* True if TM_YEAR is a struct tm's tm_year value that is acceptable |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
75 to asctime. Glibc asctime returns a useful string unless TM_YEAR |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
76 is nearly INT_MAX, but the C Standard lets C libraries overrun a |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
77 buffer if TM_YEAR needs more than 4 bytes. */ |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
78 #ifdef __GLIBC__ |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
79 # define TM_YEAR_IN_ASCTIME_RANGE(tm_year) ((tm_year) <= INT_MAX - 1900) |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
80 #else |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
81 # define TM_YEAR_IN_ASCTIME_RANGE(tm_year) \ |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
82 (-999 - 1900 <= (tm_year) && (tm_year) <= 9999 - 1900) |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
83 #endif |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
84 |
18 | 85 /* Various lists */ |
86 | |
87 struct line_record | |
88 { | |
89 char *string; | |
90 struct line_record *continuation; | |
91 }; | |
92 typedef struct line_record *line_list; | |
93 | |
94 struct header_record | |
95 { | |
96 line_list text; | |
97 struct header_record *next; | |
98 struct header_record *previous; | |
99 }; | |
100 typedef struct header_record *header; | |
42181
358035cb58d9
Conditionally include config.h.
Pavel Janík <Pavel@Janik.cz>
parents:
42134
diff
changeset
|
101 |
18 | 102 struct stream_record |
103 { | |
104 FILE *handle; | |
105 int (*action)(); | |
106 struct stream_record *rest_streams; | |
107 }; | |
108 typedef struct stream_record *stream_list; | |
109 | |
110 /* A `struct linebuffer' is a structure which holds a line of text. | |
111 * `readline' reads a line from a stream into a linebuffer | |
112 * and works regardless of the length of the line. | |
113 */ | |
114 | |
115 struct linebuffer | |
116 { | |
117 long size; | |
118 char *buffer; | |
119 }; | |
120 | |
121 struct linebuffer lb; | |
122 | |
123 #define new_list() \ | |
124 ((line_list) xmalloc (sizeof (struct line_record))) | |
125 #define new_header() \ | |
126 ((header) xmalloc (sizeof (struct header_record))) | |
127 #define new_stream() \ | |
128 ((stream_list) xmalloc (sizeof (struct stream_record))) | |
129 #define alloc_string(nchars) \ | |
130 ((char *) xmalloc ((nchars) + 1)) | |
131 | |
132 /* Global declarations */ | |
133 | |
134 #define BUFLEN 1024 | |
135 #define KEYWORD_SIZE 256 | |
136 #define FROM_PREFIX "From" | |
137 #define MY_NAME "fakemail" | |
138 #define NIL ((line_list) NULL) | |
139 #define INITIAL_LINE_SIZE 200 | |
140 | |
141 #ifndef MAIL_PROGRAM_NAME | |
142 #define MAIL_PROGRAM_NAME "/bin/mail" | |
143 #endif | |
144 | |
145 static char *my_name; | |
146 static char *the_date; | |
147 static char *the_user; | |
148 static line_list file_preface; | |
149 static stream_list the_streams; | |
150 static boolean no_problems = true; | |
151 | |
152 extern FILE *popen (); | |
153 extern int fclose (), pclose (); | |
154 | |
155 #ifdef CURRENT_USER | |
156 extern struct passwd *getpwuid (); | |
157 extern unsigned short geteuid (); | |
158 static struct passwd *my_entry; | |
159 #define cuserid(s) \ | |
160 (my_entry = getpwuid (((int) geteuid ())), \ | |
161 my_entry->pw_name) | |
162 #endif | |
163 | |
164 /* Utilities */ | |
165 | |
166 /* Print error message. `s1' is printf control string, `s2' is arg for it. */ | |
167 | |
168 static void | |
169 error (s1, s2) | |
170 char *s1, *s2; | |
171 { | |
172 printf ("%s: ", my_name); | |
173 printf (s1, s2); | |
174 printf ("\n"); | |
175 no_problems = false; | |
176 } | |
177 | |
178 /* Print error message and exit. */ | |
179 | |
180 static void | |
181 fatal (s1, s2) | |
182 char *s1, *s2; | |
183 { | |
184 error (s1, s2); | |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
185 exit (EXIT_FAILURE); |
18 | 186 } |
187 | |
188 /* Like malloc but get fatal error if memory is exhausted. */ | |
189 | |
12833
25464bf61eb1
(xmalloc, xrealloc): Use return-type long *.
Richard M. Stallman <rms@gnu.org>
parents:
10265
diff
changeset
|
190 static long * |
18 | 191 xmalloc (size) |
192 int size; | |
193 { | |
12833
25464bf61eb1
(xmalloc, xrealloc): Use return-type long *.
Richard M. Stallman <rms@gnu.org>
parents:
10265
diff
changeset
|
194 long *result = (long *) malloc (((unsigned) size)); |
25464bf61eb1
(xmalloc, xrealloc): Use return-type long *.
Richard M. Stallman <rms@gnu.org>
parents:
10265
diff
changeset
|
195 if (result == ((long *) NULL)) |
18 | 196 fatal ("virtual memory exhausted", 0); |
197 return result; | |
198 } | |
199 | |
12833
25464bf61eb1
(xmalloc, xrealloc): Use return-type long *.
Richard M. Stallman <rms@gnu.org>
parents:
10265
diff
changeset
|
200 static long * |
18 | 201 xrealloc (ptr, size) |
12833
25464bf61eb1
(xmalloc, xrealloc): Use return-type long *.
Richard M. Stallman <rms@gnu.org>
parents:
10265
diff
changeset
|
202 long *ptr; |
18 | 203 int size; |
204 { | |
12833
25464bf61eb1
(xmalloc, xrealloc): Use return-type long *.
Richard M. Stallman <rms@gnu.org>
parents:
10265
diff
changeset
|
205 long *result = (long *) realloc (ptr, ((unsigned) size)); |
12840
4e9a14304b8b
(xrealloc): Change cast to match return type.
Karl Heuer <kwzh@gnu.org>
parents:
12833
diff
changeset
|
206 if (result == ((long *) NULL)) |
18 | 207 fatal ("virtual memory exhausted"); |
208 return result; | |
209 } | |
210 | |
211 /* Initialize a linebuffer for use */ | |
212 | |
213 void | |
214 init_linebuffer (linebuffer) | |
215 struct linebuffer *linebuffer; | |
216 { | |
217 linebuffer->size = INITIAL_LINE_SIZE; | |
218 linebuffer->buffer = ((char *) xmalloc (INITIAL_LINE_SIZE)); | |
219 } | |
220 | |
221 /* Read a line of text from `stream' into `linebuffer'. | |
42181
358035cb58d9
Conditionally include config.h.
Pavel Janík <Pavel@Janik.cz>
parents:
42134
diff
changeset
|
222 Return the length of the line. */ |
18 | 223 |
224 long | |
225 readline (linebuffer, stream) | |
226 struct linebuffer *linebuffer; | |
227 FILE *stream; | |
228 { | |
229 char *buffer = linebuffer->buffer; | |
230 char *p = linebuffer->buffer; | |
231 char *end = p + linebuffer->size; | |
232 | |
233 while (true) | |
234 { | |
235 int c = getc (stream); | |
236 if (p == end) | |
237 { | |
238 linebuffer->size *= 2; | |
34951
1efc40541908
(readline): Cast buffer to "long *" to pacify
Eli Zaretskii <eliz@gnu.org>
parents:
34609
diff
changeset
|
239 buffer = ((char *) xrealloc ((long *)buffer, linebuffer->size)); |
6992
ed57331fb222
(readline): Fix updating of p when buffer grows.
Richard M. Stallman <rms@gnu.org>
parents:
6954
diff
changeset
|
240 p = buffer + (p - linebuffer->buffer); |
6954
774fdc20d115
(readline): When extending the buffer,
Richard M. Stallman <rms@gnu.org>
parents:
6109
diff
changeset
|
241 end = buffer + linebuffer->size; |
18 | 242 linebuffer->buffer = buffer; |
243 } | |
244 if (c < 0 || c == '\n') | |
245 { | |
246 *p = 0; | |
247 break; | |
248 } | |
249 *p++ = c; | |
250 } | |
251 | |
252 return p - buffer; | |
253 } | |
254 | |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
255 /* Extract a colon-terminated keyword from the string FIELD. |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
256 Return that keyword as a string stored in a static buffer. |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
257 Store the address of the rest of the string into *REST. |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
258 |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
259 If there is no keyword, return NULL and don't alter *REST. */ |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
260 |
18 | 261 char * |
262 get_keyword (field, rest) | |
263 register char *field; | |
264 char **rest; | |
265 { | |
266 static char keyword[KEYWORD_SIZE]; | |
267 register char *ptr; | |
34609
cb2667416fa5
(get_keyword): Make sure that isspace and
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
268 register int c; |
18 | 269 |
270 ptr = &keyword[0]; | |
34609
cb2667416fa5
(get_keyword): Make sure that isspace and
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
271 c = (unsigned char) *field++; |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
272 if (isspace (c) || c == ':') |
18 | 273 return ((char *) NULL); |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
274 *ptr++ = (islower (c) ? toupper (c) : c); |
34609
cb2667416fa5
(get_keyword): Make sure that isspace and
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
275 while (((c = (unsigned char) *field++) != ':') && ! isspace (c)) |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
276 *ptr++ = (islower (c) ? toupper (c) : c); |
18 | 277 *ptr++ = '\0'; |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
278 while (isspace (c)) |
34609
cb2667416fa5
(get_keyword): Make sure that isspace and
Gerd Moellmann <gerd@gnu.org>
parents:
26083
diff
changeset
|
279 c = (unsigned char) *field++; |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
280 if (c != ':') |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
281 return ((char *) NULL); |
18 | 282 *rest = field; |
283 return &keyword[0]; | |
284 } | |
285 | |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
286 /* Nonzero if the string FIELD starts with a colon-terminated keyword. */ |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
287 |
18 | 288 boolean |
289 has_keyword (field) | |
290 char *field; | |
291 { | |
292 char *ignored; | |
293 return (get_keyword (field, &ignored) != ((char *) NULL)); | |
294 } | |
295 | |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
296 /* Store the string FIELD, followed by any lines in THE_LIST, |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
297 into the buffer WHERE. |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
298 Concatenate lines, putting just a space between them. |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
299 Delete everything contained in parentheses. |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
300 When a recipient name contains <...>, we discard |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
301 everything except what is inside the <...>. |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
302 |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
303 We don't pay attention to overflowing WHERE; |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
304 the caller has to make it big enough. */ |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
305 |
18 | 306 char * |
307 add_field (the_list, field, where) | |
308 line_list the_list; | |
309 register char *field, *where; | |
310 { | |
311 register char c; | |
312 while (true) | |
313 { | |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
314 char *this_recipient_where; |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
315 int in_quotes = 0; |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
316 |
18 | 317 *where++ = ' '; |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
318 this_recipient_where = where; |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
319 |
18 | 320 while ((c = *field++) != '\0') |
321 { | |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
322 if (c == '\\') |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
323 *where++ = c; |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
324 else if (c == '"') |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
325 { |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
326 in_quotes = ! in_quotes; |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
327 *where++ = c; |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
328 } |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
329 else if (in_quotes) |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
330 *where++ = c; |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
331 else if (c == '(') |
18 | 332 { |
333 while (*field && *field != ')') ++field; | |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
334 if (! (*field++)) break; /* no close */ |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
335 continue; |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
336 } |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
337 else if (c == ',') |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
338 { |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
339 *where++ = ' '; |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
340 /* When we get to the end of one recipient, |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
341 don't discard it if the next one has <...>. */ |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
342 this_recipient_where = where; |
18 | 343 } |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
344 else if (c == '<') |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
345 /* Discard everything we got before the `<'. */ |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
346 where = this_recipient_where; |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
347 else if (c == '>') |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
348 /* Discard the rest of this name that follows the `>'. */ |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
349 { |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
350 while (*field && *field != ',') ++field; |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
351 if (! (*field++)) break; /* no comma */ |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
352 continue; |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
353 } |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
354 else |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
355 *where++ = c; |
18 | 356 } |
357 if (the_list == NIL) break; | |
358 field = the_list->string; | |
359 the_list = the_list->continuation; | |
360 } | |
361 return where; | |
362 } | |
363 | |
364 line_list | |
365 make_file_preface () | |
366 { | |
367 char *the_string, *temp; | |
368 long idiotic_interface; | |
69697
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
369 struct tm *tm; |
18 | 370 long prefix_length; |
371 long user_length; | |
372 long date_length; | |
373 line_list result; | |
374 | |
375 prefix_length = strlen (FROM_PREFIX); | |
376 time (&idiotic_interface); | |
69697
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
377 /* Convert to a string, checking for out-of-range time stamps. |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
378 Don't use 'ctime', as that might dump core if the hardware clock |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
379 is set to a bizarre value. */ |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
380 tm = localtime (&idiotic_interface); |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
381 if (! (tm && TM_YEAR_IN_ASCTIME_RANGE (tm->tm_year))) |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
382 fatal ("current time is out of range", 0); |
e112ec9aa49b
* b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents:
68647
diff
changeset
|
383 the_date = asctime (tm); |
18 | 384 /* the_date has an unwanted newline at the end */ |
385 date_length = strlen (the_date) - 1; | |
386 the_date[date_length] = '\0'; | |
387 temp = cuserid ((char *) NULL); | |
388 user_length = strlen (temp); | |
389 the_user = alloc_string (user_length + 1); | |
390 strcpy (the_user, temp); | |
18841
36704f455f32
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
391 the_string = alloc_string (3 + prefix_length |
36704f455f32
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
392 + user_length |
36704f455f32
[HAVE_UNISTD_H]: Include unistd.h.
Richard M. Stallman <rms@gnu.org>
parents:
16218
diff
changeset
|
393 + date_length); |
18 | 394 temp = the_string; |
395 strcpy (temp, FROM_PREFIX); | |
396 temp = &temp[prefix_length]; | |
397 *temp++ = ' '; | |
398 strcpy (temp, the_user); | |
399 temp = &temp[user_length]; | |
400 *temp++ = ' '; | |
401 strcpy (temp, the_date); | |
402 result = new_list (); | |
403 result->string = the_string; | |
404 result->continuation = ((line_list) NULL); | |
405 return result; | |
406 } | |
407 | |
408 void | |
409 write_line_list (the_list, the_stream) | |
410 register line_list the_list; | |
411 FILE *the_stream; | |
412 { | |
413 for ( ; | |
414 the_list != ((line_list) NULL) ; | |
415 the_list = the_list->continuation) | |
416 { | |
417 fputs (the_list->string, the_stream); | |
418 putc ('\n', the_stream); | |
419 } | |
420 return; | |
421 } | |
422 | |
423 int | |
424 close_the_streams () | |
425 { | |
426 register stream_list rem; | |
427 for (rem = the_streams; | |
428 rem != ((stream_list) NULL); | |
429 rem = rem->rest_streams) | |
430 no_problems = (no_problems && | |
431 ((*rem->action) (rem->handle) == 0)); | |
432 the_streams = ((stream_list) NULL); | |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
433 return (no_problems ? EXIT_SUCCESS : EXIT_FAILURE); |
18 | 434 } |
435 | |
436 void | |
437 add_a_stream (the_stream, closing_action) | |
438 FILE *the_stream; | |
439 int (*closing_action)(); | |
440 { | |
441 stream_list old = the_streams; | |
442 the_streams = new_stream (); | |
443 the_streams->handle = the_stream; | |
444 the_streams->action = closing_action; | |
445 the_streams->rest_streams = old; | |
446 return; | |
447 } | |
448 | |
449 int | |
450 my_fclose (the_file) | |
451 FILE *the_file; | |
452 { | |
453 putc ('\n', the_file); | |
454 fflush (the_file); | |
455 return fclose (the_file); | |
456 } | |
457 | |
458 boolean | |
459 open_a_file (name) | |
460 char *name; | |
461 { | |
462 FILE *the_stream = fopen (name, "a"); | |
463 if (the_stream != ((FILE *) NULL)) | |
464 { | |
465 add_a_stream (the_stream, my_fclose); | |
466 if (the_user == ((char *) NULL)) | |
467 file_preface = make_file_preface (); | |
468 write_line_list (file_preface, the_stream); | |
469 return true; | |
470 } | |
471 return false; | |
472 } | |
473 | |
474 void | |
475 put_string (s) | |
476 char *s; | |
477 { | |
478 register stream_list rem; | |
479 for (rem = the_streams; | |
480 rem != ((stream_list) NULL); | |
481 rem = rem->rest_streams) | |
482 fputs (s, rem->handle); | |
483 return; | |
484 } | |
485 | |
486 void | |
20 | 487 put_line (string) |
488 char *string; | |
18 | 489 { |
490 register stream_list rem; | |
491 for (rem = the_streams; | |
492 rem != ((stream_list) NULL); | |
493 rem = rem->rest_streams) | |
494 { | |
20 | 495 char *s = string; |
496 int column = 0; | |
497 | |
498 /* Divide STRING into lines. */ | |
499 while (*s != 0) | |
500 { | |
501 char *breakpos; | |
502 | |
5959
e4337a7bbe32
(put_line): Don't break the line if it all fits.
Richard M. Stallman <rms@gnu.org>
parents:
5447
diff
changeset
|
503 /* Find the last char that fits. */ |
20 | 504 for (breakpos = s; *breakpos && column < 78; ++breakpos) |
505 { | |
506 if (*breakpos == '\t') | |
507 column += 8; | |
508 else | |
509 column++; | |
510 } | |
5959
e4337a7bbe32
(put_line): Don't break the line if it all fits.
Richard M. Stallman <rms@gnu.org>
parents:
5447
diff
changeset
|
511 /* If we didn't reach end of line, break the line. */ |
e4337a7bbe32
(put_line): Don't break the line if it all fits.
Richard M. Stallman <rms@gnu.org>
parents:
5447
diff
changeset
|
512 if (*breakpos) |
20 | 513 { |
5959
e4337a7bbe32
(put_line): Don't break the line if it all fits.
Richard M. Stallman <rms@gnu.org>
parents:
5447
diff
changeset
|
514 /* Back up to just after the last comma that fits. */ |
e4337a7bbe32
(put_line): Don't break the line if it all fits.
Richard M. Stallman <rms@gnu.org>
parents:
5447
diff
changeset
|
515 while (breakpos != s && breakpos[-1] != ',') --breakpos; |
e4337a7bbe32
(put_line): Don't break the line if it all fits.
Richard M. Stallman <rms@gnu.org>
parents:
5447
diff
changeset
|
516 |
e4337a7bbe32
(put_line): Don't break the line if it all fits.
Richard M. Stallman <rms@gnu.org>
parents:
5447
diff
changeset
|
517 if (breakpos == s) |
e4337a7bbe32
(put_line): Don't break the line if it all fits.
Richard M. Stallman <rms@gnu.org>
parents:
5447
diff
changeset
|
518 { |
e4337a7bbe32
(put_line): Don't break the line if it all fits.
Richard M. Stallman <rms@gnu.org>
parents:
5447
diff
changeset
|
519 /* If no comma fits, move past the first address anyway. */ |
e4337a7bbe32
(put_line): Don't break the line if it all fits.
Richard M. Stallman <rms@gnu.org>
parents:
5447
diff
changeset
|
520 while (*breakpos != 0 && *breakpos != ',') ++breakpos; |
e4337a7bbe32
(put_line): Don't break the line if it all fits.
Richard M. Stallman <rms@gnu.org>
parents:
5447
diff
changeset
|
521 if (*breakpos != 0) |
e4337a7bbe32
(put_line): Don't break the line if it all fits.
Richard M. Stallman <rms@gnu.org>
parents:
5447
diff
changeset
|
522 /* Include the comma after it. */ |
e4337a7bbe32
(put_line): Don't break the line if it all fits.
Richard M. Stallman <rms@gnu.org>
parents:
5447
diff
changeset
|
523 ++breakpos; |
e4337a7bbe32
(put_line): Don't break the line if it all fits.
Richard M. Stallman <rms@gnu.org>
parents:
5447
diff
changeset
|
524 } |
20 | 525 } |
526 /* Output that much, then break the line. */ | |
527 fwrite (s, 1, breakpos - s, rem->handle); | |
528 column = 8; | |
529 | |
530 /* Skip whitespace and prepare to print more addresses. */ | |
531 s = breakpos; | |
532 while (*s == ' ' || *s == '\t') ++s; | |
3219
1aa8fa0a569e
(put_line): Don't output \n\t unless more text follows.
Richard M. Stallman <rms@gnu.org>
parents:
37
diff
changeset
|
533 if (*s != 0) |
1aa8fa0a569e
(put_line): Don't output \n\t unless more text follows.
Richard M. Stallman <rms@gnu.org>
parents:
37
diff
changeset
|
534 fputs ("\n\t", rem->handle); |
20 | 535 } |
18 | 536 putc ('\n', rem->handle); |
537 } | |
538 return; | |
539 } | |
540 | |
541 #define mail_error error | |
542 | |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
543 /* Handle an FCC field. FIELD is the text of the first line (after |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
544 the header name), and THE_LIST holds the continuation lines if any. |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
545 Call open_a_file for each file. */ |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
546 |
18 | 547 void |
548 setup_files (the_list, field) | |
549 register line_list the_list; | |
550 register char *field; | |
551 { | |
552 register char *start; | |
553 register char c; | |
554 while (true) | |
555 { | |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
556 while (((c = *field) != '\0') |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
557 && (c == ' ' |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
558 || c == '\t' |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
559 || c == ',')) |
18 | 560 field += 1; |
561 if (c != '\0') | |
562 { | |
563 start = field; | |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
564 while (((c = *field) != '\0') |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
565 && c != ' ' |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
566 && c != '\t' |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
567 && c != ',') |
18 | 568 field += 1; |
569 *field = '\0'; | |
570 if (!open_a_file (start)) | |
571 mail_error ("Could not open file %s", start); | |
572 *field = c; | |
573 if (c != '\0') continue; | |
574 } | |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
575 if (the_list == ((line_list) NULL)) |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
576 return; |
18 | 577 field = the_list->string; |
578 the_list = the_list->continuation; | |
579 } | |
580 } | |
581 | |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
582 /* Compute the total size of all recipient names stored in THE_HEADER. |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
583 The result says how big to make the buffer to pass to parse_header. */ |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
584 |
18 | 585 int |
586 args_size (the_header) | |
587 header the_header; | |
588 { | |
589 register header old = the_header; | |
590 register line_list rem; | |
591 register int size = 0; | |
592 do | |
593 { | |
594 char *field; | |
595 register char *keyword = get_keyword (the_header->text->string, &field); | |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
596 if ((strcmp (keyword, "TO") == 0) |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
597 || (strcmp (keyword, "CC") == 0) |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
598 || (strcmp (keyword, "BCC") == 0)) |
18 | 599 { |
600 size += 1 + strlen (field); | |
601 for (rem = the_header->text->continuation; | |
602 rem != NIL; | |
603 rem = rem->continuation) | |
604 size += 1 + strlen (rem->string); | |
605 } | |
606 the_header = the_header->next; | |
607 } while (the_header != old); | |
608 return size; | |
609 } | |
610 | |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
611 /* Scan the header described by the lists THE_HEADER, |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
612 and put all recipient names into the buffer WHERE. |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
613 Precede each recipient name with a space. |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
614 |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
615 Also, if the header has any FCC fields, call setup_files for each one. */ |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
616 |
21389
48690fd8d40a
(_XOPEN_SOURCE): Define for declaration of cuserid.
Andreas Schwab <schwab@suse.de>
parents:
18841
diff
changeset
|
617 void |
18 | 618 parse_header (the_header, where) |
619 header the_header; | |
620 register char *where; | |
621 { | |
622 register header old = the_header; | |
623 do | |
624 { | |
625 char *field; | |
626 register char *keyword = get_keyword (the_header->text->string, &field); | |
627 if (strcmp (keyword, "TO") == 0) | |
628 where = add_field (the_header->text->continuation, field, where); | |
629 else if (strcmp (keyword, "CC") == 0) | |
630 where = add_field (the_header->text->continuation, field, where); | |
631 else if (strcmp (keyword, "BCC") == 0) | |
632 { | |
633 where = add_field (the_header->text->continuation, field, where); | |
634 the_header->previous->next = the_header->next; | |
635 the_header->next->previous = the_header->previous; | |
636 } | |
637 else if (strcmp (keyword, "FCC") == 0) | |
638 setup_files (the_header->text->continuation, field); | |
639 the_header = the_header->next; | |
640 } while (the_header != old); | |
641 *where = '\0'; | |
642 return; | |
643 } | |
42181
358035cb58d9
Conditionally include config.h.
Pavel Janík <Pavel@Janik.cz>
parents:
42134
diff
changeset
|
644 |
10265
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
645 /* Read lines from the input until we get a blank line. |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
646 Create a list of `header' objects, one for each header field, |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
647 each of which points to a list of `line_list' objects, |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
648 one for each line in that field. |
c53a70ec8d85
(xmalloc, xrealloc): Add casts.
Richard M. Stallman <rms@gnu.org>
parents:
9621
diff
changeset
|
649 Continuation lines are grouped in the headers they continue. */ |
42181
358035cb58d9
Conditionally include config.h.
Pavel Janík <Pavel@Janik.cz>
parents:
42134
diff
changeset
|
650 |
18 | 651 header |
652 read_header () | |
653 { | |
654 register header the_header = ((header) NULL); | |
655 register line_list *next_line = ((line_list *) NULL); | |
656 | |
657 init_linebuffer (&lb); | |
658 | |
659 do | |
660 { | |
661 long length; | |
662 register char *line; | |
663 | |
664 readline (&lb, stdin); | |
665 line = lb.buffer; | |
666 length = strlen (line); | |
667 if (length == 0) break; | |
668 | |
669 if (has_keyword (line)) | |
670 { | |
671 register header old = the_header; | |
672 the_header = new_header (); | |
673 if (old == ((header) NULL)) | |
674 { | |
675 the_header->next = the_header; | |
676 the_header->previous = the_header; | |
677 } | |
678 else | |
679 { | |
680 the_header->previous = old; | |
681 the_header->next = old->next; | |
682 old->next = the_header; | |
683 } | |
684 next_line = &(the_header->text); | |
685 } | |
686 | |
687 if (next_line == ((line_list *) NULL)) | |
688 { | |
689 /* Not a valid header */ | |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
690 exit (EXIT_FAILURE); |
18 | 691 } |
692 *next_line = new_list (); | |
693 (*next_line)->string = alloc_string (length); | |
694 strcpy (((*next_line)->string), line); | |
695 next_line = &((*next_line)->continuation); | |
696 *next_line = NIL; | |
697 | |
698 } while (true); | |
699 | |
700 return the_header->next; | |
701 } | |
702 | |
703 void | |
704 write_header (the_header) | |
705 header the_header; | |
706 { | |
707 register header old = the_header; | |
708 do | |
709 { | |
710 register line_list the_list; | |
711 for (the_list = the_header->text; | |
712 the_list != NIL; | |
713 the_list = the_list->continuation) | |
714 put_line (the_list->string); | |
715 the_header = the_header->next; | |
716 } while (the_header != old); | |
717 put_line (""); | |
718 return; | |
719 } | |
720 | |
15683 | 721 int |
18 | 722 main (argc, argv) |
723 int argc; | |
724 char **argv; | |
725 { | |
726 char *command_line; | |
727 header the_header; | |
728 long name_length; | |
729 char *mail_program_name; | |
730 char buf[BUFLEN + 1]; | |
731 register int size; | |
732 FILE *the_pipe; | |
733 | |
734 extern char *getenv (); | |
735 | |
736 mail_program_name = getenv ("FAKEMAILER"); | |
737 if (!(mail_program_name && *mail_program_name)) | |
738 mail_program_name = MAIL_PROGRAM_NAME; | |
739 name_length = strlen (mail_program_name); | |
740 | |
741 my_name = MY_NAME; | |
742 the_streams = ((stream_list) NULL); | |
743 the_date = ((char *) NULL); | |
744 the_user = ((char *) NULL); | |
745 | |
746 the_header = read_header (); | |
747 command_line = alloc_string (name_length + args_size (the_header)); | |
748 strcpy (command_line, mail_program_name); | |
749 parse_header (the_header, &command_line[name_length]); | |
42181
358035cb58d9
Conditionally include config.h.
Pavel Janík <Pavel@Janik.cz>
parents:
42134
diff
changeset
|
750 |
18 | 751 the_pipe = popen (command_line, "w"); |
752 if (the_pipe == ((FILE *) NULL)) | |
753 fatal ("cannot open pipe to real mailer"); | |
754 | |
755 add_a_stream (the_pipe, pclose); | |
756 | |
757 write_header (the_header); | |
758 | |
759 /* Dump the message itself */ | |
760 | |
761 while (!feof (stdin)) | |
762 { | |
763 size = fread (buf, 1, BUFLEN, stdin); | |
764 buf[size] = '\0'; | |
765 put_string (buf); | |
766 } | |
767 | |
768 exit (close_the_streams ()); | |
769 } | |
770 | |
5447
6f0905b05218
(main) [MSDOS]: Dummy stub just to make the file compile.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
771 #endif /* not MSDOS */ |
18 | 772 #endif /* not BSD 4.2 (or newer) */ |
52401 | 773 |
774 /* arch-tag: acb0afa6-315a-4c5b-b9e3-def5725c8783 | |
775 (do not change this comment) */ | |
55442
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
776 |
a47704955f8d
Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
777 /* fakemail.c ends here */ |