From 4e4dcdf1cab41e975139bf62d666ed16594507df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Mon, 20 Apr 2020 15:20:27 +0200 Subject: [PATCH 1/2] mrep: Set From header according to To/Cc/Bcc header If any of the address contained in the aforementioned headers matches an address configured in the Reply-From header in mblaze-profile(5). Without this change, mrep(1) uses the mail address configured as Local-Mailbox for the From header. While generally desirable, I use different mail addresses for different proposes. As such, I do not want to reply to mails I received through my work address with my private email address. --- man/mblaze-profile.5 | 3 +++ mcom | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/man/mblaze-profile.5 b/man/mblaze-profile.5 index e1fa01c..11fad7b 100644 --- a/man/mblaze-profile.5 +++ b/man/mblaze-profile.5 @@ -44,6 +44,9 @@ to recognize messages sent to you. A comma-separated list of mail addresses that also belong to you, for .Xr mscan 1 to recognize messages sent by or directly to you. +.It Li Reply-From\&: +A comma-separated list of mail addresses that are automatically used for +the From header in a reply if present in the Cc, To, or Bcc header. .It Li FQDN\&: The fully qualified domain name used for .Li Message\&-Id\&: diff --git a/mcom b/mcom index e2f7100..65ebfaf 100755 --- a/mcom +++ b/mcom @@ -15,6 +15,11 @@ notmine() { grep -Fv -e "$mine" } +replyfrom() { + addrs="$(maddr -a -h reply-from: "$MBLAZE/profile")" + grep -F -e "$addrs" +} + ouniq() { awk '!seen[$0]++' } @@ -356,7 +361,15 @@ fi 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") + + addr=$(maddr -a -h to:cc:bcc: "$1" | replyfrom | head -n1) + if [ -n "$addr" ]; then + from=$(maddr -h reply-from "$MBLAZE/profile" | grep -Fi "<$addr>" | head -n1) + fi + if [ -z "$from" ]; then + from=$(mhdr -h local-mailbox "$MBLAZE/profile") + fi + [ "$from" ] && printf 'From: %s\n' "$from" mid=$(mhdr -h message-id "$1") if [ "$mid" ]; then From 326bcbeced509271c4f1280308e012dd2a24fa10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Mon, 20 Apr 2020 16:20:15 +0200 Subject: [PATCH 2/2] mrep: Fallback to Alternative-Mailboxes when Reply-From is unset --- mcom | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mcom b/mcom index 65ebfaf..59eeab8 100755 --- a/mcom +++ b/mcom @@ -10,14 +10,18 @@ commajoin() { END {print l}' } -notmine() { +grepmine() { mine="$(maddr -a -h local-mailbox:alternate-mailboxes: "$MBLAZE/profile")" - grep -Fv -e "$mine" + grep -F -e "$mine" "$@" } replyfrom() { addrs="$(maddr -a -h reply-from: "$MBLAZE/profile")" - grep -F -e "$addrs" + if [ -z "$addrs" ]; then + grepmine + else + grep -F -e "$addrs" + fi } ouniq() { @@ -354,7 +358,7 @@ 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 }' | @@ -364,7 +368,8 @@ fi addr=$(maddr -a -h to:cc:bcc: "$1" | replyfrom | head -n1) if [ -n "$addr" ]; then - from=$(maddr -h reply-from "$MBLAZE/profile" | grep -Fi "<$addr>" | head -n1) + from=$(maddr -h reply-from:local-mailbox:alternate-mailboxes: \ + "$MBLAZE/profile" | grep -Fi "<$addr>" | head -n1) fi if [ -z "$from" ]; then from=$(mhdr -h local-mailbox "$MBLAZE/profile")