aboutsummaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2019-12-02 17:31:34 +0100
committerSimon Ser <contact@emersion.fr>2019-12-02 17:31:34 +0100
commit640bd497317891eae8c34255c077956183d526ae (patch)
tree14993f7704d5b1e8176691cda2533f90b70bc1ca /server.go
parent8b84d81f9b56c02a53d1224eb20b25ba93609aa1 (diff)
downloadalps-640bd497317891eae8c34255c077956183d526ae.tar.gz
alps-640bd497317891eae8c34255c077956183d526ae.zip
List mailboxes
Diffstat (limited to 'server.go')
-rw-r--r--server.go28
1 files changed, 24 insertions, 4 deletions
diff --git a/server.go b/server.go
index cd03c5d..14b9892 100644
--- a/server.go
+++ b/server.go
@@ -7,6 +7,7 @@ import (
"time"
"github.com/labstack/echo/v4"
+ "github.com/emersion/go-imap"
imapclient "github.com/emersion/go-imap/client"
)
@@ -132,7 +133,12 @@ func New(imapURL string) *echo.Echo {
cookie, err := ctx.Cookie(cookieName)
if err == http.ErrNoCookie {
- return next(ctx)
+ // Require auth for all pages except /login
+ if ctx.Path() == "/login" {
+ return next(ctx)
+ } else {
+ return ctx.Redirect(http.StatusFound, "/login")
+ }
} else if err != nil {
return err
}
@@ -156,11 +162,25 @@ func New(imapURL string) *echo.Echo {
e.GET("/", func(ectx echo.Context) error {
ctx := ectx.(*context)
- if ctx.conn == nil {
- return ctx.Redirect(http.StatusFound, "/login")
+
+ ch := make(chan *imap.MailboxInfo, 10)
+ done := make(chan error, 1)
+ go func () {
+ done <- ctx.conn.List("", "*", ch)
+ }()
+
+ var mailboxes []*imap.MailboxInfo
+ for mbox := range ch {
+ mailboxes = append(mailboxes, mbox)
+ }
+
+ if err := <-done; err != nil {
+ return err
}
- return ctx.Render(http.StatusOK, "index.html", nil)
+ return ctx.Render(http.StatusOK, "index.html", map[string]interface{}{
+ "Mailboxes": mailboxes,
+ })
})
e.GET("/login", handleLogin)