diff options
author | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2013-11-29 16:46:17 +0200 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2013-11-29 18:17:44 +0200 |
commit | 2312c39df95338f6c9759b15374637d64b6d2720 (patch) | |
tree | a6bb36c07aca820d28bc88d4506616d3f8032804 | |
parent | 93f83e5c98ae899dae2c9a80768794f128727ae8 (diff) | |
download | aiaiai-2312c39df95338f6c9759b15374637d64b6d2720.tar.gz |
email-sh-functions: misc improvements
This is a huge patch and it should really be split. But I am being lazy and
committing all at once. Yes, this is bad, sorry, but I am trying to save time.
Anyway, this patch does 2 big changes:
1. Improves the strip_address function so that it does not anymore depend on
any global 'cfg_*' variables and gets the e-mail address to strip as a
parameter.
2. Simplifies the 'compose_email' function interface and teach it to get a
single list of addresses to CC. This required some an additional function
for merging 2 lists of e-mails. But the end result is that
email-test-patchset becomes simpler.
I have tested this patch.
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
-rw-r--r-- | email/aiaiai-email-sh-functions | 60 | ||||
-rwxr-xr-x | email/aiaiai-email-test-patchset | 36 |
2 files changed, 62 insertions, 34 deletions
diff --git a/email/aiaiai-email-sh-functions b/email/aiaiai-email-sh-functions index 5005ef8..937105a 100644 --- a/email/aiaiai-email-sh-functions +++ b/email/aiaiai-email-sh-functions @@ -57,17 +57,38 @@ subject_check() # Usage: strip_address <list> <email> strip_address() { - local list="$1" + local list="$1"; shift + local email="$1"; shift + local l d + + # Get the local and domain parts of the e-mail address + l="$(printf "%s" "$email" | LC_ALL=C sed "s/@.*//g")" + d="$(printf "%s" "$email" | LC_ALL=C sed "s/.*@//g")" # Quote special sed symbols - quote_sed_regexp_variable ol "$cfg_ownmail_local" - quote_sed_regexp_variable od "$cfg_ownmail_domain" + quote_sed_regexp_variable l "$l" + quote_sed_regexp_variable d "$d" + + # Strip the email from the list taking into account that local@domain + # address is equivalent to the local+xyz@domain address. + printf "%s" "$list" | LC_ALL=C sed -e "s/[^,]*$l+\{0,1\}[^@]*@$d[^,]*//g" \ + -e "s/,,/,/g" -e "s/^,//" -e "s/,$//" \ + -e "s/[[:blank:]]\+//g" +} - printf "%s" "$list" | LC_ALL=C sed -e "s/[^,]*$ol+\{0,1\}[^@]*@$od[^,]*//g" \ - -e "s/,,/,/g" -e "s/^,//" -e "s/,$//" +# Merge e-mail addresses into a comma-separated list +# Usage: merge_addresses "addr1" "addr2" +merge_addresses() +{ + local addr1="$1"; shift + local addr2="$1"; shift + local list="$(printf "%s" "$addr1,$addr2" | LC_ALL=C tr -d "\n")" + + printf "%s" "$list" | LC_ALL=C sed -e "s/,,/,/g" -e "s/^,//" \ + -e "s/,$//" -e "s/[[:blank:]]\+//g" } -# A helper function for 'init_config_get' which fails when unable to get the +# A helper function for "init_config_get" which fails when unable to get the # ini file option. __ini_config_get_or_die() { @@ -108,11 +129,11 @@ parse_config() cfg_preamble="$(cat "$cfg_preamble")" # Get the local and domain parts of own e-mail address - cfg_ownmail_local="$(printf "%s" "$cfg_ownmail" | LC_ALL=C sed 's/@.*//g')" - cfg_ownmail_domain="$(printf "%s" "$cfg_ownmail" | LC_ALL=C sed 's/.*@//g')" + cfg_ownmail_local="$(printf "%s" "$cfg_ownmail" | LC_ALL=C sed "s/@.*//g")" + cfg_ownmail_domain="$(printf "%s" "$cfg_ownmail" | LC_ALL=C sed "s/.*@//g")" } -# Similar to 'parse_config', but parses a project configuration section. If the +# Similar to "parse_config", but parses a project configuration section. If the # project is found, the following variables are defined: cfg_name. cfg_descr, # cfg_path, cfg_configs, cfg_branch, cfg_reply_to_all, cfg_accept_notify, # cfg_always_cc, cfg_unwanted_keywords. If the project is not found, this @@ -137,28 +158,33 @@ parse_prj_config() # 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. +# cfg_preamble, cfg_signature. See "parse_config()" function. # -# Usage: compose_email <to> <cc1> <cc2> <subj> <in_reply_to> <tmpfile> +# 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. compose_email() { local to="$1"; shift - local cc1="$1"; shift - local cc2="$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 + local __newline=" +" + + cc="$(LC_ALL=C; printf "%s" "$cc" | tr "," "\n" | \ + sed -e "/^$/d" -e "s/^/Cc: /g")" + cc="$__newline$cc" + fi cat > "$tmpfile" <<EOF To: $to -From: "$cfg_ownname" <$cfg_ownmail> -Cc: $cfg_always_cc -Cc: $cc1 -Cc: $cc2 +From: "$cfg_ownname" <$cfg_ownmail>$cc Subject: Re: $subj In-Reply-To: $in_reply_to Reply-To: "$cfg_adminname" <$cfg_adminmail> diff --git a/email/aiaiai-email-test-patchset b/email/aiaiai-email-test-patchset index 6c09af1..4c55226 100755 --- a/email/aiaiai-email-test-patchset +++ b/email/aiaiai-email-test-patchset @@ -190,17 +190,27 @@ fi # Find out the project name prj="$(project_name "$to")" -[ -n "$prj" ] || prj="$(project_name "$cc")" verbose "Project \"$prj\"" -# Strip own address -to=$(strip_address "$to") -cc=$(strip_address "$cc") +# Fetch project configuration +parse_prj_config "$cfgfile" "$prj" + +# Merge the "To" and "Cc" addresses +to="$(merge_addresses "$to" "$cc")" + +# If we are not going to reply to everywone, we do not need to the To/Cc +# addresses +if [ "$cfg_reply_to_all" != "1" ]; then + to= +else + # Strip own address + to=$(strip_address "$to" "$cfg_ownmail") +fi # Reject the e-mail if the project has not been specified if [ -z "$prj" ]; then - compose_email "$from" "" "" "$subj" "$id" "$tmpdir/mail" <<EOF + compose_email "$from" "" "$subj" "$id" "$tmpdir/mail" <<EOF Sorry, but you have not specified the project name. Please, specify it using symbol "+" in the e-mail address of $ownname. @@ -213,12 +223,9 @@ EOF exit 0 fi -# Fetch project configuration -parse_prj_config "$cfgfile" "$prj" - # Check if we have this project in our config file if [ -z "$cfg_name" ]; then - compose_email "$from" "" "" "$subj" "$id" "$tmpdir/mail" <<EOF + compose_email "$from" "" "$subj" "$id" "$tmpdir/mail" <<EOF Sorry, but project "$prj" is not supported. List of projects $cfg_ownname supports: $(list_projects) @@ -228,15 +235,10 @@ EOF exit 0 fi -if [ "$cfg_reply_to_all" != "1" ]; then - to= - cc= -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" "$cc" "$subj" "$id" "$tmpdir/mail" <<EOF + compose_email "$from" "$to" "$subj" "$id" "$tmpdir/mail" <<EOF Your patch or patch-set: $(fetch_header_per_patch "Subject" < "$mbox" | sort) @@ -254,7 +256,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" "$cc" "$subj" "$id" "$tmpdir/mail" <<EOF + compose_email "$from" "$to" "$subj" "$id" "$tmpdir/mail" <<EOF Sorry, but an internal error happened. Please, send a bug report to "$cfg_adminname" <$cfg_adminmail>. EOF @@ -263,7 +265,7 @@ EOF message "Test is finished, sending back the results" -compose_email "$from" "$to" "$cc" "$subj" "$id" "$tmpdir/mail" <<EOF +compose_email "$from" "$to" "$subj" "$id" "$tmpdir/mail" <<EOF $cfg_built_preamble $(fetch_header_per_patch "Subject" < "$mbox" | sort) |