]> diplodocus.org Git - nmh/commitdiff
Fixed rcvdist to pass switch arguments to post(1).
authorDavid Levine <levinedl@acm.org>
Mon, 15 Jan 2018 19:01:09 +0000 (14:01 -0500)
committerDavid Levine <levinedl@acm.org>
Mon, 15 Jan 2018 19:01:09 +0000 (14:01 -0500)
Looks like this has always been broken.  Found by Steven Winikoff
when he tried to pass a -port switch, to override the default
submission port.

This is intended to be a temporary fix.  The post switches should
be factored out into one place.

test/rcv/test-rcvdist
uip/rcvdist.c

index 55c6bf3..7ac0087 100755 (executable)
@@ -12,13 +12,17 @@ if test -z "${MH_OBJ_DIR}"; then
     MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
 fi
 
     MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
 fi
 
-. "$MH_OBJ_DIR/test/common.sh"
+. "${MH_OBJ_DIR}/test/common.sh"
 
 setup_test
 
 # Use proper program, likely not the first one on PATH.
 rcvdist="${MH_LIBEXEC_DIR}/rcvdist"
 
 
 setup_test
 
 # Use proper program, likely not the first one on PATH.
 rcvdist="${MH_LIBEXEC_DIR}/rcvdist"
 
+arith_eval 64000 + $$ % 1000
+localport=$arith_val
+testname="${MH_TEST_DIR}/$$"
+
 check_exit '-eq 1' $rcvdist -
 
 expected=$MH_TEST_DIR/$$.expected
 check_exit '-eq 1' $rcvdist -
 
 expected=$MH_TEST_DIR/$$.expected
@@ -26,6 +30,7 @@ actual=$MH_TEST_DIR/$$.actual
 
 
 # check -help
 
 
 # check -help
+start_test -help
 cat >$expected <<EOF
 Usage: rcvdist [switches] [switches for postproc] address ...
   switches are:
 cat >$expected <<EOF
 Usage: rcvdist [switches] [switches for postproc] address ...
   switches are:
@@ -39,6 +44,7 @@ run_prog "$rcvdist" -help | sed '/^$/,$d' >"$actual" 2>&1
 check "$expected" "$actual"
 
 # check -version
 check "$expected" "$actual"
 
 # check -version
+start_test -version
 case `$rcvdist -v` in
   rcvdist\ --*) ;;
   *           ) printf '%s: rcvdist -v generated unexpected output\n' "$0" >&2
 case `$rcvdist -v` in
   rcvdist\ --*) ;;
   *           ) printf '%s: rcvdist -v generated unexpected output\n' "$0" >&2
@@ -46,13 +52,76 @@ case `$rcvdist -v` in
 esac
 
 # check unknown switch
 esac
 
 # check unknown switch
+start_test 'unknown switch'
 run_test "$rcvdist -nonexistent" \
   'rcvdist: usage: rcvdist [switches] [switches for postproc] address ...'
 
 # check with no switches
 run_test "$rcvdist -nonexistent" \
   'rcvdist: usage: rcvdist [switches] [switches for postproc] address ...'
 
 # check with no switches
+start_test 'no switches'
 run_test "$rcvdist" \
   'rcvdist: usage: rcvdist [switches] [switches for postproc] address ...'
 
 run_test "$rcvdist" \
   'rcvdist: usage: rcvdist [switches] [switches for postproc] address ...'
 
+#### Use fakesmtp for this first test.
+# check post switch with argument
+start_test 'post switch with argument'
+
+cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
+From: Mr Nobody <nobody@example.com>
+To: Somebody Else <somebody@example.com>
+Subject: Test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+Date: Sun, 14 Jan 2018 12:00:00 -0500
+
+This is a test.
+EOF
+
+cat > "${testname}.expected" <<EOF
+EHLO nosuchhost.example.com
+MAIL FROM:<somebody@example.com>
+RCPT TO:<somebody@example.com>
+DATA
+From: Mr Nobody <nobody@example.com>
+To: Somebody Else <somebody@example.com>
+Subject: Test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+Date:
+Resent-To: somebody@example.com
+Resent-From: Somebody Else <somebody@example.com>
+Resent-Date:
+
+This is a test.
+.
+QUIT
+EOF
+
+cat > "$MH_TEST_DIR/Mail/rcvdistcomps" <<'EOF'
+%(lit)%(formataddr{addresses})\
+%<(nonnull)%(void(width))%(putaddr Resent-To:)%>
+%(lit)%(formataddr{to})\
+%<(nonnull)%(void(width))%(putaddr Resent-From:)\n%>
+EOF
+
+# Set this for the EHLO command
+echo "clientname: nosuchhost.example.com" >> ${MHMTSCONF}
+
+# $1: message draft file
+# $2: output filename for fakesmtp, i.e., the sent message
+test_post ()
+{
+    pid=`"${MH_OBJ_DIR}/test/fakesmtp" "$2" $localport`
+
+    run_prog $rcvdist -form "$MH_TEST_DIR/Mail/rcvdistcomps" -server 127.0.0.1 -port $localport somebody@example.com <$1
+
+    sed -e 's/^Date:.*/Date:/' -e 's/^Resent-Date:.*/Resent-Date:/' "$2" > "$2".nodate
+    rm -f "$2"
+
+    check "$2".nodate "$3"
+}
+
+test_post "${MH_TEST_DIR}/Mail/draft" "${testname}.fakesmtp" "${testname}.expected"
+
 #### Use sendmail/pipe below to override default mts.
 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
 sed -e 's/^mts:.*/mts: sendmail\/pipe/' "${MHMTSCONF}" > "$mts_fakesendmail"
 #### Use sendmail/pipe below to override default mts.
 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
 sed -e 's/^mts:.*/mts: sendmail\/pipe/' "${MHMTSCONF}" > "$mts_fakesendmail"
@@ -78,15 +147,15 @@ test_rcvdist ()
 }
 
 # check with address
 }
 
 # check with address
+start_test 'with address'
 cat > "$expected" <<EOF
 From: Test1 <test1@example.com>
 To: Some User <user@example.com>
 Date: Fri, 29 Sep 2006 00:00:00
 Message-Id: 1@test.nmh
 Subject: Testing message 1
 cat > "$expected" <<EOF
 From: Test1 <test1@example.com>
 To: Some User <user@example.com>
 Date: Fri, 29 Sep 2006 00:00:00
 Message-Id: 1@test.nmh
 Subject: Testing message 1
-Resent-From: `${MH_LIBEXEC_DIR}/ap -format '%(localmbox)' 0 | \
-              sed 's/^<\(.*\)>$/\1/'`
 Resent-To: recipient@example.com
 Resent-To: recipient@example.com
+Resent-From: Some User <user@example.com>
 Resent-Date:
 
 This is message number 1
 Resent-Date:
 
 This is message number 1
@@ -95,6 +164,7 @@ EOF
 test_rcvdist recipient@example.com < "$MH_TEST_DIR/Mail/inbox/1"
 
 # check -form
 test_rcvdist recipient@example.com < "$MH_TEST_DIR/Mail/inbox/1"
 
 # check -form
+start_test -form
 cat > "$expected" <<EOF
 From: Test2 <test2@example.com>
 To: Some User <user@example.com>
 cat > "$expected" <<EOF
 From: Test2 <test2@example.com>
 To: Some User <user@example.com>
@@ -108,15 +178,9 @@ Resent-Date:
 This is message number 2
 EOF
 
 This is message number 2
 EOF
 
-cat > "$MH_TEST_DIR/Mail/rcvdistcomps" <<'EOF'
-%(lit)%(formataddr{addresses})\
-%<(nonnull)%(void(width))%(putaddr Resent-To:)%>
-%(lit)%(formataddr{to})\
-%<(nonnull)%(void(width))%(putaddr Resent-From:)\n%>
-EOF
-
 test_rcvdist -form "$MH_TEST_DIR/Mail/rcvdistcomps" recipient@example.com \
   < "$MH_TEST_DIR/Mail/inbox/2"
 
 
 test_rcvdist -form "$MH_TEST_DIR/Mail/rcvdistcomps" recipient@example.com \
   < "$MH_TEST_DIR/Mail/inbox/2"
 
 
+finish_test
 exit ${failed:-0}
 exit ${failed:-0}
index f065ad1..531518d 100644 (file)
@@ -40,6 +40,54 @@ DEFINE_SWITCH_ENUM(RCVDIST);
 DEFINE_SWITCH_ARRAY(RCVDIST, switches);
 #undef X
 
 DEFINE_SWITCH_ARRAY(RCVDIST, switches);
 #undef X
 
+#ifndef CYRUS_SASL
+# define SASLminc(a) (a)
+#else /* CYRUS_SASL */
+# define SASLminc(a)  0
+#endif /* CYRUS_SASL */
+
+#ifndef OAUTH_SUPPORT
+# define OAUTHminc(a)  (a)
+#else /* OAUTH_SUPPORT */
+# define OAUTHminc(a)  0
+#endif /* OAUTH_SUPPORT */
+
+/* These are just the post(1) switches that take an argument. */
+#define POST_SWITCHES \
+    X("alias aliasfile", 0, ALIASW) \
+    X("filter filterfile", 0, FILTSW) \
+    X("library directory", -7, LIBSW) /* interface from send, whom */ \
+    X("width columns", 0, WIDTHSW) \
+    X("idanno number", -6, ANNOSW) /* interface from send    */ \
+    X("client host", -6, CLIESW) \
+    X("server host", 6, SERVSW) /* specify alternate SMTP server */ \
+    X("partno", -6, PARTSW) \
+    X("saslmech", SASLminc(5), SASLMECHSW) \
+    X("user", SASLminc(-4), USERSW) \
+    X("port server submission port name/number", 4, PORTSW) \
+    X("fileproc", -4, FILEPROCSW) \
+    X("mhlproc", -3, MHLPROCSW) \
+    X("sendmail program", 0, MTSSM) \
+    X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
+    X("credentials legacy|file:filename", 0, CREDENTIALSSW) \
+    X("messageid localname|random", 2, MESSAGEIDSW) \
+    X("authservice auth-service-name", OAUTHminc(-11), AUTHSERVICESW) \
+    X("oauthcredfile credential-file", OAUTHminc(-7), OAUTHCREDFILESW) \
+    X("oauthclientid client-id", OAUTHminc(-12), OAUTHCLIDSW) \
+    X("oauthclientsecret client-secret", OAUTHminc(-12), OAUTHCLSECSW) \
+    X("oauthauthendpoint authentication-endpoint", OAUTHminc(-6), OAUTHAUTHENDSW) \
+    X("oauthredirect redirect-uri", OAUTHminc(-6), OAUTHREDIRSW) \
+    X("oauthtokenendpoint token-endpoint", OAUTHminc(-6), OAUTHTOKENDSW) \
+    X("oauthscope scope", OAUTHminc(-6), OAUTHSCOPESW) \
+
+#define X(sw, minchars, id) id,
+DEFINE_SWITCH_ENUM(POST);
+#undef X
+
+#define X(sw, minchars, id) { sw, minchars, id },
+DEFINE_SWITCH_ARRAY(POST, post_switches);
+#undef X
+
 static char backup[BUFSIZ] = "";
 static char drft[BUFSIZ] = "";
 static char tmpfil[BUFSIZ] = "";
 static char backup[BUFSIZ] = "";
 static char drft[BUFSIZ] = "";
 static char tmpfil[BUFSIZ] = "";
@@ -84,6 +132,13 @@ main (int argc, char **argv)
                    done (1);
                case UNKWNSW: 
                    vec[vecp++] = --cp;
                    done (1);
                case UNKWNSW: 
                    vec[vecp++] = --cp;
+                   if (smatch(cp + 1, post_switches) != UNKWNSW) {
+                       /* It's a post switch that does take an argument. */
+                       if (!(cp = *argp) || *cp == '-') {
+                           die("missing argument to %s", argp[-1]);
+                       }
+                        vec[vecp++] = *argp++;
+                   }
                    continue;
 
                case HELPSW: 
                    continue;
 
                case HELPSW: