aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSrivathsan Murali <sri@vathsan.com>2019-11-12 12:50:00 +0100
committerDrew DeVault <sir@cmpwn.com>2019-11-17 13:19:20 -0500
commitc655afa32bea3208885386cc3e600d19c934dd39 (patch)
tree15ab3b45ba905339558ae3d5a64eeca6abb13659 /lib
parent4bdef7d8609aa2d382fa74018e28ccb176276615 (diff)
downloadaerc-c655afa32bea3208885386cc3e600d19c934dd39.tar.gz
Complete the F rune.
%F now shows the auth name or recepient name/address if the message is from you.
Diffstat (limited to 'lib')
-rw-r--r--lib/format/format.go23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/format/format.go b/lib/format/format.go
index b403f2df..a070bc94 100644
--- a/lib/format/format.go
+++ b/lib/format/format.go
@@ -3,18 +3,32 @@ package format
import (
"errors"
"fmt"
+ gomail "net/mail"
"strings"
"unicode"
"git.sr.ht/~sircmpwn/aerc/models"
)
-func ParseMessageFormat(format string, timestampformat string,
+func parseAddress(address string) *gomail.Address {
+ addrs, err := gomail.ParseAddress(address)
+ if err != nil {
+ return nil
+ }
+
+ return addrs
+}
+
+func ParseMessageFormat(
+ fromAddress string,
+ format string, timestampformat string,
accountName string, number int, msg *models.MessageInfo) (string,
[]interface{}, error) {
retval := make([]byte, 0, len(format))
var args []interface{}
+ accountFromAddress := parseAddress(fromAddress)
+
var c rune
for i, ni := 0, 0; i < len(format); {
ni = strings.IndexByte(format[i:], '%')
@@ -109,9 +123,12 @@ func ParseMessageFormat(format string, timestampformat string,
errors.New("found no address for sender")
}
addr := msg.Envelope.From[0]
- // TODO: handle case when sender is current user. Then
- // use recipient's name
var val string
+
+ if addr.Name == accountFromAddress.Name {
+ addr = msg.Envelope.To[0]
+ }
+
if addr.Name != "" {
val = addr.Name
} else {