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 alpsbase
import (
"fmt"
"net/url"
"strconv"
"strings"
)
func parseUid(s string) (uint32, error) {
uid, err := strconv.ParseUint(s, 10, 32)
if err != nil {
return 0, fmt.Errorf("invalid UID: %v", err)
}
if uid == 0 {
return 0, fmt.Errorf("UID must be non-zero")
}
return uint32(uid), nil
}
func parseMboxAndUid(mboxString, uidString string) (string, uint32, error) {
mboxName, err := url.PathUnescape(mboxString)
if err != nil {
return "", 0, fmt.Errorf("invalid mailbox name: %v", err)
}
uid, err := parseUid(uidString)
return mboxName, uid, err
}
func parseUidList(values []string) ([]uint32, error) {
var uids []uint32
for _, v := range values {
uid, err := parseUid(v)
if err != nil {
return nil, err
}
uids = append(uids, uid)
}
return uids, nil
}
func parsePartPath(s string) ([]int, error) {
if s == "" {
return nil, nil
}
l := strings.Split(s, ".")
path := make([]int, len(l))
for i, s := range l {
var err error
path[i], err = strconv.Atoi(s)
if err != nil {
return nil, err
}
if path[i] <= 0 {
return nil, fmt.Errorf("part num must be strictly positive")
}
}
return path, nil
}
func parseAddressList(s string) []string {
l := strings.Split(s, ",")
for i, addr := range l {
l[i] = strings.TrimSpace(addr)
}
return l
}
|