]>
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 #ifdef HAVE_SYS_TIME_H
20 # include <sys/time.h>
24 #include <mts/smtp/smtp.h>
27 # define SASLminc(a) (a)
28 #else /* CYRUS_SASL */
29 # define SASLminc(a) 0
30 #endif /* CYRUS_SASL */
33 # define TLSminc(a) (a)
34 #else /* TLS_SUPPORT */
36 #endif /* TLS_SUPPORT */
39 # define OAUTHminc(a) (a)
40 #else /* OAUTH_SUPPORT */
41 # define OAUTHminc(a) 0
42 #endif /* OAUTH_SUPPORT */
44 #define FCCS 10 /* max number of fccs allowed */
46 /* In the following array of structures, the numeric second field of the
47 structures (minchars) is apparently used like this:
49 -# : Switch can be abbreviated to # characters; switch hidden in -help.
50 0 : Switch can't be abbreviated; switch shown in -help.
51 # : Switch can be abbreviated to # characters; switch shown in -help. */
53 #define POST_SWITCHES \
54 X("alias aliasfile", 0, ALIASW) \
55 X("check", -5, CHKSW) /* interface from whom */ \
56 X("nocheck", -7, NCHKSW) /* interface from whom */ \
57 X("debug", -5, DEBUGSW) \
58 X("dist", -4, DISTSW) /* interface from dist */ \
59 X("filter filterfile", 0, FILTSW) \
60 X("nofilter", 0, NFILTSW) \
61 X("format", 0, FRMTSW) \
62 X("noformat", 0, NFRMTSW) \
63 X("library directory", -7, LIBSW) /* interface from send, whom */ \
64 X("mime", 0, MIMESW) \
65 X("nomime", 0, NMIMESW) \
66 X("msgid", 0, MSGDSW) \
67 X("nomsgid", 0, NMSGDSW) \
68 X("verbose", 0, VERBSW) \
69 X("noverbose", 0, NVERBSW) \
70 X("watch", 0, WATCSW) \
71 X("nowatch", 0, NWATCSW) \
72 X("whom", -4, WHOMSW) /* interface from whom */ \
73 X("width columns", 0, WIDTHSW) \
74 X("version", 0, VERSIONSW) \
75 X("help", 0, HELPSW) \
76 X("dashstuffing", -12, BITSTUFFSW) /* should we dashstuff BCC messages? */ \
77 X("nodashstuffing", -14, NBITSTUFFSW) \
78 X("idanno number", -6, ANNOSW) /* interface from send */ \
79 X("client host", -6, CLIESW) \
80 X("server host", 6, SERVSW) /* specify alternate SMTP server */ \
81 X("snoop", -5, SNOOPSW) /* snoop the SMTP transaction */ \
82 X("partno", -6, PARTSW) \
83 X("sasl", SASLminc(4), SASLSW) \
84 X("nosasl", SASLminc(6), NOSASLSW) \
85 X("saslmech", SASLminc(5), SASLMECHSW) \
86 X("user", SASLminc(-4), USERSW) \
87 X("port server submission port name/number", 4, PORTSW) \
88 X("tls", TLSminc(-3), TLSSW) \
89 X("initialtls", TLSminc(-10), INITTLSSW) \
90 X("notls", TLSminc(-5), NTLSSW) \
91 X("certverify", TLSminc(-10), CERTVERSW) \
92 X("nocertverify", TLSminc(-12), NOCERTVERSW) \
93 X("fileproc", -4, FILEPROCSW) \
94 X("mhlproc", -3, MHLPROCSW) \
95 X("sendmail program", 0, MTSSM) \
96 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
97 X("credentials legacy|file:filename", 0, CREDENTIALSSW) \
98 X("messageid localname|random", 2, MESSAGEIDSW) \
99 X("authservice auth-service-name", OAUTHminc(-11), AUTHSERVICESW) \
100 X("oauthcredfile credential-file", OAUTHminc(-7), OAUTHCREDFILESW) \
101 X("oauthclientid client-id", OAUTHminc(-12), OAUTHCLIDSW) \
102 X("oauthclientsecret client-secret", OAUTHminc(-12), OAUTHCLSECSW) \
103 X("oauthauthendpoint authentication-endpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
104 X("oauthredirect redirect-uri", OAUTHminc(-6), OAUTHREDIRSW) \
105 X("oauthtokenendpoint token-endpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
106 X("oauthscope scope", OAUTHminc(-6), OAUTHSCOPESW) \
108 #define X(sw, minchars, id) id,
109 DEFINE_SWITCH_ENUM(POST
);
112 #define X(sw, minchars, id) { sw, minchars, id },
113 DEFINE_SWITCH_ARRAY(POST
, switches
);
118 * Mapping between command-line switches and profile entries, communicated
119 * from 'send'. We use a service name of 'post' internally.
123 const char *profname
;
126 } oauthswitches
[] = {
127 { "oauth-%s-credential-file", OAUTHCREDFILESW
, NULL
},
128 { "oauth-%s-client_id", OAUTHCLIDSW
, NULL
},
129 { "oauth-%s-client_secret", OAUTHCLSECSW
, NULL
},
130 { "oauth-%s-auth_endpoint", OAUTHAUTHENDSW
, NULL
},
131 { "oauth-%s-redirect_uri", OAUTHREDIRSW
, NULL
},
132 { "oauth-%s-token_endpoint", OAUTHTOKENDSW
, NULL
},
133 { "oauth-%s-scope", OAUTHSCOPESW
, NULL
},
144 * flags for headers->flags
146 #define HNOP 0x0000 /* just used to keep .set around */
147 #define HBAD 0x0001 /* bad header - don't let it through */
148 #define HADR 0x0002 /* header has an address field */
149 #define HSUB 0x0004 /* Subject: header */
150 #define HTRY 0x0008 /* try to send to addrs on header */
151 #define HBCC 0x0010 /* don't output this header, unless MTS_SENDMAIL_PIPE */
152 #define HMNG 0x0020 /* munge this header */
153 #define HNGR 0x0040 /* no groups allowed in this header */
154 #define HFCC 0x0080 /* FCC: type header */
155 #define HNIL 0x0100 /* okay for this header not to have addrs */
156 #define HIGN 0x0200 /* ignore this header */
157 #define HDCC 0x0400 /* another undocumented feature */
158 #define HONE 0x0800 /* Only (zero or) one address allowed */
159 #define HEFM 0x1000 /* Envelope-From: header */
160 #define HMIM 0x2000 /* MIME-Version: header */
161 #define HCTE 0x4000 /* Content-Transfer-Encoding: header */
164 * flags for headers->set
166 #define MFRM 0x0001 /* we've seen a From: */
167 #define MDAT 0x0002 /* we've seen a Date: */
168 #define MRFM 0x0004 /* we've seen a Resent-From: */
169 #define MVIS 0x0008 /* we've seen sighted addrs */
170 #define MINV 0x0010 /* we've seen blind addrs */
171 #define MSND 0x0020 /* we've seen a Sender: */
172 #define MRSN 0x0040 /* We've seen a Resent-Sendr:*/
173 #define MEFM 0x0080 /* We've seen Envelope-From: */
174 #define MMIM 0x0100 /* We've seen Mime-Version: */
176 static struct headers NHeaders
[] = {
177 { "Return-Path", HBAD
, 0 },
178 { "Received", HBAD
, 0 },
179 { "Reply-To", HADR
|HNGR
, 0 },
180 { "From", HADR
|HNGR
, MFRM
},
181 { "Sender", HADR
|HNGR
|HONE
, MSND
},
183 { "Subject", HSUB
, 0 },
184 { "To", HADR
|HTRY
, MVIS
},
185 { "cc", HADR
|HTRY
, MVIS
},
186 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, MINV
},
187 { "Dcc", HADR
|HTRY
|HDCC
|HNIL
, MVIS
}, /* sorta cc & bcc combined */
188 { "Message-ID", HBAD
, 0 },
190 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
191 { "MIME-Version", HMIM
, MMIM
},
192 { "Content-Transfer-Encoding", HCTE
, 0 },
196 static struct headers RHeaders
[] = {
197 { "Resent-Reply-To", HADR
|HNGR
, 0 },
198 { "Resent-From", HADR
|HNGR
, MRFM
},
199 { "Resent-Sender", HADR
|HNGR
, MRSN
},
200 { "Resent-Date", HBAD
, 0 },
201 { "Resent-Subject", HSUB
, 0 },
202 { "Resent-To", HADR
|HTRY
, MVIS
},
203 { "Resent-cc", HADR
|HTRY
, MVIS
},
204 { "Resent-Bcc", HADR
|HTRY
|HBCC
, MINV
},
205 { "Resent-Message-ID", HBAD
, 0 },
206 { "Resent-Fcc", HFCC
, 0 },
207 { "Reply-To", HADR
, 0 },
208 { "From", HADR
|HNGR
, MFRM
},
209 { "Sender", HADR
|HNGR
, MSND
},
210 { "Date", HNOP
, MDAT
},
211 { "To", HADR
|HNIL
, 0 },
212 { "cc", HADR
|HNIL
, 0 },
213 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, 0 },
215 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
216 { "MIME-Version", HMIM
, MMIM
},
217 { "Content-Transfer-Encoding", HCTE
, 0 },
221 static short fccind
= 0; /* index into fccfold[] */
222 static short outputlinelen
= OUTPUTLINELEN
;
224 static int pfd
= NOTOK
; /* fd to write annotation list to */
225 static int recipients
= 0; /* how many people will get a copy */
226 static int unkadr
= 0; /* how many of those were unknown */
227 static int badadr
= 0; /* number of bad addrs */
228 static int badmsg
= 0; /* message has bad semantics */
229 static int verbose
= 0; /* spell it out */
230 static int format
= 1; /* format addresses */
231 static int mime
= 0; /* use MIME-style encapsulations for Bcc */
232 static int msgid
= 0; /* add msgid */
233 static int debug
= 0; /* debugging post */
234 static int watch
= 0; /* watch the delivery process */
235 static int whomsw
= 0; /* we are whom not post */
236 static int checksw
= 0; /* whom -check */
237 static int linepos
=0; /* putadr()'s position on the line */
238 static int nameoutput
=0; /* putadr() has output header name */
239 static int sasl
=0; /* Use SASL auth for SMTP */
240 static char *saslmech
=NULL
; /* Force use of particular SASL mech */
241 static char *user
=NULL
; /* Authenticate as this user */
242 static char *port
="submission"; /* Name of server port for SMTP submission */
243 static int tlsflag
=0; /* Flags to control TLS settings */
244 static int fromcount
=0; /* Count of addresses on From: header */
245 static int seensender
=0; /* Have we seen a Sender: header? */
247 static unsigned msgflags
= 0; /* what we've seen */
251 static int msgstate
= NORMAL
;
253 static time_t tclock
= 0; /* the time we started (more or less) */
255 static SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
257 static char tmpfil
[BUFSIZ
];
258 static char bccfil
[BUFSIZ
];
260 static char from
[BUFSIZ
]; /* my network address */
261 static char sender
[BUFSIZ
]; /* my Sender: header */
262 static char efrom
[BUFSIZ
]; /* my Envelope-From: header */
263 static char fullfrom
[BUFSIZ
]; /* full contents of From header */
264 static char *filter
= NULL
; /* the filter for BCC'ing */
265 static char *subject
= NULL
; /* the subject field for BCC'ing */
266 static char *fccfold
[FCCS
]; /* foldernames for FCC'ing */
267 enum encoding
{ UNKNOWN
= 0, BINARY
= 1, SEVENBIT
= 7, EIGHTBIT
= 8 };
268 static enum encoding cte
= UNKNOWN
;
270 static struct headers
*hdrtab
; /* table for the message we're doing */
272 static struct mailname localaddrs
; /* local addrs */
273 static struct mailname netaddrs
; /* network addrs */
274 static struct mailname uuaddrs
; /* uucp addrs */
275 static struct mailname tmpaddrs
; /* temporary queue */
277 static int snoop
= 0;
278 static char *clientsw
= NULL
;
279 static char *serversw
= NULL
;
281 static char prefix
[] = "----- =_aaaaaaaaaa";
283 static char *partno
= NULL
;
288 static void putfmt (char *, char *, int *, FILE *);
289 static void start_headers (void);
290 static void finish_headers (FILE *);
291 static int get_header (char *, struct headers
*);
292 static int putadr (char *, char *, struct mailname
*, FILE *, unsigned int);
293 static void putgrp (char *, char *, FILE *, unsigned int);
294 static int insert (struct mailname
*);
295 static void pl (void);
296 static void anno (void);
297 static int annoaux (struct mailname
*);
298 static void insert_fcc (struct headers
*, char *);
299 static void make_bcc_file (int);
300 static void verify_all_addresses (int, int, char *, int, char *);
301 static void chkadr (void);
302 static void sigon (void);
303 static void sigoff (void);
304 static void p_refile (char *);
305 static void fcc (char *, char *);
306 static void die (char *, char *, ...);
307 static void post (char *, int, int, int, char *, int, char *);
308 static void do_text (char *file
, int fd
);
309 static void do_an_address (struct mailname
*, int);
310 static void do_addresses (int, int);
311 static int find_prefix (void);
315 main (int argc
, char **argv
)
317 int state
, compnum
, dashstuff
= 0, swnum
, oauth_flag
= 0, tls
= -1;
319 int eai
= 0; /* use Email Address Internationalization (EAI) (SMTPUTF8) */
320 char *cp
, *msg
= NULL
, **argp
, **arguments
, *envelope
;
321 char buf
[BUFSIZ
], name
[NAMESZ
], *auth_svc
= NULL
;
323 m_getfld_state_t gstate
= 0;
325 if (nmh_init(argv
[0], 0 /* use context_foil() */)) { return 1; }
328 arguments
= getarguments (invo_name
, argc
, argv
, 0);
331 while ((cp
= *argp
++)) {
333 switch ((swnum
= smatch (++cp
, switches
))) {
335 ambigsw (cp
, switches
);
338 adios (NULL
, "-%s unknown", cp
);
341 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
342 print_help (buf
, switches
, 0);
345 print_version(invo_name
);
349 if (!(cp
= *argp
++) || *cp
== '-')
350 adios (NULL
, "missing argument to %s", argp
[-2]);
351 /* create a minimal context */
352 if (context_foil (cp
) == -1)
357 if (!(cp
= *argp
++) || *cp
== '-')
358 adios (NULL
, "missing argument to %s", argp
[-2]);
359 if ((state
= alias (cp
)) != AK_OK
)
360 adios (NULL
, "aliasing error in %s - %s",
361 cp
, akerror (state
));
380 if (!(filter
= *argp
++) || *filter
== '-')
381 adios (NULL
, "missing argument to %s", argp
[-2]);
436 if (!(cp
= *argp
++) || *cp
== '-')
437 adios (NULL
, "missing argument to %s", argp
[-2]);
438 if ((outputlinelen
= atoi (cp
)) < 10)
439 adios (NULL
, "impossible width %d", outputlinelen
);
443 if (!(cp
= *argp
++) || *cp
== '-')
444 adios (NULL
, "missing argument to %s", argp
[-2]);
445 if ((pfd
= atoi (cp
)) <= 2)
446 adios (NULL
, "bad argument %s %s", argp
[-2], cp
);
450 if (!(clientsw
= *argp
++) || *clientsw
== '-')
451 adios (NULL
, "missing argument to %s", argp
[-2]);
454 if (!(serversw
= *argp
++) || *serversw
== '-')
455 adios (NULL
, "missing argument to %s", argp
[-2]);
462 if (!(partno
= *argp
++) || *partno
== '-')
463 adios (NULL
, "missing argument to %s", argp
[-2]);
475 if (!(saslmech
= *argp
++) || *saslmech
== '-')
476 adios (NULL
, "missing argument to %s", argp
[-2]);
480 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
481 adios (NULL
, "missing argument to %s", argp
[-2]);
485 case OAUTHCREDFILESW
:
495 if (!(cp
= *argp
++) || *cp
== '-')
496 adios (NULL
, "missing argument to %s", argp
[-2]);
498 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
499 if (oauthswitches
[i
].switchnum
== swnum
) {
500 oauthswitches
[i
].value
= cp
;
505 if (oauthswitches
[i
].profname
== NULL
)
506 adios (NULL
, "internal error: cannot map switch %s "
507 "to profile entry", argp
[-2]);
514 if (!(user
= *argp
++) || *user
== '-')
515 adios (NULL
, "missing argument to %s", argp
[-2]);
519 if (!(port
= *argp
++) || *port
== '-')
520 adios (NULL
, "missing argument to %s", argp
[-2]);
544 if (!(cp
= *argp
++) || *cp
== '-')
545 adios (NULL
, "missing argument to %s", argp
[-2]);
550 if (!(cp
= *argp
++) || *cp
== '-')
551 adios (NULL
, "missing argument to %s", argp
[-2]);
556 if (!(cp
= *argp
++) || *cp
== '-')
557 adios (NULL
, "missing argument to %s", argp
[-2]);
562 if (!(cp
= *argp
++) || *cp
== '-')
563 adios (NULL
, "missing argument to %s", argp
[-2]);
564 save_mts_method (cp
);
567 case CREDENTIALSSW
: {
568 if (!(cp
= *argp
++) || *cp
== '-')
569 adios (NULL
, "missing argument to %s", argp
[-2]);
570 add_profile_entry ("credentials", cp
);
575 if (!(cp
= *argp
++) || *cp
== '-')
576 adios (NULL
, "missing argument to %s", argp
[-2]);
577 if (save_message_id_style (cp
) != 0)
578 adios (NULL
, "unsupported messageid \"%s\"", cp
);
583 adios (NULL
, "only one message at a time!");
591 adios (NULL
, "usage: %s [switches] file", invo_name
);
593 if (outputlinelen
< 10)
594 adios (NULL
, "impossible width %d", outputlinelen
);
596 if ((in
= fopen (msg
, "r")) == NULL
)
597 adios (msg
, "unable to open");
605 if ((out
= fopen ("/dev/null", "w")) == NULL
)
606 adios ("/dev/null", "unable to open");
608 char *cp
= m_mktemp2(NULL
, invo_name
, NULL
, &out
);
610 adios(NULL
, "unable to create temporary file in %s",
613 strncpy(tmpfil
, cp
, sizeof(tmpfil
));
617 hdrtab
= msgstate
== NORMAL
? NHeaders
: RHeaders
;
619 for (compnum
= 1;;) {
620 int bufsz
= sizeof buf
;
621 switch (state
= m_getfld (&gstate
, name
, buf
, &bufsz
, in
)) {
625 cp
= mh_xstrdup(buf
);
626 while (state
== FLDPLUS
) {
628 state
= m_getfld (&gstate
, name
, buf
, &bufsz
, in
);
631 putfmt (name
, cp
, &eai
, out
);
636 finish_headers (out
);
639 fprintf (out
, "\n%s", buf
);
640 while (state
== BODY
) {
642 state
= m_getfld (&gstate
, name
, buf
, &bufsz
, in
);
648 finish_headers (out
);
653 adios (NULL
, "message format error in component #%d", compnum
);
656 adios (NULL
, "getfld() returned %d", state
);
660 m_getfld_state_destroy (&gstate
);
674 * Here's how we decide which address to use as the envelope-from
677 * - If we were given an Envelope-From header, use that.
678 * - If we were given a Sender: address, use that.
679 * - Otherwise, use the address on the From: line
682 if (msgflags
& MEFM
) {
684 } else if (seensender
) {
693 * The user didn't specify any of the tls switches. Try to
694 * help them by implying -initialtls if they're using port 465
695 * (smtps, until IANA revoked that registration in 1998).
697 tls
= ! strcmp (port
, "465") || ! strcasecmp (port
, "smtps")
700 #else /* ! TLS_SUPPORT */
702 #endif /* ! TLS_SUPPORT */
706 tlsflag
= S_STARTTLS
;
713 tlsflag
|= S_NOVERIFY
;
716 * If we were given any oauth flags, store the appropriate profile
717 * entries and make sure an authservice was given (we have to do this
718 * here because we aren't guaranteed the authservice will be given on
719 * the command line before the other OAuth flags are given).
726 if (auth_svc
== NULL
) {
727 adios(NULL
, "No authentication service given with -authservice");
730 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
731 if (oauthswitches
[i
].value
!= NULL
) {
732 snprintf(sbuf
, sizeof(sbuf
),
733 oauthswitches
[i
].profname
, auth_svc
);
734 sbuf
[sizeof(sbuf
) - 1] = '\0';
735 add_profile_entry(sbuf
, oauthswitches
[i
].value
);
740 /* If we are doing a "whom" check */
742 /* This won't work with MTS_SENDMAIL_PIPE. */
743 verify_all_addresses (1, eai
, envelope
, oauth_flag
, auth_svc
);
747 if (msgflags
& MINV
) {
748 make_bcc_file (dashstuff
);
749 if (msgflags
& MVIS
) {
750 if (sm_mts
!= MTS_SENDMAIL_PIPE
) {
751 /* It would be nice to have support to call
752 verify_all_addresses with MTS_SENDMAIL_PIPE, but
753 that might require running sendmail as root. Note
754 that spost didn't verify addresses. */
755 verify_all_addresses (verbose
, eai
, envelope
, oauth_flag
,
758 post (tmpfil
, 0, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
760 post (bccfil
, 1, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
761 (void) m_unlink (bccfil
);
763 post (tmpfil
, 0, isatty (1), eai
, envelope
, oauth_flag
, auth_svc
);
767 (void) m_unlink (tmpfil
);
771 printf ("Partial Message #%s Processed\n", partno
);
773 puts("Message Processed");
786 putfmt (char *name
, char *str
, int *eai
, FILE *out
)
788 int count
, grp
, i
, keep
;
790 char namep
[BUFSIZ
], error
[BUFSIZ
];
791 struct mailname
*mp
= NULL
, *np
= NULL
;
794 while (*str
== ' ' || *str
== '\t')
797 if (msgstate
== NORMAL
&& uprf (name
, "resent")) {
798 inform("illegal header line -- %s:", name
);
804 /* Check each header field value to see if it has any 8-bit characters.
805 If it does, enable EAI support. */
806 if (contains8bit(str
, NULL
)) {
808 puts("EAI/SMTPUTF8 enabled");
811 /* Enable SMTPUTF8. */
814 /* Enable passing of utf-8 setting to getname()/getadrx(). */
819 if ((i
= get_header (name
, hdrtab
)) == NOTOK
) {
820 if (strncasecmp (name
, "nmh-", 4)) {
821 fprintf (out
, "%s: %s", name
, str
);
823 /* Filter out all Nmh-* headers, because Norm asked. They
824 should never have reached this point. Warn about any
825 that are non-empty. */
826 if (strcmp (str
, "\n")) {
827 trim_suffix_c(str
, '\n');
829 inform("ignoring header line -- %s: %s", name
, str
);
838 if (hdr
->flags
& HIGN
) {
841 if (hdr
->flags
& HBAD
) {
842 inform("illegal header line -- %s:", name
);
846 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
848 if (hdr
->flags
& HSUB
)
849 subject
= subject
? add (str
, add ("\t", subject
)) : mh_xstrdup(str
);
850 if (hdr
->flags
& HFCC
) {
851 if ((cp
= strrchr(str
, '\n')))
853 for (pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
855 insert_fcc (hdr
, pp
);
857 insert_fcc (hdr
, pp
);
860 if (hdr
->flags
& HCTE
) {
861 if (strncasecmp (str
, "7bit", 4) == 0) {
863 } else if (strncasecmp (str
, "8bit", 4) == 0) {
865 } else if (strncasecmp (str
, "binary", 6) == 0) {
869 if (!(hdr
->flags
& HADR
)) {
870 fprintf (out
, "%s: %s", name
, str
);
874 tmpaddrs
.m_next
= NULL
;
876 for (count
= 0; (cp
= getname (str
)); count
++) {
877 if ((mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
881 tmpaddrs
.m_next
= mp
;
885 admonish(cp
, "%s", error
);
886 if (hdr
->flags
& HTRY
)
894 if (hdr
->flags
& HNIL
)
895 fprintf (out
, "%s: %s", name
, str
);
898 * Sender (or Resent-Sender) can have only one address
900 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
901 : (hdr
->set
& MSND
)) {
902 inform("%s: field requires one address", name
);
906 inform("%s: field requires at least one address", name
);
913 if (count
> 1 && (hdr
->flags
& HONE
)) {
914 inform("%s: field only permits one address", name
);
919 nameoutput
= linepos
= 0;
920 snprintf (namep
, sizeof(namep
), "%s%s",
921 (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
923 for (grp
= 0, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
924 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
925 /* The address doesn't include a host, so it might be an alias. */
926 pp
= akvalue (mp
->m_mbox
); /* do mh alias substitution */
927 qp
= akvisible () ? mp
->m_mbox
: "";
930 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
931 while ((cp
= getname (pp
))) {
932 if (!(mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
933 admonish(cp
, "%s", error
);
939 * If it's a From: or Resent-From: header, save the address
940 * for later possible use (as the envelope address for SMTP)
943 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
944 : (hdr
->set
& MFRM
)) {
945 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
946 from
[sizeof(from
) - 1] = '\0';
951 * Also save the Sender: or Resent-Sender: header as well
954 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
955 : (hdr
->set
& MSND
)) {
956 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
957 sender
[sizeof(sender
) - 1] = '\0';
962 * ALSO ... save Envelope-From
965 if (hdr
->set
& MEFM
) {
966 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
967 efrom
[sizeof(efrom
) - 1] = '\0';
970 if (hdr
->flags
& HBCC
)
973 mp
->m_ingrp
= np
->m_ingrp
;
976 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
978 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
979 /* Catch this before sendmail chokes with:
980 "553 List:; syntax illegal for recipient
982 If we wanted to, we could expand out blind
983 aliases and put them in Bcc:, but then
984 they'd have the Blind-Carbon-Copy
987 "blind lists not compatible with"
993 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
))
994 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1003 /* Address includes a host, so no alias substitution is needed. */
1006 * If it's a From: or Resent-From header, save the address
1007 * for later possible use (as the envelope address for SMTP)
1010 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
1011 : (hdr
->set
& MFRM
)) {
1012 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
1017 * Also save the Sender: header as well
1020 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
1021 : (hdr
->set
& MSND
)) {
1022 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
1023 sender
[sizeof(sender
) - 1] = '\0';
1028 * ALSO ... save Envelope-From
1031 if (hdr
->set
& MEFM
) {
1032 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1033 efrom
[sizeof(efrom
) - 1] = '\0';
1036 if (hdr
->flags
& HBCC
)
1039 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1042 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
);
1046 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1053 * If this is a From:/Resent-From: header, save the full thing for
1054 * later in case we need it for use when constructing a Bcc draft message
1057 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
1058 strncpy(fullfrom
, str
, sizeof(fullfrom
));
1059 fullfrom
[sizeof(fullfrom
) - 1] = 0;
1061 * Strip off any trailing newlines
1064 while (*fullfrom
&& fullfrom
[strlen(fullfrom
) - 1] == '\n') {
1065 fullfrom
[strlen(fullfrom
) - 1] = '\0';
1069 if (grp
> 0 && (hdr
->flags
& HNGR
)) {
1070 inform("%s: field does not allow groups", name
);
1080 start_headers (void)
1085 * Probably not necessary, but just in case ...
1096 * Now that we've outputted the header fields in the draft
1097 * message, we will now output any remaining header fields
1098 * that we need to add/create.
1102 finish_headers (FILE *out
)
1106 if (!(msgflags
& MFRM
)) {
1108 * A From: header is now required in the draft.
1110 inform("message has no From: header");
1111 inform("See default components files for examples");
1116 if (fromcount
> 1 && (seensender
== 0 && !(msgflags
& MEFM
))) {
1117 inform("A Sender: or Envelope-From: header is required "
1118 "with multiple\nFrom: addresses");
1126 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1128 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1130 * If we have multiple From: addresses, make sure we have an
1131 * Sender: header. If we don't have one, then generate one
1132 * from Envelope-From: (which in this case, cannot be blank)
1135 if (fromcount
> 1 && seensender
== 0) {
1136 if (efrom
[0] == '\0') {
1137 inform("Envelope-From cannot be blank when there "
1138 "is multiple From: addresses\nand no Sender: "
1142 fprintf (out
, "Sender: %s\n", efrom
);
1146 if (!(msgflags
& MVIS
))
1147 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
1151 if (!(msgflags
& MDAT
)) {
1152 inform("message has no Date: header");
1155 if (!(msgflags
& MFRM
)) {
1156 inform("message has no From: header");
1159 if (!(msgflags
& MRFM
)) {
1160 inform("message has no Resent-From: header");
1161 inform("See default components files for examples");
1165 if (fromcount
> 1 && (seensender
== 0 && !(msgflags
& MEFM
))) {
1166 inform("A Resent-Sender: or Envelope-From: header is "
1167 "required with multiple\nResent-From: addresses");
1175 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
1177 fprintf (out
, "Resent-Message-ID: %s\n",
1178 message_id (tclock
, 0));
1180 * If we have multiple Resent-From: addresses, make sure we have an
1181 * Resent-Sender: header. If we don't have one, then generate one
1182 * from Envelope-From (which in this case, cannot be blank)
1185 if (fromcount
> 1 && seensender
== 0) {
1186 if (efrom
[0] == '\0') {
1187 inform("Envelope-From cannot be blank when there "
1188 "is multiple Resent-From: addresses and no "
1189 "Resent-Sender: header");
1192 fprintf (out
, "Resent-Sender: %s\n", efrom
);
1196 if (!(msgflags
& MVIS
))
1197 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
1202 adios (NULL
, "re-format message and try again");
1204 adios (NULL
, "no addressees");
1209 get_header (char *header
, struct headers
*table
)
1213 for (h
= table
; h
->value
; h
++)
1214 if (!strcasecmp (header
? header
: "", h
->value
? h
->value
: ""))
1222 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
, unsigned int flags
)
1226 char buffer
[BUFSIZ
];
1228 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
1230 if (sm_mts
!= MTS_SENDMAIL_PIPE
&&
1231 ((flags
& (HBCC
| HDCC
| HEFM
)) || mp
->m_ingrp
))
1235 fprintf (out
, "%s: ", name
);
1236 linepos
+= (nameoutput
= strlen (name
) + 2);
1239 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
1240 mp
->m_pers
= mh_xstrdup(aka
);
1243 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
1246 cp
= adrformat (mp
);
1253 if (linepos
!= nameoutput
) {
1254 if (len
+ linepos
+ 2 > outputlinelen
)
1255 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
1265 return (flags
& HTRY
);
1270 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
1275 if (sm_mts
!= MTS_SENDMAIL_PIPE
&& (flags
& HBCC
))
1279 fprintf (out
, "%s: ", name
);
1280 linepos
+= (nameoutput
= strlen (name
) + 2);
1283 cp
= concat (group
, ";", NULL
);
1286 if (linepos
> nameoutput
) {
1287 if (len
+ linepos
+ 2 > outputlinelen
) {
1288 fprintf (out
, ",\n%*s", nameoutput
, "");
1289 linepos
= nameoutput
;
1303 insert (struct mailname
*np
)
1305 struct mailname
*mp
;
1307 if (np
->m_mbox
== NULL
)
1310 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1311 : np
->m_type
== UUCPHOST
? &uuaddrs
1315 if (!strcasecmp (np
->m_host
? np
->m_host
: "",
1316 mp
->m_next
->m_host
? mp
->m_next
->m_host
: "") &&
1317 !strcasecmp (np
->m_mbox
? np
->m_mbox
: "",
1318 mp
->m_next
->m_mbox
? mp
->m_next
->m_mbox
: "") &&
1319 np
->m_bcc
== mp
->m_next
->m_bcc
)
1332 struct mailname
*mp
;
1334 printf ("-------\n\t-- Addresses --\nlocal:\t");
1335 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1336 printf ("%s%s%s", mp
->m_mbox
,
1337 mp
->m_bcc
? "[BCC]" : "",
1338 mp
->m_next
? ",\n\t" : "");
1340 printf ("\nnet:\t");
1341 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1342 printf ("%s%s@%s%s%s", mp
->m_path
? mp
->m_path
: "",
1343 mp
->m_mbox
, mp
->m_host
,
1344 mp
->m_bcc
? "[BCC]" : "",
1345 mp
->m_next
? ",\n\t" : "");
1347 printf ("\nuucp:\t");
1348 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1349 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1350 mp
->m_bcc
? "[BCC]" : "",
1351 mp
->m_next
? ",\n\t" : "");
1353 printf ("\n\t-- Folder Copies --\nfcc:\t");
1354 for (i
= 0; i
< fccind
; i
++)
1355 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1363 struct mailname
*mp
;
1365 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1366 if (annoaux (mp
) == NOTOK
)
1369 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1370 if (annoaux (mp
) == NOTOK
)
1373 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1374 if (annoaux (mp
) == NOTOK
)
1384 annoaux (struct mailname
*mp
)
1387 char buffer
[BUFSIZ
];
1389 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1390 i
= strlen (buffer
);
1392 return (write (pfd
, buffer
, i
) == i
? OK
: NOTOK
);
1397 insert_fcc (struct headers
*hdr
, char *pp
)
1401 for (cp
= pp
; isspace ((unsigned char) *cp
); cp
++)
1403 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace ((unsigned char) *pp
); pp
--)
1411 adios (NULL
, "too many %ss", hdr
->value
);
1412 fccfold
[fccind
++] = mh_xstrdup(cp
);
1420 make_bcc_file (int dashstuff
)
1426 char *tfile
= NULL
, *program
;
1428 if ((tfile
= m_mktemp2(NULL
, "bccs", NULL
, &out
)) == NULL
) {
1429 adios(NULL
, "unable to create temporary file in %s", get_temp_dir());
1431 strncpy (bccfil
, tfile
, sizeof(bccfil
));
1433 fprintf (out
, "From: %s\n", fullfrom
);
1434 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1436 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1438 fprintf (out
, "Subject: %s", subject
);
1439 fprintf (out
, "BCC:\n");
1442 * Use MIME encapsulation for Bcc messages
1448 * Check if any lines in the message clash with the
1449 * prefix for the MIME multipart separator. If there
1450 * is a clash, increment one of the letters in the
1451 * prefix and check again.
1453 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1454 adios (NULL
, "lost prefix start");
1455 while (find_prefix () == NOTOK
) {
1460 adios (NULL
, "can't find a unique delimiter string");
1465 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1466 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1467 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1469 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1475 * Do mhl filtering of Bcc messages instead
1476 * of MIME encapsulation.
1478 if (filter
!= NULL
) {
1479 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
1483 adios ("fork", "unable to");
1486 dup2 (fileno (out
), 1);
1488 vec
= argsplit(mhlproc
, &program
, &i
);
1489 vec
[i
++] = "-forward";
1494 /* was the flag -[no]dashstuffing specified? */
1496 vec
[i
++] = "-dashstuffing";
1497 else if (dashstuff
< 0)
1498 vec
[i
++] = "-nodashstuffing";
1501 execvp (program
, vec
);
1502 fprintf (stderr
, "unable to exec ");
1507 pidXwait (child_id
, mhlproc
);
1511 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1512 adios (tmpfil
, "unable to re-open");
1515 * If using MIME encapsulation, or if the -nodashstuffing
1516 * flag was given, then just copy message. Else do
1517 * RFC934 quoting (dashstuffing).
1519 if (mime
|| dashstuff
< 0)
1520 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1522 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1526 fseek (out
, 0L, SEEK_END
);
1528 fprintf (out
, "\n--%s--\n", prefix
);
1530 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1536 * Scan message to check if any lines clash with
1537 * the prefix of the MIME multipart separator.
1544 char buffer
[BUFSIZ
];
1547 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1548 adios (tmpfil
, "unable to re-open");
1550 while (fgets (buffer
, sizeof buffer
, in
))
1551 if (buffer
[0] == '-' && buffer
[1] == '-') {
1554 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1555 if (!isspace ((unsigned char) *cp
))
1558 if (strcmp (buffer
+ 2, prefix
) == 0) {
1569 #define plural(x) (x == 1 ? "" : "s")
1574 if (badadr
&& unkadr
)
1575 die (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1576 badadr
, plural (badadr
), unkadr
, plural (badadr
));
1578 die (NULL
, "%d address%s unparsable", badadr
, plural (badadr
));
1580 die (NULL
, "%d addressee%s undeliverable", unkadr
, plural (unkadr
));
1585 do_addresses (int bccque
, int talk
)
1589 struct mailname
*lp
;
1592 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1593 if (lp
->m_bcc
? bccque
: !bccque
) {
1595 puts(" -- Local Recipients --");
1596 do_an_address (lp
, talk
);
1601 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1602 if (lp
->m_bcc
? bccque
: !bccque
) {
1604 puts(" -- UUCP Recipients --");
1605 do_an_address (lp
, talk
);
1610 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1611 if (lp
->m_bcc
? bccque
: !bccque
) {
1613 puts(" -- Network Recipients --");
1614 do_an_address (lp
, talk
);
1620 if (rp_isbad (retval
= sm_waend ()))
1621 die (NULL
, "problem ending addresses; %s", rp_string (retval
));
1626 * MTS-SPECIFIC INTERACTION
1631 * SENDMAIL/SMTP routines
1635 post (char *file
, int bccque
, int talk
, int eai
, char *envelope
,
1636 int oauth_flag
, char *auth_svc
)
1642 if (msgflags
& MINV
)
1643 printf (" -- Posting for %s Recipients --\n",
1644 bccque
? "Blind" : "Sighted");
1646 puts(" -- Posting for All Recipients --");
1651 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1652 char **argp
, *program
;
1655 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
1659 adios ("fork", "unable to");
1662 if (freopen( file
, "r", stdin
) == NULL
) {
1663 adios (file
, "can't reopen for sendmail");
1666 argp
= argsplit(sendmail
, &program
, &argc
);
1667 argp
[argc
++] = "-t"; /* read msg for recipients */
1668 argp
[argc
++] = "-i"; /* don't stop on "." */
1670 argp
[argc
++] = "-bv";
1672 argp
[argc
++] = "-v";
1675 execv (program
, argp
);
1676 adios (sendmail
, "can't exec");
1679 pidXwait (child_id
, NULL
);
1683 const int fd
= open (file
, O_RDONLY
);
1687 die (file
, "unable to re-open");
1690 if (msgflags
& MMIM
&& cte
!= UNKNOWN
) {
1691 /* MIME message with C-T-E header. (BINARYMIME isn't
1692 supported, use 8BITMIME instead for binary.) */
1693 eightbit
= cte
!= SEVENBIT
;
1695 if (scan_input (fd
, &eightbit
) == NOTOK
) {
1697 die (file
, "problem reading from");
1701 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1702 verbose
, snoop
, sasl
, saslmech
, user
,
1703 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1704 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1706 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1709 do_addresses (bccque
, talk
&& verbose
);
1714 sm_end (!(msgflags
& MINV
) || bccque
? OK
: DONE
);
1718 if (msgflags
& MINV
)
1719 printf (" -- %s Recipient Copies Posted --\n",
1720 bccque
? "Blind" : "Sighted");
1722 puts(" -- Recipient Copies Posted --");
1730 /* Address Verification */
1733 verify_all_addresses (int talk
, int eai
, char *envelope
, int oauth_flag
,
1737 struct mailname
*lp
;
1741 if (!whomsw
|| checksw
) {
1742 /* Not sending message body, so don't need to use 8BITMIME. */
1743 const int eightbit
= 0;
1745 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1746 verbose
, snoop
, sasl
, saslmech
, user
,
1747 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1748 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1749 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1753 if (talk
&& !whomsw
)
1754 puts(" -- Address Verification --");
1755 if (talk
&& localaddrs
.m_next
)
1756 puts(" -- Local Recipients --");
1757 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1758 do_an_address (lp
, talk
);
1760 if (talk
&& uuaddrs
.m_next
)
1761 puts(" -- UUCP Recipients --");
1762 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1763 do_an_address (lp
, talk
);
1765 if (talk
&& netaddrs
.m_next
)
1766 puts(" -- Network Recipients --");
1767 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1768 do_an_address (lp
, talk
);
1771 if (talk
&& !whomsw
)
1772 puts(" -- Address Verification Successful --");
1774 if (!whomsw
|| checksw
)
1783 do_an_address (struct mailname
*lp
, int talk
)
1789 switch (lp
->m_type
) {
1793 strncpy (addr
, mbox
, sizeof(addr
));
1797 mbox
= auxformat (lp
, 0);
1799 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1802 default: /* let SendMail decide if the host is bad */
1805 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1810 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1812 if (whomsw
&& !checksw
) {
1820 switch (retval
= sm_wadr (mbox
, host
,
1821 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1830 fprintf (stderr
, " %s: ", addr
);
1831 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1832 rp_string (retval
));
1838 fprintf (stderr
, " %s: ", addr
);
1839 die (NULL
, "unexpected response; %s", rp_string (retval
));
1847 do_text (char *file
, int fd
)
1852 lseek (fd
, (off_t
) 0, SEEK_SET
);
1854 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1855 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1856 die (NULL
, "problem writing text; %s\n", rp_string (retval
));
1860 die (file
, "problem reading from");
1862 switch (retval
= sm_wtend ()) {
1868 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
, ...)
2013 (void) m_unlink (tmpfil
);
2014 if (msgflags
& MINV
)
2015 (void) m_unlink (bccfil
);
2017 if (!whomsw
|| checksw
)
2022 advertise (what
, NULL
, fmt
, ap
);