]>
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 static struct swit switches
[] = {
59 { "alias aliasfile", 0 },
61 { "check", -5 }, /* interface from whom */
63 { "nocheck", -7 }, /* interface from whom */
67 { "dist", -4 }, /* interface from dist */
69 { "filter filterfile", 0 },
77 { "library directory", -7 }, /* interface from send, whom */
95 { "whom", -4 }, /* interface from whom */
97 { "width columns", 0 },
102 #define BITSTUFFSW 22
103 { "dashstuffing", -12 }, /* should we dashstuff BCC messages? */
104 #define NBITSTUFFSW 23
105 { "nodashstuffing", -14 },
107 { "mail", -4 }, /* specify MAIL smtp mode */
109 { "saml", -4 }, /* specify SAML smtp mode */
111 { "send", -4 }, /* specify SEND smtp mode */
113 { "soml", -4 }, /* specify SOML smtp mode */
115 { "idanno number", -6 }, /* interface from send */
117 { "deliver address-list", -7 },
119 { "client host", -6 },
121 { "server host", -6 }, /* specify alternate SMTP server */
123 { "snoop", -5 }, /* snoop the SMTP transaction */
125 { "fill-in file", -7 },
143 * flags for headers->flags
145 #define HNOP 0x0000 /* just used to keep .set around */
146 #define HBAD 0x0001 /* bad header - don't let it through */
147 #define HADR 0x0002 /* header has an address field */
148 #define HSUB 0x0004 /* Subject: header */
149 #define HTRY 0x0008 /* try to send to addrs on header */
150 #define HBCC 0x0010 /* don't output this header */
151 #define HMNG 0x0020 /* munge this header */
152 #define HNGR 0x0040 /* no groups allowed in this header */
153 #define HFCC 0x0080 /* FCC: type header */
154 #define HNIL 0x0100 /* okay for this header not to have addrs */
155 #define HIGN 0x0200 /* ignore this header */
156 #define HDCC 0x0400 /* another undocumented feature */
159 * flags for headers->set
161 #define MFRM 0x0001 /* we've seen a From: */
162 #define MDAT 0x0002 /* we've seen a Date: */
163 #define MRFM 0x0004 /* we've seen a Resent-From: */
164 #define MVIS 0x0008 /* we've seen sighted addrs */
165 #define MINV 0x0010 /* we've seen blind addrs */
168 static struct headers NHeaders
[] = {
169 { "Return-Path", HBAD
, 0 },
170 { "Received", HBAD
, 0 },
171 { "Reply-To", HADR
|HNGR
, 0 },
172 { "From", HADR
|HNGR
, MFRM
},
173 { "Sender", HADR
|HBAD
, 0 },
175 { "Subject", HSUB
, 0 },
176 { "To", HADR
|HTRY
, MVIS
},
177 { "cc", HADR
|HTRY
, MVIS
},
178 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, MINV
},
179 { "Dcc", HADR
|HTRY
|HDCC
|HNIL
, MVIS
}, /* sorta cc & bcc combined */
180 { "Message-ID", HBAD
, 0 },
185 static struct headers RHeaders
[] = {
186 { "Resent-Reply-To", HADR
|HNGR
, 0 },
187 { "Resent-From", HADR
|HNGR
, MRFM
},
188 { "Resent-Sender", HADR
|HBAD
, 0 },
189 { "Resent-Date", HBAD
, 0 },
190 { "Resent-Subject", HSUB
, 0 },
191 { "Resent-To", HADR
|HTRY
, MVIS
},
192 { "Resent-cc", HADR
|HTRY
, MVIS
},
193 { "Resent-Bcc", HADR
|HTRY
|HBCC
, MINV
},
194 { "Resent-Message-ID", HBAD
, 0 },
195 { "Resent-Fcc", HFCC
, 0 },
196 { "Reply-To", HADR
, 0 },
197 { "From", HADR
|HNGR
, MFRM
},
199 { "Sender", HADR
|HNGR
|HMNG
, 0 },
201 { "Sender", HADR
|HNGR
, 0 },
203 { "Date", HNOP
, MDAT
},
204 { "To", HADR
|HNIL
, 0 },
205 { "cc", HADR
|HNIL
, 0 },
206 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, 0 },
211 static short fccind
= 0; /* index into fccfold[] */
212 static short outputlinelen
= OUTPUTLINELEN
;
214 static int pfd
= NOTOK
; /* fd to write annotation list to */
215 static uid_t myuid
= -1; /* my user id */
216 static gid_t mygid
= -1; /* my group id */
217 static int recipients
= 0; /* how many people will get a copy */
218 static int unkadr
= 0; /* how many of those were unknown */
219 static int badadr
= 0; /* number of bad addrs */
220 static int badmsg
= 0; /* message has bad semantics */
221 static int verbose
= 0; /* spell it out */
222 static int format
= 1; /* format addresses */
223 static int mime
= 0; /* use MIME-style encapsulations for Bcc */
224 static int msgid
= 0; /* add msgid */
225 static int debug
= 0; /* debugging post */
226 static int watch
= 0; /* watch the delivery process */
227 static int whomsw
= 0; /* we are whom not post */
228 static int checksw
= 0; /* whom -check */
229 static int linepos
=0; /* putadr()'s position on the line */
230 static int nameoutput
=0; /* putadr() has output header name */
232 static unsigned msgflags
= 0; /* what we've seen */
236 static int msgstate
= NORMAL
;
238 static time_t tclock
= 0; /* the time we started (more or less) */
240 static SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
242 static char tmpfil
[BUFSIZ
];
243 static char bccfil
[BUFSIZ
];
245 static char from
[BUFSIZ
]; /* my network address */
246 static char signature
[BUFSIZ
]; /* my signature */
247 static char *filter
= NULL
; /* the filter for BCC'ing */
248 static char *subject
= NULL
; /* the subject field for BCC'ing */
249 static char *fccfold
[FCCS
]; /* foldernames for FCC'ing */
251 static struct headers
*hdrtab
; /* table for the message we're doing */
253 static struct mailname localaddrs
={NULL
}; /* local addrs */
254 static struct mailname netaddrs
={NULL
}; /* network addrs */
255 static struct mailname uuaddrs
={NULL
}; /* uucp addrs */
256 static struct mailname tmpaddrs
={NULL
}; /* temporary queue */
259 static char *submitmode
= "m"; /* deliver to mailbox only */
260 static char submitopts
[6] = "vl"; /* initial options for submit */
264 static int snoop
= 0;
265 static int smtpmode
= S_MAIL
;
266 static char *clientsw
= NULL
;
267 static char *serversw
= NULL
;
269 extern struct smtp sm_reply
;
272 static char prefix
[] = "----- =_aaaaaaaaaa";
274 static int fill_up
= 0;
275 static char *fill_in
= NULL
;
276 static char *partno
= NULL
;
277 static int queued
= 0;
282 static void putfmt (char *, char *, FILE *);
283 static void start_headers (void);
284 static void finish_headers (FILE *);
285 static int get_header (char *, struct headers
*);
286 static int putadr (char *, char *, struct mailname
*, FILE *, unsigned int);
287 static void putgrp (char *, char *, FILE *, unsigned int);
288 static int insert (struct mailname
*);
289 static void pl (void);
290 static void anno (void);
291 static int annoaux (struct mailname
*);
292 static void insert_fcc (struct headers
*, char *);
293 static void make_bcc_file (int);
294 static void verify_all_addresses (int);
295 static void chkadr (void);
296 static void sigon (void);
297 static void sigoff (void);
298 static void p_refile (char *);
299 static void fcc (char *, char *);
300 static void die (char *, char *, ...);
301 static void post (char *, int, int);
302 static void do_text (char *file
, int fd
);
303 static void do_an_address (struct mailname
*, int);
304 static void do_addresses (int, int);
305 static int find_prefix (void);
309 main (int argc
, char **argv
)
311 int state
, compnum
, dashstuff
= 0;
312 char *cp
, *msg
= NULL
, **argp
, **arguments
;
313 char buf
[BUFSIZ
], name
[NAMESZ
];
317 setlocale(LC_ALL
, "");
319 invo_name
= r1bindex (argv
[0], '/');
321 /* foil search of user profile/context */
322 if (context_foil (NULL
) == -1)
325 mts_init (invo_name
);
326 arguments
= getarguments (invo_name
, argc
, argv
, 0);
329 #if defined(MMDFMTS) && defined(MMDFII)
330 mmdf_init (invo_name
);
331 #endif /* MMDFMTS and MMDFII */
333 while ((cp
= *argp
++)) {
335 switch (smatch (++cp
, switches
)) {
337 ambigsw (cp
, switches
);
340 adios (NULL
, "-%s unknown", cp
);
343 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
344 print_help (buf
, switches
, 0);
347 print_version(invo_name
);
351 if (!(cp
= *argp
++) || *cp
== '-')
352 adios (NULL
, "missing argument to %s", argp
[-2]);
353 /* create a minimal context */
354 if (context_foil (cp
) == -1)
359 if (!(cp
= *argp
++) || *cp
== '-')
360 adios (NULL
, "missing argument to %s", argp
[-2]);
361 if ((state
= alias (cp
)) != AK_OK
)
362 adios (NULL
, "aliasing error in %s - %s",
363 cp
, akerror (state
));
382 if (!(filter
= *argp
++) || *filter
== '-')
383 adios (NULL
, "missing argument to %s", argp
[-2]);
438 if (!(cp
= *argp
++) || *cp
== '-')
439 adios (NULL
, "missing argument to %s", argp
[-2]);
440 if ((outputlinelen
= atoi (cp
)) < 10)
441 adios (NULL
, "impossible width %d", outputlinelen
);
445 if (!(cp
= *argp
++) || *cp
== '-')
446 adios (NULL
, "missing argument to %s", argp
[-2]);
447 if ((pfd
= atoi (cp
)) <= 2)
448 adios (NULL
, "bad argument %s %s", argp
[-2], cp
);
455 case SOMLSW
: /* for right now, sigh... */
465 if (!(cp
= *argp
++) || *cp
== '-')
466 adios (NULL
, "missing argument to %s", argp
[-2]);
472 if (!(cp
= *argp
++) || *cp
== '-')
473 adios (NULL
, "missing argument to %s", argp
[-2]);
492 if (!(clientsw
= *argp
++) || *clientsw
== '-')
493 adios (NULL
, "missing argument to %s", argp
[-2]);
496 if (!(serversw
= *argp
++) || *serversw
== '-')
497 adios (NULL
, "missing argument to %s", argp
[-2]);
505 if (!(fill_in
= *argp
++) || *fill_in
== '-')
506 adios (NULL
, "missing argument to %s", argp
[-2]);
512 if (!(partno
= *argp
++) || *partno
== '-')
513 adios (NULL
, "missing argument to %s", argp
[-2]);
522 adios (NULL
, "only one message at a time!");
530 adios (NULL
, "usage: %s [switches] file", invo_name
);
532 if (outputlinelen
< 10)
533 adios (NULL
, "impossible width %d", outputlinelen
);
535 if ((in
= fopen (msg
, "r")) == NULL
)
536 adios (msg
, "unable to open");
541 discard (out
= stdout
); /* XXX: reference discard() to help loader */
544 if ((out
= fopen (fill_in
? fill_in
: "/dev/null", "w")) == NULL
)
545 adios ("/dev/null", "unable to open");
547 strncpy (tmpfil
, m_scratch ("", m_maildir (invo_name
)),
549 if ((out
= fopen (tmpfil
, "w")) == NULL
) {
550 strncpy (tmpfil
, m_tmpfil (invo_name
), sizeof(tmpfil
));
551 if ((out
= fopen (tmpfil
, "w")) == NULL
)
552 adios (tmpfil
, "unable to create");
554 chmod (tmpfil
, 0600);
558 hdrtab
= msgstate
== NORMAL
? NHeaders
: RHeaders
;
560 for (compnum
= 1, state
= FLD
;;) {
561 switch (state
= m_getfld (state
, name
, buf
, sizeof(buf
), in
)) {
566 cp
= add (buf
, NULL
);
567 while (state
== FLDPLUS
) {
568 state
= m_getfld (state
, name
, buf
, sizeof(buf
), in
);
571 putfmt (name
, cp
, out
);
575 finish_headers (out
);
580 finish_headers (out
);
581 if (whomsw
&& !fill_in
)
583 fprintf (out
, "\n%s", buf
);
584 while (state
== BODY
) {
585 state
= m_getfld (state
, name
, buf
, sizeof(buf
), in
);
591 finish_headers (out
);
596 adios (NULL
, "message format error in component #%d", compnum
);
599 adios (NULL
, "getfld() returned %d", state
);
615 /* If we are doing a "whom" check */
618 verify_all_addresses (1);
623 strcat (submitopts
, submitmode
);
625 strcat (submitopts
, "nw");
628 if (msgflags
& MINV
) {
629 make_bcc_file (dashstuff
);
630 if (msgflags
& MVIS
) {
631 verify_all_addresses (verbose
);
632 post (tmpfil
, 0, verbose
);
634 post (bccfil
, 1, verbose
);
637 post (tmpfil
, 0, isatty (1));
644 printf (partno
? "Partial Message #%s Processed\n" : "Message Processed\n",
655 putfmt (char *name
, char *str
, FILE *out
)
657 int count
, grp
, i
, keep
;
660 struct mailname
*mp
, *np
;
663 while (*str
== ' ' || *str
== '\t')
666 if (msgstate
== NORMAL
&& uprf (name
, "resent")) {
667 advise (NULL
, "illegal header line -- %s:", name
);
672 if ((i
= get_header (name
, hdrtab
)) == NOTOK
) {
673 fprintf (out
, "%s: %s", name
, str
);
678 if (hdr
->flags
& HIGN
) {
680 fprintf (out
, "%s: %s", name
, str
);
683 if (hdr
->flags
& HBAD
) {
685 fprintf (out
, "%s: %s", name
, str
);
687 advise (NULL
, "illegal header line -- %s:", name
);
692 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
694 if (hdr
->flags
& HSUB
)
695 subject
= subject
? add (str
, add ("\t", subject
)) : getcpy (str
);
696 if (hdr
->flags
& HFCC
) {
698 fprintf (out
, "%s: %s", name
, str
);
702 if ((cp
= strrchr(str
, '\n')))
704 for (cp
= pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
706 insert_fcc (hdr
, pp
);
708 insert_fcc (hdr
, pp
);
712 if (!(hdr
->flags
& HADR
)) {
713 fprintf (out
, "%s: %s", name
, str
);
717 tmpaddrs
.m_next
= NULL
;
718 for (count
= 0; (cp
= getname (str
)); count
++)
719 if ((mp
= getm (cp
, NULL
, 0, AD_HOST
, NULL
))) {
723 tmpaddrs
.m_next
= mp
;
727 if (hdr
->flags
& HTRY
)
733 if (hdr
->flags
& HNIL
)
734 fprintf (out
, "%s: %s", name
, str
);
737 advise (NULL
, "%s: field requires at least one address", name
);
744 nameoutput
= linepos
= 0;
745 snprintf (namep
, sizeof(namep
), "%s%s",
746 !fill_in
&& (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
748 for (grp
= 0, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
749 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
750 pp
= akvalue (mp
->m_mbox
);
751 qp
= akvisible () ? mp
->m_mbox
: "";
754 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
755 while ((cp
= getname (pp
))) {
756 if (!(mp
= getm (cp
, NULL
, 0, AD_HOST
, NULL
))) {
760 if (hdr
->flags
& HBCC
)
763 mp
->m_ingrp
= np
->m_ingrp
;
766 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
769 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
))
770 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
779 if (hdr
->flags
& HBCC
)
782 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
785 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
);
789 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
795 if (grp
> 0 && (hdr
->flags
& HNGR
)) {
796 advise (NULL
, "%s: field does not allow groups", name
);
800 if (fill_in
&& grp
> 0)
811 char myhost
[BUFSIZ
], sigbuf
[BUFSIZ
];
818 strncpy (from
, adrsprintf (NULL
, NULL
), sizeof(from
));
819 strncpy (myhost
, LocalName (), sizeof(myhost
));
821 for (cp
= myhost
; *cp
; cp
++)
824 if ((cp
= getfullname ()) && *cp
) {
825 strncpy (sigbuf
, cp
, sizeof(sigbuf
));
826 snprintf (signature
, sizeof(signature
), "%s <%s>",
827 sigbuf
, adrsprintf (NULL
, NULL
));
828 if ((cp
= getname (signature
)) == NULL
)
829 adios (NULL
, "getname () failed -- you lose extraordinarily big");
830 if ((mp
= getm (cp
, NULL
, 0, AD_HOST
, NULL
)) == NULL
)
831 adios (NULL
, "bad signature '%s'", sigbuf
);
836 strncpy (signature
, adrsprintf (NULL
, NULL
), sizeof(signature
));
842 * Now that we've outputted the header fields in the draft
843 * message, we will now output any remaining header fields
844 * that we need to add/create.
848 finish_headers (FILE *out
)
852 if (whomsw
&& !fill_up
)
855 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
857 fprintf (out
, "Message-ID: <%d.%ld@%s>\n",
858 (int) getpid (), (long) tclock
, LocalName ());
860 fprintf (out
, "Sender: %s\n", from
);
862 fprintf (out
, "From: %s\n", signature
);
866 if (!(msgflags
& MVIS
))
867 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
871 if (!(msgflags
& MDAT
)) {
872 advise (NULL
, "message has no Date: header");
875 if (!(msgflags
& MFRM
)) {
876 advise (NULL
, "message has no From: header");
879 if (whomsw
&& !fill_up
)
882 #ifdef MMDFI /* sigh */
883 fprintf (out
, "Sender: %s\n", from
);
886 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
888 fprintf (out
, "Resent-Message-ID: <%d.%ld@%s>\n",
889 (int) getpid (), (long) tclock
, LocalName ());
891 fprintf (out
, "Resent-Sender: %s\n", from
);
893 fprintf (out
, "Resent-From: %s\n", signature
);
896 if (!(msgflags
& MVIS
))
897 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
902 adios (NULL
, "re-format message and try again");
904 adios (NULL
, "no addressees");
909 get_header (char *header
, struct headers
*table
)
913 for (h
= table
; h
->value
; h
++)
914 if (!strcasecmp (header
, h
->value
))
922 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
, unsigned int flags
)
928 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
930 if ((!fill_in
&& (flags
& (HBCC
| HDCC
))) || mp
->m_ingrp
)
934 fprintf (out
, "%s: ", name
);
935 linepos
+= (nameoutput
= strlen (name
) + 2);
938 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
939 mp
->m_pers
= getcpy (aka
);
941 if (mp
->m_gname
&& !fill_in
) {
942 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
952 if (linepos
!= nameoutput
) {
953 if (len
+ linepos
+ 2 > outputlinelen
)
954 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
964 return (flags
& HTRY
);
969 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
974 if (!fill_in
&& (flags
& HBCC
))
978 fprintf (out
, "%s: ", name
);
979 linepos
+= (nameoutput
= strlen (name
) + 2);
981 linepos
-= strlen (group
);
984 cp
= fill_in
? group
: concat (group
, ";", NULL
);
987 if (linepos
> nameoutput
) {
988 if (len
+ linepos
+ 2 > outputlinelen
) {
989 fprintf (out
, ",\n%*s", nameoutput
, "");
990 linepos
= nameoutput
;
1004 insert (struct mailname
*np
)
1006 struct mailname
*mp
;
1008 if (np
->m_mbox
== NULL
)
1011 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1012 : np
->m_type
== UUCPHOST
? &uuaddrs
1016 if (!strcasecmp (np
->m_host
, mp
->m_next
->m_host
)
1017 && !strcasecmp (np
->m_mbox
, mp
->m_next
->m_mbox
)
1018 && np
->m_bcc
== mp
->m_next
->m_bcc
)
1031 struct mailname
*mp
;
1033 printf ("-------\n\t-- Addresses --\nlocal:\t");
1034 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1035 printf ("%s%s%s", mp
->m_mbox
,
1036 mp
->m_bcc
? "[BCC]" : "",
1037 mp
->m_next
? ",\n\t" : "");
1039 printf ("\nnet:\t");
1040 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1041 printf ("%s%s@%s%s%s", mp
->m_path
? mp
->m_path
: "",
1042 mp
->m_mbox
, mp
->m_host
,
1043 mp
->m_bcc
? "[BCC]" : "",
1044 mp
->m_next
? ",\n\t" : "");
1046 printf ("\nuucp:\t");
1047 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1048 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1049 mp
->m_bcc
? "[BCC]" : "",
1050 mp
->m_next
? ",\n\t" : "");
1052 printf ("\n\t-- Folder Copies --\nfcc:\t");
1053 for (i
= 0; i
< fccind
; i
++)
1054 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1062 struct mailname
*mp
;
1064 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1065 if (annoaux (mp
) == NOTOK
)
1068 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1069 if (annoaux (mp
) == NOTOK
)
1072 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1073 if (annoaux (mp
) == NOTOK
)
1083 annoaux (struct mailname
*mp
)
1086 char buffer
[BUFSIZ
];
1088 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1089 i
= strlen (buffer
);
1091 return (write (pfd
, buffer
, i
) == i
? OK
: NOTOK
);
1096 insert_fcc (struct headers
*hdr
, char *pp
)
1100 for (cp
= pp
; isspace (*cp
); cp
++)
1102 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace (*pp
); pp
--)
1110 adios (NULL
, "too many %ss", hdr
->value
);
1111 fccfold
[fccind
++] = getcpy (cp
);
1119 make_bcc_file (int dashstuff
)
1126 strncpy (bccfil
, m_tmpfil ("bccs"), sizeof(bccfil
));
1127 if ((out
= fopen (bccfil
, "w")) == NULL
)
1128 adios (bccfil
, "unable to create");
1129 chmod (bccfil
, 0600);
1131 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1133 fprintf (out
, "Message-ID: <%d.%ld@%s>\n",
1134 (int) getpid (), (long) tclock
, LocalName ());
1135 fprintf (out
, "From: %s\n", signature
);
1137 fprintf (out
, "Subject: %s", subject
);
1138 fprintf (out
, "BCC:\n");
1141 * Use MIME encapsulation for Bcc messages
1147 * Check if any lines in the message clash with the
1148 * prefix for the MIME multipart separator. If there
1149 * is a clash, increment one of the letters in the
1150 * prefix and check again.
1152 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1153 adios (NULL
, "lost prefix start");
1154 while (find_prefix () == NOTOK
) {
1159 adios (NULL
, "can't find a unique delimiter string");
1164 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1165 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1166 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1168 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1174 * Do mhl filtering of Bcc messages instead
1175 * of MIME encapsulation.
1177 if (filter
!= NULL
) {
1178 vec
[0] = r1bindex (mhlproc
, '/');
1180 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
1184 adios ("fork", "unable to");
1187 dup2 (fileno (out
), 1);
1190 vec
[i
++] = "-forward";
1195 /* was the flag -[no]dashstuffing specified? */
1197 vec
[i
++] = "-dashstuffing";
1198 else if (dashstuff
< 0)
1199 vec
[i
++] = "-nodashstuffing";
1202 execvp (mhlproc
, vec
);
1203 fprintf (stderr
, "unable to exec ");
1208 pidXwait (child_id
, mhlproc
);
1212 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1213 adios (tmpfil
, "unable to re-open");
1216 * If using MIME encapsulation, or if the -nodashstuffing
1217 * flag was given, then just copy message. Else do
1218 * RFC934 quoting (dashstuffing).
1220 if (mime
|| dashstuff
< 0)
1221 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1223 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1227 fseek (out
, 0L, SEEK_END
);
1229 fprintf (out
, "\n--%s--\n", prefix
);
1231 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1237 * Scan message to check if any lines clash with
1238 * the prefix of the MIME multipart separator.
1245 char buffer
[BUFSIZ
];
1248 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1249 adios (tmpfil
, "unable to re-open");
1251 len
= strlen (prefix
);
1254 while (fgets (buffer
, sizeof(buffer
) - 1, in
))
1255 if (buffer
[0] == '-' && buffer
[1] == '-') {
1258 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1262 if (strcmp (buffer
+ 2, prefix
) == 0) {
1273 #define plural(x) (x == 1 ? "" : "s")
1278 if (badadr
&& unkadr
)
1279 die (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1280 badadr
, plural (badadr
), unkadr
, plural (badadr
));
1282 die (NULL
, "%d address%s unparsable", badadr
, plural (badadr
));
1284 die (NULL
, "%d addressee%s undeliverable", unkadr
, plural (unkadr
));
1289 do_addresses (int bccque
, int talk
)
1293 struct mailname
*lp
;
1296 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1297 if (lp
->m_bcc
? bccque
: !bccque
) {
1299 printf (" -- Local Recipients --\n");
1300 do_an_address (lp
, talk
);
1305 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1306 if (lp
->m_bcc
? bccque
: !bccque
) {
1308 printf (" -- UUCP Recipients --\n");
1309 do_an_address (lp
, talk
);
1314 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1315 if (lp
->m_bcc
? bccque
: !bccque
) {
1317 printf (" -- Network Recipients --\n");
1318 do_an_address (lp
, talk
);
1325 if (rp_isbad (retval
= mm_waend ()))
1326 die (NULL
, "problem ending addresses [%s]\n", rp_valstr (retval
));
1327 #endif /* MMDFMTS */
1330 if (rp_isbad (retval
= sm_waend ()))
1331 die (NULL
, "problem ending addresses; %s", rp_string (retval
));
1332 #endif /* SENDMTS */
1337 * MTS-SPECIFIC INTERACTION
1342 * SENDMAIL/SMTP routines
1348 post (char *file
, int bccque
, int talk
)
1353 onex
= !(msgflags
& MINV
) || bccque
;
1355 if (msgflags
& MINV
)
1356 printf (" -- Posting for %s Recipients --\n",
1357 bccque
? "Blind" : "Sighted");
1359 printf (" -- Posting for All Recipients --\n");
1364 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, watch
, verbose
,
1365 snoop
, onex
, queued
))
1366 || rp_isbad (retval
= sm_winit (smtpmode
, from
)))
1367 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1369 do_addresses (bccque
, talk
&& verbose
);
1370 if ((fd
= open (file
, O_RDONLY
)) == NOTOK
)
1371 die (file
, "unable to re-open");
1376 sm_end (onex
? OK
: DONE
);
1380 if (msgflags
& MINV
)
1381 printf (" -- %s Recipient Copies Posted --\n",
1382 bccque
? "Blind" : "Sighted");
1384 printf (" -- Recipient Copies Posted --\n");
1391 /* Address Verification */
1394 verify_all_addresses (int talk
)
1397 struct mailname
*lp
;
1401 if (!whomsw
|| checksw
)
1402 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, 0, 0, snoop
, 0, 0))
1403 || rp_isbad (retval
= sm_winit (smtpmode
, from
)))
1404 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1406 if (talk
&& !whomsw
)
1407 printf (" -- Address Verification --\n");
1408 if (talk
&& localaddrs
.m_next
)
1409 printf (" -- Local Recipients --\n");
1410 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1411 do_an_address (lp
, talk
);
1413 if (talk
&& uuaddrs
.m_next
)
1414 printf (" -- UUCP Recipients --\n");
1415 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1416 do_an_address (lp
, talk
);
1418 if (talk
&& netaddrs
.m_next
)
1419 printf (" -- Network Recipients --\n");
1420 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1421 do_an_address (lp
, talk
);
1424 if (talk
&& !whomsw
)
1425 printf (" -- Address Verification Successful --\n");
1427 if (!whomsw
|| checksw
)
1436 do_an_address (struct mailname
*lp
, int talk
)
1442 switch (lp
->m_type
) {
1446 strncpy (addr
, mbox
, sizeof(addr
));
1450 mbox
= auxformat (lp
, 0);
1452 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1455 default: /* let SendMail decide if the host is bad */
1458 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1463 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1465 if (whomsw
&& !checksw
) {
1473 switch (retval
= sm_wadr (mbox
, host
,
1474 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1477 printf ("address ok\n");
1483 fprintf (stderr
, " %s: ", addr
);
1484 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1485 rp_string (retval
));
1491 fprintf (stderr
, " %s: ", addr
);
1492 die (NULL
, "unexpected response; %s", rp_string (retval
));
1500 do_text (char *file
, int fd
)
1505 lseek (fd
, (off_t
) 0, SEEK_SET
);
1507 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1508 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1509 die (NULL
, "problem writing text; %s\n", rp_string (retval
));
1513 die (file
, "problem reading from");
1515 switch (retval
= sm_wtend ()) {
1521 die (NULL
, "posting failed; %s", rp_string (retval
));
1524 die (NULL
, "unexpected response; %s", rp_string (retval
));
1528 #endif /* SENDMTS */
1537 post (char *file
, int bccque
, int talk
)
1543 struct rp_bufstruct reply
;
1546 onex
= !(msgflags
& MINV
) || bccque
;
1548 if (msgflags
& MINV
)
1549 printf (" -- Posting for %s Recipients --\n",
1550 bccque
? "Blind" : "Sighted");
1552 printf (" -- Posting for All Recipients --\n");
1557 if (rp_isbad (retval
= mm_init ())
1558 || rp_isbad (retval
= mm_sbinit ())
1559 || rp_isbad (retval
= mm_winit (NULL
, submitopts
, from
)))
1560 die (NULL
, "problem initializing MMDF system [%s]",
1561 rp_valstr (retval
));
1563 if (rp_isbad (retval
= mm_rrply (&reply
, &len
)))
1564 die (NULL
, "problem with sender address [%s]",
1565 rp_valstr (retval
));
1568 do_addresses (bccque
, talk
&& verbose
);
1569 if ((fd
= open (file
, O_RDONLY
)) == NOTOK
)
1570 die (file
, "unable to re-open");
1580 if (msgflags
& MINV
)
1581 printf (" -- %s Recipient Copies Posted --\n",
1582 bccque
? "Blind" : "Sighted");
1584 printf (" -- Recipient Copies Posted --\n");
1589 /* Address Verification */
1592 verify_all_addresses (int talk
)
1595 struct mailname
*lp
;
1599 struct rp_bufstruct reply
;
1604 if (!whomsw
|| checksw
) {
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]", rp_valstr (retval
));
1616 if (talk
&& !whomsw
)
1617 printf (" -- Address Verification --\n");
1618 if (talk
&& localaddrs
.m_next
)
1619 printf (" -- Local Recipients --\n");
1620 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1621 do_an_address (lp
, talk
);
1623 if (talk
&& uuaddrs
.m_next
)
1624 printf (" -- UUCP Recipients --\n");
1625 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1626 do_an_address (lp
, talk
);
1628 if (talk
&& netaddrs
.m_next
)
1629 printf (" -- Network Recipients --\n");
1630 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1631 do_an_address (lp
, talk
);
1634 if (talk
&& !whomsw
)
1635 printf (" -- Address Verification Successful --\n");
1637 if (!whomsw
|| checksw
)
1646 do_an_address (struct mailname
*lp
, int talk
)
1649 char *mbox
, *host
, *text
, *path
;
1651 struct rp_bufstruct reply
;
1653 switch (lp
->m_type
) {
1656 host
= LocalName ();
1657 strncpy (addr
, mbox
, sizeof(addr
));
1661 fprintf (talk
? stdout
: stderr
, " %s!%s: %s\n",
1662 lp
->m_host
, lp
->m_mbox
, "not supported; UUCP address");
1667 default: /* let MMDF decide if the host is bad */
1670 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1675 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1677 if (whomsw
&& !checksw
) {
1687 path
= concat (lp
->m_path
, mbox
, "@", host
, NULL
);
1691 if (rp_isbad (retval
= mm_wadr (path
? NULL
: host
, path
? path
: mbox
))
1692 || rp_isbad (retval
= mm_rrply (&reply
, &len
)))
1693 die (NULL
, "problem submitting address [%s]", rp_valstr (retval
));
1695 switch (rp_gval (reply
.rp_val
)) {
1698 printf ("address ok\n");
1705 printf ("nameserver timeout - queued for checking\n");
1716 text
= "temporary nameserver failure";
1723 text
= "not deliverable";
1727 text
= "try again later";
1731 text
= "nothing done";
1736 fprintf (stderr
, " %s: ", addr
);
1737 text
= "unexpected response";
1738 die (NULL
, "%s;\n [%s] -- %s", text
,
1739 rp_valstr (reply
.rp_val
), reply
.rp_line
);
1743 fprintf (stderr
, " %s: ", addr
);
1744 fprintf (talk
? stdout
: stderr
, "%s;\n %s\n", text
, reply
.rp_line
);
1752 do_text (char *file
, int fd
)
1756 struct rp_bufstruct reply
;
1758 lseek (fd
, (off_t
) 0, SEEK_SET
);
1760 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1761 if (rp_isbad (mm_wtxt (buf
, state
)))
1762 die (NULL
, "problem writing text [%s]\n", rp_valstr (retval
));
1766 die (file
, "problem reading from");
1768 if (rp_isbad (retval
= mm_wtend ()))
1769 die (NULL
, "problem ending text [%s]\n", rp_valstr (retval
));
1771 if (rp_isbad (retval
= mm_rrply (&reply
, &state
)))
1772 die (NULL
, "problem getting submission status [%s]\n",
1773 rp_valstr (retval
));
1775 switch (rp_gval (reply
.rp_val
)) {
1781 die (NULL
, "you lose; %s", reply
.rp_line
);
1784 die (NULL
, "no delivery occurred; %s", reply
.rp_line
);
1787 die (NULL
, "try again later; %s", reply
.rp_line
);
1790 die (NULL
, "nothing done; %s", reply
.rp_line
);
1793 die (NULL
, "unexpected response;\n\t[%s] -- %s",
1794 rp_valstr (reply
.rp_val
), reply
.rp_line
);
1798 #endif /* MMDFMTS */
1808 #ifndef RELIABLE_SIGNALS
1809 SIGNAL (i
, SIG_IGN
);
1813 if (msgflags
& MINV
)
1817 if (!whomsw
|| checksw
)
1819 #endif /* MMDFMTS */
1822 if (!whomsw
|| checksw
)
1824 #endif /* SENDMTS */
1836 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1837 istat
= SIGNAL2 (SIGINT
, sigser
);
1838 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1839 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1849 SIGNAL (SIGHUP
, hstat
);
1850 SIGNAL (SIGINT
, istat
);
1851 SIGNAL (SIGQUIT
, qstat
);
1852 SIGNAL (SIGTERM
, tstat
);
1860 p_refile (char *file
)
1868 printf (" -- Filing Folder Copies --\n");
1869 for (i
= 0; i
< fccind
; i
++)
1870 fcc (file
, fccfold
[i
]);
1872 printf (" -- Folder Copies Filed --\n");
1877 * Call the `fileproc' to add the file to the folder.
1881 fcc (char *file
, char *folder
)
1888 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
1891 for (i
= 0; (child_id
= fork ()) == NOTOK
&& i
< 5; i
++)
1897 fprintf (stderr
, " %sFcc %s: ",
1898 msgstate
== RESENT
? "Resent-" : "", folder
);
1899 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
1903 /* see if we need to add `+' */
1904 snprintf (fold
, sizeof(fold
), "%s%s",
1905 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
1907 /* now exec the fileproc */
1908 execlp (fileproc
, r1bindex (fileproc
, '/'),
1909 "-link", "-file", file
, fold
, NULL
);
1913 if ((status
= pidwait (child_id
, OK
))) {
1915 fprintf (stderr
, " %sFcc %s: ",
1916 msgstate
== RESENT
? "Resent-" : "", folder
);
1917 pidstatus (status
, verbose
? stdout
: stderr
, NULL
);
1920 printf ("folder ok\n");
1932 die (char *what
, char *fmt
, ...)
1937 if (msgflags
& MINV
)
1941 if (!whomsw
|| checksw
)
1943 #endif /* MMDFMTS */
1946 if (!whomsw
|| checksw
)
1948 #endif /* SENDMTS */
1951 advertise (what
, NULL
, fmt
, ap
);
1959 * err_abrt() is used by the mm_ routines
1960 * do not, under *ANY* circumstances, remove it from post,
1961 * or you will lose *BIG*
1965 err_abrt (int code
, char *fmt
, ...)
1967 char buffer
[BUFSIZ
];
1970 snprintf (buffer
, sizeof(buffer
), "[%s]", rp_valstr (code
));
1973 advertise (buffer
, NULL
, fmt
, ap
);
1978 #endif /* MMDFMTS */