aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go30
1 files changed, 21 insertions, 9 deletions
diff --git a/main.go b/main.go
index af75fb7..8e4b64f 100644
--- a/main.go
+++ b/main.go
@@ -5,6 +5,7 @@ import (
"fmt"
"net/url"
"os"
+ "time"
"github.com/Necoro/feed2imap-go/internal/feed"
"github.com/Necoro/feed2imap-go/internal/imap"
@@ -33,15 +34,6 @@ func run() error {
feed.Parse(feeds)
- for _, f := range feeds {
- mails, err := f.ToMails(cfg)
- if err != nil {
- return err
- }
- _ = mails
- break
- }
-
imapUrl, err := url.Parse(cfg.Target)
if err != nil {
return fmt.Errorf("parsing 'target': %w", err)
@@ -54,6 +46,26 @@ func run() error {
defer c.Disconnect()
+ for _, f := range feeds {
+ mails, err := f.ToMails(cfg)
+ if err != nil {
+ return err
+ }
+ if len(mails) == 0 {
+ continue
+ }
+ folder := c.NewFolder(f.Target)
+ if err = c.EnsureFolder(folder); err != nil {
+ return err
+ }
+ for _, mail := range mails {
+ if err = c.PutMessage(folder, mail, time.Now()); err != nil {
+ return err
+ } // TODO
+ }
+ log.Printf("Uploaded %d messages to '%s' @ %s", len(mails), f.Name, folder)
+ }
+
return nil
}