Skip to content

Commit

Permalink
mrep: use Reply-From configuration to find From header
Browse files Browse the repository at this point in the history
This allows replying from different addresses than Local-Mailbox
if they appear in To, Cc or Bcc.

Idea and initial patch by @nmeum.
  • Loading branch information
leahneukirchen committed May 23, 2020
1 parent 3ea0c9c commit 282de65
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
15 changes: 15 additions & 0 deletions man/mblaze-profile.5
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
13 changes: 11 additions & 2 deletions mcom
Original file line number Diff line number Diff line change
Expand Up @@ -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]++'
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 282de65

Please sign in to comment.