about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--config/triggers.go4
-rw-r--r--doc/aerc-config.5.scd5
-rw-r--r--lib/format/format.go23
-rw-r--r--widgets/msglist.go1
4 files changed, 27 insertions, 6 deletions
diff --git a/config/triggers.go b/config/triggers.go
index d31f267..f68cb58 100644
--- a/config/triggers.go
+++ b/config/triggers.go
@@ -36,7 +36,9 @@ func (trig *TriggersConfig) ExecNewEmail(account *AccountConfig,
 	conf *AercConfig, msg *models.MessageInfo) {
 	err := trig.ExecTrigger(trig.NewEmail,
 		func(part string) (string, error) {
-			formatstr, args, err := format.ParseMessageFormat(part,
+			formatstr, args, err := format.ParseMessageFormat(
+				account.From,
+				part,
 				conf.Ui.TimestampFormat, account.Name, 0, msg)
 			if err != nil {
 				return "", err
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index 0cde160..02fe4d6 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -57,11 +57,12 @@ These options are configured in the *[ui]* section of aerc.conf.
 |  %f
 :  sender name and address
 |  %F
-:  sender name, or sender address if none
+:  author name, or recipient name if the message is from you.
+   The adderss is shown if no name part.
 |  %i
 :  message id
 |  %n
-:  same as %F
+:  sender name, or sender address if none
 |  %r
 :  comma-separated list of formatted recipient names and addresses
 |  %R
diff --git a/lib/format/format.go b/lib/format/format.go
index b403f2d..a070bc9 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 {
diff --git a/widgets/msglist.go b/widgets/msglist.go
index 5c2d2f4..aed3ed5 100644
--- a/widgets/msglist.go
+++ b/widgets/msglist.go
@@ -107,6 +107,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
 
 		ctx.Fill(0, row, ctx.Width(), 1, ' ', style)
 		fmtStr, args, err := format.ParseMessageFormat(
+			ml.aerc.SelectedAccount().acct.From,
 			ml.conf.Ui.IndexFormat,
 			ml.conf.Ui.TimestampFormat, "", i, msg)
 		if err != nil {
'#n261'>261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335