]>
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/context_foil.h"
10 #include "sbr/readconfig.h"
11 #include "sbr/ambigsw.h"
12 #include "sbr/pidstatus.h"
13 #include "sbr/print_version.h"
14 #include "sbr/print_help.h"
15 #include "sbr/arglist.h"
16 #include "sbr/error.h"
18 #include "h/signals.h"
19 #include "h/addrsbr.h"
20 #include "h/aliasbr.h"
21 #include "h/dropsbr.h"
27 #include "sbr/m_mktemp.h"
28 #include "sbr/message_id.h"
30 #ifdef HAVE_SYS_TIME_H
31 # include <sys/time.h>
35 #include "mts/smtp/smtp.h"
38 # define SASLminc(a) (a)
39 #else /* CYRUS_SASL */
40 # define SASLminc(a) 0
41 #endif /* CYRUS_SASL */
44 # define TLSminc(a) (a)
45 #else /* TLS_SUPPORT */
47 #endif /* TLS_SUPPORT */
50 # define OAUTHminc(a) (a)
51 #else /* OAUTH_SUPPORT */
52 # define OAUTHminc(a) 0
53 #endif /* OAUTH_SUPPORT */
55 #define FCCS 10 /* max number of fccs allowed */
57 /* In the following array of structures, the numeric second field of the
58 structures (minchars) is apparently used like this:
60 -# : Switch can be abbreviated to # characters; switch hidden in -help.
61 0 : Switch can't be abbreviated; switch shown in -help.
62 # : Switch can be abbreviated to # characters; switch shown in -help. */
64 #define POST_SWITCHES \
65 X("alias aliasfile", 0, ALIASW) \
66 X("check", -5, CHKSW) /* interface from whom */ \
67 X("nocheck", -7, NCHKSW) /* interface from whom */ \
68 X("debug", -5, DEBUGSW) \
69 X("dist", -4, DISTSW) /* interface from dist */ \
70 X("filter filterfile", 0, FILTSW) \
71 X("nofilter", 0, NFILTSW) \
72 X("format", 0, FRMTSW) \
73 X("noformat", 0, NFRMTSW) \
74 X("library directory", -7, LIBSW) /* interface from send, whom */ \
75 X("mime", 0, MIMESW) \
76 X("nomime", 0, NMIMESW) \
77 X("msgid", 0, MSGDSW) \
78 X("nomsgid", 0, NMSGDSW) \
79 X("verbose", 0, VERBSW) \
80 X("noverbose", 0, NVERBSW) \
81 X("watch", 0, WATCSW) \
82 X("nowatch", 0, NWATCSW) \
83 X("whom", -4, WHOMSW) /* interface from whom */ \
84 X("width columns", 0, WIDTHSW) \
85 X("version", 0, VERSIONSW) \
86 X("help", 0, HELPSW) \
87 X("dashstuffing", -12, BITSTUFFSW) /* should we dashstuff BCC messages? */ \
88 X("nodashstuffing", -14, NBITSTUFFSW) \
89 X("idanno number", -6, ANNOSW) /* interface from send */ \
90 X("client host", -6, CLIESW) \
91 X("server host", 6, SERVSW) /* specify alternate SMTP server */ \
92 X("snoop", -5, SNOOPSW) /* snoop the SMTP transaction */ \
93 X("partno", -6, PARTSW) \
94 X("sasl", SASLminc(4), SASLSW) \
95 X("nosasl", SASLminc(6), NOSASLSW) \
96 X("saslmech", SASLminc(5), SASLMECHSW) \
97 X("user", SASLminc(-4), USERSW) \
98 X("port server submission port name/number", 4, PORTSW) \
99 X("tls", TLSminc(-3), TLSSW) \
100 X("initialtls", TLSminc(-10), INITTLSSW) \
101 X("notls", TLSminc(-5), NTLSSW) \
102 X("certverify", TLSminc(-10), CERTVERSW) \
103 X("nocertverify", TLSminc(-12), NOCERTVERSW) \
104 X("fileproc", -4, FILEPROCSW) \
105 X("mhlproc", -3, MHLPROCSW) \
106 X("sendmail program", 0, MTSSM) \
107 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
108 X("credentials legacy|file:filename", 0, CREDENTIALSSW) \
109 X("messageid localname|random", 2, MESSAGEIDSW) \
110 X("authservice auth-service-name", OAUTHminc(-11), AUTHSERVICESW) \
111 X("oauthcredfile credential-file", OAUTHminc(-7), OAUTHCREDFILESW) \
112 X("oauthclientid client-id", OAUTHminc(-12), OAUTHCLIDSW) \
113 X("oauthclientsecret client-secret", OAUTHminc(-12), OAUTHCLSECSW) \
114 X("oauthauthendpoint authentication-endpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
115 X("oauthredirect redirect-uri", OAUTHminc(-6), OAUTHREDIRSW) \
116 X("oauthtokenendpoint token-endpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
117 X("oauthscope scope", OAUTHminc(-6), OAUTHSCOPESW) \
119 #define X(sw, minchars, id) id,
120 DEFINE_SWITCH_ENUM(POST
);
123 #define X(sw, minchars, id) { sw, minchars, id },
124 DEFINE_SWITCH_ARRAY(POST
, switches
);
129 * Mapping between command-line switches and profile entries, communicated
130 * from 'send'. We use a service name of 'post' internally.
134 const char *profname
;
137 } oauthswitches
[] = {
138 { "oauth-%s-credential-file", OAUTHCREDFILESW
, NULL
},
139 { "oauth-%s-client_id", OAUTHCLIDSW
, NULL
},
140 { "oauth-%s-client_secret", OAUTHCLSECSW
, NULL
},
141 { "oauth-%s-auth_endpoint", OAUTHAUTHENDSW
, NULL
},
142 { "oauth-%s-redirect_uri", OAUTHREDIRSW
, NULL
},
143 { "oauth-%s-token_endpoint", OAUTHTOKENDSW
, NULL
},
144 { "oauth-%s-scope", OAUTHSCOPESW
, NULL
},
155 * flags for headers->flags
157 #define HNOP 0x0000 /* just used to keep .set around */
158 #define HBAD 0x0001 /* bad header - don't let it through */
159 #define HADR 0x0002 /* header has an address field */
160 #define HSUB 0x0004 /* Subject: header */
161 #define HTRY 0x0008 /* try to send to addrs on header */
162 #define HBCC 0x0010 /* don't output this header, unless MTS_SENDMAIL_PIPE */
163 #define HMNG 0x0020 /* munge this header */
164 #define HNGR 0x0040 /* no groups allowed in this header */
165 #define HFCC 0x0080 /* FCC: type header */
166 #define HNIL 0x0100 /* okay for this header not to have addrs */
167 #define HIGN 0x0200 /* ignore this header */
168 #define HDCC 0x0400 /* another undocumented feature */
169 #define HONE 0x0800 /* Only (zero or) one address allowed */
170 #define HEFM 0x1000 /* Envelope-From: header */
171 #define HMIM 0x2000 /* MIME-Version: header */
172 #define HCTE 0x4000 /* Content-Transfer-Encoding: header */
175 * flags for headers->set
177 #define MFRM 0x0001 /* we've seen a From: */
178 #define MDAT 0x0002 /* we've seen a Date: */
179 #define MRFM 0x0004 /* we've seen a Resent-From: */
180 #define MVIS 0x0008 /* we've seen sighted addrs */
181 #define MINV 0x0010 /* we've seen blind addrs */
182 #define MSND 0x0020 /* we've seen a Sender: */
183 #define MRSN 0x0040 /* We've seen a Resent-Sender: */
184 #define MEFM 0x0080 /* We've seen Envelope-From: */
185 #define MMIM 0x0100 /* We've seen Mime-Version: */
187 static struct headers NHeaders
[] = {
188 { "Return-Path", HBAD
, 0 },
189 { "Received", HBAD
, 0 },
190 { "Reply-To", HADR
|HNGR
, 0 },
191 { "From", HADR
|HNGR
, MFRM
},
192 { "Sender", HADR
|HNGR
|HONE
, MSND
},
194 { "Subject", HSUB
, 0 },
195 { "To", HADR
|HTRY
, MVIS
},
196 { "cc", HADR
|HTRY
, MVIS
},
197 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, MINV
},
198 { "Dcc", HADR
|HTRY
|HDCC
|HNIL
, MVIS
}, /* sorta cc & bcc combined */
199 { "Message-ID", HBAD
, 0 },
201 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
202 { "MIME-Version", HMIM
, MMIM
},
203 { "Content-Transfer-Encoding", HCTE
, 0 },
207 static struct headers RHeaders
[] = {
208 { "Resent-Reply-To", HADR
|HNGR
, 0 },
209 { "Resent-From", HADR
|HNGR
, MRFM
},
210 { "Resent-Sender", HADR
|HNGR
, MRSN
},
211 { "Resent-Date", HBAD
, 0 },
212 { "Resent-Subject", HSUB
, 0 },
213 { "Resent-To", HADR
|HTRY
, MVIS
},
214 { "Resent-cc", HADR
|HTRY
, MVIS
},
215 { "Resent-Bcc", HADR
|HTRY
|HBCC
, MINV
},
216 { "Resent-Message-ID", HBAD
, 0 },
217 { "Resent-Fcc", HFCC
, 0 },
218 { "Reply-To", HADR
, 0 },
219 { "From", HADR
|HNGR
, MFRM
},
220 { "Sender", HADR
|HNGR
, MSND
},
221 { "Date", HNOP
, MDAT
},
222 { "To", HADR
|HNIL
, 0 },
223 { "cc", HADR
|HNIL
, 0 },
224 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, 0 },
226 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
227 { "MIME-Version", HMIM
, MMIM
},
228 { "Content-Transfer-Encoding", HCTE
, 0 },
232 static short fccind
= 0; /* index into fccfold[] */
233 static short outputlinelen
= OUTPUTLINELEN
;
235 static int pfd
= NOTOK
; /* fd to write annotation list to */
236 static bool recipients
; /* how many people will get a copy */
237 static int unkadr
= 0; /* how many of those were unknown */
238 static int badadr
= 0; /* number of bad addrs */
239 static bool badmsg
; /* message has bad semantics */
240 static bool verbose
; /* spell it out */
241 static bool format
= true; /* format addresses */
242 static bool mime
; /* use MIME-style encapsulations for Bcc */
243 static bool msgid
; /* add msgid */
244 static bool debug
; /* debugging post */
245 static bool watch
; /* watch the delivery process */
246 static bool whomsw
; /* we are whom not post */
247 static bool checksw
; /* whom -check */
248 static int linepos
=0; /* putadr()'s position on the line */
249 static int nameoutput
=0; /* putadr() has output header name */
250 static bool sasl
; /* Use SASL auth for SMTP */
251 static char *saslmech
=NULL
; /* Force use of particular SASL mech */
252 static char *user
=NULL
; /* Authenticate as this user */
253 static char *port
="submission"; /* Name of server port for SMTP submission */
254 static int tlsflag
=0; /* Flags to control TLS settings */
255 static int fromcount
=0; /* Count of addresses on From: header */
256 static bool seensender
; /* Have we seen a Sender: header? */
258 static unsigned msgflags
= 0; /* what we've seen */
262 static int msgstate
= NORMAL
;
264 static time_t tclock
= 0; /* the time we started (more or less) */
266 static SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
268 static char tmpfil
[BUFSIZ
];
269 static char bccfil
[BUFSIZ
];
271 static char from
[BUFSIZ
]; /* my network address */
272 static char sender
[BUFSIZ
]; /* my Sender: header */
273 static char efrom
[BUFSIZ
]; /* my Envelope-From: header */
274 static char fullfrom
[BUFSIZ
]; /* full contents of From header */
275 static char *filter
= NULL
; /* the filter for BCC'ing */
276 static char *subject
= NULL
; /* the subject field for BCC'ing */
277 static char *fccfold
[FCCS
]; /* foldernames for FCC'ing */
278 enum encoding
{ UNKNOWN
= 0, BINARY
= 1, SEVENBIT
= 7, EIGHTBIT
= 8 };
279 static enum encoding cte
= UNKNOWN
;
281 static struct headers
*hdrtab
; /* table for the message we're doing */
283 static struct mailname localaddrs
; /* local addrs */
284 static struct mailname netaddrs
; /* network addrs */
285 static struct mailname uuaddrs
; /* uucp addrs */
286 static struct mailname tmpaddrs
; /* temporary queue */
289 static char *clientsw
= NULL
;
290 static char *serversw
= NULL
;
292 static char prefix
[] = "----- =_aaaaaaaaaa";
294 static char *partno
= NULL
;
299 static void putfmt (char *, char *, int *, FILE *);
300 static void start_headers (void);
301 static void finish_headers (FILE *);
302 static int get_header (char *, struct headers
*) PURE
;
303 static int putadr (char *, char *, struct mailname
*, FILE *, unsigned int,
304 char *, unsigned int);
305 static void putgrp (char *, char *, FILE *, unsigned int);
306 static int insert (struct mailname
*);
307 static void pl (void);
308 static void anno (void);
309 static int annoaux (struct mailname
*);
310 static void insert_fcc (struct headers
*, char *);
311 static void make_bcc_file (int);
312 static void verify_all_addresses (int, int, char *, int, char *);
313 static void chkadr (void) PURE
;
314 static void sigon (void);
315 static void sigoff (void);
316 static void p_refile (char *);
317 static void fcc (char *, char *);
318 static void fatal (char *, char *, ...) CHECK_PRINTF(2, 3);
319 static void post (char *, int, int, int, char *, int, char *);
320 static void do_text (char *file
, int fd
);
321 static void do_an_address (struct mailname
*, int);
322 static void do_addresses (int, int);
323 static int find_prefix (void);
327 main (int argc
, char **argv
)
329 int state
, compnum
, dashstuff
= 0, swnum
;
330 bool oauth_flag
= false;
332 bool noverify
= false;
333 int eai
= 0; /* use Email Address Internationalization (EAI) (SMTPUTF8) */
334 char *cp
, *msg
= NULL
, **argp
, **arguments
, *envelope
;
335 char buf
[NMH_BUFSIZ
], name
[NAMESZ
], *auth_svc
= NULL
;
337 m_getfld_state_t gstate
;
339 if (nmh_init(argv
[0], false, false)) { return 1; }
342 arguments
= getarguments (invo_name
, argc
, argv
, 0);
345 while ((cp
= *argp
++)) {
347 switch ((swnum
= smatch (++cp
, switches
))) {
349 ambigsw (cp
, switches
);
352 die("-%s unknown", cp
);
355 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
356 print_help (buf
, switches
, 0);
359 print_version(invo_name
);
363 if (!(cp
= *argp
++) || *cp
== '-')
364 die("missing argument to %s", argp
[-2]);
365 /* create a minimal context */
366 if (context_foil (cp
) == -1)
371 if (!(cp
= *argp
++) || *cp
== '-')
372 die("missing argument to %s", argp
[-2]);
373 if ((state
= alias (cp
)) != AK_OK
)
374 die("aliasing error in %s - %s",
375 cp
, akerror (state
));
394 if (!(filter
= *argp
++) || *filter
== '-')
395 die("missing argument to %s", argp
[-2]);
450 if (!(cp
= *argp
++) || *cp
== '-')
451 die("missing argument to %s", argp
[-2]);
452 if ((outputlinelen
= atoi (cp
)) < 10)
453 die("impossible width %d", outputlinelen
);
457 if (!(cp
= *argp
++) || *cp
== '-')
458 die("missing argument to %s", argp
[-2]);
459 if ((pfd
= atoi (cp
)) <= 2)
460 die("bad argument %s %s", argp
[-2], cp
);
464 if (!(clientsw
= *argp
++) || *clientsw
== '-')
465 die("missing argument to %s", argp
[-2]);
468 if (!(serversw
= *argp
++) || *serversw
== '-')
469 die("missing argument to %s", argp
[-2]);
476 if (!(partno
= *argp
++) || *partno
== '-')
477 die("missing argument to %s", argp
[-2]);
489 if (!(saslmech
= *argp
++) || *saslmech
== '-')
490 die("missing argument to %s", argp
[-2]);
494 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
495 die("missing argument to %s", argp
[-2]);
499 case OAUTHCREDFILESW
:
509 if (!(cp
= *argp
++) || *cp
== '-')
510 die("missing argument to %s", argp
[-2]);
512 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
513 if (oauthswitches
[i
].switchnum
== swnum
) {
514 oauthswitches
[i
].value
= cp
;
519 if (oauthswitches
[i
].profname
== NULL
)
520 die("internal error: cannot map switch %s "
521 "to profile entry", argp
[-2]);
528 if (!(user
= *argp
++) || *user
== '-')
529 die("missing argument to %s", argp
[-2]);
533 if (!(port
= *argp
++) || *port
== '-')
534 die("missing argument to %s", argp
[-2]);
558 if (!(cp
= *argp
++) || *cp
== '-')
559 die("missing argument to %s", argp
[-2]);
564 if (!(cp
= *argp
++) || *cp
== '-')
565 die("missing argument to %s", argp
[-2]);
570 if (!(cp
= *argp
++) || *cp
== '-')
571 die("missing argument to %s", argp
[-2]);
576 if (!(cp
= *argp
++) || *cp
== '-')
577 die("missing argument to %s", argp
[-2]);
578 save_mts_method (cp
);
581 case CREDENTIALSSW
: {
582 if (!(cp
= *argp
++) || *cp
== '-')
583 die("missing argument to %s", argp
[-2]);
584 add_profile_entry ("credentials", cp
);
589 if (!(cp
= *argp
++) || *cp
== '-')
590 die("missing argument to %s", argp
[-2]);
591 if (save_message_id_style (cp
) != 0)
592 die("unsupported messageid \"%s\"", cp
);
597 die("only one message at a time!");
604 die("usage: %s [switches] file", invo_name
);
606 if (outputlinelen
< 10)
607 die("impossible width %d", outputlinelen
);
609 if ((in
= fopen (msg
, "r")) == NULL
)
610 adios (msg
, "unable to open");
618 if ((out
= fopen ("/dev/null", "w")) == NULL
)
619 adios ("/dev/null", "unable to open");
621 char *cp
= m_mktemp2(NULL
, invo_name
, NULL
, &out
);
623 die("unable to create temporary file in %s",
626 strncpy(tmpfil
, cp
, sizeof(tmpfil
));
630 hdrtab
= msgstate
== NORMAL
? NHeaders
: RHeaders
;
632 gstate
= m_getfld_state_init(in
);
633 for (compnum
= 1;;) {
634 int bufsz
= sizeof buf
;
635 switch (state
= m_getfld2(&gstate
, name
, buf
, &bufsz
)) {
639 cp
= mh_xstrdup(buf
);
640 while (state
== FLDPLUS
) {
642 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
645 putfmt (name
, cp
, &eai
, out
);
650 finish_headers (out
);
653 fprintf (out
, "\n%s", buf
);
654 while (state
== BODY
) {
656 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
662 finish_headers (out
);
667 die("message format error in component #%d", compnum
);
670 die("getfld() returned %d", state
);
674 m_getfld_state_destroy (&gstate
);
687 * Here's how we decide which address to use as the envelope-from
690 * - If we were given an Envelope-From header, use that.
691 * - If we were given a Sender: address, use that.
692 * - Otherwise, use the address on the From: line
695 if (msgflags
& MEFM
) {
697 } else if (seensender
) {
706 * The user didn't specify any of the tls switches. Try to
707 * help them by implying -initialtls if they're using port 465
708 * (smtps, until IANA revoked that registration in 1998).
710 tls
= ! strcmp (port
, "465") || ! strcasecmp (port
, "smtps")
713 #else /* ! TLS_SUPPORT */
715 #endif /* ! TLS_SUPPORT */
719 tlsflag
= S_STARTTLS
;
726 tlsflag
|= S_NOVERIFY
;
729 * If we were given any oauth flags, store the appropriate profile
730 * entries and make sure an authservice was given (we have to do this
731 * here because we aren't guaranteed the authservice will be given on
732 * the command line before the other OAuth flags are given).
739 if (auth_svc
== NULL
) {
740 die("No authentication service given with -authservice");
743 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
744 if (oauthswitches
[i
].value
!= NULL
) {
745 snprintf(sbuf
, sizeof(sbuf
),
746 oauthswitches
[i
].profname
, auth_svc
);
747 sbuf
[sizeof(sbuf
) - 1] = '\0';
748 add_profile_entry(sbuf
, oauthswitches
[i
].value
);
753 /* If we are doing a "whom" check */
755 /* This won't work with MTS_SENDMAIL_PIPE. */
756 verify_all_addresses (1, eai
, envelope
, oauth_flag
, auth_svc
);
760 if (msgflags
& MINV
) {
761 make_bcc_file (dashstuff
);
762 if (msgflags
& MVIS
) {
763 if (sm_mts
!= MTS_SENDMAIL_PIPE
) {
764 /* It would be nice to have support to call
765 verify_all_addresses with MTS_SENDMAIL_PIPE, but
766 that might require running sendmail as root. Note
767 that spost didn't verify addresses. */
768 verify_all_addresses (verbose
, eai
, envelope
, oauth_flag
,
771 post (tmpfil
, 0, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
773 post (bccfil
, 1, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
774 (void) m_unlink (bccfil
);
776 post (tmpfil
, 0, isatty (1), eai
, envelope
, oauth_flag
, auth_svc
);
780 (void) m_unlink (tmpfil
);
784 printf ("Partial Message #%s Processed\n", partno
);
786 puts("Message Processed");
799 putfmt (char *name
, char *str
, int *eai
, FILE *out
)
805 char namep
[BUFSIZ
], error
[BUFSIZ
];
806 char *savehdr
= NULL
;
807 unsigned int savehdrlen
= 0;
808 struct mailname
*mp
= NULL
, *np
= NULL
;
811 while (*str
== ' ' || *str
== '\t')
814 if (msgstate
== NORMAL
&& uprf (name
, "resent")) {
815 inform("illegal header line -- %s:", name
);
821 /* Check each header field value to see if it has any 8-bit characters.
822 If it does, enable EAI support. */
823 if (contains8bit(str
, NULL
)) {
825 puts("EAI/SMTPUTF8 enabled");
828 /* Enable SMTPUTF8. */
831 /* Enable passing of utf-8 setting to getname()/getadrx(). */
836 if ((i
= get_header (name
, hdrtab
)) == NOTOK
) {
837 if (strncasecmp (name
, "nmh-", 4)) {
838 fprintf (out
, "%s: %s", name
, str
);
840 /* Filter out all Nmh-* headers, because Norm asked. They
841 should never have reached this point. Warn about any
842 that are non-empty. */
843 if (strcmp (str
, "\n")) {
844 trim_suffix_c(str
, '\n');
846 inform("ignoring header line -- %s: %s", name
, str
);
855 if (hdr
->flags
& HIGN
) {
858 if (hdr
->flags
& HBAD
) {
859 inform("illegal header line -- %s:", name
);
863 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
865 if (hdr
->flags
& HSUB
)
866 subject
= subject
? add (str
, add ("\t", subject
)) : mh_xstrdup(str
);
867 if (hdr
->flags
& HFCC
) {
868 if ((cp
= strrchr(str
, '\n')))
870 for (pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
872 insert_fcc (hdr
, pp
);
874 insert_fcc (hdr
, pp
);
877 if (hdr
->flags
& HCTE
) {
878 if (strncasecmp (str
, "7bit", 4) == 0) {
880 } else if (strncasecmp (str
, "8bit", 4) == 0) {
882 } else if (strncasecmp (str
, "binary", 6) == 0) {
886 if (!(hdr
->flags
& HADR
)) {
887 fprintf (out
, "%s: %s", name
, str
);
892 * If this is a From:/Resent-From: header, save the full thing for
893 * later in case we need it for use when constructing a Bcc draft message.
894 * Because we want to capture the results of alias expansion, save
895 * the output from putadr().
898 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
901 savehdrlen
= sizeof(fullfrom
);
904 tmpaddrs
.m_next
= NULL
;
906 for (count
= 0; (cp
= getname (str
)); count
++) {
907 if ((mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
911 tmpaddrs
.m_next
= mp
;
915 admonish(cp
, "%s", error
);
916 if (hdr
->flags
& HTRY
)
924 if (hdr
->flags
& HNIL
)
925 fprintf (out
, "%s: %s", name
, str
);
928 * Sender (or Resent-Sender) can have only one address
930 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
931 : (hdr
->set
& MSND
)) {
932 inform("%s: field requires one address", name
);
936 inform("%s: field requires at least one address", name
);
943 if (count
> 1 && (hdr
->flags
& HONE
)) {
944 inform("%s: field only permits one address", name
);
949 nameoutput
= linepos
= 0;
950 snprintf (namep
, sizeof(namep
), "%s%s",
951 (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
953 for (grp
= false, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
954 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
955 /* The address doesn't include a host, so it might be an alias. */
956 pp
= akvalue (mp
->m_mbox
); /* do mh alias substitution */
957 qp
= akvisible () ? mp
->m_mbox
: "";
960 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
961 while ((cp
= getname (pp
))) {
962 if (!(mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
963 admonish(cp
, "%s", error
);
969 * If it's a From: or Resent-From: header, save the address
970 * for later possible use (as the envelope address for SMTP)
973 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
974 : (hdr
->set
& MFRM
)) {
975 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
976 from
[sizeof(from
) - 1] = '\0';
981 * Also save the Sender: or Resent-Sender: header as well
984 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
985 : (hdr
->set
& MSND
)) {
986 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
987 sender
[sizeof(sender
) - 1] = '\0';
992 * ALSO ... save Envelope-From
995 if (hdr
->set
& MEFM
) {
996 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
997 efrom
[sizeof(efrom
) - 1] = '\0';
1000 if (hdr
->flags
& HBCC
)
1003 mp
->m_ingrp
= np
->m_ingrp
;
1004 else if (mp
->m_gname
)
1005 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1007 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1008 /* Catch this before sendmail chokes with:
1009 "553 List:; syntax illegal for recipient
1011 If we wanted to, we could expand out blind
1012 aliases and put them in Bcc:, but then
1013 they'd have the Blind-Carbon-Copy
1015 die( "blind lists not compatible with"
1021 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
, savehdr
,
1023 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1032 /* Address includes a host, so no alias substitution is needed. */
1035 * If it's a From: or Resent-From header, save the address
1036 * for later possible use (as the envelope address for SMTP)
1039 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
1040 : (hdr
->set
& MFRM
)) {
1041 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
1046 * Also save the Sender: header as well
1049 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
1050 : (hdr
->set
& MSND
)) {
1051 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
1052 sender
[sizeof(sender
) - 1] = '\0';
1057 * ALSO ... save Envelope-From
1060 if (hdr
->set
& MEFM
) {
1061 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1062 efrom
[sizeof(efrom
) - 1] = '\0';
1065 if (hdr
->flags
& HBCC
)
1068 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1071 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
, savehdr
, savehdrlen
);
1075 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1082 * If it was a From header, strip off any trailing newlines from
1083 * the alias-expanded From line.
1086 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
1087 while (*fullfrom
&& fullfrom
[strlen(fullfrom
) - 1] == '\n') {
1088 fullfrom
[strlen(fullfrom
) - 1] = '\0';
1092 if (grp
&& (hdr
->flags
& HNGR
)) {
1093 inform("%s: field does not allow groups", name
);
1103 start_headers (void)
1108 * Probably not necessary, but just in case ...
1119 * Now that we've outputted the header fields in the draft
1120 * message, we will now output any remaining header fields
1121 * that we need to add/create.
1125 finish_headers (FILE *out
)
1129 if (!(msgflags
& MFRM
)) {
1131 * A From: header is now required in the draft.
1133 inform("message has no From: header");
1134 inform("See default components files for examples");
1139 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1140 inform("A Sender: or Envelope-From: header is required "
1141 "with multiple\nFrom: addresses");
1149 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1151 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1153 * If we have multiple From: addresses, make sure we have an
1154 * Sender: header. If we don't have one, then generate one
1155 * from Envelope-From: (which in this case, cannot be blank)
1158 if (fromcount
> 1 && !seensender
) {
1159 if (efrom
[0] == '\0') {
1160 inform("Envelope-From cannot be blank when there "
1161 "is multiple From: addresses\nand no Sender: "
1165 fprintf (out
, "Sender: %s\n", efrom
);
1169 if (!(msgflags
& MVIS
))
1170 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
1174 if (!(msgflags
& MDAT
)) {
1175 inform("message has no Date: header");
1178 if (!(msgflags
& MFRM
)) {
1179 inform("message has no From: header");
1182 if (!(msgflags
& MRFM
)) {
1183 inform("message has no Resent-From: header");
1184 inform("See default components files for examples");
1188 if (fromcount
> 1 && (!seensender
&& !(msgflags
& MEFM
))) {
1189 inform("A Resent-Sender: or Envelope-From: header is "
1190 "required with multiple\nResent-From: addresses");
1198 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
1200 fprintf (out
, "Resent-Message-ID: %s\n",
1201 message_id (tclock
, 0));
1203 * If we have multiple Resent-From: addresses, make sure we have an
1204 * Resent-Sender: header. If we don't have one, then generate one
1205 * from Envelope-From (which in this case, cannot be blank)
1208 if (fromcount
> 1 && !seensender
) {
1209 if (efrom
[0] == '\0') {
1210 inform("Envelope-From cannot be blank when there "
1211 "is multiple Resent-From: addresses and no "
1212 "Resent-Sender: header");
1215 fprintf (out
, "Resent-Sender: %s\n", efrom
);
1219 if (!(msgflags
& MVIS
))
1220 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
1225 die("re-format message and try again");
1227 die("no addressees");
1232 get_header (char *header
, struct headers
*table
)
1236 header
= FENDNULL(header
);
1237 for (h
= table
; h
->value
; h
++)
1238 if (!strcasecmp(FENDNULL(h
->value
), header
))
1246 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
,
1247 unsigned int flags
, char *savehdr
, unsigned int savehdrsize
)
1250 bool saveappend
= false;
1253 char buffer
[BUFSIZ
];
1255 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
1257 if (sm_mts
!= MTS_SENDMAIL_PIPE
&&
1258 ((flags
& (HBCC
| HDCC
| HEFM
)) || mp
->m_ingrp
))
1262 fprintf (out
, "%s: ", name
);
1263 linepos
+= (nameoutput
= strlen (name
) + 2);
1267 shlen
= strlen(savehdr
);
1271 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
1272 mp
->m_pers
= mh_xstrdup(aka
);
1275 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
1278 cp
= adrformat (mp
);
1285 if (linepos
!= nameoutput
) {
1286 if (len
+ linepos
+ 2 > outputlinelen
) {
1287 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
1289 if (shlen
+ 2 + nameoutput
+ len
>= savehdrsize
) {
1292 snprintf(savehdr
+ shlen
, savehdrsize
- shlen
, ",\n%*s",
1300 if (shlen
+ 2 + len
>= savehdrsize
) {
1303 strncat(savehdr
, ", ", savehdrsize
- shlen
);
1311 if (saveappend
&& shlen
+ len
< savehdrsize
)
1312 strncat(savehdr
, cp
, savehdrsize
- shlen
+ len
);
1316 return flags
& HTRY
;
1321 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
1326 if (sm_mts
!= MTS_SENDMAIL_PIPE
&& (flags
& HBCC
))
1330 fprintf (out
, "%s: ", name
);
1331 linepos
+= (nameoutput
= strlen (name
) + 2);
1334 cp
= concat (group
, ";", NULL
);
1337 if (linepos
> nameoutput
) {
1338 if (len
+ linepos
+ 2 > outputlinelen
) {
1339 fprintf (out
, ",\n%*s", nameoutput
, "");
1340 linepos
= nameoutput
;
1354 insert (struct mailname
*np
)
1356 struct mailname
*mp
;
1358 if (np
->m_mbox
== NULL
)
1361 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1362 : np
->m_type
== UUCPHOST
? &uuaddrs
1366 if (!strcasecmp (FENDNULL(np
->m_host
),
1367 FENDNULL(mp
->m_next
->m_host
)) &&
1368 !strcasecmp (FENDNULL(np
->m_mbox
),
1369 FENDNULL(mp
->m_next
->m_mbox
)) &&
1370 np
->m_bcc
== mp
->m_next
->m_bcc
)
1383 struct mailname
*mp
;
1385 fputs("-------\n\t-- Addresses --\nlocal:\t", stdout
);
1386 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1387 printf ("%s%s%s", mp
->m_mbox
,
1388 mp
->m_bcc
? "[BCC]" : "",
1389 mp
->m_next
? ",\n\t" : "");
1391 fputs("\nnet:\t", stdout
);
1392 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1393 printf ("%s%s@%s%s%s", FENDNULL(mp
->m_path
),
1394 mp
->m_mbox
, mp
->m_host
,
1395 mp
->m_bcc
? "[BCC]" : "",
1396 mp
->m_next
? ",\n\t" : "");
1398 fputs("\nuucp:\t", stdout
);
1399 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1400 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1401 mp
->m_bcc
? "[BCC]" : "",
1402 mp
->m_next
? ",\n\t" : "");
1404 fputs("\n\t-- Folder Copies --\nfcc:\t", stdout
);
1405 for (i
= 0; i
< fccind
; i
++)
1406 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1414 struct mailname
*mp
;
1416 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1417 if (annoaux (mp
) == NOTOK
)
1420 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1421 if (annoaux (mp
) == NOTOK
)
1424 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1425 if (annoaux (mp
) == NOTOK
)
1435 annoaux (struct mailname
*mp
)
1438 char buffer
[BUFSIZ
];
1440 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1441 i
= strlen (buffer
);
1443 return write(pfd
, buffer
, i
) == i
? OK
: NOTOK
;
1448 insert_fcc (struct headers
*hdr
, char *pp
)
1452 for (cp
= pp
; isspace ((unsigned char) *cp
); cp
++)
1454 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace ((unsigned char) *pp
); pp
--)
1462 die("too many %ss", hdr
->value
);
1463 fccfold
[fccind
++] = mh_xstrdup(cp
);
1471 make_bcc_file (int dashstuff
)
1477 char *tfile
= NULL
, *program
;
1479 if ((tfile
= m_mktemp2(NULL
, "bccs", NULL
, &out
)) == NULL
) {
1480 die("unable to create temporary file in %s", get_temp_dir());
1482 strncpy (bccfil
, tfile
, sizeof(bccfil
));
1484 fprintf (out
, "From: %s\n", fullfrom
);
1485 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1487 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1489 fprintf (out
, "Subject: %s", subject
);
1490 fprintf (out
, "BCC:\n");
1493 * Use MIME encapsulation for Bcc messages
1499 * Check if any lines in the message clash with the
1500 * prefix for the MIME multipart separator. If there
1501 * is a clash, increment one of the letters in the
1502 * prefix and check again.
1504 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1505 die("lost prefix start");
1506 while (find_prefix () == NOTOK
) {
1509 else if (*++cp
== 0)
1510 die("can't find a unique delimiter string");
1515 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1516 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1517 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1519 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1525 * Do mhl filtering of Bcc messages instead
1526 * of MIME encapsulation.
1528 if (filter
!= NULL
) {
1532 adios ("fork", "unable to");
1535 dup2 (fileno (out
), 1);
1537 vec
= argsplit(mhlproc
, &program
, &i
);
1538 vec
[i
++] = "-forward";
1543 /* was the flag -[no]dashstuffing specified? */
1545 vec
[i
++] = "-dashstuffing";
1546 else if (dashstuff
< 0)
1547 vec
[i
++] = "-nodashstuffing";
1550 execvp (program
, vec
);
1551 fprintf (stderr
, "unable to exec ");
1556 pidXwait (child_id
, mhlproc
);
1560 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1561 adios (tmpfil
, "unable to re-open");
1564 * If using MIME encapsulation, or if the -nodashstuffing
1565 * flag was given, then just copy message. Else do
1566 * RFC934 quoting (dashstuffing).
1568 if (mime
|| dashstuff
< 0)
1569 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1571 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1575 fseek (out
, 0L, SEEK_END
);
1577 fprintf (out
, "\n--%s--\n", prefix
);
1579 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1585 * Scan message to check if any lines clash with
1586 * the prefix of the MIME multipart separator.
1593 char buffer
[BUFSIZ
];
1596 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1597 adios (tmpfil
, "unable to re-open");
1599 while (fgets (buffer
, sizeof buffer
, in
))
1600 if (buffer
[0] == '-' && buffer
[1] == '-') {
1603 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1604 if (!isspace ((unsigned char) *cp
))
1607 if (strcmp (buffer
+ 2, prefix
) == 0) {
1621 if (badadr
&& unkadr
)
1622 fatal (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1623 badadr
, PLURALS(badadr
), unkadr
, PLURALS(badadr
));
1625 fatal (NULL
, "%d address%s unparsable", badadr
, PLURALS(badadr
));
1627 fatal (NULL
, "%d addressee%s undeliverable", unkadr
, PLURALS(unkadr
));
1632 do_addresses (int bccque
, int talk
)
1636 struct mailname
*lp
;
1639 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1640 if (lp
->m_bcc
? bccque
: !bccque
) {
1642 puts(" -- Local Recipients --");
1643 do_an_address (lp
, talk
);
1648 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1649 if (lp
->m_bcc
? bccque
: !bccque
) {
1651 puts(" -- UUCP Recipients --");
1652 do_an_address (lp
, talk
);
1657 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1658 if (lp
->m_bcc
? bccque
: !bccque
) {
1660 puts(" -- Network Recipients --");
1661 do_an_address (lp
, talk
);
1667 if (rp_isbad (retval
= sm_waend ()))
1668 fatal (NULL
, "problem ending addresses; %s", rp_string (retval
));
1673 * MTS-SPECIFIC INTERACTION
1678 * SENDMAIL/SMTP routines
1682 post (char *file
, int bccque
, int talk
, int eai
, char *envelope
,
1683 int oauth_flag
, char *auth_svc
)
1689 if (msgflags
& MINV
)
1690 printf (" -- Posting for %s Recipients --\n",
1691 bccque
? "Blind" : "Sighted");
1693 puts(" -- Posting for All Recipients --");
1698 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1699 char **argp
, *program
;
1705 adios ("fork", "unable to");
1708 if (freopen( file
, "r", stdin
) == NULL
) {
1709 adios (file
, "can't reopen for sendmail");
1712 argp
= argsplit(sendmail
, &program
, &argc
);
1713 argp
[argc
++] = "-t"; /* read msg for recipients */
1714 argp
[argc
++] = "-i"; /* don't stop on "." */
1716 argp
[argc
++] = "-bv";
1718 argp
[argc
++] = "-v";
1721 execv (program
, argp
);
1722 adios (sendmail
, "can't exec");
1725 pidXwait (child_id
, NULL
);
1729 const int fd
= open (file
, O_RDONLY
);
1733 fatal (file
, "unable to re-open");
1736 if (msgflags
& MMIM
&& cte
!= UNKNOWN
) {
1737 /* MIME message with C-T-E header. (BINARYMIME isn't
1738 supported, use 8BITMIME instead for binary.) */
1739 eightbit
= cte
!= SEVENBIT
;
1741 if (scan_input (fd
, &eightbit
) == NOTOK
) {
1743 fatal (file
, "problem reading from");
1747 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1748 verbose
, snoop
, sasl
, saslmech
, user
,
1749 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1750 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1752 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1755 do_addresses (bccque
, talk
&& verbose
);
1760 sm_end (!(msgflags
& MINV
) || bccque
? OK
: DONE
);
1764 if (msgflags
& MINV
)
1765 printf (" -- %s Recipient Copies Posted --\n",
1766 bccque
? "Blind" : "Sighted");
1768 puts(" -- Recipient Copies Posted --");
1776 /* Address Verification */
1779 verify_all_addresses (int talk
, int eai
, char *envelope
, int oauth_flag
,
1783 struct mailname
*lp
;
1787 if (!whomsw
|| checksw
) {
1788 /* Not sending message body, so don't need to use 8BITMIME. */
1789 const int eightbit
= 0;
1791 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1792 verbose
, snoop
, sasl
, saslmech
, user
,
1793 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1794 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1795 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1799 if (talk
&& !whomsw
)
1800 puts(" -- Address Verification --");
1801 if (talk
&& localaddrs
.m_next
)
1802 puts(" -- Local Recipients --");
1803 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1804 do_an_address (lp
, talk
);
1806 if (talk
&& uuaddrs
.m_next
)
1807 puts(" -- UUCP Recipients --");
1808 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1809 do_an_address (lp
, talk
);
1811 if (talk
&& netaddrs
.m_next
)
1812 puts(" -- Network Recipients --");
1813 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1814 do_an_address (lp
, talk
);
1817 if (talk
&& !whomsw
)
1818 puts(" -- Address Verification Successful --");
1820 if (!whomsw
|| checksw
)
1821 sm_end (whomsw
? OK
: DONE
);
1829 do_an_address (struct mailname
*lp
, int talk
)
1835 switch (lp
->m_type
) {
1839 strncpy (addr
, mbox
, sizeof(addr
));
1843 mbox
= auxformat (lp
, 0);
1845 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1848 default: /* let SendMail decide if the host is bad */
1851 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1856 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1858 if (whomsw
&& !checksw
) {
1863 fputs(": ", stdout
);
1866 switch (retval
= sm_wadr (mbox
, host
,
1867 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1876 fprintf (stderr
, " %s: ", addr
);
1877 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1878 rp_string (retval
));
1884 fprintf (stderr
, " %s: ", addr
);
1885 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1893 do_text (char *file
, int fd
)
1898 lseek(fd
, 0, SEEK_SET
);
1900 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1901 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1902 fatal (NULL
, "problem writing text; %s\n", rp_string (retval
));
1906 fatal (file
, "problem reading from");
1908 switch (retval
= sm_wtend ()) {
1914 fatal (NULL
, "posting failed; %s", rp_string (retval
));
1918 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1932 (void) m_unlink (tmpfil
);
1933 if (msgflags
& MINV
)
1934 (void) m_unlink (bccfil
);
1936 if (!whomsw
|| checksw
)
1949 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1950 istat
= SIGNAL2 (SIGINT
, sigser
);
1951 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1952 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1962 SIGNAL (SIGHUP
, hstat
);
1963 SIGNAL (SIGINT
, istat
);
1964 SIGNAL (SIGQUIT
, qstat
);
1965 SIGNAL (SIGTERM
, tstat
);
1973 p_refile (char *file
)
1981 puts(" -- Filing Folder Copies --");
1982 for (i
= 0; i
< fccind
; i
++)
1983 fcc (file
, fccfold
[i
]);
1985 puts(" -- Folder Copies Filed --");
1990 * Call the `fileproc' to add the file to the folder.
1994 fcc (char *file
, char *folder
)
1999 char **arglist
, *program
;
2002 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
2009 fprintf (stderr
, " %sFcc %s: ",
2010 msgstate
== RESENT
? "Resent-" : "", folder
);
2011 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
2015 /* see if we need to add `+' */
2016 snprintf (fold
, sizeof(fold
), "%s%s",
2017 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
2019 /* now exec the fileproc */
2021 arglist
= argsplit(fileproc
, &program
, &argp
);
2022 arglist
[argp
++] = "-link";
2023 arglist
[argp
++] = "-file";
2024 arglist
[argp
++] = file
;
2025 arglist
[argp
++] = fold
;
2026 arglist
[argp
] = NULL
;
2027 execvp (program
, arglist
);
2031 if ((status
= pidwait (child_id
, OK
))) {
2033 fprintf (stderr
, " %sFcc %s: ",
2034 msgstate
== RESENT
? "Resent-" : "", folder
);
2035 pidstatus (status
, verbose
? stdout
: stderr
, fileproc
);
2050 fatal (char *what
, char *fmt
, ...)
2057 (void) m_unlink (tmpfil
);
2058 if (msgflags
& MINV
)
2059 (void) m_unlink (bccfil
);
2061 if (!whomsw
|| checksw
)
2066 advertise (what
, NULL
, fmt
, ap
);