diff options
author | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2013-11-29 18:43:28 +0200 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2013-11-29 18:45:45 +0200 |
commit | 01115712698bf127f9cfb9d86d19d1bb2ef2ae7b (patch) | |
tree | 6e90cef9fa557ffbaacb4708661723d7e0bdc3fc | |
parent | 2312c39df95338f6c9759b15374637d64b6d2720 (diff) | |
download | aiaiai-01115712698bf127f9cfb9d86d19d1bb2ef2ae7b.tar.gz |
email-sh-functions: rework e-mail sending some more
Leave only the email composition stuff in the common code, and move the e-mail
sending stuff to email-test-patchset. This way the common code does not depend
on the "verbose" and "test_mode" variables anymore, which is a bit cleaner.
Plus add an explicit check that mutt is present.
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
-rw-r--r-- | email/aiaiai-email-sh-functions | 20 | ||||
-rwxr-xr-x | email/aiaiai-email-test-patchset | 27 |
2 files changed, 27 insertions, 20 deletions
diff --git a/email/aiaiai-email-sh-functions b/email/aiaiai-email-sh-functions index 937105a..d145081 100644 --- a/email/aiaiai-email-sh-functions +++ b/email/aiaiai-email-sh-functions @@ -156,21 +156,17 @@ parse_prj_config() cfg_unwanted_keywords="$(ini_config_get "$cfgfile" ""prj_$prj"" "unwanted_keywords")" } -# Send an e-mail reply. This function assumes that the following variables are -# defined: cfg_ownname, cfg_ownmail, cfg_adminname, cfg_adminmail, -# cfg_preamble, cfg_signature. See "parse_config()" function. +# Compose (but not send) e-mail reply. This function assumes that the following +# variables are defined: cfg_ownname, cfg_ownmail, cfg_adminname, +# cfg_adminmail, cfg_preamble, cfg_signature. See "parse_config()" function. # -# Usage: compose_email <to> <cc> <subj> <in_reply_to> <tmpfile> -# -# The "tmpfile" parameter is a file where this function will store a copy of -# the send e-mail. +# Usage: compose_email <to> <cc> <subj> <in_reply_to> compose_email() { local to="$1"; shift local cc="$1"; shift local subj="$1"; shift local in_reply_to="$1"; shift - local tmpfile="$1"; shift if [ -n "$cc" ]; then # A newline characters @@ -182,7 +178,7 @@ compose_email() cc="$__newline$cc" fi - cat > "$tmpfile" <<EOF + cat <<EOF To: $to From: "$cfg_ownname" <$cfg_ownmail>$cc Subject: Re: $subj @@ -196,10 +192,4 @@ $(cat) -- $cfg_signature EOF - - [ -z "$verbose" ] || cat -- "$tmpfile" >&2 - [ -z "$test_mode" ] && - mutt -x -H "$tmpdir/mail" </dev/null || - verbose "Do not actually send the email - we are in test mode" } - diff --git a/email/aiaiai-email-test-patchset b/email/aiaiai-email-test-patchset index 4c55226..e39d1b5 100755 --- a/email/aiaiai-email-test-patchset +++ b/email/aiaiai-email-test-patchset @@ -95,6 +95,21 @@ project_name() printf "%s" "$list" | LC_ALL=C sed -n -e "s/.*$ol+\([^@]\+\)@$od.*/\1/p" | head -n1 } +# Send an e-mail reply to the patch author. +# Usage: send_email +send_email() +{ + compose_email "$from" "$to" "$subj" "$id" > "$tmpdir/mail" + + [ -z "$verbose" ] || cat -- "$tmpdir/mail" >&2 + + if [ -z "$test_mode" ]; then + mutt -x -H "$tmpdir/mail" </dev/null + else + verbose "Do not actually send the email - we are in test mode" + fi +} + TEMP=`getopt -n $PROG -o i:,C:,p,v,h --long test-mode,input:,confdir:,preserve,bisectability,sparse,smatch,cppcheck,coccinelle,verbose,help -- "$@"` || fail_usage "" eval set -- "$TEMP" @@ -155,6 +170,8 @@ done [ "$#" -eq 1 ] || fatal "Insufficient or too many arguments" +program_required "mutt" "" + cfgfile="$1"; shift # Save the mbox to a temporary file if it comes from stdin @@ -210,7 +227,7 @@ fi # Reject the e-mail if the project has not been specified if [ -z "$prj" ]; then - compose_email "$from" "" "$subj" "$id" "$tmpdir/mail" <<EOF + send_email <<EOF Sorry, but you have not specified the project name. Please, specify it using symbol "+" in the e-mail address of $ownname. @@ -225,7 +242,7 @@ fi # Check if we have this project in our config file if [ -z "$cfg_name" ]; then - compose_email "$from" "" "$subj" "$id" "$tmpdir/mail" <<EOF + send_email <<EOF Sorry, but project "$prj" is not supported. List of projects $cfg_ownname supports: $(list_projects) @@ -238,7 +255,7 @@ fi # Notify the sender that the patches have been accepted if [ "$cfg_accept_notify" = "1" ]; then message "Sending \"accepted\" e-mail" - compose_email "$from" "$to" "$subj" "$id" "$tmpdir/mail" <<EOF + send_email <<EOF Your patch or patch-set: $(fetch_header_per_patch "Subject" < "$mbox" | sort) @@ -256,7 +273,7 @@ aiaiai-test-patchset $verbose $preserve $bisectability $sparse $smatch $cppcheck "$cfg_path" "$cfg_configs" > "$tmpdir/test-patchset.log" || { message "aiaiai-test-patchset failed" - compose_email "$from" "$to" "$subj" "$id" "$tmpdir/mail" <<EOF + send_email <<EOF Sorry, but an internal error happened. Please, send a bug report to "$cfg_adminname" <$cfg_adminmail>. EOF @@ -265,7 +282,7 @@ EOF message "Test is finished, sending back the results" -compose_email "$from" "$to" "$subj" "$id" "$tmpdir/mail" <<EOF +send_email <<EOF $cfg_built_preamble $(fetch_header_per_patch "Subject" < "$mbox" | sort) |