Populate "From" header from config for new emails

This commit is contained in:
Drew DeVault 2019-05-13 16:04:01 -04:00
parent bda74452a8
commit 17bd2dc4db
5 changed files with 31 additions and 14 deletions

View File

@ -17,8 +17,8 @@ func Compose(aerc *widgets.Aerc, args []string) error {
if len(args) != 1 { if len(args) != 1 {
return errors.New("Usage: compose") return errors.New("Usage: compose")
} }
// TODO: Pass along the sender info acct := aerc.SelectedAccount()
composer := widgets.NewComposer() composer := widgets.NewComposer(acct.AccountConfig())
// TODO: Change tab name when message subject changes // TODO: Change tab name when message subject changes
aerc.NewTab(composer, runewidth.Truncate( aerc.NewTab(composer, runewidth.Truncate(
"New email", 32, "…")) "New email", 32, "…"))

View File

@ -8,10 +8,12 @@
# [Personal] # [Personal]
# source=imaps://username[:password]@hostname[:port] # source=imaps://username[:password]@hostname[:port]
# outgoing=smtps+plain://username[:password]@hostname[:port] # outgoing=smtps+plain://username[:password]@hostname[:port]
# from=Joe Bloe <joe@example.org>
# #
# [Work] # [Work]
# source=imaps://username[:password]@hostname[:port] # source=imaps://username[:password]@hostname[:port]
# outgoing=/usr/bin/sendmail # outgoing=/usr/bin/sendmail
# from=Jane Plain <jane@example.org>
# folders=INBOX,Sent,Archives # folders=INBOX,Sent,Archives
# default=Archives # default=Archives
# #

View File

@ -30,6 +30,7 @@ const (
type AccountConfig struct { type AccountConfig struct {
Default string Default string
From string
Name string Name string
Source string Source string
Folders []string Folders []string
@ -108,6 +109,8 @@ func loadAccountConfig(path string) ([]AccountConfig, error) {
account.Folders = strings.Split(val, ",") account.Folders = strings.Split(val, ",")
} else if key == "outgoing" { } else if key == "outgoing" {
account.Outgoing = val account.Outgoing = val
} else if key == "from" {
account.From = val
} else if key != "name" { } else if key != "name" {
account.Params[key] = val account.Params[key] = val
} }

View File

@ -80,6 +80,10 @@ func NewAccountView(conf *config.AercConfig, acct *config.AccountConfig,
return view return view
} }
func (acct *AccountView) AccountConfig() *config.AccountConfig {
return acct.acct
}
func (acct *AccountView) Name() string { func (acct *AccountView) Name() string {
return acct.acct.Name return acct.acct.Name
} }

View File

@ -1,11 +1,14 @@
package widgets package widgets
import ( import (
"io/ioutil"
"os"
"os/exec" "os/exec"
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"github.com/mattn/go-runewidth" "github.com/mattn/go-runewidth"
"git.sr.ht/~sircmpwn/aerc2/config"
"git.sr.ht/~sircmpwn/aerc2/lib/ui" "git.sr.ht/~sircmpwn/aerc2/lib/ui"
) )
@ -21,7 +24,10 @@ type Composer struct {
to *headerEditor to *headerEditor
} }
config *config.AccountConfig
editor *Terminal editor *Terminal
email *os.File
grid *ui.Grid grid *ui.Grid
focusable []ui.DrawableInteractive focusable []ui.DrawableInteractive
@ -29,7 +35,7 @@ type Composer struct {
} }
// TODO: Let caller configure headers, initial body (for replies), etc // TODO: Let caller configure headers, initial body (for replies), etc
func NewComposer() *Composer { func NewComposer(conf *config.AccountConfig) *Composer {
grid := ui.NewGrid().Rows([]ui.GridSpec{ grid := ui.NewGrid().Rows([]ui.GridSpec{
{ui.SIZE_EXACT, 3}, {ui.SIZE_EXACT, 3},
{ui.SIZE_WEIGHT, 1}, {ui.SIZE_WEIGHT, 1},
@ -48,32 +54,34 @@ func NewComposer() *Composer {
}) })
to := newHeaderEditor("To", "") to := newHeaderEditor("To", "")
from := newHeaderEditor("From", "") from := newHeaderEditor("From", conf.From)
subject := newHeaderEditor("Subject", "") subject := newHeaderEditor("Subject", "")
headers.AddChild(to).At(0, 0) headers.AddChild(to).At(0, 0)
headers.AddChild(from).At(0, 1) headers.AddChild(from).At(0, 1)
headers.AddChild(subject).At(1, 0).Span(1, 2) headers.AddChild(subject).At(1, 0).Span(1, 2)
headers.AddChild(ui.NewFill(' ')).At(2, 0).Span(1, 2) headers.AddChild(ui.NewFill(' ')).At(2, 0).Span(1, 2)
email, err := ioutil.TempFile("", "aerc-compose-*.eml")
if err != nil {
// TODO: handle this better
return nil
}
// TODO: built-in config option, $EDITOR, then vi, in that order // TODO: built-in config option, $EDITOR, then vi, in that order
// TODO: temp file editor := exec.Command("vim", email.Name())
editor := exec.Command("vim")
term, _ := NewTerminal(editor) term, _ := NewTerminal(editor)
grid.AddChild(headers).At(0, 0) grid.AddChild(headers).At(0, 0)
grid.AddChild(term).At(1, 0) grid.AddChild(term).At(1, 0)
return &Composer{ return &Composer{
grid: grid, config: conf,
editor: term, editor: term,
email: email,
grid: grid,
// You have to backtab to get to "From", since you usually don't edit it // You have to backtab to get to "From", since you usually don't edit it
focused: 1, focused: 1,
focusable: []ui.DrawableInteractive{ focusable: []ui.DrawableInteractive{from, to, subject, term},
from,
to,
subject,
term,
},
} }
} }