From 76b882d0eb10f4e77cc3462ab158fc6243dee56d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Mon, 30 Mar 2020 11:31:18 +0200 Subject: [PATCH 1/3] mrep: Set From header according to To/Cc header I use different mail addresses for different purposes. When replying to any email, mrep(1) currently uses the mail address configured as `Local-Mailbox` for the From header. While generally desirable, I do not want to reply to mails I received through my work address with my private email address. This commit introduces a change which uses the email address the email was sent to (as specified by To/Cc) for the From header, as long as this address was configured as an `Alternate-Mailboxes`. --- mcom | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mcom b/mcom index e2f7100..9bfeecc 100755 --- a/mcom +++ b/mcom @@ -10,9 +10,9 @@ commajoin() { END {print l}' } -notmine() { +grepmine() { mine="$(maddr -a -h local-mailbox:alternate-mailboxes: "$MBLAZE/profile")" - grep -Fv -e "$mine" + grep -F -e "$mine" "$@" } ouniq() { @@ -349,14 +349,15 @@ fi printf 'To: %s\n' "$to" printf 'Cc: %s\n' \ "$(mhdr -d -A -h to:cc: "$1" | - notmine |grep -Fv -e "$to" | + grepmine -v |grep -Fv -e "$to" | ouniq |commajoin)" printf 'Bcc: \n' printf '%s\n' "$hdrs" | awk '{ print }' | msed "/body/d" /dev/stdin fi | sed '/^$/d' printf 'Subject: Re: %s\n' "$(COLUMNS=10000 mscan -f '%S' "$1")" - from=$(mhdr -h local-mailbox "$MBLAZE/profile") + from=$(mhdr -d -A -h to:cc: "$1" | grepmine | head -n 1) + [ -z "$from" ] && from=$(mhdr -h local-mailbox "$MBLAZE/profile") [ "$from" ] && printf 'From: %s\n' "$from" mid=$(mhdr -h message-id "$1") if [ "$mid" ]; then From 41671c0deeea5d0eed1efb24703efc3555ac7424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Mon, 30 Mar 2020 19:36:31 +0200 Subject: [PATCH 2/3] fixup! mrep: Set From header according to To/Cc header --- mcom | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mcom b/mcom index 9bfeecc..70c46f8 100755 --- a/mcom +++ b/mcom @@ -356,8 +356,12 @@ fi msed "/body/d" /dev/stdin fi | sed '/^$/d' printf 'Subject: Re: %s\n' "$(COLUMNS=10000 mscan -f '%S' "$1")" - from=$(mhdr -d -A -h to:cc: "$1" | grepmine | head -n 1) - [ -z "$from" ] && from=$(mhdr -h local-mailbox "$MBLAZE/profile") + + from=$(mhdr -h local-mailbox "$MBLAZE/profile") + addr=$(maddr -a -h to:ccc:bcc: "$1" | grepmine | head -n 1) + [ -n "$addr" ] && from=$(printf "%s <%s>" \ + "$(maddr -d -h "local-mailbox" "$MBLAZE/profile")" "$addr") + [ "$from" ] && printf 'From: %s\n' "$from" mid=$(mhdr -h message-id "$1") if [ "$mid" ]; then From fe193fb4e1e8bd4beb174497710ffd347f5c1945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Mon, 30 Mar 2020 19:46:11 +0200 Subject: [PATCH 3/3] fixup! mrep: Set From header according to To/Cc header --- mcom | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mcom b/mcom index 70c46f8..c0f80d0 100755 --- a/mcom +++ b/mcom @@ -358,7 +358,7 @@ fi printf 'Subject: Re: %s\n' "$(COLUMNS=10000 mscan -f '%S' "$1")" from=$(mhdr -h local-mailbox "$MBLAZE/profile") - addr=$(maddr -a -h to:ccc:bcc: "$1" | grepmine | head -n 1) + addr=$(maddr -a -h to:cc:bcc: "$1" | grepmine | head -n 1) [ -n "$addr" ] && from=$(printf "%s <%s>" \ "$(maddr -d -h "local-mailbox" "$MBLAZE/profile")" "$addr")