]>
diplodocus.org Git - nmh/blob - uip/post.c
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
))) {
729 if (MMailids
&& (hdr
->set
& MFRM
))
730 /* The user manually specified a From: address in their draft
731 and mts.conf turned on "mmailid", so we'll set things up to
732 use the actual email address embedded in the draft From:
733 (without the GECOS full name or angle brackets) as the
735 strncpy(from
, auxformat(mp
, 0), sizeof(from
) - 1);
740 tmpaddrs
.m_next
= mp
;
744 if (hdr
->flags
& HTRY
)
750 if (hdr
->flags
& HNIL
)
751 fprintf (out
, "%s: %s", name
, str
);
754 advise (NULL
, "%s: field requires at least one address", name
);
761 nameoutput
= linepos
= 0;
762 snprintf (namep
, sizeof(namep
), "%s%s",
763 !fill_in
&& (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
765 for (grp
= 0, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
766 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
767 pp
= akvalue (mp
->m_mbox
);
768 qp
= akvisible () ? mp
->m_mbox
: "";
771 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
772 while ((cp
= getname (pp
))) {
773 if (!(mp
= getm (cp
, NULL
, 0, AD_HOST
, NULL
))) {
777 if (hdr
->flags
& HBCC
)
780 mp
->m_ingrp
= np
->m_ingrp
;
783 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
786 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
))
787 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
796 if (hdr
->flags
& HBCC
)
799 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
802 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
);
806 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
812 if (grp
> 0 && (hdr
->flags
& HNGR
)) {
813 advise (NULL
, "%s: field does not allow groups", name
);
817 if (fill_in
&& grp
> 0)
828 char myhost
[BUFSIZ
], sigbuf
[BUFSIZ
];
835 strncpy (from
, adrsprintf (NULL
, NULL
), sizeof(from
));
836 strncpy (myhost
, LocalName (), sizeof(myhost
));
838 for (cp
= myhost
; *cp
; cp
++)
841 if ((cp
= getfullname ()) && *cp
) {
842 strncpy (sigbuf
, cp
, sizeof(sigbuf
));
843 snprintf (signature
, sizeof(signature
), "%s <%s>",
844 sigbuf
, adrsprintf (NULL
, NULL
));
845 if ((cp
= getname (signature
)) == NULL
)
846 adios (NULL
, "getname () failed -- you lose extraordinarily big");
847 if ((mp
= getm (cp
, NULL
, 0, AD_HOST
, NULL
)) == NULL
)
848 adios (NULL
, "bad signature '%s'", sigbuf
);
853 strncpy (signature
, adrsprintf (NULL
, NULL
), sizeof(signature
));
859 * Now that we've outputted the header fields in the draft
860 * message, we will now output any remaining header fields
861 * that we need to add/create.
865 finish_headers (FILE *out
)
869 if (whomsw
&& !fill_up
)
872 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
874 fprintf (out
, "Message-ID: <%d.%ld@%s>\n",
875 (int) getpid (), (long) tclock
, LocalName ());
876 if (msgflags
& MFRM
) {
877 /* There was already a From: in the draft. Don't add one. */
879 /* mts.conf didn't turn on mmailid, so we'll reveal the
880 user's actual account@thismachine address in a Sender:
881 header (and use it as the envelope From: later). */
882 fprintf (out
, "Sender: %s\n", from
);
885 /* Construct a From: header. */
886 fprintf (out
, "From: %s\n", signature
);
890 if (!(msgflags
& MVIS
))
891 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
895 if (!(msgflags
& MDAT
)) {
896 advise (NULL
, "message has no Date: header");
899 if (!(msgflags
& MFRM
)) {
900 advise (NULL
, "message has no From: header");
903 if (whomsw
&& !fill_up
)
906 #ifdef MMDFI /* sigh */
907 fprintf (out
, "Sender: %s\n", from
);
910 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
912 fprintf (out
, "Resent-Message-ID: <%d.%ld@%s>\n",
913 (int) getpid (), (long) tclock
, LocalName ());
915 fprintf (out
, "Resent-Sender: %s\n", from
);
917 fprintf (out
, "Resent-From: %s\n", signature
);
920 if (!(msgflags
& MVIS
))
921 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
926 adios (NULL
, "re-format message and try again");
928 adios (NULL
, "no addressees");
933 get_header (char *header
, struct headers
*table
)
937 for (h
= table
; h
->value
; h
++)
938 if (!strcasecmp (header
, h
->value
))
946 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
, unsigned int flags
)
952 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
954 if ((!fill_in
&& (flags
& (HBCC
| HDCC
))) || mp
->m_ingrp
)
958 fprintf (out
, "%s: ", name
);
959 linepos
+= (nameoutput
= strlen (name
) + 2);
962 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
963 mp
->m_pers
= getcpy (aka
);
965 if (mp
->m_gname
&& !fill_in
) {
966 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
976 if (linepos
!= nameoutput
) {
977 if (len
+ linepos
+ 2 > outputlinelen
)
978 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
988 return (flags
& HTRY
);
993 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
998 if (!fill_in
&& (flags
& HBCC
))
1002 fprintf (out
, "%s: ", name
);
1003 linepos
+= (nameoutput
= strlen (name
) + 2);
1005 linepos
-= strlen (group
);
1008 cp
= fill_in
? group
: concat (group
, ";", NULL
);
1011 if (linepos
> nameoutput
) {
1012 if (len
+ linepos
+ 2 > outputlinelen
) {
1013 fprintf (out
, ",\n%*s", nameoutput
, "");
1014 linepos
= nameoutput
;
1028 insert (struct mailname
*np
)
1030 struct mailname
*mp
;
1032 if (np
->m_mbox
== NULL
)
1035 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1036 : np
->m_type
== UUCPHOST
? &uuaddrs
1040 if (!strcasecmp (np
->m_host
, mp
->m_next
->m_host
)
1041 && !strcasecmp (np
->m_mbox
, mp
->m_next
->m_mbox
)
1042 && np
->m_bcc
== mp
->m_next
->m_bcc
)
1055 struct mailname
*mp
;
1057 printf ("-------\n\t-- Addresses --\nlocal:\t");
1058 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1059 printf ("%s%s%s", mp
->m_mbox
,
1060 mp
->m_bcc
? "[BCC]" : "",
1061 mp
->m_next
? ",\n\t" : "");
1063 printf ("\nnet:\t");
1064 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1065 printf ("%s%s@%s%s%s", mp
->m_path
? mp
->m_path
: "",
1066 mp
->m_mbox
, mp
->m_host
,
1067 mp
->m_bcc
? "[BCC]" : "",
1068 mp
->m_next
? ",\n\t" : "");
1070 printf ("\nuucp:\t");
1071 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1072 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1073 mp
->m_bcc
? "[BCC]" : "",
1074 mp
->m_next
? ",\n\t" : "");
1076 printf ("\n\t-- Folder Copies --\nfcc:\t");
1077 for (i
= 0; i
< fccind
; i
++)
1078 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1086 struct mailname
*mp
;
1088 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1089 if (annoaux (mp
) == NOTOK
)
1092 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1093 if (annoaux (mp
) == NOTOK
)
1096 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1097 if (annoaux (mp
) == NOTOK
)
1107 annoaux (struct mailname
*mp
)
1110 char buffer
[BUFSIZ
];
1112 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1113 i
= strlen (buffer
);
1115 return (write (pfd
, buffer
, i
) == i
? OK
: NOTOK
);
1120 insert_fcc (struct headers
*hdr
, char *pp
)
1124 for (cp
= pp
; isspace (*cp
); cp
++)
1126 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace (*pp
); pp
--)
1134 adios (NULL
, "too many %ss", hdr
->value
);
1135 fccfold
[fccind
++] = getcpy (cp
);
1143 make_bcc_file (int dashstuff
)
1150 strncpy (bccfil
, m_tmpfil ("bccs"), sizeof(bccfil
));
1151 if ((out
= fopen (bccfil
, "w")) == NULL
)
1152 adios (bccfil
, "unable to create");
1153 chmod (bccfil
, 0600);
1155 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1157 fprintf (out
, "Message-ID: <%d.%ld@%s>\n",
1158 (int) getpid (), (long) tclock
, LocalName ());
1159 fprintf (out
, "From: %s\n", signature
);
1161 fprintf (out
, "Subject: %s", subject
);
1162 fprintf (out
, "BCC:\n");
1165 * Use MIME encapsulation for Bcc messages
1171 * Check if any lines in the message clash with the
1172 * prefix for the MIME multipart separator. If there
1173 * is a clash, increment one of the letters in the
1174 * prefix and check again.
1176 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1177 adios (NULL
, "lost prefix start");
1178 while (find_prefix () == NOTOK
) {
1183 adios (NULL
, "can't find a unique delimiter string");
1188 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1189 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1190 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1192 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1198 * Do mhl filtering of Bcc messages instead
1199 * of MIME encapsulation.
1201 if (filter
!= NULL
) {
1202 vec
[0] = r1bindex (mhlproc
, '/');
1204 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
1208 adios ("fork", "unable to");
1211 dup2 (fileno (out
), 1);
1214 vec
[i
++] = "-forward";
1219 /* was the flag -[no]dashstuffing specified? */
1221 vec
[i
++] = "-dashstuffing";
1222 else if (dashstuff
< 0)
1223 vec
[i
++] = "-nodashstuffing";
1226 execvp (mhlproc
, vec
);
1227 fprintf (stderr
, "unable to exec ");
1232 pidXwait (child_id
, mhlproc
);
1236 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1237 adios (tmpfil
, "unable to re-open");
1240 * If using MIME encapsulation, or if the -nodashstuffing
1241 * flag was given, then just copy message. Else do
1242 * RFC934 quoting (dashstuffing).
1244 if (mime
|| dashstuff
< 0)
1245 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1247 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1251 fseek (out
, 0L, SEEK_END
);
1253 fprintf (out
, "\n--%s--\n", prefix
);
1255 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1261 * Scan message to check if any lines clash with
1262 * the prefix of the MIME multipart separator.
1269 char buffer
[BUFSIZ
];
1272 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1273 adios (tmpfil
, "unable to re-open");
1275 len
= strlen (prefix
);
1278 while (fgets (buffer
, sizeof(buffer
) - 1, in
))
1279 if (buffer
[0] == '-' && buffer
[1] == '-') {
1282 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1286 if (strcmp (buffer
+ 2, prefix
) == 0) {
1297 #define plural(x) (x == 1 ? "" : "s")
1302 if (badadr
&& unkadr
)
1303 die (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1304 badadr
, plural (badadr
), unkadr
, plural (badadr
));
1306 die (NULL
, "%d address%s unparsable", badadr
, plural (badadr
));
1308 die (NULL
, "%d addressee%s undeliverable", unkadr
, plural (unkadr
));
1313 do_addresses (int bccque
, int talk
)
1317 struct mailname
*lp
;
1320 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1321 if (lp
->m_bcc
? bccque
: !bccque
) {
1323 printf (" -- Local Recipients --\n");
1324 do_an_address (lp
, talk
);
1329 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1330 if (lp
->m_bcc
? bccque
: !bccque
) {
1332 printf (" -- UUCP Recipients --\n");
1333 do_an_address (lp
, talk
);
1338 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1339 if (lp
->m_bcc
? bccque
: !bccque
) {
1341 printf (" -- Network Recipients --\n");
1342 do_an_address (lp
, talk
);
1349 if (rp_isbad (retval
= mm_waend ()))
1350 die (NULL
, "problem ending addresses [%s]\n", rp_valstr (retval
));
1351 #endif /* MMDFMTS */
1354 if (rp_isbad (retval
= sm_waend ()))
1355 die (NULL
, "problem ending addresses; %s", rp_string (retval
));
1356 #endif /* SENDMTS */
1361 * MTS-SPECIFIC INTERACTION
1366 * SENDMAIL/SMTP routines
1372 post (char *file
, int bccque
, int talk
)
1377 onex
= !(msgflags
& MINV
) || bccque
;
1379 if (msgflags
& MINV
)
1380 printf (" -- Posting for %s Recipients --\n",
1381 bccque
? "Blind" : "Sighted");
1383 printf (" -- Posting for All Recipients --\n");
1388 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, watch
, verbose
,
1389 snoop
, onex
, queued
))
1390 || rp_isbad (retval
= sm_winit (smtpmode
, from
)))
1391 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1393 do_addresses (bccque
, talk
&& verbose
);
1394 if ((fd
= open (file
, O_RDONLY
)) == NOTOK
)
1395 die (file
, "unable to re-open");
1400 sm_end (onex
? OK
: DONE
);
1404 if (msgflags
& MINV
)
1405 printf (" -- %s Recipient Copies Posted --\n",
1406 bccque
? "Blind" : "Sighted");
1408 printf (" -- Recipient Copies Posted --\n");
1415 /* Address Verification */
1418 verify_all_addresses (int talk
)
1421 struct mailname
*lp
;
1425 if (!whomsw
|| checksw
)
1426 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, 0, 0, snoop
, 0, 0))
1427 || rp_isbad (retval
= sm_winit (smtpmode
, from
)))
1428 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1430 if (talk
&& !whomsw
)
1431 printf (" -- Address Verification --\n");
1432 if (talk
&& localaddrs
.m_next
)
1433 printf (" -- Local Recipients --\n");
1434 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1435 do_an_address (lp
, talk
);
1437 if (talk
&& uuaddrs
.m_next
)
1438 printf (" -- UUCP Recipients --\n");
1439 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1440 do_an_address (lp
, talk
);
1442 if (talk
&& netaddrs
.m_next
)
1443 printf (" -- Network Recipients --\n");
1444 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1445 do_an_address (lp
, talk
);
1448 if (talk
&& !whomsw
)
1449 printf (" -- Address Verification Successful --\n");
1451 if (!whomsw
|| checksw
)
1460 do_an_address (struct mailname
*lp
, int talk
)
1466 switch (lp
->m_type
) {
1470 strncpy (addr
, mbox
, sizeof(addr
));
1474 mbox
= auxformat (lp
, 0);
1476 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1479 default: /* let SendMail decide if the host is bad */
1482 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1487 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1489 if (whomsw
&& !checksw
) {
1497 switch (retval
= sm_wadr (mbox
, host
,
1498 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1501 printf ("address ok\n");
1507 fprintf (stderr
, " %s: ", addr
);
1508 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1509 rp_string (retval
));
1515 fprintf (stderr
, " %s: ", addr
);
1516 die (NULL
, "unexpected response; %s", rp_string (retval
));
1524 do_text (char *file
, int fd
)
1529 lseek (fd
, (off_t
) 0, SEEK_SET
);
1531 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1532 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1533 die (NULL
, "problem writing text; %s\n", rp_string (retval
));
1537 die (file
, "problem reading from");
1539 switch (retval
= sm_wtend ()) {
1545 die (NULL
, "posting failed; %s", rp_string (retval
));
1548 die (NULL
, "unexpected response; %s", rp_string (retval
));
1552 #endif /* SENDMTS */
1561 post (char *file
, int bccque
, int talk
)
1567 struct rp_bufstruct reply
;
1570 onex
= !(msgflags
& MINV
) || bccque
;
1572 if (msgflags
& MINV
)
1573 printf (" -- Posting for %s Recipients --\n",
1574 bccque
? "Blind" : "Sighted");
1576 printf (" -- Posting for All Recipients --\n");
1581 if (rp_isbad (retval
= mm_init ())
1582 || rp_isbad (retval
= mm_sbinit ())
1583 || rp_isbad (retval
= mm_winit (NULL
, submitopts
, from
)))
1584 die (NULL
, "problem initializing MMDF system [%s]",
1585 rp_valstr (retval
));
1587 if (rp_isbad (retval
= mm_rrply (&reply
, &len
)))
1588 die (NULL
, "problem with sender address [%s]",
1589 rp_valstr (retval
));
1592 do_addresses (bccque
, talk
&& verbose
);
1593 if ((fd
= open (file
, O_RDONLY
)) == NOTOK
)
1594 die (file
, "unable to re-open");
1604 if (msgflags
& MINV
)
1605 printf (" -- %s Recipient Copies Posted --\n",
1606 bccque
? "Blind" : "Sighted");
1608 printf (" -- Recipient Copies Posted --\n");
1613 /* Address Verification */
1616 verify_all_addresses (int talk
)
1619 struct mailname
*lp
;
1623 struct rp_bufstruct reply
;
1628 if (!whomsw
|| checksw
) {
1629 if (rp_isbad (retval
= mm_init ())
1630 || rp_isbad (retval
= mm_sbinit ())
1631 || rp_isbad (retval
= mm_winit (NULL
, submitopts
, from
)))
1632 die (NULL
, "problem initializing MMDF system [%s]",
1633 rp_valstr (retval
));
1635 if (rp_isbad (retval
= mm_rrply (&reply
, &len
)))
1636 die (NULL
, "problem with sender address [%s]", rp_valstr (retval
));
1640 if (talk
&& !whomsw
)
1641 printf (" -- Address Verification --\n");
1642 if (talk
&& localaddrs
.m_next
)
1643 printf (" -- Local Recipients --\n");
1644 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1645 do_an_address (lp
, talk
);
1647 if (talk
&& uuaddrs
.m_next
)
1648 printf (" -- UUCP Recipients --\n");
1649 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1650 do_an_address (lp
, talk
);
1652 if (talk
&& netaddrs
.m_next
)
1653 printf (" -- Network Recipients --\n");
1654 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1655 do_an_address (lp
, talk
);
1658 if (talk
&& !whomsw
)
1659 printf (" -- Address Verification Successful --\n");
1661 if (!whomsw
|| checksw
)
1670 do_an_address (struct mailname
*lp
, int talk
)
1673 char *mbox
, *host
, *text
, *path
;
1675 struct rp_bufstruct reply
;
1677 switch (lp
->m_type
) {
1680 host
= LocalName ();
1681 strncpy (addr
, mbox
, sizeof(addr
));
1685 fprintf (talk
? stdout
: stderr
, " %s!%s: %s\n",
1686 lp
->m_host
, lp
->m_mbox
, "not supported; UUCP address");
1691 default: /* let MMDF decide if the host is bad */
1694 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1699 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1701 if (whomsw
&& !checksw
) {
1711 path
= concat (lp
->m_path
, mbox
, "@", host
, NULL
);
1715 if (rp_isbad (retval
= mm_wadr (path
? NULL
: host
, path
? path
: mbox
))
1716 || rp_isbad (retval
= mm_rrply (&reply
, &len
)))
1717 die (NULL
, "problem submitting address [%s]", rp_valstr (retval
));
1719 switch (rp_gval (reply
.rp_val
)) {
1722 printf ("address ok\n");
1729 printf ("nameserver timeout - queued for checking\n");
1740 text
= "temporary nameserver failure";
1747 text
= "not deliverable";
1751 text
= "try again later";
1755 text
= "nothing done";
1760 fprintf (stderr
, " %s: ", addr
);
1761 text
= "unexpected response";
1762 die (NULL
, "%s;\n [%s] -- %s", text
,
1763 rp_valstr (reply
.rp_val
), reply
.rp_line
);
1767 fprintf (stderr
, " %s: ", addr
);
1768 fprintf (talk
? stdout
: stderr
, "%s;\n %s\n", text
, reply
.rp_line
);
1776 do_text (char *file
, int fd
)
1780 struct rp_bufstruct reply
;
1782 lseek (fd
, (off_t
) 0, SEEK_SET
);
1784 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1785 if (rp_isbad (mm_wtxt (buf
, state
)))
1786 die (NULL
, "problem writing text [%s]\n", rp_valstr (retval
));
1790 die (file
, "problem reading from");
1792 if (rp_isbad (retval
= mm_wtend ()))
1793 die (NULL
, "problem ending text [%s]\n", rp_valstr (retval
));
1795 if (rp_isbad (retval
= mm_rrply (&reply
, &state
)))
1796 die (NULL
, "problem getting submission status [%s]\n",
1797 rp_valstr (retval
));
1799 switch (rp_gval (reply
.rp_val
)) {
1805 die (NULL
, "you lose; %s", reply
.rp_line
);
1808 die (NULL
, "no delivery occurred; %s", reply
.rp_line
);
1811 die (NULL
, "try again later; %s", reply
.rp_line
);
1814 die (NULL
, "nothing done; %s", reply
.rp_line
);
1817 die (NULL
, "unexpected response;\n\t[%s] -- %s",
1818 rp_valstr (reply
.rp_val
), reply
.rp_line
);
1822 #endif /* MMDFMTS */
1832 #ifndef RELIABLE_SIGNALS
1833 SIGNAL (i
, SIG_IGN
);
1837 if (msgflags
& MINV
)
1841 if (!whomsw
|| checksw
)
1843 #endif /* MMDFMTS */
1846 if (!whomsw
|| checksw
)
1848 #endif /* SENDMTS */
1860 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1861 istat
= SIGNAL2 (SIGINT
, sigser
);
1862 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1863 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1873 SIGNAL (SIGHUP
, hstat
);
1874 SIGNAL (SIGINT
, istat
);
1875 SIGNAL (SIGQUIT
, qstat
);
1876 SIGNAL (SIGTERM
, tstat
);
1884 p_refile (char *file
)
1892 printf (" -- Filing Folder Copies --\n");
1893 for (i
= 0; i
< fccind
; i
++)
1894 fcc (file
, fccfold
[i
]);
1896 printf (" -- Folder Copies Filed --\n");
1901 * Call the `fileproc' to add the file to the folder.
1905 fcc (char *file
, char *folder
)
1912 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
1915 for (i
= 0; (child_id
= fork ()) == NOTOK
&& i
< 5; i
++)
1921 fprintf (stderr
, " %sFcc %s: ",
1922 msgstate
== RESENT
? "Resent-" : "", folder
);
1923 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
1927 /* see if we need to add `+' */
1928 snprintf (fold
, sizeof(fold
), "%s%s",
1929 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
1931 /* now exec the fileproc */
1932 execlp (fileproc
, r1bindex (fileproc
, '/'),
1933 "-link", "-file", file
, fold
, NULL
);
1937 if ((status
= pidwait (child_id
, OK
))) {
1939 fprintf (stderr
, " %sFcc %s: ",
1940 msgstate
== RESENT
? "Resent-" : "", folder
);
1941 pidstatus (status
, verbose
? stdout
: stderr
, NULL
);
1944 printf ("folder ok\n");
1956 die (char *what
, char *fmt
, ...)
1961 if (msgflags
& MINV
)
1965 if (!whomsw
|| checksw
)
1967 #endif /* MMDFMTS */
1970 if (!whomsw
|| checksw
)
1972 #endif /* SENDMTS */
1975 advertise (what
, NULL
, fmt
, ap
);
1983 * err_abrt() is used by the mm_ routines
1984 * do not, under *ANY* circumstances, remove it from post,
1985 * or you will lose *BIG*
1989 err_abrt (int code
, char *fmt
, ...)
1991 char buffer
[BUFSIZ
];
1994 snprintf (buffer
, sizeof(buffer
), "[%s]", rp_valstr (code
));
1997 advertise (buffer
, NULL
, fmt
, ap
);
2002 #endif /* MMDFMTS */