This commit is contained in:
Simon Ser 2021-07-05 11:19:07 +02:00
parent 7adc90e229
commit 556ce5b2c8
5 changed files with 27 additions and 27 deletions

View File

@ -12,10 +12,10 @@ import (
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
"github.com/emersion/go-imap" "github.com/emersion/go-imap"
imapspecialuse "github.com/emersion/go-imap-specialuse"
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"
imapspecialuse "github.com/emersion/go-imap-specialuse"
) )
type MailboxInfo struct { type MailboxInfo struct {

View File

@ -14,13 +14,13 @@ import (
"git.sr.ht/~migadu/alps" "git.sr.ht/~migadu/alps"
"github.com/emersion/go-imap" "github.com/emersion/go-imap"
imapmove "github.com/emersion/go-imap-move"
imapclient "github.com/emersion/go-imap/client"
"github.com/emersion/go-message" "github.com/emersion/go-message"
"github.com/emersion/go-message/mail" "github.com/emersion/go-message/mail"
"github.com/emersion/go-smtp" "github.com/emersion/go-smtp"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"jaytaylor.com/html2text" "jaytaylor.com/html2text"
imapclient "github.com/emersion/go-imap/client"
imapmove "github.com/emersion/go-imap-move"
) )
func registerRoutes(p *alps.GoPlugin) { func registerRoutes(p *alps.GoPlugin) {
@ -85,9 +85,9 @@ type IMAPBaseRenderData struct {
type MailboxRenderData struct { type MailboxRenderData struct {
IMAPBaseRenderData IMAPBaseRenderData
Messages []IMAPMessage Messages []IMAPMessage
PrevPage, NextPage int PrevPage, NextPage int
Query string Query string
} }
type MailboxDetails struct { type MailboxDetails struct {
@ -111,7 +111,7 @@ type CategorizedMailboxes struct {
func (cc *CategorizedMailboxes) Append(mi MailboxInfo, status *MailboxStatus) { func (cc *CategorizedMailboxes) Append(mi MailboxInfo, status *MailboxStatus) {
name := mi.Name name := mi.Name
details := &MailboxDetails{ details := &MailboxDetails{
Info: &mi, Info: &mi,
Status: status, Status: status,
} }
if name == "INBOX" { if name == "INBOX" {
@ -245,7 +245,7 @@ func handleGetMailbox(ctx *alps.Context) error {
total int total int
) )
err = ctx.Session.DoIMAP(func(c *imapclient.Client) error { err = ctx.Session.DoIMAP(func(c *imapclient.Client) error {
var err error var err error
if query != "" { if query != "" {
msgs, total, err = searchMessages(c, mbox.Name, query, page, messagesPerPage) msgs, total, err = searchMessages(c, mbox.Name, query, page, messagesPerPage)
} else { } else {
@ -278,11 +278,11 @@ func handleGetMailbox(ctx *alps.Context) error {
} }
return ctx.Render(http.StatusOK, "mailbox.html", &MailboxRenderData{ return ctx.Render(http.StatusOK, "mailbox.html", &MailboxRenderData{
IMAPBaseRenderData: *ibase, IMAPBaseRenderData: *ibase,
Messages: msgs, Messages: msgs,
PrevPage: prevPage, PrevPage: prevPage,
NextPage: nextPage, NextPage: nextPage,
Query: query, Query: query,
}) })
} }
@ -303,7 +303,7 @@ func handleNewMailbox(ctx *alps.Context) error {
if name == "" { if name == "" {
return ctx.Render(http.StatusOK, "new-mailbox.html", &NewMailboxRenderData{ return ctx.Render(http.StatusOK, "new-mailbox.html", &NewMailboxRenderData{
IMAPBaseRenderData: *ibase, IMAPBaseRenderData: *ibase,
Error: "Name is required", Error: "Name is required",
}) })
} }
@ -314,7 +314,7 @@ func handleNewMailbox(ctx *alps.Context) error {
if err != nil { if err != nil {
return ctx.Render(http.StatusOK, "new-mailbox.html", &NewMailboxRenderData{ return ctx.Render(http.StatusOK, "new-mailbox.html", &NewMailboxRenderData{
IMAPBaseRenderData: *ibase, IMAPBaseRenderData: *ibase,
Error: err.Error(), Error: err.Error(),
}) })
} }
@ -323,7 +323,7 @@ func handleNewMailbox(ctx *alps.Context) error {
return ctx.Render(http.StatusOK, "new-mailbox.html", &NewMailboxRenderData{ return ctx.Render(http.StatusOK, "new-mailbox.html", &NewMailboxRenderData{
IMAPBaseRenderData: *ibase, IMAPBaseRenderData: *ibase,
Error: "", Error: "",
}) })
} }
@ -520,7 +520,7 @@ type composeOptions struct {
// Send message, append it to the Sent mailbox, mark the original message as // Send message, append it to the Sent mailbox, mark the original message as
// answered // answered
func submitCompose(ctx *alps.Context, msg *OutgoingMessage, options *composeOptions) error { func submitCompose(ctx *alps.Context, msg *OutgoingMessage, options *composeOptions) error {
err := ctx.Session.DoSMTP(func (c *smtp.Client) error { err := ctx.Session.DoSMTP(func(c *smtp.Client) error {
return sendMessage(c, msg) return sendMessage(c, msg)
}) })
if err != nil { if err != nil {
@ -571,7 +571,7 @@ func handleCompose(ctx *alps.Context, msg *OutgoingMessage, options *composeOpti
} }
if settings.From != "" { if settings.From != "" {
addr := mail.Address{ addr := mail.Address{
Name: settings.From, Name: settings.From,
Address: ctx.Session.Username(), Address: ctx.Session.Username(),
} }
msg.From = addr.String() msg.From = addr.String()

View File

@ -87,7 +87,7 @@ func splitSearchTokens(buf []byte, eof bool) (int, []byte, error) {
terminator int terminator int
quoted bool quoted bool
) )
if colon + 1 < len(buf) && buf[colon+1] == byte('"') { if colon+1 < len(buf) && buf[colon+1] == byte('"') {
terminator = bytes.IndexByte(buf[colon+2:], byte('"')) terminator = bytes.IndexByte(buf[colon+2:], byte('"'))
terminator += colon + 3 terminator += colon + 3
quoted = true quoted = true

View File

@ -396,9 +396,9 @@ func New(e *echo.Echo, options *Options) (*Server, error) {
} }
rdata := ErrorRenderData{ rdata := ErrorRenderData{
BaseRenderData: *NewBaseRenderData(ctx), BaseRenderData: *NewBaseRenderData(ctx),
Err: err, Err: err,
Code: code, Code: code,
Status: http.StatusText(code), Status: http.StatusText(code),
} }
if err := ctx.Render(code, "error.html", &rdata); err != nil { if err := ctx.Render(code, "error.html", &rdata); err != nil {

View File

@ -32,7 +32,7 @@ func generateToken() (string, error) {
} }
var ( var (
ErrSessionExpired = errors.New("session expired") ErrSessionExpired = errors.New("session expired")
ErrAttachmentCacheSize = errors.New("Attachments on session exceed maximum file size") ErrAttachmentCacheSize = errors.New("Attachments on session exceed maximum file size")
) )
@ -157,13 +157,13 @@ func (s *Session) PutAttachment(in *multipart.FileHeader,
for _, a := range s.attachments { for _, a := range s.attachments {
size += a.File.Size size += a.File.Size
} }
if size + in.Size > maxAttachmentSize { if size+in.Size > maxAttachmentSize {
return "", ErrAttachmentCacheSize return "", ErrAttachmentCacheSize
} }
s.attachments[id.String()] = &Attachment{ s.attachments[id.String()] = &Attachment{
File: in, File: in,
Form: form, Form: form,
} }
s.attachmentsLocker.Unlock() s.attachmentsLocker.Unlock()
return id.String(), nil return id.String(), nil