Deleted Added
full compact
collect.c (40171) collect.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[] = "@(#)collect.c 8.2 (Berkeley) 4/19/94";
36static char sccsid[] = "@(#)collect.c 8.2 (Berkeley) 4/19/94";
37#endif
38static const char rcsid[] =
39 "$FreeBSD: head/usr.bin/mail/collect.c 74769 2001-03-25 04:57:05Z mikeh $";
36#endif /* not lint */
37
38/*
39 * Mail -- a mail program
40 *
41 * Collect input from standard input, handling
42 * ~ escapes.
43 */

--- 25 unchanged lines hidden (view full) ---

69static jmp_buf collabort; /* To end collection with error */
70
71FILE *
72collect(hp, printheaders)
73 struct header *hp;
74 int printheaders;
75{
76 FILE *fbuf;
40#endif /* not lint */
41
42/*
43 * Mail -- a mail program
44 *
45 * Collect input from standard input, handling
46 * ~ escapes.
47 */

--- 25 unchanged lines hidden (view full) ---

73static jmp_buf collabort; /* To end collection with error */
74
75FILE *
76collect(hp, printheaders)
77 struct header *hp;
78 int printheaders;
79{
80 FILE *fbuf;
77 int lc, cc, escape, eofcount;
81 int lc, cc, escape, eofcount, fd;
78 register int c, t;
82 register int c, t;
79 char linebuf[LINESIZE], *cp;
80 extern char *tempMail;
83 char linebuf[LINESIZE], tempname[PATHSIZE], *cp;
81 char getsub;
82 int omask;
83 void collint(), collhup(), collstop();
84
85 collf = NULL;
86 /*
87 * Start catching signals from here, but we're still die on interrupts
88 * until we're in the main loop.
89 */
90 omask = sigblock(sigmask(SIGINT) | sigmask(SIGHUP));
91 if ((saveint = signal(SIGINT, SIG_IGN)) != SIG_IGN)
92 signal(SIGINT, collint);
93 if ((savehup = signal(SIGHUP, SIG_IGN)) != SIG_IGN)
94 signal(SIGHUP, collhup);
95 savetstp = signal(SIGTSTP, collstop);
96 savettou = signal(SIGTTOU, collstop);
97 savettin = signal(SIGTTIN, collstop);
98 if (setjmp(collabort) || setjmp(colljmp)) {
84 char getsub;
85 int omask;
86 void collint(), collhup(), collstop();
87
88 collf = NULL;
89 /*
90 * Start catching signals from here, but we're still die on interrupts
91 * until we're in the main loop.
92 */
93 omask = sigblock(sigmask(SIGINT) | sigmask(SIGHUP));
94 if ((saveint = signal(SIGINT, SIG_IGN)) != SIG_IGN)
95 signal(SIGINT, collint);
96 if ((savehup = signal(SIGHUP, SIG_IGN)) != SIG_IGN)
97 signal(SIGHUP, collhup);
98 savetstp = signal(SIGTSTP, collstop);
99 savettou = signal(SIGTTOU, collstop);
100 savettin = signal(SIGTTIN, collstop);
101 if (setjmp(collabort) || setjmp(colljmp)) {
99 rm(tempMail);
102 rm(tempname);
100 goto err;
101 }
102 sigsetmask(omask & ~(sigmask(SIGINT) | sigmask(SIGHUP)));
103
104 noreset++;
103 goto err;
104 }
105 sigsetmask(omask & ~(sigmask(SIGINT) | sigmask(SIGHUP)));
106
107 noreset++;
105 if ((collf = Fopen(tempMail, "w+")) == NULL) {
106 perror(tempMail);
108 snprintf(tempname, sizeof(tempname), "%s/mail.RsXXXXXXXXXX", tmpdir);
109 if ((fd = mkstemp(tempname)) == -1 ||
110 (collf = Fdopen(fd, "w+")) == NULL) {
111 warn("%s", tempname);
107 goto err;
108 }
112 goto err;
113 }
109 unlink(tempMail);
114 rm(tempname);
110
111 /*
112 * If we are going to prompt for a subject,
113 * refrain from printing a newline after
114 * the headers (since some people mind).
115 */
116 t = GTO|GSUBJECT|GCC|GNL;
117 getsub = 0;

--- 138 unchanged lines hidden (view full) ---

256 break;
257 case 'b':
258 /*
259 * Add stuff to blind carbon copies list.
260 */
261 hp->h_bcc = cat(hp->h_bcc, extract(&linebuf[2], GBCC));
262 break;
263 case 'd':
115
116 /*
117 * If we are going to prompt for a subject,
118 * refrain from printing a newline after
119 * the headers (since some people mind).
120 */
121 t = GTO|GSUBJECT|GCC|GNL;
122 getsub = 0;

--- 138 unchanged lines hidden (view full) ---

261 break;
262 case 'b':
263 /*
264 * Add stuff to blind carbon copies list.
265 */
266 hp->h_bcc = cat(hp->h_bcc, extract(&linebuf[2], GBCC));
267 break;
268 case 'd':
264 strcpy(linebuf + 2, getdeadletter());
269 if (strlcpy(linebuf + 2, getdeadletter(), sizeof(linebuf) - 2)
270 >= sizeof(linebuf) - 2) {
271 printf("Line buffer overflow\n");
272 break;
273 }
265 /* fall into . . . */
266 case 'r':
267 /*
268 * Invoke a file:
269 * Search for the file name,
270 * then open it and copy the contents to collf.
271 */
272 cp = &linebuf[2];

--- 6 unchanged lines hidden (view full) ---

279 cp = expand(cp);
280 if (cp == NOSTR)
281 break;
282 if (isdir(cp)) {
283 printf("%s: Directory\n", cp);
284 break;
285 }
286 if ((fbuf = Fopen(cp, "r")) == NULL) {
274 /* fall into . . . */
275 case 'r':
276 /*
277 * Invoke a file:
278 * Search for the file name,
279 * then open it and copy the contents to collf.
280 */
281 cp = &linebuf[2];

--- 6 unchanged lines hidden (view full) ---

288 cp = expand(cp);
289 if (cp == NOSTR)
290 break;
291 if (isdir(cp)) {
292 printf("%s: Directory\n", cp);
293 break;
294 }
295 if ((fbuf = Fopen(cp, "r")) == NULL) {
287 perror(cp);
296 warn("%s", cp);
288 break;
289 }
290 printf("\"%s\" ", cp);
291 fflush(stdout);
292 lc = 0;
293 cc = 0;
294 while (readline(fbuf, linebuf, LINESIZE) >= 0) {
295 lc++;

--- 27 unchanged lines hidden (view full) ---

323 case 'f':
324 case 'F':
325 /*
326 * Interpolate the named messages, if we
327 * are in receiving mail mode. Does the
328 * standard list processing garbage.
329 * If ~f is given, we don't shift over.
330 */
297 break;
298 }
299 printf("\"%s\" ", cp);
300 fflush(stdout);
301 lc = 0;
302 cc = 0;
303 while (readline(fbuf, linebuf, LINESIZE) >= 0) {
304 lc++;

--- 27 unchanged lines hidden (view full) ---

332 case 'f':
333 case 'F':
334 /*
335 * Interpolate the named messages, if we
336 * are in receiving mail mode. Does the
337 * standard list processing garbage.
338 * If ~f is given, we don't shift over.
339 */
331 if (forward(linebuf + 2, collf, c) < 0)
340 if (forward(linebuf + 2, collf, tempname, c) < 0)
332 goto err;
333 goto cont;
334 case '?':
335 if ((fbuf = Fopen(_PATH_TILDE, "r")) == NULL) {
341 goto err;
342 goto cont;
343 case '?':
344 if ((fbuf = Fopen(_PATH_TILDE, "r")) == NULL) {
336 perror(_PATH_TILDE);
345 warn("%s", _PATH_TILDE);
337 break;
338 }
339 while ((t = getc(fbuf)) != EOF)
340 (void) putchar(t);
341 Fclose(fbuf);
342 break;
343 case 'p':
344 /*

--- 60 unchanged lines hidden (view full) ---

405 long cc;
406 int lc;
407 struct stat junk;
408
409 if (f) {
410 printf("\"%s\" ", name);
411 fflush(stdout);
412 }
346 break;
347 }
348 while ((t = getc(fbuf)) != EOF)
349 (void) putchar(t);
350 Fclose(fbuf);
351 break;
352 case 'p':
353 /*

--- 60 unchanged lines hidden (view full) ---

414 long cc;
415 int lc;
416 struct stat junk;
417
418 if (f) {
419 printf("\"%s\" ", name);
420 fflush(stdout);
421 }
413 if (stat(name, &junk) >= 0 && (junk.st_mode & S_IFMT) == S_IFREG) {
422 if (stat(name, &junk) >= 0 && S_ISREG(junk.st_mode)) {
414 if (!f)
415 fprintf(stderr, "%s: ", name);
416 fprintf(stderr, "File exists\n");
417 return(-1);
418 }
419 if ((of = Fopen(name, "w")) == NULL) {
423 if (!f)
424 fprintf(stderr, "%s: ", name);
425 fprintf(stderr, "File exists\n");
426 return(-1);
427 }
428 if ((of = Fopen(name, "w")) == NULL) {
420 perror(NOSTR);
429 warn(NOSTR);
421 return(-1);
422 }
423 lc = 0;
424 cc = 0;
425 while ((c = getc(fp)) != EOF) {
426 cc++;
427 if (c == '\n')
428 lc++;
429 (void) putc(c, of);
430 if (ferror(of)) {
430 return(-1);
431 }
432 lc = 0;
433 cc = 0;
434 while ((c = getc(fp)) != EOF) {
435 cc++;
436 if (c == '\n')
437 lc++;
438 (void) putc(c, of);
439 if (ferror(of)) {
431 perror(name);
440 warnx("%s", name);
432 Fclose(of);
433 return(-1);
434 }
435 }
436 Fclose(of);
437 printf("%d/%ld\n", lc, cc);
438 fflush(stdout);
439 return(0);

--- 26 unchanged lines hidden (view full) ---

466 * Sh -c must return 0 to accept the new message.
467 */
468void
469mespipe(fp, cmd)
470 FILE *fp;
471 char cmd[];
472{
473 FILE *nf;
441 Fclose(of);
442 return(-1);
443 }
444 }
445 Fclose(of);
446 printf("%d/%ld\n", lc, cc);
447 fflush(stdout);
448 return(0);

--- 26 unchanged lines hidden (view full) ---

475 * Sh -c must return 0 to accept the new message.
476 */
477void
478mespipe(fp, cmd)
479 FILE *fp;
480 char cmd[];
481{
482 FILE *nf;
483 int fd;
474 sig_t sigint = signal(SIGINT, SIG_IGN);
484 sig_t sigint = signal(SIGINT, SIG_IGN);
475 extern char *tempEdit;
476 char *shell;
485 char *shell, tempname[PATHSIZE];
477
486
478 if ((nf = Fopen(tempEdit, "w+")) == NULL) {
479 perror(tempEdit);
487 snprintf(tempname, sizeof(tempname), "%s/mail.ReXXXXXXXXXX", tmpdir);
488 if ((fd = mkstemp(tempname)) == -1 ||
489 (nf = Fdopen(fd, "w+")) == NULL) {
490 warn("%s", tempname);
480 goto out;
481 }
491 goto out;
492 }
482 (void) unlink(tempEdit);
493 (void) rm(tempname);
483 /*
484 * stdin = current message.
485 * stdout = new message.
486 */
487 if ((shell = value("SHELL")) == NOSTR)
488 shell = _PATH_CSHELL;
489 if (run_command(shell,
490 0, fileno(fp), fileno(nf), "-c", cmd, NOSTR) < 0) {

--- 19 unchanged lines hidden (view full) ---

510 * Interpolate the named messages into the current
511 * message, preceding each line with a tab.
512 * Return a count of the number of characters now in
513 * the message, or -1 if an error is encountered writing
514 * the message temporary. The flag argument is 'm' if we
515 * should shift over and 'f' if not.
516 */
517int
494 /*
495 * stdin = current message.
496 * stdout = new message.
497 */
498 if ((shell = value("SHELL")) == NOSTR)
499 shell = _PATH_CSHELL;
500 if (run_command(shell,
501 0, fileno(fp), fileno(nf), "-c", cmd, NOSTR) < 0) {

--- 19 unchanged lines hidden (view full) ---

521 * Interpolate the named messages into the current
522 * message, preceding each line with a tab.
523 * Return a count of the number of characters now in
524 * the message, or -1 if an error is encountered writing
525 * the message temporary. The flag argument is 'm' if we
526 * should shift over and 'f' if not.
527 */
528int
518forward(ms, fp, f)
529forward(ms, fp, fn, f)
519 char ms[];
520 FILE *fp;
530 char ms[];
531 FILE *fp;
532 char *fn;
521 int f;
522{
523 register int *msgvec;
533 int f;
534{
535 register int *msgvec;
524 extern char *tempMail;
525 struct ignoretab *ig;
526 char *tabst;
527
528 msgvec = (int *) salloc((msgCount+1) * sizeof *msgvec);
529 if (msgvec == (int *) NOSTR)
530 return(0);
531 if (getmsglist(ms, msgvec, 0) < 0)
532 return(0);

--- 11 unchanged lines hidden (view full) ---

544 tabst = "\t";
545 ig = isupper(f) ? NULL : ignore;
546 printf("Interpolating:");
547 for (; *msgvec != 0; msgvec++) {
548 struct message *mp = message + *msgvec - 1;
549
550 touch(mp);
551 printf(" %d", *msgvec);
536 struct ignoretab *ig;
537 char *tabst;
538
539 msgvec = (int *) salloc((msgCount+1) * sizeof *msgvec);
540 if (msgvec == (int *) NOSTR)
541 return(0);
542 if (getmsglist(ms, msgvec, 0) < 0)
543 return(0);

--- 11 unchanged lines hidden (view full) ---

555 tabst = "\t";
556 ig = isupper(f) ? NULL : ignore;
557 printf("Interpolating:");
558 for (; *msgvec != 0; msgvec++) {
559 struct message *mp = message + *msgvec - 1;
560
561 touch(mp);
562 printf(" %d", *msgvec);
552 if (send(mp, fp, ig, tabst) < 0) {
553 perror(tempMail);
563 if (sendmessage(mp, fp, ig, tabst) < 0) {
564 warnx("%s", fn);
554 return(-1);
555 }
556 }
557 printf("\n");
558 return(0);
559}
560
561/*

--- 83 unchanged lines hidden ---
565 return(-1);
566 }
567 }
568 printf("\n");
569 return(0);
570}
571
572/*

--- 83 unchanged lines hidden ---