aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2019-12-03 11:54:43 +0100
committerSimon Ser <contact@emersion.fr>2019-12-03 11:54:43 +0100
commit33b8679f1c6b2055196536b3e3ae808195202377 (patch)
tree9717704abcc6d986e144e843a3f9652211b80d70
parented50cef3cf806c09762e75cf10fb022ce19d3a1b (diff)
downloadalps-33b8679f1c6b2055196536b3e3ae808195202377.tar.gz
alps-33b8679f1c6b2055196536b3e3ae808195202377.zip
Extract string conversion functions
-rw-r--r--imap.go4
-rw-r--r--server.go30
-rw-r--r--strconv.go35
3 files changed, 37 insertions, 32 deletions
diff --git a/imap.go b/imap.go
index 18220b5..78e2f88 100644
--- a/imap.go
+++ b/imap.go
@@ -138,7 +138,7 @@ func (msg *imapMessage) TextPartName() string {
}
type IMAPPartNode struct {
- Path []int
+ Path []int
MIMEType string
Children []IMAPPartNode
}
@@ -158,7 +158,7 @@ func imapPartTree(bs *imap.BodyStructure, path []int) *IMAPPartNode {
}
node := &IMAPPartNode{
- Path: path,
+ Path: path,
MIMEType: strings.ToLower(bs.MIMEType + "/" + bs.MIMESubType),
Children: make([]IMAPPartNode, len(bs.Parts)),
}
diff --git a/server.go b/server.go
index b252076..a66bbe1 100644
--- a/server.go
+++ b/server.go
@@ -4,8 +4,6 @@ import (
"fmt"
"net/http"
"net/url"
- "strconv"
- "strings"
"time"
imapclient "github.com/emersion/go-imap/client"
@@ -96,34 +94,6 @@ func handleLogin(ectx echo.Context) error {
return ctx.Render(http.StatusOK, "login.html", nil)
}
-func parseUid(s string) (uint32, error) {
- uid, err := strconv.ParseUint(s, 10, 32)
- if err != nil {
- return 0, err
- }
- if uid == 0 {
- return 0, fmt.Errorf("UID must be non-zero")
- }
- return uint32(uid), nil
-}
-
-func parsePartPath(s string) ([]int, error) {
- 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 New(imapURL string) *echo.Echo {
e := echo.New()
diff --git a/strconv.go b/strconv.go
new file mode 100644
index 0000000..2fb9d73
--- /dev/null
+++ b/strconv.go
@@ -0,0 +1,35 @@
+package koushin
+
+import (
+ "fmt"
+ "strconv"
+ "strings"
+)
+
+func parseUid(s string) (uint32, error) {
+ uid, err := strconv.ParseUint(s, 10, 32)
+ if err != nil {
+ return 0, err
+ }
+ if uid == 0 {
+ return 0, fmt.Errorf("UID must be non-zero")
+ }
+ return uint32(uid), nil
+}
+
+func parsePartPath(s string) ([]int, error) {
+ 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
+}