Support for IMAP MOVE

This commit is contained in:
Neil Alexander
2025-12-02 19:23:49 +00:00
parent d2093e00bf
commit 8385ac78da
6 changed files with 46 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ import (
"log"
idle "github.com/emersion/go-imap-idle"
move "github.com/emersion/go-imap-move"
"github.com/emersion/go-imap/server"
"github.com/emersion/go-sasl"
)
@@ -19,6 +20,7 @@ import (
type IMAPServer struct {
server *server.Server
backend *Backend
notify *IMAPNotify
}
func NewIMAPServer(backend *Backend, addr string, insecure bool) (*IMAPServer, *IMAPNotify, error) {
@@ -26,12 +28,13 @@ func NewIMAPServer(backend *Backend, addr string, insecure bool) (*IMAPServer, *
server: server.New(backend),
backend: backend,
}
notify := NewIMAPNotify(s.server, backend.Log)
s.notify = NewIMAPNotify(s.server, backend.Log)
s.server.Addr = addr
s.server.AllowInsecureAuth = insecure
//s.server.Debug = os.Stdout
s.server.Enable(idle.NewExtension())
//s.server.Enable(notify)
s.server.Enable(move.NewExtension())
// s.server.Enable(s.notify)
s.server.EnableAuth(sasl.Login, func(conn server.Conn) sasl.Server {
return sasl.NewLoginServer(func(username, password string) error {
_, err := s.backend.Login(nil, username, password)
@@ -43,5 +46,5 @@ func NewIMAPServer(backend *Backend, addr string, insecure bool) (*IMAPServer, *
log.Fatal(err)
}
}()
return s, notify, nil
return s, s.notify, nil
}

View File

@@ -13,7 +13,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"time"
"github.com/emersion/go-imap"
@@ -214,7 +213,7 @@ func (mbox *Mailbox) SearchMessages(uid bool, criteria *imap.SearchCriteria) ([]
}
func (mbox *Mailbox) CreateMessage(flags []string, date time.Time, body imap.Literal) error {
b, err := ioutil.ReadAll(body)
b, err := io.ReadAll(body)
if err != nil {
return fmt.Errorf("b.ReadFrom: %w", err)
}
@@ -312,3 +311,21 @@ func (mbox *Mailbox) CopyMessages(uid bool, seqSet *imap.SeqSet, destName string
func (mbox *Mailbox) Expunge() error {
return mbox.backend.Storage.MailExpunge(mbox.name)
}
func (mbox *Mailbox) MoveMessages(uid bool, seqset *imap.SeqSet, dest string) error {
if dest == "Outbox" {
return fmt.Errorf("can't copy into Outbox as it is a protected folder")
}
ids, err := mbox.getIDsFromSeqSet(uid, seqset)
if err != nil {
return fmt.Errorf("mbox.getIDsFromSeqSet: %w", err)
}
for _, id := range ids {
if err := mbox.backend.Storage.MailMove(mbox.name, int(id), dest); err != nil {
return err
}
}
return nil
}