]>
diplodocus.org Git - nmh/blob - uip/post.c
cf2ccf835c5a851cb525db3e2b9c97bbc61640bf
1 /* post.c -- enter messages into the mail transport system
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
10 #include "sbr/m_getfld.h"
11 #include "sbr/getarguments.h"
12 #include "sbr/concat.h"
13 #include "sbr/smatch.h"
14 #include "sbr/cpydata.h"
15 #include "sbr/cpydgst.h"
17 #include "sbr/context_foil.h"
18 #include "sbr/readconfig.h"
19 #include "sbr/ambigsw.h"
20 #include "sbr/pidstatus.h"
21 #include "sbr/print_version.h"
22 #include "sbr/print_help.h"
23 #include "sbr/arglist.h"
24 #include "sbr/error.h"
26 #include "h/signals.h"
27 #include "h/addrsbr.h"
28 #include "h/aliasbr.h"
29 #include "h/dropsbr.h"
35 #include "sbr/m_mktemp.h"
36 #include "sbr/message_id.h"
38 #ifdef HAVE_SYS_TIME_H
39 # include <sys/time.h>
43 #include "mts/smtp/smtp.h"
46 # define SASLminc(a) (a)
47 #else /* CYRUS_SASL */
48 # define SASLminc(a) 0
49 #endif /* CYRUS_SASL */
52 # define TLSminc(a) (a)
53 #else /* TLS_SUPPORT */
55 #endif /* TLS_SUPPORT */
58 # define OAUTHminc(a) (a)
59 #else /* OAUTH_SUPPORT */
60 # define OAUTHminc(a) 0
61 #endif /* OAUTH_SUPPORT */
63 #define FCCS 10 /* max number of fccs allowed */
65 /* In the following array of structures, the numeric second field of the
66 structures (minchars) is apparently used like this:
68 -# : Switch can be abbreviated to # characters; switch hidden in -help.
69 0 : Switch can't be abbreviated; switch shown in -help.
70 # : Switch can be abbreviated to # characters; switch shown in -help. */
72 #define POST_SWITCHES \
73 X("alias aliasfile", 0, ALIASW) \
74 X("check", -5, CHKSW) /* interface from whom */ \
75 X("nocheck", -7, NCHKSW) /* interface from whom */ \
76 X("debug", -5, DEBUGSW) \
77 X("dist", -4, DISTSW) /* interface from dist */ \
78 X("filter filterfile", 0, FILTSW) \
79 X("nofilter", 0, NFILTSW) \
80 X("format", 0, FRMTSW) \
81 X("noformat", 0, NFRMTSW) \
82 X("library directory", -7, LIBSW) /* interface from send, whom */ \
83 X("mime", 0, MIMESW) \
84 X("nomime", 0, NMIMESW) \
85 X("msgid", 0, MSGDSW) \
86 X("nomsgid", 0, NMSGDSW) \
87 X("verbose", 0, VERBSW) \
88 X("noverbose", 0, NVERBSW) \
89 X("watch", 0, WATCSW) \
90 X("nowatch", 0, NWATCSW) \
91 X("whom", -4, WHOMSW) /* interface from whom */ \
92 X("width columns", 0, WIDTHSW) \
93 X("version", 0, VERSIONSW) \
94 X("help", 0, HELPSW) \
95 X("dashstuffing", -12, BITSTUFFSW) /* should we dashstuff BCC messages? */ \
96 X("nodashstuffing", -14, NBITSTUFFSW) \
97 X("idanno number", -6, ANNOSW) /* interface from send */ \
98 X("client host", -6, CLIESW) \
99 X("server host", 6, SERVSW) /* specify alternate SMTP server */ \
100 X("snoop", -5, SNOOPSW) /* snoop the SMTP transaction */ \
101 X("partno", -6, PARTSW) \
102 X("sasl", SASLminc(4), SASLSW) \
103 X("nosasl", SASLminc(6), NOSASLSW) \
104 X("saslmech", SASLminc(5), SASLMECHSW) \
105 X("user", SASLminc(-4), USERSW) \
106 X("port server submission port name/number", 4, PORTSW) \
107 X("tls", TLSminc(-3), TLSSW) \
108 X("initialtls", TLSminc(-10), INITTLSSW) \
109 X("notls", TLSminc(-5), NTLSSW) \
110 X("certverify", TLSminc(-10), CERTVERSW) \
111 X("nocertverify", TLSminc(-12), NOCERTVERSW) \
112 X("fileproc", -4, FILEPROCSW) \
113 X("mhlproc", -3, MHLPROCSW) \
114 X("sendmail program", 0, MTSSM) \
115 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
116 X("credentials legacy|file:filename", 0, CREDENTIALSSW) \
117 X("messageid localname|random", 2, MESSAGEIDSW) \
118 X("authservice auth-service-name", OAUTHminc(-11), AUTHSERVICESW) \
119 X("oauthcredfile credential-file", OAUTHminc(-7), OAUTHCREDFILESW) \
120 X("oauthclientid client-id", OAUTHminc(-12), OAUTHCLIDSW) \
121 X("oauthclientsecret client-secret", OAUTHminc(-12), OAUTHCLSECSW) \
122 X("oauthauthendpoint authentication-endpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
123 X("oauthredirect redirect-uri", OAUTHminc(-6), OAUTHREDIRSW) \
124 X("oauthtokenendpoint token-endpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
125 X("oauthscope scope", OAUTHminc(-6), OAUTHSCOPESW) \
127 #define X(sw, minchars, id) id,
128 DEFINE_SWITCH_ENUM(POST
);
131 #define X(sw, minchars, id) { sw, minchars, id },
132 DEFINE_SWITCH_ARRAY(POST
, switches
);
137 * Mapping between command-line switches and profile entries, communicated
138 * from 'send'. We use a service name of 'post' internally.
142 const char *profname
;
145 } oauthswitches
[] = {
146 { "oauth-%s-credential-file", OAUTHCREDFILESW
, NULL
},
147 { "oauth-%s-client_id", OAUTHCLIDSW
, NULL
},
148 { "oauth-%s-client_secret", OAUTHCLSECSW
, NULL
},
149 { "oauth-%s-auth_endpoint", OAUTHAUTHENDSW
, NULL
},
150 { "oauth-%s-redirect_uri", OAUTHREDIRSW
, NULL
},
151 { "oauth-%s-token_endpoint", OAUTHTOKENDSW
, NULL
},
152 { "oauth-%s-scope", OAUTHSCOPESW
, NULL
},
163 * flags for headers->flags
165 #define HNOP 0x0000 /* just used to keep .set around */
166 #define HBAD 0x0001 /* bad header - don't let it through */
167 #define HADR 0x0002 /* header has an address field */
168 #define HSUB 0x0004 /* Subject: header */
169 #define HTRY 0x0008 /* try to send to addrs on header */
170 #define HBCC 0x0010 /* don't output this header, unless MTS_SENDMAIL_PIPE */
171 #define HMNG 0x0020 /* munge this header */
172 #define HNGR 0x0040 /* no groups allowed in this header */
173 #define HFCC 0x0080 /* FCC: type header */
174 #define HNIL 0x0100 /* okay for this header not to have addrs */
175 #define HIGN 0x0200 /* ignore this header */
176 #define HDCC 0x0400 /* another undocumented feature */
177 #define HONE 0x0800 /* Only (zero or) one address allowed */
178 #define HEFM 0x1000 /* Envelope-From: header */
179 #define HMIM 0x2000 /* MIME-Version: header */
180 #define HCTE 0x4000 /* Content-Transfer-Encoding: header */
183 * flags for headers->set
185 #define MFRM 0x0001 /* we've seen a From: */
186 #define MDAT 0x0002 /* we've seen a Date: */
187 #define MRFM 0x0004 /* we've seen a Resent-From: */
188 #define MVIS 0x0008 /* we've seen sighted addrs */
189 #define MINV 0x0010 /* we've seen blind addrs */
190 #define MSND 0x0020 /* we've seen a Sender: */
191 #define MRSN 0x0040 /* We've seen a Resent-Sender: */
192 #define MEFM 0x0080 /* We've seen Envelope-From: */
193 #define MMIM 0x0100 /* We've seen Mime-Version: */
195 static struct headers NHeaders
[] = {
196 { "Return-Path", HBAD
, 0 },
197 { "Received", HBAD
, 0 },
198 { "Reply-To", HADR
|HNGR
, 0 },
199 { "From", HADR
|HNGR
, MFRM
},
200 { "Sender", HADR
|HNGR
|HONE
, MSND
},
202 { "Subject", HSUB
, 0 },
203 { "To", HADR
|HTRY
, MVIS
},
204 { "cc", HADR
|HTRY
, MVIS
},
205 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, MINV
},
206 { "Dcc", HADR
|HTRY
|HDCC
|HNIL
, MVIS
}, /* sorta cc & bcc combined */
207 { "Message-ID", HBAD
, 0 },
209 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
210 { "MIME-Version", HMIM
, MMIM
},
211 { "Content-Transfer-Encoding", HCTE
, 0 },
215 static struct headers RHeaders
[] = {
216 { "Resent-Reply-To", HADR
|HNGR
, 0 },
217 { "Resent-From", HADR
|HNGR
, MRFM
},
218 { "Resent-Sender", HADR
|HNGR
, MRSN
},
219 { "Resent-Date", HBAD
, 0 },
220 { "Resent-Subject", HSUB
, 0 },
221 { "Resent-To", HADR
|HTRY
, MVIS
},
222 { "Resent-cc", HADR
|HTRY
, MVIS
},
223 { "Resent-Bcc", HADR
|HTRY
|HBCC
, MINV
},
224 { "Resent-Message-ID", HBAD
, 0 },
225 { "Resent-Fcc", HFCC
, 0 },
226 { "Reply-To", HADR
, 0 },
227 { "From", HADR
|HNGR
, MFRM
},
228 { "Sender", HADR
|HNGR
, MSND
},
229 { "Date", HNOP
, MDAT
},
230 { "To", HADR
|HNIL
, 0 },
231 { "cc", HADR
|HNIL
, 0 },
232 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, 0 },
234 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
235 { "MIME-Version", HMIM
, MMIM
},
236 { "Content-Transfer-Encoding", HCTE
, 0 },
240 static short fccind
= 0; /* index into fccfold[] */
241 static short outputlinelen
= OUTPUTLINELEN
;
243 static int pfd
= NOTOK
; /* fd to write annotation list to */
244 static bool recipients
; /* how many people will get a copy */
245 static int unkadr
= 0; /* how many of those were unknown */
246 static int badadr
= 0; /* number of bad addrs */
247 static bool badmsg
; /* message has bad semantics */
248 static bool verbose
; /* spell it out */
249 static bool format
= true; /* format addresses */
250 static bool mime
; /* use MIME-style encapsulations for Bcc */
251 static bool msgid
; /* add msgid */
252 static bool debug
; /* debugging post */
253 static bool watch
; /* watch the delivery process */
254 static bool whomsw
; /* we are whom not post */
255 static bool checksw
; /* whom -check */
256 static int linepos
=0; /* putadr()'s position on the line */
257 static int nameoutput
=0; /* putadr() has output header name */
258 static bool sasl
; /* Use SASL auth for SMTP */
259 static char *saslmech
=NULL
; /* Force use of particular SASL mech */
260 static char *user
=NULL
; /* Authenticate as this user */
261 static char *port
="submission"; /* Name of server port for SMTP submission */
262 static int tlsflag
=0; /* Flags to control TLS settings */
263 static int fromcount
=0; /* Count of addresses on From: header */
264 static bool seensender
; /* Have we seen a Sender: header? */
266 static unsigned msgflags
= 0; /* what we've seen */
270 static int msgstate
= NORMAL
;
272 static time_t tclock
= 0; /* the time we started (more or less) */
274 static SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
276 static char tmpfil
[BUFSIZ
];
277 static char bccfil
[BUFSIZ
];
279 static char from
[BUFSIZ
]; /* my network address */
280 static char sender
[BUFSIZ
]; /* my Sender: header */
281 static char efrom
[BUFSIZ
]; /* my Envelope-From: header */
282 static char fullfrom
[BUFSIZ
]; /* full contents of From header */
283 static char *filter
= NULL
; /* the filter for BCC'ing */
284 static char *subject
= NULL
; /* the subject field for BCC'ing */
285 static char *fccfold
[FCCS
]; /* foldernames for FCC'ing */
286 enum encoding
{ UNKNOWN
= 0, BINARY
= 1, SEVENBIT
= 7, EIGHTBIT
= 8 };
287 static enum encoding cte
= UNKNOWN
;
289 static struct headers
*hdrtab
; /* table for the message we're doing */
291 static struct mailname localaddrs
; /* local addrs */
292 static struct mailname netaddrs
; /* network addrs */
293 static struct mailname uuaddrs
; /* uucp addrs */
294 static struct mailname tmpaddrs
; /* temporary queue */
297 static char *clientsw
= NULL
;
298 static char *serversw
= NULL
;
300 static char prefix
[] = "----- =_aaaaaaaaaa";
302 static char *partno
= NULL
;
307 static void putfmt (char *, char *, int *, FILE *);
308 static void start_headers (void);
309 static void finish_headers (FILE *);
310 static int get_header (char *, struct headers
*) PURE
;
311 static int putadr (char *, char *, struct mailname
*, FILE *, unsigned int,
312 char *, unsigned int);
313 static void putgrp (char *, char *, FILE *, unsigned int);
314 static int insert (struct mailname
*);
315 static void pl (void);
316 static void anno (void);
317 static int annoaux (struct mailname
*);
318 static void insert_fcc (struct headers
*, char *);
319 static void make_bcc_file (int);
320 static void verify_all_addresses (int, int, char *, int, char *);
321 static void chkadr (void);
322 static void sigon (void);
323 static void sigoff (void);
324 static void p_refile (char *);
325 static void fcc (char *, char *);
326 static void fatal (char *, char *, ...) CHECK_PRINTF(2, 3);
327 static void post (char *, int, int, int, char *, int, char *);
328 static void do_text (char *file
, int fd
);
329 static void do_an_address (struct mailname
*, int);
330 static void do_addresses (int, int);
331 static int find_prefix (void);
335 main (int argc
, char **argv
)
337 int state
, compnum
, dashstuff
= 0, swnum
;
338 bool oauth_flag
= false;
340 bool noverify
= false;
341 int eai
= 0; /* use Email Address Internationalization (EAI) (SMTPUTF8) */
342 char *cp
, *msg
= NULL
, **argp
, **arguments
, *envelope
;
343 char buf
[NMH_BUFSIZ
], name
[NAMESZ
], *auth_svc
= NULL
;
345 m_getfld_state_t gstate
;
347 if (nmh_init(argv
[0], false, false)) { return 1; }
350 arguments
= getarguments (invo_name
, argc
, argv
, 0);
353 while ((cp
= *argp
++)) {
355 switch ((swnum
= smatch (++cp
, switches
))) {
357 ambigsw (cp
, switches
);
360 die("-%s unknown", cp
);
363 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
364 print_help (buf
, switches
, 0);
367 print_version(invo_name
);
371 if (!(cp
= *argp
++) || *cp
== '-')
372 die("missing argument to %s", argp
[-2]);
373 /* create a minimal context */
374 if (context_foil (cp
) == -1)
379 if (!(cp
= *argp
++) || *cp
== '-')
380 die("missing argument to %s", argp
[-2]);
381 if ((state
= alias (cp
)) != AK_OK
)
382 die("aliasing error in %s - %s",
383 cp
, akerror (state
));
402 if (!(filter
= *argp
++) || *filter
== '-')
403 die("missing argument to %s", argp
[-2]);
458 if (!(cp
= *argp
++) || *cp
== '-')
459 die("missing argument to %s", argp
[-2]);
460 if ((outputlinelen
= atoi (cp
)) < 10)
461 die("impossible width %d", outputlinelen
);
465 if (!(cp
= *argp
++) || *cp
== '-')
466 die("missing argument to %s", argp
[-2]);
467 if ((pfd
= atoi (cp
)) <= 2)
468 die("bad argument %s %s", argp
[-2], cp
);
472 if (!(clientsw
= *argp
++) || *clientsw
== '-')
473 die("missing argument to %s", argp
[-2]);
476 if (!(serversw
= *argp
++) || *serversw
== '-')
477 die("missing argument to %s", argp
[-2]);
484 if (!(partno
= *argp
++) || *partno
== '-')
485 die("missing argument to %s", argp
[-2]);
497 if (!(saslmech
= *argp
++) || *saslmech
== '-')
498 die("missing argument to %s", argp
[-2]);
502 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
503 die("missing argument to %s", argp
[-2]);
507 case OAUTHCREDFILESW
:
517 if (!(cp
= *argp
++) || *cp
== '-')
518 die("missing argument to %s", argp
[-2]);
520 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
521 if (oauthswitches
[i
].switchnum
== swnum
) {
522 oauthswitches
[i
].value
= cp
;
527 if (oauthswitches
[i
].profname
== NULL
)
528 die("internal error: cannot map switch %s "
529 "to profile entry", argp
[-2]);
536 if (!(user
= *argp
++) || *user
== '-')
537 die("missing argument to %s", argp
[-2]);
541 if (!(port
= *argp
++) || *port
== '-')
542 die("missing argument to %s", argp
[-2]);
566 if (!(cp
= *argp
++) || *cp
== '-')
567 die("missing argument to %s", argp
[-2]);
572 if (!(cp
= *argp
++) || *cp
== '-')
573 die("missing argument to %s", argp
[-2]);
578 if (!(cp
= *argp
++) || *cp
== '-')
579 die("missing argument to %s", argp
[-2]);
584 if (!(cp
= *argp
++) || *cp
== '-')
585 die("missing argument to %s", argp
[-2]);
586 save_mts_method (cp
);
589 case CREDENTIALSSW
: {
590 if (!(cp
= *argp
++) || *cp
== '-')
591 die("missing argument to %s", argp
[-2]);
592 add_profile_entry ("credentials", cp
);
597 if (!(cp
= *argp
++) || *cp
== '-')
598 die("missing argument to %s", argp
[-2]);
599 if (save_message_id_style (cp
) != 0)
600 die("unsupported messageid \"%s\"", cp
);
605 die("only one message at a time!");
612 die("usage: %s [switches] file", invo_name
);
614 if (outputlinelen
< 10)
615 die("impossible width %d", outputlinelen
);
617 if ((in
= fopen (msg
, "r")) == NULL
)
618 adios (msg
, "unable to open");
626 if ((out
= fopen ("/dev/null", "w")) == NULL
)
627 adios ("/dev/null", "unable to open");
629 char *cp
= m_mktemp2(NULL
, invo_name
, NULL
, &out
);
631 die("unable to create temporary file in %s",
634 strncpy(tmpfil
, cp
, sizeof(tmpfil
));
638 hdrtab
= msgstate
== NORMAL
? NHeaders
: RHeaders
;
640 gstate
= m_getfld_state_init(in
);
641 for (compnum
= 1;;) {
642 int bufsz
= sizeof buf
;
643 switch (state
= m_getfld2(&gstate
, name
, buf
, &bufsz
)) {
647 cp
= mh_xstrdup(buf
);
648 while (state
== FLDPLUS
) {
650 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
653 putfmt (name
, cp
, &eai
, out
);
658 finish_headers (out
);
661 fprintf (out
, "\n%s", buf
);
662 while (state
== BODY
) {
664 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
670 finish_headers (out
);
675 die("message format error in component #%d", compnum
);
678 die("getfld() returned %d", state
);
682 m_getfld_state_destroy (&gstate
);
695 * Here's how we decide which address to use as the envelope-from
698 * - If we were given an Envelope-From header, use that.
699 * - If we were given a Sender: address, use that.
700 * - Otherwise, use the address on the From: line
703 if (msgflags
& MEFM
) {
705 } else if (seensender
) {
714 * The user didn't specify any of the tls switches. Try to
715 * help them by implying -initialtls if they're using port 465
716 * (smtps, until IANA revoked that registration in 1998).
718 tls
= ! strcmp (port
, "465") || ! strcasecmp (port
, "smtps")
721 #else /* ! TLS_SUPPORT */
723 #endif /* ! TLS_SUPPORT */
727 tlsflag
= S_STARTTLS
;
734 tlsflag
|= S_NOVERIFY
;
737 * If we were given any oauth flags, store the appropriate profile
738 * entries and make sure an authservice was given (we have to do this
739 * here because we aren't guaranteed the authservice will be given on
740 * the command line before the other OAuth flags are given).
747 if (auth_svc
== NULL
) {
748 die("No authentication service given with -authservice");
751 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
752 if (oauthswitches
[i
].value
!= NULL
) {
753 snprintf(sbuf
, sizeof(sbuf
),
754 oauthswitches
[i
].profname
, auth_svc
);
755 sbuf
[sizeof(sbuf
) - 1] = '\0';
756 add_profile_entry(sbuf
, oauthswitches
[i
].value
);
761 /* If we are doing a "whom" check */
763 /* This won't work with MTS_SENDMAIL_PIPE. */
764 verify_all_addresses (1, eai
, envelope
, oauth_flag
, auth_svc
);
768 if (msgflags
& MINV
) {
769 make_bcc_file (dashstuff
);
770 if (msgflags
& MVIS
) {
771 if (sm_mts
!= MTS_SENDMAIL_PIPE
) {
772 /* It would be nice to have support to call
773 verify_all_addresses with MTS_SENDMAIL_PIPE, but
774 that might require running sendmail as root. Note
775 that spost didn't verify addresses. */
776 verify_all_addresses (verbose
, eai
, envelope
, oauth_flag
,
779 post (tmpfil
, 0, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
781 post (bccfil
, 1, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
782 (void) m_unlink (bccfil
);
784 post (tmpfil
, 0, isatty (1), eai
, envelope
, oauth_flag
, auth_svc
);
788 (void) m_unlink (tmpfil
);
792 printf ("Partial Message #%s Processed\n", partno
);
794 puts("Message Processed");
807 putfmt (char *name
, char *str
, int *eai
, FILE *out
)
813 char namep
[BUFSIZ
], error
[BUFSIZ
];
814 char *savehdr
= NULL
;
815 unsigned int savehdrlen
= 0;
816 struct mailname
*mp
= NULL
, *np
= NULL
;
819 while (*str
== ' ' || *str
== '\t')
822 if (msgstate
== NORMAL
&& uprf (name
, "resent")) {
823 inform("illegal header line -- %s:", name
);
829 /* Check each header field value to see if it has any 8-bit characters.
830 If it does, enable EAI support. */
831 if (contains8bit(str
, NULL
)) {
833 puts("EAI/SMTPUTF8 enabled");
836 /* Enable SMTPUTF8. */
839 /* Enable passing of utf-8 setting to getname()/getadrx(). */
844 if ((i
= get_header (name
, hdrtab
)) == NOTOK
) {
845 if (strncasecmp (name
, "nmh-", 4)) {
846 fprintf (out
, "%s: %s", name
, str
);
848 /* Filter out all Nmh-* headers, because Norm asked. They
849 should never have reached this point. Warn about any
850 that are non-empty. */
851 if (strcmp (str
, "\n")) {
852 trim_suffix_c(str
, '\n');
854 inform("ignoring header line -- %s: %s", name
, str
);
863 if (hdr
->flags
& HIGN
) {
866 if (hdr
->flags
& HBAD
) {
867 inform("illegal header line -- %s:", name
);
871 if (hdr
->flags
& HDCC
&& sm_mts
== MTS_SENDMAIL_PIPE
)
873 inform("Dcc header is not supported with sendmail/pipe");
877 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
879 if (hdr
->flags
& HSUB
)
880 subject
= subject
? add (str
, add ("\t", subject
)) : mh_xstrdup(str
);
881 if (hdr
->flags
& HFCC
) {
882 if ((cp
= strrchr(str
, '\n')))
884 for (pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
886 insert_fcc (hdr
, pp
);
888 insert_fcc (hdr
, pp
);
891 if (hdr
->flags
& HCTE
) {
892 if (strncasecmp (str
, "7bit", 4) == 0) {
894 } else if (strncasecmp (str
, "8bit", 4) == 0) {
896 } else if (strncasecmp (str
, "binary", 6) == 0) {
900 if (!(hdr
->flags
& HADR
)) {
901 fprintf (out
, "%s: %s", name
, str
);
906 * If this is a From:/Resent-From: header, save the full thing for
907 * later in case we need it for use when constructing a Bcc draft message.
908 * Because we want to capture the results of alias expansion, save
909 * the output from putadr().
912 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
915 savehdrlen
= sizeof(fullfrom
);
918 tmpaddrs
.m_next
= NULL
;
920 for (count
= 0; (cp
= getname (str
)); count
++) {
921 if ((mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
925 tmpaddrs
.m_next
= mp
;
929 admonish(cp
, "%s", error
);
930 if (hdr
->flags
& HTRY
)
938 if (hdr
->flags
& HNIL
)
939 fprintf (out
, "%s: %s", name
, str
);
942 * Sender (or Resent-Sender) can have only one address
944 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
945 : (hdr
->set
& MSND
)) {
946 inform("%s: field requires one address", name
);
950 inform("%s: field requires at least one address", name
);
957 if (count
> 1 && (hdr
->flags
& HONE
)) {
958 inform("%s: field only permits one address", name
);
963 nameoutput
= linepos
= 0;
964 snprintf (namep
, sizeof(namep
), "%s%s",
965 (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
967 for (grp
= false, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
968 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
969 /* The address doesn't include a host, so it might be an alias. */
970 pp
= akvalue (mp
->m_mbox
); /* do mh alias substitution */
971 qp
= akvisible () ? mp
->m_mbox
: "";
974 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
975 while ((cp
= getname (pp
))) {
976 if (!(mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
977 admonish(cp
, "%s", error
);
983 * If it's a From: or Resent-From: header, save the address
984 * for later possible use (as the envelope address for SMTP)
987 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
988 : (hdr
->set
& MFRM
)) {
989 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
990 from
[sizeof(from
) - 1] = '\0';
995 * Also save the Sender: or Resent-Sender: header as well
998 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
999 : (hdr
->set
& MSND
)) {
1000 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
1001 sender
[sizeof(sender
) - 1] = '\0';
1006 * ALSO ... save Envelope-From
1009 if (hdr
->set
& MEFM
) {
1010 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1011 efrom
[sizeof(efrom
) - 1] = '\0';
1014 if (hdr
->flags
& HBCC
)
1017 mp
->m_ingrp
= np
->m_ingrp
;
1018 else if (mp
->m_gname
)
1019 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1021 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1022 /* Catch this before sendmail chokes with:
1023 "553 List:; syntax illegal for recipient
1025 If we wanted to, we could expand out blind
1026 aliases and put them in Bcc:, but then
1027 they'd have the Blind-Carbon-Copy
1029 die( "blind lists not compatible with"
1035 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
, savehdr
,
1037 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1046 /* Address includes a host, so no alias substitution is needed. */
1049 * If it's a From: or Resent-From header, save the address
1050 * for later possible use (as the envelope address for SMTP)
1053 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
1054 : (hdr
->set
& MFRM
)) {
1055 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
1060 * Also save the Sender: header as well
1063 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
1064 : (hdr
->set
& MSND
)) {
1065 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
1066 sender
[sizeof(sender
) - 1] = '\0';
1071 * ALSO ... save Envelope-From
1074 if (hdr
->set
& MEFM
) {
1075 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1076 efrom
[sizeof(efrom
) - 1] = '\0';
1079 if (hdr
->flags
& HBCC
)
1082 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1085 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
, savehdr
, savehdrlen
);
1089 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1096 * If it was a From header, strip off any trailing newlines from
1097 * the alias-expanded From line.
1100 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
1101 while (*fullfrom
&& fullfrom
[strlen(fullfrom
) - 1] == '\n') {
1102 fullfrom
[strlen(fullfrom
) - 1] = '\0';
1106 if (grp
&& (hdr
->flags
& HNGR
)) {
1107 inform("%s: field does not allow groups", name
);
1117 start_headers (void)
1122 * Probably not necessary, but just in case ...
1133 * Now that we've outputted the header fields in the draft
1134 * message, we will now output any remaining header fields
1135 * that we need to add/create.
1139 finish_headers (FILE *out
)
1143 if (!(msgflags
& MFRM
)) {
1145 * A From: header is now required in the draft.
1147 inform("message has no From: header");
1148 inform("See default components files for examples");
1153 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1154 inform("A Sender: or Envelope-From: header is required "
1155 "with multiple\nFrom: addresses");
1163 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1165 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1167 * If we have multiple From: addresses, make sure we have an
1168 * Sender: header. If we don't have one, then generate one
1169 * from Envelope-From: (which in this case, cannot be blank)
1172 if (fromcount
> 1 && !seensender
) {
1173 if (efrom
[0] == '\0') {
1174 inform("Envelope-From cannot be blank when there "
1175 "is multiple From: addresses\nand no Sender: "
1179 fprintf (out
, "Sender: %s\n", efrom
);
1183 if (!(msgflags
& MVIS
))
1184 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
1188 if (!(msgflags
& MDAT
)) {
1189 inform("message has no Date: header");
1192 if (!(msgflags
& MFRM
)) {
1193 inform("message has no From: header");
1196 if (!(msgflags
& MRFM
)) {
1197 inform("message has no Resent-From: header");
1198 inform("See default components files for examples");
1202 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1203 inform("A Resent-Sender: or Envelope-From: header is "
1204 "required with multiple\nResent-From: addresses");
1212 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
1214 fprintf (out
, "Resent-Message-ID: %s\n",
1215 message_id (tclock
, 0));
1217 * If we have multiple Resent-From: addresses, make sure we have an
1218 * Resent-Sender: header. If we don't have one, then generate one
1219 * from Envelope-From (which in this case, cannot be blank)
1222 if (fromcount
> 1 && !seensender
) {
1223 if (efrom
[0] == '\0') {
1224 inform("Envelope-From cannot be blank when there "
1225 "is multiple Resent-From: addresses and no "
1226 "Resent-Sender: header");
1229 fprintf (out
, "Resent-Sender: %s\n", efrom
);
1233 if (!(msgflags
& MVIS
))
1234 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
1239 die("re-format message and try again");
1241 die("no addressees");
1246 get_header (char *header
, struct headers
*table
)
1250 header
= FENDNULL(header
);
1251 for (h
= table
; h
->value
; h
++)
1252 if (!strcasecmp(FENDNULL(h
->value
), header
))
1260 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
,
1261 unsigned int flags
, char *savehdr
, unsigned int savehdrsize
)
1264 bool saveappend
= false;
1267 char buffer
[BUFSIZ
];
1269 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
1271 if ((flags
& (HBCC
| HDCC
| HEFM
)) || mp
->m_ingrp
)
1275 fprintf (out
, "%s: ", name
);
1276 linepos
+= (nameoutput
= strlen (name
) + 2);
1280 shlen
= strlen(savehdr
);
1284 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
1285 mp
->m_pers
= mh_xstrdup(aka
);
1288 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
1291 cp
= adrformat (mp
);
1298 if (linepos
!= nameoutput
) {
1299 if (len
+ linepos
+ 2 > outputlinelen
) {
1300 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
1302 if (shlen
+ 2 + nameoutput
+ len
>= savehdrsize
) {
1305 snprintf(savehdr
+ shlen
, savehdrsize
- shlen
, ",\n%*s",
1313 if (shlen
+ 2 + len
>= savehdrsize
) {
1316 strncat(savehdr
, ", ", savehdrsize
- shlen
);
1324 if (saveappend
&& shlen
+ len
< savehdrsize
)
1325 strncat(savehdr
, cp
, savehdrsize
- shlen
+ len
);
1329 return flags
& HTRY
;
1334 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
1339 if (sm_mts
!= MTS_SENDMAIL_PIPE
&& (flags
& HBCC
))
1343 fprintf (out
, "%s: ", name
);
1344 linepos
+= (nameoutput
= strlen (name
) + 2);
1347 cp
= concat (group
, ";", NULL
);
1350 if (linepos
> nameoutput
) {
1351 if (len
+ linepos
+ 2 > outputlinelen
) {
1352 fprintf (out
, ",\n%*s", nameoutput
, "");
1353 linepos
= nameoutput
;
1367 insert (struct mailname
*np
)
1369 struct mailname
*mp
;
1371 if (np
->m_mbox
== NULL
)
1374 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1375 : np
->m_type
== UUCPHOST
? &uuaddrs
1379 if (!strcasecmp (FENDNULL(np
->m_host
),
1380 FENDNULL(mp
->m_next
->m_host
)) &&
1381 !strcasecmp (FENDNULL(np
->m_mbox
),
1382 FENDNULL(mp
->m_next
->m_mbox
)) &&
1383 np
->m_bcc
== mp
->m_next
->m_bcc
)
1396 struct mailname
*mp
;
1398 fputs("-------\n\t-- Addresses --\nlocal:\t", stdout
);
1399 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1400 printf ("%s%s%s", mp
->m_mbox
,
1401 mp
->m_bcc
? "[BCC]" : "",
1402 mp
->m_next
? ",\n\t" : "");
1404 fputs("\nnet:\t", stdout
);
1405 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1406 printf ("%s%s@%s%s%s", FENDNULL(mp
->m_path
),
1407 mp
->m_mbox
, mp
->m_host
,
1408 mp
->m_bcc
? "[BCC]" : "",
1409 mp
->m_next
? ",\n\t" : "");
1411 fputs("\nuucp:\t", stdout
);
1412 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1413 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1414 mp
->m_bcc
? "[BCC]" : "",
1415 mp
->m_next
? ",\n\t" : "");
1417 fputs("\n\t-- Folder Copies --\nfcc:\t", stdout
);
1418 for (i
= 0; i
< fccind
; i
++)
1419 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1427 struct mailname
*mp
;
1429 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1430 if (annoaux (mp
) == NOTOK
)
1433 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1434 if (annoaux (mp
) == NOTOK
)
1437 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1438 if (annoaux (mp
) == NOTOK
)
1448 annoaux (struct mailname
*mp
)
1451 char buffer
[BUFSIZ
];
1453 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1454 i
= strlen (buffer
);
1456 return write(pfd
, buffer
, i
) == i
? OK
: NOTOK
;
1461 insert_fcc (struct headers
*hdr
, char *pp
)
1465 for (cp
= pp
; isspace ((unsigned char) *cp
); cp
++)
1467 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace ((unsigned char) *pp
); pp
--)
1475 die("too many %ss", hdr
->value
);
1476 fccfold
[fccind
++] = mh_xstrdup(cp
);
1484 make_bcc_file (int dashstuff
)
1490 char *tfile
= NULL
, *program
;
1492 if ((tfile
= m_mktemp2(NULL
, "bccs", NULL
, &out
)) == NULL
) {
1493 die("unable to create temporary file in %s", get_temp_dir());
1495 strncpy (bccfil
, tfile
, sizeof(bccfil
));
1497 fprintf (out
, "From: %s\n", fullfrom
);
1498 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1500 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1502 fprintf (out
, "Subject: %s", subject
);
1504 /* for sendmail/pipe, insert all bcc recipients here so that the email can be routed based on the bcc: header */
1505 if (sm_mts
== MTS_SENDMAIL_PIPE
)
1507 char *allbcc
= NULL
;
1508 struct mailname
*lp
;
1510 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1512 allbcc
= allbcc
? add(concat(", ", lp
->m_mbox
, NULL
), allbcc
)
1513 : mh_xstrdup(lp
->m_mbox
);
1514 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1516 allbcc
= allbcc
? add(
1517 concat(", ", lp
->m_mbox
, "@", lp
->m_host
, NULL
),
1519 : concat(lp
->m_mbox
, "@", lp
->m_host
, NULL
);
1522 fprintf (out
, "BCC: %s\n",allbcc
);
1528 fprintf (out
, "BCC:\n");
1532 * Use MIME encapsulation for Bcc messages
1538 * Check if any lines in the message clash with the
1539 * prefix for the MIME multipart separator. If there
1540 * is a clash, increment one of the letters in the
1541 * prefix and check again.
1543 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1544 die("lost prefix start");
1545 while (find_prefix () == NOTOK
) {
1548 else if (*++cp
== 0)
1549 die("can't find a unique delimiter string");
1554 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1555 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1556 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1558 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1564 * Do mhl filtering of Bcc messages instead
1565 * of MIME encapsulation.
1567 if (filter
!= NULL
) {
1571 adios ("fork", "unable to");
1574 dup2 (fileno (out
), 1);
1576 vec
= argsplit(mhlproc
, &program
, &i
);
1577 vec
[i
++] = "-forward";
1582 /* was the flag -[no]dashstuffing specified? */
1584 vec
[i
++] = "-dashstuffing";
1585 else if (dashstuff
< 0)
1586 vec
[i
++] = "-nodashstuffing";
1589 execvp (program
, vec
);
1590 fprintf (stderr
, "unable to exec ");
1595 pidXwait (child_id
, mhlproc
);
1599 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1600 adios (tmpfil
, "unable to re-open");
1603 * If using MIME encapsulation, or if the -nodashstuffing
1604 * flag was given, then just copy message. Else do
1605 * RFC934 quoting (dashstuffing).
1607 if (mime
|| dashstuff
< 0)
1608 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1610 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1614 fseek (out
, 0L, SEEK_END
);
1616 fprintf (out
, "\n--%s--\n", prefix
);
1618 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1624 * Scan message to check if any lines clash with
1625 * the prefix of the MIME multipart separator.
1632 char buffer
[BUFSIZ
];
1635 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1636 adios (tmpfil
, "unable to re-open");
1638 while (fgets (buffer
, sizeof buffer
, in
))
1639 if (buffer
[0] == '-' && buffer
[1] == '-') {
1642 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1643 if (!isspace ((unsigned char) *cp
))
1646 if (strcmp (buffer
+ 2, prefix
) == 0) {
1660 if (badadr
&& unkadr
)
1661 fatal (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1662 badadr
, PLURALS(badadr
), unkadr
, PLURALS(badadr
));
1664 fatal (NULL
, "%d address%s unparsable", badadr
, PLURALS(badadr
));
1666 fatal (NULL
, "%d addressee%s undeliverable", unkadr
, PLURALS(unkadr
));
1671 do_addresses (int bccque
, int talk
)
1675 struct mailname
*lp
;
1678 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1679 if (lp
->m_bcc
? bccque
: !bccque
) {
1681 puts(" -- Local Recipients --");
1682 do_an_address (lp
, talk
);
1687 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1688 if (lp
->m_bcc
? bccque
: !bccque
) {
1690 puts(" -- UUCP Recipients --");
1691 do_an_address (lp
, talk
);
1696 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1697 if (lp
->m_bcc
? bccque
: !bccque
) {
1699 puts(" -- Network Recipients --");
1700 do_an_address (lp
, talk
);
1706 if (rp_isbad (retval
= sm_waend ()))
1707 fatal (NULL
, "problem ending addresses; %s", rp_string (retval
));
1712 * MTS-SPECIFIC INTERACTION
1717 * SENDMAIL/SMTP routines
1721 post (char *file
, int bccque
, int talk
, int eai
, char *envelope
,
1722 int oauth_flag
, char *auth_svc
)
1728 if (msgflags
& MINV
)
1729 printf (" -- Posting for %s Recipients --\n",
1730 bccque
? "Blind" : "Sighted");
1732 puts(" -- Posting for All Recipients --");
1737 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1738 char **argp
, *program
;
1744 adios ("fork", "unable to");
1747 if (freopen( file
, "r", stdin
) == NULL
) {
1748 adios (file
, "can't reopen for sendmail");
1751 argp
= argsplit(sendmail
, &program
, &argc
);
1752 argp
[argc
++] = "-t"; /* read msg for recipients */
1753 argp
[argc
++] = "-i"; /* don't stop on "." */
1755 argp
[argc
++] = "-bv";
1757 argp
[argc
++] = "-v";
1760 execv (program
, argp
);
1761 adios (sendmail
, "can't exec");
1764 pidXwait (child_id
, NULL
);
1768 const int fd
= open (file
, O_RDONLY
);
1772 fatal (file
, "unable to re-open");
1775 if (msgflags
& MMIM
&& cte
!= UNKNOWN
) {
1776 /* MIME message with C-T-E header. (BINARYMIME isn't
1777 supported, use 8BITMIME instead for binary.) */
1778 eightbit
= cte
!= SEVENBIT
;
1780 if (scan_input (fd
, &eightbit
) == NOTOK
) {
1782 fatal (file
, "problem reading from");
1786 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1787 verbose
, snoop
, sasl
, saslmech
, user
,
1788 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1789 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1791 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1794 do_addresses (bccque
, talk
&& verbose
);
1799 sm_end (!(msgflags
& MINV
) || bccque
? OK
: DONE
);
1803 if (msgflags
& MINV
)
1804 printf (" -- %s Recipient Copies Posted --\n",
1805 bccque
? "Blind" : "Sighted");
1807 puts(" -- Recipient Copies Posted --");
1815 /* Address Verification */
1818 verify_all_addresses (int talk
, int eai
, char *envelope
, int oauth_flag
,
1822 struct mailname
*lp
;
1826 if (!whomsw
|| checksw
) {
1827 /* Not sending message body, so don't need to use 8BITMIME. */
1828 const int eightbit
= 0;
1830 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1831 verbose
, snoop
, sasl
, saslmech
, user
,
1832 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1833 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1834 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1838 if (talk
&& !whomsw
)
1839 puts(" -- Address Verification --");
1840 if (talk
&& localaddrs
.m_next
)
1841 puts(" -- Local Recipients --");
1842 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1843 do_an_address (lp
, talk
);
1845 if (talk
&& uuaddrs
.m_next
)
1846 puts(" -- UUCP Recipients --");
1847 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1848 do_an_address (lp
, talk
);
1850 if (talk
&& netaddrs
.m_next
)
1851 puts(" -- Network Recipients --");
1852 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1853 do_an_address (lp
, talk
);
1856 if (talk
&& !whomsw
)
1857 puts(" -- Address Verification Successful --");
1859 if (!whomsw
|| checksw
)
1860 sm_end (whomsw
? OK
: DONE
);
1868 do_an_address (struct mailname
*lp
, int talk
)
1874 switch (lp
->m_type
) {
1878 strncpy (addr
, mbox
, sizeof(addr
));
1882 mbox
= auxformat (lp
, 0);
1884 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1887 default: /* let SendMail decide if the host is bad */
1890 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1895 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1897 if (whomsw
&& !checksw
) {
1902 fputs(": ", stdout
);
1905 switch (retval
= sm_wadr (mbox
, host
,
1906 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1915 fprintf (stderr
, " %s: ", addr
);
1916 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1917 rp_string (retval
));
1923 fprintf (stderr
, " %s: ", addr
);
1924 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1932 do_text (char *file
, int fd
)
1937 lseek(fd
, 0, SEEK_SET
);
1939 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1940 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1941 fatal (NULL
, "problem writing text; %s\n", rp_string (retval
));
1945 fatal (file
, "problem reading from");
1947 switch (retval
= sm_wtend ()) {
1953 fatal (NULL
, "posting failed; %s", rp_string (retval
));
1957 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1971 (void) m_unlink (tmpfil
);
1972 if (msgflags
& MINV
)
1973 (void) m_unlink (bccfil
);
1975 if (!whomsw
|| checksw
)
1988 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1989 istat
= SIGNAL2 (SIGINT
, sigser
);
1990 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1991 tstat
= SIGNAL2 (SIGTERM
, sigser
);
2001 SIGNAL (SIGHUP
, hstat
);
2002 SIGNAL (SIGINT
, istat
);
2003 SIGNAL (SIGQUIT
, qstat
);
2004 SIGNAL (SIGTERM
, tstat
);
2012 p_refile (char *file
)
2020 puts(" -- Filing Folder Copies --");
2021 for (i
= 0; i
< fccind
; i
++)
2022 fcc (file
, fccfold
[i
]);
2024 puts(" -- Folder Copies Filed --");
2029 * Call the `fileproc' to add the file to the folder.
2033 fcc (char *file
, char *folder
)
2038 char **arglist
, *program
;
2041 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
2048 fprintf (stderr
, " %sFcc %s: ",
2049 msgstate
== RESENT
? "Resent-" : "", folder
);
2050 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
2054 /* see if we need to add `+' */
2055 snprintf (fold
, sizeof(fold
), "%s%s",
2056 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
2058 /* now exec the fileproc */
2060 arglist
= argsplit(fileproc
, &program
, &argp
);
2061 arglist
[argp
++] = "-link";
2062 arglist
[argp
++] = "-file";
2063 arglist
[argp
++] = file
;
2064 arglist
[argp
++] = fold
;
2065 arglist
[argp
] = NULL
;
2066 execvp (program
, arglist
);
2070 if ((status
= pidwait (child_id
, OK
))) {
2072 fprintf (stderr
, " %sFcc %s: ",
2073 msgstate
== RESENT
? "Resent-" : "", folder
);
2074 pidstatus (status
, verbose
? stdout
: stderr
, fileproc
);
2089 fatal (char *what
, char *fmt
, ...)
2096 (void) m_unlink (tmpfil
);
2097 if (msgflags
& MINV
)
2098 (void) m_unlink (bccfil
);
2100 if (!whomsw
|| checksw
)
2105 advertise (what
, NULL
, fmt
, ap
);