]>
diplodocus.org Git - nmh/blob - uip/post.c
2 * post.c -- enter messages into the mail transport system
4 * This code is Copyright (c) 2002, by the authors of nmh. See the
5 * COPYRIGHT file in the root directory of the nmh distribution for
6 * complete copyright information.
11 #include <h/signals.h>
12 #include <h/addrsbr.h>
13 #include <h/aliasbr.h>
14 #include <h/dropsbr.h>
20 #ifdef HAVE_SYS_TIME_H
21 # include <sys/time.h>
25 #include <mts/smtp/smtp.h>
28 # define SASLminc(a) (a)
29 #else /* CYRUS_SASL */
30 # define SASLminc(a) 0
31 #endif /* CYRUS_SASL */
34 # define TLSminc(a) (a)
35 #else /* TLS_SUPPORT */
37 #endif /* TLS_SUPPORT */
40 # define OAUTHminc(a) (a)
41 #else /* OAUTH_SUPPORT */
42 # define OAUTHminc(a) 0
43 #endif /* OAUTH_SUPPORT */
45 #define FCCS 10 /* max number of fccs allowed */
47 /* In the following array of structures, the numeric second field of the
48 structures (minchars) is apparently used like this:
50 -# : Switch can be abbreviated to # characters; switch hidden in -help.
51 0 : Switch can't be abbreviated; switch shown in -help.
52 # : Switch can be abbreviated to # characters; switch shown in -help. */
54 #define POST_SWITCHES \
55 X("alias aliasfile", 0, ALIASW) \
56 X("check", -5, CHKSW) /* interface from whom */ \
57 X("nocheck", -7, NCHKSW) /* interface from whom */ \
58 X("debug", -5, DEBUGSW) \
59 X("dist", -4, DISTSW) /* interface from dist */ \
60 X("filter filterfile", 0, FILTSW) \
61 X("nofilter", 0, NFILTSW) \
62 X("format", 0, FRMTSW) \
63 X("noformat", 0, NFRMTSW) \
64 X("library directory", -7, LIBSW) /* interface from send, whom */ \
65 X("mime", 0, MIMESW) \
66 X("nomime", 0, NMIMESW) \
67 X("msgid", 0, MSGDSW) \
68 X("nomsgid", 0, NMSGDSW) \
69 X("verbose", 0, VERBSW) \
70 X("noverbose", 0, NVERBSW) \
71 X("watch", 0, WATCSW) \
72 X("nowatch", 0, NWATCSW) \
73 X("whom", -4, WHOMSW) /* interface from whom */ \
74 X("width columns", 0, WIDTHSW) \
75 X("version", 0, VERSIONSW) \
76 X("help", 0, HELPSW) \
77 X("dashstuffing", -12, BITSTUFFSW) /* should we dashstuff BCC messages? */ \
78 X("nodashstuffing", -14, NBITSTUFFSW) \
79 X("idanno number", -6, ANNOSW) /* interface from send */ \
80 X("client host", -6, CLIESW) \
81 X("server host", 6, SERVSW) /* specify alternate SMTP server */ \
82 X("snoop", -5, SNOOPSW) /* snoop the SMTP transaction */ \
83 X("partno", -6, PARTSW) \
84 X("sasl", SASLminc(4), SASLSW) \
85 X("nosasl", SASLminc(6), NOSASLSW) \
86 X("saslmech", SASLminc(5), SASLMECHSW) \
87 X("user", SASLminc(-4), USERSW) \
88 X("port server submission port name/number", 4, PORTSW) \
89 X("tls", TLSminc(-3), TLSSW) \
90 X("initialtls", TLSminc(-10), INITTLSSW) \
91 X("notls", TLSminc(-5), NTLSSW) \
92 X("certverify", TLSminc(-10), CERTVERSW) \
93 X("nocertverify", TLSminc(-12), NOCERTVERSW) \
94 X("fileproc", -4, FILEPROCSW) \
95 X("mhlproc", -3, MHLPROCSW) \
96 X("sendmail program", 0, MTSSM) \
97 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
98 X("credentials legacy|file:filename", 0, CREDENTIALSSW) \
99 X("messageid localname|random", 2, MESSAGEIDSW) \
100 X("authservice auth-service-name", OAUTHminc(-11), AUTHSERVICESW) \
101 X("oauthcredfile credential-file", OAUTHminc(-7), OAUTHCREDFILESW) \
102 X("oauthclientid client-id", OAUTHminc(-12), OAUTHCLIDSW) \
103 X("oauthclientsecret client-secret", OAUTHminc(-12), OAUTHCLSECSW) \
104 X("oauthauthendpoint authentication-endpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
105 X("oauthredirect redirect-uri", OAUTHminc(-6), OAUTHREDIRSW) \
106 X("oauthtokenendpoint token-endpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
107 X("oauthscope scope", OAUTHminc(-6), OAUTHSCOPESW) \
109 #define X(sw, minchars, id) id,
110 DEFINE_SWITCH_ENUM(POST
);
113 #define X(sw, minchars, id) { sw, minchars, id },
114 DEFINE_SWITCH_ARRAY(POST
, switches
);
119 * Mapping between command-line switches and profile entries, communicated
120 * from 'send'. We use a service name of 'post' internally.
123 static struct oauth_profile
{
124 const char *profname
;
127 } oauthswitches
[] = {
128 { "oauth-%s-credential-file", OAUTHCREDFILESW
, NULL
},
129 { "oauth-%s-client_id", OAUTHCLIDSW
, NULL
},
130 { "oauth-%s-client_secret", OAUTHCLSECSW
, NULL
},
131 { "oauth-%s-auth_endpoint", OAUTHAUTHENDSW
, NULL
},
132 { "oauth-%s-redirect_uri", OAUTHREDIRSW
, NULL
},
133 { "oauth-%s-token_endpoint", OAUTHTOKENDSW
, NULL
},
134 { "oauth-%s-scope", OAUTHSCOPESW
, NULL
},
145 * flags for headers->flags
147 #define HNOP 0x0000 /* just used to keep .set around */
148 #define HBAD 0x0001 /* bad header - don't let it through */
149 #define HADR 0x0002 /* header has an address field */
150 #define HSUB 0x0004 /* Subject: header */
151 #define HTRY 0x0008 /* try to send to addrs on header */
152 #define HBCC 0x0010 /* don't output this header, unless MTS_SENDMAIL_PIPE */
153 #define HMNG 0x0020 /* munge this header */
154 #define HNGR 0x0040 /* no groups allowed in this header */
155 #define HFCC 0x0080 /* FCC: type header */
156 #define HNIL 0x0100 /* okay for this header not to have addrs */
157 #define HIGN 0x0200 /* ignore this header */
158 #define HDCC 0x0400 /* another undocumented feature */
159 #define HONE 0x0800 /* Only (zero or) one address allowed */
160 #define HEFM 0x1000 /* Envelope-From: header */
161 #define HMIM 0x2000 /* MIME-Version: header */
162 #define HCTE 0x4000 /* Content-Transfer-Encoding: header */
165 * flags for headers->set
167 #define MFRM 0x0001 /* we've seen a From: */
168 #define MDAT 0x0002 /* we've seen a Date: */
169 #define MRFM 0x0004 /* we've seen a Resent-From: */
170 #define MVIS 0x0008 /* we've seen sighted addrs */
171 #define MINV 0x0010 /* we've seen blind addrs */
172 #define MSND 0x0020 /* we've seen a Sender: */
173 #define MRSN 0x0040 /* We've seen a Resent-Sendr:*/
174 #define MEFM 0x0080 /* We've seen Envelope-From: */
175 #define MMIM 0x0100 /* We've seen Mime-Version: */
177 static struct headers NHeaders
[] = {
178 { "Return-Path", HBAD
, 0 },
179 { "Received", HBAD
, 0 },
180 { "Reply-To", HADR
|HNGR
, 0 },
181 { "From", HADR
|HNGR
, MFRM
},
182 { "Sender", HADR
|HNGR
|HONE
, MSND
},
184 { "Subject", HSUB
, 0 },
185 { "To", HADR
|HTRY
, MVIS
},
186 { "cc", HADR
|HTRY
, MVIS
},
187 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, MINV
},
188 { "Dcc", HADR
|HTRY
|HDCC
|HNIL
, MVIS
}, /* sorta cc & bcc combined */
189 { "Message-ID", HBAD
, 0 },
191 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
192 { "MIME-Version", HMIM
, MMIM
},
193 { "Content-Transfer-Encoding", HCTE
, 0 },
197 static struct headers RHeaders
[] = {
198 { "Resent-Reply-To", HADR
|HNGR
, 0 },
199 { "Resent-From", HADR
|HNGR
, MRFM
},
200 { "Resent-Sender", HADR
|HNGR
, MRSN
},
201 { "Resent-Date", HBAD
, 0 },
202 { "Resent-Subject", HSUB
, 0 },
203 { "Resent-To", HADR
|HTRY
, MVIS
},
204 { "Resent-cc", HADR
|HTRY
, MVIS
},
205 { "Resent-Bcc", HADR
|HTRY
|HBCC
, MINV
},
206 { "Resent-Message-ID", HBAD
, 0 },
207 { "Resent-Fcc", HFCC
, 0 },
208 { "Reply-To", HADR
, 0 },
209 { "From", HADR
|HNGR
, MFRM
},
210 { "Sender", HADR
|HNGR
, MSND
},
211 { "Date", HNOP
, MDAT
},
212 { "To", HADR
|HNIL
, 0 },
213 { "cc", HADR
|HNIL
, 0 },
214 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, 0 },
216 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
217 { "MIME-Version", HMIM
, MMIM
},
218 { "Content-Transfer-Encoding", HCTE
, 0 },
222 static short fccind
= 0; /* index into fccfold[] */
223 static short outputlinelen
= OUTPUTLINELEN
;
225 static int pfd
= NOTOK
; /* fd to write annotation list to */
226 static int recipients
= 0; /* how many people will get a copy */
227 static int unkadr
= 0; /* how many of those were unknown */
228 static int badadr
= 0; /* number of bad addrs */
229 static int badmsg
= 0; /* message has bad semantics */
230 static int verbose
= 0; /* spell it out */
231 static int format
= 1; /* format addresses */
232 static int mime
= 0; /* use MIME-style encapsulations for Bcc */
233 static int msgid
= 0; /* add msgid */
234 static int debug
= 0; /* debugging post */
235 static int watch
= 0; /* watch the delivery process */
236 static int whomsw
= 0; /* we are whom not post */
237 static int checksw
= 0; /* whom -check */
238 static int linepos
=0; /* putadr()'s position on the line */
239 static int nameoutput
=0; /* putadr() has output header name */
240 static int sasl
=0; /* Use SASL auth for SMTP */
241 static char *saslmech
=NULL
; /* Force use of particular SASL mech */
242 static char *user
=NULL
; /* Authenticate as this user */
243 static char *port
="submission"; /* Name of server port for SMTP submission */
244 static int tlsflag
=0; /* Flags to control TLS settings */
245 static int fromcount
=0; /* Count of addresses on From: header */
246 static int seensender
=0; /* Have we seen a Sender: header? */
248 static unsigned msgflags
= 0; /* what we've seen */
252 static int msgstate
= NORMAL
;
254 static time_t tclock
= 0; /* the time we started (more or less) */
256 static SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
258 static char tmpfil
[BUFSIZ
];
259 static char bccfil
[BUFSIZ
];
261 static char from
[BUFSIZ
]; /* my network address */
262 static char sender
[BUFSIZ
]; /* my Sender: header */
263 static char efrom
[BUFSIZ
]; /* my Envelope-From: header */
264 static char fullfrom
[BUFSIZ
]; /* full contents of From header */
265 static char *filter
= NULL
; /* the filter for BCC'ing */
266 static char *subject
= NULL
; /* the subject field for BCC'ing */
267 static char *fccfold
[FCCS
]; /* foldernames for FCC'ing */
268 enum encoding
{ UNKNOWN
= 0, BINARY
= 1, SEVENBIT
= 7, EIGHTBIT
= 8 };
269 static enum encoding cte
= UNKNOWN
;
271 static struct headers
*hdrtab
; /* table for the message we're doing */
273 static struct mailname localaddrs
; /* local addrs */
274 static struct mailname netaddrs
; /* network addrs */
275 static struct mailname uuaddrs
; /* uucp addrs */
276 static struct mailname tmpaddrs
; /* temporary queue */
278 static int snoop
= 0;
279 static char *clientsw
= NULL
;
280 static char *serversw
= NULL
;
282 static char prefix
[] = "----- =_aaaaaaaaaa";
284 static char *partno
= NULL
;
289 static void putfmt (char *, char *, int *, FILE *);
290 static void start_headers (void);
291 static void finish_headers (FILE *);
292 static int get_header (char *, struct headers
*);
293 static int putadr (char *, char *, struct mailname
*, FILE *, unsigned int);
294 static void putgrp (char *, char *, FILE *, unsigned int);
295 static int insert (struct mailname
*);
296 static void pl (void);
297 static void anno (void);
298 static int annoaux (struct mailname
*);
299 static void insert_fcc (struct headers
*, char *);
300 static void make_bcc_file (int);
301 static void verify_all_addresses (int, int, char *, int, char *);
302 static void chkadr (void);
303 static void sigon (void);
304 static void sigoff (void);
305 static void p_refile (char *);
306 static void fcc (char *, char *);
307 static void die (char *, char *, ...);
308 static void post (char *, int, int, int, char *, int, char *);
309 static void do_text (char *file
, int fd
);
310 static void do_an_address (struct mailname
*, int);
311 static void do_addresses (int, int);
312 static int find_prefix (void);
316 main (int argc
, char **argv
)
318 int state
, compnum
, dashstuff
= 0, swnum
, oauth_flag
= 0, tls
= -1;
320 int eai
= 0; /* use Email Address Internationalization (EAI) (SMTPUTF8) */
321 char *cp
, *msg
= NULL
, **argp
, **arguments
, *envelope
;
322 char buf
[BUFSIZ
], name
[NAMESZ
], *auth_svc
= NULL
;
324 m_getfld_state_t gstate
= 0;
326 if (nmh_init(argv
[0], 0 /* use context_foil() */)) { return 1; }
329 arguments
= getarguments (invo_name
, argc
, argv
, 0);
332 while ((cp
= *argp
++)) {
334 switch ((swnum
= smatch (++cp
, switches
))) {
336 ambigsw (cp
, switches
);
339 adios (NULL
, "-%s unknown", cp
);
342 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
343 print_help (buf
, switches
, 0);
346 print_version(invo_name
);
350 if (!(cp
= *argp
++) || *cp
== '-')
351 adios (NULL
, "missing argument to %s", argp
[-2]);
352 /* create a minimal context */
353 if (context_foil (cp
) == -1)
358 if (!(cp
= *argp
++) || *cp
== '-')
359 adios (NULL
, "missing argument to %s", argp
[-2]);
360 if ((state
= alias (cp
)) != AK_OK
)
361 adios (NULL
, "aliasing error in %s - %s",
362 cp
, akerror (state
));
381 if (!(filter
= *argp
++) || *filter
== '-')
382 adios (NULL
, "missing argument to %s", argp
[-2]);
437 if (!(cp
= *argp
++) || *cp
== '-')
438 adios (NULL
, "missing argument to %s", argp
[-2]);
439 if ((outputlinelen
= atoi (cp
)) < 10)
440 adios (NULL
, "impossible width %d", outputlinelen
);
444 if (!(cp
= *argp
++) || *cp
== '-')
445 adios (NULL
, "missing argument to %s", argp
[-2]);
446 if ((pfd
= atoi (cp
)) <= 2)
447 adios (NULL
, "bad argument %s %s", argp
[-2], cp
);
451 if (!(clientsw
= *argp
++) || *clientsw
== '-')
452 adios (NULL
, "missing argument to %s", argp
[-2]);
455 if (!(serversw
= *argp
++) || *serversw
== '-')
456 adios (NULL
, "missing argument to %s", argp
[-2]);
463 if (!(partno
= *argp
++) || *partno
== '-')
464 adios (NULL
, "missing argument to %s", argp
[-2]);
476 if (!(saslmech
= *argp
++) || *saslmech
== '-')
477 adios (NULL
, "missing argument to %s", argp
[-2]);
481 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
482 adios (NULL
, "missing argument to %s", argp
[-2]);
486 case OAUTHCREDFILESW
:
496 if (!(cp
= *argp
++) || *cp
== '-')
497 adios (NULL
, "missing argument to %s", argp
[-2]);
499 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
500 if (oauthswitches
[i
].switchnum
== swnum
) {
501 oauthswitches
[i
].value
= cp
;
506 if (oauthswitches
[i
].profname
== NULL
)
507 adios (NULL
, "internal error: cannot map switch %s "
508 "to profile entry", argp
[-2]);
515 if (!(user
= *argp
++) || *user
== '-')
516 adios (NULL
, "missing argument to %s", argp
[-2]);
520 if (!(port
= *argp
++) || *port
== '-')
521 adios (NULL
, "missing argument to %s", argp
[-2]);
545 if (!(cp
= *argp
++) || *cp
== '-')
546 adios (NULL
, "missing argument to %s", argp
[-2]);
551 if (!(cp
= *argp
++) || *cp
== '-')
552 adios (NULL
, "missing argument to %s", argp
[-2]);
557 if (!(cp
= *argp
++) || *cp
== '-')
558 adios (NULL
, "missing argument to %s", argp
[-2]);
563 if (!(cp
= *argp
++) || *cp
== '-')
564 adios (NULL
, "missing argument to %s", argp
[-2]);
565 save_mts_method (cp
);
568 case CREDENTIALSSW
: {
569 if (!(cp
= *argp
++) || *cp
== '-')
570 adios (NULL
, "missing argument to %s", argp
[-2]);
571 add_profile_entry ("credentials", cp
);
576 if (!(cp
= *argp
++) || *cp
== '-')
577 adios (NULL
, "missing argument to %s", argp
[-2]);
578 if (save_message_id_style (cp
) != 0)
579 adios (NULL
, "unsupported messageid \"%s\"", cp
);
584 adios (NULL
, "only one message at a time!");
592 adios (NULL
, "usage: %s [switches] file", invo_name
);
594 if (outputlinelen
< 10)
595 adios (NULL
, "impossible width %d", outputlinelen
);
597 if ((in
= fopen (msg
, "r")) == NULL
)
598 adios (msg
, "unable to open");
606 if ((out
= fopen ("/dev/null", "w")) == NULL
)
607 adios ("/dev/null", "unable to open");
609 char *cp
= m_mktemp2(NULL
, invo_name
, NULL
, &out
);
611 adios(NULL
, "unable to create temporary file in %s",
614 strncpy(tmpfil
, cp
, sizeof(tmpfil
));
618 hdrtab
= msgstate
== NORMAL
? NHeaders
: RHeaders
;
620 for (compnum
= 1;;) {
621 int bufsz
= sizeof buf
;
622 switch (state
= m_getfld (&gstate
, name
, buf
, &bufsz
, in
)) {
626 cp
= mh_xstrdup(buf
);
627 while (state
== FLDPLUS
) {
629 state
= m_getfld (&gstate
, name
, buf
, &bufsz
, in
);
632 putfmt (name
, cp
, &eai
, out
);
637 finish_headers (out
);
640 fprintf (out
, "\n%s", buf
);
641 while (state
== BODY
) {
643 state
= m_getfld (&gstate
, name
, buf
, &bufsz
, in
);
649 finish_headers (out
);
654 adios (NULL
, "message format error in component #%d", compnum
);
657 adios (NULL
, "getfld() returned %d", state
);
661 m_getfld_state_destroy (&gstate
);
675 * Here's how we decide which address to use as the envelope-from
678 * - If we were given an Envelope-From header, use that.
679 * - If we were given a Sender: address, use that.
680 * - Otherwise, use the address on the From: line
683 if (msgflags
& MEFM
) {
685 } else if (seensender
) {
694 * The user didn't specify any of the tls switches. Try to
695 * help them by implying -initialtls if they're using port 465
696 * (smtps, until IANA revoked that registration in 1998).
698 tls
= ! strcmp (port
, "465") || ! strcasecmp (port
, "smtps")
701 #else /* ! TLS_SUPPORT */
703 #endif /* ! TLS_SUPPORT */
707 tlsflag
= S_STARTTLS
;
714 tlsflag
|= S_NOVERIFY
;
717 * If we were given any oauth flags, store the appropriate profile
718 * entries and make sure an authservice was given (we have to do this
719 * here because we aren't guaranteed the authservice will be given on
720 * the command line before the other OAuth flags are given).
727 if (auth_svc
== NULL
) {
728 adios(NULL
, "No authentication service given with -authservice");
731 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
732 if (oauthswitches
[i
].value
!= NULL
) {
733 snprintf(sbuf
, sizeof(sbuf
),
734 oauthswitches
[i
].profname
, auth_svc
);
735 sbuf
[sizeof(sbuf
) - 1] = '\0';
736 add_profile_entry(sbuf
, oauthswitches
[i
].value
);
741 /* If we are doing a "whom" check */
743 /* This won't work with MTS_SENDMAIL_PIPE. */
744 verify_all_addresses (1, eai
, envelope
, oauth_flag
, auth_svc
);
748 if (msgflags
& MINV
) {
749 make_bcc_file (dashstuff
);
750 if (msgflags
& MVIS
) {
751 if (sm_mts
!= MTS_SENDMAIL_PIPE
) {
752 /* It would be nice to have support to call
753 verify_all_addresses with MTS_SENDMAIL_PIPE, but
754 that might require running sendmail as root. Note
755 that spost didn't verify addresses. */
756 verify_all_addresses (verbose
, eai
, envelope
, oauth_flag
,
759 post (tmpfil
, 0, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
761 post (bccfil
, 1, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
762 (void) m_unlink (bccfil
);
764 post (tmpfil
, 0, isatty (1), eai
, envelope
, oauth_flag
, auth_svc
);
768 (void) m_unlink (tmpfil
);
772 printf ("Partial Message #%s Processed\n", partno
);
774 puts("Message Processed");
787 putfmt (char *name
, char *str
, int *eai
, FILE *out
)
789 int count
, grp
, i
, keep
;
791 char namep
[BUFSIZ
], error
[BUFSIZ
];
792 struct mailname
*mp
= NULL
, *np
= NULL
;
795 while (*str
== ' ' || *str
== '\t')
798 if (msgstate
== NORMAL
&& uprf (name
, "resent")) {
799 advise (NULL
, "illegal header line -- %s:", name
);
805 /* Check each header field value to see if it has any 8-bit characters.
806 If it does, enable EAI support. */
807 if (contains8bit(str
, NULL
)) {
809 puts("EAI/SMTPUTF8 enabled");
812 /* Enable SMTPUTF8. */
815 /* Enable passing of utf-8 setting to getname()/getadrx(). */
820 if ((i
= get_header (name
, hdrtab
)) == NOTOK
) {
821 if (strncasecmp (name
, "nmh-", 4)) {
822 fprintf (out
, "%s: %s", name
, str
);
824 /* Filter out all Nmh-* headers, because Norm asked. They
825 should never have reached this point. Warn about any
826 that are non-empty. */
827 if (strcmp (str
, "\n")) {
828 TrimSuffixC(str
, '\n');
830 advise (NULL
, "ignoring header line -- %s: %s", name
, str
);
839 if (hdr
->flags
& HIGN
) {
842 if (hdr
->flags
& HBAD
) {
843 advise (NULL
, "illegal header line -- %s:", name
);
847 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
849 if (hdr
->flags
& HSUB
)
850 subject
= subject
? add (str
, add ("\t", subject
)) : mh_xstrdup(str
);
851 if (hdr
->flags
& HFCC
) {
852 if ((cp
= strrchr(str
, '\n')))
854 for (pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
856 insert_fcc (hdr
, pp
);
858 insert_fcc (hdr
, pp
);
861 if (hdr
->flags
& HCTE
) {
862 if (strncasecmp (str
, "7bit", 4) == 0) {
864 } else if (strncasecmp (str
, "8bit", 4) == 0) {
866 } else if (strncasecmp (str
, "binary", 6) == 0) {
870 if (!(hdr
->flags
& HADR
)) {
871 fprintf (out
, "%s: %s", name
, str
);
875 tmpaddrs
.m_next
= NULL
;
877 for (count
= 0; (cp
= getname (str
)); count
++) {
878 if ((mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
882 tmpaddrs
.m_next
= mp
;
886 admonish(cp
, "%s", error
);
887 if (hdr
->flags
& HTRY
)
895 if (hdr
->flags
& HNIL
)
896 fprintf (out
, "%s: %s", name
, str
);
899 * Sender (or Resent-Sender) can have only one address
901 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
902 : (hdr
->set
& MSND
)) {
903 advise (NULL
, "%s: field requires one address", name
);
907 advise (NULL
, "%s: field requires at least one address", name
);
914 if (count
> 1 && (hdr
->flags
& HONE
)) {
915 advise (NULL
, "%s: field only permits one address", name
);
920 nameoutput
= linepos
= 0;
921 snprintf (namep
, sizeof(namep
), "%s%s",
922 (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
924 for (grp
= 0, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
925 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
926 /* The address doesn't include a host, so it might be an alias. */
927 pp
= akvalue (mp
->m_mbox
); /* do mh alias substitution */
928 qp
= akvisible () ? mp
->m_mbox
: "";
931 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
932 while ((cp
= getname (pp
))) {
933 if (!(mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
934 admonish(cp
, "%s", error
);
940 * If it's a From: or Resent-From: header, save the address
941 * for later possible use (as the envelope address for SMTP)
944 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
945 : (hdr
->set
& MFRM
)) {
946 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
947 from
[sizeof(from
) - 1] = '\0';
952 * Also save the Sender: or Resent-Sender: header as well
955 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
956 : (hdr
->set
& MSND
)) {
957 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
958 sender
[sizeof(sender
) - 1] = '\0';
963 * ALSO ... save Envelope-From
966 if (hdr
->set
& MEFM
) {
967 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
968 efrom
[sizeof(efrom
) - 1] = '\0';
971 if (hdr
->flags
& HBCC
)
974 mp
->m_ingrp
= np
->m_ingrp
;
977 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
979 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
980 /* Catch this before sendmail chokes with:
981 "553 List:; syntax illegal for recipient
983 If we wanted to, we could expand out blind
984 aliases and put them in Bcc:, but then
985 they'd have the Blind-Carbon-Copy
988 "blind lists not compatible with"
994 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
))
995 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1004 /* Address includes a host, so no alias substitution is needed. */
1007 * If it's a From: or Resent-From header, save the address
1008 * for later possible use (as the envelope address for SMTP)
1011 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
1012 : (hdr
->set
& MFRM
)) {
1013 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
1018 * Also save the Sender: header as well
1021 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
1022 : (hdr
->set
& MSND
)) {
1023 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
1024 sender
[sizeof(sender
) - 1] = '\0';
1029 * ALSO ... save Envelope-From
1032 if (hdr
->set
& MEFM
) {
1033 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1034 efrom
[sizeof(efrom
) - 1] = '\0';
1037 if (hdr
->flags
& HBCC
)
1040 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1043 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
);
1047 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1054 * If this is a From:/Resent-From: header, save the full thing for
1055 * later in case we need it for use when constructing a Bcc draft message
1058 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
1059 strncpy(fullfrom
, str
, sizeof(fullfrom
));
1060 fullfrom
[sizeof(fullfrom
) - 1] = 0;
1062 * Strip off any trailing newlines
1065 while (*fullfrom
&& fullfrom
[strlen(fullfrom
) - 1] == '\n') {
1066 fullfrom
[strlen(fullfrom
) - 1] = '\0';
1070 if (grp
> 0 && (hdr
->flags
& HNGR
)) {
1071 advise (NULL
, "%s: field does not allow groups", name
);
1081 start_headers (void)
1086 * Probably not necessary, but just in case ...
1097 * Now that we've outputted the header fields in the draft
1098 * message, we will now output any remaining header fields
1099 * that we need to add/create.
1103 finish_headers (FILE *out
)
1107 if (!(msgflags
& MFRM
)) {
1109 * A From: header is now required in the draft.
1111 advise (NULL
, "message has no From: header");
1112 advise (NULL
, "See default components files for examples");
1117 if (fromcount
> 1 && (seensender
== 0 && !(msgflags
& MEFM
))) {
1118 advise (NULL
, "A Sender: or Envelope-From: header is required "
1119 "with multiple\nFrom: addresses");
1127 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1129 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1131 * If we have multiple From: addresses, make sure we have an
1132 * Sender: header. If we don't have one, then generate one
1133 * from Envelope-From: (which in this case, cannot be blank)
1136 if (fromcount
> 1 && seensender
== 0) {
1137 if (efrom
[0] == '\0') {
1138 advise (NULL
, "Envelope-From cannot be blank when there "
1139 "is multiple From: addresses\nand no Sender: "
1143 fprintf (out
, "Sender: %s\n", efrom
);
1147 if (!(msgflags
& MVIS
))
1148 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
1152 if (!(msgflags
& MDAT
)) {
1153 advise (NULL
, "message has no Date: header");
1156 if (!(msgflags
& MFRM
)) {
1157 advise (NULL
, "message has no From: header");
1160 if (!(msgflags
& MRFM
)) {
1161 advise (NULL
, "message has no Resent-From: header");
1162 advise (NULL
, "See default components files for examples");
1166 if (fromcount
> 1 && (seensender
== 0 && !(msgflags
& MEFM
))) {
1167 advise (NULL
, "A Resent-Sender: or Envelope-From: header is "
1168 "required with multiple\nResent-From: addresses");
1176 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
1178 fprintf (out
, "Resent-Message-ID: %s\n",
1179 message_id (tclock
, 0));
1181 * If we have multiple Resent-From: addresses, make sure we have an
1182 * Resent-Sender: header. If we don't have one, then generate one
1183 * from Envelope-From (which in this case, cannot be blank)
1186 if (fromcount
> 1 && seensender
== 0) {
1187 if (efrom
[0] == '\0') {
1188 advise (NULL
, "Envelope-From cannot be blank when there "
1189 "is multiple Resent-From: addresses and no "
1190 "Resent-Sender: header");
1193 fprintf (out
, "Resent-Sender: %s\n", efrom
);
1197 if (!(msgflags
& MVIS
))
1198 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
1203 adios (NULL
, "re-format message and try again");
1205 adios (NULL
, "no addressees");
1210 get_header (char *header
, struct headers
*table
)
1214 for (h
= table
; h
->value
; h
++)
1215 if (!strcasecmp (header
? header
: "", h
->value
? h
->value
: ""))
1223 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
, unsigned int flags
)
1227 char buffer
[BUFSIZ
];
1229 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
1231 if (sm_mts
!= MTS_SENDMAIL_PIPE
&&
1232 ((flags
& (HBCC
| HDCC
| HEFM
)) || mp
->m_ingrp
))
1236 fprintf (out
, "%s: ", name
);
1237 linepos
+= (nameoutput
= strlen (name
) + 2);
1240 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
1241 mp
->m_pers
= mh_xstrdup(aka
);
1244 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
1247 cp
= adrformat (mp
);
1254 if (linepos
!= nameoutput
) {
1255 if (len
+ linepos
+ 2 > outputlinelen
)
1256 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
1266 return (flags
& HTRY
);
1271 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
1276 if (sm_mts
!= MTS_SENDMAIL_PIPE
&& (flags
& HBCC
))
1280 fprintf (out
, "%s: ", name
);
1281 linepos
+= (nameoutput
= strlen (name
) + 2);
1284 cp
= concat (group
, ";", NULL
);
1287 if (linepos
> nameoutput
) {
1288 if (len
+ linepos
+ 2 > outputlinelen
) {
1289 fprintf (out
, ",\n%*s", nameoutput
, "");
1290 linepos
= nameoutput
;
1304 insert (struct mailname
*np
)
1306 struct mailname
*mp
;
1308 if (np
->m_mbox
== NULL
)
1311 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1312 : np
->m_type
== UUCPHOST
? &uuaddrs
1316 if (!strcasecmp (np
->m_host
? np
->m_host
: "",
1317 mp
->m_next
->m_host
? mp
->m_next
->m_host
: "") &&
1318 !strcasecmp (np
->m_mbox
? np
->m_mbox
: "",
1319 mp
->m_next
->m_mbox
? mp
->m_next
->m_mbox
: "") &&
1320 np
->m_bcc
== mp
->m_next
->m_bcc
)
1333 struct mailname
*mp
;
1335 printf ("-------\n\t-- Addresses --\nlocal:\t");
1336 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1337 printf ("%s%s%s", mp
->m_mbox
,
1338 mp
->m_bcc
? "[BCC]" : "",
1339 mp
->m_next
? ",\n\t" : "");
1341 printf ("\nnet:\t");
1342 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1343 printf ("%s%s@%s%s%s", mp
->m_path
? mp
->m_path
: "",
1344 mp
->m_mbox
, mp
->m_host
,
1345 mp
->m_bcc
? "[BCC]" : "",
1346 mp
->m_next
? ",\n\t" : "");
1348 printf ("\nuucp:\t");
1349 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1350 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1351 mp
->m_bcc
? "[BCC]" : "",
1352 mp
->m_next
? ",\n\t" : "");
1354 printf ("\n\t-- Folder Copies --\nfcc:\t");
1355 for (i
= 0; i
< fccind
; i
++)
1356 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1364 struct mailname
*mp
;
1366 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1367 if (annoaux (mp
) == NOTOK
)
1370 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1371 if (annoaux (mp
) == NOTOK
)
1374 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1375 if (annoaux (mp
) == NOTOK
)
1385 annoaux (struct mailname
*mp
)
1388 char buffer
[BUFSIZ
];
1390 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1391 i
= strlen (buffer
);
1393 return (write (pfd
, buffer
, i
) == i
? OK
: NOTOK
);
1398 insert_fcc (struct headers
*hdr
, char *pp
)
1402 for (cp
= pp
; isspace ((unsigned char) *cp
); cp
++)
1404 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace ((unsigned char) *pp
); pp
--)
1412 adios (NULL
, "too many %ss", hdr
->value
);
1413 fccfold
[fccind
++] = mh_xstrdup(cp
);
1421 make_bcc_file (int dashstuff
)
1427 char *tfile
= NULL
, *program
;
1429 if ((tfile
= m_mktemp2(NULL
, "bccs", NULL
, &out
)) == NULL
) {
1430 adios(NULL
, "unable to create temporary file in %s", get_temp_dir());
1432 strncpy (bccfil
, tfile
, sizeof(bccfil
));
1434 fprintf (out
, "From: %s\n", fullfrom
);
1435 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1437 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1439 fprintf (out
, "Subject: %s", subject
);
1440 fprintf (out
, "BCC:\n");
1443 * Use MIME encapsulation for Bcc messages
1449 * Check if any lines in the message clash with the
1450 * prefix for the MIME multipart separator. If there
1451 * is a clash, increment one of the letters in the
1452 * prefix and check again.
1454 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1455 adios (NULL
, "lost prefix start");
1456 while (find_prefix () == NOTOK
) {
1461 adios (NULL
, "can't find a unique delimiter string");
1466 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1467 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1468 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1470 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1476 * Do mhl filtering of Bcc messages instead
1477 * of MIME encapsulation.
1479 if (filter
!= NULL
) {
1480 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
1484 adios ("fork", "unable to");
1487 dup2 (fileno (out
), 1);
1489 vec
= argsplit(mhlproc
, &program
, &i
);
1490 vec
[i
++] = "-forward";
1495 /* was the flag -[no]dashstuffing specified? */
1497 vec
[i
++] = "-dashstuffing";
1498 else if (dashstuff
< 0)
1499 vec
[i
++] = "-nodashstuffing";
1502 execvp (program
, vec
);
1503 fprintf (stderr
, "unable to exec ");
1508 pidXwait (child_id
, mhlproc
);
1512 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1513 adios (tmpfil
, "unable to re-open");
1516 * If using MIME encapsulation, or if the -nodashstuffing
1517 * flag was given, then just copy message. Else do
1518 * RFC934 quoting (dashstuffing).
1520 if (mime
|| dashstuff
< 0)
1521 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1523 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1527 fseek (out
, 0L, SEEK_END
);
1529 fprintf (out
, "\n--%s--\n", prefix
);
1531 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1537 * Scan message to check if any lines clash with
1538 * the prefix of the MIME multipart separator.
1545 char buffer
[BUFSIZ
];
1548 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1549 adios (tmpfil
, "unable to re-open");
1551 while (fgets (buffer
, sizeof buffer
, in
))
1552 if (buffer
[0] == '-' && buffer
[1] == '-') {
1555 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1556 if (!isspace ((unsigned char) *cp
))
1559 if (strcmp (buffer
+ 2, prefix
) == 0) {
1570 #define plural(x) (x == 1 ? "" : "s")
1575 if (badadr
&& unkadr
)
1576 die (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1577 badadr
, plural (badadr
), unkadr
, plural (badadr
));
1579 die (NULL
, "%d address%s unparsable", badadr
, plural (badadr
));
1581 die (NULL
, "%d addressee%s undeliverable", unkadr
, plural (unkadr
));
1586 do_addresses (int bccque
, int talk
)
1590 struct mailname
*lp
;
1593 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1594 if (lp
->m_bcc
? bccque
: !bccque
) {
1596 puts(" -- Local Recipients --");
1597 do_an_address (lp
, talk
);
1602 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1603 if (lp
->m_bcc
? bccque
: !bccque
) {
1605 puts(" -- UUCP Recipients --");
1606 do_an_address (lp
, talk
);
1611 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1612 if (lp
->m_bcc
? bccque
: !bccque
) {
1614 puts(" -- Network Recipients --");
1615 do_an_address (lp
, talk
);
1621 if (rp_isbad (retval
= sm_waend ()))
1622 die (NULL
, "problem ending addresses; %s", rp_string (retval
));
1627 * MTS-SPECIFIC INTERACTION
1632 * SENDMAIL/SMTP routines
1636 post (char *file
, int bccque
, int talk
, int eai
, char *envelope
,
1637 int oauth_flag
, char *auth_svc
)
1643 if (msgflags
& MINV
)
1644 printf (" -- Posting for %s Recipients --\n",
1645 bccque
? "Blind" : "Sighted");
1647 puts(" -- Posting for All Recipients --");
1652 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1653 char **argp
, *program
;
1656 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
1660 adios ("fork", "unable to");
1663 if (freopen( file
, "r", stdin
) == NULL
) {
1664 adios (file
, "can't reopen for sendmail");
1667 argp
= argsplit(sendmail
, &program
, &argc
);
1668 argp
[argc
++] = "-t"; /* read msg for recipients */
1669 argp
[argc
++] = "-i"; /* don't stop on "." */
1671 argp
[argc
++] = "-bv";
1673 argp
[argc
++] = "-v";
1676 execv (program
, argp
);
1677 adios (sendmail
, "can't exec");
1680 pidXwait (child_id
, NULL
);
1684 const int fd
= open (file
, O_RDONLY
);
1688 die (file
, "unable to re-open");
1691 if (msgflags
& MMIM
&& cte
!= UNKNOWN
) {
1692 /* MIME message with C-T-E header. (BINARYMIME isn't
1693 supported, use 8BITMIME instead for binary.) */
1694 eightbit
= cte
!= SEVENBIT
;
1696 if (scan_input (fd
, &eightbit
) == NOTOK
) {
1698 die (file
, "problem reading from");
1702 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1703 verbose
, snoop
, sasl
, saslmech
, user
,
1704 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1705 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1707 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1710 do_addresses (bccque
, talk
&& verbose
);
1715 sm_end (!(msgflags
& MINV
) || bccque
? OK
: DONE
);
1719 if (msgflags
& MINV
)
1720 printf (" -- %s Recipient Copies Posted --\n",
1721 bccque
? "Blind" : "Sighted");
1723 puts(" -- Recipient Copies Posted --");
1731 /* Address Verification */
1734 verify_all_addresses (int talk
, int eai
, char *envelope
, int oauth_flag
,
1738 struct mailname
*lp
;
1742 if (!whomsw
|| checksw
) {
1743 /* Not sending message body, so don't need to use 8BITMIME. */
1744 const int eightbit
= 0;
1746 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1747 verbose
, snoop
, sasl
, saslmech
, user
,
1748 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1749 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1750 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1754 if (talk
&& !whomsw
)
1755 puts(" -- Address Verification --");
1756 if (talk
&& localaddrs
.m_next
)
1757 puts(" -- Local Recipients --");
1758 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1759 do_an_address (lp
, talk
);
1761 if (talk
&& uuaddrs
.m_next
)
1762 puts(" -- UUCP Recipients --");
1763 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1764 do_an_address (lp
, talk
);
1766 if (talk
&& netaddrs
.m_next
)
1767 puts(" -- Network Recipients --");
1768 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1769 do_an_address (lp
, talk
);
1772 if (talk
&& !whomsw
)
1773 puts(" -- Address Verification Successful --");
1775 if (!whomsw
|| checksw
)
1784 do_an_address (struct mailname
*lp
, int talk
)
1790 switch (lp
->m_type
) {
1794 strncpy (addr
, mbox
, sizeof(addr
));
1798 mbox
= auxformat (lp
, 0);
1800 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1803 default: /* let SendMail decide if the host is bad */
1806 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1811 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1813 if (whomsw
&& !checksw
) {
1821 switch (retval
= sm_wadr (mbox
, host
,
1822 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1831 fprintf (stderr
, " %s: ", addr
);
1832 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1833 rp_string (retval
));
1839 fprintf (stderr
, " %s: ", addr
);
1840 die (NULL
, "unexpected response; %s", rp_string (retval
));
1848 do_text (char *file
, int fd
)
1853 lseek (fd
, (off_t
) 0, SEEK_SET
);
1855 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1856 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1857 die (NULL
, "problem writing text; %s\n", rp_string (retval
));
1861 die (file
, "problem reading from");
1863 switch (retval
= sm_wtend ()) {
1869 die (NULL
, "posting failed; %s", rp_string (retval
));
1872 die (NULL
, "unexpected response; %s", rp_string (retval
));
1886 (void) m_unlink (tmpfil
);
1887 if (msgflags
& MINV
)
1888 (void) m_unlink (bccfil
);
1890 if (!whomsw
|| checksw
)
1903 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1904 istat
= SIGNAL2 (SIGINT
, sigser
);
1905 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1906 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1916 SIGNAL (SIGHUP
, hstat
);
1917 SIGNAL (SIGINT
, istat
);
1918 SIGNAL (SIGQUIT
, qstat
);
1919 SIGNAL (SIGTERM
, tstat
);
1927 p_refile (char *file
)
1935 puts(" -- Filing Folder Copies --");
1936 for (i
= 0; i
< fccind
; i
++)
1937 fcc (file
, fccfold
[i
]);
1939 puts(" -- Folder Copies Filed --");
1944 * Call the `fileproc' to add the file to the folder.
1948 fcc (char *file
, char *folder
)
1951 int i
, status
, argp
;
1953 char **arglist
, *program
;
1956 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
1959 for (i
= 0; (child_id
= fork ()) == NOTOK
&& i
< 5; i
++)
1965 fprintf (stderr
, " %sFcc %s: ",
1966 msgstate
== RESENT
? "Resent-" : "", folder
);
1967 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
1971 /* see if we need to add `+' */
1972 snprintf (fold
, sizeof(fold
), "%s%s",
1973 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
1975 /* now exec the fileproc */
1977 arglist
= argsplit(fileproc
, &program
, &argp
);
1978 arglist
[argp
++] = "-link";
1979 arglist
[argp
++] = "-file";
1980 arglist
[argp
++] = file
;
1981 arglist
[argp
++] = fold
;
1982 arglist
[argp
] = NULL
;
1983 execvp (program
, arglist
);
1987 if ((status
= pidwait (child_id
, OK
))) {
1989 fprintf (stderr
, " %sFcc %s: ",
1990 msgstate
== RESENT
? "Resent-" : "", folder
);
1991 pidstatus (status
, verbose
? stdout
: stderr
, NULL
);
2006 die (char *what
, char *fmt
, ...)
2010 (void) m_unlink (tmpfil
);
2011 if (msgflags
& MINV
)
2012 (void) m_unlink (bccfil
);
2014 if (!whomsw
|| checksw
)
2018 advertise (what
, NULL
, fmt
, ap
);