]>
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 char *newline
= strchr (str
, '\n');
808 if (newline
) *newline
= '\0';
810 advise (NULL
, "ignoring header line -- %s: %s", name
, str
);
819 if (hdr
->flags
& HIGN
) {
822 if (hdr
->flags
& HBAD
) {
823 advise (NULL
, "illegal header line -- %s:", name
);
827 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
829 if (hdr
->flags
& HSUB
)
830 subject
= subject
? add (str
, add ("\t", subject
)) : getcpy (str
);
831 if (hdr
->flags
& HFCC
) {
832 if ((cp
= strrchr(str
, '\n')))
834 for (pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
836 insert_fcc (hdr
, pp
);
838 insert_fcc (hdr
, pp
);
841 if (hdr
->flags
& HCTE
) {
842 if (strncasecmp (str
, "7bit", 4) == 0) {
844 } else if (strncasecmp (str
, "8bit", 4) == 0) {
846 } else if (strncasecmp (str
, "binary", 6) == 0) {
850 if (!(hdr
->flags
& HADR
)) {
851 fprintf (out
, "%s: %s", name
, str
);
855 tmpaddrs
.m_next
= NULL
;
857 for (count
= 0; (cp
= getname (str
)); count
++) {
858 if ((mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
862 tmpaddrs
.m_next
= mp
;
866 admonish(cp
, "%s", error
);
867 if (hdr
->flags
& HTRY
)
875 if (hdr
->flags
& HNIL
)
876 fprintf (out
, "%s: %s", name
, str
);
879 * Sender (or Resent-Sender) can have only one address
881 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
882 : (hdr
->set
& MSND
)) {
883 advise (NULL
, "%s: field requires one address", name
);
887 advise (NULL
, "%s: field requires at least one address", name
);
894 if (count
> 1 && (hdr
->flags
& HONE
)) {
895 advise (NULL
, "%s: field only permits one address", name
);
900 nameoutput
= linepos
= 0;
901 snprintf (namep
, sizeof(namep
), "%s%s",
902 (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
904 for (grp
= 0, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
905 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
906 /* The address doesn't include a host, so it might be an alias. */
907 pp
= akvalue (mp
->m_mbox
); /* do mh alias substitution */
908 qp
= akvisible () ? mp
->m_mbox
: "";
911 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
912 while ((cp
= getname (pp
))) {
913 if (!(mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
914 admonish(cp
, "%s", error
);
920 * If it's a From: or Resent-From: header, save the address
921 * for later possible use (as the envelope address for SMTP)
924 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
925 : (hdr
->set
& MFRM
)) {
926 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
927 from
[sizeof(from
) - 1] = '\0';
932 * Also save the Sender: or Resent-Sender: header as well
935 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
936 : (hdr
->set
& MSND
)) {
937 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
938 sender
[sizeof(sender
) - 1] = '\0';
943 * ALSO ... save Envelope-From
946 if (hdr
->set
& MEFM
) {
947 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
948 efrom
[sizeof(efrom
) - 1] = '\0';
951 if (hdr
->flags
& HBCC
)
954 mp
->m_ingrp
= np
->m_ingrp
;
957 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
959 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
960 /* Catch this before sendmail chokes with:
961 "553 List:; syntax illegal for recipient
963 If we wanted to, we could expand out blind
964 aliases and put them in Bcc:, but then
965 they'd have the Blind-Carbon-Copy
968 "blind lists not compatible with"
974 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
))
975 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
984 /* Address includes a host, so no alias substitution is needed. */
987 * If it's a From: or Resent-From header, save the address
988 * for later possible use (as the envelope address for SMTP)
991 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
992 : (hdr
->set
& MFRM
)) {
993 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
998 * Also save the Sender: header as well
1001 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
1002 : (hdr
->set
& MSND
)) {
1003 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
1004 sender
[sizeof(sender
) - 1] = '\0';
1009 * ALSO ... save Envelope-From
1012 if (hdr
->set
& MEFM
) {
1013 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1014 efrom
[sizeof(efrom
) - 1] = '\0';
1017 if (hdr
->flags
& HBCC
)
1020 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1023 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
);
1027 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1034 * If this is a From:/Resent-From: header, save the full thing for
1035 * later in case we need it for use when constructing a Bcc draft message
1038 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
1039 strncpy(fullfrom
, str
, sizeof(fullfrom
));
1040 fullfrom
[sizeof(fullfrom
) - 1] = 0;
1042 * Strip off any trailing newlines
1045 while (strlen(fullfrom
) > 0 && fullfrom
[strlen(fullfrom
) - 1] == '\n') {
1046 fullfrom
[strlen(fullfrom
) - 1] = '\0';
1050 if (grp
> 0 && (hdr
->flags
& HNGR
)) {
1051 advise (NULL
, "%s: field does not allow groups", name
);
1061 start_headers (void)
1066 * Probably not necessary, but just in case ...
1077 * Now that we've outputted the header fields in the draft
1078 * message, we will now output any remaining header fields
1079 * that we need to add/create.
1083 finish_headers (FILE *out
)
1087 if (!(msgflags
& MFRM
)) {
1089 * A From: header is now required in the draft.
1091 advise (NULL
, "message has no From: header");
1092 advise (NULL
, "See default components files for examples");
1097 if (fromcount
> 1 && (seensender
== 0 && !(msgflags
& MEFM
))) {
1098 advise (NULL
, "A Sender: or Envelope-From: header is required "
1099 "with multiple\nFrom: addresses");
1107 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1109 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1111 * If we have multiple From: addresses, make sure we have an
1112 * Sender: header. If we don't have one, then generate one
1113 * from Envelope-From: (which in this case, cannot be blank)
1116 if (fromcount
> 1 && seensender
== 0) {
1117 if (efrom
[0] == '\0') {
1118 advise (NULL
, "Envelope-From cannot be blank when there "
1119 "is multiple From: addresses\nand no Sender: "
1123 fprintf (out
, "Sender: %s\n", efrom
);
1127 if (!(msgflags
& MVIS
))
1128 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
1132 if (!(msgflags
& MDAT
)) {
1133 advise (NULL
, "message has no Date: header");
1136 if (!(msgflags
& MFRM
)) {
1137 advise (NULL
, "message has no From: header");
1140 if (!(msgflags
& MRFM
)) {
1141 advise (NULL
, "message has no Resent-From: header");
1142 advise (NULL
, "See default components files for examples");
1146 if (fromcount
> 1 && (seensender
== 0 && !(msgflags
& MEFM
))) {
1147 advise (NULL
, "A Resent-Sender: or Envelope-From: header is "
1148 "required with multiple\nResent-From: addresses");
1156 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
1158 fprintf (out
, "Resent-Message-ID: %s\n",
1159 message_id (tclock
, 0));
1161 * If we have multiple Resent-From: addresses, make sure we have an
1162 * Resent-Sender: header. If we don't have one, then generate one
1163 * from Envelope-From (which in this case, cannot be blank)
1166 if (fromcount
> 1 && seensender
== 0) {
1167 if (efrom
[0] == '\0') {
1168 advise (NULL
, "Envelope-From cannot be blank when there "
1169 "is multiple Resent-From: addresses and no "
1170 "Resent-Sender: header");
1173 fprintf (out
, "Resent-Sender: %s\n", efrom
);
1177 if (!(msgflags
& MVIS
))
1178 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
1183 adios (NULL
, "re-format message and try again");
1185 adios (NULL
, "no addressees");
1190 get_header (char *header
, struct headers
*table
)
1194 for (h
= table
; h
->value
; h
++)
1195 if (!strcasecmp (header
? header
: "", h
->value
? h
->value
: ""))
1203 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
, unsigned int flags
)
1207 char buffer
[BUFSIZ
];
1209 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
1211 if (sm_mts
!= MTS_SENDMAIL_PIPE
&&
1212 ((flags
& (HBCC
| HDCC
| HEFM
)) || mp
->m_ingrp
))
1216 fprintf (out
, "%s: ", name
);
1217 linepos
+= (nameoutput
= strlen (name
) + 2);
1220 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
1221 mp
->m_pers
= getcpy (aka
);
1224 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
1227 cp
= adrformat (mp
);
1234 if (linepos
!= nameoutput
) {
1235 if (len
+ linepos
+ 2 > outputlinelen
)
1236 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
1246 return (flags
& HTRY
);
1251 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
1256 if (sm_mts
!= MTS_SENDMAIL_PIPE
&& (flags
& HBCC
))
1260 fprintf (out
, "%s: ", name
);
1261 linepos
+= (nameoutput
= strlen (name
) + 2);
1264 cp
= concat (group
, ";", NULL
);
1267 if (linepos
> nameoutput
) {
1268 if (len
+ linepos
+ 2 > outputlinelen
) {
1269 fprintf (out
, ",\n%*s", nameoutput
, "");
1270 linepos
= nameoutput
;
1284 insert (struct mailname
*np
)
1286 struct mailname
*mp
;
1288 if (np
->m_mbox
== NULL
)
1291 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1292 : np
->m_type
== UUCPHOST
? &uuaddrs
1296 if (!strcasecmp (np
->m_host
? np
->m_host
: "",
1297 mp
->m_next
->m_host
? mp
->m_next
->m_host
: "") &&
1298 !strcasecmp (np
->m_mbox
? np
->m_mbox
: "",
1299 mp
->m_next
->m_mbox
? mp
->m_next
->m_mbox
: "") &&
1300 np
->m_bcc
== mp
->m_next
->m_bcc
)
1313 struct mailname
*mp
;
1315 printf ("-------\n\t-- Addresses --\nlocal:\t");
1316 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1317 printf ("%s%s%s", mp
->m_mbox
,
1318 mp
->m_bcc
? "[BCC]" : "",
1319 mp
->m_next
? ",\n\t" : "");
1321 printf ("\nnet:\t");
1322 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1323 printf ("%s%s@%s%s%s", mp
->m_path
? mp
->m_path
: "",
1324 mp
->m_mbox
, mp
->m_host
,
1325 mp
->m_bcc
? "[BCC]" : "",
1326 mp
->m_next
? ",\n\t" : "");
1328 printf ("\nuucp:\t");
1329 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1330 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1331 mp
->m_bcc
? "[BCC]" : "",
1332 mp
->m_next
? ",\n\t" : "");
1334 printf ("\n\t-- Folder Copies --\nfcc:\t");
1335 for (i
= 0; i
< fccind
; i
++)
1336 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1344 struct mailname
*mp
;
1346 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1347 if (annoaux (mp
) == NOTOK
)
1350 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1351 if (annoaux (mp
) == NOTOK
)
1354 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1355 if (annoaux (mp
) == NOTOK
)
1365 annoaux (struct mailname
*mp
)
1368 char buffer
[BUFSIZ
];
1370 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1371 i
= strlen (buffer
);
1373 return (write (pfd
, buffer
, i
) == i
? OK
: NOTOK
);
1378 insert_fcc (struct headers
*hdr
, char *pp
)
1382 for (cp
= pp
; isspace ((unsigned char) *cp
); cp
++)
1384 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace ((unsigned char) *pp
); pp
--)
1392 adios (NULL
, "too many %ss", hdr
->value
);
1393 fccfold
[fccind
++] = getcpy (cp
);
1401 make_bcc_file (int dashstuff
)
1407 char *tfile
= NULL
, *program
;
1409 if ((tfile
= m_mktemp2(NULL
, "bccs", NULL
, &out
)) == NULL
) {
1410 adios(NULL
, "unable to create temporary file in %s", get_temp_dir());
1412 strncpy (bccfil
, tfile
, sizeof(bccfil
));
1414 fprintf (out
, "From: %s\n", fullfrom
);
1415 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1417 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1419 fprintf (out
, "Subject: %s", subject
);
1420 fprintf (out
, "BCC:\n");
1423 * Use MIME encapsulation for Bcc messages
1429 * Check if any lines in the message clash with the
1430 * prefix for the MIME multipart separator. If there
1431 * is a clash, increment one of the letters in the
1432 * prefix and check again.
1434 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1435 adios (NULL
, "lost prefix start");
1436 while (find_prefix () == NOTOK
) {
1441 adios (NULL
, "can't find a unique delimiter string");
1446 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1447 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1448 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1450 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1456 * Do mhl filtering of Bcc messages instead
1457 * of MIME encapsulation.
1459 if (filter
!= NULL
) {
1460 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
1464 adios ("fork", "unable to");
1467 dup2 (fileno (out
), 1);
1469 vec
= argsplit(mhlproc
, &program
, &i
);
1470 vec
[i
++] = "-forward";
1475 /* was the flag -[no]dashstuffing specified? */
1477 vec
[i
++] = "-dashstuffing";
1478 else if (dashstuff
< 0)
1479 vec
[i
++] = "-nodashstuffing";
1482 execvp (program
, vec
);
1483 fprintf (stderr
, "unable to exec ");
1488 pidXwait (child_id
, mhlproc
);
1492 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1493 adios (tmpfil
, "unable to re-open");
1496 * If using MIME encapsulation, or if the -nodashstuffing
1497 * flag was given, then just copy message. Else do
1498 * RFC934 quoting (dashstuffing).
1500 if (mime
|| dashstuff
< 0)
1501 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1503 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1507 fseek (out
, 0L, SEEK_END
);
1509 fprintf (out
, "\n--%s--\n", prefix
);
1511 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1517 * Scan message to check if any lines clash with
1518 * the prefix of the MIME multipart separator.
1525 char buffer
[BUFSIZ
];
1528 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1529 adios (tmpfil
, "unable to re-open");
1531 while (fgets (buffer
, sizeof(buffer
) - 1, in
))
1532 if (buffer
[0] == '-' && buffer
[1] == '-') {
1535 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1536 if (!isspace ((unsigned char) *cp
))
1539 if (strcmp (buffer
+ 2, prefix
) == 0) {
1550 #define plural(x) (x == 1 ? "" : "s")
1555 if (badadr
&& unkadr
)
1556 die (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1557 badadr
, plural (badadr
), unkadr
, plural (badadr
));
1559 die (NULL
, "%d address%s unparsable", badadr
, plural (badadr
));
1561 die (NULL
, "%d addressee%s undeliverable", unkadr
, plural (unkadr
));
1566 do_addresses (int bccque
, int talk
)
1570 struct mailname
*lp
;
1573 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1574 if (lp
->m_bcc
? bccque
: !bccque
) {
1576 printf (" -- Local Recipients --\n");
1577 do_an_address (lp
, talk
);
1582 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1583 if (lp
->m_bcc
? bccque
: !bccque
) {
1585 printf (" -- UUCP Recipients --\n");
1586 do_an_address (lp
, talk
);
1591 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1592 if (lp
->m_bcc
? bccque
: !bccque
) {
1594 printf (" -- Network Recipients --\n");
1595 do_an_address (lp
, talk
);
1601 if (rp_isbad (retval
= sm_waend ()))
1602 die (NULL
, "problem ending addresses; %s", rp_string (retval
));
1607 * MTS-SPECIFIC INTERACTION
1612 * SENDMAIL/SMTP routines
1616 post (char *file
, int bccque
, int talk
, int eai
, char *envelope
,
1617 int oauth_flag
, char *auth_svc
)
1623 if (msgflags
& MINV
)
1624 printf (" -- Posting for %s Recipients --\n",
1625 bccque
? "Blind" : "Sighted");
1627 printf (" -- Posting for All Recipients --\n");
1632 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1633 char **argp
, *program
;
1636 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
1640 adios ("fork", "unable to");
1643 if (freopen( file
, "r", stdin
) == NULL
) {
1644 adios (file
, "can't reopen for sendmail");
1647 argp
= argsplit(sendmail
, &program
, &argc
);
1648 argp
[argc
++] = "-t"; /* read msg for recipients */
1649 argp
[argc
++] = "-i"; /* don't stop on "." */
1651 argp
[argc
++] = "-bv";
1653 argp
[argc
++] = "-v";
1656 execv (program
, argp
);
1657 adios (sendmail
, "can't exec");
1660 pidXwait (child_id
, NULL
);
1664 const int fd
= open (file
, O_RDONLY
);
1668 die (file
, "unable to re-open");
1671 if (msgflags
& MMIM
&& cte
!= UNKNOWN
) {
1672 /* MIME message with C-T-E header. (BINARYMIME isn't
1673 supported, use 8BITMIME instead for binary.) */
1674 eightbit
= cte
!= SEVENBIT
;
1676 if (scan_input (fd
, &eightbit
) == NOTOK
) {
1678 die (file
, "problem reading from");
1682 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1683 verbose
, snoop
, sasl
, saslmech
, user
,
1684 oauth_flag
? auth_svc
: NULL
, tls
))
1685 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1687 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1690 do_addresses (bccque
, talk
&& verbose
);
1695 sm_end (!(msgflags
& MINV
) || bccque
? OK
: DONE
);
1699 if (msgflags
& MINV
)
1700 printf (" -- %s Recipient Copies Posted --\n",
1701 bccque
? "Blind" : "Sighted");
1703 printf (" -- Recipient Copies Posted --\n");
1711 /* Address Verification */
1714 verify_all_addresses (int talk
, int eai
, char *envelope
, int oauth_flag
,
1718 struct mailname
*lp
;
1722 if (!whomsw
|| checksw
) {
1723 /* Not sending message body, so don't need to use 8BITMIME. */
1724 const int eightbit
= 0;
1726 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1727 verbose
, snoop
, sasl
, saslmech
, user
,
1728 oauth_flag
? auth_svc
: NULL
, tls
))
1729 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1730 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1734 if (talk
&& !whomsw
)
1735 printf (" -- Address Verification --\n");
1736 if (talk
&& localaddrs
.m_next
)
1737 printf (" -- Local Recipients --\n");
1738 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1739 do_an_address (lp
, talk
);
1741 if (talk
&& uuaddrs
.m_next
)
1742 printf (" -- UUCP Recipients --\n");
1743 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1744 do_an_address (lp
, talk
);
1746 if (talk
&& netaddrs
.m_next
)
1747 printf (" -- Network Recipients --\n");
1748 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1749 do_an_address (lp
, talk
);
1752 if (talk
&& !whomsw
)
1753 printf (" -- Address Verification Successful --\n");
1755 if (!whomsw
|| checksw
)
1764 do_an_address (struct mailname
*lp
, int talk
)
1770 switch (lp
->m_type
) {
1774 strncpy (addr
, mbox
, sizeof(addr
));
1778 mbox
= auxformat (lp
, 0);
1780 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1783 default: /* let SendMail decide if the host is bad */
1786 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1791 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1793 if (whomsw
&& !checksw
) {
1801 switch (retval
= sm_wadr (mbox
, host
,
1802 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1805 printf ("address ok\n");
1811 fprintf (stderr
, " %s: ", addr
);
1812 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1813 rp_string (retval
));
1819 fprintf (stderr
, " %s: ", addr
);
1820 die (NULL
, "unexpected response; %s", rp_string (retval
));
1828 do_text (char *file
, int fd
)
1833 lseek (fd
, (off_t
) 0, SEEK_SET
);
1835 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1836 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1837 die (NULL
, "problem writing text; %s\n", rp_string (retval
));
1841 die (file
, "problem reading from");
1843 switch (retval
= sm_wtend ()) {
1849 die (NULL
, "posting failed; %s", rp_string (retval
));
1852 die (NULL
, "unexpected response; %s", rp_string (retval
));
1866 (void) m_unlink (tmpfil
);
1867 if (msgflags
& MINV
)
1868 (void) m_unlink (bccfil
);
1870 if (!whomsw
|| checksw
)
1883 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1884 istat
= SIGNAL2 (SIGINT
, sigser
);
1885 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1886 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1896 SIGNAL (SIGHUP
, hstat
);
1897 SIGNAL (SIGINT
, istat
);
1898 SIGNAL (SIGQUIT
, qstat
);
1899 SIGNAL (SIGTERM
, tstat
);
1907 p_refile (char *file
)
1915 printf (" -- Filing Folder Copies --\n");
1916 for (i
= 0; i
< fccind
; i
++)
1917 fcc (file
, fccfold
[i
]);
1919 printf (" -- Folder Copies Filed --\n");
1924 * Call the `fileproc' to add the file to the folder.
1928 fcc (char *file
, char *folder
)
1931 int i
, status
, argp
;
1933 char **arglist
, *program
;
1936 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
1939 for (i
= 0; (child_id
= fork ()) == NOTOK
&& i
< 5; i
++)
1945 fprintf (stderr
, " %sFcc %s: ",
1946 msgstate
== RESENT
? "Resent-" : "", folder
);
1947 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
1951 /* see if we need to add `+' */
1952 snprintf (fold
, sizeof(fold
), "%s%s",
1953 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
1955 /* now exec the fileproc */
1957 arglist
= argsplit(fileproc
, &program
, &argp
);
1958 arglist
[argp
++] = "-link";
1959 arglist
[argp
++] = "-file";
1960 arglist
[argp
++] = file
;
1961 arglist
[argp
++] = fold
;
1962 arglist
[argp
] = NULL
;
1963 execvp (program
, arglist
);
1967 if ((status
= pidwait (child_id
, OK
))) {
1969 fprintf (stderr
, " %sFcc %s: ",
1970 msgstate
== RESENT
? "Resent-" : "", folder
);
1971 pidstatus (status
, verbose
? stdout
: stderr
, NULL
);
1974 printf ("folder ok\n");
1986 die (char *what
, char *fmt
, ...)
1990 (void) m_unlink (tmpfil
);
1991 if (msgflags
& MINV
)
1992 (void) m_unlink (bccfil
);
1994 if (!whomsw
|| checksw
)
1998 advertise (what
, NULL
, fmt
, ap
);