From 802cb3c41d2cc0b1a2a1c00d01e038f5f89cefc6 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 18 Mar 2024 10:16:57 +0100 Subject: Upgrade go-imap --- go.mod | 2 +- go.sum | 4 ++-- imap.go | 11 +++++------ plugins/base/routes.go | 15 +++++++++++---- store.go | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index b4af80c..a4b45dd 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/chris-ramon/douceur v0.2.0 github.com/dustin/go-humanize v1.0.1 github.com/emersion/go-ical v0.0.0-20220601085725-0864dccc089f - github.com/emersion/go-imap/v2 v2.0.0-alpha.8 + github.com/emersion/go-imap/v2 v2.0.0-beta.1 github.com/emersion/go-message v0.18.0 github.com/emersion/go-sasl v0.0.0-20231106173351-e73c9f7bad43 github.com/emersion/go-smtp v0.20.1 diff --git a/go.sum b/go.sum index f821064..ed0bfd1 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/emersion/go-ical v0.0.0-20220601085725-0864dccc089f h1:feGUUxxvOtWVOhTko8Cbmp33a+tU0IMZxMEmnkoAISQ= github.com/emersion/go-ical v0.0.0-20220601085725-0864dccc089f/go.mod h1:2MKFUgfNMULRxqZkadG1Vh44we3y5gJAtTBlVsx1BKQ= -github.com/emersion/go-imap/v2 v2.0.0-alpha.8 h1:OCh6kS5N7/3AXfJ+may4CA4C0asg4F9PWQN4355nVaQ= -github.com/emersion/go-imap/v2 v2.0.0-alpha.8/go.mod h1:HVKGwfmw6RkfT33vW8DQpSlvGJatNivoFNl/z/Sq4vE= +github.com/emersion/go-imap/v2 v2.0.0-beta.1 h1:6kXAnBoLHEEJQGvdBAFzoy/dzQvx1G2d2ntRCNUeMYc= +github.com/emersion/go-imap/v2 v2.0.0-beta.1/go.mod h1:HVKGwfmw6RkfT33vW8DQpSlvGJatNivoFNl/z/Sq4vE= github.com/emersion/go-message v0.18.0 h1:7LxAXHRpSeoO/Wom3ZApVZYG7c3d17yCScYce8WiXA8= github.com/emersion/go-message v0.18.0/go.mod h1:Zi69ACvzaoV/MBnrxfVBPV3xWEuCmC2nEN39oJF4B8A= github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ= diff --git a/imap.go b/imap.go index e70a394..ebdd2c8 100644 --- a/imap.go +++ b/imap.go @@ -32,18 +32,17 @@ func (s *Server) dialIMAP() (*imapclient.Client, error) { if err != nil { return nil, fmt.Errorf("failed to connect to IMAPS server: %v", err) } + } else if !s.imap.insecure { + c, err = imapclient.DialStartTLS(s.imap.host, options) + if err != nil { + return nil, fmt.Errorf("failed to connect to IMAP server: %v", err) + } } else { conn, err := net.Dial("tcp", s.imap.host) if err != nil { return nil, fmt.Errorf("failed to connect to IMAP server: %v", err) } c = imapclient.New(conn, options) - if !s.imap.insecure { - if err := c.StartTLS(nil); err != nil { - c.Close() - return nil, fmt.Errorf("STARTTLS failed: %v", err) - } - } } return c, err diff --git a/plugins/base/routes.go b/plugins/base/routes.go index 8aaed73..0f870ec 100644 --- a/plugins/base/routes.go +++ b/plugins/base/routes.go @@ -869,7 +869,7 @@ func populateMessageFromOriginalMessage(ctx *alps.Context, inReplyToPath message hdr.GenerateMessageID() mid, _ := hdr.MessageID() ret.MessageID = "<" + mid + ">" - ret.InReplyTo = inReplyTo.Envelope.MessageID + ret.InReplyTo = "<" + inReplyTo.Envelope.MessageID + ">" // TODO: populate From from known user addresses and inReplyTo.Envelope.To replyTo := inReplyTo.Envelope.ReplyTo if len(replyTo) == 0 { @@ -957,7 +957,7 @@ func handleForward(ctx *alps.Context) error { !strings.HasPrefix(strings.ToLower(msg.Subject), "fw:") { msg.Subject = "Fwd: " + msg.Subject } - msg.InReplyTo = source.Envelope.InReplyTo + msg.InReplyTo = formatMsgIDList(source.Envelope.InReplyTo) attachments := source.Attachments() for i := range attachments { @@ -1024,8 +1024,8 @@ func handleEdit(ctx *alps.Context) error { } msg.To = unwrapIMAPAddressList(source.Envelope.To) msg.Subject = source.Envelope.Subject - msg.InReplyTo = source.Envelope.InReplyTo - msg.MessageID = source.Envelope.MessageID + msg.InReplyTo = formatMsgIDList(source.Envelope.InReplyTo) + msg.MessageID = "<" + source.Envelope.MessageID + ">" attachments := source.Attachments() for i := range attachments { @@ -1042,6 +1042,13 @@ func handleEdit(ctx *alps.Context) error { return handleCompose(ctx, &msg, &composeOptions{Draft: &sourcePath}) } +func formatMsgIDList(l []string) string { + if len(l) == 0 { + return "" + } + return "<" + strings.Join(l, ">, <") + ">" +} + func formOrQueryParam(ctx *alps.Context, k string) string { if v := ctx.FormValue(k); v != "" { return v diff --git a/store.go b/store.go index d1fa91e..f149315 100644 --- a/store.go +++ b/store.go @@ -102,7 +102,7 @@ func (s *imapStore) Get(key string, out interface{}) error { if err != nil { return err } - entries = data.EntryValues + entries = data.Entries return nil }) if err != nil { -- cgit v1.2.3-59-g8ed1b