-
Notifications
You must be signed in to change notification settings - Fork 1
/
email_delete.go
45 lines (32 loc) · 976 Bytes
/
email_delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package emailsorter
import (
"context"
"errors"
"flag"
)
const deleteHelp = `delete emails in the source folder meeting search criteria`
func (cmd *DeleteCommand) Name() string { return "delete" }
func (cmd *DeleteCommand) Args() string { return "" }
func (cmd *DeleteCommand) ShortHelp() string { return deleteHelp }
func (cmd *DeleteCommand) LongHelp() string { return deleteHelp }
func (cmd *DeleteCommand) Hidden() bool { return false }
func (cmd *DeleteCommand) Register(fs *flag.FlagSet) {}
type DeleteCommand struct {
Params *CmdParams
Imapconfig *ImapConfig
}
func (cmd *DeleteCommand) Run(ctx context.Context, args []string) error {
client, err := NewImapClient(*cmd.Imapconfig)
if err != nil {
return err
}
uids, err := GetEmailUIDs(client, *cmd.Params)
if err != nil {
return err
}
if len(uids) == 0 {
return errors.New("no emails found with the search criteria")
}
err = deleteEmail(client, uids)
return err
}