aboutsummaryrefslogtreecommitdiff
path: root/internal/imap/url.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-14 23:37:35 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-14 23:37:35 +0200
commit2a8e0cf3750d3f789bcd756e39af04f00fe0e738 (patch)
tree384fcd7c9b34de17a6e516b9e2de9c88fa11a6f1 /internal/imap/url.go
parent65fe5cb5c88beabf6c045f20738af71c8d0e38ec (diff)
downloadfeed2imap-go-2a8e0cf3750d3f789bcd756e39af04f00fe0e738.tar.gz
feed2imap-go-2a8e0cf3750d3f789bcd756e39af04f00fe0e738.tar.bz2
feed2imap-go-2a8e0cf3750d3f789bcd756e39af04f00fe0e738.zip
Verbose variant of 'target' in config
Diffstat (limited to 'internal/imap/url.go')
-rw-r--r--internal/imap/url.go76
1 files changed, 0 insertions, 76 deletions
diff --git a/internal/imap/url.go b/internal/imap/url.go
deleted file mode 100644
index 90c34e6..0000000
--- a/internal/imap/url.go
+++ /dev/null
@@ -1,76 +0,0 @@
-package imap
-
-import (
- "net"
- "net/url"
-
- "github.com/Necoro/feed2imap-go/pkg/log"
-)
-
-// Our own convenience wrapper
-type URL struct {
- *url.URL
- // url.URL has no port field and splits it everytime from Host
- port *string
-}
-
-const (
- imapsPort = "993"
- imapPort = "143"
- imapsSchema = "imaps"
- imapSchema = "imap"
-)
-
-func (url *URL) Port() string {
- if url.port == nil {
- port := url.URL.Port()
- url.port = &port
- }
- return *url.port
-}
-
-func (url *URL) ForceTLS() bool {
- return url.Scheme == imapsSchema || url.Port() == imapsPort
-}
-
-func (url *URL) setDefaultScheme() {
- switch url.Scheme {
- case imapSchema, imapsSchema:
- return
- default:
- oldScheme := url.Scheme
- if url.Port() == imapsPort {
- url.Scheme = imapsSchema
- } else {
- url.Scheme = imapSchema
- }
-
- if oldScheme != "" {
- log.Warnf("Unknown scheme '%s', defaulting to '%s'", oldScheme, url.Scheme)
- }
- }
-}
-
-func (url *URL) setDefaultPort() {
- if url.Port() == "" {
- var port string
- if url.Scheme == imapsSchema {
- port = imapsPort
- } else {
- port = imapPort
- }
- url.port = &port
- url.Host = net.JoinHostPort(url.Host, port)
- }
-}
-
-func (url *URL) sanitizeUrl() {
- url.setDefaultScheme()
- url.setDefaultPort()
-}
-
-func NewUrl(url *url.URL) *URL {
- u := URL{URL: url}
- u.sanitizeUrl()
- return &u
-}