/
config.go
69 lines (66 loc) · 1.66 KB
/
config.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
69
package main
import (
"bufio"
"os"
"strings"
)
var GlobConf map[string]string
var Mailboxes map[string](map[string]string)
var SMTPServ map[string](map[string]string)
var IMAPServ map[string](map[string]string)
func readConfig() {
GlobConf = make(map[string]string)
Mailboxes = make(map[string](map[string]string))
SMTPServ = make(map[string](map[string]string))
IMAPServ = make(map[string](map[string]string))
f, err := os.Open("CountablyMany.ini")
if err != nil {
println("error reading conf file")
os.Exit(1)
}
sc := bufio.NewReader(f)
mode := 0
acc := ""
for true {
line, err := sc.ReadString('\n')
line = strings.Trim(line, "\r\n ")
if len(line)>=1 && line[0]=='#' {
continue
}
if strings.Index(line, "[all]") == 0 {
mode = 1
} else if strings.Index(line, "[") == 0 && strings.Index(line, ".imap]") >= 0 {
mode = 2
} else if strings.Index(line, "[") == 0 && strings.Index(line, ".smtp]") >= 0 {
mode = 3
}
if mode != 1 && strings.Index(line, "[") == 0 {
acc = line[1 : len(line)-6]
if mode == 2 {
IMAPServ[acc] = make(map[string]string)
} else if mode == 3 {
SMTPServ[acc] = make(map[string]string)
}
}
if strings.Index(line, "[") != 0 {
key, val, _ := strings.Cut(line, "=")
if mode == 1 {
GlobConf[key] = val
} else if mode == 2 {
IMAPServ[acc][key] = val
if key == "Mailboxes" {
Mailboxes[acc] = make(map[string]string)
for _, mbxdef := range strings.Split(val, " ") {
mbxdefsplt := strings.Split(mbxdef, "=")
Mailboxes[acc][mbxdefsplt[0]] = mbxdefsplt[1]
}
}
} else if mode == 3 {
SMTPServ[acc][key] = val
}
if err != nil {
break
}
}
}
}