Complete the F rune.

%F now shows the auth name or recepient name/address if the
message is from you.
This commit is contained in:
Srivathsan Murali 2019-11-12 12:50:00 +01:00 committed by Drew DeVault
parent 4bdef7d860
commit c655afa32b
4 changed files with 27 additions and 6 deletions

View File

@ -36,7 +36,9 @@ func (trig *TriggersConfig) ExecNewEmail(account *AccountConfig,
conf *AercConfig, msg *models.MessageInfo) { conf *AercConfig, msg *models.MessageInfo) {
err := trig.ExecTrigger(trig.NewEmail, err := trig.ExecTrigger(trig.NewEmail,
func(part string) (string, error) { 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) conf.Ui.TimestampFormat, account.Name, 0, msg)
if err != nil { if err != nil {
return "", err return "", err

View File

@ -57,11 +57,12 @@ These options are configured in the *[ui]* section of aerc.conf.
| %f | %f
: sender name and address : sender name and address
| %F | %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 | %i
: message id : message id
| %n | %n
: same as %F : sender name, or sender address if none
| %r | %r
: comma-separated list of formatted recipient names and addresses : comma-separated list of formatted recipient names and addresses
| %R | %R

View File

@ -3,18 +3,32 @@ package format
import ( import (
"errors" "errors"
"fmt" "fmt"
gomail "net/mail"
"strings" "strings"
"unicode" "unicode"
"git.sr.ht/~sircmpwn/aerc/models" "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, accountName string, number int, msg *models.MessageInfo) (string,
[]interface{}, error) { []interface{}, error) {
retval := make([]byte, 0, len(format)) retval := make([]byte, 0, len(format))
var args []interface{} var args []interface{}
accountFromAddress := parseAddress(fromAddress)
var c rune var c rune
for i, ni := 0, 0; i < len(format); { for i, ni := 0, 0; i < len(format); {
ni = strings.IndexByte(format[i:], '%') ni = strings.IndexByte(format[i:], '%')
@ -109,9 +123,12 @@ func ParseMessageFormat(format string, timestampformat string,
errors.New("found no address for sender") errors.New("found no address for sender")
} }
addr := msg.Envelope.From[0] addr := msg.Envelope.From[0]
// TODO: handle case when sender is current user. Then
// use recipient's name
var val string var val string
if addr.Name == accountFromAddress.Name {
addr = msg.Envelope.To[0]
}
if addr.Name != "" { if addr.Name != "" {
val = addr.Name val = addr.Name
} else { } else {

View File

@ -107,6 +107,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
ctx.Fill(0, row, ctx.Width(), 1, ' ', style) ctx.Fill(0, row, ctx.Width(), 1, ' ', style)
fmtStr, args, err := format.ParseMessageFormat( fmtStr, args, err := format.ParseMessageFormat(
ml.aerc.SelectedAccount().acct.From,
ml.conf.Ui.IndexFormat, ml.conf.Ui.IndexFormat,
ml.conf.Ui.TimestampFormat, "", i, msg) ml.conf.Ui.TimestampFormat, "", i, msg)
if err != nil { if err != nil {