{ "Date", HNOP, MDAT },
{ "Subject", HSUB, 0 },
{ "To", HADR|HTRY, MVIS },
- { "cc", HADR|HTRY, MVIS },
+ { "Cc", HADR|HTRY, MVIS },
{ "Bcc", HADR|HTRY|HBCC|HNIL, MINV },
{ "Message-Id", HBAD, 0 },
{ "Fcc", HFCC, 0 },
};
-static short fccind = 0; /* index into fccfold[] */
-
static int badmsg = 0; /* message has bad semantics */
static int verbose = 0; /* spell it out */
static int debug = 0; /* debugging post */
static char *filter = NULL; /* the filter for BCC'ing */
static char *subject = NULL; /* the subject field for BCC'ing */
static char *fccfold[FCCS]; /* foldernames for FCC'ing */
+static short fccind = 0; /* index into fccfold[] */
static struct headers *hdrtab; /* table for the message we're doing */
static FILE *out; /* output (temp) file */
static int get_header(char *, struct headers *);
static void putadr(char *, struct mailname *);
static int putone(char *, int, int);
-static void insert_fcc(struct headers *, unsigned char *);
-static void file(char *);
+static void insert_fcc(char *, unsigned char *);
static void fcc(char *, char *);
#if 0
-static void die(char *, char *, ...);
static void make_bcc_file(void);
#endif
if (debug) {
done(0);
- }
- else
+ } else {
fclose(out);
+ }
- file(tmpfil);
+ /* process Fcc */
+ for (i=0; i<fccind; i++) {
+ fcc(tmpfil, fccfold[i]);
+ }
/*
** re-open the temp file, unlink it and exec sendmail, giving it
str++;
if ((i = get_header(name, hdrtab)) == NOTOK) {
+ /* some boring header: push it through */
fprintf(out, "%s: %s", name, str);
return;
}
+ /* one of the interesting headers */
hdr = &hdrtab[i];
- if (hdr->flags & HIGN)
+ if (hdr->flags & HIGN) {
return;
+ }
if (hdr->flags & HBAD) {
advise(NULL, "illegal header line -- %s:", name);
badmsg++;
}
msgflags |= hdr->set;
- if (hdr->flags & HSUB)
- subject = subject ? add(str, add("\t", subject)) :
- getcpy(str);
+ if (hdr->flags & HSUB) {
+ if (subject) {
+ /* append mupliple subject */
+ char *cp = concat(subject, "\t", str, NULL);
+ free(subject);
+ subject = cp;
+ } else {
+ subject = getcpy(str);
+ }
+ }
if (hdr->flags & HFCC) {
- if ((cp = strrchr(str, '\n')))
- *cp = 0;
+ if ((cp = strrchr(str, '\n'))) {
+ *cp = '\0';
+ }
for (cp = pp = str; (cp = strchr(pp, ',')); pp = cp) {
- *cp++ = 0;
- insert_fcc(hdr, pp);
+ *cp++ = '\0';
+ insert_fcc(hdr->value, pp);
}
- insert_fcc(hdr, pp);
+ insert_fcc(hdr->value, pp);
return;
}
register struct mailname *mp = 0;
while ((cp = getname(str))) {
- mp = getm( cp, NULL, 0, AD_HOST, NULL);
+ mp = getm(cp, NULL, 0, AD_HOST, NULL);
if (f == 0) {
f = mp;
mp->m_next = mp;
}
}
f = mp->m_next; mp->m_next = 0;
- putadr( name, f );
+ putadr(name, f);
} else {
/*
** The author(s) of spost decided that alias
}
+/*
+** Construct signature name
+*/
static void
start_headers(void)
{
char *cp;
- char sigbuf[BUFSIZ];
strncpy(from, getusername(), sizeof(from));
-
if ((cp = getfullname()) && *cp) {
- strncpy(sigbuf, cp, sizeof(sigbuf));
- snprintf(signature, sizeof(signature), "%s <%s>",
- sigbuf, from);
- } else
- snprintf(signature, sizeof(signature), "%s", from);
+ snprintf(signature, sizeof(signature), "%s <%s>", cp, from);
+ } else {
+ snprintf(signature, sizeof(signature), "%s", from);
+ }
}
+/*
+** Add yet missing headers.
+*/
static void
finish_headers(FILE *out)
{
- switch (msgstate) {
- case normal:
- if (!(msgflags & MDAT))
- fprintf(out, "Date: %s\n", dtimenow(0));
-
- if (msgflags & MFRM) {
- /*
- ** There was already a From: in the draft.
- ** Don't add one.
- */
- if (!draft_from_masquerading)
- /*
- ** mts.conf didn't contain
- ** "masquerade:[...]draft_from[...]"
- ** so we'll reveal the user's
- ** actual account@thismachine
- ** address in a Sender: header
- ** (and use it as the envelope
- ** From: later).
- */
- fprintf(out, "Sender: %s\n", from);
- } else
- fprintf(out, "From: %s\n", signature);
+ char *resentstr = (msgstate == resent) ? "Resent-" : "";
+ if (!(msgflags & MDAT)) {
+ fprintf(out, "%sDate: %s\n", resentstr, dtimenow(0));
+ }
+ if (!(msgflags & MFRM)) {
+ fprintf(out, "%sFrom: %s\n", resentstr, signature);
+ } else if (!draft_from_masquerading) {
+ /*
+ ** mts.conf didn't contain "masquerade:[...]draft_from[...]"
+ ** so we'll reveal the user's actual account@thismachine
+ ** address in a Sender: header (and use it as the envelope
+ ** From: later).
+ */
+ fprintf(out, "%sSender: %s\n", resentstr, from);
+ }
#ifdef notdef
- if (!(msgflags & MVIS))
- fprintf(out, "Bcc: Blind Distribution List: ;\n");
+ if (!(msgflags & MVIS))
+ fprintf(out, "%sBcc: Blind Distribution List: ;\n", resentstr);
#endif /* notdef */
- break;
- case resent:
- if (!(msgflags & MRDT))
- fprintf(out, "Resent-Date: %s\n", dtimenow(0));
- if (msgflags & MRFM) {
- /*
- ** There was already a Resent-From: in draft.
- ** Don't add one.
- */
- if (!draft_from_masquerading)
- /*
- ** mts.conf didn't contain
- ** "masquerade:[...]draft_from[...]"
- ** so we'll reveal the user's
- ** actual account@thismachine
- ** address in a Sender: header
- ** (and use it as the envelope
- ** From: later).
- */
- fprintf(out, "Resent-Sender: %s\n",
- from);
- } else
- /* Construct a Resent-From: header. */
- fprintf(out, "Resent-From: %s\n", signature);
-#ifdef notdef
- if (!(msgflags & MVIS))
- fprintf(out, "Resent-Bcc: Blind Re-Distribution List: ;\n");
-#endif /* notdef */
- break;
- }
-
- if (badmsg)
+ if (badmsg) {
adios(NULL, "re-format message and try again");
+ }
}
+/*
+** Return index of the requested header in the table, or NOTOK if missing.
+*/
static int
get_header(char *header, struct headers *table)
{
struct headers *h;
- for (h = table; h->value; h++)
- if (!mh_strcasecmp(header, h->value))
+ for (h=table; h->value; h++) {
+ if (mh_strcasecmp(header, h->value)==0) {
return (h - table);
+ }
+ }
return NOTOK;
}
}
+/*
+** Insert the normalized value from pp into fccfold[].
+*/
static void
-insert_fcc(struct headers *hdr, unsigned char *pp)
+insert_fcc(char *name, unsigned char *pp)
{
- unsigned char *cp;
+ unsigned char *cp;
for (cp = pp; isspace(*cp); cp++)
continue;
for (pp += strlen(pp) - 1; pp > cp && isspace(*pp); pp--)
continue;
if (pp >= cp)
- *++pp = 0;
- if (*cp == 0)
+ *++pp = '\0';
+ if (!*cp)
return;
if (fccind >= FCCS)
- adios(NULL, "too many %ss", hdr->value);
+ adios(NULL, "too many %ss", name);
fccfold[fccind++] = getcpy(cp);
}
}
#endif /* if 0 */
-/* FCC INTERACTION */
-
-static void
-file(char *path)
-{
- int i;
-
- if (fccind == 0)
- return;
-
- for (i = 0; i < fccind; i++)
- fcc(path, fccfold[i]);
-}
+/* FCC INTERACTION */
static void
fcc(char *file, char *folder)
sleep(5);
switch (child_id) {
case NOTOK:
- if (!verbose)
- fprintf(stderr, " %sFcc %s: ", msgstate == resent ?
- "Resent-" : "", folder);
- fprintf(verbose ? stdout : stderr, "no forks, so not ok\n");
+ if (verbose) {
+ printf("Sorry man, but we had no more forks.\n");
+ } else {
+ fprintf(stderr, "Skipped %sFcc %s: unable to fork.\n",
+ msgstate == resent ? "Resent-" : "",
+ folder);
+ }
break;
case OK:
snprintf(fold, sizeof(fold), "%s%s",
- *folder == '+' || *folder == '@' ? "" : "+", folder);
+ *folder == '+' || *folder == '@' ? "" : "+",
+ folder);
execlp(fileproc, mhbasename(fileproc),
- "-link", "-file", file, fold, NULL);
+ "-link", "-file", file, fold, NULL);
_exit(-1);
default:
if ((status = pidwait(child_id, OK))) {
- if (!verbose)
- fprintf(stderr, " %sFcc %s: ",
+ if (verbose) {
+ printf(" errored (0%o)\n", status);
+ } else {
+ fprintf(stderr, " %sFcc %s: errored (0%o)\n",
msgstate == resent ?
- "Resent-" : "", folder);
- fprintf(verbose ? stdout : stderr, " errored (0%o)\n",
- status);
+ "Resent-" : "", folder,
+ status);
+ }
}
}
fflush(stdout);
}
-
-
-#if 0
-
-/*
-** TERMINATION
-*/
-
-static void
-die(char *what, char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- advertise(what, NULL, fmt, ap);
- va_end(ap);
-
- done(1);
-}
-#endif