/* * 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/. */ package imapserver import ( "github.com/emersion/go-imap" "github.com/emersion/go-imap/backend" "github.com/neilalexander/yggmail/internal/notify" ) // 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()) } } }() }