go fmt
This commit is contained in:
parent
61f2f3e139
commit
4cbe2fde9d
3 changed files with 14 additions and 14 deletions
|
@ -23,7 +23,7 @@ var ErrSessionExpired = errors.New("session expired")
|
||||||
// TODO: expiration timer
|
// TODO: expiration timer
|
||||||
type ConnPool struct {
|
type ConnPool struct {
|
||||||
locker sync.Mutex
|
locker sync.Mutex
|
||||||
conns map[string]*imapclient.Client
|
conns map[string]*imapclient.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConnPool() *ConnPool {
|
func NewConnPool() *ConnPool {
|
||||||
|
|
8
imap.go
8
imap.go
|
@ -9,9 +9,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/emersion/go-imap"
|
"github.com/emersion/go-imap"
|
||||||
|
imapclient "github.com/emersion/go-imap/client"
|
||||||
"github.com/emersion/go-message"
|
"github.com/emersion/go-message"
|
||||||
"github.com/emersion/go-message/textproto"
|
"github.com/emersion/go-message/textproto"
|
||||||
imapclient "github.com/emersion/go-imap/client"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) connectIMAP() (*imapclient.Client, error) {
|
func (s *Server) connectIMAP() (*imapclient.Client, error) {
|
||||||
|
@ -41,7 +41,7 @@ func (s *Server) connectIMAP() (*imapclient.Client, error) {
|
||||||
func listMailboxes(conn *imapclient.Client) ([]*imap.MailboxInfo, error) {
|
func listMailboxes(conn *imapclient.Client) ([]*imap.MailboxInfo, error) {
|
||||||
ch := make(chan *imap.MailboxInfo, 10)
|
ch := make(chan *imap.MailboxInfo, 10)
|
||||||
done := make(chan error, 1)
|
done := make(chan error, 1)
|
||||||
go func () {
|
go func() {
|
||||||
done <- conn.List("", "*", ch)
|
done <- conn.List("", "*", ch)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -171,8 +171,8 @@ func listMessages(conn *imapclient.Client, mboxName string) ([]imapMessage, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reverse list of messages
|
// Reverse list of messages
|
||||||
for i := len(msgs)/2-1; i >= 0; i-- {
|
for i := len(msgs)/2 - 1; i >= 0; i-- {
|
||||||
opp := len(msgs)-1-i
|
opp := len(msgs) - 1 - i
|
||||||
msgs[i], msgs[opp] = msgs[opp], msgs[i]
|
msgs[i], msgs[opp] = msgs[opp], msgs[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
server.go
18
server.go
|
@ -8,16 +8,16 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
imapclient "github.com/emersion/go-imap/client"
|
imapclient "github.com/emersion/go-imap/client"
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
const cookieName = "koushin_session"
|
const cookieName = "koushin_session"
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
imap struct {
|
imap struct {
|
||||||
host string
|
host string
|
||||||
tls bool
|
tls bool
|
||||||
insecure bool
|
insecure bool
|
||||||
|
|
||||||
pool *ConnPool
|
pool *ConnPool
|
||||||
|
@ -51,15 +51,15 @@ func NewServer(imapURL string) (*Server, error) {
|
||||||
type context struct {
|
type context struct {
|
||||||
echo.Context
|
echo.Context
|
||||||
server *Server
|
server *Server
|
||||||
conn *imapclient.Client
|
conn *imapclient.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
var aLongTimeAgo = time.Unix(233431200, 0)
|
var aLongTimeAgo = time.Unix(233431200, 0)
|
||||||
|
|
||||||
func (c *context) setToken(token string) {
|
func (c *context) setToken(token string) {
|
||||||
cookie := http.Cookie{
|
cookie := http.Cookie{
|
||||||
Name: cookieName,
|
Name: cookieName,
|
||||||
Value: token,
|
Value: token,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
// TODO: domain, secure
|
// TODO: domain, secure
|
||||||
}
|
}
|
||||||
|
@ -179,9 +179,9 @@ func New(imapURL string) *echo.Echo {
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.Render(http.StatusOK, "mailbox.html", map[string]interface{}{
|
return ctx.Render(http.StatusOK, "mailbox.html", map[string]interface{}{
|
||||||
"Mailbox": ctx.conn.Mailbox(),
|
"Mailbox": ctx.conn.Mailbox(),
|
||||||
"Mailboxes": mailboxes,
|
"Mailboxes": mailboxes,
|
||||||
"Messages": msgs,
|
"Messages": msgs,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ func New(imapURL string) *echo.Echo {
|
||||||
return ctx.Render(http.StatusOK, "message.html", map[string]interface{}{
|
return ctx.Render(http.StatusOK, "message.html", map[string]interface{}{
|
||||||
"Mailbox": ctx.conn.Mailbox(),
|
"Mailbox": ctx.conn.Mailbox(),
|
||||||
"Message": msg,
|
"Message": msg,
|
||||||
"Body": body,
|
"Body": body,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue