diff options
author | Jason Cox <me@jasoncarloscox.com> | 2023-05-10 17:47:07 -0400 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-05-16 13:56:52 +0200 |
commit | 0eaf05d3fa6295e7df06793a967d3389d2a0f7d8 (patch) | |
tree | 86d1c82fc1b81b194db3d77ac0025187328c7c5e /widgets/compose.go | |
parent | d2ea1aac09fbf02873c3070cadef4386196bb040 (diff) | |
download | aerc-0eaf05d3fa6295e7df06793a967d3389d2a0f7d8.tar.gz |
compose: warn before sending with empty subject
Ask user whether they want to abort before sending if the subject header
is empty and they have enabled the warn-empty-subject config option.
Signed-off-by: Jason Cox <me@jasoncarloscox.com>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'widgets/compose.go')
-rw-r--r-- | widgets/compose.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/widgets/compose.go b/widgets/compose.go index 1e7450e9..4735782b 100644 --- a/widgets/compose.go +++ b/widgets/compose.go @@ -853,24 +853,36 @@ func (c *Composer) WriteMessage(header *mail.Header, writer io.Writer) error { } } -func (c *Composer) ShouldWarnAttachment() (bool, error) { +func (c *Composer) ShouldWarnAttachment() bool { regex := config.Compose.NoAttachmentWarning if regex == nil || len(c.attachments) > 0 { - return false, nil + return false } err := c.reloadEmail() if err != nil { - return false, errors.Wrap(err, "reloadEmail") + log.Warnf("failed to check for a forgotten attachment (reloadEmail): %v", err) + return true } body, err := io.ReadAll(c.email) if err != nil { - return false, errors.Wrap(err, "io.ReadAll") + log.Warnf("failed to check for a forgotten attachment (io.ReadAll): %v", err) + return true + } + + return regex.Match(body) +} + +func (c *Composer) ShouldWarnSubject() bool { + if !config.Compose.EmptySubjectWarning { + return false } - return regex.Match(body), nil + // ignore errors because the raw header field is sufficient here + subject, _ := c.header.Subject() + return len(subject) == 0 } func writeMsgImpl(c *Composer, header *mail.Header, writer io.Writer) error { |