-
Notifications
You must be signed in to change notification settings - Fork 1
/
email_show.go
55 lines (40 loc) · 1.09 KB
/
email_show.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
51
52
53
54
55
package emailsorter
import (
"context"
"errors"
"flag"
"fmt"
)
const showHelp = `print the subjects to the console`
func (cmd *ShowCommand) Name() string { return "show" }
func (cmd *ShowCommand) Args() string { return "" }
func (cmd *ShowCommand) ShortHelp() string { return showHelp }
func (cmd *ShowCommand) LongHelp() string { return showHelp }
func (cmd *ShowCommand) Hidden() bool { return false }
func (cmd *ShowCommand) Register(fs *flag.FlagSet) {
}
type ShowCommand struct {
Params *CmdParams
Imapconfig *ImapConfig
}
func (cmd *ShowCommand) 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 retrieved for the search criteria")
}
msgheaders, err := GetMessageHeaders(client, uids)
if err != nil {
return err
}
for _, msg := range msgheaders {
fmt.Printf("%s|%s|%s\n", msg.Sender, msg.SentDate.Format("2006-01-02"), msg.Subject)
}
return nil
}