about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2020-05-23 16:00:06 +0200
committerLeah Neukirchen <leah@vuxu.org>2020-05-23 16:00:06 +0200
commit282de65079f2a5438df3632d1811219250ee18b8 (patch)
treec96e97368b5b660e4f6bf642674a34d840eebf07
parent3ea0c9c35588464c9a529a727ba281325b08e6fa (diff)
downloadmblaze-282de65079f2a5438df3632d1811219250ee18b8.tar.gz
mblaze-282de65079f2a5438df3632d1811219250ee18b8.tar.xz
mblaze-282de65079f2a5438df3632d1811219250ee18b8.zip
mrep: use Reply-From configuration to find From header
This allows replying from different addresses than Local-Mailbox
if they appear in To, Cc or Bcc.

Idea and initial patch by @nmeum.
-rw-r--r--man/mblaze-profile.515
-rwxr-xr-xmcom13
2 files changed, 26 insertions, 2 deletions
diff --git a/man/mblaze-profile.5 b/man/mblaze-profile.5
index e1fa01c..f6f535b 100644
--- a/man/mblaze-profile.5
+++ b/man/mblaze-profile.5
@@ -54,6 +54,21 @@ If set,
 .Xr mcom 1
 will create draft messages in this maildir,
 and save messages there after sending.
+.It Li Reply-From\&:
+A comma-separated list of mail addresses (formatted like this:
+.Sq Li My Name <username@domain> )
+that are automatically used for
+the
+.Li From\&:
+header in a reply if present in the
+.Li To\&: ,
+.Li Cc\&: ,
+or
+.Li Bcc\&:
+header.
+If not set,
+.Li Alternate\&-Mailboxes\&:
+will be used as a default.
 .It Li Scan\&-Format\&:
 The default format string for
 .Xr mscan 1 .
diff --git a/mcom b/mcom
index 205a1ce..693d5c4 100755
--- a/mcom
+++ b/mcom
@@ -15,6 +15,12 @@ notmine() {
 	grep -Fv -e "$mine"
 }
 
+replyfrom() {
+	addrs="$(maddr -a -h reply-from: "$MBLAZE/profile")"
+	[ -z "$addrs" ] && addrs="$(maddr -a -h alternate-mailboxes: "$MBLAZE/profile")"
+	grep -F -e "$addrs"
+}
+
 ouniq() {
 	awk '!seen[$0]++'
 }
@@ -358,8 +364,11 @@ fi
 		printf 'Subject: Re: %s\n' "$(COLUMNS=10000 mscan -f '%S' "$1")"
 		if ! printf '%s\n' "$hdrs" | awk '{ print }' |
 		     mhdr -h from: /dev/stdin >/dev/null; then
-			from=$(mhdr -h local-mailbox "$MBLAZE/profile")
-			[ "$from" ] && printf 'From: %s\n' "$from"
+			addr=$(maddr -a -h to:cc:bcc: "$1" | replyfrom | head -n1)
+			[ -n "$addr" ] && from=$(maddr -h reply-from "$MBLAZE/profile" | grep -Fi "<$addr>" | head -n1)
+			[ -n "$addr" ] && [ -z "$from" ] && from=$(maddr -h alternate-mailboxes "$MBLAZE/profile" | grep -Fi "<$addr>" | head -n1)
+			[ -z "$from" ] && from=$(mhdr -h local-mailbox "$MBLAZE/profile")
+			[ -n "$from" ] && printf 'From: %s\n' "$from"
 		fi
 		mid=$(mhdr -h message-id "$1")
 		if [ "$mid" ]; then