Fix archive reindex and add target dedup

This commit is contained in:
DonVoo 2026-07-14 20:57:09 +02:00
parent e612896e06
commit b16deffa25
9 changed files with 798 additions and 6 deletions

View file

@ -18,6 +18,7 @@ type TargetMailbox interface {
Append(folder string, m RawMessage) error // mit m.Flags und m.InternalDate
Headers(folder string, limit, offset int) ([]MessageHeader, error)
FetchOne(folder string, uid uint32) (RawMessage, error)
DeleteUIDs(folder string, uids []uint32) error
Close() error
}
@ -129,6 +130,32 @@ func (t *imapTarget) FetchOne(folder string, uid uint32) (RawMessage, error) {
return t.mailbox.fetchOne(folder, uid)
}
func (t *imapTarget) DeleteUIDs(folder string, uids []uint32) error {
if len(uids) == 0 {
return nil
}
if _, err := t.mailbox.c.Select(folder, nil).Wait(); err != nil {
return err
}
uidSet := imap.UIDSetNum(uint32sToUIDs(uids)...)
flags := &imap.StoreFlags{Op: imap.StoreFlagsAdd, Silent: true, Flags: []imap.Flag{imap.FlagDeleted}}
if err := t.mailbox.c.Store(uidSet, flags, nil).Close(); err != nil {
return err
}
_, err := t.mailbox.c.UIDExpunge(uidSet).Collect()
return err
}
func (t *imapTarget) Close() error {
return t.mailbox.Close()
}
func uint32sToUIDs(values []uint32) []imap.UID {
out := make([]imap.UID, 0, len(values))
for _, value := range values {
if value != 0 {
out = append(out, imap.UID(value))
}
}
return out
}