Composer: fix EOF errors

PrepareHeaders generated a fresh message ID and Date header every time.
This instead generates those headers in advance.
This commit is contained in:
Drew DeVault 2019-12-12 10:22:28 -05:00
parent dfe58842b9
commit 0ef4b6f9e2

View file

@ -35,12 +35,14 @@ type Composer struct {
config *config.AercConfig config *config.AercConfig
aerc *Aerc aerc *Aerc
attachments []string
date time.Time
defaults map[string]string defaults map[string]string
editor *Terminal editor *Terminal
email *os.File email *os.File
attachments []string
grid *ui.Grid grid *ui.Grid
header *ui.Grid header *ui.Grid
msgId string
review *reviewMessage review *reviewMessage
worker *types.Worker worker *types.Worker
@ -75,14 +77,16 @@ func NewComposer(aerc *Aerc, conf *config.AercConfig,
} }
c := &Composer{ c := &Composer{
aerc: aerc,
editors: editors,
acct: acct, acct: acct,
aerc: aerc,
config: conf, config: conf,
date: time.Now(),
defaults: defaults, defaults: defaults,
editors: editors,
email: email, email: email,
worker: worker,
layout: layout, layout: layout,
msgId: mail.GenerateMessageID(),
worker: worker,
// 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: focusable, focusable: focusable,
@ -409,7 +413,7 @@ func (c *Composer) PrepareHeader() (*mail.Header, []string, error) {
} }
// Update headers // Update headers
mhdr := (*message.Header)(&header.Header) mhdr := (*message.Header)(&header.Header)
mhdr.SetText("Message-Id", mail.GenerateMessageID()) mhdr.SetText("Message-Id", c.msgId)
headerKeys := make([]string, 0, len(c.editors)) headerKeys := make([]string, 0, len(c.editors))
for key := range c.editors { for key := range c.editors {
@ -437,7 +441,7 @@ func (c *Composer) PrepareHeader() (*mail.Header, []string, error) {
} }
case "Date": case "Date":
if date, err := header.Date(); err != nil || date == (time.Time{}) { if date, err := header.Date(); err != nil || date == (time.Time{}) {
header.SetDate(time.Now()) header.SetDate(c.date)
} }
case "From", "To", "Cc", "Bcc": // Address headers case "From", "To", "Cc", "Bcc": // Address headers
if val != "" { if val != "" {