]>
diplodocus.org Git - nmh/blob - uip/post.c
18e1a79ebe3cc5eb8722c8e272fbbde5b805ce94
1 /* post.c -- enter messages into the mail transport system
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
9 #include "sbr/print_version.h"
10 #include "sbr/print_help.h"
11 #include "sbr/arglist.h"
12 #include "sbr/error.h"
14 #include "h/signals.h"
15 #include "h/addrsbr.h"
16 #include "h/aliasbr.h"
17 #include "h/dropsbr.h"
23 #include "sbr/m_mktemp.h"
24 #include "sbr/message_id.h"
26 #ifdef HAVE_SYS_TIME_H
27 # include <sys/time.h>
31 #include "mts/smtp/smtp.h"
34 # define SASLminc(a) (a)
35 #else /* CYRUS_SASL */
36 # define SASLminc(a) 0
37 #endif /* CYRUS_SASL */
40 # define TLSminc(a) (a)
41 #else /* TLS_SUPPORT */
43 #endif /* TLS_SUPPORT */
46 # define OAUTHminc(a) (a)
47 #else /* OAUTH_SUPPORT */
48 # define OAUTHminc(a) 0
49 #endif /* OAUTH_SUPPORT */
51 #define FCCS 10 /* max number of fccs allowed */
53 /* In the following array of structures, the numeric second field of the
54 structures (minchars) is apparently used like this:
56 -# : Switch can be abbreviated to # characters; switch hidden in -help.
57 0 : Switch can't be abbreviated; switch shown in -help.
58 # : Switch can be abbreviated to # characters; switch shown in -help. */
60 #define POST_SWITCHES \
61 X("alias aliasfile", 0, ALIASW) \
62 X("check", -5, CHKSW) /* interface from whom */ \
63 X("nocheck", -7, NCHKSW) /* interface from whom */ \
64 X("debug", -5, DEBUGSW) \
65 X("dist", -4, DISTSW) /* interface from dist */ \
66 X("filter filterfile", 0, FILTSW) \
67 X("nofilter", 0, NFILTSW) \
68 X("format", 0, FRMTSW) \
69 X("noformat", 0, NFRMTSW) \
70 X("library directory", -7, LIBSW) /* interface from send, whom */ \
71 X("mime", 0, MIMESW) \
72 X("nomime", 0, NMIMESW) \
73 X("msgid", 0, MSGDSW) \
74 X("nomsgid", 0, NMSGDSW) \
75 X("verbose", 0, VERBSW) \
76 X("noverbose", 0, NVERBSW) \
77 X("watch", 0, WATCSW) \
78 X("nowatch", 0, NWATCSW) \
79 X("whom", -4, WHOMSW) /* interface from whom */ \
80 X("width columns", 0, WIDTHSW) \
81 X("version", 0, VERSIONSW) \
82 X("help", 0, HELPSW) \
83 X("dashstuffing", -12, BITSTUFFSW) /* should we dashstuff BCC messages? */ \
84 X("nodashstuffing", -14, NBITSTUFFSW) \
85 X("idanno number", -6, ANNOSW) /* interface from send */ \
86 X("client host", -6, CLIESW) \
87 X("server host", 6, SERVSW) /* specify alternate SMTP server */ \
88 X("snoop", -5, SNOOPSW) /* snoop the SMTP transaction */ \
89 X("partno", -6, PARTSW) \
90 X("sasl", SASLminc(4), SASLSW) \
91 X("nosasl", SASLminc(6), NOSASLSW) \
92 X("saslmech", SASLminc(5), SASLMECHSW) \
93 X("user", SASLminc(-4), USERSW) \
94 X("port server submission port name/number", 4, PORTSW) \
95 X("tls", TLSminc(-3), TLSSW) \
96 X("initialtls", TLSminc(-10), INITTLSSW) \
97 X("notls", TLSminc(-5), NTLSSW) \
98 X("certverify", TLSminc(-10), CERTVERSW) \
99 X("nocertverify", TLSminc(-12), NOCERTVERSW) \
100 X("fileproc", -4, FILEPROCSW) \
101 X("mhlproc", -3, MHLPROCSW) \
102 X("sendmail program", 0, MTSSM) \
103 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
104 X("credentials legacy|file:filename", 0, CREDENTIALSSW) \
105 X("messageid localname|random", 2, MESSAGEIDSW) \
106 X("authservice auth-service-name", OAUTHminc(-11), AUTHSERVICESW) \
107 X("oauthcredfile credential-file", OAUTHminc(-7), OAUTHCREDFILESW) \
108 X("oauthclientid client-id", OAUTHminc(-12), OAUTHCLIDSW) \
109 X("oauthclientsecret client-secret", OAUTHminc(-12), OAUTHCLSECSW) \
110 X("oauthauthendpoint authentication-endpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
111 X("oauthredirect redirect-uri", OAUTHminc(-6), OAUTHREDIRSW) \
112 X("oauthtokenendpoint token-endpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
113 X("oauthscope scope", OAUTHminc(-6), OAUTHSCOPESW) \
115 #define X(sw, minchars, id) id,
116 DEFINE_SWITCH_ENUM(POST
);
119 #define X(sw, minchars, id) { sw, minchars, id },
120 DEFINE_SWITCH_ARRAY(POST
, switches
);
125 * Mapping between command-line switches and profile entries, communicated
126 * from 'send'. We use a service name of 'post' internally.
130 const char *profname
;
133 } oauthswitches
[] = {
134 { "oauth-%s-credential-file", OAUTHCREDFILESW
, NULL
},
135 { "oauth-%s-client_id", OAUTHCLIDSW
, NULL
},
136 { "oauth-%s-client_secret", OAUTHCLSECSW
, NULL
},
137 { "oauth-%s-auth_endpoint", OAUTHAUTHENDSW
, NULL
},
138 { "oauth-%s-redirect_uri", OAUTHREDIRSW
, NULL
},
139 { "oauth-%s-token_endpoint", OAUTHTOKENDSW
, NULL
},
140 { "oauth-%s-scope", OAUTHSCOPESW
, NULL
},
151 * flags for headers->flags
153 #define HNOP 0x0000 /* just used to keep .set around */
154 #define HBAD 0x0001 /* bad header - don't let it through */
155 #define HADR 0x0002 /* header has an address field */
156 #define HSUB 0x0004 /* Subject: header */
157 #define HTRY 0x0008 /* try to send to addrs on header */
158 #define HBCC 0x0010 /* don't output this header, unless MTS_SENDMAIL_PIPE */
159 #define HMNG 0x0020 /* munge this header */
160 #define HNGR 0x0040 /* no groups allowed in this header */
161 #define HFCC 0x0080 /* FCC: type header */
162 #define HNIL 0x0100 /* okay for this header not to have addrs */
163 #define HIGN 0x0200 /* ignore this header */
164 #define HDCC 0x0400 /* another undocumented feature */
165 #define HONE 0x0800 /* Only (zero or) one address allowed */
166 #define HEFM 0x1000 /* Envelope-From: header */
167 #define HMIM 0x2000 /* MIME-Version: header */
168 #define HCTE 0x4000 /* Content-Transfer-Encoding: header */
171 * flags for headers->set
173 #define MFRM 0x0001 /* we've seen a From: */
174 #define MDAT 0x0002 /* we've seen a Date: */
175 #define MRFM 0x0004 /* we've seen a Resent-From: */
176 #define MVIS 0x0008 /* we've seen sighted addrs */
177 #define MINV 0x0010 /* we've seen blind addrs */
178 #define MSND 0x0020 /* we've seen a Sender: */
179 #define MRSN 0x0040 /* We've seen a Resent-Sender: */
180 #define MEFM 0x0080 /* We've seen Envelope-From: */
181 #define MMIM 0x0100 /* We've seen Mime-Version: */
183 static struct headers NHeaders
[] = {
184 { "Return-Path", HBAD
, 0 },
185 { "Received", HBAD
, 0 },
186 { "Reply-To", HADR
|HNGR
, 0 },
187 { "From", HADR
|HNGR
, MFRM
},
188 { "Sender", HADR
|HNGR
|HONE
, MSND
},
190 { "Subject", HSUB
, 0 },
191 { "To", HADR
|HTRY
, MVIS
},
192 { "cc", HADR
|HTRY
, MVIS
},
193 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, MINV
},
194 { "Dcc", HADR
|HTRY
|HDCC
|HNIL
, MVIS
}, /* sorta cc & bcc combined */
195 { "Message-ID", HBAD
, 0 },
197 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
198 { "MIME-Version", HMIM
, MMIM
},
199 { "Content-Transfer-Encoding", HCTE
, 0 },
203 static struct headers RHeaders
[] = {
204 { "Resent-Reply-To", HADR
|HNGR
, 0 },
205 { "Resent-From", HADR
|HNGR
, MRFM
},
206 { "Resent-Sender", HADR
|HNGR
, MRSN
},
207 { "Resent-Date", HBAD
, 0 },
208 { "Resent-Subject", HSUB
, 0 },
209 { "Resent-To", HADR
|HTRY
, MVIS
},
210 { "Resent-cc", HADR
|HTRY
, MVIS
},
211 { "Resent-Bcc", HADR
|HTRY
|HBCC
, MINV
},
212 { "Resent-Message-ID", HBAD
, 0 },
213 { "Resent-Fcc", HFCC
, 0 },
214 { "Reply-To", HADR
, 0 },
215 { "From", HADR
|HNGR
, MFRM
},
216 { "Sender", HADR
|HNGR
, MSND
},
217 { "Date", HNOP
, MDAT
},
218 { "To", HADR
|HNIL
, 0 },
219 { "cc", HADR
|HNIL
, 0 },
220 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, 0 },
222 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
223 { "MIME-Version", HMIM
, MMIM
},
224 { "Content-Transfer-Encoding", HCTE
, 0 },
228 static short fccind
= 0; /* index into fccfold[] */
229 static short outputlinelen
= OUTPUTLINELEN
;
231 static int pfd
= NOTOK
; /* fd to write annotation list to */
232 static bool recipients
; /* how many people will get a copy */
233 static int unkadr
= 0; /* how many of those were unknown */
234 static int badadr
= 0; /* number of bad addrs */
235 static bool badmsg
; /* message has bad semantics */
236 static bool verbose
; /* spell it out */
237 static bool format
= true; /* format addresses */
238 static bool mime
; /* use MIME-style encapsulations for Bcc */
239 static bool msgid
; /* add msgid */
240 static bool debug
; /* debugging post */
241 static bool watch
; /* watch the delivery process */
242 static bool whomsw
; /* we are whom not post */
243 static bool checksw
; /* whom -check */
244 static int linepos
=0; /* putadr()'s position on the line */
245 static int nameoutput
=0; /* putadr() has output header name */
246 static bool sasl
; /* Use SASL auth for SMTP */
247 static char *saslmech
=NULL
; /* Force use of particular SASL mech */
248 static char *user
=NULL
; /* Authenticate as this user */
249 static char *port
="submission"; /* Name of server port for SMTP submission */
250 static int tlsflag
=0; /* Flags to control TLS settings */
251 static int fromcount
=0; /* Count of addresses on From: header */
252 static bool seensender
; /* Have we seen a Sender: header? */
254 static unsigned msgflags
= 0; /* what we've seen */
258 static int msgstate
= NORMAL
;
260 static time_t tclock
= 0; /* the time we started (more or less) */
262 static SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
264 static char tmpfil
[BUFSIZ
];
265 static char bccfil
[BUFSIZ
];
267 static char from
[BUFSIZ
]; /* my network address */
268 static char sender
[BUFSIZ
]; /* my Sender: header */
269 static char efrom
[BUFSIZ
]; /* my Envelope-From: header */
270 static char fullfrom
[BUFSIZ
]; /* full contents of From header */
271 static char *filter
= NULL
; /* the filter for BCC'ing */
272 static char *subject
= NULL
; /* the subject field for BCC'ing */
273 static char *fccfold
[FCCS
]; /* foldernames for FCC'ing */
274 enum encoding
{ UNKNOWN
= 0, BINARY
= 1, SEVENBIT
= 7, EIGHTBIT
= 8 };
275 static enum encoding cte
= UNKNOWN
;
277 static struct headers
*hdrtab
; /* table for the message we're doing */
279 static struct mailname localaddrs
; /* local addrs */
280 static struct mailname netaddrs
; /* network addrs */
281 static struct mailname uuaddrs
; /* uucp addrs */
282 static struct mailname tmpaddrs
; /* temporary queue */
285 static char *clientsw
= NULL
;
286 static char *serversw
= NULL
;
288 static char prefix
[] = "----- =_aaaaaaaaaa";
290 static char *partno
= NULL
;
295 static void putfmt (char *, char *, int *, FILE *);
296 static void start_headers (void);
297 static void finish_headers (FILE *);
298 static int get_header (char *, struct headers
*) PURE
;
299 static int putadr (char *, char *, struct mailname
*, FILE *, unsigned int,
300 char *, unsigned int);
301 static void putgrp (char *, char *, FILE *, unsigned int);
302 static int insert (struct mailname
*);
303 static void pl (void);
304 static void anno (void);
305 static int annoaux (struct mailname
*);
306 static void insert_fcc (struct headers
*, char *);
307 static void make_bcc_file (int);
308 static void verify_all_addresses (int, int, char *, int, char *);
309 static void chkadr (void) PURE
;
310 static void sigon (void);
311 static void sigoff (void);
312 static void p_refile (char *);
313 static void fcc (char *, char *);
314 static void fatal (char *, char *, ...) CHECK_PRINTF(2, 3);
315 static void post (char *, int, int, int, char *, int, char *);
316 static void do_text (char *file
, int fd
);
317 static void do_an_address (struct mailname
*, int);
318 static void do_addresses (int, int);
319 static int find_prefix (void);
323 main (int argc
, char **argv
)
325 int state
, compnum
, dashstuff
= 0, swnum
;
326 bool oauth_flag
= false;
328 bool noverify
= false;
329 int eai
= 0; /* use Email Address Internationalization (EAI) (SMTPUTF8) */
330 char *cp
, *msg
= NULL
, **argp
, **arguments
, *envelope
;
331 char buf
[NMH_BUFSIZ
], name
[NAMESZ
], *auth_svc
= NULL
;
333 m_getfld_state_t gstate
;
335 if (nmh_init(argv
[0], false, false)) { return 1; }
338 arguments
= getarguments (invo_name
, argc
, argv
, 0);
341 while ((cp
= *argp
++)) {
343 switch ((swnum
= smatch (++cp
, switches
))) {
345 ambigsw (cp
, switches
);
348 die("-%s unknown", cp
);
351 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
352 print_help (buf
, switches
, 0);
355 print_version(invo_name
);
359 if (!(cp
= *argp
++) || *cp
== '-')
360 die("missing argument to %s", argp
[-2]);
361 /* create a minimal context */
362 if (context_foil (cp
) == -1)
367 if (!(cp
= *argp
++) || *cp
== '-')
368 die("missing argument to %s", argp
[-2]);
369 if ((state
= alias (cp
)) != AK_OK
)
370 die("aliasing error in %s - %s",
371 cp
, akerror (state
));
390 if (!(filter
= *argp
++) || *filter
== '-')
391 die("missing argument to %s", argp
[-2]);
446 if (!(cp
= *argp
++) || *cp
== '-')
447 die("missing argument to %s", argp
[-2]);
448 if ((outputlinelen
= atoi (cp
)) < 10)
449 die("impossible width %d", outputlinelen
);
453 if (!(cp
= *argp
++) || *cp
== '-')
454 die("missing argument to %s", argp
[-2]);
455 if ((pfd
= atoi (cp
)) <= 2)
456 die("bad argument %s %s", argp
[-2], cp
);
460 if (!(clientsw
= *argp
++) || *clientsw
== '-')
461 die("missing argument to %s", argp
[-2]);
464 if (!(serversw
= *argp
++) || *serversw
== '-')
465 die("missing argument to %s", argp
[-2]);
472 if (!(partno
= *argp
++) || *partno
== '-')
473 die("missing argument to %s", argp
[-2]);
485 if (!(saslmech
= *argp
++) || *saslmech
== '-')
486 die("missing argument to %s", argp
[-2]);
490 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
491 die("missing argument to %s", argp
[-2]);
495 case OAUTHCREDFILESW
:
505 if (!(cp
= *argp
++) || *cp
== '-')
506 die("missing argument to %s", argp
[-2]);
508 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
509 if (oauthswitches
[i
].switchnum
== swnum
) {
510 oauthswitches
[i
].value
= cp
;
515 if (oauthswitches
[i
].profname
== NULL
)
516 die("internal error: cannot map switch %s "
517 "to profile entry", argp
[-2]);
524 if (!(user
= *argp
++) || *user
== '-')
525 die("missing argument to %s", argp
[-2]);
529 if (!(port
= *argp
++) || *port
== '-')
530 die("missing argument to %s", argp
[-2]);
554 if (!(cp
= *argp
++) || *cp
== '-')
555 die("missing argument to %s", argp
[-2]);
560 if (!(cp
= *argp
++) || *cp
== '-')
561 die("missing argument to %s", argp
[-2]);
566 if (!(cp
= *argp
++) || *cp
== '-')
567 die("missing argument to %s", argp
[-2]);
572 if (!(cp
= *argp
++) || *cp
== '-')
573 die("missing argument to %s", argp
[-2]);
574 save_mts_method (cp
);
577 case CREDENTIALSSW
: {
578 if (!(cp
= *argp
++) || *cp
== '-')
579 die("missing argument to %s", argp
[-2]);
580 add_profile_entry ("credentials", cp
);
585 if (!(cp
= *argp
++) || *cp
== '-')
586 die("missing argument to %s", argp
[-2]);
587 if (save_message_id_style (cp
) != 0)
588 die("unsupported messageid \"%s\"", cp
);
593 die("only one message at a time!");
600 die("usage: %s [switches] file", invo_name
);
602 if (outputlinelen
< 10)
603 die("impossible width %d", outputlinelen
);
605 if ((in
= fopen (msg
, "r")) == NULL
)
606 adios (msg
, "unable to open");
614 if ((out
= fopen ("/dev/null", "w")) == NULL
)
615 adios ("/dev/null", "unable to open");
617 char *cp
= m_mktemp2(NULL
, invo_name
, NULL
, &out
);
619 die("unable to create temporary file in %s",
622 strncpy(tmpfil
, cp
, sizeof(tmpfil
));
626 hdrtab
= msgstate
== NORMAL
? NHeaders
: RHeaders
;
628 gstate
= m_getfld_state_init(in
);
629 for (compnum
= 1;;) {
630 int bufsz
= sizeof buf
;
631 switch (state
= m_getfld2(&gstate
, name
, buf
, &bufsz
)) {
635 cp
= mh_xstrdup(buf
);
636 while (state
== FLDPLUS
) {
638 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
641 putfmt (name
, cp
, &eai
, out
);
646 finish_headers (out
);
649 fprintf (out
, "\n%s", buf
);
650 while (state
== BODY
) {
652 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
658 finish_headers (out
);
663 die("message format error in component #%d", compnum
);
666 die("getfld() returned %d", state
);
670 m_getfld_state_destroy (&gstate
);
683 * Here's how we decide which address to use as the envelope-from
686 * - If we were given an Envelope-From header, use that.
687 * - If we were given a Sender: address, use that.
688 * - Otherwise, use the address on the From: line
691 if (msgflags
& MEFM
) {
693 } else if (seensender
) {
702 * The user didn't specify any of the tls switches. Try to
703 * help them by implying -initialtls if they're using port 465
704 * (smtps, until IANA revoked that registration in 1998).
706 tls
= ! strcmp (port
, "465") || ! strcasecmp (port
, "smtps")
709 #else /* ! TLS_SUPPORT */
711 #endif /* ! TLS_SUPPORT */
715 tlsflag
= S_STARTTLS
;
722 tlsflag
|= S_NOVERIFY
;
725 * If we were given any oauth flags, store the appropriate profile
726 * entries and make sure an authservice was given (we have to do this
727 * here because we aren't guaranteed the authservice will be given on
728 * the command line before the other OAuth flags are given).
735 if (auth_svc
== NULL
) {
736 die("No authentication service given with -authservice");
739 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
740 if (oauthswitches
[i
].value
!= NULL
) {
741 snprintf(sbuf
, sizeof(sbuf
),
742 oauthswitches
[i
].profname
, auth_svc
);
743 sbuf
[sizeof(sbuf
) - 1] = '\0';
744 add_profile_entry(sbuf
, oauthswitches
[i
].value
);
749 /* If we are doing a "whom" check */
751 /* This won't work with MTS_SENDMAIL_PIPE. */
752 verify_all_addresses (1, eai
, envelope
, oauth_flag
, auth_svc
);
756 if (msgflags
& MINV
) {
757 make_bcc_file (dashstuff
);
758 if (msgflags
& MVIS
) {
759 if (sm_mts
!= MTS_SENDMAIL_PIPE
) {
760 /* It would be nice to have support to call
761 verify_all_addresses with MTS_SENDMAIL_PIPE, but
762 that might require running sendmail as root. Note
763 that spost didn't verify addresses. */
764 verify_all_addresses (verbose
, eai
, envelope
, oauth_flag
,
767 post (tmpfil
, 0, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
769 post (bccfil
, 1, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
770 (void) m_unlink (bccfil
);
772 post (tmpfil
, 0, isatty (1), eai
, envelope
, oauth_flag
, auth_svc
);
776 (void) m_unlink (tmpfil
);
780 printf ("Partial Message #%s Processed\n", partno
);
782 puts("Message Processed");
795 putfmt (char *name
, char *str
, int *eai
, FILE *out
)
801 char namep
[BUFSIZ
], error
[BUFSIZ
];
802 char *savehdr
= NULL
;
803 unsigned int savehdrlen
= 0;
804 struct mailname
*mp
= NULL
, *np
= NULL
;
807 while (*str
== ' ' || *str
== '\t')
810 if (msgstate
== NORMAL
&& uprf (name
, "resent")) {
811 inform("illegal header line -- %s:", name
);
817 /* Check each header field value to see if it has any 8-bit characters.
818 If it does, enable EAI support. */
819 if (contains8bit(str
, NULL
)) {
821 puts("EAI/SMTPUTF8 enabled");
824 /* Enable SMTPUTF8. */
827 /* Enable passing of utf-8 setting to getname()/getadrx(). */
832 if ((i
= get_header (name
, hdrtab
)) == NOTOK
) {
833 if (strncasecmp (name
, "nmh-", 4)) {
834 fprintf (out
, "%s: %s", name
, str
);
836 /* Filter out all Nmh-* headers, because Norm asked. They
837 should never have reached this point. Warn about any
838 that are non-empty. */
839 if (strcmp (str
, "\n")) {
840 trim_suffix_c(str
, '\n');
842 inform("ignoring header line -- %s: %s", name
, str
);
851 if (hdr
->flags
& HIGN
) {
854 if (hdr
->flags
& HBAD
) {
855 inform("illegal header line -- %s:", name
);
859 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
861 if (hdr
->flags
& HSUB
)
862 subject
= subject
? add (str
, add ("\t", subject
)) : mh_xstrdup(str
);
863 if (hdr
->flags
& HFCC
) {
864 if ((cp
= strrchr(str
, '\n')))
866 for (pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
868 insert_fcc (hdr
, pp
);
870 insert_fcc (hdr
, pp
);
873 if (hdr
->flags
& HCTE
) {
874 if (strncasecmp (str
, "7bit", 4) == 0) {
876 } else if (strncasecmp (str
, "8bit", 4) == 0) {
878 } else if (strncasecmp (str
, "binary", 6) == 0) {
882 if (!(hdr
->flags
& HADR
)) {
883 fprintf (out
, "%s: %s", name
, str
);
888 * If this is a From:/Resent-From: header, save the full thing for
889 * later in case we need it for use when constructing a Bcc draft message.
890 * Because we want to capture the results of alias expansion, save
891 * the output from putadr().
894 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
897 savehdrlen
= sizeof(fullfrom
);
900 tmpaddrs
.m_next
= NULL
;
902 for (count
= 0; (cp
= getname (str
)); count
++) {
903 if ((mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
907 tmpaddrs
.m_next
= mp
;
911 admonish(cp
, "%s", error
);
912 if (hdr
->flags
& HTRY
)
920 if (hdr
->flags
& HNIL
)
921 fprintf (out
, "%s: %s", name
, str
);
924 * Sender (or Resent-Sender) can have only one address
926 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
927 : (hdr
->set
& MSND
)) {
928 inform("%s: field requires one address", name
);
932 inform("%s: field requires at least one address", name
);
939 if (count
> 1 && (hdr
->flags
& HONE
)) {
940 inform("%s: field only permits one address", name
);
945 nameoutput
= linepos
= 0;
946 snprintf (namep
, sizeof(namep
), "%s%s",
947 (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
949 for (grp
= false, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
950 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
951 /* The address doesn't include a host, so it might be an alias. */
952 pp
= akvalue (mp
->m_mbox
); /* do mh alias substitution */
953 qp
= akvisible () ? mp
->m_mbox
: "";
956 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
957 while ((cp
= getname (pp
))) {
958 if (!(mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
959 admonish(cp
, "%s", error
);
965 * If it's a From: or Resent-From: header, save the address
966 * for later possible use (as the envelope address for SMTP)
969 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
970 : (hdr
->set
& MFRM
)) {
971 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
972 from
[sizeof(from
) - 1] = '\0';
977 * Also save the Sender: or Resent-Sender: header as well
980 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
981 : (hdr
->set
& MSND
)) {
982 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
983 sender
[sizeof(sender
) - 1] = '\0';
988 * ALSO ... save Envelope-From
991 if (hdr
->set
& MEFM
) {
992 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
993 efrom
[sizeof(efrom
) - 1] = '\0';
996 if (hdr
->flags
& HBCC
)
999 mp
->m_ingrp
= np
->m_ingrp
;
1000 else if (mp
->m_gname
)
1001 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1003 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1004 /* Catch this before sendmail chokes with:
1005 "553 List:; syntax illegal for recipient
1007 If we wanted to, we could expand out blind
1008 aliases and put them in Bcc:, but then
1009 they'd have the Blind-Carbon-Copy
1011 die( "blind lists not compatible with"
1017 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
, savehdr
,
1019 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1028 /* Address includes a host, so no alias substitution is needed. */
1031 * If it's a From: or Resent-From header, save the address
1032 * for later possible use (as the envelope address for SMTP)
1035 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
1036 : (hdr
->set
& MFRM
)) {
1037 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
1042 * Also save the Sender: header as well
1045 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
1046 : (hdr
->set
& MSND
)) {
1047 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
1048 sender
[sizeof(sender
) - 1] = '\0';
1053 * ALSO ... save Envelope-From
1056 if (hdr
->set
& MEFM
) {
1057 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1058 efrom
[sizeof(efrom
) - 1] = '\0';
1061 if (hdr
->flags
& HBCC
)
1064 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1067 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
, savehdr
, savehdrlen
);
1071 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1078 * If it was a From header, strip off any trailing newlines from
1079 * the alias-expanded From line.
1082 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
1083 while (*fullfrom
&& fullfrom
[strlen(fullfrom
) - 1] == '\n') {
1084 fullfrom
[strlen(fullfrom
) - 1] = '\0';
1088 if (grp
&& (hdr
->flags
& HNGR
)) {
1089 inform("%s: field does not allow groups", name
);
1099 start_headers (void)
1104 * Probably not necessary, but just in case ...
1115 * Now that we've outputted the header fields in the draft
1116 * message, we will now output any remaining header fields
1117 * that we need to add/create.
1121 finish_headers (FILE *out
)
1125 if (!(msgflags
& MFRM
)) {
1127 * A From: header is now required in the draft.
1129 inform("message has no From: header");
1130 inform("See default components files for examples");
1135 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1136 inform("A Sender: or Envelope-From: header is required "
1137 "with multiple\nFrom: addresses");
1145 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1147 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1149 * If we have multiple From: addresses, make sure we have an
1150 * Sender: header. If we don't have one, then generate one
1151 * from Envelope-From: (which in this case, cannot be blank)
1154 if (fromcount
> 1 && !seensender
) {
1155 if (efrom
[0] == '\0') {
1156 inform("Envelope-From cannot be blank when there "
1157 "is multiple From: addresses\nand no Sender: "
1161 fprintf (out
, "Sender: %s\n", efrom
);
1165 if (!(msgflags
& MVIS
))
1166 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
1170 if (!(msgflags
& MDAT
)) {
1171 inform("message has no Date: header");
1174 if (!(msgflags
& MFRM
)) {
1175 inform("message has no From: header");
1178 if (!(msgflags
& MRFM
)) {
1179 inform("message has no Resent-From: header");
1180 inform("See default components files for examples");
1184 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1185 inform("A Resent-Sender: or Envelope-From: header is "
1186 "required with multiple\nResent-From: addresses");
1194 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
1196 fprintf (out
, "Resent-Message-ID: %s\n",
1197 message_id (tclock
, 0));
1199 * If we have multiple Resent-From: addresses, make sure we have an
1200 * Resent-Sender: header. If we don't have one, then generate one
1201 * from Envelope-From (which in this case, cannot be blank)
1204 if (fromcount
> 1 && !seensender
) {
1205 if (efrom
[0] == '\0') {
1206 inform("Envelope-From cannot be blank when there "
1207 "is multiple Resent-From: addresses and no "
1208 "Resent-Sender: header");
1211 fprintf (out
, "Resent-Sender: %s\n", efrom
);
1215 if (!(msgflags
& MVIS
))
1216 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
1221 die("re-format message and try again");
1223 die("no addressees");
1228 get_header (char *header
, struct headers
*table
)
1232 header
= FENDNULL(header
);
1233 for (h
= table
; h
->value
; h
++)
1234 if (!strcasecmp(FENDNULL(h
->value
), header
))
1242 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
,
1243 unsigned int flags
, char *savehdr
, unsigned int savehdrsize
)
1246 bool saveappend
= false;
1249 char buffer
[BUFSIZ
];
1251 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
1253 if (sm_mts
!= MTS_SENDMAIL_PIPE
&&
1254 ((flags
& (HBCC
| HDCC
| HEFM
)) || mp
->m_ingrp
))
1258 fprintf (out
, "%s: ", name
);
1259 linepos
+= (nameoutput
= strlen (name
) + 2);
1263 shlen
= strlen(savehdr
);
1267 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
1268 mp
->m_pers
= mh_xstrdup(aka
);
1271 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
1274 cp
= adrformat (mp
);
1281 if (linepos
!= nameoutput
) {
1282 if (len
+ linepos
+ 2 > outputlinelen
) {
1283 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
1285 if (shlen
+ 2 + nameoutput
+ len
>= savehdrsize
) {
1288 snprintf(savehdr
+ shlen
, savehdrsize
- shlen
, ",\n%*s",
1296 if (shlen
+ 2 + len
>= savehdrsize
) {
1299 strncat(savehdr
, ", ", savehdrsize
- shlen
);
1307 if (saveappend
&& shlen
+ len
< savehdrsize
)
1308 strncat(savehdr
, cp
, savehdrsize
- shlen
+ len
);
1312 return flags
& HTRY
;
1317 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
1322 if (sm_mts
!= MTS_SENDMAIL_PIPE
&& (flags
& HBCC
))
1326 fprintf (out
, "%s: ", name
);
1327 linepos
+= (nameoutput
= strlen (name
) + 2);
1330 cp
= concat (group
, ";", NULL
);
1333 if (linepos
> nameoutput
) {
1334 if (len
+ linepos
+ 2 > outputlinelen
) {
1335 fprintf (out
, ",\n%*s", nameoutput
, "");
1336 linepos
= nameoutput
;
1350 insert (struct mailname
*np
)
1352 struct mailname
*mp
;
1354 if (np
->m_mbox
== NULL
)
1357 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1358 : np
->m_type
== UUCPHOST
? &uuaddrs
1362 if (!strcasecmp (FENDNULL(np
->m_host
),
1363 FENDNULL(mp
->m_next
->m_host
)) &&
1364 !strcasecmp (FENDNULL(np
->m_mbox
),
1365 FENDNULL(mp
->m_next
->m_mbox
)) &&
1366 np
->m_bcc
== mp
->m_next
->m_bcc
)
1379 struct mailname
*mp
;
1381 fputs("-------\n\t-- Addresses --\nlocal:\t", stdout
);
1382 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1383 printf ("%s%s%s", mp
->m_mbox
,
1384 mp
->m_bcc
? "[BCC]" : "",
1385 mp
->m_next
? ",\n\t" : "");
1387 fputs("\nnet:\t", stdout
);
1388 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1389 printf ("%s%s@%s%s%s", FENDNULL(mp
->m_path
),
1390 mp
->m_mbox
, mp
->m_host
,
1391 mp
->m_bcc
? "[BCC]" : "",
1392 mp
->m_next
? ",\n\t" : "");
1394 fputs("\nuucp:\t", stdout
);
1395 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1396 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1397 mp
->m_bcc
? "[BCC]" : "",
1398 mp
->m_next
? ",\n\t" : "");
1400 fputs("\n\t-- Folder Copies --\nfcc:\t", stdout
);
1401 for (i
= 0; i
< fccind
; i
++)
1402 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1410 struct mailname
*mp
;
1412 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1413 if (annoaux (mp
) == NOTOK
)
1416 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1417 if (annoaux (mp
) == NOTOK
)
1420 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1421 if (annoaux (mp
) == NOTOK
)
1431 annoaux (struct mailname
*mp
)
1434 char buffer
[BUFSIZ
];
1436 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1437 i
= strlen (buffer
);
1439 return write(pfd
, buffer
, i
) == i
? OK
: NOTOK
;
1444 insert_fcc (struct headers
*hdr
, char *pp
)
1448 for (cp
= pp
; isspace ((unsigned char) *cp
); cp
++)
1450 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace ((unsigned char) *pp
); pp
--)
1458 die("too many %ss", hdr
->value
);
1459 fccfold
[fccind
++] = mh_xstrdup(cp
);
1467 make_bcc_file (int dashstuff
)
1473 char *tfile
= NULL
, *program
;
1475 if ((tfile
= m_mktemp2(NULL
, "bccs", NULL
, &out
)) == NULL
) {
1476 die("unable to create temporary file in %s", get_temp_dir());
1478 strncpy (bccfil
, tfile
, sizeof(bccfil
));
1480 fprintf (out
, "From: %s\n", fullfrom
);
1481 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1483 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1485 fprintf (out
, "Subject: %s", subject
);
1486 fprintf (out
, "BCC:\n");
1489 * Use MIME encapsulation for Bcc messages
1495 * Check if any lines in the message clash with the
1496 * prefix for the MIME multipart separator. If there
1497 * is a clash, increment one of the letters in the
1498 * prefix and check again.
1500 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1501 die("lost prefix start");
1502 while (find_prefix () == NOTOK
) {
1505 else if (*++cp
== 0)
1506 die("can't find a unique delimiter string");
1511 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1512 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1513 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1515 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1521 * Do mhl filtering of Bcc messages instead
1522 * of MIME encapsulation.
1524 if (filter
!= NULL
) {
1528 adios ("fork", "unable to");
1531 dup2 (fileno (out
), 1);
1533 vec
= argsplit(mhlproc
, &program
, &i
);
1534 vec
[i
++] = "-forward";
1539 /* was the flag -[no]dashstuffing specified? */
1541 vec
[i
++] = "-dashstuffing";
1542 else if (dashstuff
< 0)
1543 vec
[i
++] = "-nodashstuffing";
1546 execvp (program
, vec
);
1547 fprintf (stderr
, "unable to exec ");
1552 pidXwait (child_id
, mhlproc
);
1556 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1557 adios (tmpfil
, "unable to re-open");
1560 * If using MIME encapsulation, or if the -nodashstuffing
1561 * flag was given, then just copy message. Else do
1562 * RFC934 quoting (dashstuffing).
1564 if (mime
|| dashstuff
< 0)
1565 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1567 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1571 fseek (out
, 0L, SEEK_END
);
1573 fprintf (out
, "\n--%s--\n", prefix
);
1575 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1581 * Scan message to check if any lines clash with
1582 * the prefix of the MIME multipart separator.
1589 char buffer
[BUFSIZ
];
1592 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1593 adios (tmpfil
, "unable to re-open");
1595 while (fgets (buffer
, sizeof buffer
, in
))
1596 if (buffer
[0] == '-' && buffer
[1] == '-') {
1599 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1600 if (!isspace ((unsigned char) *cp
))
1603 if (strcmp (buffer
+ 2, prefix
) == 0) {
1617 if (badadr
&& unkadr
)
1618 fatal (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1619 badadr
, PLURALS(badadr
), unkadr
, PLURALS(badadr
));
1621 fatal (NULL
, "%d address%s unparsable", badadr
, PLURALS(badadr
));
1623 fatal (NULL
, "%d addressee%s undeliverable", unkadr
, PLURALS(unkadr
));
1628 do_addresses (int bccque
, int talk
)
1632 struct mailname
*lp
;
1635 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1636 if (lp
->m_bcc
? bccque
: !bccque
) {
1638 puts(" -- Local Recipients --");
1639 do_an_address (lp
, talk
);
1644 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1645 if (lp
->m_bcc
? bccque
: !bccque
) {
1647 puts(" -- UUCP Recipients --");
1648 do_an_address (lp
, talk
);
1653 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1654 if (lp
->m_bcc
? bccque
: !bccque
) {
1656 puts(" -- Network Recipients --");
1657 do_an_address (lp
, talk
);
1663 if (rp_isbad (retval
= sm_waend ()))
1664 fatal (NULL
, "problem ending addresses; %s", rp_string (retval
));
1669 * MTS-SPECIFIC INTERACTION
1674 * SENDMAIL/SMTP routines
1678 post (char *file
, int bccque
, int talk
, int eai
, char *envelope
,
1679 int oauth_flag
, char *auth_svc
)
1685 if (msgflags
& MINV
)
1686 printf (" -- Posting for %s Recipients --\n",
1687 bccque
? "Blind" : "Sighted");
1689 puts(" -- Posting for All Recipients --");
1694 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1695 char **argp
, *program
;
1701 adios ("fork", "unable to");
1704 if (freopen( file
, "r", stdin
) == NULL
) {
1705 adios (file
, "can't reopen for sendmail");
1708 argp
= argsplit(sendmail
, &program
, &argc
);
1709 argp
[argc
++] = "-t"; /* read msg for recipients */
1710 argp
[argc
++] = "-i"; /* don't stop on "." */
1712 argp
[argc
++] = "-bv";
1714 argp
[argc
++] = "-v";
1717 execv (program
, argp
);
1718 adios (sendmail
, "can't exec");
1721 pidXwait (child_id
, NULL
);
1725 const int fd
= open (file
, O_RDONLY
);
1729 fatal (file
, "unable to re-open");
1732 if (msgflags
& MMIM
&& cte
!= UNKNOWN
) {
1733 /* MIME message with C-T-E header. (BINARYMIME isn't
1734 supported, use 8BITMIME instead for binary.) */
1735 eightbit
= cte
!= SEVENBIT
;
1737 if (scan_input (fd
, &eightbit
) == NOTOK
) {
1739 fatal (file
, "problem reading from");
1743 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1744 verbose
, snoop
, sasl
, saslmech
, user
,
1745 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1746 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1748 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1751 do_addresses (bccque
, talk
&& verbose
);
1756 sm_end (!(msgflags
& MINV
) || bccque
? OK
: DONE
);
1760 if (msgflags
& MINV
)
1761 printf (" -- %s Recipient Copies Posted --\n",
1762 bccque
? "Blind" : "Sighted");
1764 puts(" -- Recipient Copies Posted --");
1772 /* Address Verification */
1775 verify_all_addresses (int talk
, int eai
, char *envelope
, int oauth_flag
,
1779 struct mailname
*lp
;
1783 if (!whomsw
|| checksw
) {
1784 /* Not sending message body, so don't need to use 8BITMIME. */
1785 const int eightbit
= 0;
1787 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1788 verbose
, snoop
, sasl
, saslmech
, user
,
1789 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1790 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1791 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1795 if (talk
&& !whomsw
)
1796 puts(" -- Address Verification --");
1797 if (talk
&& localaddrs
.m_next
)
1798 puts(" -- Local Recipients --");
1799 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1800 do_an_address (lp
, talk
);
1802 if (talk
&& uuaddrs
.m_next
)
1803 puts(" -- UUCP Recipients --");
1804 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1805 do_an_address (lp
, talk
);
1807 if (talk
&& netaddrs
.m_next
)
1808 puts(" -- Network Recipients --");
1809 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1810 do_an_address (lp
, talk
);
1813 if (talk
&& !whomsw
)
1814 puts(" -- Address Verification Successful --");
1816 if (!whomsw
|| checksw
)
1817 sm_end (whomsw
? OK
: DONE
);
1825 do_an_address (struct mailname
*lp
, int talk
)
1831 switch (lp
->m_type
) {
1835 strncpy (addr
, mbox
, sizeof(addr
));
1839 mbox
= auxformat (lp
, 0);
1841 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1844 default: /* let SendMail decide if the host is bad */
1847 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1852 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1854 if (whomsw
&& !checksw
) {
1859 fputs(": ", stdout
);
1862 switch (retval
= sm_wadr (mbox
, host
,
1863 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1872 fprintf (stderr
, " %s: ", addr
);
1873 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1874 rp_string (retval
));
1880 fprintf (stderr
, " %s: ", addr
);
1881 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1889 do_text (char *file
, int fd
)
1894 lseek(fd
, 0, SEEK_SET
);
1896 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1897 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1898 fatal (NULL
, "problem writing text; %s\n", rp_string (retval
));
1902 fatal (file
, "problem reading from");
1904 switch (retval
= sm_wtend ()) {
1910 fatal (NULL
, "posting failed; %s", rp_string (retval
));
1914 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1928 (void) m_unlink (tmpfil
);
1929 if (msgflags
& MINV
)
1930 (void) m_unlink (bccfil
);
1932 if (!whomsw
|| checksw
)
1945 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1946 istat
= SIGNAL2 (SIGINT
, sigser
);
1947 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1948 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1958 SIGNAL (SIGHUP
, hstat
);
1959 SIGNAL (SIGINT
, istat
);
1960 SIGNAL (SIGQUIT
, qstat
);
1961 SIGNAL (SIGTERM
, tstat
);
1969 p_refile (char *file
)
1977 puts(" -- Filing Folder Copies --");
1978 for (i
= 0; i
< fccind
; i
++)
1979 fcc (file
, fccfold
[i
]);
1981 puts(" -- Folder Copies Filed --");
1986 * Call the `fileproc' to add the file to the folder.
1990 fcc (char *file
, char *folder
)
1995 char **arglist
, *program
;
1998 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
2005 fprintf (stderr
, " %sFcc %s: ",
2006 msgstate
== RESENT
? "Resent-" : "", folder
);
2007 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
2011 /* see if we need to add `+' */
2012 snprintf (fold
, sizeof(fold
), "%s%s",
2013 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
2015 /* now exec the fileproc */
2017 arglist
= argsplit(fileproc
, &program
, &argp
);
2018 arglist
[argp
++] = "-link";
2019 arglist
[argp
++] = "-file";
2020 arglist
[argp
++] = file
;
2021 arglist
[argp
++] = fold
;
2022 arglist
[argp
] = NULL
;
2023 execvp (program
, arglist
);
2027 if ((status
= pidwait (child_id
, OK
))) {
2029 fprintf (stderr
, " %sFcc %s: ",
2030 msgstate
== RESENT
? "Resent-" : "", folder
);
2031 pidstatus (status
, verbose
? stdout
: stderr
, fileproc
);
2046 fatal (char *what
, char *fmt
, ...)
2053 (void) m_unlink (tmpfil
);
2054 if (msgflags
& MINV
)
2055 (void) m_unlink (bccfil
);
2057 if (!whomsw
|| checksw
)
2062 advertise (what
, NULL
, fmt
, ap
);