From d8a78332490cd5a5928d6a23d06797ca9caa2b45 Mon Sep 17 00:00:00 2001 From: David Levine Date: Sun, 14 Oct 2012 19:27:17 -0500 Subject: [PATCH] The first alias contained in a blind list is now expanded. The mh-alias(5) man page was updated to show that blind lists must not be terminated with, or contain, a trailing semicolon [Bug #15604]. --- Makefile.am | 4 +- docs/pending-release-notes | 3 + man/mh-alias.man | 28 ++++++-- test/ali/test-ali | 50 +++++++++++--- test/post/test-post-aliases | 156 +++++++++++++++++++++++++++++++++++++++++++ uip/aliasbr.c | 46 ++++++++++++- 6 files changed, 267 insertions(+), 20 deletions(-) create mode 100755 test/post/test-post-aliases diff --git a/Makefile.am b/Makefile.am index 6d15d9f..8c571d2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -63,8 +63,8 @@ TESTS = test/ali/test-ali test/anno/test-anno \ test/mhshow/test-subpart test/mhstore/test-mhstore \ test/new/test-basic \ test/pick/test-pick test/pick/test-stderr \ - test/post/test-post-basic test/post/test-post-multiple \ - test/post/test-post-bcc \ + test/post/test-post-aliases test/post/test-post-basic \ + test/post/test-post-multiple test/post/test-post-bcc \ test/post/test-post-dcc test/post/test-post-fcc \ test/post/test-post-multifrom test/post/test-post-envelope \ test/post/test-post-group test/post/test-mts test/post/test-messageid \ diff --git a/docs/pending-release-notes b/docs/pending-release-notes index cf0cdca..a329ebb 100644 --- a/docs/pending-release-notes +++ b/docs/pending-release-notes @@ -72,3 +72,6 @@ BUG FIXES - Propagate Mail-Followup-To [Bug #5571]. - "mark -sequence cur -delete all" now works for cur as well as any other sequence, to allow clearing of the current message indication. +- The first alias contained in a blind list is now expanded. The + mh-alias(5) man page was updated to show that blind lists must not + be terminated with, or contain, a trailing semicolon [Bug #15604]. diff --git a/man/mh-alias.man b/man/mh-alias.man index e29db4a..926fb89 100644 --- a/man/mh-alias.man +++ b/man/mh-alias.man @@ -146,10 +146,13 @@ the address list if it is not already on the list. The alias itself is not usually output, rather the address\-group that the alias maps to is output instead. If \*(lqalias\*(rq is terminated with a `;' instead of a `:', then both the \*(lqalias\*(rq and the address are output in the -correct format. (This makes replies possible since +correct format (with the alias quoted if necessary and the address +wrapped in <>). + +This makes replies possible since .B nmh aliases -and personal aliases are unknown to the mail transport system.) +and personal aliases are unknown to the mail transport system. .RE .PP Since the alias file is read line by line, forward references work, but @@ -161,7 +164,7 @@ Example Alias File: .nf <%etcdir%/BBoardAliases sgroup: fred, fear, freida -b-people: Blind List: bill, betty; +b-people: Blind List: bill, betty fred: frated@UCI UNIX\-committee: ${MH_TEST_DIR}/Mail/aliases <"${MH_TEST_DIR}/Mail/aliases" <"${MH_TEST_DIR}/Mail/aliases" <"${MH_TEST_DIR}/Mail/aliases" <"${MH_TEST_DIR}/Mail/aliases" <>"$mts_fakesendmail" +MHMTSCONF="$mts_fakesendmail" + +# $1: -mts switch selection +# $2: expected output +test_alias () +{ + if [ "$1" = 'sendmail/smtp' ]; then + send -draft -alias "${MH_TEST_DIR}/Mail/aliases" -mts sendmail/smtp + + # fakesendmail drops the message and any cc's into this mbox. + mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox + inc -silent -file "$mbox" + rm -f "$mbox" "$mbox.map" + + # It's hard to calculate the exact Date: header post is going to + # use, so we'll just use sed to remove the actual date so we can easily + # compare it against our "correct" output. + sed -e 's/^Date:.*/Date:/' "`mhpath cur`" >"${testname}.actual" + + check "${testname}.actual" "$2" + + if [ "`mhpath cur`" != "`mhpath last`" ]; then + folder next >/dev/null + arith_eval $n + 1; n=$arith_val + fi + + elif [ "$1" = 'sendmail/pipe' ]; then + set +e + send -draft -alias "${MH_TEST_DIR}/Mail/aliases" -mts sendmail/pipe \ + >"${testname}.actual" 2>&1 + if [ $? -eq 0 ]; then + printf "$0: sendmail/pipe should have failed but didn't\n" + else + set -e + check "${testname}.actual" "$2" + fi + + else + printf "$0: invalid -mts switch selection\n" + exit 1 + fi +} + + +# check blind list +cat >"${MH_TEST_DIR}/Mail/draft" < +To: blind_list +Subject: blind list test + +This is test of a blind list. +EOF +cp -p "${MH_TEST_DIR}/Mail/draft" "${MH_TEST_DIR}/Mail/draft2" + +cat >"${testname}.expected" < +To: Blind List: ; +Subject: blind list test +Date: + +This is test of a blind list. +EOF + +test_alias sendmail/smtp "${testname}.expected" + +# Make sure the addresses were expanded correctly. +mv "${MH_TEST_DIR}/Mail/draft2" "${MH_TEST_DIR}/Mail/draft" + +cat > "${testname}.expected" < +RCPT TO: +RCPT TO: +RCPT TO: +DATA +From: Mr Nobody +To: Blind List: ; +Subject: blind list test +Date: + +This is test of a blind list. +. +QUIT +EOF + +test_post "${testname}.actual" "${testname}.expected" \ + "-alias ${MH_TEST_DIR}/Mail/aliases" + +# check named list (alias followed by ;) +cat >"${MH_TEST_DIR}/Mail/draft" < +To: named.list +Subject: named list test + +This is test of a named list. +EOF + +cat >"${testname}.expected" < +To: "named.list" , "named.list" +Subject: named list test +Date: + +This is test of a named list. +EOF + +test_alias sendmail/smtp "${testname}.expected" + +# check blind list with -mts sendmail/pipe, which should fail +cat >"${MH_TEST_DIR}/Mail/draft" < +To: blind_list +Subject: blind list test + +This is test of a blind list. +EOF + +cat >"${testname}.expected" < #include +#include #include #include #include @@ -25,7 +26,7 @@ struct home *hometail = NULL; /* * prototypes */ -int alias (char *); +int alias (char *); int akvisible (void); void init_pw (void); char *akresult (struct aka *); @@ -104,9 +105,45 @@ akval (struct aka *ak, char *s) if (!s) return s; /* XXX */ - for (; ak; ak = ak->ak_next) - if (aleq (s, ak->ak_name)) + for (; ak; ak = ak->ak_next) { + if (aleq (s, ak->ak_name)) { return akresult (ak); + } else if (strchr (s, ':')) { + /* The first address in a blind list will contain the + alias name, so try to match, but just with just the + address (not including the list name). If there's a + match, then replace the alias part with its + expansion. */ + + char *name = getname (s); + char *cp = NULL; + + if (name) { + /* s is of the form "Blind list: address". If address + is an alias, expand it. */ + struct mailname *mp = getm (name, NULL, 0, AD_NAME, NULL); + + if (mp && mp->m_ingrp) { + char *gname = add (mp->m_gname, NULL); + + if (gname && aleq (name, ak->ak_name)) { + /* Will leak cp. */ + cp = concat (gname, akresult (ak), NULL); + free (gname); + } + } + + mnfree (mp); + } + + /* Need to flush getname after use. */ + while (getname ("")) continue; + + if (cp) { + return cp; + } + } + } return getcpy (s); } @@ -429,12 +466,15 @@ getalias (char *addrs) if (*cp == 0) return (cp = NULL); + /* Remove leading any space from the address. */ for (pp = cp; isspace (*pp); pp++) continue; if (*pp == 0) return (cp = NULL); + /* Find the end of the address. */ for (qp = pp; *qp != 0 && *qp != ','; qp++) continue; + /* Set cp to point to the remainder of the addresses. */ if (*qp == ',') *qp++ = 0; for (cp = qp, qp--; qp > pp; qp--) -- 1.7.10.4