aboutsummaryrefslogtreecommitdiffstats
path: root/commands/compose/send.go
diff options
context:
space:
mode:
authorJason Cox <dev@jasoncarloscox.com>2022-10-17 13:19:33 -0400
committerRobin Jarry <robin@jarry.cc>2022-10-17 22:41:00 +0200
commit7647dfb8b47edbcb8080bd0327529383142ec888 (patch)
tree80cdd42050598815e0fa872745def3cc7d2bea80 /commands/compose/send.go
parent8ffcd3e5adfa008f33989d4589a47ae1cd1a5e68 (diff)
downloadaerc-7647dfb8b47edbcb8080bd0327529383142ec888.tar.gz
compose: warn before sending without attachment
Prevent the embarrassing forgotten attachment scenario by warning the user before sending a message that may need an attachment but does not have one. Whether a message needs an attachment is determined by testing a configurable regex against the message body. Signed-off-by: Jason Cox <dev@jasoncarloscox.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/compose/send.go')
-rw-r--r--commands/compose/send.go39
1 files changed, 37 insertions, 2 deletions
diff --git a/commands/compose/send.go b/commands/compose/send.go
index 3786721b..ccfe7886 100644
--- a/commands/compose/send.go
+++ b/commands/compose/send.go
@@ -100,6 +100,40 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
rcpts: rcpts,
}
+ warn, err := composer.ShouldWarnAttachment()
+ if err != nil || warn {
+ msg := "You may have forgotten an attachment."
+ if err != nil {
+ logging.Warnf("failed to check for a forgotten attachment: %v", err)
+ msg = "Failed to check for a forgotten attachment."
+ }
+
+ prompt := widgets.NewPrompt(aerc.Config(),
+ msg+" Abort send? [Y/n] ",
+ func(text string) {
+ if text == "n" || text == "N" {
+ send(aerc, composer, ctx, header, tabName)
+ }
+ }, func(cmd string) ([]string, string) {
+ if cmd == "" {
+ return []string{"y", "n"}, ""
+ }
+
+ return nil, ""
+ },
+ )
+
+ aerc.PushPrompt(prompt)
+ } else {
+ send(aerc, composer, ctx, header, tabName)
+ }
+
+ return nil
+}
+
+func send(aerc *widgets.Aerc, composer *widgets.Composer, ctx sendCtx,
+ header *mail.Header, tabName string,
+) {
// we don't want to block the UI thread while we are sending
// so we do everything in a goroutine and hide the composer from the user
aerc.RemoveTab(composer)
@@ -109,6 +143,7 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
mode.NoQuit()
var copyBuf bytes.Buffer // for the Sent folder content if CopyTo is set
+ config := composer.Config()
failCh := make(chan error)
// writer
@@ -116,6 +151,7 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
defer logging.PanicHandler()
var sender io.WriteCloser
+ var err error
switch ctx.scheme {
case "smtp":
fallthrough
@@ -151,7 +187,7 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
// leave no-quit mode
defer mode.NoQuitDone()
- err = <-failCh
+ err := <-failCh
if err != nil {
aerc.PushError(strings.ReplaceAll(err.Error(), "\n", " "))
aerc.NewTab(composer, tabName)
@@ -176,7 +212,6 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
composer.SetSent()
composer.Close()
}()
- return nil
}
func listRecipients(h *mail.Header) ([]*mail.Address, error) {