# 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()
{
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
# 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>
# 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.
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)
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)
"$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
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)