2021-07-18 23:03:28 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021 Neil Alexander
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-07-10 11:42:55 +01:00
|
|
|
package imapserver
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/emersion/go-imap"
|
2026-02-14 02:34:09 +05:00
|
|
|
"github.com/emersion/go-imap/backend"
|
|
|
|
|
"github.com/neilalexander/yggmail/internal/notify"
|
2021-07-10 11:42:55 +01:00
|
|
|
)
|
|
|
|
|
|
2026-02-14 02:34:09 +05:00
|
|
|
// github.com/emersion/go-imap/backend/updates.go
|
|
|
|
|
func (b *Backend) listenUpdates() {
|
|
|
|
|
allEvents := b.Notify.Subscribe(notify.AllUsers)
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
for event := range allEvents {
|
|
|
|
|
if ev, ok := event.(*notify.EmailEvent); ok {
|
|
|
|
|
// b.updates <- &backend.MailboxUpdate{
|
|
|
|
|
// Update: backend.NewUpdate(ev.GetAccountPK(), ev.Mailbox()),
|
|
|
|
|
// MailboxStatus: &imap.MailboxStatus{
|
|
|
|
|
// Name: ev.MailBox,
|
|
|
|
|
// Messages: uint32(ev.Count),
|
|
|
|
|
// UidNext: uint32(ev.MessageId),
|
|
|
|
|
// },
|
|
|
|
|
// }
|
|
|
|
|
// b.updates <- &backend.MessageUpdate{
|
|
|
|
|
// Update: backend.NewUpdate(ev.AccountPK, ev.MailBox),
|
|
|
|
|
// Message: imap.NewMessage(uint32(ev.Count), []imap.FetchItem{imap.FetchAll}),
|
|
|
|
|
// }
|
|
|
|
|
b.updates <- &backend.MailboxUpdate{
|
|
|
|
|
Update: backend.NewUpdate(ev.GetAccountPK(), ev.MailBox),
|
|
|
|
|
MailboxStatus: &imap.MailboxStatus{
|
|
|
|
|
Name: ev.MailBox,
|
|
|
|
|
Messages: uint32(ev.Count),
|
|
|
|
|
UidNext: uint32(ev.MessageId),
|
|
|
|
|
Items: map[imap.StatusItem]interface{}{imap.StatusMessages: "", imap.StatusUidNext: ev.Count},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
b.Log.Println("IMAP Notify: ", ev.Username())
|
|
|
|
|
}
|
2021-07-10 11:42:55 +01:00
|
|
|
}
|
2026-02-14 02:34:09 +05:00
|
|
|
}()
|
2021-07-10 11:42:55 +01:00
|
|
|
}
|