]>
diplodocus.org Git - nmh/blob - uip/post.c
3812f8925994a9de13768239f7c7d921a73bce11
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/readconfig.h"
10 #include "sbr/ambigsw.h"
11 #include "sbr/pidstatus.h"
12 #include "sbr/print_version.h"
13 #include "sbr/print_help.h"
14 #include "sbr/arglist.h"
15 #include "sbr/error.h"
17 #include "h/signals.h"
18 #include "h/addrsbr.h"
19 #include "h/aliasbr.h"
20 #include "h/dropsbr.h"
26 #include "sbr/m_mktemp.h"
27 #include "sbr/message_id.h"
29 #ifdef HAVE_SYS_TIME_H
30 # include <sys/time.h>
34 #include "mts/smtp/smtp.h"
37 # define SASLminc(a) (a)
38 #else /* CYRUS_SASL */
39 # define SASLminc(a) 0
40 #endif /* CYRUS_SASL */
43 # define TLSminc(a) (a)
44 #else /* TLS_SUPPORT */
46 #endif /* TLS_SUPPORT */
49 # define OAUTHminc(a) (a)
50 #else /* OAUTH_SUPPORT */
51 # define OAUTHminc(a) 0
52 #endif /* OAUTH_SUPPORT */
54 #define FCCS 10 /* max number of fccs allowed */
56 /* In the following array of structures, the numeric second field of the
57 structures (minchars) is apparently used like this:
59 -# : Switch can be abbreviated to # characters; switch hidden in -help.
60 0 : Switch can't be abbreviated; switch shown in -help.
61 # : Switch can be abbreviated to # characters; switch shown in -help. */
63 #define POST_SWITCHES \
64 X("alias aliasfile", 0, ALIASW) \
65 X("check", -5, CHKSW) /* interface from whom */ \
66 X("nocheck", -7, NCHKSW) /* interface from whom */ \
67 X("debug", -5, DEBUGSW) \
68 X("dist", -4, DISTSW) /* interface from dist */ \
69 X("filter filterfile", 0, FILTSW) \
70 X("nofilter", 0, NFILTSW) \
71 X("format", 0, FRMTSW) \
72 X("noformat", 0, NFRMTSW) \
73 X("library directory", -7, LIBSW) /* interface from send, whom */ \
74 X("mime", 0, MIMESW) \
75 X("nomime", 0, NMIMESW) \
76 X("msgid", 0, MSGDSW) \
77 X("nomsgid", 0, NMSGDSW) \
78 X("verbose", 0, VERBSW) \
79 X("noverbose", 0, NVERBSW) \
80 X("watch", 0, WATCSW) \
81 X("nowatch", 0, NWATCSW) \
82 X("whom", -4, WHOMSW) /* interface from whom */ \
83 X("width columns", 0, WIDTHSW) \
84 X("version", 0, VERSIONSW) \
85 X("help", 0, HELPSW) \
86 X("dashstuffing", -12, BITSTUFFSW) /* should we dashstuff BCC messages? */ \
87 X("nodashstuffing", -14, NBITSTUFFSW) \
88 X("idanno number", -6, ANNOSW) /* interface from send */ \
89 X("client host", -6, CLIESW) \
90 X("server host", 6, SERVSW) /* specify alternate SMTP server */ \
91 X("snoop", -5, SNOOPSW) /* snoop the SMTP transaction */ \
92 X("partno", -6, PARTSW) \
93 X("sasl", SASLminc(4), SASLSW) \
94 X("nosasl", SASLminc(6), NOSASLSW) \
95 X("saslmech", SASLminc(5), SASLMECHSW) \
96 X("user", SASLminc(-4), USERSW) \
97 X("port server submission port name/number", 4, PORTSW) \
98 X("tls", TLSminc(-3), TLSSW) \
99 X("initialtls", TLSminc(-10), INITTLSSW) \
100 X("notls", TLSminc(-5), NTLSSW) \
101 X("certverify", TLSminc(-10), CERTVERSW) \
102 X("nocertverify", TLSminc(-12), NOCERTVERSW) \
103 X("fileproc", -4, FILEPROCSW) \
104 X("mhlproc", -3, MHLPROCSW) \
105 X("sendmail program", 0, MTSSM) \
106 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
107 X("credentials legacy|file:filename", 0, CREDENTIALSSW) \
108 X("messageid localname|random", 2, MESSAGEIDSW) \
109 X("authservice auth-service-name", OAUTHminc(-11), AUTHSERVICESW) \
110 X("oauthcredfile credential-file", OAUTHminc(-7), OAUTHCREDFILESW) \
111 X("oauthclientid client-id", OAUTHminc(-12), OAUTHCLIDSW) \
112 X("oauthclientsecret client-secret", OAUTHminc(-12), OAUTHCLSECSW) \
113 X("oauthauthendpoint authentication-endpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
114 X("oauthredirect redirect-uri", OAUTHminc(-6), OAUTHREDIRSW) \
115 X("oauthtokenendpoint token-endpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
116 X("oauthscope scope", OAUTHminc(-6), OAUTHSCOPESW) \
118 #define X(sw, minchars, id) id,
119 DEFINE_SWITCH_ENUM(POST
);
122 #define X(sw, minchars, id) { sw, minchars, id },
123 DEFINE_SWITCH_ARRAY(POST
, switches
);
128 * Mapping between command-line switches and profile entries, communicated
129 * from 'send'. We use a service name of 'post' internally.
133 const char *profname
;
136 } oauthswitches
[] = {
137 { "oauth-%s-credential-file", OAUTHCREDFILESW
, NULL
},
138 { "oauth-%s-client_id", OAUTHCLIDSW
, NULL
},
139 { "oauth-%s-client_secret", OAUTHCLSECSW
, NULL
},
140 { "oauth-%s-auth_endpoint", OAUTHAUTHENDSW
, NULL
},
141 { "oauth-%s-redirect_uri", OAUTHREDIRSW
, NULL
},
142 { "oauth-%s-token_endpoint", OAUTHTOKENDSW
, NULL
},
143 { "oauth-%s-scope", OAUTHSCOPESW
, NULL
},
154 * flags for headers->flags
156 #define HNOP 0x0000 /* just used to keep .set around */
157 #define HBAD 0x0001 /* bad header - don't let it through */
158 #define HADR 0x0002 /* header has an address field */
159 #define HSUB 0x0004 /* Subject: header */
160 #define HTRY 0x0008 /* try to send to addrs on header */
161 #define HBCC 0x0010 /* don't output this header, unless MTS_SENDMAIL_PIPE */
162 #define HMNG 0x0020 /* munge this header */
163 #define HNGR 0x0040 /* no groups allowed in this header */
164 #define HFCC 0x0080 /* FCC: type header */
165 #define HNIL 0x0100 /* okay for this header not to have addrs */
166 #define HIGN 0x0200 /* ignore this header */
167 #define HDCC 0x0400 /* another undocumented feature */
168 #define HONE 0x0800 /* Only (zero or) one address allowed */
169 #define HEFM 0x1000 /* Envelope-From: header */
170 #define HMIM 0x2000 /* MIME-Version: header */
171 #define HCTE 0x4000 /* Content-Transfer-Encoding: header */
174 * flags for headers->set
176 #define MFRM 0x0001 /* we've seen a From: */
177 #define MDAT 0x0002 /* we've seen a Date: */
178 #define MRFM 0x0004 /* we've seen a Resent-From: */
179 #define MVIS 0x0008 /* we've seen sighted addrs */
180 #define MINV 0x0010 /* we've seen blind addrs */
181 #define MSND 0x0020 /* we've seen a Sender: */
182 #define MRSN 0x0040 /* We've seen a Resent-Sender: */
183 #define MEFM 0x0080 /* We've seen Envelope-From: */
184 #define MMIM 0x0100 /* We've seen Mime-Version: */
186 static struct headers NHeaders
[] = {
187 { "Return-Path", HBAD
, 0 },
188 { "Received", HBAD
, 0 },
189 { "Reply-To", HADR
|HNGR
, 0 },
190 { "From", HADR
|HNGR
, MFRM
},
191 { "Sender", HADR
|HNGR
|HONE
, MSND
},
193 { "Subject", HSUB
, 0 },
194 { "To", HADR
|HTRY
, MVIS
},
195 { "cc", HADR
|HTRY
, MVIS
},
196 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, MINV
},
197 { "Dcc", HADR
|HTRY
|HDCC
|HNIL
, MVIS
}, /* sorta cc & bcc combined */
198 { "Message-ID", HBAD
, 0 },
200 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
201 { "MIME-Version", HMIM
, MMIM
},
202 { "Content-Transfer-Encoding", HCTE
, 0 },
206 static struct headers RHeaders
[] = {
207 { "Resent-Reply-To", HADR
|HNGR
, 0 },
208 { "Resent-From", HADR
|HNGR
, MRFM
},
209 { "Resent-Sender", HADR
|HNGR
, MRSN
},
210 { "Resent-Date", HBAD
, 0 },
211 { "Resent-Subject", HSUB
, 0 },
212 { "Resent-To", HADR
|HTRY
, MVIS
},
213 { "Resent-cc", HADR
|HTRY
, MVIS
},
214 { "Resent-Bcc", HADR
|HTRY
|HBCC
, MINV
},
215 { "Resent-Message-ID", HBAD
, 0 },
216 { "Resent-Fcc", HFCC
, 0 },
217 { "Reply-To", HADR
, 0 },
218 { "From", HADR
|HNGR
, MFRM
},
219 { "Sender", HADR
|HNGR
, MSND
},
220 { "Date", HNOP
, MDAT
},
221 { "To", HADR
|HNIL
, 0 },
222 { "cc", HADR
|HNIL
, 0 },
223 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, 0 },
225 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
226 { "MIME-Version", HMIM
, MMIM
},
227 { "Content-Transfer-Encoding", HCTE
, 0 },
231 static short fccind
= 0; /* index into fccfold[] */
232 static short outputlinelen
= OUTPUTLINELEN
;
234 static int pfd
= NOTOK
; /* fd to write annotation list to */
235 static bool recipients
; /* how many people will get a copy */
236 static int unkadr
= 0; /* how many of those were unknown */
237 static int badadr
= 0; /* number of bad addrs */
238 static bool badmsg
; /* message has bad semantics */
239 static bool verbose
; /* spell it out */
240 static bool format
= true; /* format addresses */
241 static bool mime
; /* use MIME-style encapsulations for Bcc */
242 static bool msgid
; /* add msgid */
243 static bool debug
; /* debugging post */
244 static bool watch
; /* watch the delivery process */
245 static bool whomsw
; /* we are whom not post */
246 static bool checksw
; /* whom -check */
247 static int linepos
=0; /* putadr()'s position on the line */
248 static int nameoutput
=0; /* putadr() has output header name */
249 static bool sasl
; /* Use SASL auth for SMTP */
250 static char *saslmech
=NULL
; /* Force use of particular SASL mech */
251 static char *user
=NULL
; /* Authenticate as this user */
252 static char *port
="submission"; /* Name of server port for SMTP submission */
253 static int tlsflag
=0; /* Flags to control TLS settings */
254 static int fromcount
=0; /* Count of addresses on From: header */
255 static bool seensender
; /* Have we seen a Sender: header? */
257 static unsigned msgflags
= 0; /* what we've seen */
261 static int msgstate
= NORMAL
;
263 static time_t tclock
= 0; /* the time we started (more or less) */
265 static SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
267 static char tmpfil
[BUFSIZ
];
268 static char bccfil
[BUFSIZ
];
270 static char from
[BUFSIZ
]; /* my network address */
271 static char sender
[BUFSIZ
]; /* my Sender: header */
272 static char efrom
[BUFSIZ
]; /* my Envelope-From: header */
273 static char fullfrom
[BUFSIZ
]; /* full contents of From header */
274 static char *filter
= NULL
; /* the filter for BCC'ing */
275 static char *subject
= NULL
; /* the subject field for BCC'ing */
276 static char *fccfold
[FCCS
]; /* foldernames for FCC'ing */
277 enum encoding
{ UNKNOWN
= 0, BINARY
= 1, SEVENBIT
= 7, EIGHTBIT
= 8 };
278 static enum encoding cte
= UNKNOWN
;
280 static struct headers
*hdrtab
; /* table for the message we're doing */
282 static struct mailname localaddrs
; /* local addrs */
283 static struct mailname netaddrs
; /* network addrs */
284 static struct mailname uuaddrs
; /* uucp addrs */
285 static struct mailname tmpaddrs
; /* temporary queue */
288 static char *clientsw
= NULL
;
289 static char *serversw
= NULL
;
291 static char prefix
[] = "----- =_aaaaaaaaaa";
293 static char *partno
= NULL
;
298 static void putfmt (char *, char *, int *, FILE *);
299 static void start_headers (void);
300 static void finish_headers (FILE *);
301 static int get_header (char *, struct headers
*) PURE
;
302 static int putadr (char *, char *, struct mailname
*, FILE *, unsigned int,
303 char *, unsigned int);
304 static void putgrp (char *, char *, FILE *, unsigned int);
305 static int insert (struct mailname
*);
306 static void pl (void);
307 static void anno (void);
308 static int annoaux (struct mailname
*);
309 static void insert_fcc (struct headers
*, char *);
310 static void make_bcc_file (int);
311 static void verify_all_addresses (int, int, char *, int, char *);
312 static void chkadr (void) PURE
;
313 static void sigon (void);
314 static void sigoff (void);
315 static void p_refile (char *);
316 static void fcc (char *, char *);
317 static void fatal (char *, char *, ...) CHECK_PRINTF(2, 3);
318 static void post (char *, int, int, int, char *, int, char *);
319 static void do_text (char *file
, int fd
);
320 static void do_an_address (struct mailname
*, int);
321 static void do_addresses (int, int);
322 static int find_prefix (void);
326 main (int argc
, char **argv
)
328 int state
, compnum
, dashstuff
= 0, swnum
;
329 bool oauth_flag
= false;
331 bool noverify
= false;
332 int eai
= 0; /* use Email Address Internationalization (EAI) (SMTPUTF8) */
333 char *cp
, *msg
= NULL
, **argp
, **arguments
, *envelope
;
334 char buf
[NMH_BUFSIZ
], name
[NAMESZ
], *auth_svc
= NULL
;
336 m_getfld_state_t gstate
;
338 if (nmh_init(argv
[0], false, false)) { return 1; }
341 arguments
= getarguments (invo_name
, argc
, argv
, 0);
344 while ((cp
= *argp
++)) {
346 switch ((swnum
= smatch (++cp
, switches
))) {
348 ambigsw (cp
, switches
);
351 die("-%s unknown", cp
);
354 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
355 print_help (buf
, switches
, 0);
358 print_version(invo_name
);
362 if (!(cp
= *argp
++) || *cp
== '-')
363 die("missing argument to %s", argp
[-2]);
364 /* create a minimal context */
365 if (context_foil (cp
) == -1)
370 if (!(cp
= *argp
++) || *cp
== '-')
371 die("missing argument to %s", argp
[-2]);
372 if ((state
= alias (cp
)) != AK_OK
)
373 die("aliasing error in %s - %s",
374 cp
, akerror (state
));
393 if (!(filter
= *argp
++) || *filter
== '-')
394 die("missing argument to %s", argp
[-2]);
449 if (!(cp
= *argp
++) || *cp
== '-')
450 die("missing argument to %s", argp
[-2]);
451 if ((outputlinelen
= atoi (cp
)) < 10)
452 die("impossible width %d", outputlinelen
);
456 if (!(cp
= *argp
++) || *cp
== '-')
457 die("missing argument to %s", argp
[-2]);
458 if ((pfd
= atoi (cp
)) <= 2)
459 die("bad argument %s %s", argp
[-2], cp
);
463 if (!(clientsw
= *argp
++) || *clientsw
== '-')
464 die("missing argument to %s", argp
[-2]);
467 if (!(serversw
= *argp
++) || *serversw
== '-')
468 die("missing argument to %s", argp
[-2]);
475 if (!(partno
= *argp
++) || *partno
== '-')
476 die("missing argument to %s", argp
[-2]);
488 if (!(saslmech
= *argp
++) || *saslmech
== '-')
489 die("missing argument to %s", argp
[-2]);
493 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
494 die("missing argument to %s", argp
[-2]);
498 case OAUTHCREDFILESW
:
508 if (!(cp
= *argp
++) || *cp
== '-')
509 die("missing argument to %s", argp
[-2]);
511 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
512 if (oauthswitches
[i
].switchnum
== swnum
) {
513 oauthswitches
[i
].value
= cp
;
518 if (oauthswitches
[i
].profname
== NULL
)
519 die("internal error: cannot map switch %s "
520 "to profile entry", argp
[-2]);
527 if (!(user
= *argp
++) || *user
== '-')
528 die("missing argument to %s", argp
[-2]);
532 if (!(port
= *argp
++) || *port
== '-')
533 die("missing argument to %s", argp
[-2]);
557 if (!(cp
= *argp
++) || *cp
== '-')
558 die("missing argument to %s", argp
[-2]);
563 if (!(cp
= *argp
++) || *cp
== '-')
564 die("missing argument to %s", argp
[-2]);
569 if (!(cp
= *argp
++) || *cp
== '-')
570 die("missing argument to %s", argp
[-2]);
575 if (!(cp
= *argp
++) || *cp
== '-')
576 die("missing argument to %s", argp
[-2]);
577 save_mts_method (cp
);
580 case CREDENTIALSSW
: {
581 if (!(cp
= *argp
++) || *cp
== '-')
582 die("missing argument to %s", argp
[-2]);
583 add_profile_entry ("credentials", cp
);
588 if (!(cp
= *argp
++) || *cp
== '-')
589 die("missing argument to %s", argp
[-2]);
590 if (save_message_id_style (cp
) != 0)
591 die("unsupported messageid \"%s\"", cp
);
596 die("only one message at a time!");
603 die("usage: %s [switches] file", invo_name
);
605 if (outputlinelen
< 10)
606 die("impossible width %d", outputlinelen
);
608 if ((in
= fopen (msg
, "r")) == NULL
)
609 adios (msg
, "unable to open");
617 if ((out
= fopen ("/dev/null", "w")) == NULL
)
618 adios ("/dev/null", "unable to open");
620 char *cp
= m_mktemp2(NULL
, invo_name
, NULL
, &out
);
622 die("unable to create temporary file in %s",
625 strncpy(tmpfil
, cp
, sizeof(tmpfil
));
629 hdrtab
= msgstate
== NORMAL
? NHeaders
: RHeaders
;
631 gstate
= m_getfld_state_init(in
);
632 for (compnum
= 1;;) {
633 int bufsz
= sizeof buf
;
634 switch (state
= m_getfld2(&gstate
, name
, buf
, &bufsz
)) {
638 cp
= mh_xstrdup(buf
);
639 while (state
== FLDPLUS
) {
641 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
644 putfmt (name
, cp
, &eai
, out
);
649 finish_headers (out
);
652 fprintf (out
, "\n%s", buf
);
653 while (state
== BODY
) {
655 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
661 finish_headers (out
);
666 die("message format error in component #%d", compnum
);
669 die("getfld() returned %d", state
);
673 m_getfld_state_destroy (&gstate
);
686 * Here's how we decide which address to use as the envelope-from
689 * - If we were given an Envelope-From header, use that.
690 * - If we were given a Sender: address, use that.
691 * - Otherwise, use the address on the From: line
694 if (msgflags
& MEFM
) {
696 } else if (seensender
) {
705 * The user didn't specify any of the tls switches. Try to
706 * help them by implying -initialtls if they're using port 465
707 * (smtps, until IANA revoked that registration in 1998).
709 tls
= ! strcmp (port
, "465") || ! strcasecmp (port
, "smtps")
712 #else /* ! TLS_SUPPORT */
714 #endif /* ! TLS_SUPPORT */
718 tlsflag
= S_STARTTLS
;
725 tlsflag
|= S_NOVERIFY
;
728 * If we were given any oauth flags, store the appropriate profile
729 * entries and make sure an authservice was given (we have to do this
730 * here because we aren't guaranteed the authservice will be given on
731 * the command line before the other OAuth flags are given).
738 if (auth_svc
== NULL
) {
739 die("No authentication service given with -authservice");
742 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
743 if (oauthswitches
[i
].value
!= NULL
) {
744 snprintf(sbuf
, sizeof(sbuf
),
745 oauthswitches
[i
].profname
, auth_svc
);
746 sbuf
[sizeof(sbuf
) - 1] = '\0';
747 add_profile_entry(sbuf
, oauthswitches
[i
].value
);
752 /* If we are doing a "whom" check */
754 /* This won't work with MTS_SENDMAIL_PIPE. */
755 verify_all_addresses (1, eai
, envelope
, oauth_flag
, auth_svc
);
759 if (msgflags
& MINV
) {
760 make_bcc_file (dashstuff
);
761 if (msgflags
& MVIS
) {
762 if (sm_mts
!= MTS_SENDMAIL_PIPE
) {
763 /* It would be nice to have support to call
764 verify_all_addresses with MTS_SENDMAIL_PIPE, but
765 that might require running sendmail as root. Note
766 that spost didn't verify addresses. */
767 verify_all_addresses (verbose
, eai
, envelope
, oauth_flag
,
770 post (tmpfil
, 0, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
772 post (bccfil
, 1, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
773 (void) m_unlink (bccfil
);
775 post (tmpfil
, 0, isatty (1), eai
, envelope
, oauth_flag
, auth_svc
);
779 (void) m_unlink (tmpfil
);
783 printf ("Partial Message #%s Processed\n", partno
);
785 puts("Message Processed");
798 putfmt (char *name
, char *str
, int *eai
, FILE *out
)
804 char namep
[BUFSIZ
], error
[BUFSIZ
];
805 char *savehdr
= NULL
;
806 unsigned int savehdrlen
= 0;
807 struct mailname
*mp
= NULL
, *np
= NULL
;
810 while (*str
== ' ' || *str
== '\t')
813 if (msgstate
== NORMAL
&& uprf (name
, "resent")) {
814 inform("illegal header line -- %s:", name
);
820 /* Check each header field value to see if it has any 8-bit characters.
821 If it does, enable EAI support. */
822 if (contains8bit(str
, NULL
)) {
824 puts("EAI/SMTPUTF8 enabled");
827 /* Enable SMTPUTF8. */
830 /* Enable passing of utf-8 setting to getname()/getadrx(). */
835 if ((i
= get_header (name
, hdrtab
)) == NOTOK
) {
836 if (strncasecmp (name
, "nmh-", 4)) {
837 fprintf (out
, "%s: %s", name
, str
);
839 /* Filter out all Nmh-* headers, because Norm asked. They
840 should never have reached this point. Warn about any
841 that are non-empty. */
842 if (strcmp (str
, "\n")) {
843 trim_suffix_c(str
, '\n');
845 inform("ignoring header line -- %s: %s", name
, str
);
854 if (hdr
->flags
& HIGN
) {
857 if (hdr
->flags
& HBAD
) {
858 inform("illegal header line -- %s:", name
);
862 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
864 if (hdr
->flags
& HSUB
)
865 subject
= subject
? add (str
, add ("\t", subject
)) : mh_xstrdup(str
);
866 if (hdr
->flags
& HFCC
) {
867 if ((cp
= strrchr(str
, '\n')))
869 for (pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
871 insert_fcc (hdr
, pp
);
873 insert_fcc (hdr
, pp
);
876 if (hdr
->flags
& HCTE
) {
877 if (strncasecmp (str
, "7bit", 4) == 0) {
879 } else if (strncasecmp (str
, "8bit", 4) == 0) {
881 } else if (strncasecmp (str
, "binary", 6) == 0) {
885 if (!(hdr
->flags
& HADR
)) {
886 fprintf (out
, "%s: %s", name
, str
);
891 * If this is a From:/Resent-From: header, save the full thing for
892 * later in case we need it for use when constructing a Bcc draft message.
893 * Because we want to capture the results of alias expansion, save
894 * the output from putadr().
897 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
900 savehdrlen
= sizeof(fullfrom
);
903 tmpaddrs
.m_next
= NULL
;
905 for (count
= 0; (cp
= getname (str
)); count
++) {
906 if ((mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
910 tmpaddrs
.m_next
= mp
;
914 admonish(cp
, "%s", error
);
915 if (hdr
->flags
& HTRY
)
923 if (hdr
->flags
& HNIL
)
924 fprintf (out
, "%s: %s", name
, str
);
927 * Sender (or Resent-Sender) can have only one address
929 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
930 : (hdr
->set
& MSND
)) {
931 inform("%s: field requires one address", name
);
935 inform("%s: field requires at least one address", name
);
942 if (count
> 1 && (hdr
->flags
& HONE
)) {
943 inform("%s: field only permits one address", name
);
948 nameoutput
= linepos
= 0;
949 snprintf (namep
, sizeof(namep
), "%s%s",
950 (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
952 for (grp
= false, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
953 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
954 /* The address doesn't include a host, so it might be an alias. */
955 pp
= akvalue (mp
->m_mbox
); /* do mh alias substitution */
956 qp
= akvisible () ? mp
->m_mbox
: "";
959 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
960 while ((cp
= getname (pp
))) {
961 if (!(mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
962 admonish(cp
, "%s", error
);
968 * If it's a From: or Resent-From: header, save the address
969 * for later possible use (as the envelope address for SMTP)
972 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
973 : (hdr
->set
& MFRM
)) {
974 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
975 from
[sizeof(from
) - 1] = '\0';
980 * Also save the Sender: or Resent-Sender: header as well
983 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
984 : (hdr
->set
& MSND
)) {
985 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
986 sender
[sizeof(sender
) - 1] = '\0';
991 * ALSO ... save Envelope-From
994 if (hdr
->set
& MEFM
) {
995 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
996 efrom
[sizeof(efrom
) - 1] = '\0';
999 if (hdr
->flags
& HBCC
)
1002 mp
->m_ingrp
= np
->m_ingrp
;
1003 else if (mp
->m_gname
)
1004 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1006 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1007 /* Catch this before sendmail chokes with:
1008 "553 List:; syntax illegal for recipient
1010 If we wanted to, we could expand out blind
1011 aliases and put them in Bcc:, but then
1012 they'd have the Blind-Carbon-Copy
1014 die( "blind lists not compatible with"
1020 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
, savehdr
,
1022 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1031 /* Address includes a host, so no alias substitution is needed. */
1034 * If it's a From: or Resent-From header, save the address
1035 * for later possible use (as the envelope address for SMTP)
1038 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
1039 : (hdr
->set
& MFRM
)) {
1040 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
1045 * Also save the Sender: header as well
1048 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
1049 : (hdr
->set
& MSND
)) {
1050 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
1051 sender
[sizeof(sender
) - 1] = '\0';
1056 * ALSO ... save Envelope-From
1059 if (hdr
->set
& MEFM
) {
1060 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1061 efrom
[sizeof(efrom
) - 1] = '\0';
1064 if (hdr
->flags
& HBCC
)
1067 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1070 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
, savehdr
, savehdrlen
);
1074 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1081 * If it was a From header, strip off any trailing newlines from
1082 * the alias-expanded From line.
1085 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
1086 while (*fullfrom
&& fullfrom
[strlen(fullfrom
) - 1] == '\n') {
1087 fullfrom
[strlen(fullfrom
) - 1] = '\0';
1091 if (grp
&& (hdr
->flags
& HNGR
)) {
1092 inform("%s: field does not allow groups", name
);
1102 start_headers (void)
1107 * Probably not necessary, but just in case ...
1118 * Now that we've outputted the header fields in the draft
1119 * message, we will now output any remaining header fields
1120 * that we need to add/create.
1124 finish_headers (FILE *out
)
1128 if (!(msgflags
& MFRM
)) {
1130 * A From: header is now required in the draft.
1132 inform("message has no From: header");
1133 inform("See default components files for examples");
1138 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1139 inform("A Sender: or Envelope-From: header is required "
1140 "with multiple\nFrom: addresses");
1148 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1150 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1152 * If we have multiple From: addresses, make sure we have an
1153 * Sender: header. If we don't have one, then generate one
1154 * from Envelope-From: (which in this case, cannot be blank)
1157 if (fromcount
> 1 && !seensender
) {
1158 if (efrom
[0] == '\0') {
1159 inform("Envelope-From cannot be blank when there "
1160 "is multiple From: addresses\nand no Sender: "
1164 fprintf (out
, "Sender: %s\n", efrom
);
1168 if (!(msgflags
& MVIS
))
1169 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
1173 if (!(msgflags
& MDAT
)) {
1174 inform("message has no Date: header");
1177 if (!(msgflags
& MFRM
)) {
1178 inform("message has no From: header");
1181 if (!(msgflags
& MRFM
)) {
1182 inform("message has no Resent-From: header");
1183 inform("See default components files for examples");
1187 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1188 inform("A Resent-Sender: or Envelope-From: header is "
1189 "required with multiple\nResent-From: addresses");
1197 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
1199 fprintf (out
, "Resent-Message-ID: %s\n",
1200 message_id (tclock
, 0));
1202 * If we have multiple Resent-From: addresses, make sure we have an
1203 * Resent-Sender: header. If we don't have one, then generate one
1204 * from Envelope-From (which in this case, cannot be blank)
1207 if (fromcount
> 1 && !seensender
) {
1208 if (efrom
[0] == '\0') {
1209 inform("Envelope-From cannot be blank when there "
1210 "is multiple Resent-From: addresses and no "
1211 "Resent-Sender: header");
1214 fprintf (out
, "Resent-Sender: %s\n", efrom
);
1218 if (!(msgflags
& MVIS
))
1219 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
1224 die("re-format message and try again");
1226 die("no addressees");
1231 get_header (char *header
, struct headers
*table
)
1235 header
= FENDNULL(header
);
1236 for (h
= table
; h
->value
; h
++)
1237 if (!strcasecmp(FENDNULL(h
->value
), header
))
1245 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
,
1246 unsigned int flags
, char *savehdr
, unsigned int savehdrsize
)
1249 bool saveappend
= false;
1252 char buffer
[BUFSIZ
];
1254 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
1256 if (sm_mts
!= MTS_SENDMAIL_PIPE
&&
1257 ((flags
& (HBCC
| HDCC
| HEFM
)) || mp
->m_ingrp
))
1261 fprintf (out
, "%s: ", name
);
1262 linepos
+= (nameoutput
= strlen (name
) + 2);
1266 shlen
= strlen(savehdr
);
1270 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
1271 mp
->m_pers
= mh_xstrdup(aka
);
1274 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
1277 cp
= adrformat (mp
);
1284 if (linepos
!= nameoutput
) {
1285 if (len
+ linepos
+ 2 > outputlinelen
) {
1286 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
1288 if (shlen
+ 2 + nameoutput
+ len
>= savehdrsize
) {
1291 snprintf(savehdr
+ shlen
, savehdrsize
- shlen
, ",\n%*s",
1299 if (shlen
+ 2 + len
>= savehdrsize
) {
1302 strncat(savehdr
, ", ", savehdrsize
- shlen
);
1310 if (saveappend
&& shlen
+ len
< savehdrsize
)
1311 strncat(savehdr
, cp
, savehdrsize
- shlen
+ len
);
1315 return flags
& HTRY
;
1320 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
1325 if (sm_mts
!= MTS_SENDMAIL_PIPE
&& (flags
& HBCC
))
1329 fprintf (out
, "%s: ", name
);
1330 linepos
+= (nameoutput
= strlen (name
) + 2);
1333 cp
= concat (group
, ";", NULL
);
1336 if (linepos
> nameoutput
) {
1337 if (len
+ linepos
+ 2 > outputlinelen
) {
1338 fprintf (out
, ",\n%*s", nameoutput
, "");
1339 linepos
= nameoutput
;
1353 insert (struct mailname
*np
)
1355 struct mailname
*mp
;
1357 if (np
->m_mbox
== NULL
)
1360 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1361 : np
->m_type
== UUCPHOST
? &uuaddrs
1365 if (!strcasecmp (FENDNULL(np
->m_host
),
1366 FENDNULL(mp
->m_next
->m_host
)) &&
1367 !strcasecmp (FENDNULL(np
->m_mbox
),
1368 FENDNULL(mp
->m_next
->m_mbox
)) &&
1369 np
->m_bcc
== mp
->m_next
->m_bcc
)
1382 struct mailname
*mp
;
1384 fputs("-------\n\t-- Addresses --\nlocal:\t", stdout
);
1385 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1386 printf ("%s%s%s", mp
->m_mbox
,
1387 mp
->m_bcc
? "[BCC]" : "",
1388 mp
->m_next
? ",\n\t" : "");
1390 fputs("\nnet:\t", stdout
);
1391 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1392 printf ("%s%s@%s%s%s", FENDNULL(mp
->m_path
),
1393 mp
->m_mbox
, mp
->m_host
,
1394 mp
->m_bcc
? "[BCC]" : "",
1395 mp
->m_next
? ",\n\t" : "");
1397 fputs("\nuucp:\t", stdout
);
1398 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1399 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1400 mp
->m_bcc
? "[BCC]" : "",
1401 mp
->m_next
? ",\n\t" : "");
1403 fputs("\n\t-- Folder Copies --\nfcc:\t", stdout
);
1404 for (i
= 0; i
< fccind
; i
++)
1405 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1413 struct mailname
*mp
;
1415 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1416 if (annoaux (mp
) == NOTOK
)
1419 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1420 if (annoaux (mp
) == NOTOK
)
1423 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1424 if (annoaux (mp
) == NOTOK
)
1434 annoaux (struct mailname
*mp
)
1437 char buffer
[BUFSIZ
];
1439 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1440 i
= strlen (buffer
);
1442 return write(pfd
, buffer
, i
) == i
? OK
: NOTOK
;
1447 insert_fcc (struct headers
*hdr
, char *pp
)
1451 for (cp
= pp
; isspace ((unsigned char) *cp
); cp
++)
1453 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace ((unsigned char) *pp
); pp
--)
1461 die("too many %ss", hdr
->value
);
1462 fccfold
[fccind
++] = mh_xstrdup(cp
);
1470 make_bcc_file (int dashstuff
)
1476 char *tfile
= NULL
, *program
;
1478 if ((tfile
= m_mktemp2(NULL
, "bccs", NULL
, &out
)) == NULL
) {
1479 die("unable to create temporary file in %s", get_temp_dir());
1481 strncpy (bccfil
, tfile
, sizeof(bccfil
));
1483 fprintf (out
, "From: %s\n", fullfrom
);
1484 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1486 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1488 fprintf (out
, "Subject: %s", subject
);
1489 fprintf (out
, "BCC:\n");
1492 * Use MIME encapsulation for Bcc messages
1498 * Check if any lines in the message clash with the
1499 * prefix for the MIME multipart separator. If there
1500 * is a clash, increment one of the letters in the
1501 * prefix and check again.
1503 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1504 die("lost prefix start");
1505 while (find_prefix () == NOTOK
) {
1508 else if (*++cp
== 0)
1509 die("can't find a unique delimiter string");
1514 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1515 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1516 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1518 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1524 * Do mhl filtering of Bcc messages instead
1525 * of MIME encapsulation.
1527 if (filter
!= NULL
) {
1531 adios ("fork", "unable to");
1534 dup2 (fileno (out
), 1);
1536 vec
= argsplit(mhlproc
, &program
, &i
);
1537 vec
[i
++] = "-forward";
1542 /* was the flag -[no]dashstuffing specified? */
1544 vec
[i
++] = "-dashstuffing";
1545 else if (dashstuff
< 0)
1546 vec
[i
++] = "-nodashstuffing";
1549 execvp (program
, vec
);
1550 fprintf (stderr
, "unable to exec ");
1555 pidXwait (child_id
, mhlproc
);
1559 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1560 adios (tmpfil
, "unable to re-open");
1563 * If using MIME encapsulation, or if the -nodashstuffing
1564 * flag was given, then just copy message. Else do
1565 * RFC934 quoting (dashstuffing).
1567 if (mime
|| dashstuff
< 0)
1568 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1570 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1574 fseek (out
, 0L, SEEK_END
);
1576 fprintf (out
, "\n--%s--\n", prefix
);
1578 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1584 * Scan message to check if any lines clash with
1585 * the prefix of the MIME multipart separator.
1592 char buffer
[BUFSIZ
];
1595 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1596 adios (tmpfil
, "unable to re-open");
1598 while (fgets (buffer
, sizeof buffer
, in
))
1599 if (buffer
[0] == '-' && buffer
[1] == '-') {
1602 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1603 if (!isspace ((unsigned char) *cp
))
1606 if (strcmp (buffer
+ 2, prefix
) == 0) {
1620 if (badadr
&& unkadr
)
1621 fatal (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1622 badadr
, PLURALS(badadr
), unkadr
, PLURALS(badadr
));
1624 fatal (NULL
, "%d address%s unparsable", badadr
, PLURALS(badadr
));
1626 fatal (NULL
, "%d addressee%s undeliverable", unkadr
, PLURALS(unkadr
));
1631 do_addresses (int bccque
, int talk
)
1635 struct mailname
*lp
;
1638 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1639 if (lp
->m_bcc
? bccque
: !bccque
) {
1641 puts(" -- Local Recipients --");
1642 do_an_address (lp
, talk
);
1647 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1648 if (lp
->m_bcc
? bccque
: !bccque
) {
1650 puts(" -- UUCP Recipients --");
1651 do_an_address (lp
, talk
);
1656 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1657 if (lp
->m_bcc
? bccque
: !bccque
) {
1659 puts(" -- Network Recipients --");
1660 do_an_address (lp
, talk
);
1666 if (rp_isbad (retval
= sm_waend ()))
1667 fatal (NULL
, "problem ending addresses; %s", rp_string (retval
));
1672 * MTS-SPECIFIC INTERACTION
1677 * SENDMAIL/SMTP routines
1681 post (char *file
, int bccque
, int talk
, int eai
, char *envelope
,
1682 int oauth_flag
, char *auth_svc
)
1688 if (msgflags
& MINV
)
1689 printf (" -- Posting for %s Recipients --\n",
1690 bccque
? "Blind" : "Sighted");
1692 puts(" -- Posting for All Recipients --");
1697 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1698 char **argp
, *program
;
1704 adios ("fork", "unable to");
1707 if (freopen( file
, "r", stdin
) == NULL
) {
1708 adios (file
, "can't reopen for sendmail");
1711 argp
= argsplit(sendmail
, &program
, &argc
);
1712 argp
[argc
++] = "-t"; /* read msg for recipients */
1713 argp
[argc
++] = "-i"; /* don't stop on "." */
1715 argp
[argc
++] = "-bv";
1717 argp
[argc
++] = "-v";
1720 execv (program
, argp
);
1721 adios (sendmail
, "can't exec");
1724 pidXwait (child_id
, NULL
);
1728 const int fd
= open (file
, O_RDONLY
);
1732 fatal (file
, "unable to re-open");
1735 if (msgflags
& MMIM
&& cte
!= UNKNOWN
) {
1736 /* MIME message with C-T-E header. (BINARYMIME isn't
1737 supported, use 8BITMIME instead for binary.) */
1738 eightbit
= cte
!= SEVENBIT
;
1740 if (scan_input (fd
, &eightbit
) == NOTOK
) {
1742 fatal (file
, "problem reading from");
1746 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1747 verbose
, snoop
, sasl
, saslmech
, user
,
1748 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1749 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1751 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1754 do_addresses (bccque
, talk
&& verbose
);
1759 sm_end (!(msgflags
& MINV
) || bccque
? OK
: DONE
);
1763 if (msgflags
& MINV
)
1764 printf (" -- %s Recipient Copies Posted --\n",
1765 bccque
? "Blind" : "Sighted");
1767 puts(" -- Recipient Copies Posted --");
1775 /* Address Verification */
1778 verify_all_addresses (int talk
, int eai
, char *envelope
, int oauth_flag
,
1782 struct mailname
*lp
;
1786 if (!whomsw
|| checksw
) {
1787 /* Not sending message body, so don't need to use 8BITMIME. */
1788 const int eightbit
= 0;
1790 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1791 verbose
, snoop
, sasl
, saslmech
, user
,
1792 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1793 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1794 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1798 if (talk
&& !whomsw
)
1799 puts(" -- Address Verification --");
1800 if (talk
&& localaddrs
.m_next
)
1801 puts(" -- Local Recipients --");
1802 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1803 do_an_address (lp
, talk
);
1805 if (talk
&& uuaddrs
.m_next
)
1806 puts(" -- UUCP Recipients --");
1807 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1808 do_an_address (lp
, talk
);
1810 if (talk
&& netaddrs
.m_next
)
1811 puts(" -- Network Recipients --");
1812 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1813 do_an_address (lp
, talk
);
1816 if (talk
&& !whomsw
)
1817 puts(" -- Address Verification Successful --");
1819 if (!whomsw
|| checksw
)
1820 sm_end (whomsw
? OK
: DONE
);
1828 do_an_address (struct mailname
*lp
, int talk
)
1834 switch (lp
->m_type
) {
1838 strncpy (addr
, mbox
, sizeof(addr
));
1842 mbox
= auxformat (lp
, 0);
1844 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1847 default: /* let SendMail decide if the host is bad */
1850 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1855 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1857 if (whomsw
&& !checksw
) {
1862 fputs(": ", stdout
);
1865 switch (retval
= sm_wadr (mbox
, host
,
1866 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1875 fprintf (stderr
, " %s: ", addr
);
1876 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1877 rp_string (retval
));
1883 fprintf (stderr
, " %s: ", addr
);
1884 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1892 do_text (char *file
, int fd
)
1897 lseek(fd
, 0, SEEK_SET
);
1899 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1900 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1901 fatal (NULL
, "problem writing text; %s\n", rp_string (retval
));
1905 fatal (file
, "problem reading from");
1907 switch (retval
= sm_wtend ()) {
1913 fatal (NULL
, "posting failed; %s", rp_string (retval
));
1917 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1931 (void) m_unlink (tmpfil
);
1932 if (msgflags
& MINV
)
1933 (void) m_unlink (bccfil
);
1935 if (!whomsw
|| checksw
)
1948 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1949 istat
= SIGNAL2 (SIGINT
, sigser
);
1950 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1951 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1961 SIGNAL (SIGHUP
, hstat
);
1962 SIGNAL (SIGINT
, istat
);
1963 SIGNAL (SIGQUIT
, qstat
);
1964 SIGNAL (SIGTERM
, tstat
);
1972 p_refile (char *file
)
1980 puts(" -- Filing Folder Copies --");
1981 for (i
= 0; i
< fccind
; i
++)
1982 fcc (file
, fccfold
[i
]);
1984 puts(" -- Folder Copies Filed --");
1989 * Call the `fileproc' to add the file to the folder.
1993 fcc (char *file
, char *folder
)
1998 char **arglist
, *program
;
2001 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
2008 fprintf (stderr
, " %sFcc %s: ",
2009 msgstate
== RESENT
? "Resent-" : "", folder
);
2010 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
2014 /* see if we need to add `+' */
2015 snprintf (fold
, sizeof(fold
), "%s%s",
2016 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
2018 /* now exec the fileproc */
2020 arglist
= argsplit(fileproc
, &program
, &argp
);
2021 arglist
[argp
++] = "-link";
2022 arglist
[argp
++] = "-file";
2023 arglist
[argp
++] = file
;
2024 arglist
[argp
++] = fold
;
2025 arglist
[argp
] = NULL
;
2026 execvp (program
, arglist
);
2030 if ((status
= pidwait (child_id
, OK
))) {
2032 fprintf (stderr
, " %sFcc %s: ",
2033 msgstate
== RESENT
? "Resent-" : "", folder
);
2034 pidstatus (status
, verbose
? stdout
: stderr
, fileproc
);
2049 fatal (char *what
, char *fmt
, ...)
2056 (void) m_unlink (tmpfil
);
2057 if (msgflags
& MINV
)
2058 (void) m_unlink (bccfil
);
2060 if (!whomsw
|| checksw
)
2065 advertise (what
, NULL
, fmt
, ap
);