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