diff options
author | Yash Srivastav <yash111998@gmail.com> | 2019-06-08 01:05:23 +0530 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-06-07 16:22:01 -0400 |
commit | fca7321639f77bbf825dc897156d7a21993a2c69 (patch) | |
tree | 5e503bf4ebd9672eef2af5cbad49b5b73405e548 /widgets | |
parent | 6d491569c0f95bec03cc837446c2836acabe99ae (diff) |
Message list: implement index-format option
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/msglist.go | 7 | ||||
-rw-r--r-- | widgets/msgviewer.go | 28 |
2 files changed, 11 insertions, 24 deletions
diff --git a/widgets/msglist.go b/widgets/msglist.go index caa868f..f1cbb31 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -80,7 +80,12 @@ func (ml *MessageList) Draw(ctx *ui.Context) { style = style.Foreground(tcell.ColorGray) } ctx.Fill(0, row, ctx.Width(), 1, ' ', style) - ctx.Printf(0, row, style, "%s", msg.Envelope.Subject) + fmtStr, args, err := lib.ParseIndexFormat(ml.conf, i, msg) + if err != nil { + ctx.Printf(0, row, style, "%v", err) + } else { + ctx.Printf(0, row, style, fmtStr, args...) + } row += 1 } diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index 6017e50..52407b7 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -2,7 +2,6 @@ package widgets import ( "bufio" - "bytes" "fmt" "io" "os/exec" @@ -44,23 +43,6 @@ type PartSwitcher struct { showHeaders bool } -func formatAddresses(addrs []*imap.Address) string { - val := bytes.Buffer{} - for i, addr := range addrs { - if addr.PersonalName != "" { - val.WriteString(fmt.Sprintf("%s <%s@%s>", - addr.PersonalName, addr.MailboxName, addr.HostName)) - } else { - val.WriteString(fmt.Sprintf("%s@%s", - addr.MailboxName, addr.HostName)) - } - if i != len(addrs)-1 { - val.WriteString(", ") - } - } - return val.String() -} - func NewMessageViewer(acct *AccountView, conf *config.AercConfig, store *lib.MessageStore, msg *types.MessageInfo) *MessageViewer { @@ -84,12 +66,12 @@ func NewMessageViewer(acct *AccountView, conf *config.AercConfig, headers.AddChild( &HeaderView{ Name: "From", - Value: formatAddresses(msg.Envelope.From), + Value: lib.FormatAddresses(msg.Envelope.From), }).At(0, 0) headers.AddChild( &HeaderView{ Name: "To", - Value: formatAddresses(msg.Envelope.To), + Value: lib.FormatAddresses(msg.Envelope.To), }).At(0, 1) headers.AddChild( &HeaderView{ @@ -379,11 +361,11 @@ func NewPartViewer(conf *config.AercConfig, case "subject": header = msg.Envelope.Subject case "from": - header = formatAddresses(msg.Envelope.From) + header = lib.FormatAddresses(msg.Envelope.From) case "to": - header = formatAddresses(msg.Envelope.To) + header = lib.FormatAddresses(msg.Envelope.To) case "cc": - header = formatAddresses(msg.Envelope.Cc) + header = lib.FormatAddresses(msg.Envelope.Cc) } if f.Regex.Match([]byte(header)) { filter = exec.Command("sh", "-c", f.Command) |