aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-01-24 20:27:05 +0100
committerSimon Ser <contact@emersion.fr>2020-01-24 20:27:05 +0100
commit3384c39a1773c90eb4575d4017fcd92b9e9ab6f9 (patch)
treebf005a176449d6a5337ff2fa0e78111dadbd4188 /plugins
parentd31c56ec98cd3f4fc5afbdd8f840538f3ee59429 (diff)
downloadalps-3384c39a1773c90eb4575d4017fcd92b9e9ab6f9.tar.gz
alps-3384c39a1773c90eb4575d4017fcd92b9e9ab6f9.zip
plugins/base: delete previous draft
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/base/imap.go16
-rw-r--r--plugins/base/routes.go23
2 files changed, 34 insertions, 5 deletions
diff --git a/plugins/base/imap.go b/plugins/base/imap.go
index 980a8aa..280a06b 100755
--- a/plugins/base/imap.go
+++ b/plugins/base/imap.go
@@ -436,3 +436,19 @@ func appendMessage(c *imapclient.Client, msg *OutgoingMessage, mboxType mailboxT
return true, nil
}
+
+func deleteMessage(c *imapclient.Client, mboxName string, uid uint32) error {
+ if err := ensureMailboxSelected(c, mboxName); err != nil {
+ return err
+ }
+
+ seqSet := new(imap.SeqSet)
+ seqSet.AddNum(uid)
+ item := imap.FormatFlagsOp(imap.AddFlags, true)
+ flags := []interface{}{imap.DeletedFlag}
+ if err := c.UidStore(seqSet, item, flags, nil); err != nil {
+ return err
+ }
+
+ return c.Expunge(nil)
+}
diff --git a/plugins/base/routes.go b/plugins/base/routes.go
index 49f7674..bf0bc5a 100644
--- a/plugins/base/routes.go
+++ b/plugins/base/routes.go
@@ -288,7 +288,7 @@ type messagePath struct {
// Send message, append it to the Sent mailbox, mark the original message as
// answered
-func submitCompose(ctx *koushin.Context, msg *OutgoingMessage, inReplyTo *messagePath) error {
+func submitCompose(ctx *koushin.Context, msg *OutgoingMessage, draft *messagePath, inReplyTo *messagePath) error {
err := ctx.Session.DoSMTP(func(c *smtp.Client) error {
return sendMessage(c, msg)
})
@@ -309,8 +309,15 @@ func submitCompose(ctx *koushin.Context, msg *OutgoingMessage, inReplyTo *messag
}
err = ctx.Session.DoIMAP(func(c *imapclient.Client) error {
- _, err := appendMessage(c, msg, mailboxSent)
- return err
+ if _, err := appendMessage(c, msg, mailboxSent); err != nil {
+ return err
+ }
+ if draft != nil {
+ if err := deleteMessage(c, draft.Mailbox, draft.Uid); err != nil {
+ return err
+ }
+ }
+ return nil
})
if err != nil {
return fmt.Errorf("failed to save message to Sent mailbox: %v", err)
@@ -319,7 +326,7 @@ func submitCompose(ctx *koushin.Context, msg *OutgoingMessage, inReplyTo *messag
return ctx.Redirect(http.StatusFound, "/mailbox/INBOX")
}
-func handleCompose(ctx *koushin.Context, msg *OutgoingMessage, source *messagePath, inReplyTo *messagePath) error {
+func handleCompose(ctx *koushin.Context, msg *OutgoingMessage, draft *messagePath, inReplyTo *messagePath) error {
if msg.From == "" && strings.ContainsRune(ctx.Session.Username(), '@') {
msg.From = ctx.Session.Username()
}
@@ -352,13 +359,19 @@ func handleCompose(ctx *koushin.Context, msg *OutgoingMessage, source *messagePa
if !copied {
return fmt.Errorf("no Draft mailbox found")
}
+ if draft != nil {
+ if err := deleteMessage(c, draft.Mailbox, draft.Uid); err != nil {
+ return err
+ }
+ }
return nil
})
if err != nil {
return fmt.Errorf("failed to save message to Draft mailbox: %v", err)
}
+ return ctx.Redirect(http.StatusFound, "/mailbox/INBOX")
} else {
- return submitCompose(ctx, msg, inReplyTo)
+ return submitCompose(ctx, msg, draft, inReplyTo)
}
}