1package tui
2
3import (
4 "github.com/floatpane/matcha/config"
5 "github.com/floatpane/matcha/fetcher"
6)
7
8type MailboxKind string
9
10const (
11 MailboxInbox MailboxKind = "inbox"
12 MailboxSent MailboxKind = "sent"
13 MailboxTrash MailboxKind = "trash"
14 MailboxArchive MailboxKind = "archive"
15)
16
17type ViewEmailMsg struct {
18 Index int
19 UID uint32
20 AccountID string
21 Mailbox MailboxKind
22}
23
24type SendEmailMsg struct {
25 To string
26 Cc string // Cc recipient(s)
27 Bcc string // Bcc recipient(s)
28 Subject string
29 Body string
30 AttachmentPath string
31 InReplyTo string
32 References []string
33 AccountID string // ID of the account to send from
34 QuotedText string // Hidden quoted text appended when sending
35 Signature string // Signature to append to email body
36}
37
38type Credentials struct {
39 Provider string
40 Name string
41 Host string // Host (this was the previous \"Email Address\" field in the UI)
42 FetchEmail string // Single email address to fetch messages for. If empty, code should default this to Host when creating the account.
43 Password string
44 IMAPServer string
45 IMAPPort int
46 SMTPServer string
47 SMTPPort int
48}
49
50type ChooseServiceMsg struct {
51 Service string
52}
53
54type EmailResultMsg struct {
55 Err error
56}
57
58type ClearStatusMsg struct{}
59
60type EmailsFetchedMsg struct {
61 Emails []fetcher.Email
62 AccountID string
63 Mailbox MailboxKind
64}
65
66type FetchErr error
67
68type GoToInboxMsg struct{}
69
70type GoToSentInboxMsg struct{}
71
72type GoToSendMsg struct {
73 To string
74 Subject string
75 Body string
76}
77
78type GoToSettingsMsg struct{}
79
80type GoToTrashArchiveMsg struct{}
81
82type GoToSignatureEditorMsg struct{}
83
84type FetchMoreEmailsMsg struct {
85 Offset uint32
86 AccountID string
87 Mailbox MailboxKind
88 Limit uint32
89}
90
91type FetchingMoreEmailsMsg struct{}
92
93type EmailsAppendedMsg struct {
94 Emails []fetcher.Email
95 AccountID string
96 Mailbox MailboxKind
97}
98
99type ReplyToEmailMsg struct {
100 Email fetcher.Email
101}
102
103type ForwardEmailMsg struct {
104 Email fetcher.Email
105}
106
107type SetComposerCursorToStartMsg struct{}
108
109type GoToFilePickerMsg struct{}
110
111type FileSelectedMsg struct {
112 Path string
113}
114
115type CancelFilePickerMsg struct{}
116
117type DeleteEmailMsg struct {
118 UID uint32
119 AccountID string
120 Mailbox MailboxKind
121}
122
123type ArchiveEmailMsg struct {
124 UID uint32
125 AccountID string
126 Mailbox MailboxKind
127}
128
129type EmailActionDoneMsg struct {
130 UID uint32
131 AccountID string
132 Mailbox MailboxKind
133 Err error
134}
135
136type GoToChoiceMenuMsg struct{}
137
138type DownloadAttachmentMsg struct {
139 Index int
140 Filename string
141 PartID string
142 Data []byte
143 AccountID string
144 Encoding string
145 Mailbox MailboxKind
146}
147
148type AttachmentDownloadedMsg struct {
149 Path string
150 Err error
151}
152
153type RestoreViewMsg struct{}
154
155type BackToInboxMsg struct{}
156
157type BackToMailboxMsg struct {
158 Mailbox MailboxKind
159}
160
161// --- Draft Messages ---
162
163// DiscardDraftMsg signals that a draft should be cached.
164type DiscardDraftMsg struct {
165 ComposerState *Composer
166}
167
168type EmailBodyFetchedMsg struct {
169 UID uint32
170 Body string
171 Attachments []fetcher.Attachment
172 Err error
173 AccountID string
174 Mailbox MailboxKind
175}
176
177// --- Multi-Account Messages ---
178
179// GoToAddAccountMsg signals navigation to the add account screen.
180type GoToAddAccountMsg struct{}
181
182// GoToAddMailingListMsg signals navigation to the add mailing list screen.
183type GoToAddMailingListMsg struct{}
184
185// SaveMailingListMsg signals that a new mailing list should be saved.
186type SaveMailingListMsg struct {
187 Name string
188 Addresses string
189}
190
191// AddAccountMsg signals that a new account should be added.
192type AddAccountMsg struct {
193 Credentials Credentials
194}
195
196// AccountAddedMsg signals that an account was successfully added.
197type AccountAddedMsg struct {
198 AccountID string
199 Err error
200}
201
202// DeleteAccountMsg signals that an account should be deleted.
203type DeleteAccountMsg struct {
204 AccountID string
205}
206
207// AccountDeletedMsg signals that an account was successfully deleted.
208type AccountDeletedMsg struct {
209 AccountID string
210 Err error
211}
212
213// SwitchAccountMsg signals switching to view a specific account's inbox.
214type SwitchAccountMsg struct {
215 AccountID string // Empty string means "ALL" accounts
216}
217
218// AllEmailsFetchedMsg signals that emails from all accounts have been fetched.
219type AllEmailsFetchedMsg struct {
220 EmailsByAccount map[string][]fetcher.Email
221 Mailbox MailboxKind
222}
223
224// SwitchFromAccountMsg signals changing the "From" account in composer.
225type SwitchFromAccountMsg struct {
226 AccountID string
227}
228
229// GoToAccountListMsg signals navigation to the account list in settings.
230type GoToAccountListMsg struct{}
231
232// --- Draft Messages (persisted) ---
233
234// SaveDraftMsg signals that the current draft should be saved to disk.
235type SaveDraftMsg struct {
236 Draft config.Draft
237}
238
239// DraftSavedMsg signals that a draft was saved successfully.
240type DraftSavedMsg struct {
241 DraftID string
242 Err error
243}
244
245// LoadDraftsMsg signals a request to load all saved drafts.
246type LoadDraftsMsg struct{}
247
248// DraftsLoadedMsg signals that drafts were loaded from disk.
249type DraftsLoadedMsg struct {
250 Drafts []config.Draft
251}
252
253// OpenDraftMsg signals that a specific draft should be opened in the composer.
254type OpenDraftMsg struct {
255 Draft config.Draft
256}
257
258// DeleteDraftMsg signals that a draft should be deleted.
259type DeleteSavedDraftMsg struct {
260 DraftID string
261}
262
263// DraftDeletedMsg signals that a draft was deleted.
264type DraftDeletedMsg struct {
265 DraftID string
266 Err error
267}
268
269// GoToDraftsMsg signals navigation to the drafts list.
270type GoToDraftsMsg struct{}
271
272// --- Cache Messages ---
273
274// CachedEmailsLoadedMsg signals that cached emails were loaded from disk.
275type CachedEmailsLoadedMsg struct {
276 Cache *config.EmailCache
277}
278
279// RefreshingEmailsMsg signals that a background refresh is in progress.
280type RefreshingEmailsMsg struct {
281 Mailbox MailboxKind
282}
283
284// EmailsRefreshedMsg signals that fresh emails have been fetched in the background.
285type EmailsRefreshedMsg struct {
286 EmailsByAccount map[string][]fetcher.Email
287 Mailbox MailboxKind
288}
289
290// RequestRefreshMsg signals a request to refresh emails from the server.
291type RequestRefreshMsg struct {
292 Mailbox MailboxKind
293 Counts map[string]int
294}