]>
diplodocus.org Git - nmh/blob - uip/post.c
66d978cc0737c237177cb33e22782356a2d9571b
3 * post.c -- enter messages into the mail transport system
10 #include <h/signals.h>
11 #include <h/addrsbr.h>
12 #include <h/aliasbr.h>
13 #include <h/dropsbr.h>
16 #include <zotnet/tws/tws.h>
17 #include <zotnet/mts/mts.h>
23 #ifdef TIME_WITH_SYS_TIME
24 # include <sys/time.h>
27 # ifdef TM_IN_SYS_TIME
28 # include <sys/time.h>
35 # include <mts/mmdf/util.h>
36 # include <mts/mmdf/mmdf.h>
40 * Currently smtp and sendmail use
41 * the same interface for posting.
48 # include <mts/smtp/smtp.h>
52 # define uptolow(c) ((isalpha(c) && isupper (c)) ? tolower (c) : (c))
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 static struct swit switches
[] = {
66 { "alias aliasfile", 0 },
68 { "check", -5 }, /* interface from whom */
70 { "nocheck", -7 }, /* interface from whom */
74 { "dist", -4 }, /* interface from dist */
76 { "filter filterfile", 0 },
84 { "library directory", -7 }, /* interface from send, whom */
102 { "whom", -4 }, /* interface from whom */
104 { "width columns", 0 },
109 #define BITSTUFFSW 22
110 { "dashstuffing", -12 }, /* should we dashstuff BCC messages? */
111 #define NBITSTUFFSW 23
112 { "nodashstuffing", -14 },
114 { "mail", -4 }, /* specify MAIL smtp mode */
116 { "saml", -4 }, /* specify SAML smtp mode */
118 { "send", -4 }, /* specify SEND smtp mode */
120 { "soml", -4 }, /* specify SOML smtp mode */
122 { "idanno number", -6 }, /* interface from send */
124 { "deliver address-list", -7 },
126 { "client host", -6 },
128 { "server host", -6 }, /* specify alternate SMTP server */
130 { "snoop", -5 }, /* snoop the SMTP transaction */
132 { "fill-in file", -7 },
150 * flags for headers->flags
152 #define HNOP 0x0000 /* just used to keep .set around */
153 #define HBAD 0x0001 /* bad header - don't let it through */
154 #define HADR 0x0002 /* header has an address field */
155 #define HSUB 0x0004 /* Subject: header */
156 #define HTRY 0x0008 /* try to send to addrs on header */
157 #define HBCC 0x0010 /* don't output this header */
158 #define HMNG 0x0020 /* munge this header */
159 #define HNGR 0x0040 /* no groups allowed in this header */
160 #define HFCC 0x0080 /* FCC: type header */
161 #define HNIL 0x0100 /* okay for this header not to have addrs */
162 #define HIGN 0x0200 /* ignore this header */
163 #define HDCC 0x0400 /* another undocumented feature */
166 * flags for headers->set
168 #define MFRM 0x0001 /* we've seen a From: */
169 #define MDAT 0x0002 /* we've seen a Date: */
170 #define MRFM 0x0004 /* we've seen a Resent-From: */
171 #define MVIS 0x0008 /* we've seen sighted addrs */
172 #define MINV 0x0010 /* we've seen blind addrs */
175 static struct headers NHeaders
[] = {
176 { "Return-Path", HBAD
, 0 },
177 { "Received", HBAD
, 0 },
178 { "Reply-To", HADR
|HNGR
, 0 },
179 { "From", HADR
|HNGR
, MFRM
},
180 { "Sender", HADR
|HBAD
, 0 },
182 { "Subject", HSUB
, 0 },
183 { "To", HADR
|HTRY
, MVIS
},
184 { "cc", HADR
|HTRY
, MVIS
},
185 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, MINV
},
186 { "Dcc", HADR
|HTRY
|HDCC
|HNIL
, MVIS
}, /* sorta cc & bcc combined */
187 { "Message-ID", HBAD
, 0 },
192 static struct headers RHeaders
[] = {
193 { "Resent-Reply-To", HADR
|HNGR
, 0 },
194 { "Resent-From", HADR
|HNGR
, MRFM
},
195 { "Resent-Sender", HADR
|HBAD
, 0 },
196 { "Resent-Date", HBAD
, 0 },
197 { "Resent-Subject", HSUB
, 0 },
198 { "Resent-To", HADR
|HTRY
, MVIS
},
199 { "Resent-cc", HADR
|HTRY
, MVIS
},
200 { "Resent-Bcc", HADR
|HTRY
|HBCC
, MINV
},
201 { "Resent-Message-ID", HBAD
, 0 },
202 { "Resent-Fcc", HFCC
, 0 },
203 { "Reply-To", HADR
, 0 },
204 { "From", HADR
|HNGR
, MFRM
},
206 { "Sender", HADR
|HNGR
|HMNG
, 0 },
208 { "Sender", HADR
|HNGR
, 0 },
210 { "Date", HNOP
, MDAT
},
211 { "To", HADR
|HNIL
, 0 },
212 { "cc", HADR
|HNIL
, 0 },
213 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, 0 },
218 static short fccind
= 0; /* index into fccfold[] */
219 static short outputlinelen
= OUTPUTLINELEN
;
221 static int pfd
= NOTOK
; /* fd to write annotation list to */
222 static uid_t myuid
= -1; /* my user id */
223 static gid_t mygid
= -1; /* my group id */
224 static int recipients
= 0; /* how many people will get a copy */
225 static int unkadr
= 0; /* how many of those were unknown */
226 static int badadr
= 0; /* number of bad addrs */
227 static int badmsg
= 0; /* message has bad semantics */
228 static int verbose
= 0; /* spell it out */
229 static int format
= 1; /* format addresses */
230 static int mime
= 0; /* use MIME-style encapsulations for Bcc */
231 static int msgid
= 0; /* add msgid */
232 static int debug
= 0; /* debugging post */
233 static int watch
= 0; /* watch the delivery process */
234 static int whomsw
= 0; /* we are whom not post */
235 static int checksw
= 0; /* whom -check */
236 static int linepos
=0; /* putadr()'s position on the line */
237 static int nameoutput
=0; /* putadr() has output header name */
239 static unsigned msgflags
= 0; /* what we've seen */
243 static int msgstate
= NORMAL
;
245 static time_t tclock
= 0; /* the time we started (more or less) */
247 static SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
249 static char tmpfil
[BUFSIZ
];
250 static char bccfil
[BUFSIZ
];
252 static char from
[BUFSIZ
]; /* my network address */
253 static char signature
[BUFSIZ
]; /* my signature */
254 static char *filter
= NULL
; /* the filter for BCC'ing */
255 static char *subject
= NULL
; /* the subject field for BCC'ing */
256 static char *fccfold
[FCCS
]; /* foldernames for FCC'ing */
258 static struct headers
*hdrtab
; /* table for the message we're doing */
260 static struct mailname localaddrs
={NULL
}; /* local addrs */
261 static struct mailname netaddrs
={NULL
}; /* network addrs */
262 static struct mailname uuaddrs
={NULL
}; /* uucp addrs */
263 static struct mailname tmpaddrs
={NULL
}; /* temporary queue */
266 static char *submitmode
= "m"; /* deliver to mailbox only */
267 static char submitopts
[6] = "vl"; /* initial options for submit */
271 static int snoop
= 0;
272 static int smtpmode
= S_MAIL
;
273 static char *clientsw
= NULL
;
274 static char *serversw
= NULL
;
276 extern struct smtp sm_reply
;
279 static char prefix
[] = "----- =_aaaaaaaaaa";
281 static int fill_up
= 0;
282 static char *fill_in
= NULL
;
283 static char *partno
= NULL
;
284 static int queued
= 0;
291 static void putfmt (char *, char *, FILE *);
292 static void start_headers (void);
293 static void finish_headers (FILE *);
294 static int get_header (char *, struct headers
*);
295 static int putadr (char *, char *, struct mailname
*, FILE *, unsigned int);
296 static void putgrp (char *, char *, FILE *, unsigned int);
297 static int insert (struct mailname
*);
298 static void pl (void);
299 static void anno (void);
300 static int annoaux (struct mailname
*);
301 static void insert_fcc (struct headers
*, char *);
302 static void make_bcc_file (int);
303 static void verify_all_addresses (int);
304 static void chkadr (void);
305 static void sigon (void);
306 static void sigoff (void);
307 static void p_refile (char *);
308 static void fcc (char *, char *);
309 static void die (char *, char *, ...);
310 static void post (char *, int, int);
311 static void do_text (char *file
, int fd
);
312 static void do_an_address (struct mailname
*, int);
313 static void do_addresses (int, int);
314 static int find_prefix (void);
318 main (int argc
, char **argv
)
320 int state
, compnum
, dashstuff
= 0;
321 char *cp
, *msg
= NULL
, **argp
, **arguments
;
322 char buf
[BUFSIZ
], name
[NAMESZ
];
326 setlocale(LC_ALL
, "");
328 invo_name
= r1bindex (argv
[0], '/');
330 /* foil search of user profile/context */
331 if (context_foil (NULL
) == -1)
334 mts_init (invo_name
);
335 arguments
= getarguments (invo_name
, argc
, argv
, 0);
338 #if defined(MMDFMTS) && defined(MMDFII)
339 mmdf_init (invo_name
);
340 #endif /* MMDFMTS and MMDFII */
342 while ((cp
= *argp
++)) {
344 switch (smatch (++cp
, switches
)) {
346 ambigsw (cp
, switches
);
349 adios (NULL
, "-%s unknown", cp
);
352 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
353 print_help (buf
, switches
, 0);
356 print_version(invo_name
);
360 if (!(cp
= *argp
++) || *cp
== '-')
361 adios (NULL
, "missing argument to %s", argp
[-2]);
362 /* create a minimal context */
363 if (context_foil (cp
) == -1)
368 if (!(cp
= *argp
++) || *cp
== '-')
369 adios (NULL
, "missing argument to %s", argp
[-2]);
370 if ((state
= alias (cp
)) != AK_OK
)
371 adios (NULL
, "aliasing error in %s - %s",
372 cp
, akerror (state
));
391 if (!(filter
= *argp
++) || *filter
== '-')
392 adios (NULL
, "missing argument to %s", argp
[-2]);
447 if (!(cp
= *argp
++) || *cp
== '-')
448 adios (NULL
, "missing argument to %s", argp
[-2]);
449 if ((outputlinelen
= atoi (cp
)) < 10)
450 adios (NULL
, "impossible width %d", outputlinelen
);
454 if (!(cp
= *argp
++) || *cp
== '-')
455 adios (NULL
, "missing argument to %s", argp
[-2]);
456 if ((pfd
= atoi (cp
)) <= 2)
457 adios (NULL
, "bad argument %s %s", argp
[-2], cp
);
464 case SOMLSW
: /* for right now, sigh... */
474 if (!(cp
= *argp
++) || *cp
== '-')
475 adios (NULL
, "missing argument to %s", argp
[-2]);
481 if (!(cp
= *argp
++) || *cp
== '-')
482 adios (NULL
, "missing argument to %s", argp
[-2]);
501 if (!(clientsw
= *argp
++) || *clientsw
== '-')
502 adios (NULL
, "missing argument to %s", argp
[-2]);
505 if (!(serversw
= *argp
++) || *serversw
== '-')
506 adios (NULL
, "missing argument to %s", argp
[-2]);
514 if (!(fill_in
= *argp
++) || *fill_in
== '-')
515 adios (NULL
, "missing argument to %s", argp
[-2]);
521 if (!(partno
= *argp
++) || *partno
== '-')
522 adios (NULL
, "missing argument to %s", argp
[-2]);
531 adios (NULL
, "only one message at a time!");
539 adios (NULL
, "usage: %s [switches] file", invo_name
);
541 if (outputlinelen
< 10)
542 adios (NULL
, "impossible width %d", outputlinelen
);
544 if ((in
= fopen (msg
, "r")) == NULL
)
545 adios (msg
, "unable to open");
550 discard (out
= stdout
); /* XXX: reference discard() to help loader */
553 if ((out
= fopen (fill_in
? fill_in
: "/dev/null", "w")) == NULL
)
554 adios ("/dev/null", "unable to open");
556 strncpy (tmpfil
, m_scratch ("", m_maildir (invo_name
)),
558 if ((out
= fopen (tmpfil
, "w")) == NULL
) {
559 strncpy (tmpfil
, m_tmpfil (invo_name
), sizeof(tmpfil
));
560 if ((out
= fopen (tmpfil
, "w")) == NULL
)
561 adios (tmpfil
, "unable to create");
563 chmod (tmpfil
, 0600);
567 hdrtab
= msgstate
== NORMAL
? NHeaders
: RHeaders
;
569 for (compnum
= 1, state
= FLD
;;) {
570 switch (state
= m_getfld (state
, name
, buf
, sizeof(buf
), in
)) {
575 cp
= add (buf
, NULL
);
576 while (state
== FLDPLUS
) {
577 state
= m_getfld (state
, name
, buf
, sizeof(buf
), in
);
580 putfmt (name
, cp
, out
);
584 finish_headers (out
);
589 finish_headers (out
);
590 if (whomsw
&& !fill_in
)
592 fprintf (out
, "\n%s", buf
);
593 while (state
== BODY
) {
594 state
= m_getfld (state
, name
, buf
, sizeof(buf
), in
);
600 finish_headers (out
);
605 adios (NULL
, "message format error in component #%d", compnum
);
608 adios (NULL
, "getfld() returned %d", state
);
624 /* If we are doing a "whom" check */
627 verify_all_addresses (1);
632 strcat (submitopts
, submitmode
);
634 strcat (submitopts
, "nw");
637 if (msgflags
& MINV
) {
638 make_bcc_file (dashstuff
);
639 if (msgflags
& MVIS
) {
640 verify_all_addresses (verbose
);
641 post (tmpfil
, 0, verbose
);
643 post (bccfil
, 1, verbose
);
646 post (tmpfil
, 0, isatty (1));
653 printf (partno
? "Partial Message #%s Processed\n" : "Message Processed\n",
664 putfmt (char *name
, char *str
, FILE *out
)
666 int count
, grp
, i
, keep
;
669 struct mailname
*mp
, *np
;
672 while (*str
== ' ' || *str
== '\t')
675 if (msgstate
== NORMAL
&& uprf (name
, "resent")) {
676 advise (NULL
, "illegal header line -- %s:", name
);
681 if ((i
= get_header (name
, hdrtab
)) == NOTOK
) {
682 fprintf (out
, "%s: %s", name
, str
);
687 if (hdr
->flags
& HIGN
) {
689 fprintf (out
, "%s: %s", name
, str
);
692 if (hdr
->flags
& HBAD
) {
694 fprintf (out
, "%s: %s", name
, str
);
696 advise (NULL
, "illegal header line -- %s:", name
);
701 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
703 if (hdr
->flags
& HSUB
)
704 subject
= subject
? add (str
, add ("\t", subject
)) : getcpy (str
);
705 if (hdr
->flags
& HFCC
) {
707 fprintf (out
, "%s: %s", name
, str
);
711 if ((cp
= strrchr(str
, '\n')))
713 for (cp
= pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
715 insert_fcc (hdr
, pp
);
717 insert_fcc (hdr
, pp
);
721 if (!(hdr
->flags
& HADR
)) {
722 fprintf (out
, "%s: %s", name
, str
);
726 tmpaddrs
.m_next
= NULL
;
727 for (count
= 0; (cp
= getname (str
)); count
++)
728 if ((mp
= getm (cp
, NULL
, 0, AD_HOST
, NULL
))) {
732 tmpaddrs
.m_next
= mp
;
736 if (hdr
->flags
& HTRY
)
742 if (hdr
->flags
& HNIL
)
743 fprintf (out
, "%s: %s", name
, str
);
746 advise (NULL
, "%s: field requires at least one address", name
);
753 nameoutput
= linepos
= 0;
754 snprintf (namep
, sizeof(namep
), "%s%s",
755 !fill_in
&& (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
757 for (grp
= 0, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
758 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
759 /* The address doesn't include a host, so it might be an alias. */
760 pp
= akvalue (mp
->m_mbox
); /* do mh alias substitution */
761 qp
= akvisible () ? mp
->m_mbox
: "";
764 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
765 while ((cp
= getname (pp
))) {
766 if (!(mp
= getm (cp
, NULL
, 0, AD_HOST
, NULL
))) {
771 if (MMailids
&& ((msgstate
== RESENT
)
773 : (hdr
->set
& MFRM
)))
774 /* The user manually specified a [Resent-]From: address in
775 their draft and mts.conf turned on "mmailid", so we'll
776 set things up to use the actual email address embedded in
777 the draft [Resent-]From: (after alias substitution, and
778 without the GECOS full name or angle brackets) as the
780 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
782 if (hdr
->flags
& HBCC
)
785 mp
->m_ingrp
= np
->m_ingrp
;
788 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
791 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
))
792 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
801 /* Address includes a host, so no alias substitution is needed. */
802 if (MMailids
&& ((msgstate
== RESENT
)
804 : (hdr
->set
& MFRM
)))
805 /* The user manually specified a [Resent-]From: address in their
806 draft and mts.conf turned on "mmailid", so we'll set things
807 up to use the actual email address embedded in the draft
808 [Resent-]From: (without the GECOS full name or angle
809 brackets) as the envelope From:. */
810 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
812 if (hdr
->flags
& HBCC
)
815 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
818 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
);
822 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
828 if (grp
> 0 && (hdr
->flags
& HNGR
)) {
829 advise (NULL
, "%s: field does not allow groups", name
);
833 if (fill_in
&& grp
> 0)
844 char myhost
[BUFSIZ
], sigbuf
[BUFSIZ
];
851 strncpy (from
, adrsprintf (NULL
, NULL
), sizeof(from
));
852 strncpy (myhost
, LocalName (), sizeof(myhost
));
854 for (cp
= myhost
; *cp
; cp
++)
857 if ((cp
= getfullname ()) && *cp
) {
858 strncpy (sigbuf
, cp
, sizeof(sigbuf
));
859 snprintf (signature
, sizeof(signature
), "%s <%s>",
860 sigbuf
, adrsprintf (NULL
, NULL
));
861 if ((cp
= getname (signature
)) == NULL
)
862 adios (NULL
, "getname () failed -- you lose extraordinarily big");
863 if ((mp
= getm (cp
, NULL
, 0, AD_HOST
, NULL
)) == NULL
)
864 adios (NULL
, "bad signature '%s'", sigbuf
);
869 strncpy (signature
, adrsprintf (NULL
, NULL
), sizeof(signature
));
875 * Now that we've outputted the header fields in the draft
876 * message, we will now output any remaining header fields
877 * that we need to add/create.
881 finish_headers (FILE *out
)
885 if (whomsw
&& !fill_up
)
888 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
890 fprintf (out
, "Message-ID: <%d.%ld@%s>\n",
891 (int) getpid (), (long) tclock
, LocalName ());
892 if (msgflags
& MFRM
) {
893 /* There was already a From: in the draft. Don't add one. */
895 /* mts.conf didn't turn on mmailid, so we'll reveal the
896 user's actual account@thismachine address in a Sender:
897 header (and use it as the envelope From: later). */
898 fprintf (out
, "Sender: %s\n", from
);
901 /* Construct a From: header. */
902 fprintf (out
, "From: %s\n", signature
);
906 if (!(msgflags
& MVIS
))
907 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
911 if (!(msgflags
& MDAT
)) {
912 advise (NULL
, "message has no Date: header");
915 if (!(msgflags
& MFRM
)) {
916 advise (NULL
, "message has no From: header");
919 if (whomsw
&& !fill_up
)
922 #ifdef MMDFI /* sigh */
923 fprintf (out
, "Sender: %s\n", from
);
926 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
928 fprintf (out
, "Resent-Message-ID: <%d.%ld@%s>\n",
929 (int) getpid (), (long) tclock
, LocalName ());
930 if (msgflags
& MRFM
) {
931 /* There was already a Resent-From: in draft. Don't add one. */
933 /* mts.conf didn't turn on mmailid, so we'll reveal the
934 user's actual account@thismachine address in a
935 Resent-Sender: header (and use it as the envelope From:
937 fprintf (out
, "Resent-Sender: %s\n", from
);
940 /* Construct a Resent-From: header. */
941 fprintf (out
, "Resent-From: %s\n", signature
);
944 if (!(msgflags
& MVIS
))
945 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
950 adios (NULL
, "re-format message and try again");
952 adios (NULL
, "no addressees");
957 get_header (char *header
, struct headers
*table
)
961 for (h
= table
; h
->value
; h
++)
962 if (!strcasecmp (header
, h
->value
))
970 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
, unsigned int flags
)
976 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
978 if ((!fill_in
&& (flags
& (HBCC
| HDCC
))) || mp
->m_ingrp
)
982 fprintf (out
, "%s: ", name
);
983 linepos
+= (nameoutput
= strlen (name
) + 2);
986 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
987 mp
->m_pers
= getcpy (aka
);
989 if (mp
->m_gname
&& !fill_in
) {
990 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
1000 if (linepos
!= nameoutput
) {
1001 if (len
+ linepos
+ 2 > outputlinelen
)
1002 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
1012 return (flags
& HTRY
);
1017 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
1022 if (!fill_in
&& (flags
& HBCC
))
1026 fprintf (out
, "%s: ", name
);
1027 linepos
+= (nameoutput
= strlen (name
) + 2);
1029 linepos
-= strlen (group
);
1032 cp
= fill_in
? group
: concat (group
, ";", NULL
);
1035 if (linepos
> nameoutput
) {
1036 if (len
+ linepos
+ 2 > outputlinelen
) {
1037 fprintf (out
, ",\n%*s", nameoutput
, "");
1038 linepos
= nameoutput
;
1052 insert (struct mailname
*np
)
1054 struct mailname
*mp
;
1056 if (np
->m_mbox
== NULL
)
1059 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1060 : np
->m_type
== UUCPHOST
? &uuaddrs
1064 if (!strcasecmp (np
->m_host
, mp
->m_next
->m_host
)
1065 && !strcasecmp (np
->m_mbox
, mp
->m_next
->m_mbox
)
1066 && np
->m_bcc
== mp
->m_next
->m_bcc
)
1079 struct mailname
*mp
;
1081 printf ("-------\n\t-- Addresses --\nlocal:\t");
1082 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1083 printf ("%s%s%s", mp
->m_mbox
,
1084 mp
->m_bcc
? "[BCC]" : "",
1085 mp
->m_next
? ",\n\t" : "");
1087 printf ("\nnet:\t");
1088 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1089 printf ("%s%s@%s%s%s", mp
->m_path
? mp
->m_path
: "",
1090 mp
->m_mbox
, mp
->m_host
,
1091 mp
->m_bcc
? "[BCC]" : "",
1092 mp
->m_next
? ",\n\t" : "");
1094 printf ("\nuucp:\t");
1095 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1096 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1097 mp
->m_bcc
? "[BCC]" : "",
1098 mp
->m_next
? ",\n\t" : "");
1100 printf ("\n\t-- Folder Copies --\nfcc:\t");
1101 for (i
= 0; i
< fccind
; i
++)
1102 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1110 struct mailname
*mp
;
1112 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1113 if (annoaux (mp
) == NOTOK
)
1116 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1117 if (annoaux (mp
) == NOTOK
)
1120 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1121 if (annoaux (mp
) == NOTOK
)
1131 annoaux (struct mailname
*mp
)
1134 char buffer
[BUFSIZ
];
1136 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1137 i
= strlen (buffer
);
1139 return (write (pfd
, buffer
, i
) == i
? OK
: NOTOK
);
1144 insert_fcc (struct headers
*hdr
, char *pp
)
1148 for (cp
= pp
; isspace (*cp
); cp
++)
1150 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace (*pp
); pp
--)
1158 adios (NULL
, "too many %ss", hdr
->value
);
1159 fccfold
[fccind
++] = getcpy (cp
);
1167 make_bcc_file (int dashstuff
)
1174 strncpy (bccfil
, m_tmpfil ("bccs"), sizeof(bccfil
));
1175 if ((out
= fopen (bccfil
, "w")) == NULL
)
1176 adios (bccfil
, "unable to create");
1177 chmod (bccfil
, 0600);
1179 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1181 fprintf (out
, "Message-ID: <%d.%ld@%s>\n",
1182 (int) getpid (), (long) tclock
, LocalName ());
1183 fprintf (out
, "From: %s\n", signature
);
1185 fprintf (out
, "Subject: %s", subject
);
1186 fprintf (out
, "BCC:\n");
1189 * Use MIME encapsulation for Bcc messages
1195 * Check if any lines in the message clash with the
1196 * prefix for the MIME multipart separator. If there
1197 * is a clash, increment one of the letters in the
1198 * prefix and check again.
1200 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1201 adios (NULL
, "lost prefix start");
1202 while (find_prefix () == NOTOK
) {
1207 adios (NULL
, "can't find a unique delimiter string");
1212 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1213 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1214 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1216 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1222 * Do mhl filtering of Bcc messages instead
1223 * of MIME encapsulation.
1225 if (filter
!= NULL
) {
1226 vec
[0] = r1bindex (mhlproc
, '/');
1228 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
1232 adios ("fork", "unable to");
1235 dup2 (fileno (out
), 1);
1238 vec
[i
++] = "-forward";
1243 /* was the flag -[no]dashstuffing specified? */
1245 vec
[i
++] = "-dashstuffing";
1246 else if (dashstuff
< 0)
1247 vec
[i
++] = "-nodashstuffing";
1250 execvp (mhlproc
, vec
);
1251 fprintf (stderr
, "unable to exec ");
1256 pidXwait (child_id
, mhlproc
);
1260 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1261 adios (tmpfil
, "unable to re-open");
1264 * If using MIME encapsulation, or if the -nodashstuffing
1265 * flag was given, then just copy message. Else do
1266 * RFC934 quoting (dashstuffing).
1268 if (mime
|| dashstuff
< 0)
1269 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1271 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1275 fseek (out
, 0L, SEEK_END
);
1277 fprintf (out
, "\n--%s--\n", prefix
);
1279 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1285 * Scan message to check if any lines clash with
1286 * the prefix of the MIME multipart separator.
1293 char buffer
[BUFSIZ
];
1296 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1297 adios (tmpfil
, "unable to re-open");
1299 len
= strlen (prefix
);
1302 while (fgets (buffer
, sizeof(buffer
) - 1, in
))
1303 if (buffer
[0] == '-' && buffer
[1] == '-') {
1306 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1310 if (strcmp (buffer
+ 2, prefix
) == 0) {
1321 #define plural(x) (x == 1 ? "" : "s")
1326 if (badadr
&& unkadr
)
1327 die (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1328 badadr
, plural (badadr
), unkadr
, plural (badadr
));
1330 die (NULL
, "%d address%s unparsable", badadr
, plural (badadr
));
1332 die (NULL
, "%d addressee%s undeliverable", unkadr
, plural (unkadr
));
1337 do_addresses (int bccque
, int talk
)
1341 struct mailname
*lp
;
1344 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1345 if (lp
->m_bcc
? bccque
: !bccque
) {
1347 printf (" -- Local Recipients --\n");
1348 do_an_address (lp
, talk
);
1353 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1354 if (lp
->m_bcc
? bccque
: !bccque
) {
1356 printf (" -- UUCP Recipients --\n");
1357 do_an_address (lp
, talk
);
1362 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1363 if (lp
->m_bcc
? bccque
: !bccque
) {
1365 printf (" -- Network Recipients --\n");
1366 do_an_address (lp
, talk
);
1373 if (rp_isbad (retval
= mm_waend ()))
1374 die (NULL
, "problem ending addresses [%s]\n", rp_valstr (retval
));
1375 #endif /* MMDFMTS */
1378 if (rp_isbad (retval
= sm_waend ()))
1379 die (NULL
, "problem ending addresses; %s", rp_string (retval
));
1380 #endif /* SENDMTS */
1385 * MTS-SPECIFIC INTERACTION
1390 * SENDMAIL/SMTP routines
1396 post (char *file
, int bccque
, int talk
)
1401 onex
= !(msgflags
& MINV
) || bccque
;
1403 if (msgflags
& MINV
)
1404 printf (" -- Posting for %s Recipients --\n",
1405 bccque
? "Blind" : "Sighted");
1407 printf (" -- Posting for All Recipients --\n");
1412 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, watch
, verbose
,
1413 snoop
, onex
, queued
))
1414 || rp_isbad (retval
= sm_winit (smtpmode
, from
)))
1415 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1417 do_addresses (bccque
, talk
&& verbose
);
1418 if ((fd
= open (file
, O_RDONLY
)) == NOTOK
)
1419 die (file
, "unable to re-open");
1424 sm_end (onex
? OK
: DONE
);
1428 if (msgflags
& MINV
)
1429 printf (" -- %s Recipient Copies Posted --\n",
1430 bccque
? "Blind" : "Sighted");
1432 printf (" -- Recipient Copies Posted --\n");
1439 /* Address Verification */
1442 verify_all_addresses (int talk
)
1445 struct mailname
*lp
;
1449 if (!whomsw
|| checksw
)
1450 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, 0, 0, snoop
, 0, 0))
1451 || rp_isbad (retval
= sm_winit (smtpmode
, from
)))
1452 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1454 if (talk
&& !whomsw
)
1455 printf (" -- Address Verification --\n");
1456 if (talk
&& localaddrs
.m_next
)
1457 printf (" -- Local Recipients --\n");
1458 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1459 do_an_address (lp
, talk
);
1461 if (talk
&& uuaddrs
.m_next
)
1462 printf (" -- UUCP Recipients --\n");
1463 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1464 do_an_address (lp
, talk
);
1466 if (talk
&& netaddrs
.m_next
)
1467 printf (" -- Network Recipients --\n");
1468 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1469 do_an_address (lp
, talk
);
1472 if (talk
&& !whomsw
)
1473 printf (" -- Address Verification Successful --\n");
1475 if (!whomsw
|| checksw
)
1484 do_an_address (struct mailname
*lp
, int talk
)
1490 switch (lp
->m_type
) {
1494 strncpy (addr
, mbox
, sizeof(addr
));
1498 mbox
= auxformat (lp
, 0);
1500 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1503 default: /* let SendMail decide if the host is bad */
1506 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1511 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1513 if (whomsw
&& !checksw
) {
1521 switch (retval
= sm_wadr (mbox
, host
,
1522 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1525 printf ("address ok\n");
1531 fprintf (stderr
, " %s: ", addr
);
1532 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1533 rp_string (retval
));
1539 fprintf (stderr
, " %s: ", addr
);
1540 die (NULL
, "unexpected response; %s", rp_string (retval
));
1548 do_text (char *file
, int fd
)
1553 lseek (fd
, (off_t
) 0, SEEK_SET
);
1555 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1556 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1557 die (NULL
, "problem writing text; %s\n", rp_string (retval
));
1561 die (file
, "problem reading from");
1563 switch (retval
= sm_wtend ()) {
1569 die (NULL
, "posting failed; %s", rp_string (retval
));
1572 die (NULL
, "unexpected response; %s", rp_string (retval
));
1576 #endif /* SENDMTS */
1585 post (char *file
, int bccque
, int talk
)
1591 struct rp_bufstruct reply
;
1594 onex
= !(msgflags
& MINV
) || bccque
;
1596 if (msgflags
& MINV
)
1597 printf (" -- Posting for %s Recipients --\n",
1598 bccque
? "Blind" : "Sighted");
1600 printf (" -- Posting for All Recipients --\n");
1605 if (rp_isbad (retval
= mm_init ())
1606 || rp_isbad (retval
= mm_sbinit ())
1607 || rp_isbad (retval
= mm_winit (NULL
, submitopts
, from
)))
1608 die (NULL
, "problem initializing MMDF system [%s]",
1609 rp_valstr (retval
));
1611 if (rp_isbad (retval
= mm_rrply (&reply
, &len
)))
1612 die (NULL
, "problem with sender address [%s]",
1613 rp_valstr (retval
));
1616 do_addresses (bccque
, talk
&& verbose
);
1617 if ((fd
= open (file
, O_RDONLY
)) == NOTOK
)
1618 die (file
, "unable to re-open");
1628 if (msgflags
& MINV
)
1629 printf (" -- %s Recipient Copies Posted --\n",
1630 bccque
? "Blind" : "Sighted");
1632 printf (" -- Recipient Copies Posted --\n");
1637 /* Address Verification */
1640 verify_all_addresses (int talk
)
1643 struct mailname
*lp
;
1647 struct rp_bufstruct reply
;
1652 if (!whomsw
|| checksw
) {
1653 if (rp_isbad (retval
= mm_init ())
1654 || rp_isbad (retval
= mm_sbinit ())
1655 || rp_isbad (retval
= mm_winit (NULL
, submitopts
, from
)))
1656 die (NULL
, "problem initializing MMDF system [%s]",
1657 rp_valstr (retval
));
1659 if (rp_isbad (retval
= mm_rrply (&reply
, &len
)))
1660 die (NULL
, "problem with sender address [%s]", rp_valstr (retval
));
1664 if (talk
&& !whomsw
)
1665 printf (" -- Address Verification --\n");
1666 if (talk
&& localaddrs
.m_next
)
1667 printf (" -- Local Recipients --\n");
1668 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1669 do_an_address (lp
, talk
);
1671 if (talk
&& uuaddrs
.m_next
)
1672 printf (" -- UUCP Recipients --\n");
1673 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1674 do_an_address (lp
, talk
);
1676 if (talk
&& netaddrs
.m_next
)
1677 printf (" -- Network Recipients --\n");
1678 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1679 do_an_address (lp
, talk
);
1682 if (talk
&& !whomsw
)
1683 printf (" -- Address Verification Successful --\n");
1685 if (!whomsw
|| checksw
)
1694 do_an_address (struct mailname
*lp
, int talk
)
1697 char *mbox
, *host
, *text
, *path
;
1699 struct rp_bufstruct reply
;
1701 switch (lp
->m_type
) {
1704 host
= LocalName ();
1705 strncpy (addr
, mbox
, sizeof(addr
));
1709 fprintf (talk
? stdout
: stderr
, " %s!%s: %s\n",
1710 lp
->m_host
, lp
->m_mbox
, "not supported; UUCP address");
1715 default: /* let MMDF decide if the host is bad */
1718 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1723 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1725 if (whomsw
&& !checksw
) {
1735 path
= concat (lp
->m_path
, mbox
, "@", host
, NULL
);
1739 if (rp_isbad (retval
= mm_wadr (path
? NULL
: host
, path
? path
: mbox
))
1740 || rp_isbad (retval
= mm_rrply (&reply
, &len
)))
1741 die (NULL
, "problem submitting address [%s]", rp_valstr (retval
));
1743 switch (rp_gval (reply
.rp_val
)) {
1746 printf ("address ok\n");
1753 printf ("nameserver timeout - queued for checking\n");
1764 text
= "temporary nameserver failure";
1771 text
= "not deliverable";
1775 text
= "try again later";
1779 text
= "nothing done";
1784 fprintf (stderr
, " %s: ", addr
);
1785 text
= "unexpected response";
1786 die (NULL
, "%s;\n [%s] -- %s", text
,
1787 rp_valstr (reply
.rp_val
), reply
.rp_line
);
1791 fprintf (stderr
, " %s: ", addr
);
1792 fprintf (talk
? stdout
: stderr
, "%s;\n %s\n", text
, reply
.rp_line
);
1800 do_text (char *file
, int fd
)
1804 struct rp_bufstruct reply
;
1806 lseek (fd
, (off_t
) 0, SEEK_SET
);
1808 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1809 if (rp_isbad (mm_wtxt (buf
, state
)))
1810 die (NULL
, "problem writing text [%s]\n", rp_valstr (retval
));
1814 die (file
, "problem reading from");
1816 if (rp_isbad (retval
= mm_wtend ()))
1817 die (NULL
, "problem ending text [%s]\n", rp_valstr (retval
));
1819 if (rp_isbad (retval
= mm_rrply (&reply
, &state
)))
1820 die (NULL
, "problem getting submission status [%s]\n",
1821 rp_valstr (retval
));
1823 switch (rp_gval (reply
.rp_val
)) {
1829 die (NULL
, "you lose; %s", reply
.rp_line
);
1832 die (NULL
, "no delivery occurred; %s", reply
.rp_line
);
1835 die (NULL
, "try again later; %s", reply
.rp_line
);
1838 die (NULL
, "nothing done; %s", reply
.rp_line
);
1841 die (NULL
, "unexpected response;\n\t[%s] -- %s",
1842 rp_valstr (reply
.rp_val
), reply
.rp_line
);
1846 #endif /* MMDFMTS */
1856 #ifndef RELIABLE_SIGNALS
1857 SIGNAL (i
, SIG_IGN
);
1861 if (msgflags
& MINV
)
1865 if (!whomsw
|| checksw
)
1867 #endif /* MMDFMTS */
1870 if (!whomsw
|| checksw
)
1872 #endif /* SENDMTS */
1884 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1885 istat
= SIGNAL2 (SIGINT
, sigser
);
1886 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1887 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1897 SIGNAL (SIGHUP
, hstat
);
1898 SIGNAL (SIGINT
, istat
);
1899 SIGNAL (SIGQUIT
, qstat
);
1900 SIGNAL (SIGTERM
, tstat
);
1908 p_refile (char *file
)
1916 printf (" -- Filing Folder Copies --\n");
1917 for (i
= 0; i
< fccind
; i
++)
1918 fcc (file
, fccfold
[i
]);
1920 printf (" -- Folder Copies Filed --\n");
1925 * Call the `fileproc' to add the file to the folder.
1929 fcc (char *file
, char *folder
)
1936 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
1939 for (i
= 0; (child_id
= fork ()) == NOTOK
&& i
< 5; i
++)
1945 fprintf (stderr
, " %sFcc %s: ",
1946 msgstate
== RESENT
? "Resent-" : "", folder
);
1947 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
1951 /* see if we need to add `+' */
1952 snprintf (fold
, sizeof(fold
), "%s%s",
1953 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
1955 /* now exec the fileproc */
1956 execlp (fileproc
, r1bindex (fileproc
, '/'),
1957 "-link", "-file", file
, fold
, NULL
);
1961 if ((status
= pidwait (child_id
, OK
))) {
1963 fprintf (stderr
, " %sFcc %s: ",
1964 msgstate
== RESENT
? "Resent-" : "", folder
);
1965 pidstatus (status
, verbose
? stdout
: stderr
, NULL
);
1968 printf ("folder ok\n");
1980 die (char *what
, char *fmt
, ...)
1985 if (msgflags
& MINV
)
1989 if (!whomsw
|| checksw
)
1991 #endif /* MMDFMTS */
1994 if (!whomsw
|| checksw
)
1996 #endif /* SENDMTS */
1999 advertise (what
, NULL
, fmt
, ap
);
2007 * err_abrt() is used by the mm_ routines
2008 * do not, under *ANY* circumstances, remove it from post,
2009 * or you will lose *BIG*
2013 err_abrt (int code
, char *fmt
, ...)
2015 char buffer
[BUFSIZ
];
2018 snprintf (buffer
, sizeof(buffer
), "[%s]", rp_valstr (code
));
2021 advertise (buffer
, NULL
, fmt
, ap
);
2026 #endif /* MMDFMTS */