cmd3.c: fix compiler warnings..
[s-mailx.git] / sendout.c
blobf265c716d88dd591b119592a19d1af87b930afb2
1 /*
2 * Heirloom mailx - a mail user agent derived from Berkeley Mail.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 Steffen Daode Nurpmeso.
6 * All rights reserved.
7 */
8 /*
9 * Copyright (c) 1980, 1993
10 * The Regents of the University of California. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
41 #ifndef lint
42 #ifdef DOSCCS
43 static char sccsid[] = "@(#)sendout.c 2.100 (gritter) 3/1/09";
44 #endif
45 #endif /* not lint */
47 #include "rcv.h"
48 #include "extern.h"
49 #include <errno.h>
50 #include <sys/stat.h>
51 #include <fcntl.h>
52 #include <unistd.h>
53 #include <time.h>
54 #include "md5.h"
57 * Mail -- a mail program
59 * Mail to others.
62 static char *send_boundary;
64 static char *getencoding(enum conversion convert);
65 static struct name *fixhead(struct header *hp, struct name *tolist);
66 static int put_signature(FILE *fo, int convert);
67 static int attach_file1(struct attachment *ap, FILE *fo, int dosign);
68 static int attach_file(struct attachment *ap, FILE *fo, int dosign);
69 static int attach_message(struct attachment *ap, FILE *fo, int dosign);
70 static int make_multipart(struct header *hp, int convert, FILE *fi, FILE *fo,
71 const char *contenttype, const char *charset, int dosign);
72 static FILE *infix(struct header *hp, FILE *fi, int dosign);
73 static int savemail(char *name, FILE *fi);
74 static int sendmail_internal(void *v, int recipient_record);
75 static enum okay transfer(struct name *to, struct name *mailargs, FILE *input,
76 struct header *hp);
77 static enum okay start_mta(struct name *to, struct name *mailargs, FILE *input,
78 struct header *hp);
79 static void message_id(FILE *fo, struct header *hp);
80 static int fmt(char *str, struct name *np, FILE *fo, int comma,
81 int dropinvalid, int domime);
82 static int infix_resend(FILE *fi, FILE *fo, struct message *mp,
83 struct name *to, int add_resent);
86 * Generate a boundary for MIME multipart messages.
88 char *
89 makeboundary(void)
91 static char bound[70];
92 time_t now;
94 time(&now);
95 snprintf(bound, sizeof bound, "=_%lx.%s", (long)now, getrandstring(48));
96 send_boundary = bound;
97 return send_boundary;
101 * Get an encoding flag based on the given string.
103 static char *
104 getencoding(enum conversion convert)
106 switch (convert) {
107 case CONV_7BIT:
108 return "7bit";
109 case CONV_8BIT:
110 return "8bit";
111 case CONV_TOQP:
112 return "quoted-printable";
113 case CONV_TOB64:
114 return "base64";
115 default:
116 break;
118 /*NOTREACHED*/
119 return NULL;
123 * Fix the header by glopping all of the expanded names from
124 * the distribution list into the appropriate fields.
126 static struct name *
127 fixhead(struct header *hp, struct name *tolist)
129 struct name *np;
131 hp->h_to = NULL;
132 hp->h_cc = NULL;
133 hp->h_bcc = NULL;
134 for (np = tolist; np != NULL; np = np->n_flink)
135 if ((np->n_type & GMASK) == GTO)
136 hp->h_to =
137 cat(hp->h_to, nalloc(np->n_fullname,
138 np->n_type|GFULL));
139 else if ((np->n_type & GMASK) == GCC)
140 hp->h_cc =
141 cat(hp->h_cc, nalloc(np->n_fullname,
142 np->n_type|GFULL));
143 else if ((np->n_type & GMASK) == GBCC)
144 hp->h_bcc =
145 cat(hp->h_bcc, nalloc(np->n_fullname,
146 np->n_type|GFULL));
147 return tolist;
152 * Do not change, you get incorrect base64 encodings else!
154 #define INFIX_BUF 972
157 * Put the signature file at fo.
159 static int
160 put_signature(FILE *fo, int convert)
162 char *sig, buf[INFIX_BUF], c = '\n';
163 FILE *fsig;
164 size_t sz;
166 sig = value("signature");
167 if (sig == NULL || *sig == '\0')
168 return 0;
169 else
170 sig = expand(sig);
171 if ((fsig = Fopen(sig, "r")) == NULL) {
172 perror(sig);
173 return -1;
175 while ((sz = fread(buf, sizeof *buf, INFIX_BUF, fsig)) != 0) {
176 c = buf[sz - 1];
177 if (mime_write(buf, sz, fo, convert, TD_NONE,
178 NULL, (size_t)0, NULL, NULL)
179 == 0) {
180 perror(sig);
181 Fclose(fsig);
182 return -1;
185 if (ferror(fsig)) {
186 perror(sig);
187 Fclose(fsig);
188 return -1;
190 Fclose(fsig);
191 if (c != '\n')
192 putc('\n', fo);
193 return 0;
197 * Write an attachment to the file buffer, converting to MIME.
199 static int
200 attach_file1(struct attachment *ap, FILE *fo, int dosign)
202 FILE *fi;
203 char *charset = NULL, *contenttype = NULL, *basename;
204 enum conversion convert = CONV_TOB64;
205 int err = 0;
206 enum mimeclean isclean;
207 size_t sz;
208 char *buf;
209 size_t bufsize, count;
210 int lastc = EOF;
211 #ifdef HAVE_ICONV
212 char *tcs;
213 #endif
215 if ((fi = Fopen(ap->a_name, "r")) == NULL) {
216 perror(ap->a_name);
217 return -1;
219 if ((basename = strrchr(ap->a_name, '/')) == NULL)
220 basename = ap->a_name;
221 else
222 basename++;
223 if (ap->a_content_type)
224 contenttype = ap->a_content_type;
225 else
226 contenttype = mime_filecontent(basename);
227 if (ap->a_charset)
228 charset = ap->a_charset;
229 convert = get_mime_convert(fi, &contenttype, &charset, &isclean,
230 dosign);
231 fprintf(fo,
232 "\n--%s\n"
233 "Content-Type: %s",
234 send_boundary, contenttype);
235 if (charset == NULL)
236 putc('\n', fo);
237 else
238 fprintf(fo, ";\n charset=%s\n", charset);
239 if (ap->a_content_disposition == NULL)
240 ap->a_content_disposition = "attachment";
241 fprintf(fo, "Content-Transfer-Encoding: %s\n"
242 "Content-Disposition: %s;\n"
243 " filename=\"",
244 getencoding(convert),
245 ap->a_content_disposition);
246 mime_write(basename, strlen(basename), fo,
247 CONV_TOHDR, TD_NONE, NULL, (size_t)0, NULL, NULL);
248 fwrite("\"\n", sizeof (char), 2, fo);
249 if (ap->a_content_id)
250 fprintf(fo, "Content-ID: %s\n", ap->a_content_id);
251 if (ap->a_content_description)
252 fprintf(fo, "Content-Description: %s\n",
253 ap->a_content_description);
254 putc('\n', fo);
255 #ifdef HAVE_ICONV
256 if (iconvd != (iconv_t)-1) {
257 iconv_close(iconvd);
258 iconvd = (iconv_t)-1;
260 tcs = gettcharset();
261 if ((isclean & (MIME_HASNUL|MIME_CTRLCHAR)) == 0 &&
262 ascncasecmp(contenttype, "text/", 5) == 0 &&
263 isclean & MIME_HIGHBIT &&
264 charset != NULL) {
265 if ((iconvd = iconv_open_ft(charset, tcs)) == (iconv_t)-1 &&
266 errno != 0) {
267 if (errno == EINVAL)
268 fprintf(stderr, catgets(catd, CATSET, 179,
269 "Cannot convert from %s to %s\n"), tcs, charset);
270 else
271 perror("iconv_open");
272 Fclose(fi);
273 return -1;
276 #endif /* HAVE_ICONV */
277 buf = smalloc(bufsize = INFIX_BUF);
278 if (convert == CONV_TOQP
279 #ifdef HAVE_ICONV
280 || iconvd != (iconv_t)-1
281 #endif
283 fflush(fi);
284 count = fsize(fi);
286 for (;;) {
287 if (convert == CONV_TOQP
288 #ifdef HAVE_ICONV
289 || iconvd != (iconv_t)-1
290 #endif
292 if (fgetline(&buf, &bufsize, &count, &sz, fi, 0)
293 == NULL)
294 break;
295 } else {
296 if ((sz = fread(buf, sizeof *buf, bufsize, fi)) == 0)
297 break;
299 lastc = buf[sz-1];
300 if (mime_write(buf, sz, fo, convert, TD_ICONV,
301 NULL, (size_t)0, NULL, NULL) == 0)
302 err = -1;
304 if (convert == CONV_TOQP && lastc != '\n')
305 fwrite("=\n", 1, 2, fo);
306 if (ferror(fi))
307 err = -1;
308 Fclose(fi);
309 free(buf);
310 return err;
314 * Try out different character set conversions to attach a file.
316 static int
317 attach_file(struct attachment *ap, FILE *fo, int dosign)
319 char *_wantcharset, *charsets, *ncs;
320 size_t offs = ftell(fo);
322 if (ap->a_charset || (charsets = value("sendcharsets")) == NULL)
323 return attach_file1(ap, fo, dosign);
324 _wantcharset = wantcharset;
325 wantcharset = savestr(charsets);
326 loop: if ((ncs = strchr(wantcharset, ',')) != NULL)
327 *ncs++ = '\0';
328 try: if (attach_file1(ap, fo, dosign) != 0) {
329 if (errno == EILSEQ || errno == EINVAL) {
330 if (ncs && *ncs) {
331 wantcharset = ncs;
332 clearerr(fo);
333 fseek(fo, offs, SEEK_SET);
334 goto loop;
336 if (wantcharset) {
337 if (wantcharset == (char *)-1)
338 wantcharset = NULL;
339 else {
340 wantcharset = (char *)-1;
341 clearerr(fo);
342 fseek(fo, offs, SEEK_SET);
343 goto try;
348 wantcharset = _wantcharset;
349 return 0;
353 * Attach a message to the file buffer.
355 static int
356 attach_message(struct attachment *ap, FILE *fo, int dosign)
358 struct message *mp;
360 fprintf(fo, "\n--%s\n"
361 "Content-Type: message/rfc822\n"
362 "Content-Disposition: inline\n\n", send_boundary);
363 mp = &message[ap->a_msgno - 1];
364 touch(mp);
365 if (send(mp, fo, 0, NULL, SEND_RFC822, NULL) < 0)
366 return -1;
367 return 0;
371 * Generate the body of a MIME multipart message.
373 static int
374 make_multipart(struct header *hp, int convert, FILE *fi, FILE *fo,
375 const char *contenttype, const char *charset, int dosign)
377 struct attachment *att;
379 fputs("This is a multi-part message in MIME format.\n", fo);
380 if (fsize(fi) != 0) {
381 char *buf, c = '\n';
382 size_t sz, bufsize, count;
384 fprintf(fo, "\n--%s\n", send_boundary);
385 fprintf(fo, "Content-Type: %s", contenttype);
386 if (charset)
387 fprintf(fo, "; charset=%s", charset);
388 fprintf(fo, "\nContent-Transfer-Encoding: %s\n"
389 "Content-Disposition: inline\n\n",
390 getencoding(convert));
391 buf = smalloc(bufsize = INFIX_BUF);
392 if (convert == CONV_TOQP
393 #ifdef HAVE_ICONV
394 || iconvd != (iconv_t)-1
395 #endif /* HAVE_ICONV */
397 fflush(fi);
398 count = fsize(fi);
400 for (;;) {
401 if (convert == CONV_TOQP
402 #ifdef HAVE_ICONV
403 || iconvd != (iconv_t)-1
404 #endif /* HAVE_ICONV */
406 if (fgetline(&buf, &bufsize, &count, &sz, fi, 0)
407 == NULL)
408 break;
409 } else {
410 sz = fread(buf, sizeof *buf, bufsize, fi);
411 if (sz == 0)
412 break;
414 c = buf[sz - 1];
415 if (mime_write(buf, sz, fo, convert,
416 TD_ICONV, NULL, (size_t)0,
417 NULL, NULL) == 0) {
418 free(buf);
419 return -1;
422 free(buf);
423 if (ferror(fi))
424 return -1;
425 if (c != '\n')
426 putc('\n', fo);
427 if (charset != NULL)
428 put_signature(fo, convert);
430 for (att = hp->h_attach; att != NULL; att = att->a_flink) {
431 if (att->a_msgno) {
432 if (attach_message(att, fo, dosign) != 0)
433 return -1;
434 } else {
435 if (attach_file(att, fo, dosign) != 0)
436 return -1;
439 /* the final boundary with two attached dashes */
440 fprintf(fo, "\n--%s--\n", send_boundary);
441 return 0;
445 * Prepend a header in front of the collected stuff
446 * and return the new file.
448 static FILE *
449 infix(struct header *hp, FILE *fi, int dosign)
451 FILE *nfo, *nfi;
452 char *tempMail;
453 #ifdef HAVE_ICONV
454 char *tcs, *convhdr = NULL;
455 #endif
456 enum mimeclean isclean;
457 enum conversion convert;
458 char *charset = NULL, *contenttype = NULL;
459 int lastc = EOF;
461 if ((nfo = Ftemp(&tempMail, "Rs", "w", 0600, 1)) == NULL) {
462 perror(catgets(catd, CATSET, 178, "temporary mail file"));
463 return(NULL);
465 if ((nfi = Fopen(tempMail, "r")) == NULL) {
466 perror(tempMail);
467 Fclose(nfo);
468 return(NULL);
470 rm(tempMail);
471 Ftfree(&tempMail);
472 convert = get_mime_convert(fi, &contenttype, &charset,
473 &isclean, dosign);
474 #ifdef HAVE_ICONV
475 tcs = gettcharset();
476 if ((convhdr = need_hdrconv(hp, GTO|GSUBJECT|GCC|GBCC|GIDENT)) != 0) {
477 if (iconvd != (iconv_t)-1)
478 iconv_close(iconvd);
479 if ((iconvd = iconv_open_ft(convhdr, tcs)) == (iconv_t)-1
480 && errno != 0) {
481 if (errno == EINVAL)
482 fprintf(stderr, catgets(catd, CATSET, 179,
483 "Cannot convert from %s to %s\n"), tcs, convhdr);
484 else
485 perror("iconv_open");
486 Fclose(nfo);
487 return NULL;
490 #endif /* HAVE_ICONV */
491 if (puthead(hp, nfo,
492 GTO|GSUBJECT|GCC|GBCC|GNL|GCOMMA|GUA|GMIME
493 |GMSGID|GIDENT|GREF|GDATE,
494 SEND_MBOX, convert, contenttype, charset)) {
495 Fclose(nfo);
496 Fclose(nfi);
497 #ifdef HAVE_ICONV
498 if (iconvd != (iconv_t)-1) {
499 iconv_close(iconvd);
500 iconvd = (iconv_t)-1;
502 #endif
503 return NULL;
505 #ifdef HAVE_ICONV
506 if (convhdr && iconvd != (iconv_t)-1) {
507 iconv_close(iconvd);
508 iconvd = (iconv_t)-1;
510 if ((isclean & (MIME_HASNUL|MIME_CTRLCHAR)) == 0 &&
511 ascncasecmp(contenttype, "text/", 5) == 0 &&
512 isclean & MIME_HIGHBIT &&
513 charset != NULL) {
514 if (iconvd != (iconv_t)-1)
515 iconv_close(iconvd);
516 if ((iconvd = iconv_open_ft(charset, tcs)) == (iconv_t)-1
517 && errno != 0) {
518 if (errno == EINVAL)
519 fprintf(stderr, catgets(catd, CATSET, 179,
520 "Cannot convert from %s to %s\n"), tcs, charset);
521 else
522 perror("iconv_open");
523 Fclose(nfo);
524 return NULL;
527 #endif
528 if (hp->h_attach != NULL) {
529 if (make_multipart(hp, convert, fi, nfo,
530 contenttype, charset, dosign) != 0) {
531 Fclose(nfo);
532 Fclose(nfi);
533 #ifdef HAVE_ICONV
534 if (iconvd != (iconv_t)-1) {
535 iconv_close(iconvd);
536 iconvd = (iconv_t)-1;
538 #endif
539 return NULL;
541 } else {
542 size_t sz, bufsize, count;
543 char *buf;
545 if (convert == CONV_TOQP
546 #ifdef HAVE_ICONV
547 || iconvd != (iconv_t)-1
548 #endif /* HAVE_ICONV */
550 fflush(fi);
551 count = fsize(fi);
553 buf = smalloc(bufsize = INFIX_BUF);
554 for (;;) {
555 if (convert == CONV_TOQP
556 #ifdef HAVE_ICONV
557 || iconvd != (iconv_t)-1
558 #endif /* HAVE_ICONV */
560 if (fgetline(&buf, &bufsize, &count, &sz, fi, 0)
561 == NULL)
562 break;
563 } else {
564 sz = fread(buf, sizeof *buf, bufsize, fi);
565 if (sz == 0)
566 break;
568 lastc = buf[sz - 1];
569 if (mime_write(buf, sz, nfo, convert,
570 TD_ICONV, NULL, (size_t)0,
571 NULL, NULL) == 0) {
572 Fclose(nfo);
573 Fclose(nfi);
574 #ifdef HAVE_ICONV
575 if (iconvd != (iconv_t)-1) {
576 iconv_close(iconvd);
577 iconvd = (iconv_t)-1;
579 #endif
580 free(buf);
581 return NULL;
584 if (convert == CONV_TOQP && lastc != '\n')
585 fwrite("=\n", 1, 2, nfo);
586 free(buf);
587 if (ferror(fi)) {
588 Fclose(nfo);
589 Fclose(nfi);
590 #ifdef HAVE_ICONV
591 if (iconvd != (iconv_t)-1) {
592 iconv_close(iconvd);
593 iconvd = (iconv_t)-1;
595 #endif
596 return NULL;
598 if (charset != NULL)
599 put_signature(nfo, convert);
601 #ifdef HAVE_ICONV
602 if (iconvd != (iconv_t)-1) {
603 iconv_close(iconvd);
604 iconvd = (iconv_t)-1;
606 #endif
607 fflush(nfo);
608 if (ferror(nfo)) {
609 perror(catgets(catd, CATSET, 180, "temporary mail file"));
610 Fclose(nfo);
611 Fclose(nfi);
612 return NULL;
614 Fclose(nfo);
615 Fclose(fi);
616 fflush(nfi);
617 rewind(nfi);
618 return(nfi);
622 * Save the outgoing mail on the passed file.
625 /*ARGSUSED*/
626 static int
627 savemail(char *name, FILE *fi)
629 FILE *fo;
630 char *buf;
631 size_t bufsize, buflen, count;
632 char *p;
633 time_t now;
634 int prependnl = 0;
635 int error = 0;
637 buf = smalloc(bufsize = LINESIZE);
638 time(&now);
639 if ((fo = Zopen(name, "a+", NULL)) == NULL) {
640 if ((fo = Zopen(name, "wx", NULL)) == NULL) {
641 perror(name);
642 free(buf);
643 return (-1);
645 } else {
646 if (fseek(fo, -2L, SEEK_END) == 0) {
647 switch (fread(buf, sizeof *buf, 2, fo)) {
648 case 2:
649 if (buf[1] != '\n') {
650 prependnl = 1;
651 break;
653 /*FALLTHRU*/
654 case 1:
655 if (buf[0] != '\n')
656 prependnl = 1;
657 break;
658 default:
659 if (ferror(fo)) {
660 perror(name);
661 free(buf);
662 return -1;
665 fflush(fo);
666 if (prependnl) {
667 putc('\n', fo);
668 fflush(fo);
672 fprintf(fo, "From %s %s", myname, ctime(&now));
673 buflen = 0;
674 fflush(fi);
675 rewind(fi);
676 count = fsize(fi);
677 while (fgetline(&buf, &bufsize, &count, &buflen, fi, 0) != NULL) {
678 if (*buf == '>') {
679 p = buf + 1;
680 while (*p == '>')
681 p++;
682 if (strncmp(p, "From ", 5) == 0)
683 /* we got a masked From line */
684 putc('>', fo);
685 } else if (strncmp(buf, "From ", 5) == 0)
686 putc('>', fo);
687 fwrite(buf, sizeof *buf, buflen, fo);
689 if (buflen && *(buf + buflen - 1) != '\n')
690 putc('\n', fo);
691 putc('\n', fo);
692 fflush(fo);
693 if (ferror(fo)) {
694 perror(name);
695 error = -1;
697 if (Fclose(fo) != 0)
698 error = -1;
699 fflush(fi);
700 rewind(fi);
701 free(buf);
702 return error;
706 * Interface between the argument list and the mail1 routine
707 * which does all the dirty work.
709 int
710 mail(struct name *to, struct name *cc, struct name *bcc,
711 struct name *smopts, char *subject, struct attachment *attach,
712 char *quotefile, int recipient_record, int tflag, int Eflag)
714 struct header head;
715 struct str in, out;
717 memset(&head, 0, sizeof head);
718 /* The given subject may be in RFC1522 format. */
719 if (subject != NULL) {
720 in.s = subject;
721 in.l = strlen(subject);
722 mime_fromhdr(&in, &out, TD_ISPR | TD_ICONV);
723 head.h_subject = out.s;
725 if (tflag == 0) {
726 head.h_to = to;
727 head.h_cc = cc;
728 head.h_bcc = bcc;
730 head.h_attach = attach;
731 head.h_smopts = smopts;
732 mail1(&head, 0, NULL, quotefile, recipient_record, 0, tflag, Eflag);
733 if (subject != NULL)
734 free(out.s);
735 return(0);
739 * Send mail to a bunch of user names. The interface is through
740 * the mail routine below.
742 static int
743 sendmail_internal(void *v, int recipient_record)
745 int Eflag;
746 char *str = v;
747 struct header head;
749 memset(&head, 0, sizeof head);
750 head.h_to = extract(str, GTO|GFULL);
751 Eflag = value("skipemptybody") != NULL;
752 mail1(&head, 0, NULL, NULL, recipient_record, 0, 0, Eflag);
753 return(0);
756 int
757 sendmail(void *v)
759 return sendmail_internal(v, 0);
762 int
763 Sendmail(void *v)
765 return sendmail_internal(v, 1);
768 static enum okay
769 transfer(struct name *to, struct name *mailargs, FILE *input, struct header *hp)
771 char o[LINESIZE], *cp;
772 struct name *np, *nt;
773 int cnt = 0;
774 FILE *ef;
775 enum okay ok = OKAY;
777 np = to;
778 while (np) {
779 snprintf(o, sizeof o, "smime-encrypt-%s", np->n_name);
780 if ((cp = value(o)) != NULL) {
781 if ((ef = smime_encrypt(input, cp, np->n_name)) != 0) {
782 nt = nalloc(np->n_name,
783 np->n_type & ~(GFULL|GSKIN));
784 if (start_mta(nt, mailargs, ef, hp) != OKAY)
785 ok = STOP;
786 Fclose(ef);
787 } else {
788 fprintf(stderr, "Message not sent to <%s>\n",
789 np->n_name);
790 senderr++;
792 rewind(input);
793 if (np->n_flink)
794 np->n_flink->n_blink = np->n_blink;
795 if (np->n_blink)
796 np->n_blink->n_flink = np->n_flink;
797 if (np == to)
798 to = np->n_flink;
799 np = np->n_flink;
800 } else {
801 cnt++;
802 np = np->n_flink;
805 if (cnt) {
806 if (value("smime-force-encryption") ||
807 start_mta(to, mailargs, input, hp) != OKAY)
808 ok = STOP;
810 return ok;
814 * Start the Mail Transfer Agent
815 * mailing to namelist and stdin redirected to input.
817 static enum okay
818 start_mta(struct name *to, struct name *mailargs, FILE *input,
819 struct header *hp)
821 char **args = NULL, **t;
822 pid_t pid;
823 sigset_t nset;
824 char *cp, *smtp;
825 char *user = NULL, *password = NULL, *skinned = NULL;
826 enum okay ok = STOP;
827 #ifdef USE_SMTP
828 struct termios otio;
829 int reset_tio;
830 #endif
832 if ((smtp = value("smtp")) == NULL) {
833 args = unpack(cat(mailargs, to));
834 if (debug || value("debug")) {
835 printf(catgets(catd, CATSET, 181,
836 "Sendmail arguments:"));
837 for (t = args; *t != NULL; t++)
838 printf(" \"%s\"", *t);
839 printf("\n");
840 return OKAY;
843 #ifdef USE_SMTP
844 if (smtp != NULL) {
845 skinned = skin(myorigin(hp));
846 if ((user = smtp_auth_var("-user", skinned)) != NULL &&
847 (password = smtp_auth_var("-password",
848 skinned)) == NULL)
849 password = getpassword(&otio, &reset_tio, NULL);
851 #endif
853 * Fork, set up the temporary mail file as standard
854 * input for "mail", and exec with the user list we generated
855 * far above.
857 if ((pid = fork()) == -1) {
858 perror("fork");
859 savedeadletter(input);
860 senderr++;
861 return STOP;
863 if (pid == 0) {
864 sigemptyset(&nset);
865 sigaddset(&nset, SIGHUP);
866 sigaddset(&nset, SIGINT);
867 sigaddset(&nset, SIGQUIT);
868 sigaddset(&nset, SIGTSTP);
869 sigaddset(&nset, SIGTTIN);
870 sigaddset(&nset, SIGTTOU);
871 freopen("/dev/null", "r", stdin);
872 if (smtp != NULL) {
873 prepare_child(&nset, 0, 1);
874 if (smtp_mta(smtp, to, input, hp,
875 user, password, skinned) == 0)
876 _exit(0);
877 } else {
878 prepare_child(&nset, fileno(input), -1);
879 if ((cp = value("sendmail")) != NULL)
880 cp = expand(cp);
881 else
882 cp = SENDMAIL;
883 execv(cp, args);
884 perror(cp);
886 savedeadletter(input);
887 fputs(catgets(catd, CATSET, 182,
888 ". . . message not sent.\n"), stderr);
889 _exit(1);
891 if (value("verbose") != NULL || value("sendwait") || debug
892 || value("debug")) {
893 if (wait_child(pid) == 0)
894 ok = OKAY;
895 else
896 senderr++;
897 } else {
898 ok = OKAY;
899 free_child(pid);
901 return ok;
905 * Record outgoing mail if instructed to do so.
907 static enum okay
908 mightrecord(FILE *fp, struct name *to, int recipient_record)
910 char *cp, *cq, *ep;
912 if (recipient_record) {
913 cq = skin(to->n_name);
914 cp = salloc(strlen(cq) + 1);
915 strcpy(cp, cq);
916 for (cq = cp; *cq && *cq != '@'; cq++);
917 *cq = '\0';
918 } else
919 cp = value("record");
920 if (cp != NULL) {
921 ep = expand(cp);
922 if (value("outfolder") && *ep != '/' && *ep != '+' &&
923 which_protocol(ep) == PROTO_FILE) {
924 cq = salloc(strlen(cp) + 2);
925 cq[0] = '+';
926 strcpy(&cq[1], cp);
927 cp = cq;
928 ep = expand(cp);
930 if (savemail(ep, fp) != 0) {
931 fprintf(stderr,
932 "Error while saving message to %s - "
933 "message not sent\n", ep);
934 rewind(fp);
935 exit_status |= 1;
936 savedeadletter(fp);
937 return STOP;
940 return OKAY;
944 * Mail a message on standard input to the people indicated
945 * in the passed header. (Internal interface).
947 enum okay
948 mail1(struct header *hp, int printheaders, struct message *quote,
949 char *quotefile, int recipient_record, int doprefix, int tflag,
950 int Eflag)
952 struct name *to;
953 FILE *mtf, *nmtf;
954 enum okay ok = STOP;
955 int dosign = -1;
956 char *charsets, *ncs = NULL, *cp;
958 #ifdef notdef
959 if ((hp->h_to = checkaddrs(hp->h_to)) == NULL) {
960 senderr++;
961 return STOP;
963 #endif
964 if ((cp = value("autocc")) != NULL && *cp)
965 hp->h_cc = cat(hp->h_cc, checkaddrs(sextract(cp, GCC|GFULL)));
966 if ((cp = value("autobcc")) != NULL && *cp)
967 hp->h_bcc = cat(hp->h_bcc,
968 checkaddrs(sextract(cp, GBCC|GFULL)));
970 * Collect user's mail from standard input.
971 * Get the result as mtf.
973 if ((mtf = collect(hp, printheaders, quote, quotefile, doprefix,
974 tflag)) == NULL)
975 return STOP;
976 if (value("interactive") != NULL) {
977 if (((value("bsdcompat") || value("askatend"))
978 && (value("askcc") != NULL ||
979 value("askbcc") != NULL)) ||
980 value("askattach") != NULL ||
981 value("asksign") != NULL) {
982 if (value("askcc") != NULL)
983 grabh(hp, GCC, 1);
984 if (value("askbcc") != NULL)
985 grabh(hp, GBCC, 1);
986 if (value("askattach") != NULL)
987 hp->h_attach = edit_attachments(hp->h_attach);
988 if (value("asksign") != NULL)
989 dosign = yorn("Sign this message (y/n)? ");
990 } else {
991 printf(catgets(catd, CATSET, 183, "EOT\n"));
992 fflush(stdout);
995 if (fsize(mtf) == 0) {
996 if (Eflag)
997 goto out;
998 if (hp->h_subject == NULL)
999 printf(catgets(catd, CATSET, 184,
1000 "No message, no subject; hope that's ok\n"));
1001 else if (value("bsdcompat") || value("bsdmsgs"))
1002 printf(catgets(catd, CATSET, 185,
1003 "Null message body; hope that's ok\n"));
1005 if (dosign < 0) {
1006 if (value("smime-sign") != NULL)
1007 dosign = 1;
1008 else
1009 dosign = 0;
1012 * Now, take the user names from the combined
1013 * to and cc lists and do all the alias
1014 * processing.
1016 senderr = 0;
1017 if ((to = usermap(cat(hp->h_bcc, cat(hp->h_to, hp->h_cc)))) == NULL) {
1018 printf(catgets(catd, CATSET, 186, "No recipients specified\n"));
1019 senderr++;
1021 to = fixhead(hp, to);
1022 if (hp->h_charset) {
1023 wantcharset = hp->h_charset;
1024 goto try;
1026 hloop: wantcharset = NULL;
1027 if ((charsets = value("sendcharsets")) != NULL) {
1028 wantcharset = savestr(charsets);
1029 loop: if ((ncs = strchr(wantcharset, ',')) != NULL)
1030 *ncs++ = '\0';
1032 try: if ((nmtf = infix(hp, mtf, dosign)) == NULL) {
1033 if (hp->h_charset && (errno == EILSEQ || errno == EINVAL)) {
1034 rewind(mtf);
1035 hp->h_charset = NULL;
1036 goto hloop;
1038 if (errno == EILSEQ || errno == EINVAL) {
1039 if (ncs && *ncs) {
1040 rewind(mtf);
1041 wantcharset = ncs;
1042 goto loop;
1044 if (wantcharset && value("interactive") == NULL) {
1045 if (wantcharset == (char *)-1)
1046 wantcharset = NULL;
1047 else {
1048 rewind(mtf);
1049 wantcharset = (char *)-1;
1050 goto try;
1054 /* fprintf(stderr, ". . . message lost, sorry.\n"); */
1055 perror("");
1056 fail: senderr++;
1057 rewind(mtf);
1058 savedeadletter(mtf);
1059 fputs(catgets(catd, CATSET, 187,
1060 ". . . message not sent.\n"), stderr);
1061 return STOP;
1063 mtf = nmtf;
1064 if (dosign) {
1065 if ((nmtf = smime_sign(mtf, hp)) == NULL)
1066 goto fail;
1067 Fclose(mtf);
1068 mtf = nmtf;
1071 * Look through the recipient list for names with /'s
1072 * in them which we write to as files directly.
1074 to = outof(to, mtf, hp);
1075 if (senderr)
1076 savedeadletter(mtf);
1077 to = elide(to);
1078 if (count(to) == 0) {
1079 if (senderr == 0)
1080 ok = OKAY;
1081 goto out;
1083 if (mightrecord(mtf, to, recipient_record) != OKAY)
1084 goto out;
1085 ok = transfer(to, hp->h_smopts, mtf, hp);
1086 out:
1087 Fclose(mtf);
1088 return ok;
1092 * Create a Message-Id: header field.
1093 * Use either the host name or the from address.
1095 static void
1096 message_id(FILE *fo, struct header *hp)
1098 char *cp;
1099 time_t now;
1101 time(&now);
1102 if ((cp = value("hostname")) != NULL)
1103 fprintf(fo, "Message-ID: <%lx.%s@%s>\n",
1104 (long)now, getrandstring(24), cp);
1105 else if ((cp = skin(myorigin(hp))) != NULL && strchr(cp, '@') != NULL)
1106 fprintf(fo, "Message-ID: <%lx.%s%%%s>\n",
1107 (long)now, getrandstring(16), cp);
1110 static const char *weekday_names[] = {
1111 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
1114 const char *month_names[] = {
1115 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
1116 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL
1120 * Create a Date: header field.
1121 * We compare the localtime() and gmtime() results to get the timezone,
1122 * because numeric timezones are easier to read and because $TZ is
1123 * not set on most GNU systems.
1126 mkdate(FILE *fo, const char *field)
1128 time_t t;
1129 struct tm *tmptr;
1130 int tzdiff, tzdiff_hour, tzdiff_min;
1132 time(&t);
1133 tzdiff = t - mktime(gmtime(&t));
1134 tzdiff_hour = (int)(tzdiff / 60);
1135 tzdiff_min = tzdiff_hour % 60;
1136 tzdiff_hour /= 60;
1137 tmptr = localtime(&t);
1138 if (tmptr->tm_isdst > 0)
1139 tzdiff_hour++;
1140 return fprintf(fo, "%s: %s, %02d %s %04d %02d:%02d:%02d %+05d\n",
1141 field,
1142 weekday_names[tmptr->tm_wday],
1143 tmptr->tm_mday, month_names[tmptr->tm_mon],
1144 tmptr->tm_year + 1900, tmptr->tm_hour,
1145 tmptr->tm_min, tmptr->tm_sec,
1146 tzdiff_hour * 100 + tzdiff_min);
1149 static enum okay
1150 putname(char *line, enum gfield w, enum sendaction action, int *gotcha,
1151 char *prefix, FILE *fo, struct name **xp)
1153 struct name *np;
1155 np = sextract(line, GEXTRA|GFULL);
1156 if (xp)
1157 *xp = np;
1158 if (np == NULL)
1159 return 0;
1160 if (fmt(prefix, np, fo, w&(GCOMMA|GFILES), 0, action != SEND_TODISP))
1161 return 1;
1162 if (gotcha)
1163 (*gotcha)++;
1164 return 0;
1167 #define FMT_CC_AND_BCC { \
1168 if (hp->h_cc != NULL && w & GCC) { \
1169 if (fmt("Cc:", hp->h_cc, fo, \
1170 w&(GCOMMA|GFILES), 0, \
1171 action!=SEND_TODISP)) \
1172 return 1; \
1173 gotcha++; \
1175 if (hp->h_bcc != NULL && w & GBCC) { \
1176 if (fmt("Bcc:", hp->h_bcc, fo, \
1177 w&(GCOMMA|GFILES), 0, \
1178 action!=SEND_TODISP)) \
1179 return 1; \
1180 gotcha++; \
1184 * Dump the to, subject, cc header on the
1185 * passed file buffer.
1188 puthead(struct header *hp, FILE *fo, enum gfield w,
1189 enum sendaction action, enum conversion convert,
1190 char *contenttype, char *charset)
1192 int gotcha;
1193 char *addr/*, *cp*/;
1194 int stealthmua;
1195 struct name *np, *fromfield = NULL, *senderfield = NULL;
1198 if (value("stealthmua"))
1199 stealthmua = 1;
1200 else
1201 stealthmua = 0;
1202 gotcha = 0;
1203 if (w & GDATE) {
1204 mkdate(fo, "Date"), gotcha++;
1206 if (w & GIDENT) {
1207 if (hp->h_from != NULL) {
1208 if (fmt("From:", hp->h_from, fo, w&(GCOMMA|GFILES), 0,
1209 action!=SEND_TODISP))
1210 return 1;
1211 gotcha++;
1212 fromfield = hp->h_from;
1213 } else if ((addr = myaddrs(hp)) != NULL)
1214 if (putname(addr, w, action, &gotcha, "From:", fo,
1215 &fromfield))
1216 return 1;
1217 if (((addr = hp->h_organization) != NULL ||
1218 (addr = value("ORGANIZATION")) != NULL)
1219 && strlen(addr) > 0) {
1220 fwrite("Organization: ", sizeof (char), 14, fo);
1221 if (mime_write(addr, strlen(addr), fo,
1222 action == SEND_TODISP ?
1223 CONV_NONE:CONV_TOHDR,
1224 action == SEND_TODISP ?
1225 TD_ISPR|TD_ICONV:TD_ICONV,
1226 NULL, (size_t)0,
1227 NULL, NULL) == 0)
1228 return 1;
1229 gotcha++;
1230 putc('\n', fo);
1232 if (hp->h_replyto != NULL) {
1233 if (fmt("Reply-To:", hp->h_replyto, fo,
1234 w&(GCOMMA|GFILES), 0,
1235 action!=SEND_TODISP))
1236 return 1;
1237 gotcha++;
1238 } else if ((addr = value("replyto")) != NULL)
1239 if (putname(addr, w, action, &gotcha, "Reply-To:", fo,
1240 NULL))
1241 return 1;
1242 if (hp->h_sender != NULL) {
1243 if (fmt("Sender:", hp->h_sender, fo,
1244 w&(GCOMMA|GFILES), 0,
1245 action!=SEND_TODISP))
1246 return 1;
1247 gotcha++;
1248 senderfield = hp->h_sender;
1249 } else if ((addr = value("sender")) != NULL)
1250 if (putname(addr, w, action, &gotcha, "Sender:", fo,
1251 &senderfield))
1252 return 1;
1253 if (check_from_and_sender(fromfield, senderfield))
1254 return 1;
1256 if (hp->h_to != NULL && w & GTO) {
1257 if (fmt("To:", hp->h_to, fo, w&(GCOMMA|GFILES), 0,
1258 action!=SEND_TODISP))
1259 return 1;
1260 gotcha++;
1262 if (value("bsdcompat") == NULL && value("bsdorder") == NULL)
1263 FMT_CC_AND_BCC
1264 if (hp->h_subject != NULL && w & GSUBJECT) {
1265 fwrite("Subject: ", sizeof (char), 9, fo);
1266 if (ascncasecmp(hp->h_subject, "re: ", 4) == 0) {
1267 fwrite("Re: ", sizeof (char), 4, fo);
1268 if (strlen(hp->h_subject + 4) > 0 &&
1269 mime_write(hp->h_subject + 4,
1270 strlen(hp->h_subject + 4),
1271 fo, action == SEND_TODISP ?
1272 CONV_NONE:CONV_TOHDR,
1273 action == SEND_TODISP ?
1274 TD_ISPR|TD_ICONV:TD_ICONV,
1275 NULL, (size_t)0,
1276 NULL, NULL) == 0)
1277 return 1;
1278 } else if (*hp->h_subject) {
1279 if (mime_write(hp->h_subject,
1280 strlen(hp->h_subject),
1281 fo, action == SEND_TODISP ?
1282 CONV_NONE:CONV_TOHDR,
1283 action == SEND_TODISP ?
1284 TD_ISPR|TD_ICONV:TD_ICONV,
1285 NULL, (size_t)0,
1286 NULL, NULL) == 0)
1287 return 1;
1289 gotcha++;
1290 fwrite("\n", sizeof (char), 1, fo);
1292 if (value("bsdcompat") || value("bsdorder"))
1293 FMT_CC_AND_BCC
1294 if (w & GMSGID && stealthmua == 0)
1295 message_id(fo, hp), gotcha++;
1296 if (hp->h_ref != NULL && w & GREF) {
1297 fmt("References:", hp->h_ref, fo, 0, 1, 0);
1298 if ((np = hp->h_ref) != NULL && np->n_name) {
1299 while (np->n_flink)
1300 np = np->n_flink;
1301 if (mime_name_invalid(np->n_name, 0) == 0) {
1302 fprintf(fo, "In-Reply-To: %s\n", np->n_name);
1303 gotcha++;
1307 if (w & GUA && stealthmua == 0)
1308 fprintf(fo, "User-Agent: S-nail %s\n",
1309 version), gotcha++;
1310 if (w & GMIME) {
1311 fputs("MIME-Version: 1.0\n", fo), gotcha++;
1312 if (hp->h_attach != NULL) {
1313 makeboundary();
1314 fprintf(fo, "Content-Type: multipart/mixed;\n"
1315 " boundary=\"%s\"\n", send_boundary);
1316 } else {
1317 fprintf(fo, "Content-Type: %s", contenttype);
1318 if (charset)
1319 fprintf(fo, "; charset=%s", charset);
1320 fprintf(fo, "\nContent-Transfer-Encoding: %s\n",
1321 getencoding(convert));
1324 if (gotcha && w & GNL)
1325 putc('\n', fo);
1326 return(0);
1330 * Format the given header line to not exceed 72 characters.
1332 static int
1333 fmt(char *str, struct name *np, FILE *fo, int flags, int dropinvalid,
1334 int domime)
1336 int col, len, count = 0;
1337 int is_to = 0, comma;
1339 comma = flags&GCOMMA ? 1 : 0;
1340 col = strlen(str);
1341 if (col) {
1342 fwrite(str, sizeof *str, strlen(str), fo);
1343 if ((flags&GFILES) == 0 &&
1344 col == 3 && asccasecmp(str, "to:") == 0 ||
1345 col == 3 && asccasecmp(str, "cc:") == 0 ||
1346 col == 4 && asccasecmp(str, "bcc:") == 0 ||
1347 col == 10 && asccasecmp(str, "Resent-To:") == 0)
1348 is_to = 1;
1350 for (; np != NULL; np = np->n_flink) {
1351 if (is_to && is_fileaddr(np->n_name))
1352 continue;
1353 if (np->n_flink == NULL)
1354 comma = 0;
1355 if (mime_name_invalid(np->n_name, !dropinvalid)) {
1356 if (dropinvalid)
1357 continue;
1358 else
1359 return 1;
1361 len = strlen(np->n_fullname);
1362 col++; /* for the space */
1363 if (count && col + len + comma > 72 && col > 1) {
1364 fputs("\n ", fo);
1365 col = 1;
1366 } else
1367 putc(' ', fo);
1368 len = mime_write(np->n_fullname,
1369 len, fo,
1370 domime?CONV_TOHDR_A:CONV_NONE,
1371 TD_ICONV, NULL, (size_t)0,
1372 NULL, NULL);
1373 if (comma && !(is_to && is_fileaddr(np->n_flink->n_name)))
1374 putc(',', fo);
1375 col += len + comma;
1376 count++;
1378 putc('\n', fo);
1379 return 0;
1383 * Rewrite a message for resending, adding the Resent-Headers.
1385 static int
1386 infix_resend(FILE *fi, FILE *fo, struct message *mp, struct name *to,
1387 int add_resent)
1389 size_t count;
1390 char *buf = NULL, *cp/*, *cp2*/;
1391 size_t c, bufsize = 0;
1392 struct name *fromfield = NULL, *senderfield = NULL;
1394 count = mp->m_size;
1396 * Write the Resent-Fields.
1398 if (add_resent) {
1399 fputs("Resent-", fo);
1400 mkdate(fo, "Date");
1401 if ((cp = myaddrs(NULL)) != NULL) {
1402 if (putname(cp, GCOMMA, SEND_MBOX, NULL,
1403 "Resent-From:", fo, &fromfield))
1404 return 1;
1406 if ((cp = value("sender")) != NULL) {
1407 if (putname(cp, GCOMMA, SEND_MBOX, NULL,
1408 "Resent-Sender:", fo, &senderfield))
1409 return 1;
1411 #ifdef notdef
1413 * RFC 2822 disallows generation of this field.
1415 cp = value("replyto");
1416 if (cp != NULL) {
1417 if (mime_name_invalid(cp, 1)) {
1418 if (buf)
1419 free(buf);
1420 return 1;
1422 fwrite("Resent-Reply-To: ", sizeof (char),
1423 17, fo);
1424 mime_write(cp, strlen(cp), fo,
1425 CONV_TOHDR_A, TD_ICONV,
1426 NULL, (size_t)0,
1427 NULL, NULL);
1428 putc('\n', fo);
1430 #endif /* notdef */
1431 if (fmt("Resent-To:", to, fo, 1, 1, 0)) {
1432 if (buf)
1433 free(buf);
1434 return 1;
1436 if (value("stealthmua") == NULL) {
1437 fputs("Resent-", fo);
1438 message_id(fo, NULL);
1441 if (check_from_and_sender(fromfield, senderfield))
1442 return 1;
1444 * Write the original headers.
1446 while (count > 0) {
1447 if ((cp = foldergets(&buf, &bufsize, &count, &c, fi)) == NULL)
1448 break;
1449 if (ascncasecmp("status: ", buf, 8) != 0
1450 && strncmp("From ", buf, 5) != 0) {
1451 fwrite(buf, sizeof *buf, c, fo);
1453 if (count > 0 && *buf == '\n')
1454 break;
1457 * Write the message body.
1459 while (count > 0) {
1460 if (foldergets(&buf, &bufsize, &count, &c, fi) == NULL)
1461 break;
1462 if (count == 0 && *buf == '\n')
1463 break;
1464 fwrite(buf, sizeof *buf, c, fo);
1466 if (buf)
1467 free(buf);
1468 if (ferror(fo)) {
1469 perror(catgets(catd, CATSET, 188, "temporary mail file"));
1470 return 1;
1472 return 0;
1475 enum okay
1476 resend_msg(struct message *mp, struct name *to, int add_resent)
1478 FILE *ibuf, *nfo, *nfi;
1479 char *tempMail;
1480 struct header head;
1481 enum okay ok = STOP;
1483 memset(&head, 0, sizeof head);
1484 if ((to = checkaddrs(to)) == NULL) {
1485 senderr++;
1486 return STOP;
1488 if ((nfo = Ftemp(&tempMail, "Rs", "w", 0600, 1)) == NULL) {
1489 senderr++;
1490 perror(catgets(catd, CATSET, 189, "temporary mail file"));
1491 return STOP;
1493 if ((nfi = Fopen(tempMail, "r")) == NULL) {
1494 senderr++;
1495 perror(tempMail);
1496 return STOP;
1498 rm(tempMail);
1499 Ftfree(&tempMail);
1500 if ((ibuf = setinput(&mb, mp, NEED_BODY)) == NULL)
1501 return STOP;
1502 head.h_to = to;
1503 to = fixhead(&head, to);
1504 if (infix_resend(ibuf, nfo, mp, head.h_to, add_resent) != 0) {
1505 senderr++;
1506 rewind(nfo);
1507 savedeadletter(nfi);
1508 fputs(catgets(catd, CATSET, 190,
1509 ". . . message not sent.\n"), stderr);
1510 Fclose(nfo);
1511 Fclose(nfi);
1512 return STOP;
1514 fflush(nfo);
1515 rewind(nfo);
1516 Fclose(nfo);
1517 to = outof(to, nfi, &head);
1518 if (senderr)
1519 savedeadletter(nfi);
1520 to = elide(to);
1521 if (count(to) != 0) {
1522 if (value("record-resent") == NULL ||
1523 mightrecord(nfi, to, 0) == OKAY)
1524 ok = transfer(to, head.h_smopts, nfi, NULL);
1525 } else if (senderr == 0)
1526 ok = OKAY;
1527 Fclose(nfi);
1528 return ok;