]>
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/m_getfld.h"
10 #include "sbr/getarguments.h"
11 #include "sbr/concat.h"
12 #include "sbr/smatch.h"
13 #include "sbr/cpydata.h"
14 #include "sbr/cpydgst.h"
16 #include "sbr/context_foil.h"
17 #include "sbr/readconfig.h"
18 #include "sbr/ambigsw.h"
19 #include "sbr/pidstatus.h"
20 #include "sbr/print_version.h"
21 #include "sbr/print_help.h"
22 #include "sbr/arglist.h"
23 #include "sbr/error.h"
25 #include "h/signals.h"
26 #include "h/addrsbr.h"
27 #include "h/aliasbr.h"
28 #include "h/dropsbr.h"
34 #include "sbr/m_mktemp.h"
35 #include "sbr/message_id.h"
37 #ifdef HAVE_SYS_TIME_H
38 # include <sys/time.h>
42 #include "mts/smtp/smtp.h"
45 # define SASLminc(a) (a)
46 #else /* CYRUS_SASL */
47 # define SASLminc(a) 0
48 #endif /* CYRUS_SASL */
51 # define TLSminc(a) (a)
52 #else /* TLS_SUPPORT */
54 #endif /* TLS_SUPPORT */
57 # define OAUTHminc(a) (a)
58 #else /* OAUTH_SUPPORT */
59 # define OAUTHminc(a) 0
60 #endif /* OAUTH_SUPPORT */
62 #define FCCS 10 /* max number of fccs allowed */
64 /* In the following array of structures, the numeric second field of the
65 structures (minchars) is apparently used like this:
67 -# : Switch can be abbreviated to # characters; switch hidden in -help.
68 0 : Switch can't be abbreviated; switch shown in -help.
69 # : Switch can be abbreviated to # characters; switch shown in -help. */
71 #define POST_SWITCHES \
72 X("alias aliasfile", 0, ALIASW) \
73 X("check", -5, CHKSW) /* interface from whom */ \
74 X("nocheck", -7, NCHKSW) /* interface from whom */ \
75 X("debug", -5, DEBUGSW) \
76 X("dist", -4, DISTSW) /* interface from dist */ \
77 X("filter filterfile", 0, FILTSW) \
78 X("nofilter", 0, NFILTSW) \
79 X("format", 0, FRMTSW) \
80 X("noformat", 0, NFRMTSW) \
81 X("library directory", -7, LIBSW) /* interface from send, whom */ \
82 X("mime", 0, MIMESW) \
83 X("nomime", 0, NMIMESW) \
84 X("msgid", 0, MSGDSW) \
85 X("nomsgid", 0, NMSGDSW) \
86 X("verbose", 0, VERBSW) \
87 X("noverbose", 0, NVERBSW) \
88 X("watch", 0, WATCSW) \
89 X("nowatch", 0, NWATCSW) \
90 X("whom", -4, WHOMSW) /* interface from whom */ \
91 X("width columns", 0, WIDTHSW) \
92 X("version", 0, VERSIONSW) \
93 X("help", 0, HELPSW) \
94 X("dashstuffing", -12, BITSTUFFSW) /* should we dashstuff BCC messages? */ \
95 X("nodashstuffing", -14, NBITSTUFFSW) \
96 X("idanno number", -6, ANNOSW) /* interface from send */ \
97 X("client host", -6, CLIESW) \
98 X("server host", 6, SERVSW) /* specify alternate SMTP server */ \
99 X("snoop", -5, SNOOPSW) /* snoop the SMTP transaction */ \
100 X("partno", -6, PARTSW) \
101 X("sasl", SASLminc(4), SASLSW) \
102 X("nosasl", SASLminc(6), NOSASLSW) \
103 X("saslmech", SASLminc(5), SASLMECHSW) \
104 X("user", SASLminc(-4), USERSW) \
105 X("port server submission port name/number", 4, PORTSW) \
106 X("tls", TLSminc(-3), TLSSW) \
107 X("initialtls", TLSminc(-10), INITTLSSW) \
108 X("notls", TLSminc(-5), NTLSSW) \
109 X("certverify", TLSminc(-10), CERTVERSW) \
110 X("nocertverify", TLSminc(-12), NOCERTVERSW) \
111 X("fileproc", -4, FILEPROCSW) \
112 X("mhlproc", -3, MHLPROCSW) \
113 X("sendmail program", 0, MTSSM) \
114 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
115 X("credentials legacy|file:filename", 0, CREDENTIALSSW) \
116 X("messageid localname|random", 2, MESSAGEIDSW) \
117 X("authservice auth-service-name", OAUTHminc(-11), AUTHSERVICESW) \
118 X("oauthcredfile credential-file", OAUTHminc(-7), OAUTHCREDFILESW) \
119 X("oauthclientid client-id", OAUTHminc(-12), OAUTHCLIDSW) \
120 X("oauthclientsecret client-secret", OAUTHminc(-12), OAUTHCLSECSW) \
121 X("oauthauthendpoint authentication-endpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
122 X("oauthredirect redirect-uri", OAUTHminc(-6), OAUTHREDIRSW) \
123 X("oauthtokenendpoint token-endpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
124 X("oauthscope scope", OAUTHminc(-6), OAUTHSCOPESW) \
126 #define X(sw, minchars, id) id,
127 DEFINE_SWITCH_ENUM(POST
);
130 #define X(sw, minchars, id) { sw, minchars, id },
131 DEFINE_SWITCH_ARRAY(POST
, switches
);
136 * Mapping between command-line switches and profile entries, communicated
137 * from 'send'. We use a service name of 'post' internally.
141 const char *profname
;
144 } oauthswitches
[] = {
145 { "oauth-%s-credential-file", OAUTHCREDFILESW
, NULL
},
146 { "oauth-%s-client_id", OAUTHCLIDSW
, NULL
},
147 { "oauth-%s-client_secret", OAUTHCLSECSW
, NULL
},
148 { "oauth-%s-auth_endpoint", OAUTHAUTHENDSW
, NULL
},
149 { "oauth-%s-redirect_uri", OAUTHREDIRSW
, NULL
},
150 { "oauth-%s-token_endpoint", OAUTHTOKENDSW
, NULL
},
151 { "oauth-%s-scope", OAUTHSCOPESW
, NULL
},
162 * flags for headers->flags
164 #define HNOP 0x0000 /* just used to keep .set around */
165 #define HBAD 0x0001 /* bad header - don't let it through */
166 #define HADR 0x0002 /* header has an address field */
167 #define HSUB 0x0004 /* Subject: header */
168 #define HTRY 0x0008 /* try to send to addrs on header */
169 #define HBCC 0x0010 /* don't output this header, unless MTS_SENDMAIL_PIPE */
170 #define HMNG 0x0020 /* munge this header */
171 #define HNGR 0x0040 /* no groups allowed in this header */
172 #define HFCC 0x0080 /* FCC: type header */
173 #define HNIL 0x0100 /* okay for this header not to have addrs */
174 #define HIGN 0x0200 /* ignore this header */
175 #define HDCC 0x0400 /* another undocumented feature */
176 #define HONE 0x0800 /* Only (zero or) one address allowed */
177 #define HEFM 0x1000 /* Envelope-From: header */
178 #define HMIM 0x2000 /* MIME-Version: header */
179 #define HCTE 0x4000 /* Content-Transfer-Encoding: header */
182 * flags for headers->set
184 #define MFRM 0x0001 /* we've seen a From: */
185 #define MDAT 0x0002 /* we've seen a Date: */
186 #define MRFM 0x0004 /* we've seen a Resent-From: */
187 #define MVIS 0x0008 /* we've seen sighted addrs */
188 #define MINV 0x0010 /* we've seen blind addrs */
189 #define MSND 0x0020 /* we've seen a Sender: */
190 #define MRSN 0x0040 /* We've seen a Resent-Sender: */
191 #define MEFM 0x0080 /* We've seen Envelope-From: */
192 #define MMIM 0x0100 /* We've seen Mime-Version: */
194 static struct headers NHeaders
[] = {
195 { "Return-Path", HBAD
, 0 },
196 { "Received", HBAD
, 0 },
197 { "Reply-To", HADR
|HNGR
, 0 },
198 { "From", HADR
|HNGR
, MFRM
},
199 { "Sender", HADR
|HNGR
|HONE
, MSND
},
201 { "Subject", HSUB
, 0 },
202 { "To", HADR
|HTRY
, MVIS
},
203 { "cc", HADR
|HTRY
, MVIS
},
204 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, MINV
},
205 { "Dcc", HADR
|HTRY
|HDCC
|HNIL
, MVIS
}, /* sorta cc & bcc combined */
206 { "Message-ID", HBAD
, 0 },
208 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
209 { "MIME-Version", HMIM
, MMIM
},
210 { "Content-Transfer-Encoding", HCTE
, 0 },
214 static struct headers RHeaders
[] = {
215 { "Resent-Reply-To", HADR
|HNGR
, 0 },
216 { "Resent-From", HADR
|HNGR
, MRFM
},
217 { "Resent-Sender", HADR
|HNGR
, MRSN
},
218 { "Resent-Date", HBAD
, 0 },
219 { "Resent-Subject", HSUB
, 0 },
220 { "Resent-To", HADR
|HTRY
, MVIS
},
221 { "Resent-cc", HADR
|HTRY
, MVIS
},
222 { "Resent-Bcc", HADR
|HTRY
|HBCC
, MINV
},
223 { "Resent-Message-ID", HBAD
, 0 },
224 { "Resent-Fcc", HFCC
, 0 },
225 { "Reply-To", HADR
, 0 },
226 { "From", HADR
|HNGR
, MFRM
},
227 { "Sender", HADR
|HNGR
, MSND
},
228 { "Date", HNOP
, MDAT
},
229 { "To", HADR
|HNIL
, 0 },
230 { "cc", HADR
|HNIL
, 0 },
231 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, 0 },
233 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
234 { "MIME-Version", HMIM
, MMIM
},
235 { "Content-Transfer-Encoding", HCTE
, 0 },
239 static short fccind
= 0; /* index into fccfold[] */
240 static short outputlinelen
= OUTPUTLINELEN
;
242 static int pfd
= NOTOK
; /* fd to write annotation list to */
243 static bool recipients
; /* how many people will get a copy */
244 static int unkadr
= 0; /* how many of those were unknown */
245 static int badadr
= 0; /* number of bad addrs */
246 static bool badmsg
; /* message has bad semantics */
247 static bool verbose
; /* spell it out */
248 static bool format
= true; /* format addresses */
249 static bool mime
; /* use MIME-style encapsulations for Bcc */
250 static bool msgid
; /* add msgid */
251 static bool debug
; /* debugging post */
252 static bool watch
; /* watch the delivery process */
253 static bool whomsw
; /* we are whom not post */
254 static bool checksw
; /* whom -check */
255 static int linepos
=0; /* putadr()'s position on the line */
256 static int nameoutput
=0; /* putadr() has output header name */
257 static bool sasl
; /* Use SASL auth for SMTP */
258 static char *saslmech
=NULL
; /* Force use of particular SASL mech */
259 static char *user
=NULL
; /* Authenticate as this user */
260 static char *port
="submission"; /* Name of server port for SMTP submission */
261 static int tlsflag
=0; /* Flags to control TLS settings */
262 static int fromcount
=0; /* Count of addresses on From: header */
263 static bool seensender
; /* Have we seen a Sender: header? */
265 static unsigned msgflags
= 0; /* what we've seen */
269 static int msgstate
= NORMAL
;
271 static time_t tclock
= 0; /* the time we started (more or less) */
273 static SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
275 static char tmpfil
[BUFSIZ
];
276 static char bccfil
[BUFSIZ
];
278 static char from
[BUFSIZ
]; /* my network address */
279 static char sender
[BUFSIZ
]; /* my Sender: header */
280 static char efrom
[BUFSIZ
]; /* my Envelope-From: header */
281 static char fullfrom
[BUFSIZ
]; /* full contents of From header */
282 static char *filter
= NULL
; /* the filter for BCC'ing */
283 static char *subject
= NULL
; /* the subject field for BCC'ing */
284 static char *fccfold
[FCCS
]; /* foldernames for FCC'ing */
285 enum encoding
{ UNKNOWN
= 0, BINARY
= 1, SEVENBIT
= 7, EIGHTBIT
= 8 };
286 static enum encoding cte
= UNKNOWN
;
288 static struct headers
*hdrtab
; /* table for the message we're doing */
290 static struct mailname localaddrs
; /* local addrs */
291 static struct mailname netaddrs
; /* network addrs */
292 static struct mailname uuaddrs
; /* uucp addrs */
293 static struct mailname tmpaddrs
; /* temporary queue */
296 static char *clientsw
= NULL
;
297 static char *serversw
= NULL
;
299 static char prefix
[] = "----- =_aaaaaaaaaa";
301 static char *partno
= NULL
;
306 static void putfmt (char *, char *, int *, FILE *);
307 static void start_headers (void);
308 static void finish_headers (FILE *);
309 static int get_header (char *, struct headers
*) PURE
;
310 static int putadr (char *, char *, struct mailname
*, FILE *, unsigned int,
311 char *, unsigned int);
312 static void putgrp (char *, char *, FILE *, unsigned int);
313 static int insert (struct mailname
*);
314 static void pl (void);
315 static void anno (void);
316 static int annoaux (struct mailname
*);
317 static void insert_fcc (struct headers
*, char *);
318 static void make_bcc_file (int);
319 static void verify_all_addresses (int, int, char *, int, char *);
320 static void chkadr (void) PURE
;
321 static void sigon (void);
322 static void sigoff (void);
323 static void p_refile (char *);
324 static void fcc (char *, char *);
325 static void fatal (char *, char *, ...) CHECK_PRINTF(2, 3);
326 static void post (char *, int, int, int, char *, int, char *);
327 static void do_text (char *file
, int fd
);
328 static void do_an_address (struct mailname
*, int);
329 static void do_addresses (int, int);
330 static int find_prefix (void);
334 main (int argc
, char **argv
)
336 int state
, compnum
, dashstuff
= 0, swnum
;
337 bool oauth_flag
= false;
339 bool noverify
= false;
340 int eai
= 0; /* use Email Address Internationalization (EAI) (SMTPUTF8) */
341 char *cp
, *msg
= NULL
, **argp
, **arguments
, *envelope
;
342 char buf
[NMH_BUFSIZ
], name
[NAMESZ
], *auth_svc
= NULL
;
344 m_getfld_state_t gstate
;
346 if (nmh_init(argv
[0], false, false)) { return 1; }
349 arguments
= getarguments (invo_name
, argc
, argv
, 0);
352 while ((cp
= *argp
++)) {
354 switch ((swnum
= smatch (++cp
, switches
))) {
356 ambigsw (cp
, switches
);
359 die("-%s unknown", cp
);
362 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
363 print_help (buf
, switches
, 0);
366 print_version(invo_name
);
370 if (!(cp
= *argp
++) || *cp
== '-')
371 die("missing argument to %s", argp
[-2]);
372 /* create a minimal context */
373 if (context_foil (cp
) == -1)
378 if (!(cp
= *argp
++) || *cp
== '-')
379 die("missing argument to %s", argp
[-2]);
380 if ((state
= alias (cp
)) != AK_OK
)
381 die("aliasing error in %s - %s",
382 cp
, akerror (state
));
401 if (!(filter
= *argp
++) || *filter
== '-')
402 die("missing argument to %s", argp
[-2]);
457 if (!(cp
= *argp
++) || *cp
== '-')
458 die("missing argument to %s", argp
[-2]);
459 if ((outputlinelen
= atoi (cp
)) < 10)
460 die("impossible width %d", outputlinelen
);
464 if (!(cp
= *argp
++) || *cp
== '-')
465 die("missing argument to %s", argp
[-2]);
466 if ((pfd
= atoi (cp
)) <= 2)
467 die("bad argument %s %s", argp
[-2], cp
);
471 if (!(clientsw
= *argp
++) || *clientsw
== '-')
472 die("missing argument to %s", argp
[-2]);
475 if (!(serversw
= *argp
++) || *serversw
== '-')
476 die("missing argument to %s", argp
[-2]);
483 if (!(partno
= *argp
++) || *partno
== '-')
484 die("missing argument to %s", argp
[-2]);
496 if (!(saslmech
= *argp
++) || *saslmech
== '-')
497 die("missing argument to %s", argp
[-2]);
501 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
502 die("missing argument to %s", argp
[-2]);
506 case OAUTHCREDFILESW
:
516 if (!(cp
= *argp
++) || *cp
== '-')
517 die("missing argument to %s", argp
[-2]);
519 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
520 if (oauthswitches
[i
].switchnum
== swnum
) {
521 oauthswitches
[i
].value
= cp
;
526 if (oauthswitches
[i
].profname
== NULL
)
527 die("internal error: cannot map switch %s "
528 "to profile entry", argp
[-2]);
535 if (!(user
= *argp
++) || *user
== '-')
536 die("missing argument to %s", argp
[-2]);
540 if (!(port
= *argp
++) || *port
== '-')
541 die("missing argument to %s", argp
[-2]);
565 if (!(cp
= *argp
++) || *cp
== '-')
566 die("missing argument to %s", argp
[-2]);
571 if (!(cp
= *argp
++) || *cp
== '-')
572 die("missing argument to %s", argp
[-2]);
577 if (!(cp
= *argp
++) || *cp
== '-')
578 die("missing argument to %s", argp
[-2]);
583 if (!(cp
= *argp
++) || *cp
== '-')
584 die("missing argument to %s", argp
[-2]);
585 save_mts_method (cp
);
588 case CREDENTIALSSW
: {
589 if (!(cp
= *argp
++) || *cp
== '-')
590 die("missing argument to %s", argp
[-2]);
591 add_profile_entry ("credentials", cp
);
596 if (!(cp
= *argp
++) || *cp
== '-')
597 die("missing argument to %s", argp
[-2]);
598 if (save_message_id_style (cp
) != 0)
599 die("unsupported messageid \"%s\"", cp
);
604 die("only one message at a time!");
611 die("usage: %s [switches] file", invo_name
);
613 if (outputlinelen
< 10)
614 die("impossible width %d", outputlinelen
);
616 if ((in
= fopen (msg
, "r")) == NULL
)
617 adios (msg
, "unable to open");
625 if ((out
= fopen ("/dev/null", "w")) == NULL
)
626 adios ("/dev/null", "unable to open");
628 char *cp
= m_mktemp2(NULL
, invo_name
, NULL
, &out
);
630 die("unable to create temporary file in %s",
633 strncpy(tmpfil
, cp
, sizeof(tmpfil
));
637 hdrtab
= msgstate
== NORMAL
? NHeaders
: RHeaders
;
639 gstate
= m_getfld_state_init(in
);
640 for (compnum
= 1;;) {
641 int bufsz
= sizeof buf
;
642 switch (state
= m_getfld2(&gstate
, name
, buf
, &bufsz
)) {
646 cp
= mh_xstrdup(buf
);
647 while (state
== FLDPLUS
) {
649 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
652 putfmt (name
, cp
, &eai
, out
);
657 finish_headers (out
);
660 fprintf (out
, "\n%s", buf
);
661 while (state
== BODY
) {
663 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
669 finish_headers (out
);
674 die("message format error in component #%d", compnum
);
677 die("getfld() returned %d", state
);
681 m_getfld_state_destroy (&gstate
);
694 * Here's how we decide which address to use as the envelope-from
697 * - If we were given an Envelope-From header, use that.
698 * - If we were given a Sender: address, use that.
699 * - Otherwise, use the address on the From: line
702 if (msgflags
& MEFM
) {
704 } else if (seensender
) {
713 * The user didn't specify any of the tls switches. Try to
714 * help them by implying -initialtls if they're using port 465
715 * (smtps, until IANA revoked that registration in 1998).
717 tls
= ! strcmp (port
, "465") || ! strcasecmp (port
, "smtps")
720 #else /* ! TLS_SUPPORT */
722 #endif /* ! TLS_SUPPORT */
726 tlsflag
= S_STARTTLS
;
733 tlsflag
|= S_NOVERIFY
;
736 * If we were given any oauth flags, store the appropriate profile
737 * entries and make sure an authservice was given (we have to do this
738 * here because we aren't guaranteed the authservice will be given on
739 * the command line before the other OAuth flags are given).
746 if (auth_svc
== NULL
) {
747 die("No authentication service given with -authservice");
750 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
751 if (oauthswitches
[i
].value
!= NULL
) {
752 snprintf(sbuf
, sizeof(sbuf
),
753 oauthswitches
[i
].profname
, auth_svc
);
754 sbuf
[sizeof(sbuf
) - 1] = '\0';
755 add_profile_entry(sbuf
, oauthswitches
[i
].value
);
760 /* If we are doing a "whom" check */
762 /* This won't work with MTS_SENDMAIL_PIPE. */
763 verify_all_addresses (1, eai
, envelope
, oauth_flag
, auth_svc
);
767 if (msgflags
& MINV
) {
768 make_bcc_file (dashstuff
);
769 if (msgflags
& MVIS
) {
770 if (sm_mts
!= MTS_SENDMAIL_PIPE
) {
771 /* It would be nice to have support to call
772 verify_all_addresses with MTS_SENDMAIL_PIPE, but
773 that might require running sendmail as root. Note
774 that spost didn't verify addresses. */
775 verify_all_addresses (verbose
, eai
, envelope
, oauth_flag
,
778 post (tmpfil
, 0, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
780 post (bccfil
, 1, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
781 (void) m_unlink (bccfil
);
783 post (tmpfil
, 0, isatty (1), eai
, envelope
, oauth_flag
, auth_svc
);
787 (void) m_unlink (tmpfil
);
791 printf ("Partial Message #%s Processed\n", partno
);
793 puts("Message Processed");
806 putfmt (char *name
, char *str
, int *eai
, FILE *out
)
812 char namep
[BUFSIZ
], error
[BUFSIZ
];
813 char *savehdr
= NULL
;
814 unsigned int savehdrlen
= 0;
815 struct mailname
*mp
= NULL
, *np
= NULL
;
818 while (*str
== ' ' || *str
== '\t')
821 if (msgstate
== NORMAL
&& uprf (name
, "resent")) {
822 inform("illegal header line -- %s:", name
);
828 /* Check each header field value to see if it has any 8-bit characters.
829 If it does, enable EAI support. */
830 if (contains8bit(str
, NULL
)) {
832 puts("EAI/SMTPUTF8 enabled");
835 /* Enable SMTPUTF8. */
838 /* Enable passing of utf-8 setting to getname()/getadrx(). */
843 if ((i
= get_header (name
, hdrtab
)) == NOTOK
) {
844 if (strncasecmp (name
, "nmh-", 4)) {
845 fprintf (out
, "%s: %s", name
, str
);
847 /* Filter out all Nmh-* headers, because Norm asked. They
848 should never have reached this point. Warn about any
849 that are non-empty. */
850 if (strcmp (str
, "\n")) {
851 trim_suffix_c(str
, '\n');
853 inform("ignoring header line -- %s: %s", name
, str
);
862 if (hdr
->flags
& HIGN
) {
865 if (hdr
->flags
& HBAD
) {
866 inform("illegal header line -- %s:", name
);
870 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
872 if (hdr
->flags
& HSUB
)
873 subject
= subject
? add (str
, add ("\t", subject
)) : mh_xstrdup(str
);
874 if (hdr
->flags
& HFCC
) {
875 if ((cp
= strrchr(str
, '\n')))
877 for (pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
879 insert_fcc (hdr
, pp
);
881 insert_fcc (hdr
, pp
);
884 if (hdr
->flags
& HCTE
) {
885 if (strncasecmp (str
, "7bit", 4) == 0) {
887 } else if (strncasecmp (str
, "8bit", 4) == 0) {
889 } else if (strncasecmp (str
, "binary", 6) == 0) {
893 if (!(hdr
->flags
& HADR
)) {
894 fprintf (out
, "%s: %s", name
, str
);
899 * If this is a From:/Resent-From: header, save the full thing for
900 * later in case we need it for use when constructing a Bcc draft message.
901 * Because we want to capture the results of alias expansion, save
902 * the output from putadr().
905 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
908 savehdrlen
= sizeof(fullfrom
);
911 tmpaddrs
.m_next
= NULL
;
913 for (count
= 0; (cp
= getname (str
)); count
++) {
914 if ((mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
918 tmpaddrs
.m_next
= mp
;
922 admonish(cp
, "%s", error
);
923 if (hdr
->flags
& HTRY
)
931 if (hdr
->flags
& HNIL
)
932 fprintf (out
, "%s: %s", name
, str
);
935 * Sender (or Resent-Sender) can have only one address
937 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
938 : (hdr
->set
& MSND
)) {
939 inform("%s: field requires one address", name
);
943 inform("%s: field requires at least one address", name
);
950 if (count
> 1 && (hdr
->flags
& HONE
)) {
951 inform("%s: field only permits one address", name
);
956 nameoutput
= linepos
= 0;
957 snprintf (namep
, sizeof(namep
), "%s%s",
958 (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
960 for (grp
= false, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
961 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
962 /* The address doesn't include a host, so it might be an alias. */
963 pp
= akvalue (mp
->m_mbox
); /* do mh alias substitution */
964 qp
= akvisible () ? mp
->m_mbox
: "";
967 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
968 while ((cp
= getname (pp
))) {
969 if (!(mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
970 admonish(cp
, "%s", error
);
976 * If it's a From: or Resent-From: header, save the address
977 * for later possible use (as the envelope address for SMTP)
980 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
981 : (hdr
->set
& MFRM
)) {
982 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
983 from
[sizeof(from
) - 1] = '\0';
988 * Also save the Sender: or Resent-Sender: header as well
991 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
992 : (hdr
->set
& MSND
)) {
993 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
994 sender
[sizeof(sender
) - 1] = '\0';
999 * ALSO ... save Envelope-From
1002 if (hdr
->set
& MEFM
) {
1003 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1004 efrom
[sizeof(efrom
) - 1] = '\0';
1007 if (hdr
->flags
& HBCC
)
1010 mp
->m_ingrp
= np
->m_ingrp
;
1011 else if (mp
->m_gname
)
1012 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1014 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1015 /* Catch this before sendmail chokes with:
1016 "553 List:; syntax illegal for recipient
1018 If we wanted to, we could expand out blind
1019 aliases and put them in Bcc:, but then
1020 they'd have the Blind-Carbon-Copy
1022 die( "blind lists not compatible with"
1028 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
, savehdr
,
1030 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1039 /* Address includes a host, so no alias substitution is needed. */
1042 * If it's a From: or Resent-From header, save the address
1043 * for later possible use (as the envelope address for SMTP)
1046 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
1047 : (hdr
->set
& MFRM
)) {
1048 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
1053 * Also save the Sender: header as well
1056 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
1057 : (hdr
->set
& MSND
)) {
1058 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
1059 sender
[sizeof(sender
) - 1] = '\0';
1064 * ALSO ... save Envelope-From
1067 if (hdr
->set
& MEFM
) {
1068 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1069 efrom
[sizeof(efrom
) - 1] = '\0';
1072 if (hdr
->flags
& HBCC
)
1075 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1078 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
, savehdr
, savehdrlen
);
1082 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1089 * If it was a From header, strip off any trailing newlines from
1090 * the alias-expanded From line.
1093 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
1094 while (*fullfrom
&& fullfrom
[strlen(fullfrom
) - 1] == '\n') {
1095 fullfrom
[strlen(fullfrom
) - 1] = '\0';
1099 if (grp
&& (hdr
->flags
& HNGR
)) {
1100 inform("%s: field does not allow groups", name
);
1110 start_headers (void)
1115 * Probably not necessary, but just in case ...
1126 * Now that we've outputted the header fields in the draft
1127 * message, we will now output any remaining header fields
1128 * that we need to add/create.
1132 finish_headers (FILE *out
)
1136 if (!(msgflags
& MFRM
)) {
1138 * A From: header is now required in the draft.
1140 inform("message has no From: header");
1141 inform("See default components files for examples");
1146 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1147 inform("A Sender: or Envelope-From: header is required "
1148 "with multiple\nFrom: addresses");
1156 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1158 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1160 * If we have multiple From: addresses, make sure we have an
1161 * Sender: header. If we don't have one, then generate one
1162 * from Envelope-From: (which in this case, cannot be blank)
1165 if (fromcount
> 1 && !seensender
) {
1166 if (efrom
[0] == '\0') {
1167 inform("Envelope-From cannot be blank when there "
1168 "is multiple From: addresses\nand no Sender: "
1172 fprintf (out
, "Sender: %s\n", efrom
);
1176 if (!(msgflags
& MVIS
))
1177 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
1181 if (!(msgflags
& MDAT
)) {
1182 inform("message has no Date: header");
1185 if (!(msgflags
& MFRM
)) {
1186 inform("message has no From: header");
1189 if (!(msgflags
& MRFM
)) {
1190 inform("message has no Resent-From: header");
1191 inform("See default components files for examples");
1195 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1196 inform("A Resent-Sender: or Envelope-From: header is "
1197 "required with multiple\nResent-From: addresses");
1205 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
1207 fprintf (out
, "Resent-Message-ID: %s\n",
1208 message_id (tclock
, 0));
1210 * If we have multiple Resent-From: addresses, make sure we have an
1211 * Resent-Sender: header. If we don't have one, then generate one
1212 * from Envelope-From (which in this case, cannot be blank)
1215 if (fromcount
> 1 && !seensender
) {
1216 if (efrom
[0] == '\0') {
1217 inform("Envelope-From cannot be blank when there "
1218 "is multiple Resent-From: addresses and no "
1219 "Resent-Sender: header");
1222 fprintf (out
, "Resent-Sender: %s\n", efrom
);
1226 if (!(msgflags
& MVIS
))
1227 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
1232 die("re-format message and try again");
1234 die("no addressees");
1239 get_header (char *header
, struct headers
*table
)
1243 header
= FENDNULL(header
);
1244 for (h
= table
; h
->value
; h
++)
1245 if (!strcasecmp(FENDNULL(h
->value
), header
))
1253 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
,
1254 unsigned int flags
, char *savehdr
, unsigned int savehdrsize
)
1257 bool saveappend
= false;
1260 char buffer
[BUFSIZ
];
1262 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
1264 if (sm_mts
!= MTS_SENDMAIL_PIPE
&&
1265 ((flags
& (HBCC
| HDCC
| HEFM
)) || mp
->m_ingrp
))
1269 fprintf (out
, "%s: ", name
);
1270 linepos
+= (nameoutput
= strlen (name
) + 2);
1274 shlen
= strlen(savehdr
);
1278 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
1279 mp
->m_pers
= mh_xstrdup(aka
);
1282 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
1285 cp
= adrformat (mp
);
1292 if (linepos
!= nameoutput
) {
1293 if (len
+ linepos
+ 2 > outputlinelen
) {
1294 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
1296 if (shlen
+ 2 + nameoutput
+ len
>= savehdrsize
) {
1299 snprintf(savehdr
+ shlen
, savehdrsize
- shlen
, ",\n%*s",
1307 if (shlen
+ 2 + len
>= savehdrsize
) {
1310 strncat(savehdr
, ", ", savehdrsize
- shlen
);
1318 if (saveappend
&& shlen
+ len
< savehdrsize
)
1319 strncat(savehdr
, cp
, savehdrsize
- shlen
+ len
);
1323 return flags
& HTRY
;
1328 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
1333 if (sm_mts
!= MTS_SENDMAIL_PIPE
&& (flags
& HBCC
))
1337 fprintf (out
, "%s: ", name
);
1338 linepos
+= (nameoutput
= strlen (name
) + 2);
1341 cp
= concat (group
, ";", NULL
);
1344 if (linepos
> nameoutput
) {
1345 if (len
+ linepos
+ 2 > outputlinelen
) {
1346 fprintf (out
, ",\n%*s", nameoutput
, "");
1347 linepos
= nameoutput
;
1361 insert (struct mailname
*np
)
1363 struct mailname
*mp
;
1365 if (np
->m_mbox
== NULL
)
1368 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1369 : np
->m_type
== UUCPHOST
? &uuaddrs
1373 if (!strcasecmp (FENDNULL(np
->m_host
),
1374 FENDNULL(mp
->m_next
->m_host
)) &&
1375 !strcasecmp (FENDNULL(np
->m_mbox
),
1376 FENDNULL(mp
->m_next
->m_mbox
)) &&
1377 np
->m_bcc
== mp
->m_next
->m_bcc
)
1390 struct mailname
*mp
;
1392 fputs("-------\n\t-- Addresses --\nlocal:\t", stdout
);
1393 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1394 printf ("%s%s%s", mp
->m_mbox
,
1395 mp
->m_bcc
? "[BCC]" : "",
1396 mp
->m_next
? ",\n\t" : "");
1398 fputs("\nnet:\t", stdout
);
1399 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1400 printf ("%s%s@%s%s%s", FENDNULL(mp
->m_path
),
1401 mp
->m_mbox
, mp
->m_host
,
1402 mp
->m_bcc
? "[BCC]" : "",
1403 mp
->m_next
? ",\n\t" : "");
1405 fputs("\nuucp:\t", stdout
);
1406 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1407 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1408 mp
->m_bcc
? "[BCC]" : "",
1409 mp
->m_next
? ",\n\t" : "");
1411 fputs("\n\t-- Folder Copies --\nfcc:\t", stdout
);
1412 for (i
= 0; i
< fccind
; i
++)
1413 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1421 struct mailname
*mp
;
1423 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1424 if (annoaux (mp
) == NOTOK
)
1427 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1428 if (annoaux (mp
) == NOTOK
)
1431 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1432 if (annoaux (mp
) == NOTOK
)
1442 annoaux (struct mailname
*mp
)
1445 char buffer
[BUFSIZ
];
1447 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1448 i
= strlen (buffer
);
1450 return write(pfd
, buffer
, i
) == i
? OK
: NOTOK
;
1455 insert_fcc (struct headers
*hdr
, char *pp
)
1459 for (cp
= pp
; isspace ((unsigned char) *cp
); cp
++)
1461 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace ((unsigned char) *pp
); pp
--)
1469 die("too many %ss", hdr
->value
);
1470 fccfold
[fccind
++] = mh_xstrdup(cp
);
1478 make_bcc_file (int dashstuff
)
1484 char *tfile
= NULL
, *program
;
1486 if ((tfile
= m_mktemp2(NULL
, "bccs", NULL
, &out
)) == NULL
) {
1487 die("unable to create temporary file in %s", get_temp_dir());
1489 strncpy (bccfil
, tfile
, sizeof(bccfil
));
1491 fprintf (out
, "From: %s\n", fullfrom
);
1492 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1494 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1496 fprintf (out
, "Subject: %s", subject
);
1497 fprintf (out
, "BCC:\n");
1500 * Use MIME encapsulation for Bcc messages
1506 * Check if any lines in the message clash with the
1507 * prefix for the MIME multipart separator. If there
1508 * is a clash, increment one of the letters in the
1509 * prefix and check again.
1511 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1512 die("lost prefix start");
1513 while (find_prefix () == NOTOK
) {
1516 else if (*++cp
== 0)
1517 die("can't find a unique delimiter string");
1522 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1523 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1524 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1526 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1532 * Do mhl filtering of Bcc messages instead
1533 * of MIME encapsulation.
1535 if (filter
!= NULL
) {
1539 adios ("fork", "unable to");
1542 dup2 (fileno (out
), 1);
1544 vec
= argsplit(mhlproc
, &program
, &i
);
1545 vec
[i
++] = "-forward";
1550 /* was the flag -[no]dashstuffing specified? */
1552 vec
[i
++] = "-dashstuffing";
1553 else if (dashstuff
< 0)
1554 vec
[i
++] = "-nodashstuffing";
1557 execvp (program
, vec
);
1558 fprintf (stderr
, "unable to exec ");
1563 pidXwait (child_id
, mhlproc
);
1567 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1568 adios (tmpfil
, "unable to re-open");
1571 * If using MIME encapsulation, or if the -nodashstuffing
1572 * flag was given, then just copy message. Else do
1573 * RFC934 quoting (dashstuffing).
1575 if (mime
|| dashstuff
< 0)
1576 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1578 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1582 fseek (out
, 0L, SEEK_END
);
1584 fprintf (out
, "\n--%s--\n", prefix
);
1586 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1592 * Scan message to check if any lines clash with
1593 * the prefix of the MIME multipart separator.
1600 char buffer
[BUFSIZ
];
1603 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1604 adios (tmpfil
, "unable to re-open");
1606 while (fgets (buffer
, sizeof buffer
, in
))
1607 if (buffer
[0] == '-' && buffer
[1] == '-') {
1610 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1611 if (!isspace ((unsigned char) *cp
))
1614 if (strcmp (buffer
+ 2, prefix
) == 0) {
1628 if (badadr
&& unkadr
)
1629 fatal (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1630 badadr
, PLURALS(badadr
), unkadr
, PLURALS(badadr
));
1632 fatal (NULL
, "%d address%s unparsable", badadr
, PLURALS(badadr
));
1634 fatal (NULL
, "%d addressee%s undeliverable", unkadr
, PLURALS(unkadr
));
1639 do_addresses (int bccque
, int talk
)
1643 struct mailname
*lp
;
1646 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1647 if (lp
->m_bcc
? bccque
: !bccque
) {
1649 puts(" -- Local Recipients --");
1650 do_an_address (lp
, talk
);
1655 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1656 if (lp
->m_bcc
? bccque
: !bccque
) {
1658 puts(" -- UUCP Recipients --");
1659 do_an_address (lp
, talk
);
1664 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1665 if (lp
->m_bcc
? bccque
: !bccque
) {
1667 puts(" -- Network Recipients --");
1668 do_an_address (lp
, talk
);
1674 if (rp_isbad (retval
= sm_waend ()))
1675 fatal (NULL
, "problem ending addresses; %s", rp_string (retval
));
1680 * MTS-SPECIFIC INTERACTION
1685 * SENDMAIL/SMTP routines
1689 post (char *file
, int bccque
, int talk
, int eai
, char *envelope
,
1690 int oauth_flag
, char *auth_svc
)
1696 if (msgflags
& MINV
)
1697 printf (" -- Posting for %s Recipients --\n",
1698 bccque
? "Blind" : "Sighted");
1700 puts(" -- Posting for All Recipients --");
1705 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1706 char **argp
, *program
;
1712 adios ("fork", "unable to");
1715 if (freopen( file
, "r", stdin
) == NULL
) {
1716 adios (file
, "can't reopen for sendmail");
1719 argp
= argsplit(sendmail
, &program
, &argc
);
1720 argp
[argc
++] = "-t"; /* read msg for recipients */
1721 argp
[argc
++] = "-i"; /* don't stop on "." */
1723 argp
[argc
++] = "-bv";
1725 argp
[argc
++] = "-v";
1728 execv (program
, argp
);
1729 adios (sendmail
, "can't exec");
1732 pidXwait (child_id
, NULL
);
1736 const int fd
= open (file
, O_RDONLY
);
1740 fatal (file
, "unable to re-open");
1743 if (msgflags
& MMIM
&& cte
!= UNKNOWN
) {
1744 /* MIME message with C-T-E header. (BINARYMIME isn't
1745 supported, use 8BITMIME instead for binary.) */
1746 eightbit
= cte
!= SEVENBIT
;
1748 if (scan_input (fd
, &eightbit
) == NOTOK
) {
1750 fatal (file
, "problem reading from");
1754 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1755 verbose
, snoop
, sasl
, saslmech
, user
,
1756 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1757 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1759 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1762 do_addresses (bccque
, talk
&& verbose
);
1767 sm_end (!(msgflags
& MINV
) || bccque
? OK
: DONE
);
1771 if (msgflags
& MINV
)
1772 printf (" -- %s Recipient Copies Posted --\n",
1773 bccque
? "Blind" : "Sighted");
1775 puts(" -- Recipient Copies Posted --");
1783 /* Address Verification */
1786 verify_all_addresses (int talk
, int eai
, char *envelope
, int oauth_flag
,
1790 struct mailname
*lp
;
1794 if (!whomsw
|| checksw
) {
1795 /* Not sending message body, so don't need to use 8BITMIME. */
1796 const int eightbit
= 0;
1798 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1799 verbose
, snoop
, sasl
, saslmech
, user
,
1800 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1801 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1802 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1806 if (talk
&& !whomsw
)
1807 puts(" -- Address Verification --");
1808 if (talk
&& localaddrs
.m_next
)
1809 puts(" -- Local Recipients --");
1810 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1811 do_an_address (lp
, talk
);
1813 if (talk
&& uuaddrs
.m_next
)
1814 puts(" -- UUCP Recipients --");
1815 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1816 do_an_address (lp
, talk
);
1818 if (talk
&& netaddrs
.m_next
)
1819 puts(" -- Network Recipients --");
1820 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1821 do_an_address (lp
, talk
);
1824 if (talk
&& !whomsw
)
1825 puts(" -- Address Verification Successful --");
1827 if (!whomsw
|| checksw
)
1828 sm_end (whomsw
? OK
: DONE
);
1836 do_an_address (struct mailname
*lp
, int talk
)
1842 switch (lp
->m_type
) {
1846 strncpy (addr
, mbox
, sizeof(addr
));
1850 mbox
= auxformat (lp
, 0);
1852 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1855 default: /* let SendMail decide if the host is bad */
1858 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1863 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1865 if (whomsw
&& !checksw
) {
1870 fputs(": ", stdout
);
1873 switch (retval
= sm_wadr (mbox
, host
,
1874 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1883 fprintf (stderr
, " %s: ", addr
);
1884 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1885 rp_string (retval
));
1891 fprintf (stderr
, " %s: ", addr
);
1892 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1900 do_text (char *file
, int fd
)
1905 lseek(fd
, 0, SEEK_SET
);
1907 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1908 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1909 fatal (NULL
, "problem writing text; %s\n", rp_string (retval
));
1913 fatal (file
, "problem reading from");
1915 switch (retval
= sm_wtend ()) {
1921 fatal (NULL
, "posting failed; %s", rp_string (retval
));
1925 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1939 (void) m_unlink (tmpfil
);
1940 if (msgflags
& MINV
)
1941 (void) m_unlink (bccfil
);
1943 if (!whomsw
|| checksw
)
1956 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1957 istat
= SIGNAL2 (SIGINT
, sigser
);
1958 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1959 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1969 SIGNAL (SIGHUP
, hstat
);
1970 SIGNAL (SIGINT
, istat
);
1971 SIGNAL (SIGQUIT
, qstat
);
1972 SIGNAL (SIGTERM
, tstat
);
1980 p_refile (char *file
)
1988 puts(" -- Filing Folder Copies --");
1989 for (i
= 0; i
< fccind
; i
++)
1990 fcc (file
, fccfold
[i
]);
1992 puts(" -- Folder Copies Filed --");
1997 * Call the `fileproc' to add the file to the folder.
2001 fcc (char *file
, char *folder
)
2006 char **arglist
, *program
;
2009 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
2016 fprintf (stderr
, " %sFcc %s: ",
2017 msgstate
== RESENT
? "Resent-" : "", folder
);
2018 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
2022 /* see if we need to add `+' */
2023 snprintf (fold
, sizeof(fold
), "%s%s",
2024 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
2026 /* now exec the fileproc */
2028 arglist
= argsplit(fileproc
, &program
, &argp
);
2029 arglist
[argp
++] = "-link";
2030 arglist
[argp
++] = "-file";
2031 arglist
[argp
++] = file
;
2032 arglist
[argp
++] = fold
;
2033 arglist
[argp
] = NULL
;
2034 execvp (program
, arglist
);
2038 if ((status
= pidwait (child_id
, OK
))) {
2040 fprintf (stderr
, " %sFcc %s: ",
2041 msgstate
== RESENT
? "Resent-" : "", folder
);
2042 pidstatus (status
, verbose
? stdout
: stderr
, fileproc
);
2057 fatal (char *what
, char *fmt
, ...)
2064 (void) m_unlink (tmpfil
);
2065 if (msgflags
& MINV
)
2066 (void) m_unlink (bccfil
);
2068 if (!whomsw
|| checksw
)
2073 advertise (what
, NULL
, fmt
, ap
);