]> www.infradead.org Git - users/dedekind/aiaiai.git/commitdiff
email-sh-functions: rework e-mail sending some more
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Fri, 29 Nov 2013 16:43:28 +0000 (18:43 +0200)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Fri, 29 Nov 2013 16:45:45 +0000 (18:45 +0200)
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>
email/aiaiai-email-sh-functions
email/aiaiai-email-test-patchset

index 937105aba63a9e5d2954e9dbae281c09fe07126e..d1450814067f68da03fc840bb746bfb2a571dd38 100644 (file)
@@ -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"
 }
-
index 4c55226fb1d2925e02a56f5d2da5aa70106fafae..e39d1b50f90760157705ed551093db085da72448 100755 (executable)
@@ -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)