]>
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.
9 #include "sbr/pidstatus.h"
10 #include "sbr/print_version.h"
11 #include "sbr/print_help.h"
12 #include "sbr/arglist.h"
13 #include "sbr/error.h"
15 #include "h/signals.h"
16 #include "h/addrsbr.h"
17 #include "h/aliasbr.h"
18 #include "h/dropsbr.h"
24 #include "sbr/m_mktemp.h"
25 #include "sbr/message_id.h"
27 #ifdef HAVE_SYS_TIME_H
28 # include <sys/time.h>
32 #include "mts/smtp/smtp.h"
35 # define SASLminc(a) (a)
36 #else /* CYRUS_SASL */
37 # define SASLminc(a) 0
38 #endif /* CYRUS_SASL */
41 # define TLSminc(a) (a)
42 #else /* TLS_SUPPORT */
44 #endif /* TLS_SUPPORT */
47 # define OAUTHminc(a) (a)
48 #else /* OAUTH_SUPPORT */
49 # define OAUTHminc(a) 0
50 #endif /* OAUTH_SUPPORT */
52 #define FCCS 10 /* max number of fccs allowed */
54 /* In the following array of structures, the numeric second field of the
55 structures (minchars) is apparently used like this:
57 -# : Switch can be abbreviated to # characters; switch hidden in -help.
58 0 : Switch can't be abbreviated; switch shown in -help.
59 # : Switch can be abbreviated to # characters; switch shown in -help. */
61 #define POST_SWITCHES \
62 X("alias aliasfile", 0, ALIASW) \
63 X("check", -5, CHKSW) /* interface from whom */ \
64 X("nocheck", -7, NCHKSW) /* interface from whom */ \
65 X("debug", -5, DEBUGSW) \
66 X("dist", -4, DISTSW) /* interface from dist */ \
67 X("filter filterfile", 0, FILTSW) \
68 X("nofilter", 0, NFILTSW) \
69 X("format", 0, FRMTSW) \
70 X("noformat", 0, NFRMTSW) \
71 X("library directory", -7, LIBSW) /* interface from send, whom */ \
72 X("mime", 0, MIMESW) \
73 X("nomime", 0, NMIMESW) \
74 X("msgid", 0, MSGDSW) \
75 X("nomsgid", 0, NMSGDSW) \
76 X("verbose", 0, VERBSW) \
77 X("noverbose", 0, NVERBSW) \
78 X("watch", 0, WATCSW) \
79 X("nowatch", 0, NWATCSW) \
80 X("whom", -4, WHOMSW) /* interface from whom */ \
81 X("width columns", 0, WIDTHSW) \
82 X("version", 0, VERSIONSW) \
83 X("help", 0, HELPSW) \
84 X("dashstuffing", -12, BITSTUFFSW) /* should we dashstuff BCC messages? */ \
85 X("nodashstuffing", -14, NBITSTUFFSW) \
86 X("idanno number", -6, ANNOSW) /* interface from send */ \
87 X("client host", -6, CLIESW) \
88 X("server host", 6, SERVSW) /* specify alternate SMTP server */ \
89 X("snoop", -5, SNOOPSW) /* snoop the SMTP transaction */ \
90 X("partno", -6, PARTSW) \
91 X("sasl", SASLminc(4), SASLSW) \
92 X("nosasl", SASLminc(6), NOSASLSW) \
93 X("saslmech", SASLminc(5), SASLMECHSW) \
94 X("user", SASLminc(-4), USERSW) \
95 X("port server submission port name/number", 4, PORTSW) \
96 X("tls", TLSminc(-3), TLSSW) \
97 X("initialtls", TLSminc(-10), INITTLSSW) \
98 X("notls", TLSminc(-5), NTLSSW) \
99 X("certverify", TLSminc(-10), CERTVERSW) \
100 X("nocertverify", TLSminc(-12), NOCERTVERSW) \
101 X("fileproc", -4, FILEPROCSW) \
102 X("mhlproc", -3, MHLPROCSW) \
103 X("sendmail program", 0, MTSSM) \
104 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
105 X("credentials legacy|file:filename", 0, CREDENTIALSSW) \
106 X("messageid localname|random", 2, MESSAGEIDSW) \
107 X("authservice auth-service-name", OAUTHminc(-11), AUTHSERVICESW) \
108 X("oauthcredfile credential-file", OAUTHminc(-7), OAUTHCREDFILESW) \
109 X("oauthclientid client-id", OAUTHminc(-12), OAUTHCLIDSW) \
110 X("oauthclientsecret client-secret", OAUTHminc(-12), OAUTHCLSECSW) \
111 X("oauthauthendpoint authentication-endpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
112 X("oauthredirect redirect-uri", OAUTHminc(-6), OAUTHREDIRSW) \
113 X("oauthtokenendpoint token-endpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
114 X("oauthscope scope", OAUTHminc(-6), OAUTHSCOPESW) \
116 #define X(sw, minchars, id) id,
117 DEFINE_SWITCH_ENUM(POST
);
120 #define X(sw, minchars, id) { sw, minchars, id },
121 DEFINE_SWITCH_ARRAY(POST
, switches
);
126 * Mapping between command-line switches and profile entries, communicated
127 * from 'send'. We use a service name of 'post' internally.
131 const char *profname
;
134 } oauthswitches
[] = {
135 { "oauth-%s-credential-file", OAUTHCREDFILESW
, NULL
},
136 { "oauth-%s-client_id", OAUTHCLIDSW
, NULL
},
137 { "oauth-%s-client_secret", OAUTHCLSECSW
, NULL
},
138 { "oauth-%s-auth_endpoint", OAUTHAUTHENDSW
, NULL
},
139 { "oauth-%s-redirect_uri", OAUTHREDIRSW
, NULL
},
140 { "oauth-%s-token_endpoint", OAUTHTOKENDSW
, NULL
},
141 { "oauth-%s-scope", OAUTHSCOPESW
, NULL
},
152 * flags for headers->flags
154 #define HNOP 0x0000 /* just used to keep .set around */
155 #define HBAD 0x0001 /* bad header - don't let it through */
156 #define HADR 0x0002 /* header has an address field */
157 #define HSUB 0x0004 /* Subject: header */
158 #define HTRY 0x0008 /* try to send to addrs on header */
159 #define HBCC 0x0010 /* don't output this header, unless MTS_SENDMAIL_PIPE */
160 #define HMNG 0x0020 /* munge this header */
161 #define HNGR 0x0040 /* no groups allowed in this header */
162 #define HFCC 0x0080 /* FCC: type header */
163 #define HNIL 0x0100 /* okay for this header not to have addrs */
164 #define HIGN 0x0200 /* ignore this header */
165 #define HDCC 0x0400 /* another undocumented feature */
166 #define HONE 0x0800 /* Only (zero or) one address allowed */
167 #define HEFM 0x1000 /* Envelope-From: header */
168 #define HMIM 0x2000 /* MIME-Version: header */
169 #define HCTE 0x4000 /* Content-Transfer-Encoding: header */
172 * flags for headers->set
174 #define MFRM 0x0001 /* we've seen a From: */
175 #define MDAT 0x0002 /* we've seen a Date: */
176 #define MRFM 0x0004 /* we've seen a Resent-From: */
177 #define MVIS 0x0008 /* we've seen sighted addrs */
178 #define MINV 0x0010 /* we've seen blind addrs */
179 #define MSND 0x0020 /* we've seen a Sender: */
180 #define MRSN 0x0040 /* We've seen a Resent-Sender: */
181 #define MEFM 0x0080 /* We've seen Envelope-From: */
182 #define MMIM 0x0100 /* We've seen Mime-Version: */
184 static struct headers NHeaders
[] = {
185 { "Return-Path", HBAD
, 0 },
186 { "Received", HBAD
, 0 },
187 { "Reply-To", HADR
|HNGR
, 0 },
188 { "From", HADR
|HNGR
, MFRM
},
189 { "Sender", HADR
|HNGR
|HONE
, MSND
},
191 { "Subject", HSUB
, 0 },
192 { "To", HADR
|HTRY
, MVIS
},
193 { "cc", HADR
|HTRY
, MVIS
},
194 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, MINV
},
195 { "Dcc", HADR
|HTRY
|HDCC
|HNIL
, MVIS
}, /* sorta cc & bcc combined */
196 { "Message-ID", HBAD
, 0 },
198 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
199 { "MIME-Version", HMIM
, MMIM
},
200 { "Content-Transfer-Encoding", HCTE
, 0 },
204 static struct headers RHeaders
[] = {
205 { "Resent-Reply-To", HADR
|HNGR
, 0 },
206 { "Resent-From", HADR
|HNGR
, MRFM
},
207 { "Resent-Sender", HADR
|HNGR
, MRSN
},
208 { "Resent-Date", HBAD
, 0 },
209 { "Resent-Subject", HSUB
, 0 },
210 { "Resent-To", HADR
|HTRY
, MVIS
},
211 { "Resent-cc", HADR
|HTRY
, MVIS
},
212 { "Resent-Bcc", HADR
|HTRY
|HBCC
, MINV
},
213 { "Resent-Message-ID", HBAD
, 0 },
214 { "Resent-Fcc", HFCC
, 0 },
215 { "Reply-To", HADR
, 0 },
216 { "From", HADR
|HNGR
, MFRM
},
217 { "Sender", HADR
|HNGR
, MSND
},
218 { "Date", HNOP
, MDAT
},
219 { "To", HADR
|HNIL
, 0 },
220 { "cc", HADR
|HNIL
, 0 },
221 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, 0 },
223 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
224 { "MIME-Version", HMIM
, MMIM
},
225 { "Content-Transfer-Encoding", HCTE
, 0 },
229 static short fccind
= 0; /* index into fccfold[] */
230 static short outputlinelen
= OUTPUTLINELEN
;
232 static int pfd
= NOTOK
; /* fd to write annotation list to */
233 static bool recipients
; /* how many people will get a copy */
234 static int unkadr
= 0; /* how many of those were unknown */
235 static int badadr
= 0; /* number of bad addrs */
236 static bool badmsg
; /* message has bad semantics */
237 static bool verbose
; /* spell it out */
238 static bool format
= true; /* format addresses */
239 static bool mime
; /* use MIME-style encapsulations for Bcc */
240 static bool msgid
; /* add msgid */
241 static bool debug
; /* debugging post */
242 static bool watch
; /* watch the delivery process */
243 static bool whomsw
; /* we are whom not post */
244 static bool checksw
; /* whom -check */
245 static int linepos
=0; /* putadr()'s position on the line */
246 static int nameoutput
=0; /* putadr() has output header name */
247 static bool sasl
; /* Use SASL auth for SMTP */
248 static char *saslmech
=NULL
; /* Force use of particular SASL mech */
249 static char *user
=NULL
; /* Authenticate as this user */
250 static char *port
="submission"; /* Name of server port for SMTP submission */
251 static int tlsflag
=0; /* Flags to control TLS settings */
252 static int fromcount
=0; /* Count of addresses on From: header */
253 static bool seensender
; /* Have we seen a Sender: header? */
255 static unsigned msgflags
= 0; /* what we've seen */
259 static int msgstate
= NORMAL
;
261 static time_t tclock
= 0; /* the time we started (more or less) */
263 static SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
265 static char tmpfil
[BUFSIZ
];
266 static char bccfil
[BUFSIZ
];
268 static char from
[BUFSIZ
]; /* my network address */
269 static char sender
[BUFSIZ
]; /* my Sender: header */
270 static char efrom
[BUFSIZ
]; /* my Envelope-From: header */
271 static char fullfrom
[BUFSIZ
]; /* full contents of From header */
272 static char *filter
= NULL
; /* the filter for BCC'ing */
273 static char *subject
= NULL
; /* the subject field for BCC'ing */
274 static char *fccfold
[FCCS
]; /* foldernames for FCC'ing */
275 enum encoding
{ UNKNOWN
= 0, BINARY
= 1, SEVENBIT
= 7, EIGHTBIT
= 8 };
276 static enum encoding cte
= UNKNOWN
;
278 static struct headers
*hdrtab
; /* table for the message we're doing */
280 static struct mailname localaddrs
; /* local addrs */
281 static struct mailname netaddrs
; /* network addrs */
282 static struct mailname uuaddrs
; /* uucp addrs */
283 static struct mailname tmpaddrs
; /* temporary queue */
286 static char *clientsw
= NULL
;
287 static char *serversw
= NULL
;
289 static char prefix
[] = "----- =_aaaaaaaaaa";
291 static char *partno
= NULL
;
296 static void putfmt (char *, char *, int *, FILE *);
297 static void start_headers (void);
298 static void finish_headers (FILE *);
299 static int get_header (char *, struct headers
*) PURE
;
300 static int putadr (char *, char *, struct mailname
*, FILE *, unsigned int,
301 char *, unsigned int);
302 static void putgrp (char *, char *, FILE *, unsigned int);
303 static int insert (struct mailname
*);
304 static void pl (void);
305 static void anno (void);
306 static int annoaux (struct mailname
*);
307 static void insert_fcc (struct headers
*, char *);
308 static void make_bcc_file (int);
309 static void verify_all_addresses (int, int, char *, int, char *);
310 static void chkadr (void) PURE
;
311 static void sigon (void);
312 static void sigoff (void);
313 static void p_refile (char *);
314 static void fcc (char *, char *);
315 static void fatal (char *, char *, ...) CHECK_PRINTF(2, 3);
316 static void post (char *, int, int, int, char *, int, char *);
317 static void do_text (char *file
, int fd
);
318 static void do_an_address (struct mailname
*, int);
319 static void do_addresses (int, int);
320 static int find_prefix (void);
324 main (int argc
, char **argv
)
326 int state
, compnum
, dashstuff
= 0, swnum
;
327 bool oauth_flag
= false;
329 bool noverify
= false;
330 int eai
= 0; /* use Email Address Internationalization (EAI) (SMTPUTF8) */
331 char *cp
, *msg
= NULL
, **argp
, **arguments
, *envelope
;
332 char buf
[NMH_BUFSIZ
], name
[NAMESZ
], *auth_svc
= NULL
;
334 m_getfld_state_t gstate
;
336 if (nmh_init(argv
[0], false, false)) { return 1; }
339 arguments
= getarguments (invo_name
, argc
, argv
, 0);
342 while ((cp
= *argp
++)) {
344 switch ((swnum
= smatch (++cp
, switches
))) {
346 ambigsw (cp
, switches
);
349 die("-%s unknown", cp
);
352 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
353 print_help (buf
, switches
, 0);
356 print_version(invo_name
);
360 if (!(cp
= *argp
++) || *cp
== '-')
361 die("missing argument to %s", argp
[-2]);
362 /* create a minimal context */
363 if (context_foil (cp
) == -1)
368 if (!(cp
= *argp
++) || *cp
== '-')
369 die("missing argument to %s", argp
[-2]);
370 if ((state
= alias (cp
)) != AK_OK
)
371 die("aliasing error in %s - %s",
372 cp
, akerror (state
));
391 if (!(filter
= *argp
++) || *filter
== '-')
392 die("missing argument to %s", argp
[-2]);
447 if (!(cp
= *argp
++) || *cp
== '-')
448 die("missing argument to %s", argp
[-2]);
449 if ((outputlinelen
= atoi (cp
)) < 10)
450 die("impossible width %d", outputlinelen
);
454 if (!(cp
= *argp
++) || *cp
== '-')
455 die("missing argument to %s", argp
[-2]);
456 if ((pfd
= atoi (cp
)) <= 2)
457 die("bad argument %s %s", argp
[-2], cp
);
461 if (!(clientsw
= *argp
++) || *clientsw
== '-')
462 die("missing argument to %s", argp
[-2]);
465 if (!(serversw
= *argp
++) || *serversw
== '-')
466 die("missing argument to %s", argp
[-2]);
473 if (!(partno
= *argp
++) || *partno
== '-')
474 die("missing argument to %s", argp
[-2]);
486 if (!(saslmech
= *argp
++) || *saslmech
== '-')
487 die("missing argument to %s", argp
[-2]);
491 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
492 die("missing argument to %s", argp
[-2]);
496 case OAUTHCREDFILESW
:
506 if (!(cp
= *argp
++) || *cp
== '-')
507 die("missing argument to %s", argp
[-2]);
509 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
510 if (oauthswitches
[i
].switchnum
== swnum
) {
511 oauthswitches
[i
].value
= cp
;
516 if (oauthswitches
[i
].profname
== NULL
)
517 die("internal error: cannot map switch %s "
518 "to profile entry", argp
[-2]);
525 if (!(user
= *argp
++) || *user
== '-')
526 die("missing argument to %s", argp
[-2]);
530 if (!(port
= *argp
++) || *port
== '-')
531 die("missing argument to %s", argp
[-2]);
555 if (!(cp
= *argp
++) || *cp
== '-')
556 die("missing argument to %s", argp
[-2]);
561 if (!(cp
= *argp
++) || *cp
== '-')
562 die("missing argument to %s", argp
[-2]);
567 if (!(cp
= *argp
++) || *cp
== '-')
568 die("missing argument to %s", argp
[-2]);
573 if (!(cp
= *argp
++) || *cp
== '-')
574 die("missing argument to %s", argp
[-2]);
575 save_mts_method (cp
);
578 case CREDENTIALSSW
: {
579 if (!(cp
= *argp
++) || *cp
== '-')
580 die("missing argument to %s", argp
[-2]);
581 add_profile_entry ("credentials", cp
);
586 if (!(cp
= *argp
++) || *cp
== '-')
587 die("missing argument to %s", argp
[-2]);
588 if (save_message_id_style (cp
) != 0)
589 die("unsupported messageid \"%s\"", cp
);
594 die("only one message at a time!");
601 die("usage: %s [switches] file", invo_name
);
603 if (outputlinelen
< 10)
604 die("impossible width %d", outputlinelen
);
606 if ((in
= fopen (msg
, "r")) == NULL
)
607 adios (msg
, "unable to open");
615 if ((out
= fopen ("/dev/null", "w")) == NULL
)
616 adios ("/dev/null", "unable to open");
618 char *cp
= m_mktemp2(NULL
, invo_name
, NULL
, &out
);
620 die("unable to create temporary file in %s",
623 strncpy(tmpfil
, cp
, sizeof(tmpfil
));
627 hdrtab
= msgstate
== NORMAL
? NHeaders
: RHeaders
;
629 gstate
= m_getfld_state_init(in
);
630 for (compnum
= 1;;) {
631 int bufsz
= sizeof buf
;
632 switch (state
= m_getfld2(&gstate
, name
, buf
, &bufsz
)) {
636 cp
= mh_xstrdup(buf
);
637 while (state
== FLDPLUS
) {
639 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
642 putfmt (name
, cp
, &eai
, out
);
647 finish_headers (out
);
650 fprintf (out
, "\n%s", buf
);
651 while (state
== BODY
) {
653 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
659 finish_headers (out
);
664 die("message format error in component #%d", compnum
);
667 die("getfld() returned %d", state
);
671 m_getfld_state_destroy (&gstate
);
684 * Here's how we decide which address to use as the envelope-from
687 * - If we were given an Envelope-From header, use that.
688 * - If we were given a Sender: address, use that.
689 * - Otherwise, use the address on the From: line
692 if (msgflags
& MEFM
) {
694 } else if (seensender
) {
703 * The user didn't specify any of the tls switches. Try to
704 * help them by implying -initialtls if they're using port 465
705 * (smtps, until IANA revoked that registration in 1998).
707 tls
= ! strcmp (port
, "465") || ! strcasecmp (port
, "smtps")
710 #else /* ! TLS_SUPPORT */
712 #endif /* ! TLS_SUPPORT */
716 tlsflag
= S_STARTTLS
;
723 tlsflag
|= S_NOVERIFY
;
726 * If we were given any oauth flags, store the appropriate profile
727 * entries and make sure an authservice was given (we have to do this
728 * here because we aren't guaranteed the authservice will be given on
729 * the command line before the other OAuth flags are given).
736 if (auth_svc
== NULL
) {
737 die("No authentication service given with -authservice");
740 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
741 if (oauthswitches
[i
].value
!= NULL
) {
742 snprintf(sbuf
, sizeof(sbuf
),
743 oauthswitches
[i
].profname
, auth_svc
);
744 sbuf
[sizeof(sbuf
) - 1] = '\0';
745 add_profile_entry(sbuf
, oauthswitches
[i
].value
);
750 /* If we are doing a "whom" check */
752 /* This won't work with MTS_SENDMAIL_PIPE. */
753 verify_all_addresses (1, eai
, envelope
, oauth_flag
, auth_svc
);
757 if (msgflags
& MINV
) {
758 make_bcc_file (dashstuff
);
759 if (msgflags
& MVIS
) {
760 if (sm_mts
!= MTS_SENDMAIL_PIPE
) {
761 /* It would be nice to have support to call
762 verify_all_addresses with MTS_SENDMAIL_PIPE, but
763 that might require running sendmail as root. Note
764 that spost didn't verify addresses. */
765 verify_all_addresses (verbose
, eai
, envelope
, oauth_flag
,
768 post (tmpfil
, 0, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
770 post (bccfil
, 1, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
771 (void) m_unlink (bccfil
);
773 post (tmpfil
, 0, isatty (1), eai
, envelope
, oauth_flag
, auth_svc
);
777 (void) m_unlink (tmpfil
);
781 printf ("Partial Message #%s Processed\n", partno
);
783 puts("Message Processed");
796 putfmt (char *name
, char *str
, int *eai
, FILE *out
)
802 char namep
[BUFSIZ
], error
[BUFSIZ
];
803 char *savehdr
= NULL
;
804 unsigned int savehdrlen
= 0;
805 struct mailname
*mp
= NULL
, *np
= NULL
;
808 while (*str
== ' ' || *str
== '\t')
811 if (msgstate
== NORMAL
&& uprf (name
, "resent")) {
812 inform("illegal header line -- %s:", name
);
818 /* Check each header field value to see if it has any 8-bit characters.
819 If it does, enable EAI support. */
820 if (contains8bit(str
, NULL
)) {
822 puts("EAI/SMTPUTF8 enabled");
825 /* Enable SMTPUTF8. */
828 /* Enable passing of utf-8 setting to getname()/getadrx(). */
833 if ((i
= get_header (name
, hdrtab
)) == NOTOK
) {
834 if (strncasecmp (name
, "nmh-", 4)) {
835 fprintf (out
, "%s: %s", name
, str
);
837 /* Filter out all Nmh-* headers, because Norm asked. They
838 should never have reached this point. Warn about any
839 that are non-empty. */
840 if (strcmp (str
, "\n")) {
841 trim_suffix_c(str
, '\n');
843 inform("ignoring header line -- %s: %s", name
, str
);
852 if (hdr
->flags
& HIGN
) {
855 if (hdr
->flags
& HBAD
) {
856 inform("illegal header line -- %s:", name
);
860 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
862 if (hdr
->flags
& HSUB
)
863 subject
= subject
? add (str
, add ("\t", subject
)) : mh_xstrdup(str
);
864 if (hdr
->flags
& HFCC
) {
865 if ((cp
= strrchr(str
, '\n')))
867 for (pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
869 insert_fcc (hdr
, pp
);
871 insert_fcc (hdr
, pp
);
874 if (hdr
->flags
& HCTE
) {
875 if (strncasecmp (str
, "7bit", 4) == 0) {
877 } else if (strncasecmp (str
, "8bit", 4) == 0) {
879 } else if (strncasecmp (str
, "binary", 6) == 0) {
883 if (!(hdr
->flags
& HADR
)) {
884 fprintf (out
, "%s: %s", name
, str
);
889 * If this is a From:/Resent-From: header, save the full thing for
890 * later in case we need it for use when constructing a Bcc draft message.
891 * Because we want to capture the results of alias expansion, save
892 * the output from putadr().
895 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
898 savehdrlen
= sizeof(fullfrom
);
901 tmpaddrs
.m_next
= NULL
;
903 for (count
= 0; (cp
= getname (str
)); count
++) {
904 if ((mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
908 tmpaddrs
.m_next
= mp
;
912 admonish(cp
, "%s", error
);
913 if (hdr
->flags
& HTRY
)
921 if (hdr
->flags
& HNIL
)
922 fprintf (out
, "%s: %s", name
, str
);
925 * Sender (or Resent-Sender) can have only one address
927 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
928 : (hdr
->set
& MSND
)) {
929 inform("%s: field requires one address", name
);
933 inform("%s: field requires at least one address", name
);
940 if (count
> 1 && (hdr
->flags
& HONE
)) {
941 inform("%s: field only permits one address", name
);
946 nameoutput
= linepos
= 0;
947 snprintf (namep
, sizeof(namep
), "%s%s",
948 (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
950 for (grp
= false, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
951 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
952 /* The address doesn't include a host, so it might be an alias. */
953 pp
= akvalue (mp
->m_mbox
); /* do mh alias substitution */
954 qp
= akvisible () ? mp
->m_mbox
: "";
957 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
958 while ((cp
= getname (pp
))) {
959 if (!(mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
960 admonish(cp
, "%s", error
);
966 * If it's a From: or Resent-From: header, save the address
967 * for later possible use (as the envelope address for SMTP)
970 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
971 : (hdr
->set
& MFRM
)) {
972 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
973 from
[sizeof(from
) - 1] = '\0';
978 * Also save the Sender: or Resent-Sender: header as well
981 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
982 : (hdr
->set
& MSND
)) {
983 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
984 sender
[sizeof(sender
) - 1] = '\0';
989 * ALSO ... save Envelope-From
992 if (hdr
->set
& MEFM
) {
993 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
994 efrom
[sizeof(efrom
) - 1] = '\0';
997 if (hdr
->flags
& HBCC
)
1000 mp
->m_ingrp
= np
->m_ingrp
;
1001 else if (mp
->m_gname
)
1002 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1004 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1005 /* Catch this before sendmail chokes with:
1006 "553 List:; syntax illegal for recipient
1008 If we wanted to, we could expand out blind
1009 aliases and put them in Bcc:, but then
1010 they'd have the Blind-Carbon-Copy
1012 die( "blind lists not compatible with"
1018 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
, savehdr
,
1020 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1029 /* Address includes a host, so no alias substitution is needed. */
1032 * If it's a From: or Resent-From header, save the address
1033 * for later possible use (as the envelope address for SMTP)
1036 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
1037 : (hdr
->set
& MFRM
)) {
1038 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
1043 * Also save the Sender: header as well
1046 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
1047 : (hdr
->set
& MSND
)) {
1048 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
1049 sender
[sizeof(sender
) - 1] = '\0';
1054 * ALSO ... save Envelope-From
1057 if (hdr
->set
& MEFM
) {
1058 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1059 efrom
[sizeof(efrom
) - 1] = '\0';
1062 if (hdr
->flags
& HBCC
)
1065 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1068 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
, savehdr
, savehdrlen
);
1072 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1079 * If it was a From header, strip off any trailing newlines from
1080 * the alias-expanded From line.
1083 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
1084 while (*fullfrom
&& fullfrom
[strlen(fullfrom
) - 1] == '\n') {
1085 fullfrom
[strlen(fullfrom
) - 1] = '\0';
1089 if (grp
&& (hdr
->flags
& HNGR
)) {
1090 inform("%s: field does not allow groups", name
);
1100 start_headers (void)
1105 * Probably not necessary, but just in case ...
1116 * Now that we've outputted the header fields in the draft
1117 * message, we will now output any remaining header fields
1118 * that we need to add/create.
1122 finish_headers (FILE *out
)
1126 if (!(msgflags
& MFRM
)) {
1128 * A From: header is now required in the draft.
1130 inform("message has no From: header");
1131 inform("See default components files for examples");
1136 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1137 inform("A Sender: or Envelope-From: header is required "
1138 "with multiple\nFrom: addresses");
1146 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1148 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1150 * If we have multiple From: addresses, make sure we have an
1151 * Sender: header. If we don't have one, then generate one
1152 * from Envelope-From: (which in this case, cannot be blank)
1155 if (fromcount
> 1 && !seensender
) {
1156 if (efrom
[0] == '\0') {
1157 inform("Envelope-From cannot be blank when there "
1158 "is multiple From: addresses\nand no Sender: "
1162 fprintf (out
, "Sender: %s\n", efrom
);
1166 if (!(msgflags
& MVIS
))
1167 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
1171 if (!(msgflags
& MDAT
)) {
1172 inform("message has no Date: header");
1175 if (!(msgflags
& MFRM
)) {
1176 inform("message has no From: header");
1179 if (!(msgflags
& MRFM
)) {
1180 inform("message has no Resent-From: header");
1181 inform("See default components files for examples");
1185 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1186 inform("A Resent-Sender: or Envelope-From: header is "
1187 "required with multiple\nResent-From: addresses");
1195 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
1197 fprintf (out
, "Resent-Message-ID: %s\n",
1198 message_id (tclock
, 0));
1200 * If we have multiple Resent-From: addresses, make sure we have an
1201 * Resent-Sender: header. If we don't have one, then generate one
1202 * from Envelope-From (which in this case, cannot be blank)
1205 if (fromcount
> 1 && !seensender
) {
1206 if (efrom
[0] == '\0') {
1207 inform("Envelope-From cannot be blank when there "
1208 "is multiple Resent-From: addresses and no "
1209 "Resent-Sender: header");
1212 fprintf (out
, "Resent-Sender: %s\n", efrom
);
1216 if (!(msgflags
& MVIS
))
1217 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
1222 die("re-format message and try again");
1224 die("no addressees");
1229 get_header (char *header
, struct headers
*table
)
1233 header
= FENDNULL(header
);
1234 for (h
= table
; h
->value
; h
++)
1235 if (!strcasecmp(FENDNULL(h
->value
), header
))
1243 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
,
1244 unsigned int flags
, char *savehdr
, unsigned int savehdrsize
)
1247 bool saveappend
= false;
1250 char buffer
[BUFSIZ
];
1252 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
1254 if (sm_mts
!= MTS_SENDMAIL_PIPE
&&
1255 ((flags
& (HBCC
| HDCC
| HEFM
)) || mp
->m_ingrp
))
1259 fprintf (out
, "%s: ", name
);
1260 linepos
+= (nameoutput
= strlen (name
) + 2);
1264 shlen
= strlen(savehdr
);
1268 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
1269 mp
->m_pers
= mh_xstrdup(aka
);
1272 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
1275 cp
= adrformat (mp
);
1282 if (linepos
!= nameoutput
) {
1283 if (len
+ linepos
+ 2 > outputlinelen
) {
1284 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
1286 if (shlen
+ 2 + nameoutput
+ len
>= savehdrsize
) {
1289 snprintf(savehdr
+ shlen
, savehdrsize
- shlen
, ",\n%*s",
1297 if (shlen
+ 2 + len
>= savehdrsize
) {
1300 strncat(savehdr
, ", ", savehdrsize
- shlen
);
1308 if (saveappend
&& shlen
+ len
< savehdrsize
)
1309 strncat(savehdr
, cp
, savehdrsize
- shlen
+ len
);
1313 return flags
& HTRY
;
1318 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
1323 if (sm_mts
!= MTS_SENDMAIL_PIPE
&& (flags
& HBCC
))
1327 fprintf (out
, "%s: ", name
);
1328 linepos
+= (nameoutput
= strlen (name
) + 2);
1331 cp
= concat (group
, ";", NULL
);
1334 if (linepos
> nameoutput
) {
1335 if (len
+ linepos
+ 2 > outputlinelen
) {
1336 fprintf (out
, ",\n%*s", nameoutput
, "");
1337 linepos
= nameoutput
;
1351 insert (struct mailname
*np
)
1353 struct mailname
*mp
;
1355 if (np
->m_mbox
== NULL
)
1358 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1359 : np
->m_type
== UUCPHOST
? &uuaddrs
1363 if (!strcasecmp (FENDNULL(np
->m_host
),
1364 FENDNULL(mp
->m_next
->m_host
)) &&
1365 !strcasecmp (FENDNULL(np
->m_mbox
),
1366 FENDNULL(mp
->m_next
->m_mbox
)) &&
1367 np
->m_bcc
== mp
->m_next
->m_bcc
)
1380 struct mailname
*mp
;
1382 fputs("-------\n\t-- Addresses --\nlocal:\t", stdout
);
1383 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1384 printf ("%s%s%s", mp
->m_mbox
,
1385 mp
->m_bcc
? "[BCC]" : "",
1386 mp
->m_next
? ",\n\t" : "");
1388 fputs("\nnet:\t", stdout
);
1389 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1390 printf ("%s%s@%s%s%s", FENDNULL(mp
->m_path
),
1391 mp
->m_mbox
, mp
->m_host
,
1392 mp
->m_bcc
? "[BCC]" : "",
1393 mp
->m_next
? ",\n\t" : "");
1395 fputs("\nuucp:\t", stdout
);
1396 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1397 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1398 mp
->m_bcc
? "[BCC]" : "",
1399 mp
->m_next
? ",\n\t" : "");
1401 fputs("\n\t-- Folder Copies --\nfcc:\t", stdout
);
1402 for (i
= 0; i
< fccind
; i
++)
1403 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1411 struct mailname
*mp
;
1413 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1414 if (annoaux (mp
) == NOTOK
)
1417 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1418 if (annoaux (mp
) == NOTOK
)
1421 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1422 if (annoaux (mp
) == NOTOK
)
1432 annoaux (struct mailname
*mp
)
1435 char buffer
[BUFSIZ
];
1437 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1438 i
= strlen (buffer
);
1440 return write(pfd
, buffer
, i
) == i
? OK
: NOTOK
;
1445 insert_fcc (struct headers
*hdr
, char *pp
)
1449 for (cp
= pp
; isspace ((unsigned char) *cp
); cp
++)
1451 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace ((unsigned char) *pp
); pp
--)
1459 die("too many %ss", hdr
->value
);
1460 fccfold
[fccind
++] = mh_xstrdup(cp
);
1468 make_bcc_file (int dashstuff
)
1474 char *tfile
= NULL
, *program
;
1476 if ((tfile
= m_mktemp2(NULL
, "bccs", NULL
, &out
)) == NULL
) {
1477 die("unable to create temporary file in %s", get_temp_dir());
1479 strncpy (bccfil
, tfile
, sizeof(bccfil
));
1481 fprintf (out
, "From: %s\n", fullfrom
);
1482 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1484 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1486 fprintf (out
, "Subject: %s", subject
);
1487 fprintf (out
, "BCC:\n");
1490 * Use MIME encapsulation for Bcc messages
1496 * Check if any lines in the message clash with the
1497 * prefix for the MIME multipart separator. If there
1498 * is a clash, increment one of the letters in the
1499 * prefix and check again.
1501 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1502 die("lost prefix start");
1503 while (find_prefix () == NOTOK
) {
1506 else if (*++cp
== 0)
1507 die("can't find a unique delimiter string");
1512 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1513 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1514 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1516 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1522 * Do mhl filtering of Bcc messages instead
1523 * of MIME encapsulation.
1525 if (filter
!= NULL
) {
1529 adios ("fork", "unable to");
1532 dup2 (fileno (out
), 1);
1534 vec
= argsplit(mhlproc
, &program
, &i
);
1535 vec
[i
++] = "-forward";
1540 /* was the flag -[no]dashstuffing specified? */
1542 vec
[i
++] = "-dashstuffing";
1543 else if (dashstuff
< 0)
1544 vec
[i
++] = "-nodashstuffing";
1547 execvp (program
, vec
);
1548 fprintf (stderr
, "unable to exec ");
1553 pidXwait (child_id
, mhlproc
);
1557 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1558 adios (tmpfil
, "unable to re-open");
1561 * If using MIME encapsulation, or if the -nodashstuffing
1562 * flag was given, then just copy message. Else do
1563 * RFC934 quoting (dashstuffing).
1565 if (mime
|| dashstuff
< 0)
1566 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1568 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1572 fseek (out
, 0L, SEEK_END
);
1574 fprintf (out
, "\n--%s--\n", prefix
);
1576 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1582 * Scan message to check if any lines clash with
1583 * the prefix of the MIME multipart separator.
1590 char buffer
[BUFSIZ
];
1593 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1594 adios (tmpfil
, "unable to re-open");
1596 while (fgets (buffer
, sizeof buffer
, in
))
1597 if (buffer
[0] == '-' && buffer
[1] == '-') {
1600 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1601 if (!isspace ((unsigned char) *cp
))
1604 if (strcmp (buffer
+ 2, prefix
) == 0) {
1618 if (badadr
&& unkadr
)
1619 fatal (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1620 badadr
, PLURALS(badadr
), unkadr
, PLURALS(badadr
));
1622 fatal (NULL
, "%d address%s unparsable", badadr
, PLURALS(badadr
));
1624 fatal (NULL
, "%d addressee%s undeliverable", unkadr
, PLURALS(unkadr
));
1629 do_addresses (int bccque
, int talk
)
1633 struct mailname
*lp
;
1636 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1637 if (lp
->m_bcc
? bccque
: !bccque
) {
1639 puts(" -- Local Recipients --");
1640 do_an_address (lp
, talk
);
1645 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1646 if (lp
->m_bcc
? bccque
: !bccque
) {
1648 puts(" -- UUCP Recipients --");
1649 do_an_address (lp
, talk
);
1654 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1655 if (lp
->m_bcc
? bccque
: !bccque
) {
1657 puts(" -- Network Recipients --");
1658 do_an_address (lp
, talk
);
1664 if (rp_isbad (retval
= sm_waend ()))
1665 fatal (NULL
, "problem ending addresses; %s", rp_string (retval
));
1670 * MTS-SPECIFIC INTERACTION
1675 * SENDMAIL/SMTP routines
1679 post (char *file
, int bccque
, int talk
, int eai
, char *envelope
,
1680 int oauth_flag
, char *auth_svc
)
1686 if (msgflags
& MINV
)
1687 printf (" -- Posting for %s Recipients --\n",
1688 bccque
? "Blind" : "Sighted");
1690 puts(" -- Posting for All Recipients --");
1695 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1696 char **argp
, *program
;
1702 adios ("fork", "unable to");
1705 if (freopen( file
, "r", stdin
) == NULL
) {
1706 adios (file
, "can't reopen for sendmail");
1709 argp
= argsplit(sendmail
, &program
, &argc
);
1710 argp
[argc
++] = "-t"; /* read msg for recipients */
1711 argp
[argc
++] = "-i"; /* don't stop on "." */
1713 argp
[argc
++] = "-bv";
1715 argp
[argc
++] = "-v";
1718 execv (program
, argp
);
1719 adios (sendmail
, "can't exec");
1722 pidXwait (child_id
, NULL
);
1726 const int fd
= open (file
, O_RDONLY
);
1730 fatal (file
, "unable to re-open");
1733 if (msgflags
& MMIM
&& cte
!= UNKNOWN
) {
1734 /* MIME message with C-T-E header. (BINARYMIME isn't
1735 supported, use 8BITMIME instead for binary.) */
1736 eightbit
= cte
!= SEVENBIT
;
1738 if (scan_input (fd
, &eightbit
) == NOTOK
) {
1740 fatal (file
, "problem reading from");
1744 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1745 verbose
, snoop
, sasl
, saslmech
, user
,
1746 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1747 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1749 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1752 do_addresses (bccque
, talk
&& verbose
);
1757 sm_end (!(msgflags
& MINV
) || bccque
? OK
: DONE
);
1761 if (msgflags
& MINV
)
1762 printf (" -- %s Recipient Copies Posted --\n",
1763 bccque
? "Blind" : "Sighted");
1765 puts(" -- Recipient Copies Posted --");
1773 /* Address Verification */
1776 verify_all_addresses (int talk
, int eai
, char *envelope
, int oauth_flag
,
1780 struct mailname
*lp
;
1784 if (!whomsw
|| checksw
) {
1785 /* Not sending message body, so don't need to use 8BITMIME. */
1786 const int eightbit
= 0;
1788 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1789 verbose
, snoop
, sasl
, saslmech
, user
,
1790 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1791 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1792 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1796 if (talk
&& !whomsw
)
1797 puts(" -- Address Verification --");
1798 if (talk
&& localaddrs
.m_next
)
1799 puts(" -- Local Recipients --");
1800 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1801 do_an_address (lp
, talk
);
1803 if (talk
&& uuaddrs
.m_next
)
1804 puts(" -- UUCP Recipients --");
1805 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1806 do_an_address (lp
, talk
);
1808 if (talk
&& netaddrs
.m_next
)
1809 puts(" -- Network Recipients --");
1810 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1811 do_an_address (lp
, talk
);
1814 if (talk
&& !whomsw
)
1815 puts(" -- Address Verification Successful --");
1817 if (!whomsw
|| checksw
)
1818 sm_end (whomsw
? OK
: DONE
);
1826 do_an_address (struct mailname
*lp
, int talk
)
1832 switch (lp
->m_type
) {
1836 strncpy (addr
, mbox
, sizeof(addr
));
1840 mbox
= auxformat (lp
, 0);
1842 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1845 default: /* let SendMail decide if the host is bad */
1848 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1853 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1855 if (whomsw
&& !checksw
) {
1860 fputs(": ", stdout
);
1863 switch (retval
= sm_wadr (mbox
, host
,
1864 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1873 fprintf (stderr
, " %s: ", addr
);
1874 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1875 rp_string (retval
));
1881 fprintf (stderr
, " %s: ", addr
);
1882 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1890 do_text (char *file
, int fd
)
1895 lseek(fd
, 0, SEEK_SET
);
1897 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1898 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1899 fatal (NULL
, "problem writing text; %s\n", rp_string (retval
));
1903 fatal (file
, "problem reading from");
1905 switch (retval
= sm_wtend ()) {
1911 fatal (NULL
, "posting failed; %s", rp_string (retval
));
1915 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1929 (void) m_unlink (tmpfil
);
1930 if (msgflags
& MINV
)
1931 (void) m_unlink (bccfil
);
1933 if (!whomsw
|| checksw
)
1946 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1947 istat
= SIGNAL2 (SIGINT
, sigser
);
1948 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1949 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1959 SIGNAL (SIGHUP
, hstat
);
1960 SIGNAL (SIGINT
, istat
);
1961 SIGNAL (SIGQUIT
, qstat
);
1962 SIGNAL (SIGTERM
, tstat
);
1970 p_refile (char *file
)
1978 puts(" -- Filing Folder Copies --");
1979 for (i
= 0; i
< fccind
; i
++)
1980 fcc (file
, fccfold
[i
]);
1982 puts(" -- Folder Copies Filed --");
1987 * Call the `fileproc' to add the file to the folder.
1991 fcc (char *file
, char *folder
)
1996 char **arglist
, *program
;
1999 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
2006 fprintf (stderr
, " %sFcc %s: ",
2007 msgstate
== RESENT
? "Resent-" : "", folder
);
2008 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
2012 /* see if we need to add `+' */
2013 snprintf (fold
, sizeof(fold
), "%s%s",
2014 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
2016 /* now exec the fileproc */
2018 arglist
= argsplit(fileproc
, &program
, &argp
);
2019 arglist
[argp
++] = "-link";
2020 arglist
[argp
++] = "-file";
2021 arglist
[argp
++] = file
;
2022 arglist
[argp
++] = fold
;
2023 arglist
[argp
] = NULL
;
2024 execvp (program
, arglist
);
2028 if ((status
= pidwait (child_id
, OK
))) {
2030 fprintf (stderr
, " %sFcc %s: ",
2031 msgstate
== RESENT
? "Resent-" : "", folder
);
2032 pidstatus (status
, verbose
? stdout
: stderr
, fileproc
);
2047 fatal (char *what
, char *fmt
, ...)
2054 (void) m_unlink (tmpfil
);
2055 if (msgflags
& MINV
)
2056 (void) m_unlink (bccfil
);
2058 if (!whomsw
|| checksw
)
2063 advertise (what
, NULL
, fmt
, ap
);