0 : Switch can't be abbreviated; switch shown in -help.
# : Switch can be abbreviated to # characters; switch shown in -help. */
-static struct swit switches[] = {
-#define ALIASW 0
- { "alias aliasfile", 0 },
-#define CHKSW 1
- { "check", -5 }, /* interface from whom */
-#define NCHKSW 2
- { "nocheck", -7 }, /* interface from whom */
-#define DEBUGSW 3
- { "debug", -5 },
-#define DISTSW 4
- { "dist", -4 }, /* interface from dist */
-#define FILTSW 5
- { "filter filterfile", 0 },
-#define NFILTSW 6
- { "nofilter", 0 },
-#define FRMTSW 7
- { "format", 0 },
-#define NFRMTSW 8
- { "noformat", 0 },
-#define LIBSW 9
- { "library directory", -7 }, /* interface from send, whom */
-#define MIMESW 10
- { "mime", 0 },
-#define NMIMESW 11
- { "nomime", 0 },
-#define MSGDSW 12
- { "msgid", 0 },
-#define NMSGDSW 13
- { "nomsgid", 0 },
-#define VERBSW 14
- { "verbose", 0 },
-#define NVERBSW 15
- { "noverbose", 0 },
-#define WATCSW 16
- { "watch", 0 },
-#define NWATCSW 17
- { "nowatch", 0 },
-#define WHOMSW 18
- { "whom", -4 }, /* interface from whom */
-#define WIDTHSW 19
- { "width columns", 0 },
-#define VERSIONSW 20
- { "version", 0 },
-#define HELPSW 21
- { "help", 0 },
-#define BITSTUFFSW 22
- { "dashstuffing", -12 }, /* should we dashstuff BCC messages? */
-#define NBITSTUFFSW 23
- { "nodashstuffing", -14 },
-#define ANNOSW 24
- { "idanno number", -6 }, /* interface from send */
-#define CLIESW 25
- { "client host", -6 },
-#define SERVSW 26
- { "server host", 6 }, /* specify alternate SMTP server */
-#define SNOOPSW 27
- { "snoop", -5 }, /* snoop the SMTP transaction */
-#define PARTSW 28
- { "partno", -6 },
-#define QUEUESW 29
- { "queued", -6 },
-#define SASLSW 30
- { "sasl", SASLminc(-4) },
-#define NOSASLSW 31
- { "nosasl", SASLminc(-6) },
-#define SASLMXSSFSW 32
- { "saslmaxssf", SASLminc(-10) },
-#define SASLMECHSW 33
- { "saslmech", SASLminc(-5) },
-#define USERSW 34
- { "user", SASLminc(-4) },
-#define PORTSW 35
- { "port server port name/number", 4 },
-#define TLSSW 36
- { "tls", TLSminc(-3) },
-#define NTLSSW 37
- { "notls", TLSminc(-5) },
-#define FILEPROCSW 38
- { "fileproc", -4 },
-#define MHLPROCSW 39
- { "mhlproc", -3 },
- { NULL, 0 }
-};
+#define POST_SWITCHES \
+ X("alias aliasfile", 0, ALIASW) \
+ X("check", -5, CHKSW) /* interface from whom */ \
+ X("nocheck", -7, NCHKSW) /* interface from whom */ \
+ X("debug", -5, DEBUGSW) \
+ X("dist", -4, DISTSW) /* interface from dist */ \
+ X("filter filterfile", 0, FILTSW) \
+ X("nofilter", 0, NFILTSW) \
+ X("format", 0, FRMTSW) \
+ X("noformat", 0, NFRMTSW) \
+ X("library directory", -7, LIBSW) /* interface from send, whom */ \
+ X("mime", 0, MIMESW) \
+ X("nomime", 0, NMIMESW) \
+ X("msgid", 0, MSGDSW) \
+ X("nomsgid", 0, NMSGDSW) \
+ X("verbose", 0, VERBSW) \
+ X("noverbose", 0, NVERBSW) \
+ X("watch", 0, WATCSW) \
+ X("nowatch", 0, NWATCSW) \
+ X("whom", -4, WHOMSW) /* interface from whom */ \
+ X("width columns", 0, WIDTHSW) \
+ X("version", 0, VERSIONSW) \
+ X("help", 0, HELPSW) \
+ X("dashstuffing", -12, BITSTUFFSW) /* should we dashstuff BCC messages? */ \
+ X("nodashstuffing", -14, NBITSTUFFSW) \
+ X("idanno number", -6, ANNOSW) /* interface from send */ \
+ X("client host", -6, CLIESW) \
+ X("server host", 6, SERVSW) /* specify alternate SMTP server */ \
+ X("snoop", -5, SNOOPSW) /* snoop the SMTP transaction */ \
+ X("partno", -6, PARTSW) \
+ X("queued", -6, QUEUESW) \
+ X("sasl", SASLminc(-4), SASLSW) \
+ X("nosasl", SASLminc(-6), NOSASLSW) \
+ X("saslmaxssf", SASLminc(-10), SASLMXSSFSW) \
+ X("saslmech", SASLminc(-5), SASLMECHSW) \
+ X("user", SASLminc(-4), USERSW) \
+ X("port server port name/number", 4, PORTSW) \
+ X("tls", TLSminc(-3), TLSSW) \
+ X("notls", TLSminc(-5), NTLSSW) \
+ X("fileproc", -4, FILEPROCSW) \
+ X("mhlproc", -3, MHLPROCSW) \
+ X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
+ X("messageid localname|random", 2, MESSAGEIDSW) \
+
+#define X(sw, minchars, id) id,
+DEFINE_SWITCH_ENUM(POST);
+#undef X
+
+#define X(sw, minchars, id) { sw, minchars, id },
+DEFINE_SWITCH_ARRAY(POST, switches);
+#undef X
struct headers {
static char from[BUFSIZ]; /* my network address */
static char sender[BUFSIZ]; /* my Sender: header */
static char efrom[BUFSIZ]; /* my Envelope-From: header */
+static char fullfrom[BUFSIZ]; /* full contents of From header */
static char signature[BUFSIZ]; /* my signature */
static char *filter = NULL; /* the filter for BCC'ing */
static char *subject = NULL; /* the subject field for BCC'ing */
char *cp, *msg = NULL, **argp, **arguments, *envelope;
char buf[BUFSIZ], name[NAMESZ];
FILE *in, *out;
+ m_getfld_state_t gstate = 0;
#ifdef LOCALE
setlocale(LC_ALL, "");
adios (NULL, "missing argument to %s", argp[-2]);
mhlproc = cp;
continue;
+
+ case MTSSW:
+ if (!(cp = *argp++) || *cp == '-')
+ adios (NULL, "missing argument to %s", argp[-2]);
+ save_mts_method (cp);
+ continue;
+
+ case MESSAGEIDSW:
+ if (!(cp = *argp++) || *cp == '-')
+ adios (NULL, "missing argument to %s", argp[-2]);
+ if (save_message_id_style (cp) != 0)
+ adios (NULL, "unsupported messageid \"%s\"", cp);
+ continue;
}
}
if (msg)
start_headers ();
if (debug) {
verbose++;
- discard (out = stdout); /* XXX: reference discard() to help loader */
+ out = stdout;
} else {
if (whomsw) {
if ((out = fopen ("/dev/null", "w")) == NULL)
hdrtab = msgstate == NORMAL ? NHeaders : RHeaders;
- for (compnum = 1, state = FLD;;) {
- switch (state = m_getfld (state, name, buf, sizeof(buf), in)) {
+ for (compnum = 1;;) {
+ int bufsz = sizeof buf;
+ switch (state = m_getfld (&gstate, name, buf, &bufsz, in)) {
case FLD:
- case FLDEOF:
case FLDPLUS:
compnum++;
cp = add (buf, NULL);
while (state == FLDPLUS) {
- state = m_getfld (state, name, buf, sizeof(buf), in);
+ bufsz = sizeof buf;
+ state = m_getfld (&gstate, name, buf, &bufsz, in);
cp = add (buf, cp);
}
putfmt (name, cp, out);
free (cp);
- if (state != FLDEOF)
- continue;
- finish_headers (out);
- break;
+ continue;
case BODY:
- case BODYEOF:
finish_headers (out);
if (whomsw)
break;
fprintf (out, "\n%s", buf);
while (state == BODY) {
- state = m_getfld (state, name, buf, sizeof(buf), in);
+ bufsz = sizeof buf;
+ state = m_getfld (&gstate, name, buf, &bufsz, in);
fputs (buf, out);
}
break;
}
break;
}
+ m_getfld_state_destroy (&gstate);
if (pfd != NOTOK)
anno ();
}
if ((i = get_header (name, hdrtab)) == NOTOK) {
- fprintf (out, "%s: %s", name, str);
+ if (strncasecmp (name, "nmh-", 4)) {
+ fprintf (out, "%s: %s", name, str);
+ } else {
+ /* Filter out all Nmh-* headers, because Norm asked. They
+ should never have reached this point. Warn about any
+ that are non-empty. */
+ if (strcmp (str, "\n")) {
+ char *newline = strchr (str, '\n');
+ if (newline) *newline = '\0';
+ if (! whomsw) {
+ advise (NULL, "ignoring header line -- %s: %s", name, str);
+ }
+ }
+ }
+
return;
}
else
if (mp->m_gname)
putgrp (namep, mp->m_gname, out, hdr->flags);
- if (mp->m_ingrp)
+ if (mp->m_ingrp) {
+ if (sm_mts == MTS_SENDMAIL_PIPE) {
+ /* Catch this before sendmail chokes with:
+ "553 List:; syntax illegal for recipient
+ addresses".
+ If we wanted to, we could expand out blind
+ aliases and put them in Bcc:, but then
+ they'd have the Blind-Carbon-Copy
+ indication. */
+ adios (NULL,
+ "blind lists not compatible with"
+ " sendmail/pipe");
+ }
+
grp++;
+ }
if (putadr (namep, qp, mp, out, hdr->flags))
msgflags |= (hdr->set & (MVIS | MINV));
else
mnfree (mp);
}
+ /*
+ * If this is a From:/Resent-From: header, save the full thing for
+ * later in case we need it for use when constructing a Bcc draft message
+ */
+
+ if ((msgstate == RESENT) ? (hdr->set & MRFM) : (hdr->set & MFRM)) {
+ strncpy(fullfrom, str, sizeof(fullfrom));
+ fullfrom[sizeof(fullfrom) - 1] = 0;
+ /*
+ * Strip off any trailing newlines
+ */
+
+ while (strlen(fullfrom) > 0 && fullfrom[strlen(fullfrom) - 1] == '\n') {
+ fullfrom[strlen(fullfrom) - 1] = '\0';
+ }
+ }
+
if (grp > 0 && (hdr->flags & HNGR)) {
advise (NULL, "%s: field does not allow groups", name);
badmsg++;
from[0] = '\0';
efrom[0] = '\0';
sender[0] = '\0';
+ fullfrom[0] = '\0';
if ((cp = getfullname ()) && *cp) {
strncpy (sigbuf, cp, sizeof(sigbuf));
fprintf (out, "Date: %s\n", dtime (&tclock, 0));
if (msgid)
- fprintf (out, "Message-ID: <%d.%ld@%s>\n",
- (int) getpid (), (long) tclock, LocalName (1));
+ fprintf (out, "Message-ID: %s\n", message_id (tclock, 0));
/*
* If we have multiple From: addresses, make sure we have an
* Sender: header. If we don't have one, then generate one
fprintf (out, "Resent-Date: %s\n", dtime (&tclock, 0));
if (msgid)
- fprintf (out, "Resent-Message-ID: <%d.%ld@%s>\n",
- (int) getpid (), (long) tclock, LocalName (1));
+ fprintf (out, "Resent-Message-ID: %s\n",
+ message_id (tclock, 0));
/*
* If we have multiple Resent-From: addresses, make sure we have an
* Resent-Sender: header. If we don't have one, then generate one
tfile = m_mktemp2(NULL, "bccs", NULL, &out);
if (tfile == NULL) adios("bcc", "unable to create temporary file");
- chmod (bccfil, 0600);
strncpy (bccfil, tfile, sizeof(bccfil));
+ fprintf (out, "From: %s\n", fullfrom);
fprintf (out, "Date: %s\n", dtime (&tclock, 0));
if (msgid)
- fprintf (out, "Message-ID: <%d.%ld@%s>\n",
- (int) getpid (), (long) tclock, LocalName (1));
+ fprintf (out, "Message-ID: %s\n", message_id (tclock, 0));
if (subject)
fprintf (out, "Subject: %s", subject);
fprintf (out, "BCC:\n");
fcc (char *file, char *folder)
{
pid_t child_id;
- int i, status;
+ int i, status, argp;
char fold[BUFSIZ];
+ char **arglist, *program;
if (verbose)
printf (" %sFcc %s: ", msgstate == RESENT ? "Resent-" : "", folder);
*folder == '+' || *folder == '@' ? "" : "+", folder);
/* now exec the fileproc */
- execlp (fileproc, r1bindex (fileproc, '/'),
- "-link", "-file", file, fold, NULL);
+
+ arglist = argsplit(fileproc, &program, &argp);
+ arglist[argp++] = "-link";
+ arglist[argp++] = "-file";
+ arglist[argp++] = file;
+ arglist[argp++] = fold;
+ arglist[argp] = NULL;
+ execvp (program, arglist);
_exit (-1);
default: