Browse Source

plugins/base: delete previous draft

master
Simon Ser 4 years ago
parent
commit
3384c39a17
No known key found for this signature in database GPG Key ID: FDE7BE0E88F5E48
2 changed files with 34 additions and 5 deletions
  1. +16
    -0
      plugins/base/imap.go
  2. +18
    -5
      plugins/base/routes.go

+ 16
- 0
plugins/base/imap.go View File

@@ -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)
}

+ 18
- 5
plugins/base/routes.go View File

@@ -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)
}
}



Loading…
Cancel
Save