aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-21 22:20:20 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-21 22:20:20 +0200
commit89f46e31998dd62a52d7dd07b16f1d81d9597e3e (patch)
tree7bb463d986804601c04c01f2855eb15293a1a7ee /main.go
parent1845873048e1f2c3499e75a4e5cbbe8d1247170d (diff)
downloadfeed2imap-go-89f46e31998dd62a52d7dd07b16f1d81d9597e3e.tar.gz
feed2imap-go-89f46e31998dd62a52d7dd07b16f1d81d9597e3e.tar.bz2
feed2imap-go-89f46e31998dd62a52d7dd07b16f1d81d9597e3e.zip
Upload mails to imap
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
}