From 456c3cedca10fe75f822f9d287e5e4e08282efbb Mon Sep 17 00:00:00 2001 From: Andreas Gruenbacher Date: Thu, 25 Oct 2007 11:59:15 +0000 Subject: - quilt/mail.in: Make sure that shell meta-characters like * in subjects won't get expanded by accident (this was broken). Add test case. - quilt/mail.in: ``formail -x Foo'' will extract all Foo* headers, so use ``formail -x Foo:'' instead. - quilt/mail.in: Recognize sequences of common subject prefixes like Fwd:, Fw:, Re:, Aw:, Tr:, [foo] only at the beginning of subjects. --- quilt.changes | 14 +++++++++- quilt/mail.in | 86 +++++++++++++++++++++++++--------------------------------- test/mail.test | 19 +++++++++---- 3 files changed, 63 insertions(+), 56 deletions(-) diff --git a/quilt.changes b/quilt.changes index e31a9fd..d733f57 100644 --- a/quilt.changes +++ b/quilt.changes @@ -1,7 +1,19 @@ +------------------------------------------------------------------- +Thu Oct 25 13:52:34 CEST 2007 - agruen@suse.de + +- quilt/mail.in: Make sure that shell meta-characters like * in + subjects won't get expanded by accident (this was broken). Add + test case. +- quilt/mail.in: ``formail -x Foo'' will extract all Foo* headers, + so use ``formail -x Foo:'' instead. +- quilt/mail.in: Recognize sequences of common subject prefixes + like Fwd:, Fw:, Re:, Aw:, Tr:, [foo] only at the beginning of + subjects. + ------------------------------------------------------------------- Mon Oct 15 15:29:55 CEST 2007 - agruen@suse.de -- quilt/main.in: Add a --signature flag that allows to override +- quilt/mail.in: Add a --signature flag that allows to override the signature used. (The test suite still depended on the .signature file of the user runnig it; fixed now.) diff --git a/quilt/mail.in b/quilt/mail.in index d7293d3..953253e 100644 --- a/quilt/mail.in +++ b/quilt/mail.in @@ -84,7 +84,7 @@ msgid() in_reply_to_header() { local message=$1 message_id - message_id=$(formail -x Message-ID < "$message") + message_id=$(formail -x Message-ID: < "$message") message_id=${message_id# } [ -n "$message_id" ] && echo "In-Reply-To: $message_id" } @@ -92,14 +92,14 @@ in_reply_to_header() { references_header() { local message=$1 message_id references in_reply_to - message_id=$(formail -x Message-ID < "$message") + message_id=$(formail -x Message-ID: < "$message") message_id=${message_id# } - references=$(formail -x References < "$message") + references=$(formail -x References: < "$message") references=${references# } if [ -z "$references" ] then - in_reply_to=$(formail -x In-Reply-To < "$message") + in_reply_to=$(formail -x In-Reply-To: < "$message") in_reply_to=${in_reply_to# } if [ -n "$in_reply_to" ] && ! [[ "$in_reply_to" =~ "@.*@" ]] @@ -122,6 +122,7 @@ process_mail() local tmpfile=$(gen_tempfile) cat > $tmpfile + set -- $($QUILT_DIR/scripts/edmail --charset $opt_charset \ --extract-recipients To \ --extract-recipients Cc \ @@ -144,6 +145,16 @@ process_mail() rm -f $tmpfile } +join_lines() { + awk ' + BEGIN { RS="\n\n" } + { gsub(/[ \t\n]+/, " ") + sub(/ $/, "") + sub(/^ /, "") + print } + ' +} + options=`getopt -o m:h --long from:,to:,cc:,bcc:,subject: \ --long send,mbox:,charset:,sender: \ --long prefix:,reply-to:,signature: -- "$@"` @@ -278,16 +289,13 @@ if [ "$(type -t quilt_mail_patch_filter 2> /dev/null)" != function ] then quilt_mail_patch_filter() { local patch=$(cat) - local header=$(echo "$patch" | patch_header) body + local header=$(echo "$patch" | patch_header) body subject local -a mh # Does this patch have a Subject: line? - local subject=$(echo $(echo "$header" \ - | sed -n -e '/^$/q' \ - -e $'s/^Subject:[ \\t]//ip')) + subject=$(echo "$header" | formail -x Subject:) if [ -n "$subject" ] then - mh=( "Replace-Subject: $subject" ) body=$(echo "$patch" | awk ' in_body { print } /^$/ { in_body = 1 } @@ -295,16 +303,16 @@ then fi # Does this patch have DESC // subject // EDESC? - if [ ${#mh[@]} -eq 0 ] + if [ -z "$subject" ] then - local desc=$(echo $(echo "$header" | awk ' + local desc=$(echo "$header" | awk ' /^EDESC\>/ { desc = 0 } desc { print } /^DESC\>/ { desc = 1 } - ')) + ') if [ -n "$desc" ] then - mh=( "Replace-Subject: $desc" ) + subject=$(echo "$desc" | join_lines) body=$(echo "$patch" | awk ' /^DESC/ { desc = 1 } ! desc { print } @@ -313,31 +321,13 @@ then fi fi - # Does the first paragraph look like a mail header? - #if [ ${#mh[@]} -eq 0 ] - #then - # if echo "$header" | awk ' - # /^$/ { exit (!mh || not_mh) } - # END { exit (!mh || not_mh) } - # { if (tolower($0) ~ \ - # /^(from|to|reply-to|date|cc):[ \t]/) - # mh = 1 - # else - # not_mh = 1 - # }' - # then - # return 1 - # fi - #fi - # Is the first paragraph short enough to be used as the subject? - if [ ${#mh[@]} -eq 0 ] + if [ -z "$subject" ] then - local para=$(echo $(echo "$header" \ - | sed -e $'/^[ \t]*$/q')) + local para=$(echo "$header" | sed -e $'/^[ \t]*$/q') if [ ${#para} -gt 0 -a ${#para} -lt 150 ] then - mh=( "Replace-Subject: $para" ) + subject=$(echo "$para" | join_lines) body="$(echo "$patch" | awk ' in_body { print } /^[ \t]*$/ { in_body = 1 } @@ -352,14 +342,14 @@ then # body=$patch #fi - if [ ${#mh[@]} -eq 0 ] + if [ -z "$subject" ] then return 1 fi - mh[0]=$(echo "${mh[0]}" \ - | sed -e $'s/\\[[^]]*\\][ \t]*//gi' \ - -e $'s/\<\(fwd\|fw\|re\|aw\|tr\):[ \t]//gi') + subject=$(echo "$subject" \ + | sed -e $'s/^\\(\\(\\[[^]]*\\]\\|fwd:\\|fw:\\|re:\\|aw:\\|tr:\\)[ \t]*\\)*//i') + mh=( "Replace-Subject: $subject" ) # Add recipients defined by some recognized keywords local saved_IFS=$IFS; IFS=$'\n' @@ -412,9 +402,7 @@ do | quilt_mail_patch_filter "$patch" > "$tmpdir/$patch" status=${PIPESTATUS[1]} - subject=$(echo $(sed -n -e '/^$/q' \ - -e $'s/^Replace-Subject:[ \t]*//ip' \ - "$tmpdir/$patch")) + subject=$(formail -x Replace-Subject: < "$tmpdir/$patch" | join_lines) if [ $status -ne 0 -o -z "$subject" ] then printf \ @@ -457,7 +445,7 @@ then if [ -z "$opt_subject" ] then - opt_subject="Re: $(formail -x Subject < "$opt_reply_to" \ + opt_subject="Re: $(formail -x Subject: < "$opt_reply_to" \ | sed -e 's/^ *\([rR][eE]: *\)*//')" fi fi @@ -506,9 +494,8 @@ then fi fi -if [ -z "$(sed -n -e '/^$/q' \ - -e $'s/^Subject:[ \t]*//ip' \ - $introduction)" ] +subject=$(formail -x Subject: < $introduction | join_lines) +if [ -z "$subject" ] then if [ -z "$opt_message" ] then @@ -526,7 +513,7 @@ then exec 1> $opt_mbox fi -subject_prefix=$(sed -ne $'s/^Subject-Prefix:[ \t]*//p' $introduction) +subject_prefix=$(formail -x Subject-Prefix: < $introduction | join_lines) [ -n "$subject_prefix" ] && subject_prefix="$subject_prefix " subject_prefix=${subject_prefix//\'/\'\'} @@ -568,16 +555,17 @@ for patch in "${patches[@]}"; do s = $0 sub(/^[^:]*:[ \t]*/, "", s) gsub(/'\''/, "'\'\''", s) - print "--add-recipient " r "='\''" s "'\''" + print "--add-recipient " r "='\''" s "'\'' \\" } sub(/^Replace-/, "") { r = $0 sub(/:.*/, "", r) s = $0 sub(/^[^:]*:[ \t]*/, "", s) gsub(/'\''/, "'\'\''", s) - print "--replace-header " r "='\''" s "'\''" + print "--replace-header " r "='\''" s "'\'' \\" } ' $body)" +# echo "$modify" | sed -e 's/^/>> /' >&2 p=${subject_prefix//@num@/$(printf %0*d ${#total} $num)} p=${p//@total@/$total} ( echo "Message-Id: <$(msgid)>" @@ -603,7 +591,7 @@ for patch in "${patches[@]}"; do ) | eval $QUILT_DIR/scripts/edmail --charset $opt_charset \ --replace-header Date="\"$new_date\"" \ To Cc Bcc \ - $modify \ + "$modify" \ | sed -e $'s/^\\(Subject:[ \t]\\)/\\1'"$p"'/' \ -e '/^Subject-Prefix:/d' \ | $QUILT_DIR/scripts/edmail --remove-empty-headers \ diff --git a/test/mail.test b/test/mail.test index 7812752..a761175 100644 --- a/test/mail.test +++ b/test/mail.test @@ -62,29 +62,36 @@ < Aw: [patch] Fwd: Re: [patch 5/7] Fw: Subject of 5.diff < + $ cat - no-subject > patches/6.diff + < Subject: Must not expand * ? [abc] + < + + $ ls patches/ > series $ quilt mail --mbox mbox --prefix "test" --subject "This is a test" -m "Message" $ sed -nre "s/^(From [^ ]*).*/\\1/p" -e "/^Subject:/p" -e "/^To:/p" -e "/^Cc:/p" -e "/^ /p" mbox > From a@b.c - > Subject: [test 0/5] This is a test + > Subject: [test 0/6] This is a test > From a@b.c > Cc: Dummy - > Subject: [test 1/5] Subject of 1.diff + > Subject: [test 1/6] Subject of 1.diff > From a@b.c > Cc: Dummy - > Subject: [test 2/5] Subject of 2.diff is: split into multiple lines + > Subject: [test 2/6] Subject of 2.diff is: split into multiple lines > From a@b.c > To: "John X. Doe" - > Subject: [test 3/5] Subject of 3.diff + > Subject: [test 3/6] Subject of 3.diff > To: John X. Doe > From a@b.c > Cc: "Joe R. Hacker" , > "John X. Doe" , > =?UTF-8?q?=C3=9C=20is=20an=20umlaut?= - > Subject: [test 4/5] First paragraph used as subject of 4.diff. + > Subject: [test 4/6] First paragraph used as subject of 4.diff. > Cc: "John X. Doe" > Cc: Ü is an umlaut > From a@b.c - > Subject: [test 5/5] Subject of 5.diff + > Subject: [test 5/6] Subject of 5.diff + > From a@b.c + > Subject: [test 6/6] Must not expand * ? [abc] $ cd .. $ rm -rf d -- cgit