diff options
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | commands/compose/send.go | 17 | ||||
-rw-r--r-- | config/aerc.conf | 5 | ||||
-rw-r--r-- | config/compose.go | 1 | ||||
-rw-r--r-- | doc/aerc-config.5.scd | 5 | ||||
-rw-r--r-- | widgets/compose.go | 22 |
6 files changed, 41 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index b293b869..53208c19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added - Colorize can style diff chunk function names with `diff_chunk_func`. +- Warn before sending emails with an empty subject with `empty-subject-warning` + in `aerc.conf`. ## [0.15.2](https://git.sr.ht/~rjarry/aerc/refs/0.15.2) - 2023-05-11 diff --git a/commands/compose/send.go b/commands/compose/send.go index d43f28ea..eeea96cd 100644 --- a/commands/compose/send.go +++ b/commands/compose/send.go @@ -109,12 +109,17 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error { log.Debugf("send config rcpts: %s", ctx.rcpts) log.Debugf("send config domain: %s", ctx.domain) - warn, err := composer.ShouldWarnAttachment() - if err != nil || warn { - msg := "You may have forgotten an attachment." - if err != nil { - log.Warnf("failed to check for a forgotten attachment: %v", err) - msg = "Failed to check for a forgotten attachment." + warnSubject := composer.ShouldWarnSubject() + warnAttachment := composer.ShouldWarnAttachment() + if warnSubject || warnAttachment { + var msg string + switch { + case warnSubject && warnAttachment: + msg = "The subject is empty, and you may have forgotten an attachment." + case warnSubject: + msg = "The subject is empty." + default: + msg = "You may have forgotten an attachment." } prompt := widgets.NewPrompt( diff --git a/config/aerc.conf b/config/aerc.conf index cb720e07..800e6ec6 100644 --- a/config/aerc.conf +++ b/config/aerc.conf @@ -417,6 +417,11 @@ # Default: true #reply-to-self=true +# Warn before sending an email with an empty subject. +# +# Default: false +#empty-subject-warning=false + # # Warn before sending an email that matches the specified regexp but does not # have any attachments. Leave empty to disable this feature. diff --git a/config/compose.go b/config/compose.go index 70533453..017b9efb 100644 --- a/config/compose.go +++ b/config/compose.go @@ -13,6 +13,7 @@ type ComposeConfig struct { AddressBookCmd string `ini:"address-book-cmd"` ReplyToSelf bool `ini:"reply-to-self" default:"true"` NoAttachmentWarning *regexp.Regexp `ini:"no-attachment-warning" parse:"ParseNoAttachmentWarning"` + EmptySubjectWarning bool `ini:"empty-subject-warning"` FilePickerCmd string `ini:"file-picker-cmd"` FormatFlowed bool `ini:"format-flowed"` } diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd index 5a04288a..aff57729 100644 --- a/doc/aerc-config.5.scd +++ b/doc/aerc-config.5.scd @@ -571,6 +571,11 @@ These options are configured in the *[compose]* section of _aerc.conf_. Default: _true_ +*empty-subject-warning* = _true_|_false_ + Warn before sending an email with an empty subject. + + Default: _false_ + *no-attachment-warning* = _<regexp>_ Specifies a regular expression against which an email's body should be tested before sending an email with no attachment. If the regexp 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 { |