diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/feed/feed.go | 12 | ||||
-rw-r--r-- | internal/feed/mail.go | 5 | ||||
-rw-r--r-- | internal/feed/state.go | 13 | ||||
-rw-r--r-- | internal/imap/connection.go | 1 | ||||
-rw-r--r-- | internal/imap/folder.go | 10 | ||||
-rw-r--r-- | internal/imap/mailboxes.go | 8 | ||||
-rw-r--r-- | internal/msg/msg.go | 10 |
7 files changed, 44 insertions, 15 deletions
diff --git a/internal/feed/feed.go b/internal/feed/feed.go index 4e84443..de28ef8 100644 --- a/internal/feed/feed.go +++ b/internal/feed/feed.go @@ -1,6 +1,7 @@ package feed import ( + "fmt" "strings" "time" @@ -58,3 +59,14 @@ func (feed *Feed) MarkSuccess() { feed.cached.Commit() } } + +func Create(parsedFeed *config.Feed, global config.GlobalOptions) (*Feed, error) { + var itemFilter *filter.Filter + var err error + if parsedFeed.ItemFilter != "" { + if itemFilter, err = filter.New(parsedFeed.ItemFilter); err != nil { + return nil, fmt.Errorf("Feed %s: Parsing item-filter: %w", parsedFeed.Name, err) + } + } + return &Feed{Feed: parsedFeed, Global: global, filter: itemFilter}, nil +} diff --git a/internal/feed/mail.go b/internal/feed/mail.go index 3010bfb..b201d61 100644 --- a/internal/feed/mail.go +++ b/internal/feed/mail.go @@ -328,6 +328,11 @@ func (item *item) buildBody() { cid := "cid:" + cidNr(idx) selection.SetAttr(attr, cid) } + + // srcset overrides src and would reload all the images + // we do not want to include all images in the srcset either, so just strip it + selection.RemoveAttr("srcset") + doneAnything = true }) diff --git a/internal/feed/state.go b/internal/feed/state.go index 41d8751..364616f 100644 --- a/internal/feed/state.go +++ b/internal/feed/state.go @@ -2,12 +2,10 @@ package feed import ( "encoding/json" - "fmt" "sync" "github.com/mmcdole/gofeed" - "github.com/Necoro/feed2imap-go/internal/feed/filter" "github.com/Necoro/feed2imap-go/pkg/config" "github.com/Necoro/feed2imap-go/pkg/log" ) @@ -163,14 +161,11 @@ func NewState(cfg *config.Config) (*State, error) { } for name, parsedFeed := range cfg.Feeds { - var itemFilter *filter.Filter - var err error - if parsedFeed.ItemFilter != "" { - if itemFilter, err = filter.New(parsedFeed.ItemFilter); err != nil { - return nil, fmt.Errorf("Feed %s: Parsing item-filter: %w", parsedFeed.Name, err) - } + feed, err := Create(parsedFeed, cfg.GlobalOptions) + if err != nil { + return nil, err } - state.feeds[name] = &Feed{Feed: parsedFeed, Global: cfg.GlobalOptions, filter: itemFilter} + state.feeds[name] = feed } return &state, nil diff --git a/internal/imap/connection.go b/internal/imap/connection.go index e8d4da2..213171e 100644 --- a/internal/imap/connection.go +++ b/internal/imap/connection.go @@ -225,6 +225,7 @@ func (conn *connection) replace(folder Folder, header, value, newContent string, func (conn *connection) searchHeader(header, value string) ([]uint32, error) { criteria := imap.NewSearchCriteria() criteria.Header.Set(header, value) + criteria.WithoutFlags = []string{imap.DeletedFlag} ids, err := conn.search(criteria) if err != nil { return nil, fmt.Errorf("searching for header %q=%q: %w", header, value, err) diff --git a/internal/imap/folder.go b/internal/imap/folder.go index e845862..6353bb3 100644 --- a/internal/imap/folder.go +++ b/internal/imap/folder.go @@ -21,9 +21,17 @@ func (f Folder) Append(other Folder) Folder { } } +func buildFolderName(path []string, delimiter string) (name string) { + name = strings.Join(path, delimiter) + if delimiter != "" { + name = strings.Trim(name, delimiter[0:1]) + } + return +} + func (cl *Client) folderName(path []string) Folder { return Folder{ - strings.Join(path, cl.delimiter), + buildFolderName(path, cl.delimiter), cl.delimiter, } } diff --git a/internal/imap/mailboxes.go b/internal/imap/mailboxes.go index f1dc6c6..25bf087 100644 --- a/internal/imap/mailboxes.go +++ b/internal/imap/mailboxes.go @@ -26,6 +26,14 @@ func (mbs *mailboxes) unlocking(elem Folder) { func (mbs *mailboxes) locking(elem Folder) bool { mbs.mu.Lock() + + // check again, if the folder has been created in the meantime + _, ok := mbs.mb[elem.str] + if ok { + mbs.mu.Unlock() + return true + } + ch, ok := mbs.changeLocks[elem.str] if !ok { ch = make(chan struct{}) diff --git a/internal/msg/msg.go b/internal/msg/msg.go index c96bc6c..54c83ac 100644 --- a/internal/msg/msg.go +++ b/internal/msg/msg.go @@ -27,11 +27,11 @@ type Message struct { func (m Messages) Upload(client *imap.Client, folder imap.Folder, reupload bool) error { toStore := make([]string, 0, len(m)) - msgs := make(chan Message, 5) + updateMsgs := make(chan Message, 5) ok := make(chan bool) - go func() { + go func() { /* update goroutine */ errHappened := false - for msg := range msgs { + for msg := range updateMsgs { if err := client.Replace(folder, IdHeader, msg.ID, msg.Content, reupload); err != nil { log.Errorf("Error while updating mail with id '%s' in folder '%s'. Skipping.: %s", msg.ID, folder, err) @@ -46,11 +46,11 @@ func (m Messages) Upload(client *imap.Client, folder imap.Folder, reupload bool) if !msg.IsUpdate { toStore = append(toStore, msg.Content) } else { - msgs <- msg + updateMsgs <- msg } } - close(msgs) + close(updateMsgs) putErr := client.PutMessages(folder, toStore) updOk := <-ok |