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 AttachmentPaths []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 SignSMIME bool // Whether to sign the email using S/MIME
37 EncryptSMIME bool // Whether to encrypt the email using S/MIME
38 SignPGP bool // Whether to sign the email using PGP
39}
40
41type Credentials struct {
42 Provider string
43 Name string
44 Host string // Host (this was the previous "Email Address" field in the UI)
45 FetchEmail string // Single email address to fetch messages for. If empty, code should default this to Host when creating the account.
46 SendAsEmail string // Optional From header email. If empty, sending falls back to FetchEmail, then Host.
47 Password string
48 IMAPServer string
49 IMAPPort int
50 SMTPServer string
51 SMTPPort int
52 AuthMethod string // "password" or "oauth2"
53 Protocol string // "imap" (default), "jmap", or "pop3"
54 JMAPEndpoint string // JMAP session URL
55 POP3Server string // POP3 server hostname
56 POP3Port int // POP3 server port
57}
58
59// StartOAuth2Msg is sent when the user requests OAuth2 authorization for a Gmail account.
60type StartOAuth2Msg struct {
61 Email string
62}
63
64// OAuth2CompleteMsg is sent when OAuth2 authorization completes.
65type OAuth2CompleteMsg struct {
66 Email string
67 Err error
68}
69
70type ChooseServiceMsg struct {
71 Service string
72}
73
74type EmailResultMsg struct {
75 Err error
76}
77
78type ClearStatusMsg struct{}
79
80type EmailsFetchedMsg struct {
81 Emails []fetcher.Email
82 AccountID string
83 Mailbox MailboxKind
84}
85
86type FetchErr error
87
88type GoToInboxMsg struct{}
89
90type GoToSentInboxMsg struct{}
91
92type GoToSendMsg struct {
93 To string
94 Subject string
95 Body string
96}
97
98type GoToSettingsMsg struct{}
99
100type GoToTrashArchiveMsg struct{}
101
102type GoToSignatureEditorMsg struct{}
103
104type FetchMoreEmailsMsg struct {
105 Offset uint32
106 AccountID string
107 Mailbox MailboxKind
108 Limit uint32
109}
110
111type FetchingMoreEmailsMsg struct{}
112
113type EmailsAppendedMsg struct {
114 Emails []fetcher.Email
115 AccountID string
116 Mailbox MailboxKind
117}
118
119type ReplyToEmailMsg struct {
120 Email fetcher.Email
121}
122
123type ForwardEmailMsg struct {
124 Email fetcher.Email
125}
126
127type SetComposerCursorToStartMsg struct{}
128
129type GoToFilePickerMsg struct{}
130
131type FileSelectedMsg struct {
132 Path string
133}
134
135type CancelFilePickerMsg struct{}
136
137type DeleteEmailMsg struct {
138 UID uint32
139 AccountID string
140 Mailbox MailboxKind
141}
142
143type ArchiveEmailMsg struct {
144 UID uint32
145 AccountID string
146 Mailbox MailboxKind
147}
148
149type EmailActionDoneMsg struct {
150 UID uint32
151 AccountID string
152 Mailbox MailboxKind
153 Err error
154}
155
156// Batch operation messages
157type BatchDeleteEmailsMsg struct {
158 UIDs []uint32
159 AccountID string
160 Mailbox MailboxKind
161}
162
163type BatchArchiveEmailsMsg struct {
164 UIDs []uint32
165 AccountID string
166 Mailbox MailboxKind
167}
168
169type BatchMoveEmailsMsg struct {
170 UIDs []uint32
171 AccountID string
172 SourceFolder string
173 DestFolder string
174}
175
176type BatchEmailActionDoneMsg struct {
177 Count int
178 SuccessCount int
179 FailureCount int
180 Action string // "delete", "archive", or "move"
181 Mailbox MailboxKind
182 Err error
183}
184
185type GoToChoiceMenuMsg struct{}
186
187type DownloadAttachmentMsg struct {
188 Index int
189 Filename string
190 PartID string
191 Data []byte
192 AccountID string
193 Encoding string
194 Mailbox MailboxKind
195}
196
197type AttachmentDownloadedMsg struct {
198 Path string
199 Err error
200}
201
202type RestoreViewMsg struct{}
203
204type BackToInboxMsg struct{}
205
206type BackToMailboxMsg struct {
207 Mailbox MailboxKind
208}
209
210// --- Draft Messages ---
211
212// DiscardDraftMsg signals that a draft should be cached.
213type DiscardDraftMsg struct {
214 ComposerState *Composer
215}
216
217type EmailBodyFetchedMsg struct {
218 UID uint32
219 Body string
220 Attachments []fetcher.Attachment
221 Err error
222 AccountID string
223 Mailbox MailboxKind
224}
225
226// --- Multi-Account Messages ---
227
228// GoToAddAccountMsg signals navigation to the add account screen.
229type GoToAddAccountMsg struct{}
230
231// GoToAddMailingListMsg signals navigation to the add mailing list screen.
232type GoToAddMailingListMsg struct{}
233
234// GoToEditAccountMsg signals navigation to edit an existing account.
235type GoToEditAccountMsg struct {
236 AccountID string
237 Provider string
238 Name string
239 Email string
240 FetchEmail string
241 SendAsEmail string
242 IMAPServer string
243 IMAPPort int
244 SMTPServer string
245 SMTPPort int
246 Protocol string
247 JMAPEndpoint string
248 POP3Server string
249 POP3Port int
250}
251
252// GoToEditMailingListMsg signals navigation to edit an existing mailing list.
253type GoToEditMailingListMsg struct {
254 Index int
255 Name string
256 Addresses string
257}
258
259// SaveMailingListMsg signals that a new or edited mailing list should be saved.
260type SaveMailingListMsg struct {
261 Name string
262 Addresses string
263 EditIndex int // -1 means new, >= 0 means editing existing
264}
265
266// AddAccountMsg signals that a new account should be added.
267type AddAccountMsg struct {
268 Credentials Credentials
269}
270
271// AccountAddedMsg signals that an account was successfully added.
272type AccountAddedMsg struct {
273 AccountID string
274 Err error
275}
276
277// DeleteAccountMsg signals that an account should be deleted.
278type DeleteAccountMsg struct {
279 AccountID string
280}
281
282// AccountDeletedMsg signals that an account was successfully deleted.
283type AccountDeletedMsg struct {
284 AccountID string
285 Err error
286}
287
288// SwitchAccountMsg signals switching to view a specific account's inbox.
289type SwitchAccountMsg struct {
290 AccountID string // Empty string means "ALL" accounts
291}
292
293// AllEmailsFetchedMsg signals that emails from all accounts have been fetched.
294type AllEmailsFetchedMsg struct {
295 EmailsByAccount map[string][]fetcher.Email
296 Mailbox MailboxKind
297}
298
299// SwitchFromAccountMsg signals changing the "From" account in composer.
300type SwitchFromAccountMsg struct {
301 AccountID string
302}
303
304// GoToAccountListMsg signals navigation to the account list in settings.
305type GoToAccountListMsg struct{}
306
307// --- Draft Messages (persisted) ---
308
309// SaveDraftMsg signals that the current draft should be saved to disk.
310type SaveDraftMsg struct {
311 Draft config.Draft
312}
313
314// DraftSavedMsg signals that a draft was saved successfully.
315type DraftSavedMsg struct {
316 DraftID string
317 Err error
318}
319
320// LoadDraftsMsg signals a request to load all saved drafts.
321type LoadDraftsMsg struct{}
322
323// DraftsLoadedMsg signals that drafts were loaded from disk.
324type DraftsLoadedMsg struct {
325 Drafts []config.Draft
326}
327
328// OpenDraftMsg signals that a specific draft should be opened in the composer.
329type OpenDraftMsg struct {
330 Draft config.Draft
331}
332
333// DeleteDraftMsg signals that a draft should be deleted.
334type DeleteSavedDraftMsg struct {
335 DraftID string
336}
337
338// DraftDeletedMsg signals that a draft was deleted.
339type DraftDeletedMsg struct {
340 DraftID string
341 Err error
342}
343
344// GoToDraftsMsg signals navigation to the drafts list.
345type GoToDraftsMsg struct{}
346
347// --- Cache Messages ---
348
349// CachedEmailsLoadedMsg signals that cached emails were loaded from disk.
350type CachedEmailsLoadedMsg struct {
351 Cache *config.EmailCache
352}
353
354// RefreshingEmailsMsg signals that a background refresh is in progress.
355type RefreshingEmailsMsg struct {
356 Mailbox MailboxKind
357}
358
359// EmailsRefreshedMsg signals that fresh emails have been fetched in the background.
360type EmailsRefreshedMsg struct {
361 EmailsByAccount map[string][]fetcher.Email
362 Mailbox MailboxKind
363}
364
365// RequestRefreshMsg signals a request to refresh emails from the server.
366type RequestRefreshMsg struct {
367 Mailbox MailboxKind
368 Counts map[string]int
369 FolderName string
370}
371
372// --- Folder Messages ---
373
374// FoldersFetchedMsg signals that IMAP folders have been fetched for all accounts.
375type FoldersFetchedMsg struct {
376 FoldersByAccount map[string][]fetcher.Folder // accountID -> folders
377 MergedFolders []fetcher.Folder // unique folders across all accounts
378}
379
380// SwitchFolderMsg signals switching to a different IMAP folder.
381type SwitchFolderMsg struct {
382 FolderName string
383 AccountID string
384}
385
386// FolderEmailsFetchedMsg signals that emails from a folder have been fetched.
387type FolderEmailsFetchedMsg struct {
388 Emails []fetcher.Email
389 AccountID string
390 FolderName string
391}
392
393// FolderEmailsAppendedMsg signals that more emails from a folder have been fetched (pagination).
394type FolderEmailsAppendedMsg struct {
395 Emails []fetcher.Email
396 AccountID string
397 FolderName string
398}
399
400// MoveEmailMsg signals a request to show the move-to-folder picker.
401type MoveEmailMsg struct {
402 UID uint32
403 AccountID string
404 SourceFolder string
405}
406
407// MoveEmailToFolderMsg signals that an email should be moved to a folder.
408type MoveEmailToFolderMsg struct {
409 UID uint32
410 AccountID string
411 SourceFolder string
412 DestFolder string
413}
414
415// EmailMovedMsg signals that an email was moved to a folder.
416type EmailMovedMsg struct {
417 UID uint32
418 AccountID string
419 SourceFolder string
420 DestFolder string
421 Err error
422}
423
424// MarkEmailAsReadMsg signals that an email should be marked as read on the server.
425type MarkEmailAsReadMsg struct {
426 UID uint32
427 AccountID string
428 FolderName string
429}
430
431// EmailMarkedReadMsg signals that an email was marked as read.
432type EmailMarkedReadMsg struct {
433 UID uint32
434 AccountID string
435 Err error
436}
437
438// FetchFolderMoreEmailsMsg signals a request to fetch more emails from a folder (pagination).
439type FetchFolderMoreEmailsMsg struct {
440 Offset uint32
441 AccountID string
442 FolderName string
443 Limit uint32
444}
445
446// --- External Editor Messages ---
447
448// OpenEditorMsg signals that the composer body should be opened in $EDITOR.
449type OpenEditorMsg struct{}
450
451// EditorFinishedMsg signals that the external editor has closed.
452type EditorFinishedMsg struct {
453 Body string
454 Err error
455}
456
457// --- IDLE Messages ---
458
459// IdleNewMailMsg signals that IMAP IDLE detected new mail for an account/folder.
460type IdleNewMailMsg struct {
461 AccountID string
462 FolderName string
463}
464
465// --- Plugin Messages ---
466
467// PluginNotifyMsg signals that a plugin wants to show a notification.
468type PluginNotifyMsg struct {
469 Message string
470 Duration float64 // Duration in seconds (default 2)
471}
472
473// PluginKeyBinding describes a plugin-registered keyboard shortcut for display in the help bar.
474type PluginKeyBinding struct {
475 Key string
476 Description string
477}
478
479// PluginPromptSubmitMsg signals that the user submitted a plugin prompt input.
480type PluginPromptSubmitMsg struct {
481 Value string
482}
483
484// PluginPromptCancelMsg signals that the user cancelled a plugin prompt input.
485type PluginPromptCancelMsg struct{}
486
487// GoToMarketplaceMsg signals navigation to the plugin marketplace.
488type GoToMarketplaceMsg struct{}
489
490// PasswordVerifiedMsg signals that the encryption password was verified (or failed).
491type PasswordVerifiedMsg struct {
492 Key []byte // The derived encryption key (nil on failure)
493 Err error // Non-nil if verification failed
494}
495
496// SecureModeEnabledMsg signals that encryption was enabled from settings.
497type SecureModeEnabledMsg struct {
498 Err error
499}
500
501// SecureModeDisabledMsg signals that encryption was disabled from settings.
502type SecureModeDisabledMsg struct {
503 Err error
504}