]>
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.
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) PURE
;
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 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
873 if (hdr
->flags
& HSUB
)
874 subject
= subject
? add (str
, add ("\t", subject
)) : mh_xstrdup(str
);
875 if (hdr
->flags
& HFCC
) {
876 if ((cp
= strrchr(str
, '\n')))
878 for (pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
880 insert_fcc (hdr
, pp
);
882 insert_fcc (hdr
, pp
);
885 if (hdr
->flags
& HCTE
) {
886 if (strncasecmp (str
, "7bit", 4) == 0) {
888 } else if (strncasecmp (str
, "8bit", 4) == 0) {
890 } else if (strncasecmp (str
, "binary", 6) == 0) {
894 if (!(hdr
->flags
& HADR
)) {
895 fprintf (out
, "%s: %s", name
, str
);
900 * If this is a From:/Resent-From: header, save the full thing for
901 * later in case we need it for use when constructing a Bcc draft message.
902 * Because we want to capture the results of alias expansion, save
903 * the output from putadr().
906 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
909 savehdrlen
= sizeof(fullfrom
);
912 tmpaddrs
.m_next
= NULL
;
914 for (count
= 0; (cp
= getname (str
)); count
++) {
915 if ((mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
919 tmpaddrs
.m_next
= mp
;
923 admonish(cp
, "%s", error
);
924 if (hdr
->flags
& HTRY
)
932 if (hdr
->flags
& HNIL
)
933 fprintf (out
, "%s: %s", name
, str
);
936 * Sender (or Resent-Sender) can have only one address
938 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
939 : (hdr
->set
& MSND
)) {
940 inform("%s: field requires one address", name
);
944 inform("%s: field requires at least one address", name
);
951 if (count
> 1 && (hdr
->flags
& HONE
)) {
952 inform("%s: field only permits one address", name
);
957 nameoutput
= linepos
= 0;
958 snprintf (namep
, sizeof(namep
), "%s%s",
959 (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
961 for (grp
= false, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
962 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
963 /* The address doesn't include a host, so it might be an alias. */
964 pp
= akvalue (mp
->m_mbox
); /* do mh alias substitution */
965 qp
= akvisible () ? mp
->m_mbox
: "";
968 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
969 while ((cp
= getname (pp
))) {
970 if (!(mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
971 admonish(cp
, "%s", error
);
977 * If it's a From: or Resent-From: header, save the address
978 * for later possible use (as the envelope address for SMTP)
981 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
982 : (hdr
->set
& MFRM
)) {
983 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
984 from
[sizeof(from
) - 1] = '\0';
989 * Also save the Sender: or Resent-Sender: header as well
992 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
993 : (hdr
->set
& MSND
)) {
994 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
995 sender
[sizeof(sender
) - 1] = '\0';
1000 * ALSO ... save Envelope-From
1003 if (hdr
->set
& MEFM
) {
1004 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1005 efrom
[sizeof(efrom
) - 1] = '\0';
1008 if (hdr
->flags
& HBCC
)
1011 mp
->m_ingrp
= np
->m_ingrp
;
1012 else if (mp
->m_gname
)
1013 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1015 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1016 /* Catch this before sendmail chokes with:
1017 "553 List:; syntax illegal for recipient
1019 If we wanted to, we could expand out blind
1020 aliases and put them in Bcc:, but then
1021 they'd have the Blind-Carbon-Copy
1023 die( "blind lists not compatible with"
1029 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
, savehdr
,
1031 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1040 /* Address includes a host, so no alias substitution is needed. */
1043 * If it's a From: or Resent-From header, save the address
1044 * for later possible use (as the envelope address for SMTP)
1047 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
1048 : (hdr
->set
& MFRM
)) {
1049 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
1054 * Also save the Sender: header as well
1057 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
1058 : (hdr
->set
& MSND
)) {
1059 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
1060 sender
[sizeof(sender
) - 1] = '\0';
1065 * ALSO ... save Envelope-From
1068 if (hdr
->set
& MEFM
) {
1069 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1070 efrom
[sizeof(efrom
) - 1] = '\0';
1073 if (hdr
->flags
& HBCC
)
1076 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1079 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
, savehdr
, savehdrlen
);
1083 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1090 * If it was a From header, strip off any trailing newlines from
1091 * the alias-expanded From line.
1094 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
1095 while (*fullfrom
&& fullfrom
[strlen(fullfrom
) - 1] == '\n') {
1096 fullfrom
[strlen(fullfrom
) - 1] = '\0';
1100 if (grp
&& (hdr
->flags
& HNGR
)) {
1101 inform("%s: field does not allow groups", name
);
1111 start_headers (void)
1116 * Probably not necessary, but just in case ...
1127 * Now that we've outputted the header fields in the draft
1128 * message, we will now output any remaining header fields
1129 * that we need to add/create.
1133 finish_headers (FILE *out
)
1137 if (!(msgflags
& MFRM
)) {
1139 * A From: header is now required in the draft.
1141 inform("message has no From: header");
1142 inform("See default components files for examples");
1147 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1148 inform("A Sender: or Envelope-From: header is required "
1149 "with multiple\nFrom: addresses");
1157 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1159 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1161 * If we have multiple From: addresses, make sure we have an
1162 * Sender: header. If we don't have one, then generate one
1163 * from Envelope-From: (which in this case, cannot be blank)
1166 if (fromcount
> 1 && !seensender
) {
1167 if (efrom
[0] == '\0') {
1168 inform("Envelope-From cannot be blank when there "
1169 "is multiple From: addresses\nand no Sender: "
1173 fprintf (out
, "Sender: %s\n", efrom
);
1177 if (!(msgflags
& MVIS
))
1178 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
1182 if (!(msgflags
& MDAT
)) {
1183 inform("message has no Date: header");
1186 if (!(msgflags
& MFRM
)) {
1187 inform("message has no From: header");
1190 if (!(msgflags
& MRFM
)) {
1191 inform("message has no Resent-From: header");
1192 inform("See default components files for examples");
1196 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1197 inform("A Resent-Sender: or Envelope-From: header is "
1198 "required with multiple\nResent-From: addresses");
1206 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
1208 fprintf (out
, "Resent-Message-ID: %s\n",
1209 message_id (tclock
, 0));
1211 * If we have multiple Resent-From: addresses, make sure we have an
1212 * Resent-Sender: header. If we don't have one, then generate one
1213 * from Envelope-From (which in this case, cannot be blank)
1216 if (fromcount
> 1 && !seensender
) {
1217 if (efrom
[0] == '\0') {
1218 inform("Envelope-From cannot be blank when there "
1219 "is multiple Resent-From: addresses and no "
1220 "Resent-Sender: header");
1223 fprintf (out
, "Resent-Sender: %s\n", efrom
);
1227 if (!(msgflags
& MVIS
))
1228 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
1233 die("re-format message and try again");
1235 die("no addressees");
1240 get_header (char *header
, struct headers
*table
)
1244 header
= FENDNULL(header
);
1245 for (h
= table
; h
->value
; h
++)
1246 if (!strcasecmp(FENDNULL(h
->value
), header
))
1254 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
,
1255 unsigned int flags
, char *savehdr
, unsigned int savehdrsize
)
1258 bool saveappend
= false;
1261 char buffer
[BUFSIZ
];
1263 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
1265 if (sm_mts
!= MTS_SENDMAIL_PIPE
&&
1266 ((flags
& (HBCC
| HDCC
| HEFM
)) || mp
->m_ingrp
))
1270 fprintf (out
, "%s: ", name
);
1271 linepos
+= (nameoutput
= strlen (name
) + 2);
1275 shlen
= strlen(savehdr
);
1279 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
1280 mp
->m_pers
= mh_xstrdup(aka
);
1283 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
1286 cp
= adrformat (mp
);
1293 if (linepos
!= nameoutput
) {
1294 if (len
+ linepos
+ 2 > outputlinelen
) {
1295 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
1297 if (shlen
+ 2 + nameoutput
+ len
>= savehdrsize
) {
1300 snprintf(savehdr
+ shlen
, savehdrsize
- shlen
, ",\n%*s",
1308 if (shlen
+ 2 + len
>= savehdrsize
) {
1311 strncat(savehdr
, ", ", savehdrsize
- shlen
);
1319 if (saveappend
&& shlen
+ len
< savehdrsize
)
1320 strncat(savehdr
, cp
, savehdrsize
- shlen
+ len
);
1324 return flags
& HTRY
;
1329 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
1334 if (sm_mts
!= MTS_SENDMAIL_PIPE
&& (flags
& HBCC
))
1338 fprintf (out
, "%s: ", name
);
1339 linepos
+= (nameoutput
= strlen (name
) + 2);
1342 cp
= concat (group
, ";", NULL
);
1345 if (linepos
> nameoutput
) {
1346 if (len
+ linepos
+ 2 > outputlinelen
) {
1347 fprintf (out
, ",\n%*s", nameoutput
, "");
1348 linepos
= nameoutput
;
1362 insert (struct mailname
*np
)
1364 struct mailname
*mp
;
1366 if (np
->m_mbox
== NULL
)
1369 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1370 : np
->m_type
== UUCPHOST
? &uuaddrs
1374 if (!strcasecmp (FENDNULL(np
->m_host
),
1375 FENDNULL(mp
->m_next
->m_host
)) &&
1376 !strcasecmp (FENDNULL(np
->m_mbox
),
1377 FENDNULL(mp
->m_next
->m_mbox
)) &&
1378 np
->m_bcc
== mp
->m_next
->m_bcc
)
1391 struct mailname
*mp
;
1393 fputs("-------\n\t-- Addresses --\nlocal:\t", stdout
);
1394 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1395 printf ("%s%s%s", mp
->m_mbox
,
1396 mp
->m_bcc
? "[BCC]" : "",
1397 mp
->m_next
? ",\n\t" : "");
1399 fputs("\nnet:\t", stdout
);
1400 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1401 printf ("%s%s@%s%s%s", FENDNULL(mp
->m_path
),
1402 mp
->m_mbox
, mp
->m_host
,
1403 mp
->m_bcc
? "[BCC]" : "",
1404 mp
->m_next
? ",\n\t" : "");
1406 fputs("\nuucp:\t", stdout
);
1407 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1408 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1409 mp
->m_bcc
? "[BCC]" : "",
1410 mp
->m_next
? ",\n\t" : "");
1412 fputs("\n\t-- Folder Copies --\nfcc:\t", stdout
);
1413 for (i
= 0; i
< fccind
; i
++)
1414 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1422 struct mailname
*mp
;
1424 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1425 if (annoaux (mp
) == NOTOK
)
1428 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1429 if (annoaux (mp
) == NOTOK
)
1432 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1433 if (annoaux (mp
) == NOTOK
)
1443 annoaux (struct mailname
*mp
)
1446 char buffer
[BUFSIZ
];
1448 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1449 i
= strlen (buffer
);
1451 return write(pfd
, buffer
, i
) == i
? OK
: NOTOK
;
1456 insert_fcc (struct headers
*hdr
, char *pp
)
1460 for (cp
= pp
; isspace ((unsigned char) *cp
); cp
++)
1462 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace ((unsigned char) *pp
); pp
--)
1470 die("too many %ss", hdr
->value
);
1471 fccfold
[fccind
++] = mh_xstrdup(cp
);
1479 make_bcc_file (int dashstuff
)
1485 char *tfile
= NULL
, *program
;
1487 if ((tfile
= m_mktemp2(NULL
, "bccs", NULL
, &out
)) == NULL
) {
1488 die("unable to create temporary file in %s", get_temp_dir());
1490 strncpy (bccfil
, tfile
, sizeof(bccfil
));
1492 fprintf (out
, "From: %s\n", fullfrom
);
1493 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1495 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1497 fprintf (out
, "Subject: %s", subject
);
1498 fprintf (out
, "BCC:\n");
1501 * Use MIME encapsulation for Bcc messages
1507 * Check if any lines in the message clash with the
1508 * prefix for the MIME multipart separator. If there
1509 * is a clash, increment one of the letters in the
1510 * prefix and check again.
1512 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1513 die("lost prefix start");
1514 while (find_prefix () == NOTOK
) {
1517 else if (*++cp
== 0)
1518 die("can't find a unique delimiter string");
1523 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1524 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1525 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1527 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1533 * Do mhl filtering of Bcc messages instead
1534 * of MIME encapsulation.
1536 if (filter
!= NULL
) {
1540 adios ("fork", "unable to");
1543 dup2 (fileno (out
), 1);
1545 vec
= argsplit(mhlproc
, &program
, &i
);
1546 vec
[i
++] = "-forward";
1551 /* was the flag -[no]dashstuffing specified? */
1553 vec
[i
++] = "-dashstuffing";
1554 else if (dashstuff
< 0)
1555 vec
[i
++] = "-nodashstuffing";
1558 execvp (program
, vec
);
1559 fprintf (stderr
, "unable to exec ");
1564 pidXwait (child_id
, mhlproc
);
1568 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1569 adios (tmpfil
, "unable to re-open");
1572 * If using MIME encapsulation, or if the -nodashstuffing
1573 * flag was given, then just copy message. Else do
1574 * RFC934 quoting (dashstuffing).
1576 if (mime
|| dashstuff
< 0)
1577 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1579 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1583 fseek (out
, 0L, SEEK_END
);
1585 fprintf (out
, "\n--%s--\n", prefix
);
1587 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1593 * Scan message to check if any lines clash with
1594 * the prefix of the MIME multipart separator.
1601 char buffer
[BUFSIZ
];
1604 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1605 adios (tmpfil
, "unable to re-open");
1607 while (fgets (buffer
, sizeof buffer
, in
))
1608 if (buffer
[0] == '-' && buffer
[1] == '-') {
1611 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1612 if (!isspace ((unsigned char) *cp
))
1615 if (strcmp (buffer
+ 2, prefix
) == 0) {
1629 if (badadr
&& unkadr
)
1630 fatal (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1631 badadr
, PLURALS(badadr
), unkadr
, PLURALS(badadr
));
1633 fatal (NULL
, "%d address%s unparsable", badadr
, PLURALS(badadr
));
1635 fatal (NULL
, "%d addressee%s undeliverable", unkadr
, PLURALS(unkadr
));
1640 do_addresses (int bccque
, int talk
)
1644 struct mailname
*lp
;
1647 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1648 if (lp
->m_bcc
? bccque
: !bccque
) {
1650 puts(" -- Local Recipients --");
1651 do_an_address (lp
, talk
);
1656 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1657 if (lp
->m_bcc
? bccque
: !bccque
) {
1659 puts(" -- UUCP Recipients --");
1660 do_an_address (lp
, talk
);
1665 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1666 if (lp
->m_bcc
? bccque
: !bccque
) {
1668 puts(" -- Network Recipients --");
1669 do_an_address (lp
, talk
);
1675 if (rp_isbad (retval
= sm_waend ()))
1676 fatal (NULL
, "problem ending addresses; %s", rp_string (retval
));
1681 * MTS-SPECIFIC INTERACTION
1686 * SENDMAIL/SMTP routines
1690 post (char *file
, int bccque
, int talk
, int eai
, char *envelope
,
1691 int oauth_flag
, char *auth_svc
)
1697 if (msgflags
& MINV
)
1698 printf (" -- Posting for %s Recipients --\n",
1699 bccque
? "Blind" : "Sighted");
1701 puts(" -- Posting for All Recipients --");
1706 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1707 char **argp
, *program
;
1713 adios ("fork", "unable to");
1716 if (freopen( file
, "r", stdin
) == NULL
) {
1717 adios (file
, "can't reopen for sendmail");
1720 argp
= argsplit(sendmail
, &program
, &argc
);
1721 argp
[argc
++] = "-t"; /* read msg for recipients */
1722 argp
[argc
++] = "-i"; /* don't stop on "." */
1724 argp
[argc
++] = "-bv";
1726 argp
[argc
++] = "-v";
1729 execv (program
, argp
);
1730 adios (sendmail
, "can't exec");
1733 pidXwait (child_id
, NULL
);
1737 const int fd
= open (file
, O_RDONLY
);
1741 fatal (file
, "unable to re-open");
1744 if (msgflags
& MMIM
&& cte
!= UNKNOWN
) {
1745 /* MIME message with C-T-E header. (BINARYMIME isn't
1746 supported, use 8BITMIME instead for binary.) */
1747 eightbit
= cte
!= SEVENBIT
;
1749 if (scan_input (fd
, &eightbit
) == NOTOK
) {
1751 fatal (file
, "problem reading from");
1755 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1756 verbose
, snoop
, sasl
, saslmech
, user
,
1757 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1758 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1760 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1763 do_addresses (bccque
, talk
&& verbose
);
1768 sm_end (!(msgflags
& MINV
) || bccque
? OK
: DONE
);
1772 if (msgflags
& MINV
)
1773 printf (" -- %s Recipient Copies Posted --\n",
1774 bccque
? "Blind" : "Sighted");
1776 puts(" -- Recipient Copies Posted --");
1784 /* Address Verification */
1787 verify_all_addresses (int talk
, int eai
, char *envelope
, int oauth_flag
,
1791 struct mailname
*lp
;
1795 if (!whomsw
|| checksw
) {
1796 /* Not sending message body, so don't need to use 8BITMIME. */
1797 const int eightbit
= 0;
1799 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1800 verbose
, snoop
, sasl
, saslmech
, user
,
1801 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1802 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1803 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1807 if (talk
&& !whomsw
)
1808 puts(" -- Address Verification --");
1809 if (talk
&& localaddrs
.m_next
)
1810 puts(" -- Local Recipients --");
1811 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1812 do_an_address (lp
, talk
);
1814 if (talk
&& uuaddrs
.m_next
)
1815 puts(" -- UUCP Recipients --");
1816 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1817 do_an_address (lp
, talk
);
1819 if (talk
&& netaddrs
.m_next
)
1820 puts(" -- Network Recipients --");
1821 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1822 do_an_address (lp
, talk
);
1825 if (talk
&& !whomsw
)
1826 puts(" -- Address Verification Successful --");
1828 if (!whomsw
|| checksw
)
1829 sm_end (whomsw
? OK
: DONE
);
1837 do_an_address (struct mailname
*lp
, int talk
)
1843 switch (lp
->m_type
) {
1847 strncpy (addr
, mbox
, sizeof(addr
));
1851 mbox
= auxformat (lp
, 0);
1853 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1856 default: /* let SendMail decide if the host is bad */
1859 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1864 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1866 if (whomsw
&& !checksw
) {
1871 fputs(": ", stdout
);
1874 switch (retval
= sm_wadr (mbox
, host
,
1875 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1884 fprintf (stderr
, " %s: ", addr
);
1885 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1886 rp_string (retval
));
1892 fprintf (stderr
, " %s: ", addr
);
1893 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1901 do_text (char *file
, int fd
)
1906 lseek(fd
, 0, SEEK_SET
);
1908 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1909 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1910 fatal (NULL
, "problem writing text; %s\n", rp_string (retval
));
1914 fatal (file
, "problem reading from");
1916 switch (retval
= sm_wtend ()) {
1922 fatal (NULL
, "posting failed; %s", rp_string (retval
));
1926 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1940 (void) m_unlink (tmpfil
);
1941 if (msgflags
& MINV
)
1942 (void) m_unlink (bccfil
);
1944 if (!whomsw
|| checksw
)
1957 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1958 istat
= SIGNAL2 (SIGINT
, sigser
);
1959 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1960 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1970 SIGNAL (SIGHUP
, hstat
);
1971 SIGNAL (SIGINT
, istat
);
1972 SIGNAL (SIGQUIT
, qstat
);
1973 SIGNAL (SIGTERM
, tstat
);
1981 p_refile (char *file
)
1989 puts(" -- Filing Folder Copies --");
1990 for (i
= 0; i
< fccind
; i
++)
1991 fcc (file
, fccfold
[i
]);
1993 puts(" -- Folder Copies Filed --");
1998 * Call the `fileproc' to add the file to the folder.
2002 fcc (char *file
, char *folder
)
2007 char **arglist
, *program
;
2010 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
2017 fprintf (stderr
, " %sFcc %s: ",
2018 msgstate
== RESENT
? "Resent-" : "", folder
);
2019 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
2023 /* see if we need to add `+' */
2024 snprintf (fold
, sizeof(fold
), "%s%s",
2025 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
2027 /* now exec the fileproc */
2029 arglist
= argsplit(fileproc
, &program
, &argp
);
2030 arglist
[argp
++] = "-link";
2031 arglist
[argp
++] = "-file";
2032 arglist
[argp
++] = file
;
2033 arglist
[argp
++] = fold
;
2034 arglist
[argp
] = NULL
;
2035 execvp (program
, arglist
);
2039 if ((status
= pidwait (child_id
, OK
))) {
2041 fprintf (stderr
, " %sFcc %s: ",
2042 msgstate
== RESENT
? "Resent-" : "", folder
);
2043 pidstatus (status
, verbose
? stdout
: stderr
, fileproc
);
2058 fatal (char *what
, char *fmt
, ...)
2065 (void) m_unlink (tmpfil
);
2066 if (msgflags
& MINV
)
2067 (void) m_unlink (bccfil
);
2069 if (!whomsw
|| checksw
)
2074 advertise (what
, NULL
, fmt
, ap
);