Skip to content
Snippets Groups Projects
Commit a9d33696 authored by ale's avatar ale
Browse files

Add a move-to-trash option for GMail compat

parent 07bc4fe8
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@ var (
folder = flag.String("folder", "INBOX", "remote IMAP folder")
verbose = flag.Bool("verbose", false, "print additional debug messages")
batchSize = flag.Int("batch-size", 100, "deletion batch size")
moveToTrash = flag.Bool("move-to-gmail-trash", false, "move messages to Trash folder before deleting them (GMail workaround)")
)
func vlog(fmt string, args ...interface{}) {
......@@ -106,6 +107,28 @@ func uidBatch(c *client.Client, uids []uint32, f func([]uint32) error) error {
return nil
}
func actuallyDelete(c *client.Client, uids *imap.SeqSet) error {
// Do the GMail move-to-Trash dance.
if *moveToTrash {
if err := c.UidStore(
uids,
"+X-GM-LABELS",
[]interface{}{"\\Trash"},
nil,
); err != nil {
return err
}
}
// Just set the \\Deleted flag as one normally would.
return c.UidStore(
uids,
imap.FormatFlagsOp(imap.AddFlags, true),
[]interface{}{imap.DeletedFlag},
nil,
)
}
func main() {
log.SetFlags(0)
flag.Parse()
......@@ -146,12 +169,7 @@ func main() {
}
vlog("deleting %d messages...", len(uids))
return c.UidStore(
set,
imap.FormatFlagsOp(imap.AddFlags, true),
[]interface{}{imap.DeletedFlag},
nil,
)
return actuallyDelete(c, set)
})
if err != nil {
log.Fatalf("delete error: %v", err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment