aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/routes.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2020-11-13 12:19:46 -0500
committerDrew DeVault <sir@cmpwn.com>2020-11-13 12:19:46 -0500
commit6ecb243620c6114cc5b25ec780aff9040ac49260 (patch)
tree96abdd2a9b12da3c4ba82224294ccef7f1123ccd /plugins/base/routes.go
parent1321cea241e0fa3f3ac7da38b7364b46e0858f11 (diff)
downloadalps-6ecb243620c6114cc5b25ec780aff9040ac49260.tar.gz
alps-6ecb243620c6114cc5b25ec780aff9040ac49260.zip
Fix duplicate drafts on repeated saves
Diffstat (limited to 'plugins/base/routes.go')
-rw-r--r--plugins/base/routes.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/plugins/base/routes.go b/plugins/base/routes.go
index 1f3b8b4..ea5bec5 100644
--- a/plugins/base/routes.go
+++ b/plugins/base/routes.go
@@ -7,6 +7,7 @@ import (
"io/ioutil"
"mime"
"net/http"
+ "net/textproto"
"net/url"
"strconv"
"strings"
@@ -507,7 +508,7 @@ func submitCompose(ctx *alps.Context, msg *OutgoingMessage, options *composeOpti
}
err = ctx.Session.DoIMAP(func(c *imapclient.Client) error {
- if _, _, err := appendMessage(c, msg, mailboxSent); err != nil {
+ if _, err := appendMessage(c, msg, mailboxSent); err != nil {
return err
}
if draft := options.Draft; draft != nil {
@@ -625,15 +626,29 @@ func handleCompose(ctx *alps.Context, msg *OutgoingMessage, options *composeOpti
uid uint32
)
err = ctx.Session.DoIMAP(func(c *imapclient.Client) error {
- drafts, uid, err = appendMessage(c, msg, mailboxDrafts)
+ drafts, err = appendMessage(c, msg, mailboxDrafts)
if err != nil {
return err
}
+
if draft := options.Draft; draft != nil {
if err := deleteMessage(c, draft.Mailbox, draft.Uid); err != nil {
return err
}
}
+
+ criteria := &imap.SearchCriteria{
+ Header: make(textproto.MIMEHeader),
+ }
+ criteria.Header.Add("Message-Id", msg.MessageID)
+ if uids, err := c.UidSearch(criteria); err != nil {
+ return err
+ } else {
+ if len(uids) != 1 {
+ panic(fmt.Errorf("Duplicate message ID"))
+ }
+ uid = uids[0]
+ }
return nil
})
if err != nil {