aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/compose.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 /widgets/compose.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 'widgets/compose.go')
-rw-r--r--widgets/compose.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/widgets/compose.go b/widgets/compose.go
index dc0c21aa..6e34365a 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -776,6 +776,26 @@ func (c *Composer) WriteMessage(header *mail.Header, writer io.Writer) error {
}
}
+func (c *Composer) ShouldWarnAttachment() (bool, error) {
+ regex := c.config.Compose.NoAttachmentWarning
+
+ if regex == nil || len(c.attachments) > 0 {
+ return false, nil
+ }
+
+ err := c.reloadEmail()
+ if err != nil {
+ return false, errors.Wrap(err, "reloadEmail")
+ }
+
+ body, err := io.ReadAll(c.email)
+ if err != nil {
+ return false, errors.Wrap(err, "io.ReadAll")
+ }
+
+ return regex.Match(body), nil
+}
+
func writeMsgImpl(c *Composer, header *mail.Header, writer io.Writer) error {
if len(c.attachments) == 0 && len(c.textParts) == 0 {
// no attachments