names.c (40171) | names.c (74769) |
---|---|
1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint | 1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint |
35#if 0 |
|
35static char sccsid[] = "@(#)names.c 8.1 (Berkeley) 6/6/93"; | 36static char sccsid[] = "@(#)names.c 8.1 (Berkeley) 6/6/93"; |
37#endif 38static const char rcsid[] = 39 "$FreeBSD: head/usr.bin/mail/names.c 74769 2001-03-25 04:57:05Z mikeh $"; |
|
36#endif /* not lint */ 37 38/* 39 * Mail -- a mail program 40 * 41 * Handle name lists. 42 */ 43 --- 45 unchanged lines hidden (view full) --- 89 */ 90struct name * 91extract(line, ntype) 92 char line[]; 93 int ntype; 94{ 95 register char *cp; 96 register struct name *top, *np, *t; | 40#endif /* not lint */ 41 42/* 43 * Mail -- a mail program 44 * 45 * Handle name lists. 46 */ 47 --- 45 unchanged lines hidden (view full) --- 93 */ 94struct name * 95extract(line, ntype) 96 char line[]; 97 int ntype; 98{ 99 register char *cp; 100 register struct name *top, *np, *t; |
97 char nbuf[BUFSIZ]; | 101 char *nbuf; |
98 99 if (line == NOSTR || *line == '\0') 100 return NIL; | 102 103 if (line == NOSTR || *line == '\0') 104 return NIL; |
105 if ((nbuf = (char *)malloc(strlen(line) + 1)) == NULL) 106 err(1, "Out of memory"); |
|
101 top = NIL; 102 np = NIL; 103 cp = line; 104 while ((cp = yankword(cp, nbuf)) != NOSTR) { 105 t = nalloc(nbuf, ntype); 106 if (top == NIL) 107 top = t; 108 else 109 np->n_flink = t; 110 t->n_blink = np; 111 np = t; 112 } | 107 top = NIL; 108 np = NIL; 109 cp = line; 110 while ((cp = yankword(cp, nbuf)) != NOSTR) { 111 t = nalloc(nbuf, ntype); 112 if (top == NIL) 113 top = t; 114 else 115 np->n_flink = t; 116 t->n_blink = np; 117 np = t; 118 } |
119 free(nbuf); |
|
113 return top; 114} 115 116/* 117 * Turn a list of names into a string of the same names. 118 */ 119char * 120detract(np, ntype) --- 22 unchanged lines hidden (view full) --- 143 if (s == 0) 144 return(NOSTR); 145 s += 2; 146 top = salloc(s); 147 cp = top; 148 for (p = np; p != NIL; p = p->n_flink) { 149 if (ntype && (p->n_type & GMASK) != ntype) 150 continue; | 120 return top; 121} 122 123/* 124 * Turn a list of names into a string of the same names. 125 */ 126char * 127detract(np, ntype) --- 22 unchanged lines hidden (view full) --- 150 if (s == 0) 151 return(NOSTR); 152 s += 2; 153 top = salloc(s); 154 cp = top; 155 for (p = np; p != NIL; p = p->n_flink) { 156 if (ntype && (p->n_type & GMASK) != ntype) 157 continue; |
151 cp = copy(p->n_name, cp); | 158 cp += strlcpy(cp, p->n_name, strlen(p->n_name) + 1); |
152 if (comma && p->n_flink != NIL) 153 *cp++ = ','; 154 *cp++ = ' '; 155 } | 159 if (comma && p->n_flink != NIL) 160 *cp++ = ','; 161 *cp++ = ' '; 162 } |
156 *--cp = 0; | 163 *--cp = '\0'; |
157 if (comma && *--cp == ',') | 164 if (comma && *--cp == ',') |
158 *cp = 0; | 165 *cp = '\0'; |
159 return(top); 160} 161 162/* 163 * Grab a single word (liberal word) 164 * Throw away things between ()'s, and take anything between <>. 165 */ 166char * --- 25 unchanged lines hidden (view full) --- 192 cp++; 193 else 194 break; 195 } 196 if (*cp == '<') 197 for (cp2 = wbuf; *cp && (*cp2++ = *cp++) != '>';) 198 ; 199 else | 166 return(top); 167} 168 169/* 170 * Grab a single word (liberal word) 171 * Throw away things between ()'s, and take anything between <>. 172 */ 173char * --- 25 unchanged lines hidden (view full) --- 199 cp++; 200 else 201 break; 202 } 203 if (*cp == '<') 204 for (cp2 = wbuf; *cp && (*cp2++ = *cp++) != '>';) 205 ; 206 else |
200 for (cp2 = wbuf; *cp && !index(" \t,(", *cp); *cp2++ = *cp++) | 207 for (cp2 = wbuf; *cp && !strchr(" \t,(", *cp); *cp2++ = *cp++) |
201 ; 202 *cp2 = '\0'; 203 return cp; 204} 205 206/* 207 * For each recipient in the passed name list with a / 208 * in the name, append the message to the end of the named file --- 9 unchanged lines hidden (view full) --- 218 struct header *hp; 219{ 220 register int c; 221 register struct name *np, *top; 222 time_t now, time(); 223 char *date, *fname, *ctime(); 224 FILE *fout, *fin; 225 int ispipe; | 208 ; 209 *cp2 = '\0'; 210 return cp; 211} 212 213/* 214 * For each recipient in the passed name list with a / 215 * in the name, append the message to the end of the named file --- 9 unchanged lines hidden (view full) --- 225 struct header *hp; 226{ 227 register int c; 228 register struct name *np, *top; 229 time_t now, time(); 230 char *date, *fname, *ctime(); 231 FILE *fout, *fin; 232 int ispipe; |
226 extern char *tempEdit; | |
227 228 top = names; 229 np = names; 230 (void) time(&now); 231 date = ctime(&now); 232 while (np != NIL) { 233 if (!isfileaddr(np->n_name) && np->n_name[0] != '|') { 234 np = np->n_flink; --- 6 unchanged lines hidden (view full) --- 241 fname = expand(np->n_name); 242 243 /* 244 * See if we have copied the complete message out yet. 245 * If not, do so. 246 */ 247 248 if (image < 0) { | 233 234 top = names; 235 np = names; 236 (void) time(&now); 237 date = ctime(&now); 238 while (np != NIL) { 239 if (!isfileaddr(np->n_name) && np->n_name[0] != '|') { 240 np = np->n_flink; --- 6 unchanged lines hidden (view full) --- 247 fname = expand(np->n_name); 248 249 /* 250 * See if we have copied the complete message out yet. 251 * If not, do so. 252 */ 253 254 if (image < 0) { |
249 if ((fout = Fopen(tempEdit, "a")) == NULL) { 250 perror(tempEdit); | 255 int fd; 256 char tempname[PATHSIZE]; 257 258 snprintf(tempname, sizeof(tempname), 259 "%s/mail.ReXXXXXXXXXX", tmpdir); 260 if ((fd = mkstemp(tempname)) == -1 || 261 (fout = Fdopen(fd, "a")) == NULL) { 262 warn("%s", tempname); |
251 senderr++; 252 goto cant; 253 } | 263 senderr++; 264 goto cant; 265 } |
254 image = open(tempEdit, 2); 255 (void) unlink(tempEdit); | 266 image = open(tempname, O_RDWR); 267 (void) rm(tempname); |
256 if (image < 0) { | 268 if (image < 0) { |
257 perror(tempEdit); | 269 warn("%s", tempname); |
258 senderr++; 259 (void) Fclose(fout); 260 goto cant; 261 } 262 (void) fcntl(image, F_SETFD, 1); 263 fprintf(fout, "From %s %s", myname, date); 264 puthead(hp, fout, 265 GTO|GSUBJECT|GCC|GREPLYTO|GINREPLYTO|GNL); 266 while ((c = getc(fo)) != EOF) 267 (void) putc(c, fout); 268 rewind(fo); 269 (void) putc('\n', fout); 270 (void) fflush(fout); | 270 senderr++; 271 (void) Fclose(fout); 272 goto cant; 273 } 274 (void) fcntl(image, F_SETFD, 1); 275 fprintf(fout, "From %s %s", myname, date); 276 puthead(hp, fout, 277 GTO|GSUBJECT|GCC|GREPLYTO|GINREPLYTO|GNL); 278 while ((c = getc(fo)) != EOF) 279 (void) putc(c, fout); 280 rewind(fo); 281 (void) putc('\n', fout); 282 (void) fflush(fout); |
271 if (ferror(fout)) 272 perror(tempEdit); | 283 if (ferror(fout)) { 284 warn("%s", tempname); 285 senderr++; 286 Fclose(fout); 287 goto cant; 288 } |
273 (void) Fclose(fout); 274 } 275 276 /* 277 * Now either copy "image" to the desired file 278 * or give it as the standard input to the desired 279 * program as appropriate. 280 */ --- 17 unchanged lines hidden (view full) --- 298 if (pid < 0) { 299 senderr++; 300 goto cant; 301 } 302 free_child(pid); 303 } else { 304 int f; 305 if ((fout = Fopen(fname, "a")) == NULL) { | 289 (void) Fclose(fout); 290 } 291 292 /* 293 * Now either copy "image" to the desired file 294 * or give it as the standard input to the desired 295 * program as appropriate. 296 */ --- 17 unchanged lines hidden (view full) --- 314 if (pid < 0) { 315 senderr++; 316 goto cant; 317 } 318 free_child(pid); 319 } else { 320 int f; 321 if ((fout = Fopen(fname, "a")) == NULL) { |
306 perror(fname); | 322 warn("%s", fname); |
307 senderr++; 308 goto cant; 309 } 310 if ((f = dup(image)) < 0) { | 323 senderr++; 324 goto cant; 325 } 326 if ((f = dup(image)) < 0) { |
311 perror("dup"); | 327 warn("dup"); |
312 fin = NULL; 313 } else 314 fin = Fdopen(f, "r"); 315 if (fin == NULL) { 316 fprintf(stderr, "Can't reopen image\n"); 317 (void) Fclose(fout); 318 senderr++; 319 goto cant; 320 } 321 rewind(fin); 322 while ((c = getc(fin)) != EOF) 323 (void) putc(c, fout); | 328 fin = NULL; 329 } else 330 fin = Fdopen(f, "r"); 331 if (fin == NULL) { 332 fprintf(stderr, "Can't reopen image\n"); 333 (void) Fclose(fout); 334 senderr++; 335 goto cant; 336 } 337 rewind(fin); 338 while ((c = getc(fin)) != EOF) 339 (void) putc(c, fout); |
324 if (ferror(fout)) 325 senderr++, perror(fname); | 340 if (ferror(fout)) { 341 warnx("%s", fname); 342 senderr++; 343 Fclose(fout); 344 Fclose(fin); 345 goto cant; 346 } |
326 (void) Fclose(fout); 327 (void) Fclose(fin); 328 } 329cant: 330 /* 331 * In days of old we removed the entry from the 332 * the list; now for sake of header expansion 333 * we leave it in and mark it as deleted. --- 144 unchanged lines hidden (view full) --- 478 struct name *np; 479{ 480 register char **ap, **top; 481 register struct name *n; 482 int t, extra, metoo, verbose; 483 484 n = np; 485 if ((t = count(n)) == 0) | 347 (void) Fclose(fout); 348 (void) Fclose(fin); 349 } 350cant: 351 /* 352 * In days of old we removed the entry from the 353 * the list; now for sake of header expansion 354 * we leave it in and mark it as deleted. --- 144 unchanged lines hidden (view full) --- 499 struct name *np; 500{ 501 register char **ap, **top; 502 register struct name *n; 503 int t, extra, metoo, verbose; 504 505 n = np; 506 if ((t = count(n)) == 0) |
486 panic("No names to unpack"); | 507 errx(1, "No names to unpack"); |
487 /* 488 * Compute the number of extra arguments we will need. 489 * We need at least two extra -- one for "mail" and one for 490 * the terminating 0 pointer. Additional spots may be needed 491 * to pass along -f to the host mailer. 492 */ 493 extra = 2; 494 extra++; --- 201 unchanged lines hidden --- | 508 /* 509 * Compute the number of extra arguments we will need. 510 * We need at least two extra -- one for "mail" and one for 511 * the terminating 0 pointer. Additional spots may be needed 512 * to pass along -f to the host mailer. 513 */ 514 extra = 2; 515 extra++; --- 201 unchanged lines hidden --- |