mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-18 08:06:59 +00:00
Other: More descriptive event poll name
This commit is contained in:
@ -86,7 +86,7 @@ func (conn *imapConnector) Authorize(username string, password []byte) bool {
|
||||
|
||||
// CreateMailbox creates a label with the given name.
|
||||
func (conn *imapConnector) CreateMailbox(ctx context.Context, name []string) (imap.Mailbox, error) {
|
||||
defer conn.goPoll(false)
|
||||
defer conn.goPollAPIEvents(false)
|
||||
|
||||
if len(name) < 2 {
|
||||
return imap.Mailbox{}, fmt.Errorf("invalid mailbox name %q", name)
|
||||
@ -157,7 +157,7 @@ func (conn *imapConnector) createFolder(ctx context.Context, name []string) (ima
|
||||
|
||||
// UpdateMailboxName sets the name of the label with the given ID.
|
||||
func (conn *imapConnector) UpdateMailboxName(ctx context.Context, labelID imap.MailboxID, name []string) error {
|
||||
defer conn.goPoll(false)
|
||||
defer conn.goPollAPIEvents(false)
|
||||
|
||||
if len(name) < 2 {
|
||||
return fmt.Errorf("invalid mailbox name %q", name)
|
||||
@ -234,7 +234,7 @@ func (conn *imapConnector) updateFolder(ctx context.Context, labelID imap.Mailbo
|
||||
|
||||
// DeleteMailbox deletes the label with the given ID.
|
||||
func (conn *imapConnector) DeleteMailbox(ctx context.Context, labelID imap.MailboxID) error {
|
||||
defer conn.goPoll(false)
|
||||
defer conn.goPollAPIEvents(false)
|
||||
|
||||
return conn.client.DeleteLabel(ctx, string(labelID))
|
||||
}
|
||||
@ -249,7 +249,7 @@ func (conn *imapConnector) CreateMessage(
|
||||
flags imap.FlagSet,
|
||||
date time.Time,
|
||||
) (imap.Message, []byte, error) {
|
||||
defer conn.goPoll(false)
|
||||
defer conn.goPollAPIEvents(false)
|
||||
|
||||
// Compute the hash of the message (to match it against SMTP messages).
|
||||
hash, err := getMessageHash(literal)
|
||||
@ -313,14 +313,14 @@ func (conn *imapConnector) CreateMessage(
|
||||
|
||||
// AddMessagesToMailbox labels the given messages with the given label ID.
|
||||
func (conn *imapConnector) AddMessagesToMailbox(ctx context.Context, messageIDs []imap.MessageID, mailboxID imap.MailboxID) error {
|
||||
defer conn.goPoll(false)
|
||||
defer conn.goPollAPIEvents(false)
|
||||
|
||||
return conn.client.LabelMessages(ctx, mapTo[imap.MessageID, string](messageIDs), string(mailboxID))
|
||||
}
|
||||
|
||||
// RemoveMessagesFromMailbox unlabels the given messages with the given label ID.
|
||||
func (conn *imapConnector) RemoveMessagesFromMailbox(ctx context.Context, messageIDs []imap.MessageID, mailboxID imap.MailboxID) error {
|
||||
defer conn.goPoll(false)
|
||||
defer conn.goPollAPIEvents(false)
|
||||
|
||||
if err := conn.client.UnlabelMessages(ctx, mapTo[imap.MessageID, string](messageIDs), string(mailboxID)); err != nil {
|
||||
return err
|
||||
@ -363,7 +363,7 @@ func (conn *imapConnector) RemoveMessagesFromMailbox(ctx context.Context, messag
|
||||
|
||||
// MoveMessages removes the given messages from one label and adds them to the other label.
|
||||
func (conn *imapConnector) MoveMessages(ctx context.Context, messageIDs []imap.MessageID, labelFromID imap.MailboxID, labelToID imap.MailboxID) error {
|
||||
defer conn.goPoll(false)
|
||||
defer conn.goPollAPIEvents(false)
|
||||
|
||||
if err := conn.client.LabelMessages(ctx, mapTo[imap.MessageID, string](messageIDs), string(labelToID)); err != nil {
|
||||
return fmt.Errorf("labeling messages: %w", err)
|
||||
@ -378,7 +378,7 @@ func (conn *imapConnector) MoveMessages(ctx context.Context, messageIDs []imap.M
|
||||
|
||||
// MarkMessagesSeen sets the seen value of the given messages.
|
||||
func (conn *imapConnector) MarkMessagesSeen(ctx context.Context, messageIDs []imap.MessageID, seen bool) error {
|
||||
defer conn.goPoll(false)
|
||||
defer conn.goPollAPIEvents(false)
|
||||
|
||||
if seen {
|
||||
return conn.client.MarkMessagesRead(ctx, mapTo[imap.MessageID, string](messageIDs)...)
|
||||
@ -389,7 +389,7 @@ func (conn *imapConnector) MarkMessagesSeen(ctx context.Context, messageIDs []im
|
||||
|
||||
// MarkMessagesFlagged sets the flagged value of the given messages.
|
||||
func (conn *imapConnector) MarkMessagesFlagged(ctx context.Context, messageIDs []imap.MessageID, flagged bool) error {
|
||||
defer conn.goPoll(false)
|
||||
defer conn.goPollAPIEvents(false)
|
||||
|
||||
if flagged {
|
||||
return conn.client.LabelMessages(ctx, mapTo[imap.MessageID, string](messageIDs), liteapi.StarredLabel)
|
||||
|
||||
@ -72,10 +72,11 @@ type User struct {
|
||||
|
||||
tasks *async.Group
|
||||
abortable async.Abortable
|
||||
pollCh chan chan struct{}
|
||||
goPoll func(bool)
|
||||
goSync func()
|
||||
|
||||
pollAPIEventsCh chan chan struct{}
|
||||
goPollAPIEvents func(wait bool)
|
||||
|
||||
syncWorkers int
|
||||
syncBuffer int
|
||||
showAllMail uint32
|
||||
@ -132,7 +133,7 @@ func New(
|
||||
reporter: reporter,
|
||||
|
||||
tasks: async.NewGroup(context.Background(), crashHandler),
|
||||
pollCh: make(chan chan struct{}),
|
||||
pollAPIEventsCh: make(chan chan struct{}),
|
||||
|
||||
syncWorkers: syncWorkers,
|
||||
syncBuffer: syncBuffer,
|
||||
@ -179,7 +180,7 @@ func New(
|
||||
case <-ctx.Done():
|
||||
return
|
||||
|
||||
case doneCh = <-user.pollCh:
|
||||
case doneCh = <-user.pollAPIEventsCh:
|
||||
// ...
|
||||
|
||||
case <-ticker.C:
|
||||
@ -201,10 +202,10 @@ func New(
|
||||
})
|
||||
|
||||
// When triggered, poll the API for events, optionally blocking until the poll is complete.
|
||||
user.goPoll = func(wait bool) {
|
||||
user.goPollAPIEvents = func(wait bool) {
|
||||
doneCh := make(chan struct{})
|
||||
|
||||
go func() { user.pollCh <- doneCh }()
|
||||
go func() { user.pollAPIEventsCh <- doneCh }()
|
||||
|
||||
if wait {
|
||||
<-doneCh
|
||||
@ -411,7 +412,7 @@ func (user *User) NewIMAPConnectors() (map[string]connector.Connector, error) {
|
||||
//
|
||||
// nolint:funlen
|
||||
func (user *User) SendMail(authID string, from string, to []string, r io.Reader) error {
|
||||
defer user.goPoll(true)
|
||||
defer user.goPollAPIEvents(true)
|
||||
|
||||
if len(to) == 0 {
|
||||
return ErrInvalidRecipient
|
||||
|
||||
Reference in New Issue
Block a user