-
Notifications
You must be signed in to change notification settings - Fork 1
/
email_copy.go
50 lines (37 loc) · 1023 Bytes
/
email_copy.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
46
47
48
49
50
package emailsorter
import (
"context"
"errors"
"flag"
)
const copyHelp = `copy emails to the destfolder`
func (cmd *CopyCommand) Name() string { return "copy" }
func (cmd *CopyCommand) Args() string { return "" }
func (cmd *CopyCommand) ShortHelp() string { return copyHelp }
func (cmd *CopyCommand) LongHelp() string { return copyHelp }
func (cmd *CopyCommand) Hidden() bool { return false }
func (cmd *CopyCommand) Register(fs *flag.FlagSet) {
}
type CopyCommand struct {
Params *CmdParams
Imapconfig *ImapConfig
}
func (cmd *CopyCommand) Run(ctx context.Context, args []string) error {
client, err := NewImapClient(*cmd.Imapconfig)
if err != nil {
return err
}
if len(cmd.Params.DestFolder) == 0 {
return errors.New("destfolder should be provided for copy")
}
uids, err := GetEmailUIDs(client, *cmd.Params)
if err != nil {
return err
}
err = copyTo(client, uids, cmd.Params.DestFolder)
if err != nil {
return err
}
err = deleteEmail(client, uids)
return err
}