From 5c29e49f9f422c8889ce2ed6b5b5a2914b55cace Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Sun, 17 Oct 2021 17:04:06 +0200 Subject: Support feed targets per feed --- pkg/config/url.go | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'pkg/config/url.go') 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, "/") +} -- cgit v1.2.3-54-g00ecf