]>
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("fileproc", -4, FILEPROCSW) \
93 X("mhlproc", -3, MHLPROCSW) \
94 X("sendmail program", 0, MTSSM) \
95 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
96 X("credentials legacy|file:filename", 0, CREDENTIALSSW) \
97 X("messageid localname|random", 2, MESSAGEIDSW) \
98 X("authservice auth-service-name", OAUTHminc(-11), AUTHSERVICESW) \
99 X("oauthcredfile credential-file", OAUTHminc(-7), OAUTHCREDFILESW) \
100 X("oauthclientid client-id", OAUTHminc(-12), OAUTHCLIDSW) \
101 X("oauthclientsecret client-secret", OAUTHminc(-12), OAUTHCLSECSW) \
102 X("oauthauthendpoint authentication-endpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
103 X("oauthredirect redirect-uri", OAUTHminc(-6), OAUTHREDIRSW) \
104 X("oauthtokenendpoint token-endpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
105 X("oauthscope scope", OAUTHminc(-6), OAUTHSCOPESW) \
107 #define X(sw, minchars, id) id,
108 DEFINE_SWITCH_ENUM(POST
);
111 #define X(sw, minchars, id) { sw, minchars, id },
112 DEFINE_SWITCH_ARRAY(POST
, switches
);
117 * Mapping between command-line switches and profile entries, communicated
118 * from 'send'. We use a service name of 'post' internally.
121 static struct oauth_profile
{
122 const char *profname
;
125 } oauthswitches
[] = {
126 { "oauth-%s-credential-file", OAUTHCREDFILESW
, NULL
},
127 { "oauth-%s-client_id", OAUTHCLIDSW
, NULL
},
128 { "oauth-%s-client_secret", OAUTHCLSECSW
, NULL
},
129 { "oauth-%s-auth_endpoint", OAUTHAUTHENDSW
, NULL
},
130 { "oauth-%s-redirect_uri", OAUTHREDIRSW
, NULL
},
131 { "oauth-%s-token_endpoint", OAUTHTOKENDSW
, NULL
},
132 { "oauth-%s-scope", OAUTHSCOPESW
, NULL
},
143 * flags for headers->flags
145 #define HNOP 0x0000 /* just used to keep .set around */
146 #define HBAD 0x0001 /* bad header - don't let it through */
147 #define HADR 0x0002 /* header has an address field */
148 #define HSUB 0x0004 /* Subject: header */
149 #define HTRY 0x0008 /* try to send to addrs on header */
150 #define HBCC 0x0010 /* don't output this header, unless MTS_SENDMAIL_PIPE */
151 #define HMNG 0x0020 /* munge this header */
152 #define HNGR 0x0040 /* no groups allowed in this header */
153 #define HFCC 0x0080 /* FCC: type header */
154 #define HNIL 0x0100 /* okay for this header not to have addrs */
155 #define HIGN 0x0200 /* ignore this header */
156 #define HDCC 0x0400 /* another undocumented feature */
157 #define HONE 0x0800 /* Only (zero or) one address allowed */
158 #define HEFM 0x1000 /* Envelope-From: header */
159 #define HMIM 0x2000 /* MIME-Version: header */
160 #define HCTE 0x4000 /* Content-Transfer-Encoding: header */
163 * flags for headers->set
165 #define MFRM 0x0001 /* we've seen a From: */
166 #define MDAT 0x0002 /* we've seen a Date: */
167 #define MRFM 0x0004 /* we've seen a Resent-From: */
168 #define MVIS 0x0008 /* we've seen sighted addrs */
169 #define MINV 0x0010 /* we've seen blind addrs */
170 #define MSND 0x0020 /* we've seen a Sender: */
171 #define MRSN 0x0040 /* We've seen a Resent-Sendr:*/
172 #define MEFM 0x0080 /* We've seen Envelope-From: */
173 #define MMIM 0x0100 /* We've seen Mime-Version: */
175 static struct headers NHeaders
[] = {
176 { "Return-Path", HBAD
, 0 },
177 { "Received", HBAD
, 0 },
178 { "Reply-To", HADR
|HNGR
, 0 },
179 { "From", HADR
|HNGR
, MFRM
},
180 { "Sender", HADR
|HNGR
|HONE
, MSND
},
182 { "Subject", HSUB
, 0 },
183 { "To", HADR
|HTRY
, MVIS
},
184 { "cc", HADR
|HTRY
, MVIS
},
185 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, MINV
},
186 { "Dcc", HADR
|HTRY
|HDCC
|HNIL
, MVIS
}, /* sorta cc & bcc combined */
187 { "Message-ID", HBAD
, 0 },
189 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
190 { "MIME-Version", HMIM
, MMIM
},
191 { "Content-Transfer-Encoding", HCTE
, 0 },
195 static struct headers RHeaders
[] = {
196 { "Resent-Reply-To", HADR
|HNGR
, 0 },
197 { "Resent-From", HADR
|HNGR
, MRFM
},
198 { "Resent-Sender", HADR
|HNGR
, MRSN
},
199 { "Resent-Date", HBAD
, 0 },
200 { "Resent-Subject", HSUB
, 0 },
201 { "Resent-To", HADR
|HTRY
, MVIS
},
202 { "Resent-cc", HADR
|HTRY
, MVIS
},
203 { "Resent-Bcc", HADR
|HTRY
|HBCC
, MINV
},
204 { "Resent-Message-ID", HBAD
, 0 },
205 { "Resent-Fcc", HFCC
, 0 },
206 { "Reply-To", HADR
, 0 },
207 { "From", HADR
|HNGR
, MFRM
},
208 { "Sender", HADR
|HNGR
, MSND
},
209 { "Date", HNOP
, MDAT
},
210 { "To", HADR
|HNIL
, 0 },
211 { "cc", HADR
|HNIL
, 0 },
212 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, 0 },
214 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
215 { "MIME-Version", HMIM
, MMIM
},
216 { "Content-Transfer-Encoding", HCTE
, 0 },
220 static short fccind
= 0; /* index into fccfold[] */
221 static short outputlinelen
= OUTPUTLINELEN
;
223 static int pfd
= NOTOK
; /* fd to write annotation list to */
224 static int recipients
= 0; /* how many people will get a copy */
225 static int unkadr
= 0; /* how many of those were unknown */
226 static int badadr
= 0; /* number of bad addrs */
227 static int badmsg
= 0; /* message has bad semantics */
228 static int verbose
= 0; /* spell it out */
229 static int format
= 1; /* format addresses */
230 static int mime
= 0; /* use MIME-style encapsulations for Bcc */
231 static int msgid
= 0; /* add msgid */
232 static int debug
= 0; /* debugging post */
233 static int watch
= 0; /* watch the delivery process */
234 static int whomsw
= 0; /* we are whom not post */
235 static int checksw
= 0; /* whom -check */
236 static int linepos
=0; /* putadr()'s position on the line */
237 static int nameoutput
=0; /* putadr() has output header name */
238 static int sasl
=0; /* Use SASL auth for SMTP */
239 static char *saslmech
=NULL
; /* Force use of particular SASL mech */
240 static char *user
=NULL
; /* Authenticate as this user */
241 static char *port
="submission"; /* Name of server port for SMTP submission */
242 static int tls
=-1; /* Use TLS for encryption */
243 static int fromcount
=0; /* Count of addresses on From: header */
244 static int seensender
=0; /* Have we seen a Sender: header? */
246 static unsigned msgflags
= 0; /* what we've seen */
250 static int msgstate
= NORMAL
;
252 static time_t tclock
= 0; /* the time we started (more or less) */
254 static SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
256 static char tmpfil
[BUFSIZ
];
257 static char bccfil
[BUFSIZ
];
259 static char from
[BUFSIZ
]; /* my network address */
260 static char sender
[BUFSIZ
]; /* my Sender: header */
261 static char efrom
[BUFSIZ
]; /* my Envelope-From: header */
262 static char fullfrom
[BUFSIZ
]; /* full contents of From header */
263 static char *filter
= NULL
; /* the filter for BCC'ing */
264 static char *subject
= NULL
; /* the subject field for BCC'ing */
265 static char *fccfold
[FCCS
]; /* foldernames for FCC'ing */
266 enum encoding
{ UNKNOWN
= 0, BINARY
= 1, SEVENBIT
= 7, EIGHTBIT
= 8 };
267 static enum encoding cte
= UNKNOWN
;
269 static struct headers
*hdrtab
; /* table for the message we're doing */
271 static struct mailname localaddrs
; /* local addrs */
272 static struct mailname netaddrs
; /* network addrs */
273 static struct mailname uuaddrs
; /* uucp addrs */
274 static struct mailname tmpaddrs
; /* temporary queue */
276 static int snoop
= 0;
277 static char *clientsw
= NULL
;
278 static char *serversw
= NULL
;
280 static char prefix
[] = "----- =_aaaaaaaaaa";
282 static char *partno
= NULL
;
287 static void putfmt (char *, char *, int *, FILE *);
288 static void start_headers (void);
289 static void finish_headers (FILE *);
290 static int get_header (char *, struct headers
*);
291 static int putadr (char *, char *, struct mailname
*, FILE *, unsigned int);
292 static void putgrp (char *, char *, FILE *, unsigned int);
293 static int insert (struct mailname
*);
294 static void pl (void);
295 static void anno (void);
296 static int annoaux (struct mailname
*);
297 static void insert_fcc (struct headers
*, char *);
298 static void make_bcc_file (int);
299 static void verify_all_addresses (int, int, char *, int, char *);
300 static void chkadr (void);
301 static void sigon (void);
302 static void sigoff (void);
303 static void p_refile (char *);
304 static void fcc (char *, char *);
305 static void die (char *, char *, ...);
306 static void post (char *, int, int, int, char *, int, char *);
307 static void do_text (char *file
, int fd
);
308 static void do_an_address (struct mailname
*, int);
309 static void do_addresses (int, int);
310 static int find_prefix (void);
314 main (int argc
, char **argv
)
316 int state
, compnum
, dashstuff
= 0, swnum
, oauth_flag
= 0;
317 int eai
= 0; /* use Email Address Internationalization (EAI) (SMTPUTF8) */
318 char *cp
, *msg
= NULL
, **argp
, **arguments
, *envelope
;
319 char buf
[BUFSIZ
], name
[NAMESZ
], *auth_svc
= NULL
;
321 m_getfld_state_t gstate
= 0;
323 if (nmh_init(argv
[0], 0 /* use context_foil() */)) { return 1; }
326 arguments
= getarguments (invo_name
, argc
, argv
, 0);
329 while ((cp
= *argp
++)) {
331 switch ((swnum
= smatch (++cp
, switches
))) {
333 ambigsw (cp
, switches
);
336 adios (NULL
, "-%s unknown", cp
);
339 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
340 print_help (buf
, switches
, 0);
343 print_version(invo_name
);
347 if (!(cp
= *argp
++) || *cp
== '-')
348 adios (NULL
, "missing argument to %s", argp
[-2]);
349 /* create a minimal context */
350 if (context_foil (cp
) == -1)
355 if (!(cp
= *argp
++) || *cp
== '-')
356 adios (NULL
, "missing argument to %s", argp
[-2]);
357 if ((state
= alias (cp
)) != AK_OK
)
358 adios (NULL
, "aliasing error in %s - %s",
359 cp
, akerror (state
));
378 if (!(filter
= *argp
++) || *filter
== '-')
379 adios (NULL
, "missing argument to %s", argp
[-2]);
434 if (!(cp
= *argp
++) || *cp
== '-')
435 adios (NULL
, "missing argument to %s", argp
[-2]);
436 if ((outputlinelen
= atoi (cp
)) < 10)
437 adios (NULL
, "impossible width %d", outputlinelen
);
441 if (!(cp
= *argp
++) || *cp
== '-')
442 adios (NULL
, "missing argument to %s", argp
[-2]);
443 if ((pfd
= atoi (cp
)) <= 2)
444 adios (NULL
, "bad argument %s %s", argp
[-2], cp
);
448 if (!(clientsw
= *argp
++) || *clientsw
== '-')
449 adios (NULL
, "missing argument to %s", argp
[-2]);
452 if (!(serversw
= *argp
++) || *serversw
== '-')
453 adios (NULL
, "missing argument to %s", argp
[-2]);
460 if (!(partno
= *argp
++) || *partno
== '-')
461 adios (NULL
, "missing argument to %s", argp
[-2]);
473 if (!(saslmech
= *argp
++) || *saslmech
== '-')
474 adios (NULL
, "missing argument to %s", argp
[-2]);
478 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
479 adios (NULL
, "missing argument to %s", argp
[-2]);
483 case OAUTHCREDFILESW
:
493 if (!(cp
= *argp
++) || *cp
== '-')
494 adios (NULL
, "missing argument to %s", argp
[-2]);
496 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
497 if (oauthswitches
[i
].switchnum
== swnum
) {
498 oauthswitches
[i
].value
= cp
;
503 if (oauthswitches
[i
].profname
== NULL
)
504 adios (NULL
, "internal error: cannot map switch %s "
505 "to profile entry", argp
[-2]);
512 if (!(user
= *argp
++) || *user
== '-')
513 adios (NULL
, "missing argument to %s", argp
[-2]);
517 if (!(port
= *argp
++) || *port
== '-')
518 adios (NULL
, "missing argument to %s", argp
[-2]);
534 if (!(cp
= *argp
++) || *cp
== '-')
535 adios (NULL
, "missing argument to %s", argp
[-2]);
540 if (!(cp
= *argp
++) || *cp
== '-')
541 adios (NULL
, "missing argument to %s", argp
[-2]);
546 if (!(cp
= *argp
++) || *cp
== '-')
547 adios (NULL
, "missing argument to %s", argp
[-2]);
552 if (!(cp
= *argp
++) || *cp
== '-')
553 adios (NULL
, "missing argument to %s", argp
[-2]);
554 save_mts_method (cp
);
557 case CREDENTIALSSW
: {
558 if (!(cp
= *argp
++) || *cp
== '-')
559 adios (NULL
, "missing argument to %s", argp
[-2]);
560 add_profile_entry ("credentials", cp
);
565 if (!(cp
= *argp
++) || *cp
== '-')
566 adios (NULL
, "missing argument to %s", argp
[-2]);
567 if (save_message_id_style (cp
) != 0)
568 adios (NULL
, "unsupported messageid \"%s\"", cp
);
573 adios (NULL
, "only one message at a time!");
581 adios (NULL
, "usage: %s [switches] file", invo_name
);
583 if (outputlinelen
< 10)
584 adios (NULL
, "impossible width %d", outputlinelen
);
586 if ((in
= fopen (msg
, "r")) == NULL
)
587 adios (msg
, "unable to open");
595 if ((out
= fopen ("/dev/null", "w")) == NULL
)
596 adios ("/dev/null", "unable to open");
598 char *cp
= m_mktemp2(NULL
, invo_name
, NULL
, &out
);
600 adios(NULL
, "unable to create temporary file in %s",
603 strncpy(tmpfil
, cp
, sizeof(tmpfil
));
607 hdrtab
= msgstate
== NORMAL
? NHeaders
: RHeaders
;
609 for (compnum
= 1;;) {
610 int bufsz
= sizeof buf
;
611 switch (state
= m_getfld (&gstate
, name
, buf
, &bufsz
, in
)) {
615 cp
= add (buf
, NULL
);
616 while (state
== FLDPLUS
) {
618 state
= m_getfld (&gstate
, name
, buf
, &bufsz
, in
);
621 putfmt (name
, cp
, &eai
, out
);
626 finish_headers (out
);
629 fprintf (out
, "\n%s", buf
);
630 while (state
== BODY
) {
632 state
= m_getfld (&gstate
, name
, buf
, &bufsz
, in
);
638 finish_headers (out
);
643 adios (NULL
, "message format error in component #%d", compnum
);
646 adios (NULL
, "getfld() returned %d", state
);
650 m_getfld_state_destroy (&gstate
);
664 * Here's how we decide which address to use as the envelope-from
667 * - If we were given an Envelope-From header, use that.
668 * - If we were given a Sender: address, use that.
669 * - Otherwise, use the address on the From: line
672 if (msgflags
& MEFM
) {
674 } else if (seensender
) {
683 * The user didn't specify any of the tls switches. Try to
684 * help them by implying -initialtls if they're using port 465
685 * (smtps, until IANA revoked that registration in 1998).
687 tls
= ! strcmp (port
, "465") || ! strcasecmp (port
, "smtps")
690 #else /* ! TLS_SUPPORT */
692 #endif /* ! TLS_SUPPORT */
696 * If we were given any oauth flags, store the appropriate profile
697 * entries and make sure an authservice was given (we have to do this
698 * here because we aren't guaranteed the authservice will be given on
699 * the command line before the other OAuth flags are given).
706 if (auth_svc
== NULL
) {
707 adios(NULL
, "No authentication service given with -authservice");
710 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
711 if (oauthswitches
[i
].value
!= NULL
) {
712 snprintf(sbuf
, sizeof(sbuf
),
713 oauthswitches
[i
].profname
, auth_svc
);
714 sbuf
[sizeof(sbuf
) - 1] = '\0';
715 add_profile_entry(sbuf
, oauthswitches
[i
].value
);
720 /* If we are doing a "whom" check */
722 /* This won't work with MTS_SENDMAIL_PIPE. */
723 verify_all_addresses (1, eai
, envelope
, oauth_flag
, auth_svc
);
727 if (msgflags
& MINV
) {
728 make_bcc_file (dashstuff
);
729 if (msgflags
& MVIS
) {
730 if (sm_mts
!= MTS_SENDMAIL_PIPE
) {
731 /* It would be nice to have support to call
732 verify_all_addresses with MTS_SENDMAIL_PIPE, but
733 that might require running sendmail as root. Note
734 that spost didn't verify addresses. */
735 verify_all_addresses (verbose
, eai
, envelope
, oauth_flag
,
738 post (tmpfil
, 0, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
740 post (bccfil
, 1, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
741 (void) m_unlink (bccfil
);
743 post (tmpfil
, 0, isatty (1), eai
, envelope
, oauth_flag
, auth_svc
);
747 (void) m_unlink (tmpfil
);
751 printf ("Partial Message #%s Processed\n", partno
);
753 printf ("Message Processed\n");
766 putfmt (char *name
, char *str
, int *eai
, FILE *out
)
768 int count
, grp
, i
, keep
;
770 char namep
[BUFSIZ
], error
[BUFSIZ
];
771 struct mailname
*mp
= NULL
, *np
= NULL
;
774 while (*str
== ' ' || *str
== '\t')
777 if (msgstate
== NORMAL
&& uprf (name
, "resent")) {
778 advise (NULL
, "illegal header line -- %s:", name
);
784 /* Check each header field value to see if it has any 8-bit characters.
785 If it does, enable EAI support. */
786 if (contains8bit(str
, NULL
)) {
788 printf ("EAI/SMTPUTF8 enabled\n");
791 /* Enable SMTPUTF8. */
794 /* Enable passing of utf-8 setting to getname()/getadrx(). */
799 if ((i
= get_header (name
, hdrtab
)) == NOTOK
) {
800 if (strncasecmp (name
, "nmh-", 4)) {
801 fprintf (out
, "%s: %s", name
, str
);
803 /* Filter out all Nmh-* headers, because Norm asked. They
804 should never have reached this point. Warn about any
805 that are non-empty. */
806 if (strcmp (str
, "\n")) {
807 TrimSuffixC(str
, '\n');
809 advise (NULL
, "ignoring header line -- %s: %s", name
, str
);
818 if (hdr
->flags
& HIGN
) {
821 if (hdr
->flags
& HBAD
) {
822 advise (NULL
, "illegal header line -- %s:", name
);
826 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
828 if (hdr
->flags
& HSUB
)
829 subject
= subject
? add (str
, add ("\t", subject
)) : mh_xstrdup(str
);
830 if (hdr
->flags
& HFCC
) {
831 if ((cp
= strrchr(str
, '\n')))
833 for (pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
835 insert_fcc (hdr
, pp
);
837 insert_fcc (hdr
, pp
);
840 if (hdr
->flags
& HCTE
) {
841 if (strncasecmp (str
, "7bit", 4) == 0) {
843 } else if (strncasecmp (str
, "8bit", 4) == 0) {
845 } else if (strncasecmp (str
, "binary", 6) == 0) {
849 if (!(hdr
->flags
& HADR
)) {
850 fprintf (out
, "%s: %s", name
, str
);
854 tmpaddrs
.m_next
= NULL
;
856 for (count
= 0; (cp
= getname (str
)); count
++) {
857 if ((mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
861 tmpaddrs
.m_next
= mp
;
865 admonish(cp
, "%s", error
);
866 if (hdr
->flags
& HTRY
)
874 if (hdr
->flags
& HNIL
)
875 fprintf (out
, "%s: %s", name
, str
);
878 * Sender (or Resent-Sender) can have only one address
880 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
881 : (hdr
->set
& MSND
)) {
882 advise (NULL
, "%s: field requires one address", name
);
886 advise (NULL
, "%s: field requires at least one address", name
);
893 if (count
> 1 && (hdr
->flags
& HONE
)) {
894 advise (NULL
, "%s: field only permits one address", name
);
899 nameoutput
= linepos
= 0;
900 snprintf (namep
, sizeof(namep
), "%s%s",
901 (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
903 for (grp
= 0, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
904 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
905 /* The address doesn't include a host, so it might be an alias. */
906 pp
= akvalue (mp
->m_mbox
); /* do mh alias substitution */
907 qp
= akvisible () ? mp
->m_mbox
: "";
910 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
911 while ((cp
= getname (pp
))) {
912 if (!(mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
913 admonish(cp
, "%s", error
);
919 * If it's a From: or Resent-From: header, save the address
920 * for later possible use (as the envelope address for SMTP)
923 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
924 : (hdr
->set
& MFRM
)) {
925 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
926 from
[sizeof(from
) - 1] = '\0';
931 * Also save the Sender: or Resent-Sender: header as well
934 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
935 : (hdr
->set
& MSND
)) {
936 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
937 sender
[sizeof(sender
) - 1] = '\0';
942 * ALSO ... save Envelope-From
945 if (hdr
->set
& MEFM
) {
946 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
947 efrom
[sizeof(efrom
) - 1] = '\0';
950 if (hdr
->flags
& HBCC
)
953 mp
->m_ingrp
= np
->m_ingrp
;
956 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
958 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
959 /* Catch this before sendmail chokes with:
960 "553 List:; syntax illegal for recipient
962 If we wanted to, we could expand out blind
963 aliases and put them in Bcc:, but then
964 they'd have the Blind-Carbon-Copy
967 "blind lists not compatible with"
973 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
))
974 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
983 /* Address includes a host, so no alias substitution is needed. */
986 * If it's a From: or Resent-From header, save the address
987 * for later possible use (as the envelope address for SMTP)
990 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
991 : (hdr
->set
& MFRM
)) {
992 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
997 * Also save the Sender: header as well
1000 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
1001 : (hdr
->set
& MSND
)) {
1002 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
1003 sender
[sizeof(sender
) - 1] = '\0';
1008 * ALSO ... save Envelope-From
1011 if (hdr
->set
& MEFM
) {
1012 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1013 efrom
[sizeof(efrom
) - 1] = '\0';
1016 if (hdr
->flags
& HBCC
)
1019 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1022 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
);
1026 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1033 * If this is a From:/Resent-From: header, save the full thing for
1034 * later in case we need it for use when constructing a Bcc draft message
1037 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
1038 strncpy(fullfrom
, str
, sizeof(fullfrom
));
1039 fullfrom
[sizeof(fullfrom
) - 1] = 0;
1041 * Strip off any trailing newlines
1044 while (strlen(fullfrom
) > 0 && fullfrom
[strlen(fullfrom
) - 1] == '\n') {
1045 fullfrom
[strlen(fullfrom
) - 1] = '\0';
1049 if (grp
> 0 && (hdr
->flags
& HNGR
)) {
1050 advise (NULL
, "%s: field does not allow groups", name
);
1060 start_headers (void)
1065 * Probably not necessary, but just in case ...
1076 * Now that we've outputted the header fields in the draft
1077 * message, we will now output any remaining header fields
1078 * that we need to add/create.
1082 finish_headers (FILE *out
)
1086 if (!(msgflags
& MFRM
)) {
1088 * A From: header is now required in the draft.
1090 advise (NULL
, "message has no From: header");
1091 advise (NULL
, "See default components files for examples");
1096 if (fromcount
> 1 && (seensender
== 0 && !(msgflags
& MEFM
))) {
1097 advise (NULL
, "A Sender: or Envelope-From: header is required "
1098 "with multiple\nFrom: addresses");
1106 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1108 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1110 * If we have multiple From: addresses, make sure we have an
1111 * Sender: header. If we don't have one, then generate one
1112 * from Envelope-From: (which in this case, cannot be blank)
1115 if (fromcount
> 1 && seensender
== 0) {
1116 if (efrom
[0] == '\0') {
1117 advise (NULL
, "Envelope-From cannot be blank when there "
1118 "is multiple From: addresses\nand no Sender: "
1122 fprintf (out
, "Sender: %s\n", efrom
);
1126 if (!(msgflags
& MVIS
))
1127 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
1131 if (!(msgflags
& MDAT
)) {
1132 advise (NULL
, "message has no Date: header");
1135 if (!(msgflags
& MFRM
)) {
1136 advise (NULL
, "message has no From: header");
1139 if (!(msgflags
& MRFM
)) {
1140 advise (NULL
, "message has no Resent-From: header");
1141 advise (NULL
, "See default components files for examples");
1145 if (fromcount
> 1 && (seensender
== 0 && !(msgflags
& MEFM
))) {
1146 advise (NULL
, "A Resent-Sender: or Envelope-From: header is "
1147 "required with multiple\nResent-From: addresses");
1155 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
1157 fprintf (out
, "Resent-Message-ID: %s\n",
1158 message_id (tclock
, 0));
1160 * If we have multiple Resent-From: addresses, make sure we have an
1161 * Resent-Sender: header. If we don't have one, then generate one
1162 * from Envelope-From (which in this case, cannot be blank)
1165 if (fromcount
> 1 && seensender
== 0) {
1166 if (efrom
[0] == '\0') {
1167 advise (NULL
, "Envelope-From cannot be blank when there "
1168 "is multiple Resent-From: addresses and no "
1169 "Resent-Sender: header");
1172 fprintf (out
, "Resent-Sender: %s\n", efrom
);
1176 if (!(msgflags
& MVIS
))
1177 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
1182 adios (NULL
, "re-format message and try again");
1184 adios (NULL
, "no addressees");
1189 get_header (char *header
, struct headers
*table
)
1193 for (h
= table
; h
->value
; h
++)
1194 if (!strcasecmp (header
? header
: "", h
->value
? h
->value
: ""))
1202 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
, unsigned int flags
)
1206 char buffer
[BUFSIZ
];
1208 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
1210 if (sm_mts
!= MTS_SENDMAIL_PIPE
&&
1211 ((flags
& (HBCC
| HDCC
| HEFM
)) || mp
->m_ingrp
))
1215 fprintf (out
, "%s: ", name
);
1216 linepos
+= (nameoutput
= strlen (name
) + 2);
1219 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
1220 mp
->m_pers
= mh_xstrdup(aka
);
1223 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
1226 cp
= adrformat (mp
);
1233 if (linepos
!= nameoutput
) {
1234 if (len
+ linepos
+ 2 > outputlinelen
)
1235 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
1245 return (flags
& HTRY
);
1250 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
1255 if (sm_mts
!= MTS_SENDMAIL_PIPE
&& (flags
& HBCC
))
1259 fprintf (out
, "%s: ", name
);
1260 linepos
+= (nameoutput
= strlen (name
) + 2);
1263 cp
= concat (group
, ";", NULL
);
1266 if (linepos
> nameoutput
) {
1267 if (len
+ linepos
+ 2 > outputlinelen
) {
1268 fprintf (out
, ",\n%*s", nameoutput
, "");
1269 linepos
= nameoutput
;
1283 insert (struct mailname
*np
)
1285 struct mailname
*mp
;
1287 if (np
->m_mbox
== NULL
)
1290 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1291 : np
->m_type
== UUCPHOST
? &uuaddrs
1295 if (!strcasecmp (np
->m_host
? np
->m_host
: "",
1296 mp
->m_next
->m_host
? mp
->m_next
->m_host
: "") &&
1297 !strcasecmp (np
->m_mbox
? np
->m_mbox
: "",
1298 mp
->m_next
->m_mbox
? mp
->m_next
->m_mbox
: "") &&
1299 np
->m_bcc
== mp
->m_next
->m_bcc
)
1312 struct mailname
*mp
;
1314 printf ("-------\n\t-- Addresses --\nlocal:\t");
1315 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1316 printf ("%s%s%s", mp
->m_mbox
,
1317 mp
->m_bcc
? "[BCC]" : "",
1318 mp
->m_next
? ",\n\t" : "");
1320 printf ("\nnet:\t");
1321 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1322 printf ("%s%s@%s%s%s", mp
->m_path
? mp
->m_path
: "",
1323 mp
->m_mbox
, mp
->m_host
,
1324 mp
->m_bcc
? "[BCC]" : "",
1325 mp
->m_next
? ",\n\t" : "");
1327 printf ("\nuucp:\t");
1328 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1329 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1330 mp
->m_bcc
? "[BCC]" : "",
1331 mp
->m_next
? ",\n\t" : "");
1333 printf ("\n\t-- Folder Copies --\nfcc:\t");
1334 for (i
= 0; i
< fccind
; i
++)
1335 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1343 struct mailname
*mp
;
1345 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1346 if (annoaux (mp
) == NOTOK
)
1349 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1350 if (annoaux (mp
) == NOTOK
)
1353 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1354 if (annoaux (mp
) == NOTOK
)
1364 annoaux (struct mailname
*mp
)
1367 char buffer
[BUFSIZ
];
1369 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1370 i
= strlen (buffer
);
1372 return (write (pfd
, buffer
, i
) == i
? OK
: NOTOK
);
1377 insert_fcc (struct headers
*hdr
, char *pp
)
1381 for (cp
= pp
; isspace ((unsigned char) *cp
); cp
++)
1383 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace ((unsigned char) *pp
); pp
--)
1391 adios (NULL
, "too many %ss", hdr
->value
);
1392 fccfold
[fccind
++] = mh_xstrdup(cp
);
1400 make_bcc_file (int dashstuff
)
1406 char *tfile
= NULL
, *program
;
1408 if ((tfile
= m_mktemp2(NULL
, "bccs", NULL
, &out
)) == NULL
) {
1409 adios(NULL
, "unable to create temporary file in %s", get_temp_dir());
1411 strncpy (bccfil
, tfile
, sizeof(bccfil
));
1413 fprintf (out
, "From: %s\n", fullfrom
);
1414 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1416 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1418 fprintf (out
, "Subject: %s", subject
);
1419 fprintf (out
, "BCC:\n");
1422 * Use MIME encapsulation for Bcc messages
1428 * Check if any lines in the message clash with the
1429 * prefix for the MIME multipart separator. If there
1430 * is a clash, increment one of the letters in the
1431 * prefix and check again.
1433 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1434 adios (NULL
, "lost prefix start");
1435 while (find_prefix () == NOTOK
) {
1440 adios (NULL
, "can't find a unique delimiter string");
1445 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1446 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1447 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1449 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1455 * Do mhl filtering of Bcc messages instead
1456 * of MIME encapsulation.
1458 if (filter
!= NULL
) {
1459 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
1463 adios ("fork", "unable to");
1466 dup2 (fileno (out
), 1);
1468 vec
= argsplit(mhlproc
, &program
, &i
);
1469 vec
[i
++] = "-forward";
1474 /* was the flag -[no]dashstuffing specified? */
1476 vec
[i
++] = "-dashstuffing";
1477 else if (dashstuff
< 0)
1478 vec
[i
++] = "-nodashstuffing";
1481 execvp (program
, vec
);
1482 fprintf (stderr
, "unable to exec ");
1487 pidXwait (child_id
, mhlproc
);
1491 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1492 adios (tmpfil
, "unable to re-open");
1495 * If using MIME encapsulation, or if the -nodashstuffing
1496 * flag was given, then just copy message. Else do
1497 * RFC934 quoting (dashstuffing).
1499 if (mime
|| dashstuff
< 0)
1500 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1502 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1506 fseek (out
, 0L, SEEK_END
);
1508 fprintf (out
, "\n--%s--\n", prefix
);
1510 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1516 * Scan message to check if any lines clash with
1517 * the prefix of the MIME multipart separator.
1524 char buffer
[BUFSIZ
];
1527 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1528 adios (tmpfil
, "unable to re-open");
1530 while (fgets (buffer
, sizeof(buffer
) - 1, in
))
1531 if (buffer
[0] == '-' && buffer
[1] == '-') {
1534 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1535 if (!isspace ((unsigned char) *cp
))
1538 if (strcmp (buffer
+ 2, prefix
) == 0) {
1549 #define plural(x) (x == 1 ? "" : "s")
1554 if (badadr
&& unkadr
)
1555 die (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1556 badadr
, plural (badadr
), unkadr
, plural (badadr
));
1558 die (NULL
, "%d address%s unparsable", badadr
, plural (badadr
));
1560 die (NULL
, "%d addressee%s undeliverable", unkadr
, plural (unkadr
));
1565 do_addresses (int bccque
, int talk
)
1569 struct mailname
*lp
;
1572 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1573 if (lp
->m_bcc
? bccque
: !bccque
) {
1575 printf (" -- Local Recipients --\n");
1576 do_an_address (lp
, talk
);
1581 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1582 if (lp
->m_bcc
? bccque
: !bccque
) {
1584 printf (" -- UUCP Recipients --\n");
1585 do_an_address (lp
, talk
);
1590 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1591 if (lp
->m_bcc
? bccque
: !bccque
) {
1593 printf (" -- Network Recipients --\n");
1594 do_an_address (lp
, talk
);
1600 if (rp_isbad (retval
= sm_waend ()))
1601 die (NULL
, "problem ending addresses; %s", rp_string (retval
));
1606 * MTS-SPECIFIC INTERACTION
1611 * SENDMAIL/SMTP routines
1615 post (char *file
, int bccque
, int talk
, int eai
, char *envelope
,
1616 int oauth_flag
, char *auth_svc
)
1622 if (msgflags
& MINV
)
1623 printf (" -- Posting for %s Recipients --\n",
1624 bccque
? "Blind" : "Sighted");
1626 printf (" -- Posting for All Recipients --\n");
1631 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1632 char **argp
, *program
;
1635 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
1639 adios ("fork", "unable to");
1642 if (freopen( file
, "r", stdin
) == NULL
) {
1643 adios (file
, "can't reopen for sendmail");
1646 argp
= argsplit(sendmail
, &program
, &argc
);
1647 argp
[argc
++] = "-t"; /* read msg for recipients */
1648 argp
[argc
++] = "-i"; /* don't stop on "." */
1650 argp
[argc
++] = "-bv";
1652 argp
[argc
++] = "-v";
1655 execv (program
, argp
);
1656 adios (sendmail
, "can't exec");
1659 pidXwait (child_id
, NULL
);
1663 const int fd
= open (file
, O_RDONLY
);
1667 die (file
, "unable to re-open");
1670 if (msgflags
& MMIM
&& cte
!= UNKNOWN
) {
1671 /* MIME message with C-T-E header. (BINARYMIME isn't
1672 supported, use 8BITMIME instead for binary.) */
1673 eightbit
= cte
!= SEVENBIT
;
1675 if (scan_input (fd
, &eightbit
) == NOTOK
) {
1677 die (file
, "problem reading from");
1681 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1682 verbose
, snoop
, sasl
, saslmech
, user
,
1683 oauth_flag
? auth_svc
: NULL
, tls
))
1684 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1686 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1689 do_addresses (bccque
, talk
&& verbose
);
1694 sm_end (!(msgflags
& MINV
) || bccque
? OK
: DONE
);
1698 if (msgflags
& MINV
)
1699 printf (" -- %s Recipient Copies Posted --\n",
1700 bccque
? "Blind" : "Sighted");
1702 printf (" -- Recipient Copies Posted --\n");
1710 /* Address Verification */
1713 verify_all_addresses (int talk
, int eai
, char *envelope
, int oauth_flag
,
1717 struct mailname
*lp
;
1721 if (!whomsw
|| checksw
) {
1722 /* Not sending message body, so don't need to use 8BITMIME. */
1723 const int eightbit
= 0;
1725 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1726 verbose
, snoop
, sasl
, saslmech
, user
,
1727 oauth_flag
? auth_svc
: NULL
, tls
))
1728 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1729 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1733 if (talk
&& !whomsw
)
1734 printf (" -- Address Verification --\n");
1735 if (talk
&& localaddrs
.m_next
)
1736 printf (" -- Local Recipients --\n");
1737 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1738 do_an_address (lp
, talk
);
1740 if (talk
&& uuaddrs
.m_next
)
1741 printf (" -- UUCP Recipients --\n");
1742 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1743 do_an_address (lp
, talk
);
1745 if (talk
&& netaddrs
.m_next
)
1746 printf (" -- Network Recipients --\n");
1747 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1748 do_an_address (lp
, talk
);
1751 if (talk
&& !whomsw
)
1752 printf (" -- Address Verification Successful --\n");
1754 if (!whomsw
|| checksw
)
1763 do_an_address (struct mailname
*lp
, int talk
)
1769 switch (lp
->m_type
) {
1773 strncpy (addr
, mbox
, sizeof(addr
));
1777 mbox
= auxformat (lp
, 0);
1779 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1782 default: /* let SendMail decide if the host is bad */
1785 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1790 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1792 if (whomsw
&& !checksw
) {
1800 switch (retval
= sm_wadr (mbox
, host
,
1801 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1804 printf ("address ok\n");
1810 fprintf (stderr
, " %s: ", addr
);
1811 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1812 rp_string (retval
));
1818 fprintf (stderr
, " %s: ", addr
);
1819 die (NULL
, "unexpected response; %s", rp_string (retval
));
1827 do_text (char *file
, int fd
)
1832 lseek (fd
, (off_t
) 0, SEEK_SET
);
1834 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1835 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1836 die (NULL
, "problem writing text; %s\n", rp_string (retval
));
1840 die (file
, "problem reading from");
1842 switch (retval
= sm_wtend ()) {
1848 die (NULL
, "posting failed; %s", rp_string (retval
));
1851 die (NULL
, "unexpected response; %s", rp_string (retval
));
1865 (void) m_unlink (tmpfil
);
1866 if (msgflags
& MINV
)
1867 (void) m_unlink (bccfil
);
1869 if (!whomsw
|| checksw
)
1882 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1883 istat
= SIGNAL2 (SIGINT
, sigser
);
1884 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1885 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1895 SIGNAL (SIGHUP
, hstat
);
1896 SIGNAL (SIGINT
, istat
);
1897 SIGNAL (SIGQUIT
, qstat
);
1898 SIGNAL (SIGTERM
, tstat
);
1906 p_refile (char *file
)
1914 printf (" -- Filing Folder Copies --\n");
1915 for (i
= 0; i
< fccind
; i
++)
1916 fcc (file
, fccfold
[i
]);
1918 printf (" -- Folder Copies Filed --\n");
1923 * Call the `fileproc' to add the file to the folder.
1927 fcc (char *file
, char *folder
)
1930 int i
, status
, argp
;
1932 char **arglist
, *program
;
1935 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
1938 for (i
= 0; (child_id
= fork ()) == NOTOK
&& i
< 5; i
++)
1944 fprintf (stderr
, " %sFcc %s: ",
1945 msgstate
== RESENT
? "Resent-" : "", folder
);
1946 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
1950 /* see if we need to add `+' */
1951 snprintf (fold
, sizeof(fold
), "%s%s",
1952 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
1954 /* now exec the fileproc */
1956 arglist
= argsplit(fileproc
, &program
, &argp
);
1957 arglist
[argp
++] = "-link";
1958 arglist
[argp
++] = "-file";
1959 arglist
[argp
++] = file
;
1960 arglist
[argp
++] = fold
;
1961 arglist
[argp
] = NULL
;
1962 execvp (program
, arglist
);
1966 if ((status
= pidwait (child_id
, OK
))) {
1968 fprintf (stderr
, " %sFcc %s: ",
1969 msgstate
== RESENT
? "Resent-" : "", folder
);
1970 pidstatus (status
, verbose
? stdout
: stderr
, NULL
);
1973 printf ("folder ok\n");
1985 die (char *what
, char *fmt
, ...)
1989 (void) m_unlink (tmpfil
);
1990 if (msgflags
& MINV
)
1991 (void) m_unlink (bccfil
);
1993 if (!whomsw
|| checksw
)
1997 advertise (what
, NULL
, fmt
, ap
);