aboutsummaryrefslogtreecommitdiff
path: root/pkg/config/url.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2021-10-17 17:04:06 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2021-10-18 18:36:04 +0200
commit5c29e49f9f422c8889ce2ed6b5b5a2914b55cace (patch)
tree20b2d8725fa0bc763d32b6f59d796143a453548e /pkg/config/url.go
parent44ff3d08a0e1f3b49e07795a9fdb0ad3af4c7540 (diff)
downloadfeed2imap-go-5c29e49f9f422c8889ce2ed6b5b5a2914b55cace.tar.gz
feed2imap-go-5c29e49f9f422c8889ce2ed6b5b5a2914b55cace.tar.bz2
feed2imap-go-5c29e49f9f422c8889ce2ed6b5b5a2914b55cace.zip
Support feed targets per feed
Diffstat (limited to 'pkg/config/url.go')
-rw-r--r--pkg/config/url.go46
1 files changed, 41 insertions, 5 deletions
diff --git a/pkg/config/url.go b/pkg/config/url.go
index 39cce16..7e91411 100644
--- a/pkg/config/url.go
+++ b/pkg/config/url.go
@@ -4,6 +4,7 @@ import (
"fmt"
"net"
"net/url"
+ "strings"
"gopkg.in/yaml.v3"
)
@@ -63,7 +64,7 @@ func (u *Url) UnmarshalYAML(value *yaml.Node) (err error) {
return nil
}
-func (u *Url) String() string {
+func (u Url) String() string {
scheme := u.Scheme + "://"
var pwd string
@@ -86,12 +87,28 @@ func (u *Url) HostPort() string {
}
const (
- imapsPort = "993"
- imapPort = "143"
- imapsSchema = "imaps"
- imapSchema = "imap"
+ imapsPort = "993"
+ imapPort = "143"
+ imapsSchema = "imaps"
+ imapsSchemaFull = imapsSchema + "://"
+ imapSchema = "imap"
+ imapSchemaFull = imapSchema + "://"
+ maildirSchemaFull = "maildir://"
)
+func isRecognizedUrl(s string) bool {
+ return isImapUrl(s) || isMaildirUrl(s)
+
+}
+
+func isImapUrl(s string) bool {
+ return strings.HasPrefix(s, imapsSchemaFull) || strings.HasPrefix(s, imapSchemaFull)
+}
+
+func isMaildirUrl(s string) bool {
+ return strings.HasPrefix(s, maildirSchemaFull)
+}
+
func (u *Url) ForceTLS() bool {
return u.Scheme == imapsSchema || u.Port == imapsPort
}
@@ -132,3 +149,22 @@ func (u *Url) validate() (errors []string) {
return
}
+
+func (u Url) BaseUrl() Url {
+ // 'u' is not a pointer and thus a copy, modification is fine
+ u.Root = ""
+ return u
+}
+
+func (u *Url) CommonBaseUrl(other Url) bool {
+ other.Root = ""
+ return other == u.BaseUrl()
+}
+
+func (u *Url) RootPath() []string {
+ path := u.Root
+ if path[0] == '/' {
+ path = path[1:]
+ }
+ return strings.Split(path, "/")
+}