File: filters.go

package info (click to toggle)
golang-github-protonmail-gluon 0.17.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,020 kB
  • sloc: sh: 55; makefile: 5
file content (93 lines) | stat: -rw-r--r-- 2,086 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package state

import (
	"fmt"

	"github.com/ProtonMail/gluon/imap"
)

type SnapFilter interface {
	Filter(s *State) bool
	String() string
}

type AllStateFilter struct{}

func (*AllStateFilter) Filter(s *State) bool {
	return s.snap != nil
}

func (*AllStateFilter) String() string {
	return "AllStates"
}

func NewAllStateFilter() SnapFilter {
	return &AllStateFilter{}
}

type MBoxIDStateFilter struct {
	MboxID imap.InternalMailboxID
}

func NewMBoxIDStateFilter(mboxID imap.InternalMailboxID) SnapFilter {
	return &MBoxIDStateFilter{MboxID: mboxID}
}

func (f *MBoxIDStateFilter) String() string {
	return fmt.Sprintf("mbox = %v", f.MboxID.ShortID())
}

func (f *MBoxIDStateFilter) Filter(s *State) bool {
	return s.snap != nil && s.snap.mboxID.InternalID == f.MboxID
}

type MessageIDStateFilter struct {
	MessageID imap.InternalMessageID
}

func NewMessageIDStateFilter(msgID imap.InternalMessageID) SnapFilter {
	return &MessageIDStateFilter{MessageID: msgID}
}

func (f *MessageIDStateFilter) Filter(s *State) bool {
	return s.snap != nil && s.snap.hasMessage(f.MessageID)
}

func (f *MessageIDStateFilter) String() string {
	return fmt.Sprintf("message = %v", f.MessageID.ShortID())
}

type MessageAndMBoxIDStateFilter struct {
	MessageID imap.InternalMessageID
	MBoxID    imap.InternalMailboxID
}

func NewMessageAndMBoxIDStateFilter(msgID imap.InternalMessageID, mboxID imap.InternalMailboxID) SnapFilter {
	return &MessageAndMBoxIDStateFilter{MessageID: msgID, MBoxID: mboxID}
}

func (f *MessageAndMBoxIDStateFilter) Filter(s *State) bool {
	return s.snap != nil && s.snap.mboxID.InternalID == f.MBoxID && s.snap.hasMessage(f.MessageID)
}

func (f *MessageAndMBoxIDStateFilter) String() string {
	return fmt.Sprintf("mbox = %v message = %v", f.MBoxID.ShortID(), f.MessageID.ShortID())
}

type AnyMessageIDStateFilter struct {
	MessageIDs []imap.InternalMessageID
}

func (f *AnyMessageIDStateFilter) Filter(s *State) bool {
	if s.snap == nil {
		return false
	}

	for _, msgID := range f.MessageIDs {
		if s.snap.hasMessage(msgID) {
			return true
		}
	}

	return false
}