]>
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 <h/signals.h>
11 #include <h/addrsbr.h>
12 #include <h/aliasbr.h>
13 #include <h/dropsbr.h>
19 #include "sbr/m_mktemp.h"
20 #include "sbr/message_id.h"
22 #ifdef HAVE_SYS_TIME_H
23 # include <sys/time.h>
27 #include <mts/smtp/smtp.h>
30 # define SASLminc(a) (a)
31 #else /* CYRUS_SASL */
32 # define SASLminc(a) 0
33 #endif /* CYRUS_SASL */
36 # define TLSminc(a) (a)
37 #else /* TLS_SUPPORT */
39 #endif /* TLS_SUPPORT */
42 # define OAUTHminc(a) (a)
43 #else /* OAUTH_SUPPORT */
44 # define OAUTHminc(a) 0
45 #endif /* OAUTH_SUPPORT */
47 #define FCCS 10 /* max number of fccs allowed */
49 /* In the following array of structures, the numeric second field of the
50 structures (minchars) is apparently used like this:
52 -# : Switch can be abbreviated to # characters; switch hidden in -help.
53 0 : Switch can't be abbreviated; switch shown in -help.
54 # : Switch can be abbreviated to # characters; switch shown in -help. */
56 #define POST_SWITCHES \
57 X("alias aliasfile", 0, ALIASW) \
58 X("check", -5, CHKSW) /* interface from whom */ \
59 X("nocheck", -7, NCHKSW) /* interface from whom */ \
60 X("debug", -5, DEBUGSW) \
61 X("dist", -4, DISTSW) /* interface from dist */ \
62 X("filter filterfile", 0, FILTSW) \
63 X("nofilter", 0, NFILTSW) \
64 X("format", 0, FRMTSW) \
65 X("noformat", 0, NFRMTSW) \
66 X("library directory", -7, LIBSW) /* interface from send, whom */ \
67 X("mime", 0, MIMESW) \
68 X("nomime", 0, NMIMESW) \
69 X("msgid", 0, MSGDSW) \
70 X("nomsgid", 0, NMSGDSW) \
71 X("verbose", 0, VERBSW) \
72 X("noverbose", 0, NVERBSW) \
73 X("watch", 0, WATCSW) \
74 X("nowatch", 0, NWATCSW) \
75 X("whom", -4, WHOMSW) /* interface from whom */ \
76 X("width columns", 0, WIDTHSW) \
77 X("version", 0, VERSIONSW) \
78 X("help", 0, HELPSW) \
79 X("dashstuffing", -12, BITSTUFFSW) /* should we dashstuff BCC messages? */ \
80 X("nodashstuffing", -14, NBITSTUFFSW) \
81 X("idanno number", -6, ANNOSW) /* interface from send */ \
82 X("client host", -6, CLIESW) \
83 X("server host", 6, SERVSW) /* specify alternate SMTP server */ \
84 X("snoop", -5, SNOOPSW) /* snoop the SMTP transaction */ \
85 X("partno", -6, PARTSW) \
86 X("sasl", SASLminc(4), SASLSW) \
87 X("nosasl", SASLminc(6), NOSASLSW) \
88 X("saslmech", SASLminc(5), SASLMECHSW) \
89 X("user", SASLminc(-4), USERSW) \
90 X("port server submission port name/number", 4, PORTSW) \
91 X("tls", TLSminc(-3), TLSSW) \
92 X("initialtls", TLSminc(-10), INITTLSSW) \
93 X("notls", TLSminc(-5), NTLSSW) \
94 X("certverify", TLSminc(-10), CERTVERSW) \
95 X("nocertverify", TLSminc(-12), NOCERTVERSW) \
96 X("fileproc", -4, FILEPROCSW) \
97 X("mhlproc", -3, MHLPROCSW) \
98 X("sendmail program", 0, MTSSM) \
99 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
100 X("credentials legacy|file:filename", 0, CREDENTIALSSW) \
101 X("messageid localname|random", 2, MESSAGEIDSW) \
102 X("authservice auth-service-name", OAUTHminc(-11), AUTHSERVICESW) \
103 X("oauthcredfile credential-file", OAUTHminc(-7), OAUTHCREDFILESW) \
104 X("oauthclientid client-id", OAUTHminc(-12), OAUTHCLIDSW) \
105 X("oauthclientsecret client-secret", OAUTHminc(-12), OAUTHCLSECSW) \
106 X("oauthauthendpoint authentication-endpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
107 X("oauthredirect redirect-uri", OAUTHminc(-6), OAUTHREDIRSW) \
108 X("oauthtokenendpoint token-endpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
109 X("oauthscope scope", OAUTHminc(-6), OAUTHSCOPESW) \
111 #define X(sw, minchars, id) id,
112 DEFINE_SWITCH_ENUM(POST
);
115 #define X(sw, minchars, id) { sw, minchars, id },
116 DEFINE_SWITCH_ARRAY(POST
, switches
);
121 * Mapping between command-line switches and profile entries, communicated
122 * from 'send'. We use a service name of 'post' internally.
126 const char *profname
;
129 } oauthswitches
[] = {
130 { "oauth-%s-credential-file", OAUTHCREDFILESW
, NULL
},
131 { "oauth-%s-client_id", OAUTHCLIDSW
, NULL
},
132 { "oauth-%s-client_secret", OAUTHCLSECSW
, NULL
},
133 { "oauth-%s-auth_endpoint", OAUTHAUTHENDSW
, NULL
},
134 { "oauth-%s-redirect_uri", OAUTHREDIRSW
, NULL
},
135 { "oauth-%s-token_endpoint", OAUTHTOKENDSW
, NULL
},
136 { "oauth-%s-scope", OAUTHSCOPESW
, NULL
},
147 * flags for headers->flags
149 #define HNOP 0x0000 /* just used to keep .set around */
150 #define HBAD 0x0001 /* bad header - don't let it through */
151 #define HADR 0x0002 /* header has an address field */
152 #define HSUB 0x0004 /* Subject: header */
153 #define HTRY 0x0008 /* try to send to addrs on header */
154 #define HBCC 0x0010 /* don't output this header, unless MTS_SENDMAIL_PIPE */
155 #define HMNG 0x0020 /* munge this header */
156 #define HNGR 0x0040 /* no groups allowed in this header */
157 #define HFCC 0x0080 /* FCC: type header */
158 #define HNIL 0x0100 /* okay for this header not to have addrs */
159 #define HIGN 0x0200 /* ignore this header */
160 #define HDCC 0x0400 /* another undocumented feature */
161 #define HONE 0x0800 /* Only (zero or) one address allowed */
162 #define HEFM 0x1000 /* Envelope-From: header */
163 #define HMIM 0x2000 /* MIME-Version: header */
164 #define HCTE 0x4000 /* Content-Transfer-Encoding: header */
167 * flags for headers->set
169 #define MFRM 0x0001 /* we've seen a From: */
170 #define MDAT 0x0002 /* we've seen a Date: */
171 #define MRFM 0x0004 /* we've seen a Resent-From: */
172 #define MVIS 0x0008 /* we've seen sighted addrs */
173 #define MINV 0x0010 /* we've seen blind addrs */
174 #define MSND 0x0020 /* we've seen a Sender: */
175 #define MRSN 0x0040 /* We've seen a Resent-Sender: */
176 #define MEFM 0x0080 /* We've seen Envelope-From: */
177 #define MMIM 0x0100 /* We've seen Mime-Version: */
179 static struct headers NHeaders
[] = {
180 { "Return-Path", HBAD
, 0 },
181 { "Received", HBAD
, 0 },
182 { "Reply-To", HADR
|HNGR
, 0 },
183 { "From", HADR
|HNGR
, MFRM
},
184 { "Sender", HADR
|HNGR
|HONE
, MSND
},
186 { "Subject", HSUB
, 0 },
187 { "To", HADR
|HTRY
, MVIS
},
188 { "cc", HADR
|HTRY
, MVIS
},
189 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, MINV
},
190 { "Dcc", HADR
|HTRY
|HDCC
|HNIL
, MVIS
}, /* sorta cc & bcc combined */
191 { "Message-ID", HBAD
, 0 },
193 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
194 { "MIME-Version", HMIM
, MMIM
},
195 { "Content-Transfer-Encoding", HCTE
, 0 },
199 static struct headers RHeaders
[] = {
200 { "Resent-Reply-To", HADR
|HNGR
, 0 },
201 { "Resent-From", HADR
|HNGR
, MRFM
},
202 { "Resent-Sender", HADR
|HNGR
, MRSN
},
203 { "Resent-Date", HBAD
, 0 },
204 { "Resent-Subject", HSUB
, 0 },
205 { "Resent-To", HADR
|HTRY
, MVIS
},
206 { "Resent-cc", HADR
|HTRY
, MVIS
},
207 { "Resent-Bcc", HADR
|HTRY
|HBCC
, MINV
},
208 { "Resent-Message-ID", HBAD
, 0 },
209 { "Resent-Fcc", HFCC
, 0 },
210 { "Reply-To", HADR
, 0 },
211 { "From", HADR
|HNGR
, MFRM
},
212 { "Sender", HADR
|HNGR
, MSND
},
213 { "Date", HNOP
, MDAT
},
214 { "To", HADR
|HNIL
, 0 },
215 { "cc", HADR
|HNIL
, 0 },
216 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, 0 },
218 { "Envelope-From", HADR
|HONE
|HEFM
, MEFM
},
219 { "MIME-Version", HMIM
, MMIM
},
220 { "Content-Transfer-Encoding", HCTE
, 0 },
224 static short fccind
= 0; /* index into fccfold[] */
225 static short outputlinelen
= OUTPUTLINELEN
;
227 static int pfd
= NOTOK
; /* fd to write annotation list to */
228 static int recipients
= 0; /* how many people will get a copy */
229 static int unkadr
= 0; /* how many of those were unknown */
230 static int badadr
= 0; /* number of bad addrs */
231 static int badmsg
= 0; /* message has bad semantics */
232 static int verbose
= 0; /* spell it out */
233 static int format
= 1; /* format addresses */
234 static int mime
= 0; /* use MIME-style encapsulations for Bcc */
235 static int msgid
= 0; /* add msgid */
236 static int debug
= 0; /* debugging post */
237 static int watch
= 0; /* watch the delivery process */
238 static int whomsw
= 0; /* we are whom not post */
239 static int checksw
= 0; /* whom -check */
240 static int linepos
=0; /* putadr()'s position on the line */
241 static int nameoutput
=0; /* putadr() has output header name */
242 static int sasl
=0; /* Use SASL auth for SMTP */
243 static char *saslmech
=NULL
; /* Force use of particular SASL mech */
244 static char *user
=NULL
; /* Authenticate as this user */
245 static char *port
="submission"; /* Name of server port for SMTP submission */
246 static int tlsflag
=0; /* Flags to control TLS settings */
247 static int fromcount
=0; /* Count of addresses on From: header */
248 static int seensender
=0; /* Have we seen a Sender: header? */
250 static unsigned msgflags
= 0; /* what we've seen */
254 static int msgstate
= NORMAL
;
256 static time_t tclock
= 0; /* the time we started (more or less) */
258 static SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
260 static char tmpfil
[BUFSIZ
];
261 static char bccfil
[BUFSIZ
];
263 static char from
[BUFSIZ
]; /* my network address */
264 static char sender
[BUFSIZ
]; /* my Sender: header */
265 static char efrom
[BUFSIZ
]; /* my Envelope-From: header */
266 static char fullfrom
[BUFSIZ
]; /* full contents of From header */
267 static char *filter
= NULL
; /* the filter for BCC'ing */
268 static char *subject
= NULL
; /* the subject field for BCC'ing */
269 static char *fccfold
[FCCS
]; /* foldernames for FCC'ing */
270 enum encoding
{ UNKNOWN
= 0, BINARY
= 1, SEVENBIT
= 7, EIGHTBIT
= 8 };
271 static enum encoding cte
= UNKNOWN
;
273 static struct headers
*hdrtab
; /* table for the message we're doing */
275 static struct mailname localaddrs
; /* local addrs */
276 static struct mailname netaddrs
; /* network addrs */
277 static struct mailname uuaddrs
; /* uucp addrs */
278 static struct mailname tmpaddrs
; /* temporary queue */
280 static int snoop
= 0;
281 static char *clientsw
= NULL
;
282 static char *serversw
= NULL
;
284 static char prefix
[] = "----- =_aaaaaaaaaa";
286 static char *partno
= NULL
;
291 static void putfmt (char *, char *, int *, FILE *);
292 static void start_headers (void);
293 static void finish_headers (FILE *);
294 static int get_header (char *, struct headers
*) PURE
;
295 static int putadr (char *, char *, struct mailname
*, FILE *, unsigned int,
296 char *, unsigned int);
297 static void putgrp (char *, char *, FILE *, unsigned int);
298 static int insert (struct mailname
*);
299 static void pl (void);
300 static void anno (void);
301 static int annoaux (struct mailname
*);
302 static void insert_fcc (struct headers
*, char *);
303 static void make_bcc_file (int);
304 static void verify_all_addresses (int, int, char *, int, char *);
305 static void chkadr (void) PURE
;
306 static void sigon (void);
307 static void sigoff (void);
308 static void p_refile (char *);
309 static void fcc (char *, char *);
310 static void fatal (char *, char *, ...) CHECK_PRINTF(2, 3);
311 static void post (char *, int, int, int, char *, int, char *);
312 static void do_text (char *file
, int fd
);
313 static void do_an_address (struct mailname
*, int);
314 static void do_addresses (int, int);
315 static int find_prefix (void);
319 main (int argc
, char **argv
)
321 int state
, compnum
, dashstuff
= 0, swnum
, oauth_flag
= 0, tls
= -1;
323 int eai
= 0; /* use Email Address Internationalization (EAI) (SMTPUTF8) */
324 char *cp
, *msg
= NULL
, **argp
, **arguments
, *envelope
;
325 char buf
[NMH_BUFSIZ
], name
[NAMESZ
], *auth_svc
= NULL
;
327 m_getfld_state_t gstate
;
329 if (nmh_init(argv
[0], 0 /* use context_foil() */)) { return 1; }
332 arguments
= getarguments (invo_name
, argc
, argv
, 0);
335 while ((cp
= *argp
++)) {
337 switch ((swnum
= smatch (++cp
, switches
))) {
339 ambigsw (cp
, switches
);
342 adios (NULL
, "-%s unknown", cp
);
345 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
346 print_help (buf
, switches
, 0);
349 print_version(invo_name
);
353 if (!(cp
= *argp
++) || *cp
== '-')
354 adios (NULL
, "missing argument to %s", argp
[-2]);
355 /* create a minimal context */
356 if (context_foil (cp
) == -1)
361 if (!(cp
= *argp
++) || *cp
== '-')
362 adios (NULL
, "missing argument to %s", argp
[-2]);
363 if ((state
= alias (cp
)) != AK_OK
)
364 adios (NULL
, "aliasing error in %s - %s",
365 cp
, akerror (state
));
384 if (!(filter
= *argp
++) || *filter
== '-')
385 adios (NULL
, "missing argument to %s", argp
[-2]);
440 if (!(cp
= *argp
++) || *cp
== '-')
441 adios (NULL
, "missing argument to %s", argp
[-2]);
442 if ((outputlinelen
= atoi (cp
)) < 10)
443 adios (NULL
, "impossible width %d", outputlinelen
);
447 if (!(cp
= *argp
++) || *cp
== '-')
448 adios (NULL
, "missing argument to %s", argp
[-2]);
449 if ((pfd
= atoi (cp
)) <= 2)
450 adios (NULL
, "bad argument %s %s", argp
[-2], cp
);
454 if (!(clientsw
= *argp
++) || *clientsw
== '-')
455 adios (NULL
, "missing argument to %s", argp
[-2]);
458 if (!(serversw
= *argp
++) || *serversw
== '-')
459 adios (NULL
, "missing argument to %s", argp
[-2]);
466 if (!(partno
= *argp
++) || *partno
== '-')
467 adios (NULL
, "missing argument to %s", argp
[-2]);
479 if (!(saslmech
= *argp
++) || *saslmech
== '-')
480 adios (NULL
, "missing argument to %s", argp
[-2]);
484 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
485 adios (NULL
, "missing argument to %s", argp
[-2]);
489 case OAUTHCREDFILESW
:
499 if (!(cp
= *argp
++) || *cp
== '-')
500 adios (NULL
, "missing argument to %s", argp
[-2]);
502 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
503 if (oauthswitches
[i
].switchnum
== swnum
) {
504 oauthswitches
[i
].value
= cp
;
509 if (oauthswitches
[i
].profname
== NULL
)
510 adios (NULL
, "internal error: cannot map switch %s "
511 "to profile entry", argp
[-2]);
518 if (!(user
= *argp
++) || *user
== '-')
519 adios (NULL
, "missing argument to %s", argp
[-2]);
523 if (!(port
= *argp
++) || *port
== '-')
524 adios (NULL
, "missing argument to %s", argp
[-2]);
548 if (!(cp
= *argp
++) || *cp
== '-')
549 adios (NULL
, "missing argument to %s", argp
[-2]);
554 if (!(cp
= *argp
++) || *cp
== '-')
555 adios (NULL
, "missing argument to %s", argp
[-2]);
560 if (!(cp
= *argp
++) || *cp
== '-')
561 adios (NULL
, "missing argument to %s", argp
[-2]);
566 if (!(cp
= *argp
++) || *cp
== '-')
567 adios (NULL
, "missing argument to %s", argp
[-2]);
568 save_mts_method (cp
);
571 case CREDENTIALSSW
: {
572 if (!(cp
= *argp
++) || *cp
== '-')
573 adios (NULL
, "missing argument to %s", argp
[-2]);
574 add_profile_entry ("credentials", cp
);
579 if (!(cp
= *argp
++) || *cp
== '-')
580 adios (NULL
, "missing argument to %s", argp
[-2]);
581 if (save_message_id_style (cp
) != 0)
582 adios (NULL
, "unsupported messageid \"%s\"", cp
);
587 adios (NULL
, "only one message at a time!");
594 adios (NULL
, "usage: %s [switches] file", invo_name
);
596 if (outputlinelen
< 10)
597 adios (NULL
, "impossible width %d", outputlinelen
);
599 if ((in
= fopen (msg
, "r")) == NULL
)
600 adios (msg
, "unable to open");
608 if ((out
= fopen ("/dev/null", "w")) == NULL
)
609 adios ("/dev/null", "unable to open");
611 char *cp
= m_mktemp2(NULL
, invo_name
, NULL
, &out
);
613 adios(NULL
, "unable to create temporary file in %s",
616 strncpy(tmpfil
, cp
, sizeof(tmpfil
));
620 hdrtab
= msgstate
== NORMAL
? NHeaders
: RHeaders
;
622 gstate
= m_getfld_state_init(in
);
623 for (compnum
= 1;;) {
624 int bufsz
= sizeof buf
;
625 switch (state
= m_getfld2(&gstate
, name
, buf
, &bufsz
)) {
629 cp
= mh_xstrdup(buf
);
630 while (state
== FLDPLUS
) {
632 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
635 putfmt (name
, cp
, &eai
, out
);
640 finish_headers (out
);
643 fprintf (out
, "\n%s", buf
);
644 while (state
== BODY
) {
646 state
= m_getfld2(&gstate
, name
, buf
, &bufsz
);
652 finish_headers (out
);
657 adios (NULL
, "message format error in component #%d", compnum
);
660 adios (NULL
, "getfld() returned %d", state
);
664 m_getfld_state_destroy (&gstate
);
677 * Here's how we decide which address to use as the envelope-from
680 * - If we were given an Envelope-From header, use that.
681 * - If we were given a Sender: address, use that.
682 * - Otherwise, use the address on the From: line
685 if (msgflags
& MEFM
) {
687 } else if (seensender
) {
696 * The user didn't specify any of the tls switches. Try to
697 * help them by implying -initialtls if they're using port 465
698 * (smtps, until IANA revoked that registration in 1998).
700 tls
= ! strcmp (port
, "465") || ! strcasecmp (port
, "smtps")
703 #else /* ! TLS_SUPPORT */
705 #endif /* ! TLS_SUPPORT */
709 tlsflag
= S_STARTTLS
;
716 tlsflag
|= S_NOVERIFY
;
719 * If we were given any oauth flags, store the appropriate profile
720 * entries and make sure an authservice was given (we have to do this
721 * here because we aren't guaranteed the authservice will be given on
722 * the command line before the other OAuth flags are given).
729 if (auth_svc
== NULL
) {
730 adios(NULL
, "No authentication service given with -authservice");
733 for (i
= 0; oauthswitches
[i
].profname
!= NULL
; i
++) {
734 if (oauthswitches
[i
].value
!= NULL
) {
735 snprintf(sbuf
, sizeof(sbuf
),
736 oauthswitches
[i
].profname
, auth_svc
);
737 sbuf
[sizeof(sbuf
) - 1] = '\0';
738 add_profile_entry(sbuf
, oauthswitches
[i
].value
);
743 /* If we are doing a "whom" check */
745 /* This won't work with MTS_SENDMAIL_PIPE. */
746 verify_all_addresses (1, eai
, envelope
, oauth_flag
, auth_svc
);
750 if (msgflags
& MINV
) {
751 make_bcc_file (dashstuff
);
752 if (msgflags
& MVIS
) {
753 if (sm_mts
!= MTS_SENDMAIL_PIPE
) {
754 /* It would be nice to have support to call
755 verify_all_addresses with MTS_SENDMAIL_PIPE, but
756 that might require running sendmail as root. Note
757 that spost didn't verify addresses. */
758 verify_all_addresses (verbose
, eai
, envelope
, oauth_flag
,
761 post (tmpfil
, 0, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
763 post (bccfil
, 1, verbose
, eai
, envelope
, oauth_flag
, auth_svc
);
764 (void) m_unlink (bccfil
);
766 post (tmpfil
, 0, isatty (1), eai
, envelope
, oauth_flag
, auth_svc
);
770 (void) m_unlink (tmpfil
);
774 printf ("Partial Message #%s Processed\n", partno
);
776 puts("Message Processed");
789 putfmt (char *name
, char *str
, int *eai
, FILE *out
)
791 int count
, grp
, i
, keep
;
793 char namep
[BUFSIZ
], error
[BUFSIZ
];
794 char *savehdr
= NULL
;
795 unsigned int savehdrlen
= 0;
796 struct mailname
*mp
= NULL
, *np
= NULL
;
799 while (*str
== ' ' || *str
== '\t')
802 if (msgstate
== NORMAL
&& uprf (name
, "resent")) {
803 inform("illegal header line -- %s:", name
);
809 /* Check each header field value to see if it has any 8-bit characters.
810 If it does, enable EAI support. */
811 if (contains8bit(str
, NULL
)) {
813 puts("EAI/SMTPUTF8 enabled");
816 /* Enable SMTPUTF8. */
819 /* Enable passing of utf-8 setting to getname()/getadrx(). */
824 if ((i
= get_header (name
, hdrtab
)) == NOTOK
) {
825 if (strncasecmp (name
, "nmh-", 4)) {
826 fprintf (out
, "%s: %s", name
, str
);
828 /* Filter out all Nmh-* headers, because Norm asked. They
829 should never have reached this point. Warn about any
830 that are non-empty. */
831 if (strcmp (str
, "\n")) {
832 trim_suffix_c(str
, '\n');
834 inform("ignoring header line -- %s: %s", name
, str
);
843 if (hdr
->flags
& HIGN
) {
846 if (hdr
->flags
& HBAD
) {
847 inform("illegal header line -- %s:", name
);
851 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
853 if (hdr
->flags
& HSUB
)
854 subject
= subject
? add (str
, add ("\t", subject
)) : mh_xstrdup(str
);
855 if (hdr
->flags
& HFCC
) {
856 if ((cp
= strrchr(str
, '\n')))
858 for (pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
860 insert_fcc (hdr
, pp
);
862 insert_fcc (hdr
, pp
);
865 if (hdr
->flags
& HCTE
) {
866 if (strncasecmp (str
, "7bit", 4) == 0) {
868 } else if (strncasecmp (str
, "8bit", 4) == 0) {
870 } else if (strncasecmp (str
, "binary", 6) == 0) {
874 if (!(hdr
->flags
& HADR
)) {
875 fprintf (out
, "%s: %s", name
, str
);
880 * If this is a From:/Resent-From: header, save the full thing for
881 * later in case we need it for use when constructing a Bcc draft message.
882 * Because we want to capture the results of alias expansion, save
883 * the output from putadr().
886 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
889 savehdrlen
= sizeof(fullfrom
);
892 tmpaddrs
.m_next
= NULL
;
894 for (count
= 0; (cp
= getname (str
)); count
++) {
895 if ((mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
899 tmpaddrs
.m_next
= mp
;
903 admonish(cp
, "%s", error
);
904 if (hdr
->flags
& HTRY
)
912 if (hdr
->flags
& HNIL
)
913 fprintf (out
, "%s: %s", name
, str
);
916 * Sender (or Resent-Sender) can have only one address
918 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
919 : (hdr
->set
& MSND
)) {
920 inform("%s: field requires one address", name
);
924 inform("%s: field requires at least one address", name
);
931 if (count
> 1 && (hdr
->flags
& HONE
)) {
932 inform("%s: field only permits one address", name
);
937 nameoutput
= linepos
= 0;
938 snprintf (namep
, sizeof(namep
), "%s%s",
939 (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
941 for (grp
= 0, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
942 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
943 /* The address doesn't include a host, so it might be an alias. */
944 pp
= akvalue (mp
->m_mbox
); /* do mh alias substitution */
945 qp
= akvisible () ? mp
->m_mbox
: "";
948 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
949 while ((cp
= getname (pp
))) {
950 if (!(mp
= getm (cp
, NULL
, 0, error
, sizeof(error
)))) {
951 admonish(cp
, "%s", error
);
957 * If it's a From: or Resent-From: header, save the address
958 * for later possible use (as the envelope address for SMTP)
961 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
962 : (hdr
->set
& MFRM
)) {
963 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
964 from
[sizeof(from
) - 1] = '\0';
969 * Also save the Sender: or Resent-Sender: header as well
972 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
973 : (hdr
->set
& MSND
)) {
974 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
975 sender
[sizeof(sender
) - 1] = '\0';
980 * ALSO ... save Envelope-From
983 if (hdr
->set
& MEFM
) {
984 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
985 efrom
[sizeof(efrom
) - 1] = '\0';
988 if (hdr
->flags
& HBCC
)
991 mp
->m_ingrp
= np
->m_ingrp
;
992 else if (mp
->m_gname
)
993 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
995 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
996 /* Catch this before sendmail chokes with:
997 "553 List:; syntax illegal for recipient
999 If we wanted to, we could expand out blind
1000 aliases and put them in Bcc:, but then
1001 they'd have the Blind-Carbon-Copy
1004 "blind lists not compatible with"
1010 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
, savehdr
,
1012 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1021 /* Address includes a host, so no alias substitution is needed. */
1024 * If it's a From: or Resent-From header, save the address
1025 * for later possible use (as the envelope address for SMTP)
1028 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
)
1029 : (hdr
->set
& MFRM
)) {
1030 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
1035 * Also save the Sender: header as well
1038 if ((msgstate
== RESENT
) ? (hdr
->set
& MRSN
)
1039 : (hdr
->set
& MSND
)) {
1040 strncpy(sender
, auxformat(mp
, 0), sizeof(sender
) - 1);
1041 sender
[sizeof(sender
) - 1] = '\0';
1046 * ALSO ... save Envelope-From
1049 if (hdr
->set
& MEFM
) {
1050 strncpy(efrom
, auxformat(mp
, 0), sizeof(efrom
) - 1);
1051 efrom
[sizeof(efrom
) - 1] = '\0';
1054 if (hdr
->flags
& HBCC
)
1057 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
1060 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
, savehdr
, savehdrlen
);
1064 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
1071 * If it was a From header, strip off any trailing newlines from
1072 * the alias-expanded From line.
1075 if ((msgstate
== RESENT
) ? (hdr
->set
& MRFM
) : (hdr
->set
& MFRM
)) {
1076 while (*fullfrom
&& fullfrom
[strlen(fullfrom
) - 1] == '\n') {
1077 fullfrom
[strlen(fullfrom
) - 1] = '\0';
1081 if (grp
> 0 && (hdr
->flags
& HNGR
)) {
1082 inform("%s: field does not allow groups", name
);
1092 start_headers (void)
1097 * Probably not necessary, but just in case ...
1108 * Now that we've outputted the header fields in the draft
1109 * message, we will now output any remaining header fields
1110 * that we need to add/create.
1114 finish_headers (FILE *out
)
1118 if (!(msgflags
& MFRM
)) {
1120 * A From: header is now required in the draft.
1122 inform("message has no From: header");
1123 inform("See default components files for examples");
1128 if (fromcount
> 1 && (seensender
== 0 && !(msgflags
& MEFM
))) {
1129 inform("A Sender: or Envelope-From: header is required "
1130 "with multiple\nFrom: addresses");
1138 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1140 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1142 * If we have multiple From: addresses, make sure we have an
1143 * Sender: header. If we don't have one, then generate one
1144 * from Envelope-From: (which in this case, cannot be blank)
1147 if (fromcount
> 1 && seensender
== 0) {
1148 if (efrom
[0] == '\0') {
1149 inform("Envelope-From cannot be blank when there "
1150 "is multiple From: addresses\nand no Sender: "
1154 fprintf (out
, "Sender: %s\n", efrom
);
1158 if (!(msgflags
& MVIS
))
1159 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
1163 if (!(msgflags
& MDAT
)) {
1164 inform("message has no Date: header");
1167 if (!(msgflags
& MFRM
)) {
1168 inform("message has no From: header");
1171 if (!(msgflags
& MRFM
)) {
1172 inform("message has no Resent-From: header");
1173 inform("See default components files for examples");
1177 if (fromcount
> 1 && (seensender
== 0 && !(msgflags
& MEFM
))) {
1178 inform("A Resent-Sender: or Envelope-From: header is "
1179 "required with multiple\nResent-From: addresses");
1187 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
1189 fprintf (out
, "Resent-Message-ID: %s\n",
1190 message_id (tclock
, 0));
1192 * If we have multiple Resent-From: addresses, make sure we have an
1193 * Resent-Sender: header. If we don't have one, then generate one
1194 * from Envelope-From (which in this case, cannot be blank)
1197 if (fromcount
> 1 && seensender
== 0) {
1198 if (efrom
[0] == '\0') {
1199 inform("Envelope-From cannot be blank when there "
1200 "is multiple Resent-From: addresses and no "
1201 "Resent-Sender: header");
1204 fprintf (out
, "Resent-Sender: %s\n", efrom
);
1208 if (!(msgflags
& MVIS
))
1209 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
1214 adios (NULL
, "re-format message and try again");
1216 adios (NULL
, "no addressees");
1221 get_header (char *header
, struct headers
*table
)
1225 header
= FENDNULL(header
);
1226 for (h
= table
; h
->value
; h
++)
1227 if (!strcasecmp(FENDNULL(h
->value
), header
))
1235 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
,
1236 unsigned int flags
, char *savehdr
, unsigned int savehdrsize
)
1238 int len
, saveappend
= 0;
1241 char buffer
[BUFSIZ
];
1243 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
1245 if (sm_mts
!= MTS_SENDMAIL_PIPE
&&
1246 ((flags
& (HBCC
| HDCC
| HEFM
)) || mp
->m_ingrp
))
1250 fprintf (out
, "%s: ", name
);
1251 linepos
+= (nameoutput
= strlen (name
) + 2);
1255 shlen
= strlen(savehdr
);
1259 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
1260 mp
->m_pers
= mh_xstrdup(aka
);
1263 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
1266 cp
= adrformat (mp
);
1273 if (linepos
!= nameoutput
) {
1274 if (len
+ linepos
+ 2 > outputlinelen
) {
1275 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
1277 if (shlen
+ 2 + nameoutput
+ len
>= savehdrsize
) {
1280 snprintf(savehdr
+ shlen
, savehdrsize
- shlen
, ",\n%*s",
1288 if (shlen
+ 2 + len
>= savehdrsize
) {
1291 strncat(savehdr
, ", ", savehdrsize
- shlen
);
1299 if (saveappend
&& shlen
+ len
< savehdrsize
)
1300 strncat(savehdr
, cp
, savehdrsize
- shlen
+ len
);
1304 return flags
& HTRY
;
1309 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
1314 if (sm_mts
!= MTS_SENDMAIL_PIPE
&& (flags
& HBCC
))
1318 fprintf (out
, "%s: ", name
);
1319 linepos
+= (nameoutput
= strlen (name
) + 2);
1322 cp
= concat (group
, ";", NULL
);
1325 if (linepos
> nameoutput
) {
1326 if (len
+ linepos
+ 2 > outputlinelen
) {
1327 fprintf (out
, ",\n%*s", nameoutput
, "");
1328 linepos
= nameoutput
;
1342 insert (struct mailname
*np
)
1344 struct mailname
*mp
;
1346 if (np
->m_mbox
== NULL
)
1349 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1350 : np
->m_type
== UUCPHOST
? &uuaddrs
1354 if (!strcasecmp (FENDNULL(np
->m_host
),
1355 FENDNULL(mp
->m_next
->m_host
)) &&
1356 !strcasecmp (FENDNULL(np
->m_mbox
),
1357 FENDNULL(mp
->m_next
->m_mbox
)) &&
1358 np
->m_bcc
== mp
->m_next
->m_bcc
)
1371 struct mailname
*mp
;
1373 printf ("-------\n\t-- Addresses --\nlocal:\t");
1374 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1375 printf ("%s%s%s", mp
->m_mbox
,
1376 mp
->m_bcc
? "[BCC]" : "",
1377 mp
->m_next
? ",\n\t" : "");
1379 printf ("\nnet:\t");
1380 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1381 printf ("%s%s@%s%s%s", FENDNULL(mp
->m_path
),
1382 mp
->m_mbox
, mp
->m_host
,
1383 mp
->m_bcc
? "[BCC]" : "",
1384 mp
->m_next
? ",\n\t" : "");
1386 printf ("\nuucp:\t");
1387 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1388 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1389 mp
->m_bcc
? "[BCC]" : "",
1390 mp
->m_next
? ",\n\t" : "");
1392 printf ("\n\t-- Folder Copies --\nfcc:\t");
1393 for (i
= 0; i
< fccind
; i
++)
1394 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1402 struct mailname
*mp
;
1404 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1405 if (annoaux (mp
) == NOTOK
)
1408 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1409 if (annoaux (mp
) == NOTOK
)
1412 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1413 if (annoaux (mp
) == NOTOK
)
1423 annoaux (struct mailname
*mp
)
1426 char buffer
[BUFSIZ
];
1428 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1429 i
= strlen (buffer
);
1431 return write(pfd
, buffer
, i
) == i
? OK
: NOTOK
;
1436 insert_fcc (struct headers
*hdr
, char *pp
)
1440 for (cp
= pp
; isspace ((unsigned char) *cp
); cp
++)
1442 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace ((unsigned char) *pp
); pp
--)
1450 adios (NULL
, "too many %ss", hdr
->value
);
1451 fccfold
[fccind
++] = mh_xstrdup(cp
);
1459 make_bcc_file (int dashstuff
)
1465 char *tfile
= NULL
, *program
;
1467 if ((tfile
= m_mktemp2(NULL
, "bccs", NULL
, &out
)) == NULL
) {
1468 adios(NULL
, "unable to create temporary file in %s", get_temp_dir());
1470 strncpy (bccfil
, tfile
, sizeof(bccfil
));
1472 fprintf (out
, "From: %s\n", fullfrom
);
1473 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1475 fprintf (out
, "Message-ID: %s\n", message_id (tclock
, 0));
1477 fprintf (out
, "Subject: %s", subject
);
1478 fprintf (out
, "BCC:\n");
1481 * Use MIME encapsulation for Bcc messages
1487 * Check if any lines in the message clash with the
1488 * prefix for the MIME multipart separator. If there
1489 * is a clash, increment one of the letters in the
1490 * prefix and check again.
1492 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1493 adios (NULL
, "lost prefix start");
1494 while (find_prefix () == NOTOK
) {
1497 else if (*++cp
== 0)
1498 adios (NULL
, "can't find a unique delimiter string");
1503 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1504 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1505 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1507 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1513 * Do mhl filtering of Bcc messages instead
1514 * of MIME encapsulation.
1516 if (filter
!= NULL
) {
1520 adios ("fork", "unable to");
1523 dup2 (fileno (out
), 1);
1525 vec
= argsplit(mhlproc
, &program
, &i
);
1526 vec
[i
++] = "-forward";
1531 /* was the flag -[no]dashstuffing specified? */
1533 vec
[i
++] = "-dashstuffing";
1534 else if (dashstuff
< 0)
1535 vec
[i
++] = "-nodashstuffing";
1538 execvp (program
, vec
);
1539 fprintf (stderr
, "unable to exec ");
1544 pidXwait (child_id
, mhlproc
);
1548 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1549 adios (tmpfil
, "unable to re-open");
1552 * If using MIME encapsulation, or if the -nodashstuffing
1553 * flag was given, then just copy message. Else do
1554 * RFC934 quoting (dashstuffing).
1556 if (mime
|| dashstuff
< 0)
1557 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1559 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1563 fseek (out
, 0L, SEEK_END
);
1565 fprintf (out
, "\n--%s--\n", prefix
);
1567 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1573 * Scan message to check if any lines clash with
1574 * the prefix of the MIME multipart separator.
1581 char buffer
[BUFSIZ
];
1584 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1585 adios (tmpfil
, "unable to re-open");
1587 while (fgets (buffer
, sizeof buffer
, in
))
1588 if (buffer
[0] == '-' && buffer
[1] == '-') {
1591 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1592 if (!isspace ((unsigned char) *cp
))
1595 if (strcmp (buffer
+ 2, prefix
) == 0) {
1609 if (badadr
&& unkadr
)
1610 fatal (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1611 badadr
, PLURALS(badadr
), unkadr
, PLURALS(badadr
));
1613 fatal (NULL
, "%d address%s unparsable", badadr
, PLURALS(badadr
));
1615 fatal (NULL
, "%d addressee%s undeliverable", unkadr
, PLURALS(unkadr
));
1620 do_addresses (int bccque
, int talk
)
1624 struct mailname
*lp
;
1627 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1628 if (lp
->m_bcc
? bccque
: !bccque
) {
1630 puts(" -- Local Recipients --");
1631 do_an_address (lp
, talk
);
1636 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1637 if (lp
->m_bcc
? bccque
: !bccque
) {
1639 puts(" -- UUCP Recipients --");
1640 do_an_address (lp
, talk
);
1645 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1646 if (lp
->m_bcc
? bccque
: !bccque
) {
1648 puts(" -- Network Recipients --");
1649 do_an_address (lp
, talk
);
1655 if (rp_isbad (retval
= sm_waend ()))
1656 fatal (NULL
, "problem ending addresses; %s", rp_string (retval
));
1661 * MTS-SPECIFIC INTERACTION
1666 * SENDMAIL/SMTP routines
1670 post (char *file
, int bccque
, int talk
, int eai
, char *envelope
,
1671 int oauth_flag
, char *auth_svc
)
1677 if (msgflags
& MINV
)
1678 printf (" -- Posting for %s Recipients --\n",
1679 bccque
? "Blind" : "Sighted");
1681 puts(" -- Posting for All Recipients --");
1686 if (sm_mts
== MTS_SENDMAIL_PIPE
) {
1687 char **argp
, *program
;
1693 adios ("fork", "unable to");
1696 if (freopen( file
, "r", stdin
) == NULL
) {
1697 adios (file
, "can't reopen for sendmail");
1700 argp
= argsplit(sendmail
, &program
, &argc
);
1701 argp
[argc
++] = "-t"; /* read msg for recipients */
1702 argp
[argc
++] = "-i"; /* don't stop on "." */
1704 argp
[argc
++] = "-bv";
1706 argp
[argc
++] = "-v";
1709 execv (program
, argp
);
1710 adios (sendmail
, "can't exec");
1713 pidXwait (child_id
, NULL
);
1717 const int fd
= open (file
, O_RDONLY
);
1721 fatal (file
, "unable to re-open");
1724 if (msgflags
& MMIM
&& cte
!= UNKNOWN
) {
1725 /* MIME message with C-T-E header. (BINARYMIME isn't
1726 supported, use 8BITMIME instead for binary.) */
1727 eightbit
= cte
!= SEVENBIT
;
1729 if (scan_input (fd
, &eightbit
) == NOTOK
) {
1731 fatal (file
, "problem reading from");
1735 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1736 verbose
, snoop
, sasl
, saslmech
, user
,
1737 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1738 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1740 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1743 do_addresses (bccque
, talk
&& verbose
);
1748 sm_end (!(msgflags
& MINV
) || bccque
? OK
: DONE
);
1752 if (msgflags
& MINV
)
1753 printf (" -- %s Recipient Copies Posted --\n",
1754 bccque
? "Blind" : "Sighted");
1756 puts(" -- Recipient Copies Posted --");
1764 /* Address Verification */
1767 verify_all_addresses (int talk
, int eai
, char *envelope
, int oauth_flag
,
1771 struct mailname
*lp
;
1775 if (!whomsw
|| checksw
) {
1776 /* Not sending message body, so don't need to use 8BITMIME. */
1777 const int eightbit
= 0;
1779 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, port
, watch
,
1780 verbose
, snoop
, sasl
, saslmech
, user
,
1781 oauth_flag
? auth_svc
: NULL
, tlsflag
))
1782 || rp_isbad (retval
= sm_winit (envelope
, eai
, eightbit
))) {
1783 fatal (NULL
, "problem initializing server; %s", rp_string (retval
));
1787 if (talk
&& !whomsw
)
1788 puts(" -- Address Verification --");
1789 if (talk
&& localaddrs
.m_next
)
1790 puts(" -- Local Recipients --");
1791 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1792 do_an_address (lp
, talk
);
1794 if (talk
&& uuaddrs
.m_next
)
1795 puts(" -- UUCP Recipients --");
1796 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1797 do_an_address (lp
, talk
);
1799 if (talk
&& netaddrs
.m_next
)
1800 puts(" -- Network Recipients --");
1801 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1802 do_an_address (lp
, talk
);
1805 if (talk
&& !whomsw
)
1806 puts(" -- Address Verification Successful --");
1808 if (!whomsw
|| checksw
)
1809 sm_end (whomsw
? OK
: DONE
);
1817 do_an_address (struct mailname
*lp
, int talk
)
1823 switch (lp
->m_type
) {
1827 strncpy (addr
, mbox
, sizeof(addr
));
1831 mbox
= auxformat (lp
, 0);
1833 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1836 default: /* let SendMail decide if the host is bad */
1839 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1844 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1846 if (whomsw
&& !checksw
) {
1854 switch (retval
= sm_wadr (mbox
, host
,
1855 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1864 fprintf (stderr
, " %s: ", addr
);
1865 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1866 rp_string (retval
));
1872 fprintf (stderr
, " %s: ", addr
);
1873 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1881 do_text (char *file
, int fd
)
1886 lseek(fd
, 0, SEEK_SET
);
1888 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1889 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1890 fatal (NULL
, "problem writing text; %s\n", rp_string (retval
));
1894 fatal (file
, "problem reading from");
1896 switch (retval
= sm_wtend ()) {
1902 fatal (NULL
, "posting failed; %s", rp_string (retval
));
1906 fatal (NULL
, "unexpected response; %s", rp_string (retval
));
1920 (void) m_unlink (tmpfil
);
1921 if (msgflags
& MINV
)
1922 (void) m_unlink (bccfil
);
1924 if (!whomsw
|| checksw
)
1937 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1938 istat
= SIGNAL2 (SIGINT
, sigser
);
1939 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1940 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1950 SIGNAL (SIGHUP
, hstat
);
1951 SIGNAL (SIGINT
, istat
);
1952 SIGNAL (SIGQUIT
, qstat
);
1953 SIGNAL (SIGTERM
, tstat
);
1961 p_refile (char *file
)
1969 puts(" -- Filing Folder Copies --");
1970 for (i
= 0; i
< fccind
; i
++)
1971 fcc (file
, fccfold
[i
]);
1973 puts(" -- Folder Copies Filed --");
1978 * Call the `fileproc' to add the file to the folder.
1982 fcc (char *file
, char *folder
)
1987 char **arglist
, *program
;
1990 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
1997 fprintf (stderr
, " %sFcc %s: ",
1998 msgstate
== RESENT
? "Resent-" : "", folder
);
1999 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
2003 /* see if we need to add `+' */
2004 snprintf (fold
, sizeof(fold
), "%s%s",
2005 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
2007 /* now exec the fileproc */
2009 arglist
= argsplit(fileproc
, &program
, &argp
);
2010 arglist
[argp
++] = "-link";
2011 arglist
[argp
++] = "-file";
2012 arglist
[argp
++] = file
;
2013 arglist
[argp
++] = fold
;
2014 arglist
[argp
] = NULL
;
2015 execvp (program
, arglist
);
2019 if ((status
= pidwait (child_id
, OK
))) {
2021 fprintf (stderr
, " %sFcc %s: ",
2022 msgstate
== RESENT
? "Resent-" : "", folder
);
2023 pidstatus (status
, verbose
? stdout
: stderr
, fileproc
);
2038 fatal (char *what
, char *fmt
, ...)
2045 (void) m_unlink (tmpfil
);
2046 if (msgflags
& MINV
)
2047 (void) m_unlink (bccfil
);
2049 if (!whomsw
|| checksw
)
2054 advertise (what
, NULL
, fmt
, ap
);