]>
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/smatch.h"
10 #include "sbr/cpydata.h"
11 #include "sbr/cpydgst.h"
13 #include "sbr/context_foil.h"
14 #include "sbr/readconfig.h"
15 #include "sbr/ambigsw.h"
16 #include "sbr/pidstatus.h"
17 #include "sbr/print_version.h"
18 #include "sbr/print_help.h"
19 #include "sbr/arglist.h"
20 #include "sbr/error.h"
22 #include "h/signals.h"
23 #include "h/addrsbr.h"
24 #include "h/aliasbr.h"
25 #include "h/dropsbr.h"
31 #include "sbr/m_mktemp.h"
32 #include "sbr/message_id.h"
34 #ifdef HAVE_SYS_TIME_H
35 # include <sys/time.h>
39 #include "mts/smtp/smtp.h"
42 # define SASLminc(a) (a)
43 #else /* CYRUS_SASL */
44 # define SASLminc(a) 0
45 #endif /* CYRUS_SASL */
48 # define TLSminc(a) (a)
49 #else /* TLS_SUPPORT */
51 #endif /* TLS_SUPPORT */
54 # define OAUTHminc(a) (a)
55 #else /* OAUTH_SUPPORT */
56 # define OAUTHminc(a) 0
57 #endif /* OAUTH_SUPPORT */
59 #define FCCS 10 /* max number of fccs allowed */
61 /* In the following array of structures, the numeric second field of the
62 structures (minchars) is apparently used like this:
64 -# : Switch can be abbreviated to # characters; switch hidden in -help.
65 0 : Switch can't be abbreviated; switch shown in -help.
66 # : Switch can be abbreviated to # characters; switch shown in -help. */
68 #define POST_SWITCHES \
69 X("alias aliasfile", 0, ALIASW) \
70 X("check", -5, CHKSW) /* interface from whom */ \
71 X("nocheck", -7, NCHKSW) /* interface from whom */ \
72 X("debug", -5, DEBUGSW) \
73 X("dist", -4, DISTSW) /* interface from dist */ \
74 X("filter filterfile", 0, FILTSW) \
75 X("nofilter", 0, NFILTSW) \
76 X("format", 0, FRMTSW) \
77 X("noformat", 0, NFRMTSW) \
78 X("library directory", -7, LIBSW) /* interface from send, whom */ \
79 X("mime", 0, MIMESW) \
80 X("nomime", 0, NMIMESW) \
81 X("msgid", 0, MSGDSW) \
82 X("nomsgid", 0, NMSGDSW) \
83 X("verbose", 0, VERBSW) \
84 X("noverbose", 0, NVERBSW) \
85 X("watch", 0, WATCSW) \
86 X("nowatch", 0, NWATCSW) \
87 X("whom", -4, WHOMSW) /* interface from whom */ \
88 X("width columns", 0, WIDTHSW) \
89 X("version", 0, VERSIONSW) \
90 X("help", 0, HELPSW) \
91 X("dashstuffing", -12, BITSTUFFSW) /* should we dashstuff BCC messages? */ \
92 X("nodashstuffing", -14, NBITSTUFFSW) \
93 X("idanno number", -6, ANNOSW) /* interface from send */ \
94 X("client host", -6, CLIESW) \
95 X("server host", 6, SERVSW) /* specify alternate SMTP server */ \
96 X("snoop", -5, SNOOPSW) /* snoop the SMTP transaction */ \
97 X("partno", -6, PARTSW) \
98 X("sasl", SASLminc(4), SASLSW) \
99 X("nosasl", SASLminc(6), NOSASLSW) \
100 X("saslmech", SASLminc(5), SASLMECHSW) \
101 X("user", SASLminc(-4), USERSW) \
102 X("port server submission port name/number", 4, PORTSW) \
103 X("tls", TLSminc(-3), TLSSW) \
104 X("initialtls", TLSminc(-10), INITTLSSW) \
105 X("notls", TLSminc(-5), NTLSSW) \
106 X("certverify", TLSminc(-10), CERTVERSW) \
107 X("nocertverify", TLSminc(-12), NOCERTVERSW) \
108 X("fileproc", -4, FILEPROCSW) \
109 X("mhlproc", -3, MHLPROCSW) \
110 X("sendmail program", 0, MTSSM) \
111 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
112 X("credentials legacy|file:filename", 0, CREDENTIALSSW) \
113 X("messageid localname|random", 2, MESSAGEIDSW) \
114 X("authservice auth-service-name", OAUTHminc(-11), AUTHSERVICESW) \
115 X("oauthcredfile credential-file", OAUTHminc(-7), OAUTHCREDFILESW) \
116 X("oauthclientid client-id", OAUTHminc(-12), OAUTHCLIDSW) \
117 X("oauthclientsecret client-secret", OAUTHminc(-12), OAUTHCLSECSW) \
118 X("oauthauthendpoint authentication-endpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
119 X("oauthredirect redirect-uri", OAUTHminc(-6), OAUTHREDIRSW) \
120 X("oauthtokenendpoint token-endpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
121 X("oauthscope scope", OAUTHminc(-6), OAUTHSCOPESW) \
123 #define X(sw, minchars, id) id,
124 DEFINE_SWITCH_ENUM(POST
);
127 #define X(sw, minchars, id) { sw, minchars, id },
128 DEFINE_SWITCH_ARRAY(POST
, switches
);
133 * Mapping between command-line switches and profile entries, communicated
134 * from 'send'. We use a service name of 'post' internally.
138 const char *profname
;
141 } oauthswitches
[] = {
142 { "oauth-%s-credential-file", OAUTHCREDFILESW
, NULL
},
143 { "oauth-%s-client_id", OAUTHCLIDSW
, NULL
},
144 { "oauth-%s-client_secret", OAUTHCLSECSW
, NULL
},
145 { "oauth-%s-auth_endpoint", OAUTHAUTHENDSW
, NULL
},
146 { "oauth-%s-redirect_uri", OAUTHREDIRSW
, NULL
},
147 { "oauth-%s-token_endpoint", OAUTHTOKENDSW
, NULL
},
148 { "oauth-%s-scope", OAUTHSCOPESW
, NULL
},
159 * flags for headers->flags
161 #define HNOP 0x0000 /* just used to keep .set around */
162 #define HBAD 0x0001 /* bad header - don't let it through */
163 #define HADR 0x0002 /* header has an address field */
164 #define HSUB 0x0004 /* Subject: header */
165 #define HTRY 0x0008 /* try to send to addrs on header */
166 #define HBCC 0x0010 /* don't output this header, unless MTS_SENDMAIL_PIPE */
167 #define HMNG 0x0020 /* munge this header */
168 #define HNGR 0x0040 /* no groups allowed in this header */
169 #define HFCC 0x0080 /* FCC: type header */
170 #define HNIL 0x0100 /* okay for this header not to have addrs */
171 #define HIGN 0x0200 /* ignore this header */
172 #define HDCC 0x0400 /* another undocumented feature */
173 #define HONE 0x0800 /* Only (zero or) one address allowed */
174 #define HEFM 0x1000 /* Envelope-From: header */
175 #define HMIM 0x2000 /* MIME-Version: header */
176 #define HCTE 0x4000 /* Content-Transfer-Encoding: header */
179 * flags for headers->set
181 #define MFRM 0x0001 /* we've seen a From: */
182 #define MDAT 0x0002 /* we've seen a Date: */
183 #define MRFM 0x0004 /* we've seen a Resent-From: */
184 #define MVIS 0x0008 /* we've seen sighted addrs */
185 #define MINV 0x0010 /* we've seen blind addrs */
186 #define MSND 0x0020 /* we've seen a Sender: */
187 #define MRSN 0x0040 /* We've seen a Resent-Sender: */
188 #define MEFM 0x0080 /* We've seen Envelope-From: */
189 #define MMIM 0x0100 /* We've seen Mime-Version: */
191 static struct headers NHeaders
[] = {
192 { "Return-Path", HBAD
, 0 },
193 { "Received", HBAD
, 0 },
194 { "Reply-To", HADR
|HNGR
, 0 },
195 { "From", HADR
|HNGR
, MFRM
},
196 { "Sender", HADR
|HNGR
|HONE
, MSND
},
198 { "Subject", HSUB
, 0 },
199 { "To", HADR
|HTRY
, MVIS
},
200 { "cc", HADR
|HTRY
, MVIS
},
201 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, MINV
},
202 { "Dcc", HADR
|HTRY
|HDCC
|HNIL
, MVIS
}, /* sorta cc & bcc combined */
203 { "Message-ID", HBAD
, 0 },
205 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
206 { "MIME-Version", HMIM
, MMIM
},
207 { "Content-Transfer-Encoding", HCTE
, 0 },
211 static struct headers RHeaders
[] = {
212 { "Resent-Reply-To", HADR
|HNGR
, 0 },
213 { "Resent-From", HADR
|HNGR
, MRFM
},
214 { "Resent-Sender", HADR
|HNGR
, MRSN
},
215 { "Resent-Date", HBAD
, 0 },
216 { "Resent-Subject", HSUB
, 0 },
217 { "Resent-To", HADR
|HTRY
, MVIS
},
218 { "Resent-cc", HADR
|HTRY
, MVIS
},
219 { "Resent-Bcc", HADR
|HTRY
|HBCC
, MINV
},
220 { "Resent-Message-ID", HBAD
, 0 },
221 { "Resent-Fcc", HFCC
, 0 },
222 { "Reply-To", HADR
, 0 },
223 { "From", HADR
|HNGR
, MFRM
},
224 { "Sender", HADR
|HNGR
, MSND
},
225 { "Date", HNOP
, MDAT
},
226 { "To", HADR
|HNIL
, 0 },
227 { "cc", HADR
|HNIL
, 0 },
228 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, 0 },
230 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
231 { "MIME-Version", HMIM
, MMIM
},
232 { "Content-Transfer-Encoding", HCTE
, 0 },
236 static short fccind
= 0; /* index into fccfold[] */
237 static short outputlinelen
= OUTPUTLINELEN
;
239 static int pfd
= NOTOK
; /* fd to write annotation list to */
240 static bool recipients
; /* how many people will get a copy */
241 static int unkadr
= 0; /* how many of those were unknown */
242 static int badadr
= 0; /* number of bad addrs */
243 static bool badmsg
; /* message has bad semantics */
244 static bool verbose
; /* spell it out */
245 static bool format
= true; /* format addresses */
246 static bool mime
; /* use MIME-style encapsulations for Bcc */
247 static bool msgid
; /* add msgid */
248 static bool debug
; /* debugging post */
249 static bool watch
; /* watch the delivery process */
250 static bool whomsw
; /* we are whom not post */
251 static bool checksw
; /* whom -check */
252 static int linepos
=0; /* putadr()'s position on the line */
253 static int nameoutput
=0; /* putadr() has output header name */
254 static bool sasl
; /* Use SASL auth for SMTP */
255 static char *saslmech
=NULL
; /* Force use of particular SASL mech */
256 static char *user
=NULL
; /* Authenticate as this user */
257 static char *port
="submission"; /* Name of server port for SMTP submission */
258 static int tlsflag
=0; /* Flags to control TLS settings */
259 static int fromcount
=0; /* Count of addresses on From: header */
260 static bool seensender
; /* Have we seen a Sender: header? */
262 static unsigned msgflags
= 0; /* what we've seen */
266 static int msgstate
= NORMAL
;
268 static time_t tclock
= 0; /* the time we started (more or less) */
270 static SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
272 static char tmpfil
[BUFSIZ
];
273 static char bccfil
[BUFSIZ
];
275 static char from
[BUFSIZ
]; /* my network address */
276 static char sender
[BUFSIZ
]; /* my Sender: header */
277 static char efrom
[BUFSIZ
]; /* my Envelope-From: header */
278 static char fullfrom
[BUFSIZ
]; /* full contents of From header */
279 static char *filter
= NULL
; /* the filter for BCC'ing */
280 static char *subject
= NULL
; /* the subject field for BCC'ing */
281 static char *fccfold
[FCCS
]; /* foldernames for FCC'ing */
282 enum encoding
{ UNKNOWN
= 0, BINARY
= 1, SEVENBIT
= 7, EIGHTBIT
= 8 };
283 static enum encoding cte
= UNKNOWN
;
285 static struct headers
*hdrtab
; /* table for the message we're doing */
287 static struct mailname localaddrs
; /* local addrs */
288 static struct mailname netaddrs
; /* network addrs */
289 static struct mailname uuaddrs
; /* uucp addrs */
290 static struct mailname tmpaddrs
; /* temporary queue */
293 static char *clientsw
= NULL
;
294 static char *serversw
= NULL
;
296 static char prefix
[] = "----- =_aaaaaaaaaa";
298 static char *partno
= NULL
;
303 static void putfmt (char *, char *, int *, FILE *);
304 static void start_headers (void);
305 static void finish_headers (FILE *);
306 static int get_header (char *, struct headers
*) PURE
;
307 static int putadr (char *, char *, struct mailname
*, FILE *, unsigned int,
308 char *, unsigned int);
309 static void putgrp (char *, char *, FILE *, unsigned int);
310 static int insert (struct mailname
*);
311 static void pl (void);
312 static void anno (void);
313 static int annoaux (struct mailname
*);
314 static void insert_fcc (struct headers
*, char *);
315 static void make_bcc_file (int);
316 static void verify_all_addresses (int, int, char *, int, char *);
317 static void chkadr (void) PURE
;
318 static void sigon (void);
319 static void sigoff (void);
320 static void p_refile (char *);
321 static void fcc (char *, char *);
322 static void fatal (char *, char *, ...) CHECK_PRINTF(2, 3);
323 static void post (char *, int, int, int, char *, int, char *);
324 static void do_text (char *file
, int fd
);
325 static void do_an_address (struct mailname
*, int);
326 static void do_addresses (int, int);
327 static int find_prefix (void);
331 main (int argc
, char **argv
)
333 int state
, compnum
, dashstuff
= 0, swnum
;
334 bool oauth_flag
= false;
336 bool noverify
= false;
337 int eai
= 0; /* use Email Address Internationalization (EAI) (SMTPUTF8) */
338 char *cp
, *msg
= NULL
, **argp
, **arguments
, *envelope
;
339 char buf
[NMH_BUFSIZ
], name
[NAMESZ
], *auth_svc
= NULL
;
341 m_getfld_state_t gstate
;
343 if (nmh_init(argv
[0], false, false)) { return 1; }
346 arguments
= getarguments (invo_name
, argc
, argv
, 0);
349 while ((cp
= *argp
++)) {
351 switch ((swnum
= smatch (++cp
, switches
))) {
353 ambigsw (cp
, switches
);
356 die("-%s unknown", cp
);
359 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
360 print_help (buf
, switches
, 0);
363 print_version(invo_name
);
367 if (!(cp
= *argp
++) || *cp
== '-')
368 die("missing argument to %s", argp
[-2]);
369 /* create a minimal context */
370 if (context_foil (cp
) == -1)
375 if (!(cp
= *argp
++) || *cp
== '-')
376 die("missing argument to %s", argp
[-2]);
377 if ((state
= alias (cp
)) != AK_OK
)
378 die("aliasing error in %s - %s",
379 cp
, akerror (state
));
398 if (!(filter
= *argp
++) || *filter
== '-')
399 die("missing argument to %s", argp
[-2]);
454 if (!(cp
= *argp
++) || *cp
== '-')
455 die("missing argument to %s", argp
[-2]);
456 if ((outputlinelen
= atoi (cp
)) < 10)
457 die("impossible width %d", outputlinelen
);
461 if (!(cp
= *argp
++) || *cp
== '-')
462 die("missing argument to %s", argp
[-2]);
463 if ((pfd
= atoi (cp
)) <= 2)
464 die("bad argument %s %s", argp
[-2], cp
);
468 if (!(clientsw
= *argp
++) || *clientsw
== '-')
469 die("missing argument to %s", argp
[-2]);
472 if (!(serversw
= *argp
++) || *serversw
== '-')
473 die("missing argument to %s", argp
[-2]);
480 if (!(partno
= *argp
++) || *partno
== '-')
481 die("missing argument to %s", argp
[-2]);
493 if (!(saslmech
= *argp
++) || *saslmech
== '-')
494 die("missing argument to %s", argp
[-2]);
498 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
499 die("missing argument to %s", argp
[-2]);
503 case OAUTHCREDFILESW
:
513 if (!(cp
= *argp
++) || *cp
== '-')
514 die("missing argument to %s", argp
[-2]);
516 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
517 if (oauthswitches
[i
].switchnum
== swnum
) {
518 oauthswitches
[i
].value
= cp
;
523 if (oauthswitches
[i
].profname
== NULL
)
524 die("internal error: cannot map switch %s "
525 "to profile entry", argp
[-2]);
532 if (!(user
= *argp
++) || *user
== '-')
533 die("missing argument to %s", argp
[-2]);
537 if (!(port
= *argp
++) || *port
== '-')
538 die("missing argument to %s", argp
[-2]);
562 if (!(cp
= *argp
++) || *cp
== '-')
563 die("missing argument to %s", argp
[-2]);
568 if (!(cp
= *argp
++) || *cp
== '-')
569 die("missing argument to %s", argp
[-2]);
574 if (!(cp
= *argp
++) || *cp
== '-')
575 die("missing argument to %s", argp
[-2]);
580 if (!(cp
= *argp
++) || *cp
== '-')
581 die("missing argument to %s", argp
[-2]);
582 save_mts_method (cp
);
585 case CREDENTIALSSW
: {
586 if (!(cp
= *argp
++) || *cp
== '-')
587 die("missing argument to %s", argp
[-2]);
588 add_profile_entry ("credentials", cp
);
593 if (!(cp
= *argp
++) || *cp
== '-')
594 die("missing argument to %s", argp
[-2]);
595 if (save_message_id_style (cp
) != 0)
596 die("unsupported messageid \"%s\"", cp
);
601 die("only one message at a time!");
608 die("usage: %s [switches] file", invo_name
);
610 if (outputlinelen
< 10)
611 die("impossible width %d", outputlinelen
);
613 if ((in
= fopen (msg
, "r")) == NULL
)
614 adios (msg
, "unable to open");
622 if ((out
= fopen ("/dev/null", "w")) == NULL
)
623 adios ("/dev/null", "unable to open");
625 char *cp
= m_mktemp2(NULL
, invo_name
, NULL
, &out
);
627 die("unable to create temporary file in %s",
630 strncpy(tmpfil
, cp
, sizeof(tmpfil
));
634 hdrtab
= msgstate
== NORMAL
? NHeaders
: RHeaders
;
636 gstate
= m_getfld_state_init(in
);
637 for (compnum
= 1;;) {
638 int bufsz
= sizeof buf
;
639 switch (state
= m_getfld2(&gstate
, name
, buf
, &bufsz
)) {
643 cp
= mh_xstrdup(buf
);
644 while (state
== FLDPLUS
) {
646 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
649 putfmt (name
, cp
, &eai
, out
);
654 finish_headers (out
);
657 fprintf (out
, "\n%s", buf
);
658 while (state
== BODY
) {
660 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
666 finish_headers (out
);
671 die("message format error in component #%d", compnum
);
674 die("getfld() returned %d", state
);
678 m_getfld_state_destroy (&gstate
);
691 * Here's how we decide which address to use as the envelope-from
694 * - If we were given an Envelope-From header, use that.
695 * - If we were given a Sender: address, use that.
696 * - Otherwise, use the address on the From: line
699 if (msgflags
& MEFM
) {
701 } else if (seensender
) {
710 * The user didn't specify any of the tls switches. Try to
711 * help them by implying -initialtls if they're using port 465
712 * (smtps, until IANA revoked that registration in 1998).
714 tls
= ! strcmp (port
, "465") || ! strcasecmp (port
, "smtps")
717 #else /* ! TLS_SUPPORT */
719 #endif /* ! TLS_SUPPORT */
723 tlsflag
= S_STARTTLS
;
730 tlsflag
|= S_NOVERIFY
;
733 * If we were given any oauth flags, store the appropriate profile
734 * entries and make sure an authservice was given (we have to do this
735 * here because we aren't guaranteed the authservice will be given on
736 * the command line before the other OAuth flags are given).
743 if (auth_svc
== NULL
) {
744 die("No authentication service given with -authservice");
747 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
748 if (oauthswitches
[i
].value
!= NULL
) {
749 snprintf(sbuf
, sizeof(sbuf
),
750 oauthswitches
[i
].profname
, auth_svc
);
751 sbuf
[sizeof(sbuf
) - 1] = '\0';
752 add_profile_entry(sbuf
, oauthswitches
[i
].value
);
757 /* If we are doing a "whom" check */
759 /* This won't work with MTS_SENDMAIL_PIPE. */
760 verify_all_addresses (1, eai
, envelope
, oauth_flag
, auth_svc
);
764 if (msgflags
& MINV
) {
765 make_bcc_file (dashstuff
);
766 if (msgflags
& MVIS
) {
767 if (sm_mts
!= MTS_SENDMAIL_PIPE
) {
768 /* It would be nice to have support to call
769 verify_all_addresses with MTS_SENDMAIL_PIPE, but
770 that might require running sendmail as root. Note
771 that spost didn't verify addresses. */
772 verify_all_addresses (verbose
, eai
, envelope
, oauth_flag
,
775 post (tmpfil
, 0, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
777 post (bccfil
, 1, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
778 (void) m_unlink (bccfil
);
780 post (tmpfil
, 0, isatty (1), eai
, envelope
, oauth_flag
, auth_svc
);
784 (void) m_unlink (tmpfil
);
788 printf ("Partial Message #%s Processed\n", partno
);
790 puts("Message Processed");
803 putfmt (char *name
, char *str
, int *eai
, FILE *out
)
809 char namep
[BUFSIZ
], error
[BUFSIZ
];
810 char *savehdr
= NULL
;
811 unsigned int savehdrlen
= 0;
812 struct mailname
*mp
= NULL
, *np
= NULL
;
815 while (*str
== ' ' || *str
== '\t')
818 if (msgstate
== NORMAL
&& uprf (name
, "resent")) {
819 inform("illegal header line -- %s:", name
);
825 /* Check each header field value to see if it has any 8-bit characters.
826 If it does, enable EAI support. */
827 if (contains8bit(str
, NULL
)) {
829 puts("EAI/SMTPUTF8 enabled");
832 /* Enable SMTPUTF8. */
835 /* Enable passing of utf-8 setting to getname()/getadrx(). */
840 if ((i
= get_header (name
, hdrtab
)) == NOTOK
) {
841 if (strncasecmp (name
, "nmh-", 4)) {
842 fprintf (out
, "%s: %s", name
, str
);
844 /* Filter out all Nmh-* headers, because Norm asked. They
845 should never have reached this point. Warn about any
846 that are non-empty. */
847 if (strcmp (str
, "\n")) {
848 trim_suffix_c(str
, '\n');
850 inform("ignoring header line -- %s: %s", name
, str
);
859 if (hdr
->flags
& HIGN
) {
862 if (hdr
->flags
& HBAD
) {
863 inform("illegal header line -- %s:", name
);
867 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
869 if (hdr
->flags
& HSUB
)
870 subject
= subject
? add (str
, add ("\t", subject
)) : mh_xstrdup(str
);
871 if (hdr
->flags
& HFCC
) {
872 if ((cp
= strrchr(str
, '\n')))
874 for (pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
876 insert_fcc (hdr
, pp
);
878 insert_fcc (hdr
, pp
);
881 if (hdr
->flags
& HCTE
) {
882 if (strncasecmp (str
, "7bit", 4) == 0) {
884 } else if (strncasecmp (str
, "8bit", 4) == 0) {
886 } else if (strncasecmp (str
, "binary", 6) == 0) {
890 if (!(hdr
->flags
& HADR
)) {
891 fprintf (out
, "%s: %s", name
, str
);
896 * If this is a From:/Resent-From: header, save the full thing for
897 * later in case we need it for use when constructing a Bcc draft message.
898 * Because we want to capture the results of alias expansion, save
899 * the output from putadr().
902 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
905 savehdrlen
= sizeof(fullfrom
);
908 tmpaddrs
.m_next
= NULL
;
910 for (count
= 0; (cp
= getname (str
)); count
++) {
911 if ((mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
915 tmpaddrs
.m_next
= mp
;
919 admonish(cp
, "%s", error
);
920 if (hdr
->flags
& HTRY
)
928 if (hdr
->flags
& HNIL
)
929 fprintf (out
, "%s: %s", name
, str
);
932 * Sender (or Resent-Sender) can have only one address
934 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
935 : (hdr
->set
& MSND
)) {
936 inform("%s: field requires one address", name
);
940 inform("%s: field requires at least one address", name
);
947 if (count
> 1 && (hdr
->flags
& HONE
)) {
948 inform("%s: field only permits one address", name
);
953 nameoutput
= linepos
= 0;
954 snprintf (namep
, sizeof(namep
), "%s%s",
955 (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
957 for (grp
= false, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
958 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
959 /* The address doesn't include a host, so it might be an alias. */
960 pp
= akvalue (mp
->m_mbox
); /* do mh alias substitution */
961 qp
= akvisible () ? mp
->m_mbox
: "";
964 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
965 while ((cp
= getname (pp
))) {
966 if (!(mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
967 admonish(cp
, "%s", error
);
973 * If it's a From: or Resent-From: header, save the address
974 * for later possible use (as the envelope address for SMTP)
977 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
978 : (hdr
->set
& MFRM
)) {
979 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
980 from
[sizeof(from
) - 1] = '\0';
985 * Also save the Sender: or Resent-Sender: header as well
988 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
989 : (hdr
->set
& MSND
)) {
990 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
991 sender
[sizeof(sender
) - 1] = '\0';
996 * ALSO ... save Envelope-From
999 if (hdr
->set
& MEFM
) {
1000 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1001 efrom
[sizeof(efrom
) - 1] = '\0';
1004 if (hdr
->flags
& HBCC
)
1007 mp
->m_ingrp
= np
->m_ingrp
;
1008 else if (mp
->m_gname
)
1009 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1011 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1012 /* Catch this before sendmail chokes with:
1013 "553 List:; syntax illegal for recipient
1015 If we wanted to, we could expand out blind
1016 aliases and put them in Bcc:, but then
1017 they'd have the Blind-Carbon-Copy
1019 die( "blind lists not compatible with"
1025 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
, savehdr
,
1027 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1036 /* Address includes a host, so no alias substitution is needed. */
1039 * If it's a From: or Resent-From header, save the address
1040 * for later possible use (as the envelope address for SMTP)
1043 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
1044 : (hdr
->set
& MFRM
)) {
1045 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
1050 * Also save the Sender: header as well
1053 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
1054 : (hdr
->set
& MSND
)) {
1055 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
1056 sender
[sizeof(sender
) - 1] = '\0';
1061 * ALSO ... save Envelope-From
1064 if (hdr
->set
& MEFM
) {
1065 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1066 efrom
[sizeof(efrom
) - 1] = '\0';
1069 if (hdr
->flags
& HBCC
)
1072 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1075 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
, savehdr
, savehdrlen
);
1079 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1086 * If it was a From header, strip off any trailing newlines from
1087 * the alias-expanded From line.
1090 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
1091 while (*fullfrom
&& fullfrom
[strlen(fullfrom
) - 1] == '\n') {
1092 fullfrom
[strlen(fullfrom
) - 1] = '\0';
1096 if (grp
&& (hdr
->flags
& HNGR
)) {
1097 inform("%s: field does not allow groups", name
);
1107 start_headers (void)
1112 * Probably not necessary, but just in case ...
1123 * Now that we've outputted the header fields in the draft
1124 * message, we will now output any remaining header fields
1125 * that we need to add/create.
1129 finish_headers (FILE *out
)
1133 if (!(msgflags
& MFRM
)) {
1135 * A From: header is now required in the draft.
1137 inform("message has no From: header");
1138 inform("See default components files for examples");
1143 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1144 inform("A Sender: or Envelope-From: header is required "
1145 "with multiple\nFrom: addresses");
1153 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1155 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1157 * If we have multiple From: addresses, make sure we have an
1158 * Sender: header. If we don't have one, then generate one
1159 * from Envelope-From: (which in this case, cannot be blank)
1162 if (fromcount
> 1 && !seensender
) {
1163 if (efrom
[0] == '\0') {
1164 inform("Envelope-From cannot be blank when there "
1165 "is multiple From: addresses\nand no Sender: "
1169 fprintf (out
, "Sender: %s\n", efrom
);
1173 if (!(msgflags
& MVIS
))
1174 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
1178 if (!(msgflags
& MDAT
)) {
1179 inform("message has no Date: header");
1182 if (!(msgflags
& MFRM
)) {
1183 inform("message has no From: header");
1186 if (!(msgflags
& MRFM
)) {
1187 inform("message has no Resent-From: header");
1188 inform("See default components files for examples");
1192 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1193 inform("A Resent-Sender: or Envelope-From: header is "
1194 "required with multiple\nResent-From: addresses");
1202 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
1204 fprintf (out
, "Resent-Message-ID: %s\n",
1205 message_id (tclock
, 0));
1207 * If we have multiple Resent-From: addresses, make sure we have an
1208 * Resent-Sender: header. If we don't have one, then generate one
1209 * from Envelope-From (which in this case, cannot be blank)
1212 if (fromcount
> 1 && !seensender
) {
1213 if (efrom
[0] == '\0') {
1214 inform("Envelope-From cannot be blank when there "
1215 "is multiple Resent-From: addresses and no "
1216 "Resent-Sender: header");
1219 fprintf (out
, "Resent-Sender: %s\n", efrom
);
1223 if (!(msgflags
& MVIS
))
1224 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
1229 die("re-format message and try again");
1231 die("no addressees");
1236 get_header (char *header
, struct headers
*table
)
1240 header
= FENDNULL(header
);
1241 for (h
= table
; h
->value
; h
++)
1242 if (!strcasecmp(FENDNULL(h
->value
), header
))
1250 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
,
1251 unsigned int flags
, char *savehdr
, unsigned int savehdrsize
)
1254 bool saveappend
= false;
1257 char buffer
[BUFSIZ
];
1259 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
1261 if (sm_mts
!= MTS_SENDMAIL_PIPE
&&
1262 ((flags
& (HBCC
| HDCC
| HEFM
)) || mp
->m_ingrp
))
1266 fprintf (out
, "%s: ", name
);
1267 linepos
+= (nameoutput
= strlen (name
) + 2);
1271 shlen
= strlen(savehdr
);
1275 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
1276 mp
->m_pers
= mh_xstrdup(aka
);
1279 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
1282 cp
= adrformat (mp
);
1289 if (linepos
!= nameoutput
) {
1290 if (len
+ linepos
+ 2 > outputlinelen
) {
1291 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
1293 if (shlen
+ 2 + nameoutput
+ len
>= savehdrsize
) {
1296 snprintf(savehdr
+ shlen
, savehdrsize
- shlen
, ",\n%*s",
1304 if (shlen
+ 2 + len
>= savehdrsize
) {
1307 strncat(savehdr
, ", ", savehdrsize
- shlen
);
1315 if (saveappend
&& shlen
+ len
< savehdrsize
)
1316 strncat(savehdr
, cp
, savehdrsize
- shlen
+ len
);
1320 return flags
& HTRY
;
1325 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
1330 if (sm_mts
!= MTS_SENDMAIL_PIPE
&& (flags
& HBCC
))
1334 fprintf (out
, "%s: ", name
);
1335 linepos
+= (nameoutput
= strlen (name
) + 2);
1338 cp
= concat (group
, ";", NULL
);
1341 if (linepos
> nameoutput
) {
1342 if (len
+ linepos
+ 2 > outputlinelen
) {
1343 fprintf (out
, ",\n%*s", nameoutput
, "");
1344 linepos
= nameoutput
;
1358 insert (struct mailname
*np
)
1360 struct mailname
*mp
;
1362 if (np
->m_mbox
== NULL
)
1365 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1366 : np
->m_type
== UUCPHOST
? &uuaddrs
1370 if (!strcasecmp (FENDNULL(np
->m_host
),
1371 FENDNULL(mp
->m_next
->m_host
)) &&
1372 !strcasecmp (FENDNULL(np
->m_mbox
),
1373 FENDNULL(mp
->m_next
->m_mbox
)) &&
1374 np
->m_bcc
== mp
->m_next
->m_bcc
)
1387 struct mailname
*mp
;
1389 fputs("-------\n\t-- Addresses --\nlocal:\t", stdout
);
1390 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1391 printf ("%s%s%s", mp
->m_mbox
,
1392 mp
->m_bcc
? "[BCC]" : "",
1393 mp
->m_next
? ",\n\t" : "");
1395 fputs("\nnet:\t", stdout
);
1396 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1397 printf ("%s%s@%s%s%s", FENDNULL(mp
->m_path
),
1398 mp
->m_mbox
, mp
->m_host
,
1399 mp
->m_bcc
? "[BCC]" : "",
1400 mp
->m_next
? ",\n\t" : "");
1402 fputs("\nuucp:\t", stdout
);
1403 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1404 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1405 mp
->m_bcc
? "[BCC]" : "",
1406 mp
->m_next
? ",\n\t" : "");
1408 fputs("\n\t-- Folder Copies --\nfcc:\t", stdout
);
1409 for (i
= 0; i
< fccind
; i
++)
1410 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1418 struct mailname
*mp
;
1420 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1421 if (annoaux (mp
) == NOTOK
)
1424 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1425 if (annoaux (mp
) == NOTOK
)
1428 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1429 if (annoaux (mp
) == NOTOK
)
1439 annoaux (struct mailname
*mp
)
1442 char buffer
[BUFSIZ
];
1444 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1445 i
= strlen (buffer
);
1447 return write(pfd
, buffer
, i
) == i
? OK
: NOTOK
;
1452 insert_fcc (struct headers
*hdr
, char *pp
)
1456 for (cp
= pp
; isspace ((unsigned char) *cp
); cp
++)
1458 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace ((unsigned char) *pp
); pp
--)
1466 die("too many %ss", hdr
->value
);
1467 fccfold
[fccind
++] = mh_xstrdup(cp
);
1475 make_bcc_file (int dashstuff
)
1481 char *tfile
= NULL
, *program
;
1483 if ((tfile
= m_mktemp2(NULL
, "bccs", NULL
, &out
)) == NULL
) {
1484 die("unable to create temporary file in %s", get_temp_dir());
1486 strncpy (bccfil
, tfile
, sizeof(bccfil
));
1488 fprintf (out
, "From: %s\n", fullfrom
);
1489 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1491 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1493 fprintf (out
, "Subject: %s", subject
);
1494 fprintf (out
, "BCC:\n");
1497 * Use MIME encapsulation for Bcc messages
1503 * Check if any lines in the message clash with the
1504 * prefix for the MIME multipart separator. If there
1505 * is a clash, increment one of the letters in the
1506 * prefix and check again.
1508 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1509 die("lost prefix start");
1510 while (find_prefix () == NOTOK
) {
1513 else if (*++cp
== 0)
1514 die("can't find a unique delimiter string");
1519 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1520 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1521 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1523 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1529 * Do mhl filtering of Bcc messages instead
1530 * of MIME encapsulation.
1532 if (filter
!= NULL
) {
1536 adios ("fork", "unable to");
1539 dup2 (fileno (out
), 1);
1541 vec
= argsplit(mhlproc
, &program
, &i
);
1542 vec
[i
++] = "-forward";
1547 /* was the flag -[no]dashstuffing specified? */
1549 vec
[i
++] = "-dashstuffing";
1550 else if (dashstuff
< 0)
1551 vec
[i
++] = "-nodashstuffing";
1554 execvp (program
, vec
);
1555 fprintf (stderr
, "unable to exec ");
1560 pidXwait (child_id
, mhlproc
);
1564 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1565 adios (tmpfil
, "unable to re-open");
1568 * If using MIME encapsulation, or if the -nodashstuffing
1569 * flag was given, then just copy message. Else do
1570 * RFC934 quoting (dashstuffing).
1572 if (mime
|| dashstuff
< 0)
1573 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1575 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1579 fseek (out
, 0L, SEEK_END
);
1581 fprintf (out
, "\n--%s--\n", prefix
);
1583 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1589 * Scan message to check if any lines clash with
1590 * the prefix of the MIME multipart separator.
1597 char buffer
[BUFSIZ
];
1600 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1601 adios (tmpfil
, "unable to re-open");
1603 while (fgets (buffer
, sizeof buffer
, in
))
1604 if (buffer
[0] == '-' && buffer
[1] == '-') {
1607 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1608 if (!isspace ((unsigned char) *cp
))
1611 if (strcmp (buffer
+ 2, prefix
) == 0) {
1625 if (badadr
&& unkadr
)
1626 fatal (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1627 badadr
, PLURALS(badadr
), unkadr
, PLURALS(badadr
));
1629 fatal (NULL
, "%d address%s unparsable", badadr
, PLURALS(badadr
));
1631 fatal (NULL
, "%d addressee%s undeliverable", unkadr
, PLURALS(unkadr
));
1636 do_addresses (int bccque
, int talk
)
1640 struct mailname
*lp
;
1643 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1644 if (lp
->m_bcc
? bccque
: !bccque
) {
1646 puts(" -- Local Recipients --");
1647 do_an_address (lp
, talk
);
1652 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1653 if (lp
->m_bcc
? bccque
: !bccque
) {
1655 puts(" -- UUCP Recipients --");
1656 do_an_address (lp
, talk
);
1661 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1662 if (lp
->m_bcc
? bccque
: !bccque
) {
1664 puts(" -- Network Recipients --");
1665 do_an_address (lp
, talk
);
1671 if (rp_isbad (retval
= sm_waend ()))
1672 fatal (NULL
, "problem ending addresses; %s", rp_string (retval
));
1677 * MTS-SPECIFIC INTERACTION
1682 * SENDMAIL/SMTP routines
1686 post (char *file
, int bccque
, int talk
, int eai
, char *envelope
,
1687 int oauth_flag
, char *auth_svc
)
1693 if (msgflags
& MINV
)
1694 printf (" -- Posting for %s Recipients --\n",
1695 bccque
? "Blind" : "Sighted");
1697 puts(" -- Posting for All Recipients --");
1702 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1703 char **argp
, *program
;
1709 adios ("fork", "unable to");
1712 if (freopen( file
, "r", stdin
) == NULL
) {
1713 adios (file
, "can't reopen for sendmail");
1716 argp
= argsplit(sendmail
, &program
, &argc
);
1717 argp
[argc
++] = "-t"; /* read msg for recipients */
1718 argp
[argc
++] = "-i"; /* don't stop on "." */
1720 argp
[argc
++] = "-bv";
1722 argp
[argc
++] = "-v";
1725 execv (program
, argp
);
1726 adios (sendmail
, "can't exec");
1729 pidXwait (child_id
, NULL
);
1733 const int fd
= open (file
, O_RDONLY
);
1737 fatal (file
, "unable to re-open");
1740 if (msgflags
& MMIM
&& cte
!= UNKNOWN
) {
1741 /* MIME message with C-T-E header. (BINARYMIME isn't
1742 supported, use 8BITMIME instead for binary.) */
1743 eightbit
= cte
!= SEVENBIT
;
1745 if (scan_input (fd
, &eightbit
) == NOTOK
) {
1747 fatal (file
, "problem reading from");
1751 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1752 verbose
, snoop
, sasl
, saslmech
, user
,
1753 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1754 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1756 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1759 do_addresses (bccque
, talk
&& verbose
);
1764 sm_end (!(msgflags
& MINV
) || bccque
? OK
: DONE
);
1768 if (msgflags
& MINV
)
1769 printf (" -- %s Recipient Copies Posted --\n",
1770 bccque
? "Blind" : "Sighted");
1772 puts(" -- Recipient Copies Posted --");
1780 /* Address Verification */
1783 verify_all_addresses (int talk
, int eai
, char *envelope
, int oauth_flag
,
1787 struct mailname
*lp
;
1791 if (!whomsw
|| checksw
) {
1792 /* Not sending message body, so don't need to use 8BITMIME. */
1793 const int eightbit
= 0;
1795 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1796 verbose
, snoop
, sasl
, saslmech
, user
,
1797 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1798 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1799 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1803 if (talk
&& !whomsw
)
1804 puts(" -- Address Verification --");
1805 if (talk
&& localaddrs
.m_next
)
1806 puts(" -- Local Recipients --");
1807 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1808 do_an_address (lp
, talk
);
1810 if (talk
&& uuaddrs
.m_next
)
1811 puts(" -- UUCP Recipients --");
1812 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1813 do_an_address (lp
, talk
);
1815 if (talk
&& netaddrs
.m_next
)
1816 puts(" -- Network Recipients --");
1817 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1818 do_an_address (lp
, talk
);
1821 if (talk
&& !whomsw
)
1822 puts(" -- Address Verification Successful --");
1824 if (!whomsw
|| checksw
)
1825 sm_end (whomsw
? OK
: DONE
);
1833 do_an_address (struct mailname
*lp
, int talk
)
1839 switch (lp
->m_type
) {
1843 strncpy (addr
, mbox
, sizeof(addr
));
1847 mbox
= auxformat (lp
, 0);
1849 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1852 default: /* let SendMail decide if the host is bad */
1855 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1860 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1862 if (whomsw
&& !checksw
) {
1867 fputs(": ", stdout
);
1870 switch (retval
= sm_wadr (mbox
, host
,
1871 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1880 fprintf (stderr
, " %s: ", addr
);
1881 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1882 rp_string (retval
));
1888 fprintf (stderr
, " %s: ", addr
);
1889 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1897 do_text (char *file
, int fd
)
1902 lseek(fd
, 0, SEEK_SET
);
1904 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1905 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1906 fatal (NULL
, "problem writing text; %s\n", rp_string (retval
));
1910 fatal (file
, "problem reading from");
1912 switch (retval
= sm_wtend ()) {
1918 fatal (NULL
, "posting failed; %s", rp_string (retval
));
1922 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1936 (void) m_unlink (tmpfil
);
1937 if (msgflags
& MINV
)
1938 (void) m_unlink (bccfil
);
1940 if (!whomsw
|| checksw
)
1953 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1954 istat
= SIGNAL2 (SIGINT
, sigser
);
1955 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1956 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1966 SIGNAL (SIGHUP
, hstat
);
1967 SIGNAL (SIGINT
, istat
);
1968 SIGNAL (SIGQUIT
, qstat
);
1969 SIGNAL (SIGTERM
, tstat
);
1977 p_refile (char *file
)
1985 puts(" -- Filing Folder Copies --");
1986 for (i
= 0; i
< fccind
; i
++)
1987 fcc (file
, fccfold
[i
]);
1989 puts(" -- Folder Copies Filed --");
1994 * Call the `fileproc' to add the file to the folder.
1998 fcc (char *file
, char *folder
)
2003 char **arglist
, *program
;
2006 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
2013 fprintf (stderr
, " %sFcc %s: ",
2014 msgstate
== RESENT
? "Resent-" : "", folder
);
2015 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
2019 /* see if we need to add `+' */
2020 snprintf (fold
, sizeof(fold
), "%s%s",
2021 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
2023 /* now exec the fileproc */
2025 arglist
= argsplit(fileproc
, &program
, &argp
);
2026 arglist
[argp
++] = "-link";
2027 arglist
[argp
++] = "-file";
2028 arglist
[argp
++] = file
;
2029 arglist
[argp
++] = fold
;
2030 arglist
[argp
] = NULL
;
2031 execvp (program
, arglist
);
2035 if ((status
= pidwait (child_id
, OK
))) {
2037 fprintf (stderr
, " %sFcc %s: ",
2038 msgstate
== RESENT
? "Resent-" : "", folder
);
2039 pidstatus (status
, verbose
? stdout
: stderr
, fileproc
);
2054 fatal (char *what
, char *fmt
, ...)
2061 (void) m_unlink (tmpfil
);
2062 if (msgflags
& MINV
)
2063 (void) m_unlink (bccfil
);
2065 if (!whomsw
|| checksw
)
2070 advertise (what
, NULL
, fmt
, ap
);