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