]>
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>
24 # include <mts/mmdf/util.h>
25 # include <mts/mmdf/mmdf.h>
29 * Currently smtp and sendmail use
30 * the same interface for posting.
37 # include <mts/smtp/smtp.h>
41 # define uptolow(c) ((isalpha(c) && isupper (c)) ? tolower (c) : (c))
44 #define FCCS 10 /* max number of fccs allowed */
46 static struct swit switches
[] = {
48 { "alias aliasfile", 0 },
50 { "check", -5 }, /* interface from whom */
52 { "nocheck", -7 }, /* interface from whom */
56 { "dist", -4 }, /* interface from dist */
58 { "filter filterfile", 0 },
66 { "library directory", -7 }, /* interface from send, whom */
84 { "whom", -4 }, /* interface from whom */
86 { "width columns", 0 },
92 { "dashstuffing", -12 }, /* should we dashstuff BCC messages? */
93 #define NBITSTUFFSW 23
94 { "nodashstuffing", -14 },
96 { "mail", -4 }, /* specify MAIL smtp mode */
98 { "saml", -4 }, /* specify SAML smtp mode */
100 { "send", -4 }, /* specify SEND smtp mode */
102 { "soml", -4 }, /* specify SOML smtp mode */
104 { "idanno number", -6 }, /* interface from send */
106 { "deliver address-list", -7 },
108 { "client host", -6 },
110 { "server host", -6 }, /* specify alternate SMTP server */
112 { "snoop", -5 }, /* snoop the SMTP transaction */
114 { "fill-in file", -7 },
132 * flags for headers->flags
134 #define HNOP 0x0000 /* just used to keep .set around */
135 #define HBAD 0x0001 /* bad header - don't let it through */
136 #define HADR 0x0002 /* header has an address field */
137 #define HSUB 0x0004 /* Subject: header */
138 #define HTRY 0x0008 /* try to send to addrs on header */
139 #define HBCC 0x0010 /* don't output this header */
140 #define HMNG 0x0020 /* munge this header */
141 #define HNGR 0x0040 /* no groups allowed in this header */
142 #define HFCC 0x0080 /* FCC: type header */
143 #define HNIL 0x0100 /* okay for this header not to have addrs */
144 #define HIGN 0x0200 /* ignore this header */
145 #define HDCC 0x0400 /* another undocumented feature */
148 * flags for headers->set
150 #define MFRM 0x0001 /* we've seen a From: */
151 #define MDAT 0x0002 /* we've seen a Date: */
152 #define MRFM 0x0004 /* we've seen a Resent-From: */
153 #define MVIS 0x0008 /* we've seen sighted addrs */
154 #define MINV 0x0010 /* we've seen blind addrs */
157 static struct headers NHeaders
[] = {
158 { "Return-Path", HBAD
, 0 },
159 { "Received", HBAD
, 0 },
160 { "Reply-To", HADR
|HNGR
, 0 },
161 { "From", HADR
|HNGR
, MFRM
},
162 { "Sender", HADR
|HBAD
, 0 },
164 { "Subject", HSUB
, 0 },
165 { "To", HADR
|HTRY
, MVIS
},
166 { "cc", HADR
|HTRY
, MVIS
},
167 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, MINV
},
168 { "Dcc", HADR
|HTRY
|HDCC
|HNIL
, MVIS
}, /* sorta cc & bcc combined */
169 { "Message-ID", HBAD
, 0 },
174 static struct headers RHeaders
[] = {
175 { "Resent-Reply-To", HADR
|HNGR
, 0 },
176 { "Resent-From", HADR
|HNGR
, MRFM
},
177 { "Resent-Sender", HADR
|HBAD
, 0 },
178 { "Resent-Date", HBAD
, 0 },
179 { "Resent-Subject", HSUB
, 0 },
180 { "Resent-To", HADR
|HTRY
, MVIS
},
181 { "Resent-cc", HADR
|HTRY
, MVIS
},
182 { "Resent-Bcc", HADR
|HTRY
|HBCC
, MINV
},
183 { "Resent-Message-ID", HBAD
, 0 },
184 { "Resent-Fcc", HFCC
, 0 },
185 { "Reply-To", HADR
, 0 },
186 { "From", HADR
|HNGR
, MFRM
},
188 { "Sender", HADR
|HNGR
|HMNG
, 0 },
190 { "Sender", HADR
|HNGR
, 0 },
192 { "Date", HNOP
, MDAT
},
193 { "To", HADR
|HNIL
, 0 },
194 { "cc", HADR
|HNIL
, 0 },
195 { "Bcc", HADR
|HTRY
|HBCC
|HNIL
, 0 },
200 static short fccind
= 0; /* index into fccfold[] */
201 static short outputlinelen
= OUTPUTLINELEN
;
203 static int pfd
= NOTOK
; /* fd to write annotation list to */
204 static uid_t myuid
= -1; /* my user id */
205 static gid_t mygid
= -1; /* my group id */
206 static int recipients
= 0; /* how many people will get a copy */
207 static int unkadr
= 0; /* how many of those were unknown */
208 static int badadr
= 0; /* number of bad addrs */
209 static int badmsg
= 0; /* message has bad semantics */
210 static int verbose
= 0; /* spell it out */
211 static int format
= 1; /* format addresses */
212 static int mime
= 0; /* use MIME-style encapsulations for Bcc */
213 static int msgid
= 0; /* add msgid */
214 static int debug
= 0; /* debugging post */
215 static int watch
= 0; /* watch the delivery process */
216 static int whomsw
= 0; /* we are whom not post */
217 static int checksw
= 0; /* whom -check */
218 static int linepos
=0; /* putadr()'s position on the line */
219 static int nameoutput
=0; /* putadr() has output header name */
221 static unsigned msgflags
= 0; /* what we've seen */
225 static int msgstate
= NORMAL
;
227 static time_t tclock
= 0; /* the time we started (more or less) */
229 static SIGNAL_HANDLER hstat
, istat
, qstat
, tstat
;
231 static char tmpfil
[BUFSIZ
];
232 static char bccfil
[BUFSIZ
];
234 static char from
[BUFSIZ
]; /* my network address */
235 static char signature
[BUFSIZ
]; /* my signature */
236 static char *filter
= NULL
; /* the filter for BCC'ing */
237 static char *subject
= NULL
; /* the subject field for BCC'ing */
238 static char *fccfold
[FCCS
]; /* foldernames for FCC'ing */
240 static struct headers
*hdrtab
; /* table for the message we're doing */
242 static struct mailname localaddrs
={NULL
}; /* local addrs */
243 static struct mailname netaddrs
={NULL
}; /* network addrs */
244 static struct mailname uuaddrs
={NULL
}; /* uucp addrs */
245 static struct mailname tmpaddrs
={NULL
}; /* temporary queue */
248 static char *submitmode
= "m"; /* deliver to mailbox only */
249 static char submitopts
[6] = "vl"; /* initial options for submit */
253 static int snoop
= 0;
254 static int smtpmode
= S_MAIL
;
255 static char *clientsw
= NULL
;
256 static char *serversw
= NULL
;
258 extern struct smtp sm_reply
;
261 static char prefix
[] = "----- =_aaaaaaaaaa";
263 static int fill_up
= 0;
264 static char *fill_in
= NULL
;
265 static char *partno
= NULL
;
266 static int queued
= 0;
271 static void putfmt (char *, char *, FILE *);
272 static void start_headers (void);
273 static void finish_headers (FILE *);
274 static int get_header (char *, struct headers
*);
275 static int putadr (char *, char *, struct mailname
*, FILE *, unsigned int);
276 static void putgrp (char *, char *, FILE *, unsigned int);
277 static int insert (struct mailname
*);
278 static void pl (void);
279 static void anno (void);
280 static int annoaux (struct mailname
*);
281 static void insert_fcc (struct headers
*, char *);
282 static void make_bcc_file (int);
283 static void verify_all_addresses (int);
284 static void chkadr (void);
285 static void sigon (void);
286 static void sigoff (void);
287 static void p_refile (char *);
288 static void fcc (char *, char *);
289 static void die (char *, char *, ...);
290 static void post (char *, int, int);
291 static void do_text (char *file
, int fd
);
292 static void do_an_address (struct mailname
*, int);
293 static void do_addresses (int, int);
294 static int find_prefix (void);
298 main (int argc
, char **argv
)
300 int state
, compnum
, dashstuff
= 0;
301 char *cp
, *msg
= NULL
, **argp
, **arguments
;
302 char buf
[BUFSIZ
], name
[NAMESZ
];
306 setlocale(LC_ALL
, "");
308 invo_name
= r1bindex (argv
[0], '/');
310 /* foil search of user profile/context */
311 if (context_foil (NULL
) == -1)
314 mts_init (invo_name
);
315 arguments
= getarguments (invo_name
, argc
, argv
, 0);
318 #if defined(MMDFMTS) && defined(MMDFII)
319 mmdf_init (invo_name
);
320 #endif /* MMDFMTS and MMDFII */
322 while ((cp
= *argp
++)) {
324 switch (smatch (++cp
, switches
)) {
326 ambigsw (cp
, switches
);
329 adios (NULL
, "-%s unknown", cp
);
332 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
333 print_help (buf
, switches
, 0);
336 print_version(invo_name
);
340 if (!(cp
= *argp
++) || *cp
== '-')
341 adios (NULL
, "missing argument to %s", argp
[-2]);
342 /* create a minimal context */
343 if (context_foil (cp
) == -1)
348 if (!(cp
= *argp
++) || *cp
== '-')
349 adios (NULL
, "missing argument to %s", argp
[-2]);
350 if ((state
= alias (cp
)) != AK_OK
)
351 adios (NULL
, "aliasing error in %s - %s",
352 cp
, akerror (state
));
371 if (!(filter
= *argp
++) || *filter
== '-')
372 adios (NULL
, "missing argument to %s", argp
[-2]);
427 if (!(cp
= *argp
++) || *cp
== '-')
428 adios (NULL
, "missing argument to %s", argp
[-2]);
429 if ((outputlinelen
= atoi (cp
)) < 10)
430 adios (NULL
, "impossible width %d", outputlinelen
);
434 if (!(cp
= *argp
++) || *cp
== '-')
435 adios (NULL
, "missing argument to %s", argp
[-2]);
436 if ((pfd
= atoi (cp
)) <= 2)
437 adios (NULL
, "bad argument %s %s", argp
[-2], cp
);
444 case SOMLSW
: /* for right now, sigh... */
454 if (!(cp
= *argp
++) || *cp
== '-')
455 adios (NULL
, "missing argument to %s", argp
[-2]);
461 if (!(cp
= *argp
++) || *cp
== '-')
462 adios (NULL
, "missing argument to %s", argp
[-2]);
481 if (!(clientsw
= *argp
++) || *clientsw
== '-')
482 adios (NULL
, "missing argument to %s", argp
[-2]);
485 if (!(serversw
= *argp
++) || *serversw
== '-')
486 adios (NULL
, "missing argument to %s", argp
[-2]);
494 if (!(fill_in
= *argp
++) || *fill_in
== '-')
495 adios (NULL
, "missing argument to %s", argp
[-2]);
501 if (!(partno
= *argp
++) || *partno
== '-')
502 adios (NULL
, "missing argument to %s", argp
[-2]);
511 adios (NULL
, "only one message at a time!");
519 adios (NULL
, "usage: %s [switches] file", invo_name
);
521 if (outputlinelen
< 10)
522 adios (NULL
, "impossible width %d", outputlinelen
);
524 if ((in
= fopen (msg
, "r")) == NULL
)
525 adios (msg
, "unable to open");
530 discard (out
= stdout
); /* XXX: reference discard() to help loader */
533 if ((out
= fopen (fill_in
? fill_in
: "/dev/null", "w")) == NULL
)
534 adios ("/dev/null", "unable to open");
536 strncpy (tmpfil
, m_scratch ("", m_maildir (invo_name
)),
538 if ((out
= fopen (tmpfil
, "w")) == NULL
) {
539 strncpy (tmpfil
, m_tmpfil (invo_name
), sizeof(tmpfil
));
540 if ((out
= fopen (tmpfil
, "w")) == NULL
)
541 adios (tmpfil
, "unable to create");
543 chmod (tmpfil
, 0600);
547 hdrtab
= msgstate
== NORMAL
? NHeaders
: RHeaders
;
549 for (compnum
= 1, state
= FLD
;;) {
550 switch (state
= m_getfld (state
, name
, buf
, sizeof(buf
), in
)) {
555 cp
= add (buf
, NULL
);
556 while (state
== FLDPLUS
) {
557 state
= m_getfld (state
, name
, buf
, sizeof(buf
), in
);
560 putfmt (name
, cp
, out
);
564 finish_headers (out
);
569 finish_headers (out
);
570 if (whomsw
&& !fill_in
)
572 fprintf (out
, "\n%s", buf
);
573 while (state
== BODY
) {
574 state
= m_getfld (state
, name
, buf
, sizeof(buf
), in
);
580 finish_headers (out
);
585 adios (NULL
, "message format error in component #%d", compnum
);
588 adios (NULL
, "getfld() returned %d", state
);
604 /* If we are doing a "whom" check */
607 verify_all_addresses (1);
612 strcat (submitopts
, submitmode
);
614 strcat (submitopts
, "nw");
617 if (msgflags
& MINV
) {
618 make_bcc_file (dashstuff
);
619 if (msgflags
& MVIS
) {
620 verify_all_addresses (verbose
);
621 post (tmpfil
, 0, verbose
);
623 post (bccfil
, 1, verbose
);
626 post (tmpfil
, 0, isatty (1));
633 printf (partno
? "Partial Message #%s Processed\n" : "Message Processed\n",
644 putfmt (char *name
, char *str
, FILE *out
)
646 int count
, grp
, i
, keep
;
649 struct mailname
*mp
, *np
;
652 while (*str
== ' ' || *str
== '\t')
655 if (msgstate
== NORMAL
&& uprf (name
, "resent")) {
656 advise (NULL
, "illegal header line -- %s:", name
);
661 if ((i
= get_header (name
, hdrtab
)) == NOTOK
) {
662 fprintf (out
, "%s: %s", name
, str
);
667 if (hdr
->flags
& HIGN
) {
669 fprintf (out
, "%s: %s", name
, str
);
672 if (hdr
->flags
& HBAD
) {
674 fprintf (out
, "%s: %s", name
, str
);
676 advise (NULL
, "illegal header line -- %s:", name
);
681 msgflags
|= (hdr
->set
& ~(MVIS
| MINV
));
683 if (hdr
->flags
& HSUB
)
684 subject
= subject
? add (str
, add ("\t", subject
)) : getcpy (str
);
685 if (hdr
->flags
& HFCC
) {
687 fprintf (out
, "%s: %s", name
, str
);
691 if ((cp
= strrchr(str
, '\n')))
693 for (cp
= pp
= str
; (cp
= strchr(pp
, ',')); pp
= cp
) {
695 insert_fcc (hdr
, pp
);
697 insert_fcc (hdr
, pp
);
701 if (!(hdr
->flags
& HADR
)) {
702 fprintf (out
, "%s: %s", name
, str
);
706 tmpaddrs
.m_next
= NULL
;
707 for (count
= 0; (cp
= getname (str
)); count
++)
708 if ((mp
= getm (cp
, NULL
, 0, AD_HOST
, NULL
))) {
712 tmpaddrs
.m_next
= mp
;
716 if (hdr
->flags
& HTRY
)
722 if (hdr
->flags
& HNIL
)
723 fprintf (out
, "%s: %s", name
, str
);
726 advise (NULL
, "%s: field requires at least one address", name
);
733 nameoutput
= linepos
= 0;
734 snprintf (namep
, sizeof(namep
), "%s%s",
735 !fill_in
&& (hdr
->flags
& HMNG
) ? "Original-" : "", name
);
737 for (grp
= 0, mp
= tmpaddrs
.m_next
; mp
; mp
= np
)
738 if (mp
->m_nohost
) { /* also used to test (hdr->flags & HTRY) */
739 pp
= akvalue (mp
->m_mbox
);
740 qp
= akvisible () ? mp
->m_mbox
: "";
743 putgrp (namep
, np
->m_gname
, out
, hdr
->flags
);
744 while ((cp
= getname (pp
))) {
745 if (!(mp
= getm (cp
, NULL
, 0, AD_HOST
, NULL
))) {
749 if (hdr
->flags
& HBCC
)
752 mp
->m_ingrp
= np
->m_ingrp
;
755 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
758 if (putadr (namep
, qp
, mp
, out
, hdr
->flags
))
759 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
768 if (hdr
->flags
& HBCC
)
771 putgrp (namep
, mp
->m_gname
, out
, hdr
->flags
);
774 keep
= putadr (namep
, "", mp
, out
, hdr
->flags
);
778 msgflags
|= (hdr
->set
& (MVIS
| MINV
));
784 if (grp
> 0 && (hdr
->flags
& HNGR
)) {
785 advise (NULL
, "%s: field does not allow groups", name
);
789 if (fill_in
&& grp
> 0)
800 char myhost
[BUFSIZ
], sigbuf
[BUFSIZ
];
807 strncpy (from
, adrsprintf (NULL
, NULL
), sizeof(from
));
808 strncpy (myhost
, LocalName (), sizeof(myhost
));
810 for (cp
= myhost
; *cp
; cp
++)
813 if ((cp
= getfullname ()) && *cp
) {
814 strncpy (sigbuf
, cp
, sizeof(sigbuf
));
815 snprintf (signature
, sizeof(signature
), "%s <%s>",
816 sigbuf
, adrsprintf (NULL
, NULL
));
817 if ((cp
= getname (signature
)) == NULL
)
818 adios (NULL
, "getname () failed -- you lose extraordinarily big");
819 if ((mp
= getm (cp
, NULL
, 0, AD_HOST
, NULL
)) == NULL
)
820 adios (NULL
, "bad signature '%s'", sigbuf
);
825 strncpy (signature
, adrsprintf (NULL
, NULL
), sizeof(signature
));
831 * Now that we've outputted the header fields in the draft
832 * message, we will now output any remaining header fields
833 * that we need to add/create.
837 finish_headers (FILE *out
)
841 if (whomsw
&& !fill_up
)
844 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
846 fprintf (out
, "Message-ID: <%d.%ld@%s>\n",
847 (int) getpid (), tclock
, LocalName ());
849 fprintf (out
, "Sender: %s\n", from
);
851 fprintf (out
, "From: %s\n", signature
);
855 if (!(msgflags
& MVIS
))
856 fprintf (out
, "Bcc: Blind Distribution List: ;\n");
860 if (!(msgflags
& MDAT
)) {
861 advise (NULL
, "message has no Date: header");
864 if (!(msgflags
& MFRM
)) {
865 advise (NULL
, "message has no From: header");
868 if (whomsw
&& !fill_up
)
871 #ifdef MMDFI /* sigh */
872 fprintf (out
, "Sender: %s\n", from
);
875 fprintf (out
, "Resent-Date: %s\n", dtime (&tclock
, 0));
877 fprintf (out
, "Resent-Message-ID: <%d.%ld@%s>\n",
878 (int) getpid (), tclock
, LocalName ());
880 fprintf (out
, "Resent-Sender: %s\n", from
);
882 fprintf (out
, "Resent-From: %s\n", signature
);
885 if (!(msgflags
& MVIS
))
886 fprintf (out
, "Resent-Bcc: Blind Re-Distribution List: ;\n");
891 adios (NULL
, "re-format message and try again");
893 adios (NULL
, "no addressees");
898 get_header (char *header
, struct headers
*table
)
902 for (h
= table
; h
->value
; h
++)
903 if (!strcasecmp (header
, h
->value
))
911 putadr (char *name
, char *aka
, struct mailname
*mp
, FILE *out
, unsigned int flags
)
917 if (mp
->m_mbox
== NULL
|| ((flags
& HTRY
) && !insert (mp
)))
919 if ((!fill_in
&& (flags
& (HBCC
| HDCC
))) || mp
->m_ingrp
)
923 fprintf (out
, "%s: ", name
);
924 linepos
+= (nameoutput
= strlen (name
) + 2);
927 if (*aka
&& mp
->m_type
!= UUCPHOST
&& !mp
->m_pers
)
928 mp
->m_pers
= getcpy (aka
);
930 if (mp
->m_gname
&& !fill_in
) {
931 snprintf (buffer
, sizeof(buffer
), "%s;", mp
->m_gname
);
941 if (linepos
!= nameoutput
) {
942 if (len
+ linepos
+ 2 > outputlinelen
)
943 fprintf (out
, ",\n%*s", linepos
= nameoutput
, "");
953 return (flags
& HTRY
);
958 putgrp (char *name
, char *group
, FILE *out
, unsigned int flags
)
963 if (!fill_in
&& (flags
& HBCC
))
967 fprintf (out
, "%s: ", name
);
968 linepos
+= (nameoutput
= strlen (name
) + 2);
970 linepos
-= strlen (group
);
973 cp
= fill_in
? group
: concat (group
, ";", NULL
);
976 if (linepos
> nameoutput
) {
977 if (len
+ linepos
+ 2 > outputlinelen
) {
978 fprintf (out
, ",\n%*s", nameoutput
, "");
979 linepos
= nameoutput
;
993 insert (struct mailname
*np
)
997 if (np
->m_mbox
== NULL
)
1000 for (mp
= np
->m_type
== LOCALHOST
? &localaddrs
1001 : np
->m_type
== UUCPHOST
? &uuaddrs
1005 if (!strcasecmp (np
->m_host
, mp
->m_next
->m_host
)
1006 && !strcasecmp (np
->m_mbox
, mp
->m_next
->m_mbox
)
1007 && np
->m_bcc
== mp
->m_next
->m_bcc
)
1020 struct mailname
*mp
;
1022 printf ("-------\n\t-- Addresses --\nlocal:\t");
1023 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1024 printf ("%s%s%s", mp
->m_mbox
,
1025 mp
->m_bcc
? "[BCC]" : "",
1026 mp
->m_next
? ",\n\t" : "");
1028 printf ("\nnet:\t");
1029 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1030 printf ("%s%s@%s%s%s", mp
->m_path
? mp
->m_path
: "",
1031 mp
->m_mbox
, mp
->m_host
,
1032 mp
->m_bcc
? "[BCC]" : "",
1033 mp
->m_next
? ",\n\t" : "");
1035 printf ("\nuucp:\t");
1036 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1037 printf ("%s!%s%s%s", mp
->m_host
, mp
->m_mbox
,
1038 mp
->m_bcc
? "[BCC]" : "",
1039 mp
->m_next
? ",\n\t" : "");
1041 printf ("\n\t-- Folder Copies --\nfcc:\t");
1042 for (i
= 0; i
< fccind
; i
++)
1043 printf ("%s%s", fccfold
[i
], i
+ 1 < fccind
? ",\n\t" : "");
1051 struct mailname
*mp
;
1053 for (mp
= localaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1054 if (annoaux (mp
) == NOTOK
)
1057 for (mp
= netaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1058 if (annoaux (mp
) == NOTOK
)
1061 for (mp
= uuaddrs
.m_next
; mp
; mp
= mp
->m_next
)
1062 if (annoaux (mp
) == NOTOK
)
1072 annoaux (struct mailname
*mp
)
1075 char buffer
[BUFSIZ
];
1077 snprintf (buffer
, sizeof(buffer
), "%s\n", adrformat (mp
));
1078 i
= strlen (buffer
);
1080 return (write (pfd
, buffer
, i
) == i
? OK
: NOTOK
);
1085 insert_fcc (struct headers
*hdr
, char *pp
)
1089 for (cp
= pp
; isspace (*cp
); cp
++)
1091 for (pp
+= strlen (pp
) - 1; pp
> cp
&& isspace (*pp
); pp
--)
1099 adios (NULL
, "too many %ss", hdr
->value
);
1100 fccfold
[fccind
++] = getcpy (cp
);
1108 make_bcc_file (int dashstuff
)
1115 strncpy (bccfil
, m_tmpfil ("bccs"), sizeof(bccfil
));
1116 if ((out
= fopen (bccfil
, "w")) == NULL
)
1117 adios (bccfil
, "unable to create");
1118 chmod (bccfil
, 0600);
1120 fprintf (out
, "Date: %s\n", dtime (&tclock
, 0));
1122 fprintf (out
, "Message-ID: <%d.%ld@%s>\n",
1123 (int) getpid (), tclock
, LocalName ());
1124 fprintf (out
, "From: %s\n", signature
);
1126 fprintf (out
, "Subject: %s", subject
);
1127 fprintf (out
, "BCC:\n");
1130 * Use MIME encapsulation for Bcc messages
1136 * Check if any lines in the message clash with the
1137 * prefix for the MIME multipart separator. If there
1138 * is a clash, increment one of the letters in the
1139 * prefix and check again.
1141 if ((cp
= strchr(prefix
, 'a')) == NULL
)
1142 adios (NULL
, "lost prefix start");
1143 while (find_prefix () == NOTOK
) {
1148 adios (NULL
, "can't find a unique delimiter string");
1153 fprintf (out
, "%s: %s\n%s: multipart/digest; boundary=\"",
1154 VRSN_FIELD
, VRSN_VALUE
, TYPE_FIELD
);
1155 fprintf (out
, "%s\"\n\n--%s\n\n", prefix
, prefix
);
1157 fprintf (out
, "\n------- Blind-Carbon-Copy\n\n");
1163 * Do mhl filtering of Bcc messages instead
1164 * of MIME encapsulation.
1166 if (filter
!= NULL
) {
1167 vec
[0] = r1bindex (mhlproc
, '/');
1169 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
1173 adios ("fork", "unable to");
1176 dup2 (fileno (out
), 1);
1179 vec
[i
++] = "-forward";
1184 /* was the flag -[no]dashstuffing specified? */
1186 vec
[i
++] = "-dashstuffing";
1187 else if (dashstuff
< 0)
1188 vec
[i
++] = "-nodashstuffing";
1191 execvp (mhlproc
, vec
);
1192 fprintf (stderr
, "unable to exec ");
1197 pidXwait (child_id
, mhlproc
);
1201 if ((fd
= open (tmpfil
, O_RDONLY
)) == NOTOK
)
1202 adios (tmpfil
, "unable to re-open");
1205 * If using MIME encapsulation, or if the -nodashstuffing
1206 * flag was given, then just copy message. Else do
1207 * RFC934 quoting (dashstuffing).
1209 if (mime
|| dashstuff
< 0)
1210 cpydata (fd
, fileno (out
), tmpfil
, bccfil
);
1212 cpydgst (fd
, fileno (out
), tmpfil
, bccfil
);
1216 fseek (out
, 0L, SEEK_END
);
1218 fprintf (out
, "\n--%s--\n", prefix
);
1220 fprintf (out
, "\n------- End of Blind-Carbon-Copy\n");
1226 * Scan message to check if any lines clash with
1227 * the prefix of the MIME multipart separator.
1234 char buffer
[BUFSIZ
];
1237 if ((in
= fopen (tmpfil
, "r")) == NULL
)
1238 adios (tmpfil
, "unable to re-open");
1240 len
= strlen (prefix
);
1243 while (fgets (buffer
, sizeof(buffer
) - 1, in
))
1244 if (buffer
[0] == '-' && buffer
[1] == '-') {
1247 for (cp
= buffer
+ strlen (buffer
) - 1; cp
>= buffer
; cp
--)
1251 if (strcmp (buffer
+ 2, prefix
) == 0) {
1262 #define plural(x) (x == 1 ? "" : "s")
1267 if (badadr
&& unkadr
)
1268 die (NULL
, "%d address%s unparsable, %d addressee%s undeliverable",
1269 badadr
, plural (badadr
), unkadr
, plural (badadr
));
1271 die (NULL
, "%d address%s unparsable", badadr
, plural (badadr
));
1273 die (NULL
, "%d addressee%s undeliverable", unkadr
, plural (unkadr
));
1278 do_addresses (int bccque
, int talk
)
1282 struct mailname
*lp
;
1285 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1286 if (lp
->m_bcc
? bccque
: !bccque
) {
1288 printf (" -- Local Recipients --\n");
1289 do_an_address (lp
, talk
);
1294 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1295 if (lp
->m_bcc
? bccque
: !bccque
) {
1297 printf (" -- UUCP Recipients --\n");
1298 do_an_address (lp
, talk
);
1303 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1304 if (lp
->m_bcc
? bccque
: !bccque
) {
1306 printf (" -- Network Recipients --\n");
1307 do_an_address (lp
, talk
);
1314 if (rp_isbad (retval
= mm_waend ()))
1315 die (NULL
, "problem ending addresses [%s]\n", rp_valstr (retval
));
1316 #endif /* MMDFMTS */
1319 if (rp_isbad (retval
= sm_waend ()))
1320 die (NULL
, "problem ending addresses; %s", rp_string (retval
));
1321 #endif /* SENDMTS */
1326 * MTS-SPECIFIC INTERACTION
1331 * SENDMAIL/SMTP routines
1337 post (char *file
, int bccque
, int talk
)
1342 onex
= !(msgflags
& MINV
) || bccque
;
1344 if (msgflags
& MINV
)
1345 printf (" -- Posting for %s Recipients --\n",
1346 bccque
? "Blind" : "Sighted");
1348 printf (" -- Posting for All Recipients --\n");
1353 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, watch
, verbose
,
1354 snoop
, onex
, queued
))
1355 || rp_isbad (retval
= sm_winit (smtpmode
, from
)))
1356 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1358 do_addresses (bccque
, talk
&& verbose
);
1359 if ((fd
= open (file
, O_RDONLY
)) == NOTOK
)
1360 die (file
, "unable to re-open");
1365 sm_end (onex
? OK
: DONE
);
1369 if (msgflags
& MINV
)
1370 printf (" -- %s Recipient Copies Posted --\n",
1371 bccque
? "Blind" : "Sighted");
1373 printf (" -- Recipient Copies Posted --\n");
1380 /* Address Verification */
1383 verify_all_addresses (int talk
)
1386 struct mailname
*lp
;
1390 if (!whomsw
|| checksw
)
1391 if (rp_isbad (retval
= sm_init (clientsw
, serversw
, 0, 0, snoop
, 0, 0))
1392 || rp_isbad (retval
= sm_winit (smtpmode
, from
)))
1393 die (NULL
, "problem initializing server; %s", rp_string (retval
));
1395 if (talk
&& !whomsw
)
1396 printf (" -- Address Verification --\n");
1397 if (talk
&& localaddrs
.m_next
)
1398 printf (" -- Local Recipients --\n");
1399 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1400 do_an_address (lp
, talk
);
1402 if (talk
&& uuaddrs
.m_next
)
1403 printf (" -- UUCP Recipients --\n");
1404 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1405 do_an_address (lp
, talk
);
1407 if (talk
&& netaddrs
.m_next
)
1408 printf (" -- Network Recipients --\n");
1409 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1410 do_an_address (lp
, talk
);
1413 if (talk
&& !whomsw
)
1414 printf (" -- Address Verification Successful --\n");
1416 if (!whomsw
|| checksw
)
1425 do_an_address (struct mailname
*lp
, int talk
)
1431 switch (lp
->m_type
) {
1435 strncpy (addr
, mbox
, sizeof(addr
));
1439 mbox
= auxformat (lp
, 0);
1441 snprintf (addr
, sizeof(addr
), "%s!%s", lp
->m_host
, lp
->m_mbox
);
1444 default: /* let SendMail decide if the host is bad */
1447 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1452 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1454 if (whomsw
&& !checksw
) {
1462 switch (retval
= sm_wadr (mbox
, host
,
1463 lp
->m_type
!= UUCPHOST
? lp
->m_path
: NULL
)) {
1466 printf ("address ok\n");
1472 fprintf (stderr
, " %s: ", addr
);
1473 fprintf (talk
? stdout
: stderr
, "loses; %s\n",
1474 rp_string (retval
));
1480 fprintf (stderr
, " %s: ", addr
);
1481 die (NULL
, "unexpected response; %s", rp_string (retval
));
1489 do_text (char *file
, int fd
)
1494 lseek (fd
, (off_t
) 0, SEEK_SET
);
1496 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1497 if (rp_isbad (retval
= sm_wtxt (buf
, state
)))
1498 die (NULL
, "problem writing text; %s\n", rp_string (retval
));
1502 die (file
, "problem reading from");
1504 switch (retval
= sm_wtend ()) {
1510 die (NULL
, "posting failed; %s", rp_string (retval
));
1513 die (NULL
, "unexpected response; %s", rp_string (retval
));
1517 #endif /* SENDMTS */
1526 post (char *file
, int bccque
, int talk
)
1532 struct rp_bufstruct reply
;
1535 onex
= !(msgflags
& MINV
) || bccque
;
1537 if (msgflags
& MINV
)
1538 printf (" -- Posting for %s Recipients --\n",
1539 bccque
? "Blind" : "Sighted");
1541 printf (" -- Posting for All Recipients --\n");
1546 if (rp_isbad (retval
= mm_init ())
1547 || rp_isbad (retval
= mm_sbinit ())
1548 || rp_isbad (retval
= mm_winit (NULL
, submitopts
, from
)))
1549 die (NULL
, "problem initializing MMDF system [%s]",
1550 rp_valstr (retval
));
1552 if (rp_isbad (retval
= mm_rrply (&reply
, &len
)))
1553 die (NULL
, "problem with sender address [%s]",
1554 rp_valstr (retval
));
1557 do_addresses (bccque
, talk
&& verbose
);
1558 if ((fd
= open (file
, O_RDONLY
)) == NOTOK
)
1559 die (file
, "unable to re-open");
1569 if (msgflags
& MINV
)
1570 printf (" -- %s Recipient Copies Posted --\n",
1571 bccque
? "Blind" : "Sighted");
1573 printf (" -- Recipient Copies Posted --\n");
1578 /* Address Verification */
1581 verify_all_addresses (int talk
)
1584 struct mailname
*lp
;
1588 struct rp_bufstruct reply
;
1593 if (!whomsw
|| checksw
) {
1594 if (rp_isbad (retval
= mm_init ())
1595 || rp_isbad (retval
= mm_sbinit ())
1596 || rp_isbad (retval
= mm_winit (NULL
, submitopts
, from
)))
1597 die (NULL
, "problem initializing MMDF system [%s]",
1598 rp_valstr (retval
));
1600 if (rp_isbad (retval
= mm_rrply (&reply
, &len
)))
1601 die (NULL
, "problem with sender address [%s]", rp_valstr (retval
));
1605 if (talk
&& !whomsw
)
1606 printf (" -- Address Verification --\n");
1607 if (talk
&& localaddrs
.m_next
)
1608 printf (" -- Local Recipients --\n");
1609 for (lp
= localaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1610 do_an_address (lp
, talk
);
1612 if (talk
&& uuaddrs
.m_next
)
1613 printf (" -- UUCP Recipients --\n");
1614 for (lp
= uuaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1615 do_an_address (lp
, talk
);
1617 if (talk
&& netaddrs
.m_next
)
1618 printf (" -- Network Recipients --\n");
1619 for (lp
= netaddrs
.m_next
; lp
; lp
= lp
->m_next
)
1620 do_an_address (lp
, talk
);
1623 if (talk
&& !whomsw
)
1624 printf (" -- Address Verification Successful --\n");
1626 if (!whomsw
|| checksw
)
1635 do_an_address (struct mailname
*lp
, int talk
)
1638 char *mbox
, *host
, *text
, *path
;
1640 struct rp_bufstruct reply
;
1642 switch (lp
->m_type
) {
1645 host
= LocalName ();
1646 strncpy (addr
, mbox
, sizeof(addr
));
1650 fprintf (talk
? stdout
: stderr
, " %s!%s: %s\n",
1651 lp
->m_host
, lp
->m_mbox
, "not supported; UUCP address");
1656 default: /* let MMDF decide if the host is bad */
1659 snprintf (addr
, sizeof(addr
), "%s at %s", mbox
, host
);
1664 printf (" %s%s", addr
, whomsw
&& lp
->m_bcc
? "[BCC]" : "");
1666 if (whomsw
&& !checksw
) {
1676 path
= concat (lp
->m_path
, mbox
, "@", host
, NULL
);
1680 if (rp_isbad (retval
= mm_wadr (path
? NULL
: host
, path
? path
: mbox
))
1681 || rp_isbad (retval
= mm_rrply (&reply
, &len
)))
1682 die (NULL
, "problem submitting address [%s]", rp_valstr (retval
));
1684 switch (rp_gval (reply
.rp_val
)) {
1687 printf ("address ok\n");
1694 printf ("nameserver timeout - queued for checking\n");
1705 text
= "temporary nameserver failure";
1712 text
= "not deliverable";
1716 text
= "try again later";
1720 text
= "nothing done";
1725 fprintf (stderr
, " %s: ", addr
);
1726 text
= "unexpected response";
1727 die (NULL
, "%s;\n [%s] -- %s", text
,
1728 rp_valstr (reply
.rp_val
), reply
.rp_line
);
1732 fprintf (stderr
, " %s: ", addr
);
1733 fprintf (talk
? stdout
: stderr
, "%s;\n %s\n", text
, reply
.rp_line
);
1741 do_text (char *file
, int fd
)
1745 struct rp_bufstruct reply
;
1747 lseek (fd
, (off_t
) 0, SEEK_SET
);
1749 while ((state
= read (fd
, buf
, sizeof(buf
))) > 0) {
1750 if (rp_isbad (mm_wtxt (buf
, state
)))
1751 die (NULL
, "problem writing text [%s]\n", rp_valstr (retval
));
1755 die (file
, "problem reading from");
1757 if (rp_isbad (retval
= mm_wtend ()))
1758 die (NULL
, "problem ending text [%s]\n", rp_valstr (retval
));
1760 if (rp_isbad (retval
= mm_rrply (&reply
, &state
)))
1761 die (NULL
, "problem getting submission status [%s]\n",
1762 rp_valstr (retval
));
1764 switch (rp_gval (reply
.rp_val
)) {
1770 die (NULL
, "you lose; %s", reply
.rp_line
);
1773 die (NULL
, "no delivery occurred; %s", reply
.rp_line
);
1776 die (NULL
, "try again later; %s", reply
.rp_line
);
1779 die (NULL
, "nothing done; %s", reply
.rp_line
);
1782 die (NULL
, "unexpected response;\n\t[%s] -- %s",
1783 rp_valstr (reply
.rp_val
), reply
.rp_line
);
1787 #endif /* MMDFMTS */
1797 #ifndef RELIABLE_SIGNALS
1798 SIGNAL (i
, SIG_IGN
);
1802 if (msgflags
& MINV
)
1806 if (!whomsw
|| checksw
)
1808 #endif /* MMDFMTS */
1811 if (!whomsw
|| checksw
)
1813 #endif /* SENDMTS */
1825 hstat
= SIGNAL2 (SIGHUP
, sigser
);
1826 istat
= SIGNAL2 (SIGINT
, sigser
);
1827 qstat
= SIGNAL2 (SIGQUIT
, sigser
);
1828 tstat
= SIGNAL2 (SIGTERM
, sigser
);
1838 SIGNAL (SIGHUP
, hstat
);
1839 SIGNAL (SIGINT
, istat
);
1840 SIGNAL (SIGQUIT
, qstat
);
1841 SIGNAL (SIGTERM
, tstat
);
1849 p_refile (char *file
)
1857 printf (" -- Filing Folder Copies --\n");
1858 for (i
= 0; i
< fccind
; i
++)
1859 fcc (file
, fccfold
[i
]);
1861 printf (" -- Folder Copies Filed --\n");
1866 * Call the `fileproc' to add the file to the folder.
1870 fcc (char *file
, char *folder
)
1877 printf (" %sFcc %s: ", msgstate
== RESENT
? "Resent-" : "", folder
);
1880 for (i
= 0; (child_id
= fork ()) == NOTOK
&& i
< 5; i
++)
1886 fprintf (stderr
, " %sFcc %s: ",
1887 msgstate
== RESENT
? "Resent-" : "", folder
);
1888 fprintf (verbose
? stdout
: stderr
, "no forks, so not ok\n");
1892 /* see if we need to add `+' */
1893 snprintf (fold
, sizeof(fold
), "%s%s",
1894 *folder
== '+' || *folder
== '@' ? "" : "+", folder
);
1896 /* now exec the fileproc */
1897 execlp (fileproc
, r1bindex (fileproc
, '/'),
1898 "-link", "-file", file
, fold
, NULL
);
1902 if ((status
= pidwait (child_id
, OK
))) {
1904 fprintf (stderr
, " %sFcc %s: ",
1905 msgstate
== RESENT
? "Resent-" : "", folder
);
1906 pidstatus (status
, verbose
? stdout
: stderr
, NULL
);
1909 printf ("folder ok\n");
1921 die (char *what
, char *fmt
, ...)
1926 if (msgflags
& MINV
)
1930 if (!whomsw
|| checksw
)
1932 #endif /* MMDFMTS */
1935 if (!whomsw
|| checksw
)
1937 #endif /* SENDMTS */
1940 advertise (what
, NULL
, fmt
, ap
);
1948 * err_abrt() is used by the mm_ routines
1949 * do not, under *ANY* circumstances, remove it from post,
1950 * or you will lose *BIG*
1954 err_abrt (int code
, char *fmt
, ...)
1956 char buffer
[BUFSIZ
];
1959 snprintf (buffer
, sizeof(buffer
), "[%s]", rp_valstr (code
));
1962 advertise (buffer
, NULL
, fmt
, ap
);
1967 #endif /* MMDFMTS */