-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers.go
68 lines (63 loc) · 1.44 KB
/
handlers.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
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"encoding/base64"
"fmt"
"os"
"path/filepath"
"github.com/emersion/go-imap/client"
)
func (conf *Config) InitClient() (cc chan *client.Client, e error) {
salt, addr, a, e := LoadConfig(conf.r)
if e != nil {
return nil, e
}
conf.r.Close()
conf.addr = addr
conf.a = a
if tmp, e := base64.URLEncoding.DecodeString(salt); e != nil {
return nil, e
} else {
conf.salt = tmp
}
if !*printauth {
// do nothing
} else if m, ir, e := a.Start(); e != nil {
panic(e)
} else {
fmt.Fprintln(os.Stdout, conf.PrintAuth(m, ir))
}
client_chan := make(chan *client.Client, 1)
if c, e := client.DialTLS(addr, nil); e != nil {
return nil, e
} else if e := c.Authenticate(a); e != nil {
return nil, e
} else {
// for idling
// defer c.Logout()
client_chan <- c
}
return client_chan, nil
}
func InitHandler(cc chan *client.Client, conf *Config, unsorted_index_chan chan *IndexData) error {
for k, mailbox := range conf.folders {
if c := <-cc; c == nil {
return fmt.Errorf("client is nil")
} else if _, e := c.Select(mailbox, false); e != nil {
return e
} else {
id := new(IndexData)
id.filename = filepath.Join(*indexdir, GenerateMailboxID(mailbox, conf.addr, conf.salt))
id.cc = cc
id.k = k
id.addr = conf.addr
id.mailboxname = mailbox
if e := id.ReadIndexFile(); e != nil && !os.IsNotExist(e) {
return e
} else {
unsorted_index_chan <- id
cc <- c
}
}
}
return nil
}