messages.go

  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
156type GoToChoiceMenuMsg struct{}
157
158type DownloadAttachmentMsg struct {
159	Index     int
160	Filename  string
161	PartID    string
162	Data      []byte
163	AccountID string
164	Encoding  string
165	Mailbox   MailboxKind
166}
167
168type AttachmentDownloadedMsg struct {
169	Path string
170	Err  error
171}
172
173type RestoreViewMsg struct{}
174
175type BackToInboxMsg struct{}
176
177type BackToMailboxMsg struct {
178	Mailbox MailboxKind
179}
180
181// --- Draft Messages ---
182
183// DiscardDraftMsg signals that a draft should be cached.
184type DiscardDraftMsg struct {
185	ComposerState *Composer
186}
187
188type EmailBodyFetchedMsg struct {
189	UID         uint32
190	Body        string
191	Attachments []fetcher.Attachment
192	Err         error
193	AccountID   string
194	Mailbox     MailboxKind
195}
196
197// --- Multi-Account Messages ---
198
199// GoToAddAccountMsg signals navigation to the add account screen.
200type GoToAddAccountMsg struct{}
201
202// GoToAddMailingListMsg signals navigation to the add mailing list screen.
203type GoToAddMailingListMsg struct{}
204
205// GoToEditAccountMsg signals navigation to edit an existing account.
206type GoToEditAccountMsg struct {
207	AccountID    string
208	Provider     string
209	Name         string
210	Email        string
211	FetchEmail   string
212	SendAsEmail  string
213	IMAPServer   string
214	IMAPPort     int
215	SMTPServer   string
216	SMTPPort     int
217	Protocol     string
218	JMAPEndpoint string
219	POP3Server   string
220	POP3Port     int
221}
222
223// GoToEditMailingListMsg signals navigation to edit an existing mailing list.
224type GoToEditMailingListMsg struct {
225	Index     int
226	Name      string
227	Addresses string
228}
229
230// SaveMailingListMsg signals that a new or edited mailing list should be saved.
231type SaveMailingListMsg struct {
232	Name      string
233	Addresses string
234	EditIndex int // -1 means new, >= 0 means editing existing
235}
236
237// AddAccountMsg signals that a new account should be added.
238type AddAccountMsg struct {
239	Credentials Credentials
240}
241
242// AccountAddedMsg signals that an account was successfully added.
243type AccountAddedMsg struct {
244	AccountID string
245	Err       error
246}
247
248// DeleteAccountMsg signals that an account should be deleted.
249type DeleteAccountMsg struct {
250	AccountID string
251}
252
253// AccountDeletedMsg signals that an account was successfully deleted.
254type AccountDeletedMsg struct {
255	AccountID string
256	Err       error
257}
258
259// SwitchAccountMsg signals switching to view a specific account's inbox.
260type SwitchAccountMsg struct {
261	AccountID string // Empty string means "ALL" accounts
262}
263
264// AllEmailsFetchedMsg signals that emails from all accounts have been fetched.
265type AllEmailsFetchedMsg struct {
266	EmailsByAccount map[string][]fetcher.Email
267	Mailbox         MailboxKind
268}
269
270// SwitchFromAccountMsg signals changing the "From" account in composer.
271type SwitchFromAccountMsg struct {
272	AccountID string
273}
274
275// GoToAccountListMsg signals navigation to the account list in settings.
276type GoToAccountListMsg struct{}
277
278// --- Draft Messages (persisted) ---
279
280// SaveDraftMsg signals that the current draft should be saved to disk.
281type SaveDraftMsg struct {
282	Draft config.Draft
283}
284
285// DraftSavedMsg signals that a draft was saved successfully.
286type DraftSavedMsg struct {
287	DraftID string
288	Err     error
289}
290
291// LoadDraftsMsg signals a request to load all saved drafts.
292type LoadDraftsMsg struct{}
293
294// DraftsLoadedMsg signals that drafts were loaded from disk.
295type DraftsLoadedMsg struct {
296	Drafts []config.Draft
297}
298
299// OpenDraftMsg signals that a specific draft should be opened in the composer.
300type OpenDraftMsg struct {
301	Draft config.Draft
302}
303
304// DeleteDraftMsg signals that a draft should be deleted.
305type DeleteSavedDraftMsg struct {
306	DraftID string
307}
308
309// DraftDeletedMsg signals that a draft was deleted.
310type DraftDeletedMsg struct {
311	DraftID string
312	Err     error
313}
314
315// GoToDraftsMsg signals navigation to the drafts list.
316type GoToDraftsMsg struct{}
317
318// --- Cache Messages ---
319
320// CachedEmailsLoadedMsg signals that cached emails were loaded from disk.
321type CachedEmailsLoadedMsg struct {
322	Cache *config.EmailCache
323}
324
325// RefreshingEmailsMsg signals that a background refresh is in progress.
326type RefreshingEmailsMsg struct {
327	Mailbox MailboxKind
328}
329
330// EmailsRefreshedMsg signals that fresh emails have been fetched in the background.
331type EmailsRefreshedMsg struct {
332	EmailsByAccount map[string][]fetcher.Email
333	Mailbox         MailboxKind
334}
335
336// RequestRefreshMsg signals a request to refresh emails from the server.
337type RequestRefreshMsg struct {
338	Mailbox    MailboxKind
339	Counts     map[string]int
340	FolderName string
341}
342
343// --- Folder Messages ---
344
345// FoldersFetchedMsg signals that IMAP folders have been fetched for all accounts.
346type FoldersFetchedMsg struct {
347	FoldersByAccount map[string][]fetcher.Folder // accountID -> folders
348	MergedFolders    []fetcher.Folder            // unique folders across all accounts
349}
350
351// SwitchFolderMsg signals switching to a different IMAP folder.
352type SwitchFolderMsg struct {
353	FolderName string
354	AccountID  string
355}
356
357// FolderEmailsFetchedMsg signals that emails from a folder have been fetched.
358type FolderEmailsFetchedMsg struct {
359	Emails     []fetcher.Email
360	AccountID  string
361	FolderName string
362}
363
364// FolderEmailsAppendedMsg signals that more emails from a folder have been fetched (pagination).
365type FolderEmailsAppendedMsg struct {
366	Emails     []fetcher.Email
367	AccountID  string
368	FolderName string
369}
370
371// MoveEmailMsg signals a request to show the move-to-folder picker.
372type MoveEmailMsg struct {
373	UID          uint32
374	AccountID    string
375	SourceFolder string
376}
377
378// MoveEmailToFolderMsg signals that an email should be moved to a folder.
379type MoveEmailToFolderMsg struct {
380	UID          uint32
381	AccountID    string
382	SourceFolder string
383	DestFolder   string
384}
385
386// EmailMovedMsg signals that an email was moved to a folder.
387type EmailMovedMsg struct {
388	UID          uint32
389	AccountID    string
390	SourceFolder string
391	DestFolder   string
392	Err          error
393}
394
395// MarkEmailAsReadMsg signals that an email should be marked as read on the server.
396type MarkEmailAsReadMsg struct {
397	UID        uint32
398	AccountID  string
399	FolderName string
400}
401
402// EmailMarkedReadMsg signals that an email was marked as read.
403type EmailMarkedReadMsg struct {
404	UID       uint32
405	AccountID string
406	Err       error
407}
408
409// FetchFolderMoreEmailsMsg signals a request to fetch more emails from a folder (pagination).
410type FetchFolderMoreEmailsMsg struct {
411	Offset     uint32
412	AccountID  string
413	FolderName string
414	Limit      uint32
415}
416
417// --- External Editor Messages ---
418
419// OpenEditorMsg signals that the composer body should be opened in $EDITOR.
420type OpenEditorMsg struct{}
421
422// EditorFinishedMsg signals that the external editor has closed.
423type EditorFinishedMsg struct {
424	Body string
425	Err  error
426}
427
428// --- IDLE Messages ---
429
430// IdleNewMailMsg signals that IMAP IDLE detected new mail for an account/folder.
431type IdleNewMailMsg struct {
432	AccountID  string
433	FolderName string
434}
435
436// --- Plugin Messages ---
437
438// PluginNotifyMsg signals that a plugin wants to show a notification.
439type PluginNotifyMsg struct {
440	Message  string
441	Duration float64 // Duration in seconds (default 2)
442}
443
444// PluginKeyBinding describes a plugin-registered keyboard shortcut for display in the help bar.
445type PluginKeyBinding struct {
446	Key         string
447	Description string
448}
449
450// PluginPromptSubmitMsg signals that the user submitted a plugin prompt input.
451type PluginPromptSubmitMsg struct {
452	Value string
453}
454
455// PluginPromptCancelMsg signals that the user cancelled a plugin prompt input.
456type PluginPromptCancelMsg struct{}
457
458// GoToMarketplaceMsg signals navigation to the plugin marketplace.
459type GoToMarketplaceMsg struct{}
460
461// PasswordVerifiedMsg signals that the encryption password was verified (or failed).
462type PasswordVerifiedMsg struct {
463	Key []byte // The derived encryption key (nil on failure)
464	Err error  // Non-nil if verification failed
465}
466
467// SecureModeEnabledMsg signals that encryption was enabled from settings.
468type SecureModeEnabledMsg struct {
469	Err error
470}
471
472// SecureModeDisabledMsg signals that encryption was disabled from settings.
473type SecureModeDisabledMsg struct {
474	Err error
475}