]>
diplodocus.org Git - nmh/blob - uip/post.c
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.
10 #include <h/signals.h>
11 #include <h/addrsbr.h>
12 #include <h/aliasbr.h>
13 #include <h/dropsbr.h>
19 #include "sbr/m_mktemp.h"
20 #include "sbr/message_id.h"
22 #ifdef HAVE_SYS_TIME_H
23 # include <sys/time.h>
27 #include <mts/smtp/smtp.h>
30 # define SASLminc(a) (a)
31 #else /* CYRUS_SASL */
32 # define SASLminc(a) 0
33 #endif /* CYRUS_SASL */
36 # define TLSminc(a) (a)
37 #else /* TLS_SUPPORT */
39 #endif /* TLS_SUPPORT */
42 # define OAUTHminc(a) (a)
43 #else /* OAUTH_SUPPORT */
44 # define OAUTHminc(a) 0
45 #endif /* OAUTH_SUPPORT */
47 #define FCCS 10 /* max number of fccs allowed */
49 /* In the following array of structures, the numeric second field of the
50 structures (minchars) is apparently used like this:
52 -# : Switch can be abbreviated to # characters; switch hidden in -help.
53 0 : Switch can't be abbreviated; switch shown in -help.
54 # : Switch can be abbreviated to # characters; switch shown in -help. */
56 #define POST_SWITCHES \
57 X("alias aliasfile", 0, ALIASW) \
58 X("check", -5, CHKSW) /* interface from whom */ \
59 X("nocheck", -7, NCHKSW) /* interface from whom */ \
60 X("debug", -5, DEBUGSW) \
61 X("dist", -4, DISTSW) /* interface from dist */ \
62 X("filter filterfile", 0, FILTSW) \
63 X("nofilter", 0, NFILTSW) \
64 X("format", 0, FRMTSW) \
65 X("noformat", 0, NFRMTSW) \
66 X("library directory", -7, LIBSW) /* interface from send, whom */ \
67 X("mime", 0, MIMESW) \
68 X("nomime", 0, NMIMESW) \
69 X("msgid", 0, MSGDSW) \
70 X("nomsgid", 0, NMSGDSW) \
71 X("verbose", 0, VERBSW) \
72 X("noverbose", 0, NVERBSW) \
73 X("watch", 0, WATCSW) \
74 X("nowatch", 0, NWATCSW) \
75 X("whom", -4, WHOMSW) /* interface from whom */ \
76 X("width columns", 0, WIDTHSW) \
77 X("version", 0, VERSIONSW) \
78 X("help", 0, HELPSW) \
79 X("dashstuffing", -12, BITSTUFFSW) /* should we dashstuff BCC messages? */ \
80 X("nodashstuffing", -14, NBITSTUFFSW) \
81 X("idanno number", -6, ANNOSW) /* interface from send */ \
82 X("client host", -6, CLIESW) \
83 X("server host", 6, SERVSW) /* specify alternate SMTP server */ \
84 X("snoop", -5, SNOOPSW) /* snoop the SMTP transaction */ \
85 X("partno", -6, PARTSW) \
86 X("sasl", SASLminc(4), SASLSW) \
87 X("nosasl", SASLminc(6), NOSASLSW) \
88 X("saslmech", SASLminc(5), SASLMECHSW) \
89 X("user", SASLminc(-4), USERSW) \
90 X("port server submission port name/number", 4, PORTSW) \
91 X("tls", TLSminc(-3), TLSSW) \
92 X("initialtls", TLSminc(-10), INITTLSSW) \
93 X("notls", TLSminc(-5), NTLSSW) \
94 X("certverify", TLSminc(-10), CERTVERSW) \
95 X("nocertverify", TLSminc(-12), NOCERTVERSW) \
96 X("fileproc", -4, FILEPROCSW) \
97 X("mhlproc", -3, MHLPROCSW) \
98 X("sendmail program", 0, MTSSM) \
99 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
100 X("credentials legacy|file:filename", 0, CREDENTIALSSW) \
101 X("messageid localname|random", 2, MESSAGEIDSW) \
102 X("authservice auth-service-name", OAUTHminc(-11), AUTHSERVICESW) \
103 X("oauthcredfile credential-file", OAUTHminc(-7), OAUTHCREDFILESW) \
104 X("oauthclientid client-id", OAUTHminc(-12), OAUTHCLIDSW) \
105 X("oauthclientsecret client-secret", OAUTHminc(-12), OAUTHCLSECSW) \
106 X("oauthauthendpoint authentication-endpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
107 X("oauthredirect redirect-uri", OAUTHminc(-6), OAUTHREDIRSW) \
108 X("oauthtokenendpoint token-endpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
109 X("oauthscope scope", OAUTHminc(-6), OAUTHSCOPESW) \
111 #define X(sw, minchars, id) id,
112 DEFINE_SWITCH_ENUM(POST
);
115 #define X(sw, minchars, id) { sw, minchars, id },
116 DEFINE_SWITCH_ARRAY(POST
, switches
);
121 * Mapping between command-line switches and profile entries, communicated
122 * from 'send'. We use a service name of 'post' internally.
126 const char *profname
;
129 } oauthswitches
[] = {
130 { "oauth-%s-credential-file", OAUTHCREDFILESW
, NULL
},
131 { "oauth-%s-client_id", OAUTHCLIDSW
, NULL
},
132 { "oauth-%s-client_secret", OAUTHCLSECSW
, NULL
},
133 { "oauth-%s-auth_endpoint", OAUTHAUTHENDSW
, NULL
},
134 { "oauth-%s-redirect_uri", OAUTHREDIRSW
, NULL
},
135 { "oauth-%s-token_endpoint", OAUTHTOKENDSW
, NULL
},
136 { "oauth-%s-scope", OAUTHSCOPESW
, NULL
},
147 * flags for headers->flags
149 #define HNOP 0x0000 /* just used to keep .set around */
150 #define HBAD 0x0001 /* bad header - don't let it through */
151 #define HADR 0x0002 /* header has an address field */
152 #define HSUB 0x0004 /* Subject: header */
153 #define HTRY 0x0008 /* try to send to addrs on header */
154 #define HBCC 0x0010 /* don't output this header, unless MTS_SENDMAIL_PIPE */
155 #define HMNG 0x0020 /* munge this header */
156 #define HNGR 0x0040 /* no groups allowed in this header */
157 #define HFCC 0x0080 /* FCC: type header */
158 #define HNIL 0x0100 /* okay for this header not to have addrs */
159 #define HIGN 0x0200 /* ignore this header */
160 #define HDCC 0x0400 /* another undocumented feature */
161 #define HONE 0x0800 /* Only (zero or) one address allowed */
162 #define HEFM 0x1000 /* Envelope-From: header */
163 #define HMIM 0x2000 /* MIME-Version: header */
164 #define HCTE 0x4000 /* Content-Transfer-Encoding: header */
167 * flags for headers->set
169 #define MFRM 0x0001 /* we've seen a From: */
170 #define MDAT 0x0002 /* we've seen a Date: */
171 #define MRFM 0x0004 /* we've seen a Resent-From: */
172 #define MVIS 0x0008 /* we've seen sighted addrs */
173 #define MINV 0x0010 /* we've seen blind addrs */
174 #define MSND 0x0020 /* we've seen a Sender: */
175 #define MRSN 0x0040 /* We've seen a Resent-Sender: */
176 #define MEFM 0x0080 /* We've seen Envelope-From: */
177 #define MMIM 0x0100 /* We've seen Mime-Version: */
179 static struct headers NHeaders
[] = {
180 { "Return-Path", HBAD
, 0 },
181 { "Received", HBAD
, 0 },
182 { "Reply-To", HADR
|HNGR
, 0 },
183 { "From", HADR
|HNGR
, MFRM
},
184 { "Sender", HADR
|HNGR
|HONE
, MSND
},
186 { "Subject", HSUB
, 0 },
187 { "To", HADR
|HTRY
, MVIS
},
188 { "cc", HADR
|HTRY
, MVIS
},
189 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, MINV
},
190 { "Dcc", HADR
|HTRY
|HDCC
|HNIL
, MVIS
}, /* sorta cc & bcc combined */
191 { "Message-ID", HBAD
, 0 },
193 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
194 { "MIME-Version", HMIM
, MMIM
},
195 { "Content-Transfer-Encoding", HCTE
, 0 },
199 static struct headers RHeaders
[] = {
200 { "Resent-Reply-To", HADR
|HNGR
, 0 },
201 { "Resent-From", HADR
|HNGR
, MRFM
},
202 { "Resent-Sender", HADR
|HNGR
, MRSN
},
203 { "Resent-Date", HBAD
, 0 },
204 { "Resent-Subject", HSUB
, 0 },
205 { "Resent-To", HADR
|HTRY
, MVIS
},
206 { "Resent-cc", HADR
|HTRY
, MVIS
},
207 { "Resent-Bcc", HADR
|HTRY
|HBCC
, MINV
},
208 { "Resent-Message-ID", HBAD
, 0 },
209 { "Resent-Fcc", HFCC
, 0 },
210 { "Reply-To", HADR
, 0 },
211 { "From", HADR
|HNGR
, MFRM
},
212 { "Sender", HADR
|HNGR
, MSND
},
213 { "Date", HNOP
, MDAT
},
214 { "To", HADR
|HNIL
, 0 },
215 { "cc", HADR
|HNIL
, 0 },
216 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, 0 },
218 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
219 { "MIME-Version", HMIM
, MMIM
},
220 { "Content-Transfer-Encoding", HCTE
, 0 },
224 static short fccind
= 0; /* index into fccfold[] */
225 static short outputlinelen
= OUTPUTLINELEN
;
227 static int pfd
= NOTOK
; /* fd to write annotation list to */
228 static bool recipients
; /* how many people will get a copy */
229 static int unkadr
= 0; /* how many of those were unknown */
230 static int badadr
= 0; /* number of bad addrs */
231 static bool badmsg
; /* message has bad semantics */
232 static bool verbose
; /* spell it out */
233 static bool format
= true; /* format addresses */
234 static bool mime
; /* use MIME-style encapsulations for Bcc */
235 static bool msgid
; /* add msgid */
236 static bool debug
; /* debugging post */
237 static bool watch
; /* watch the delivery process */
238 static bool whomsw
; /* we are whom not post */
239 static bool checksw
; /* whom -check */
240 static int linepos
=0; /* putadr()'s position on the line */
241 static int nameoutput
=0; /* putadr() has output header name */
242 static bool sasl
; /* Use SASL auth for SMTP */
243 static char *saslmech
=NULL
; /* Force use of particular SASL mech */
244 static char *user
=NULL
; /* Authenticate as this user */
245 static char *port
="submission"; /* Name of server port for SMTP submission */
246 static int tlsflag
=0; /* Flags to control TLS settings */
247 static int fromcount
=0; /* Count of addresses on From: header */
248 static bool seensender
; /* Have we seen a Sender: header? */
250 static unsigned msgflags
= 0; /* what we've seen */
254 static int msgstate
= NORMAL
;
256 static time_t tclock
= 0; /* the time we started (more or less) */
258 static SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
260 static char tmpfil
[BUFSIZ
];
261 static char bccfil
[BUFSIZ
];
263 static char from
[BUFSIZ
]; /* my network address */
264 static char sender
[BUFSIZ
]; /* my Sender: header */
265 static char efrom
[BUFSIZ
]; /* my Envelope-From: header */
266 static char fullfrom
[BUFSIZ
]; /* full contents of From header */
267 static char *filter
= NULL
; /* the filter for BCC'ing */
268 static char *subject
= NULL
; /* the subject field for BCC'ing */
269 static char *fccfold
[FCCS
]; /* foldernames for FCC'ing */
270 enum encoding
{ UNKNOWN
= 0, BINARY
= 1, SEVENBIT
= 7, EIGHTBIT
= 8 };
271 static enum encoding cte
= UNKNOWN
;
273 static struct headers
*hdrtab
; /* table for the message we're doing */
275 static struct mailname localaddrs
; /* local addrs */
276 static struct mailname netaddrs
; /* network addrs */
277 static struct mailname uuaddrs
; /* uucp addrs */
278 static struct mailname tmpaddrs
; /* temporary queue */
281 static char *clientsw
= NULL
;
282 static char *serversw
= NULL
;
284 static char prefix
[] = "----- =_aaaaaaaaaa";
286 static char *partno
= NULL
;
291 static void putfmt (char *, char *, int *, FILE *);
292 static void start_headers (void);
293 static void finish_headers (FILE *);
294 static int get_header (char *, struct headers
*) PURE
;
295 static int putadr (char *, char *, struct mailname
*, FILE *, unsigned int,
296 char *, unsigned int);
297 static void putgrp (char *, char *, FILE *, unsigned int);
298 static int insert (struct mailname
*);
299 static void pl (void);
300 static void anno (void);
301 static int annoaux (struct mailname
*);
302 static void insert_fcc (struct headers
*, char *);
303 static void make_bcc_file (int);
304 static void verify_all_addresses (int, int, char *, int, char *);
305 static void chkadr (void) PURE
;
306 static void sigon (void);
307 static void sigoff (void);
308 static void p_refile (char *);
309 static void fcc (char *, char *);
310 static void fatal (char *, char *, ...) CHECK_PRINTF(2, 3);
311 static void post (char *, int, int, int, char *, int, char *);
312 static void do_text (char *file
, int fd
);
313 static void do_an_address (struct mailname
*, int);
314 static void do_addresses (int, int);
315 static int find_prefix (void);
319 main (int argc
, char **argv
)
321 int state
, compnum
, dashstuff
= 0, swnum
;
322 bool oauth_flag
= false;
324 bool noverify
= false;
325 int eai
= 0; /* use Email Address Internationalization (EAI) (SMTPUTF8) */
326 char *cp
, *msg
= NULL
, **argp
, **arguments
, *envelope
;
327 char buf
[NMH_BUFSIZ
], name
[NAMESZ
], *auth_svc
= NULL
;
329 m_getfld_state_t gstate
;
331 if (nmh_init(argv
[0], false, false)) { return 1; }
334 arguments
= getarguments (invo_name
, argc
, argv
, 0);
337 while ((cp
= *argp
++)) {
339 switch ((swnum
= smatch (++cp
, switches
))) {
341 ambigsw (cp
, switches
);
344 die("-%s unknown", cp
);
347 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
348 print_help (buf
, switches
, 0);
351 print_version(invo_name
);
355 if (!(cp
= *argp
++) || *cp
== '-')
356 die("missing argument to %s", argp
[-2]);
357 /* create a minimal context */
358 if (context_foil (cp
) == -1)
363 if (!(cp
= *argp
++) || *cp
== '-')
364 die("missing argument to %s", argp
[-2]);
365 if ((state
= alias (cp
)) != AK_OK
)
366 die("aliasing error in %s - %s",
367 cp
, akerror (state
));
386 if (!(filter
= *argp
++) || *filter
== '-')
387 die("missing argument to %s", argp
[-2]);
442 if (!(cp
= *argp
++) || *cp
== '-')
443 die("missing argument to %s", argp
[-2]);
444 if ((outputlinelen
= atoi (cp
)) < 10)
445 die("impossible width %d", outputlinelen
);
449 if (!(cp
= *argp
++) || *cp
== '-')
450 die("missing argument to %s", argp
[-2]);
451 if ((pfd
= atoi (cp
)) <= 2)
452 die("bad argument %s %s", argp
[-2], cp
);
456 if (!(clientsw
= *argp
++) || *clientsw
== '-')
457 die("missing argument to %s", argp
[-2]);
460 if (!(serversw
= *argp
++) || *serversw
== '-')
461 die("missing argument to %s", argp
[-2]);
468 if (!(partno
= *argp
++) || *partno
== '-')
469 die("missing argument to %s", argp
[-2]);
481 if (!(saslmech
= *argp
++) || *saslmech
== '-')
482 die("missing argument to %s", argp
[-2]);
486 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
487 die("missing argument to %s", argp
[-2]);
491 case OAUTHCREDFILESW
:
501 if (!(cp
= *argp
++) || *cp
== '-')
502 die("missing argument to %s", argp
[-2]);
504 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
505 if (oauthswitches
[i
].switchnum
== swnum
) {
506 oauthswitches
[i
].value
= cp
;
511 if (oauthswitches
[i
].profname
== NULL
)
512 die("internal error: cannot map switch %s "
513 "to profile entry", argp
[-2]);
520 if (!(user
= *argp
++) || *user
== '-')
521 die("missing argument to %s", argp
[-2]);
525 if (!(port
= *argp
++) || *port
== '-')
526 die("missing argument to %s", argp
[-2]);
550 if (!(cp
= *argp
++) || *cp
== '-')
551 die("missing argument to %s", argp
[-2]);
556 if (!(cp
= *argp
++) || *cp
== '-')
557 die("missing argument to %s", argp
[-2]);
562 if (!(cp
= *argp
++) || *cp
== '-')
563 die("missing argument to %s", argp
[-2]);
568 if (!(cp
= *argp
++) || *cp
== '-')
569 die("missing argument to %s", argp
[-2]);
570 save_mts_method (cp
);
573 case CREDENTIALSSW
: {
574 if (!(cp
= *argp
++) || *cp
== '-')
575 die("missing argument to %s", argp
[-2]);
576 add_profile_entry ("credentials", cp
);
581 if (!(cp
= *argp
++) || *cp
== '-')
582 die("missing argument to %s", argp
[-2]);
583 if (save_message_id_style (cp
) != 0)
584 die("unsupported messageid \"%s\"", cp
);
589 die("only one message at a time!");
596 die("usage: %s [switches] file", invo_name
);
598 if (outputlinelen
< 10)
599 die("impossible width %d", outputlinelen
);
601 if ((in
= fopen (msg
, "r")) == NULL
)
602 adios (msg
, "unable to open");
610 if ((out
= fopen ("/dev/null", "w")) == NULL
)
611 adios ("/dev/null", "unable to open");
613 char *cp
= m_mktemp2(NULL
, invo_name
, NULL
, &out
);
615 die("unable to create temporary file in %s",
618 strncpy(tmpfil
, cp
, sizeof(tmpfil
));
622 hdrtab
= msgstate
== NORMAL
? NHeaders
: RHeaders
;
624 gstate
= m_getfld_state_init(in
);
625 for (compnum
= 1;;) {
626 int bufsz
= sizeof buf
;
627 switch (state
= m_getfld2(&gstate
, name
, buf
, &bufsz
)) {
631 cp
= mh_xstrdup(buf
);
632 while (state
== FLDPLUS
) {
634 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
637 putfmt (name
, cp
, &eai
, out
);
642 finish_headers (out
);
645 fprintf (out
, "\n%s", buf
);
646 while (state
== BODY
) {
648 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
654 finish_headers (out
);
659 die("message format error in component #%d", compnum
);
662 die("getfld() returned %d", state
);
666 m_getfld_state_destroy (&gstate
);
679 * Here's how we decide which address to use as the envelope-from
682 * - If we were given an Envelope-From header, use that.
683 * - If we were given a Sender: address, use that.
684 * - Otherwise, use the address on the From: line
687 if (msgflags
& MEFM
) {
689 } else if (seensender
) {
698 * The user didn't specify any of the tls switches. Try to
699 * help them by implying -initialtls if they're using port 465
700 * (smtps, until IANA revoked that registration in 1998).
702 tls
= ! strcmp (port
, "465") || ! strcasecmp (port
, "smtps")
705 #else /* ! TLS_SUPPORT */
707 #endif /* ! TLS_SUPPORT */
711 tlsflag
= S_STARTTLS
;
718 tlsflag
|= S_NOVERIFY
;
721 * If we were given any oauth flags, store the appropriate profile
722 * entries and make sure an authservice was given (we have to do this
723 * here because we aren't guaranteed the authservice will be given on
724 * the command line before the other OAuth flags are given).
731 if (auth_svc
== NULL
) {
732 die("No authentication service given with -authservice");
735 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
736 if (oauthswitches
[i
].value
!= NULL
) {
737 snprintf(sbuf
, sizeof(sbuf
),
738 oauthswitches
[i
].profname
, auth_svc
);
739 sbuf
[sizeof(sbuf
) - 1] = '\0';
740 add_profile_entry(sbuf
, oauthswitches
[i
].value
);
745 /* If we are doing a "whom" check */
747 /* This won't work with MTS_SENDMAIL_PIPE. */
748 verify_all_addresses (1, eai
, envelope
, oauth_flag
, auth_svc
);
752 if (msgflags
& MINV
) {
753 make_bcc_file (dashstuff
);
754 if (msgflags
& MVIS
) {
755 if (sm_mts
!= MTS_SENDMAIL_PIPE
) {
756 /* It would be nice to have support to call
757 verify_all_addresses with MTS_SENDMAIL_PIPE, but
758 that might require running sendmail as root. Note
759 that spost didn't verify addresses. */
760 verify_all_addresses (verbose
, eai
, envelope
, oauth_flag
,
763 post (tmpfil
, 0, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
765 post (bccfil
, 1, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
766 (void) m_unlink (bccfil
);
768 post (tmpfil
, 0, isatty (1), eai
, envelope
, oauth_flag
, auth_svc
);
772 (void) m_unlink (tmpfil
);
776 printf ("Partial Message #%s Processed\n", partno
);
778 puts("Message Processed");
791 putfmt (char *name
, char *str
, int *eai
, FILE *out
)
797 char namep
[BUFSIZ
], error
[BUFSIZ
];
798 char *savehdr
= NULL
;
799 unsigned int savehdrlen
= 0;
800 struct mailname
*mp
= NULL
, *np
= NULL
;
803 while (*str
== ' ' || *str
== '\t')
806 if (msgstate
== NORMAL
&& uprf (name
, "resent")) {
807 inform("illegal header line -- %s:", name
);
813 /* Check each header field value to see if it has any 8-bit characters.
814 If it does, enable EAI support. */
815 if (contains8bit(str
, NULL
)) {
817 puts("EAI/SMTPUTF8 enabled");
820 /* Enable SMTPUTF8. */
823 /* Enable passing of utf-8 setting to getname()/getadrx(). */
828 if ((i
= get_header (name
, hdrtab
)) == NOTOK
) {
829 if (strncasecmp (name
, "nmh-", 4)) {
830 fprintf (out
, "%s: %s", name
, str
);
832 /* Filter out all Nmh-* headers, because Norm asked. They
833 should never have reached this point. Warn about any
834 that are non-empty. */
835 if (strcmp (str
, "\n")) {
836 trim_suffix_c(str
, '\n');
838 inform("ignoring header line -- %s: %s", name
, str
);
847 if (hdr
->flags
& HIGN
) {
850 if (hdr
->flags
& HBAD
) {
851 inform("illegal header line -- %s:", name
);
855 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
857 if (hdr
->flags
& HSUB
)
858 subject
= subject
? add (str
, add ("\t", subject
)) : mh_xstrdup(str
);
859 if (hdr
->flags
& HFCC
) {
860 if ((cp
= strrchr(str
, '\n')))
862 for (pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
864 insert_fcc (hdr
, pp
);
866 insert_fcc (hdr
, pp
);
869 if (hdr
->flags
& HCTE
) {
870 if (strncasecmp (str
, "7bit", 4) == 0) {
872 } else if (strncasecmp (str
, "8bit", 4) == 0) {
874 } else if (strncasecmp (str
, "binary", 6) == 0) {
878 if (!(hdr
->flags
& HADR
)) {
879 fprintf (out
, "%s: %s", name
, str
);
884 * If this is a From:/Resent-From: header, save the full thing for
885 * later in case we need it for use when constructing a Bcc draft message.
886 * Because we want to capture the results of alias expansion, save
887 * the output from putadr().
890 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
893 savehdrlen
= sizeof(fullfrom
);
896 tmpaddrs
.m_next
= NULL
;
898 for (count
= 0; (cp
= getname (str
)); count
++) {
899 if ((mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
903 tmpaddrs
.m_next
= mp
;
907 admonish(cp
, "%s", error
);
908 if (hdr
->flags
& HTRY
)
916 if (hdr
->flags
& HNIL
)
917 fprintf (out
, "%s: %s", name
, str
);
920 * Sender (or Resent-Sender) can have only one address
922 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
923 : (hdr
->set
& MSND
)) {
924 inform("%s: field requires one address", name
);
928 inform("%s: field requires at least one address", name
);
935 if (count
> 1 && (hdr
->flags
& HONE
)) {
936 inform("%s: field only permits one address", name
);
941 nameoutput
= linepos
= 0;
942 snprintf (namep
, sizeof(namep
), "%s%s",
943 (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
945 for (grp
= false, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
946 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
947 /* The address doesn't include a host, so it might be an alias. */
948 pp
= akvalue (mp
->m_mbox
); /* do mh alias substitution */
949 qp
= akvisible () ? mp
->m_mbox
: "";
952 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
953 while ((cp
= getname (pp
))) {
954 if (!(mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
955 admonish(cp
, "%s", error
);
961 * If it's a From: or Resent-From: header, save the address
962 * for later possible use (as the envelope address for SMTP)
965 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
966 : (hdr
->set
& MFRM
)) {
967 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
968 from
[sizeof(from
) - 1] = '\0';
973 * Also save the Sender: or Resent-Sender: header as well
976 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
977 : (hdr
->set
& MSND
)) {
978 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
979 sender
[sizeof(sender
) - 1] = '\0';
984 * ALSO ... save Envelope-From
987 if (hdr
->set
& MEFM
) {
988 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
989 efrom
[sizeof(efrom
) - 1] = '\0';
992 if (hdr
->flags
& HBCC
)
995 mp
->m_ingrp
= np
->m_ingrp
;
996 else if (mp
->m_gname
)
997 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
999 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1000 /* Catch this before sendmail chokes with:
1001 "553 List:; syntax illegal for recipient
1003 If we wanted to, we could expand out blind
1004 aliases and put them in Bcc:, but then
1005 they'd have the Blind-Carbon-Copy
1007 die( "blind lists not compatible with"
1013 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
, savehdr
,
1015 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1024 /* Address includes a host, so no alias substitution is needed. */
1027 * If it's a From: or Resent-From header, save the address
1028 * for later possible use (as the envelope address for SMTP)
1031 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
1032 : (hdr
->set
& MFRM
)) {
1033 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
1038 * Also save the Sender: header as well
1041 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
1042 : (hdr
->set
& MSND
)) {
1043 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
1044 sender
[sizeof(sender
) - 1] = '\0';
1049 * ALSO ... save Envelope-From
1052 if (hdr
->set
& MEFM
) {
1053 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1054 efrom
[sizeof(efrom
) - 1] = '\0';
1057 if (hdr
->flags
& HBCC
)
1060 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1063 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
, savehdr
, savehdrlen
);
1067 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1074 * If it was a From header, strip off any trailing newlines from
1075 * the alias-expanded From line.
1078 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
1079 while (*fullfrom
&& fullfrom
[strlen(fullfrom
) - 1] == '\n') {
1080 fullfrom
[strlen(fullfrom
) - 1] = '\0';
1084 if (grp
&& (hdr
->flags
& HNGR
)) {
1085 inform("%s: field does not allow groups", name
);
1095 start_headers (void)
1100 * Probably not necessary, but just in case ...
1111 * Now that we've outputted the header fields in the draft
1112 * message, we will now output any remaining header fields
1113 * that we need to add/create.
1117 finish_headers (FILE *out
)
1121 if (!(msgflags
& MFRM
)) {
1123 * A From: header is now required in the draft.
1125 inform("message has no From: header");
1126 inform("See default components files for examples");
1131 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1132 inform("A Sender: or Envelope-From: header is required "
1133 "with multiple\nFrom: addresses");
1141 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1143 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1145 * If we have multiple From: addresses, make sure we have an
1146 * Sender: header. If we don't have one, then generate one
1147 * from Envelope-From: (which in this case, cannot be blank)
1150 if (fromcount
> 1 && !seensender
) {
1151 if (efrom
[0] == '\0') {
1152 inform("Envelope-From cannot be blank when there "
1153 "is multiple From: addresses\nand no Sender: "
1157 fprintf (out
, "Sender: %s\n", efrom
);
1161 if (!(msgflags
& MVIS
))
1162 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
1166 if (!(msgflags
& MDAT
)) {
1167 inform("message has no Date: header");
1170 if (!(msgflags
& MFRM
)) {
1171 inform("message has no From: header");
1174 if (!(msgflags
& MRFM
)) {
1175 inform("message has no Resent-From: header");
1176 inform("See default components files for examples");
1180 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1181 inform("A Resent-Sender: or Envelope-From: header is "
1182 "required with multiple\nResent-From: addresses");
1190 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
1192 fprintf (out
, "Resent-Message-ID: %s\n",
1193 message_id (tclock
, 0));
1195 * If we have multiple Resent-From: addresses, make sure we have an
1196 * Resent-Sender: header. If we don't have one, then generate one
1197 * from Envelope-From (which in this case, cannot be blank)
1200 if (fromcount
> 1 && !seensender
) {
1201 if (efrom
[0] == '\0') {
1202 inform("Envelope-From cannot be blank when there "
1203 "is multiple Resent-From: addresses and no "
1204 "Resent-Sender: header");
1207 fprintf (out
, "Resent-Sender: %s\n", efrom
);
1211 if (!(msgflags
& MVIS
))
1212 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
1217 die("re-format message and try again");
1219 die("no addressees");
1224 get_header (char *header
, struct headers
*table
)
1228 header
= FENDNULL(header
);
1229 for (h
= table
; h
->value
; h
++)
1230 if (!strcasecmp(FENDNULL(h
->value
), header
))
1238 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
,
1239 unsigned int flags
, char *savehdr
, unsigned int savehdrsize
)
1242 bool saveappend
= false;
1245 char buffer
[BUFSIZ
];
1247 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
1249 if (sm_mts
!= MTS_SENDMAIL_PIPE
&&
1250 ((flags
& (HBCC
| HDCC
| HEFM
)) || mp
->m_ingrp
))
1254 fprintf (out
, "%s: ", name
);
1255 linepos
+= (nameoutput
= strlen (name
) + 2);
1259 shlen
= strlen(savehdr
);
1263 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
1264 mp
->m_pers
= mh_xstrdup(aka
);
1267 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
1270 cp
= adrformat (mp
);
1277 if (linepos
!= nameoutput
) {
1278 if (len
+ linepos
+ 2 > outputlinelen
) {
1279 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
1281 if (shlen
+ 2 + nameoutput
+ len
>= savehdrsize
) {
1284 snprintf(savehdr
+ shlen
, savehdrsize
- shlen
, ",\n%*s",
1292 if (shlen
+ 2 + len
>= savehdrsize
) {
1295 strncat(savehdr
, ", ", savehdrsize
- shlen
);
1303 if (saveappend
&& shlen
+ len
< savehdrsize
)
1304 strncat(savehdr
, cp
, savehdrsize
- shlen
+ len
);
1308 return flags
& HTRY
;
1313 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
1318 if (sm_mts
!= MTS_SENDMAIL_PIPE
&& (flags
& HBCC
))
1322 fprintf (out
, "%s: ", name
);
1323 linepos
+= (nameoutput
= strlen (name
) + 2);
1326 cp
= concat (group
, ";", NULL
);
1329 if (linepos
> nameoutput
) {
1330 if (len
+ linepos
+ 2 > outputlinelen
) {
1331 fprintf (out
, ",\n%*s", nameoutput
, "");
1332 linepos
= nameoutput
;
1346 insert (struct mailname
*np
)
1348 struct mailname
*mp
;
1350 if (np
->m_mbox
== NULL
)
1353 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1354 : np
->m_type
== UUCPHOST
? &uuaddrs
1358 if (!strcasecmp (FENDNULL(np
->m_host
),
1359 FENDNULL(mp
->m_next
->m_host
)) &&
1360 !strcasecmp (FENDNULL(np
->m_mbox
),
1361 FENDNULL(mp
->m_next
->m_mbox
)) &&
1362 np
->m_bcc
== mp
->m_next
->m_bcc
)
1375 struct mailname
*mp
;
1377 fputs("-------\n\t-- Addresses --\nlocal:\t", stdout
);
1378 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1379 printf ("%s%s%s", mp
->m_mbox
,
1380 mp
->m_bcc
? "[BCC]" : "",
1381 mp
->m_next
? ",\n\t" : "");
1383 fputs("\nnet:\t", stdout
);
1384 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1385 printf ("%s%s@%s%s%s", FENDNULL(mp
->m_path
),
1386 mp
->m_mbox
, mp
->m_host
,
1387 mp
->m_bcc
? "[BCC]" : "",
1388 mp
->m_next
? ",\n\t" : "");
1390 fputs("\nuucp:\t", stdout
);
1391 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1392 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1393 mp
->m_bcc
? "[BCC]" : "",
1394 mp
->m_next
? ",\n\t" : "");
1396 fputs("\n\t-- Folder Copies --\nfcc:\t", stdout
);
1397 for (i
= 0; i
< fccind
; i
++)
1398 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1406 struct mailname
*mp
;
1408 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1409 if (annoaux (mp
) == NOTOK
)
1412 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1413 if (annoaux (mp
) == NOTOK
)
1416 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1417 if (annoaux (mp
) == NOTOK
)
1427 annoaux (struct mailname
*mp
)
1430 char buffer
[BUFSIZ
];
1432 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1433 i
= strlen (buffer
);
1435 return write(pfd
, buffer
, i
) == i
? OK
: NOTOK
;
1440 insert_fcc (struct headers
*hdr
, char *pp
)
1444 for (cp
= pp
; isspace ((unsigned char) *cp
); cp
++)
1446 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace ((unsigned char) *pp
); pp
--)
1454 die("too many %ss", hdr
->value
);
1455 fccfold
[fccind
++] = mh_xstrdup(cp
);
1463 make_bcc_file (int dashstuff
)
1469 char *tfile
= NULL
, *program
;
1471 if ((tfile
= m_mktemp2(NULL
, "bccs", NULL
, &out
)) == NULL
) {
1472 die("unable to create temporary file in %s", get_temp_dir());
1474 strncpy (bccfil
, tfile
, sizeof(bccfil
));
1476 fprintf (out
, "From: %s\n", fullfrom
);
1477 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1479 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1481 fprintf (out
, "Subject: %s", subject
);
1482 fprintf (out
, "BCC:\n");
1485 * Use MIME encapsulation for Bcc messages
1491 * Check if any lines in the message clash with the
1492 * prefix for the MIME multipart separator. If there
1493 * is a clash, increment one of the letters in the
1494 * prefix and check again.
1496 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1497 die("lost prefix start");
1498 while (find_prefix () == NOTOK
) {
1501 else if (*++cp
== 0)
1502 die("can't find a unique delimiter string");
1507 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1508 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1509 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1511 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1517 * Do mhl filtering of Bcc messages instead
1518 * of MIME encapsulation.
1520 if (filter
!= NULL
) {
1524 adios ("fork", "unable to");
1527 dup2 (fileno (out
), 1);
1529 vec
= argsplit(mhlproc
, &program
, &i
);
1530 vec
[i
++] = "-forward";
1535 /* was the flag -[no]dashstuffing specified? */
1537 vec
[i
++] = "-dashstuffing";
1538 else if (dashstuff
< 0)
1539 vec
[i
++] = "-nodashstuffing";
1542 execvp (program
, vec
);
1543 fprintf (stderr
, "unable to exec ");
1548 pidXwait (child_id
, mhlproc
);
1552 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1553 adios (tmpfil
, "unable to re-open");
1556 * If using MIME encapsulation, or if the -nodashstuffing
1557 * flag was given, then just copy message. Else do
1558 * RFC934 quoting (dashstuffing).
1560 if (mime
|| dashstuff
< 0)
1561 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1563 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1567 fseek (out
, 0L, SEEK_END
);
1569 fprintf (out
, "\n--%s--\n", prefix
);
1571 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1577 * Scan message to check if any lines clash with
1578 * the prefix of the MIME multipart separator.
1585 char buffer
[BUFSIZ
];
1588 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1589 adios (tmpfil
, "unable to re-open");
1591 while (fgets (buffer
, sizeof buffer
, in
))
1592 if (buffer
[0] == '-' && buffer
[1] == '-') {
1595 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1596 if (!isspace ((unsigned char) *cp
))
1599 if (strcmp (buffer
+ 2, prefix
) == 0) {
1613 if (badadr
&& unkadr
)
1614 fatal (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1615 badadr
, PLURALS(badadr
), unkadr
, PLURALS(badadr
));
1617 fatal (NULL
, "%d address%s unparsable", badadr
, PLURALS(badadr
));
1619 fatal (NULL
, "%d addressee%s undeliverable", unkadr
, PLURALS(unkadr
));
1624 do_addresses (int bccque
, int talk
)
1628 struct mailname
*lp
;
1631 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1632 if (lp
->m_bcc
? bccque
: !bccque
) {
1634 puts(" -- Local Recipients --");
1635 do_an_address (lp
, talk
);
1640 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1641 if (lp
->m_bcc
? bccque
: !bccque
) {
1643 puts(" -- UUCP Recipients --");
1644 do_an_address (lp
, talk
);
1649 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1650 if (lp
->m_bcc
? bccque
: !bccque
) {
1652 puts(" -- Network Recipients --");
1653 do_an_address (lp
, talk
);
1659 if (rp_isbad (retval
= sm_waend ()))
1660 fatal (NULL
, "problem ending addresses; %s", rp_string (retval
));
1665 * MTS-SPECIFIC INTERACTION
1670 * SENDMAIL/SMTP routines
1674 post (char *file
, int bccque
, int talk
, int eai
, char *envelope
,
1675 int oauth_flag
, char *auth_svc
)
1681 if (msgflags
& MINV
)
1682 printf (" -- Posting for %s Recipients --\n",
1683 bccque
? "Blind" : "Sighted");
1685 puts(" -- Posting for All Recipients --");
1690 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1691 char **argp
, *program
;
1697 adios ("fork", "unable to");
1700 if (freopen( file
, "r", stdin
) == NULL
) {
1701 adios (file
, "can't reopen for sendmail");
1704 argp
= argsplit(sendmail
, &program
, &argc
);
1705 argp
[argc
++] = "-t"; /* read msg for recipients */
1706 argp
[argc
++] = "-i"; /* don't stop on "." */
1708 argp
[argc
++] = "-bv";
1710 argp
[argc
++] = "-v";
1713 execv (program
, argp
);
1714 adios (sendmail
, "can't exec");
1717 pidXwait (child_id
, NULL
);
1721 const int fd
= open (file
, O_RDONLY
);
1725 fatal (file
, "unable to re-open");
1728 if (msgflags
& MMIM
&& cte
!= UNKNOWN
) {
1729 /* MIME message with C-T-E header. (BINARYMIME isn't
1730 supported, use 8BITMIME instead for binary.) */
1731 eightbit
= cte
!= SEVENBIT
;
1733 if (scan_input (fd
, &eightbit
) == NOTOK
) {
1735 fatal (file
, "problem reading from");
1739 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1740 verbose
, snoop
, sasl
, saslmech
, user
,
1741 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1742 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1744 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1747 do_addresses (bccque
, talk
&& verbose
);
1752 sm_end (!(msgflags
& MINV
) || bccque
? OK
: DONE
);
1756 if (msgflags
& MINV
)
1757 printf (" -- %s Recipient Copies Posted --\n",
1758 bccque
? "Blind" : "Sighted");
1760 puts(" -- Recipient Copies Posted --");
1768 /* Address Verification */
1771 verify_all_addresses (int talk
, int eai
, char *envelope
, int oauth_flag
,
1775 struct mailname
*lp
;
1779 if (!whomsw
|| checksw
) {
1780 /* Not sending message body, so don't need to use 8BITMIME. */
1781 const int eightbit
= 0;
1783 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1784 verbose
, snoop
, sasl
, saslmech
, user
,
1785 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1786 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1787 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1791 if (talk
&& !whomsw
)
1792 puts(" -- Address Verification --");
1793 if (talk
&& localaddrs
.m_next
)
1794 puts(" -- Local Recipients --");
1795 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1796 do_an_address (lp
, talk
);
1798 if (talk
&& uuaddrs
.m_next
)
1799 puts(" -- UUCP Recipients --");
1800 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1801 do_an_address (lp
, talk
);
1803 if (talk
&& netaddrs
.m_next
)
1804 puts(" -- Network Recipients --");
1805 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1806 do_an_address (lp
, talk
);
1809 if (talk
&& !whomsw
)
1810 puts(" -- Address Verification Successful --");
1812 if (!whomsw
|| checksw
)
1813 sm_end (whomsw
? OK
: DONE
);
1821 do_an_address (struct mailname
*lp
, int talk
)
1827 switch (lp
->m_type
) {
1831 strncpy (addr
, mbox
, sizeof(addr
));
1835 mbox
= auxformat (lp
, 0);
1837 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1840 default: /* let SendMail decide if the host is bad */
1843 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1848 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1850 if (whomsw
&& !checksw
) {
1855 fputs(": ", stdout
);
1858 switch (retval
= sm_wadr (mbox
, host
,
1859 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1868 fprintf (stderr
, " %s: ", addr
);
1869 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1870 rp_string (retval
));
1876 fprintf (stderr
, " %s: ", addr
);
1877 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1885 do_text (char *file
, int fd
)
1890 lseek(fd
, 0, SEEK_SET
);
1892 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1893 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1894 fatal (NULL
, "problem writing text; %s\n", rp_string (retval
));
1898 fatal (file
, "problem reading from");
1900 switch (retval
= sm_wtend ()) {
1906 fatal (NULL
, "posting failed; %s", rp_string (retval
));
1910 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1924 (void) m_unlink (tmpfil
);
1925 if (msgflags
& MINV
)
1926 (void) m_unlink (bccfil
);
1928 if (!whomsw
|| checksw
)
1941 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1942 istat
= SIGNAL2 (SIGINT
, sigser
);
1943 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1944 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1954 SIGNAL (SIGHUP
, hstat
);
1955 SIGNAL (SIGINT
, istat
);
1956 SIGNAL (SIGQUIT
, qstat
);
1957 SIGNAL (SIGTERM
, tstat
);
1965 p_refile (char *file
)
1973 puts(" -- Filing Folder Copies --");
1974 for (i
= 0; i
< fccind
; i
++)
1975 fcc (file
, fccfold
[i
]);
1977 puts(" -- Folder Copies Filed --");
1982 * Call the `fileproc' to add the file to the folder.
1986 fcc (char *file
, char *folder
)
1991 char **arglist
, *program
;
1994 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
2001 fprintf (stderr
, " %sFcc %s: ",
2002 msgstate
== RESENT
? "Resent-" : "", folder
);
2003 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
2007 /* see if we need to add `+' */
2008 snprintf (fold
, sizeof(fold
), "%s%s",
2009 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
2011 /* now exec the fileproc */
2013 arglist
= argsplit(fileproc
, &program
, &argp
);
2014 arglist
[argp
++] = "-link";
2015 arglist
[argp
++] = "-file";
2016 arglist
[argp
++] = file
;
2017 arglist
[argp
++] = fold
;
2018 arglist
[argp
] = NULL
;
2019 execvp (program
, arglist
);
2023 if ((status
= pidwait (child_id
, OK
))) {
2025 fprintf (stderr
, " %sFcc %s: ",
2026 msgstate
== RESENT
? "Resent-" : "", folder
);
2027 pidstatus (status
, verbose
? stdout
: stderr
, fileproc
);
2042 fatal (char *what
, char *fmt
, ...)
2049 (void) m_unlink (tmpfil
);
2050 if (msgflags
& MINV
)
2051 (void) m_unlink (bccfil
);
2053 if (!whomsw
|| checksw
)
2058 advertise (what
, NULL
, fmt
, ap
);