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	EncryptPGP      bool   // Whether to encrypt the email using PGP
 40}
 41
 42type Credentials struct {
 43	Provider     string
 44	Name         string
 45	Host         string // Host (this was the previous "Email Address" field in the UI)
 46	FetchEmail   string // Single email address to fetch messages for. If empty, code should default this to Host when creating the account.
 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	IMAPServer   string
213	IMAPPort     int
214	SMTPServer   string
215	SMTPPort     int
216	Protocol     string
217	JMAPEndpoint string
218	POP3Server   string
219	POP3Port     int
220}
221
222// GoToEditMailingListMsg signals navigation to edit an existing mailing list.
223type GoToEditMailingListMsg struct {
224	Index     int
225	Name      string
226	Addresses string
227}
228
229// SaveMailingListMsg signals that a new or edited mailing list should be saved.
230type SaveMailingListMsg struct {
231	Name      string
232	Addresses string
233	EditIndex int // -1 means new, >= 0 means editing existing
234}
235
236// AddAccountMsg signals that a new account should be added.
237type AddAccountMsg struct {
238	Credentials Credentials
239}
240
241// AccountAddedMsg signals that an account was successfully added.
242type AccountAddedMsg struct {
243	AccountID string
244	Err       error
245}
246
247// DeleteAccountMsg signals that an account should be deleted.
248type DeleteAccountMsg struct {
249	AccountID string
250}
251
252// AccountDeletedMsg signals that an account was successfully deleted.
253type AccountDeletedMsg struct {
254	AccountID string
255	Err       error
256}
257
258// SwitchAccountMsg signals switching to view a specific account's inbox.
259type SwitchAccountMsg struct {
260	AccountID string // Empty string means "ALL" accounts
261}
262
263// AllEmailsFetchedMsg signals that emails from all accounts have been fetched.
264type AllEmailsFetchedMsg struct {
265	EmailsByAccount map[string][]fetcher.Email
266	Mailbox         MailboxKind
267}
268
269// SwitchFromAccountMsg signals changing the "From" account in composer.
270type SwitchFromAccountMsg struct {
271	AccountID string
272}
273
274// GoToAccountListMsg signals navigation to the account list in settings.
275type GoToAccountListMsg struct{}
276
277// --- Draft Messages (persisted) ---
278
279// SaveDraftMsg signals that the current draft should be saved to disk.
280type SaveDraftMsg struct {
281	Draft config.Draft
282}
283
284// DraftSavedMsg signals that a draft was saved successfully.
285type DraftSavedMsg struct {
286	DraftID string
287	Err     error
288}
289
290// LoadDraftsMsg signals a request to load all saved drafts.
291type LoadDraftsMsg struct{}
292
293// DraftsLoadedMsg signals that drafts were loaded from disk.
294type DraftsLoadedMsg struct {
295	Drafts []config.Draft
296}
297
298// OpenDraftMsg signals that a specific draft should be opened in the composer.
299type OpenDraftMsg struct {
300	Draft config.Draft
301}
302
303// DeleteDraftMsg signals that a draft should be deleted.
304type DeleteSavedDraftMsg struct {
305	DraftID string
306}
307
308// DraftDeletedMsg signals that a draft was deleted.
309type DraftDeletedMsg struct {
310	DraftID string
311	Err     error
312}
313
314// GoToDraftsMsg signals navigation to the drafts list.
315type GoToDraftsMsg struct{}
316
317// --- Cache Messages ---
318
319// CachedEmailsLoadedMsg signals that cached emails were loaded from disk.
320type CachedEmailsLoadedMsg struct {
321	Cache *config.EmailCache
322}
323
324// RefreshingEmailsMsg signals that a background refresh is in progress.
325type RefreshingEmailsMsg struct {
326	Mailbox MailboxKind
327}
328
329// EmailsRefreshedMsg signals that fresh emails have been fetched in the background.
330type EmailsRefreshedMsg struct {
331	EmailsByAccount map[string][]fetcher.Email
332	Mailbox         MailboxKind
333}
334
335// RequestRefreshMsg signals a request to refresh emails from the server.
336type RequestRefreshMsg struct {
337	Mailbox    MailboxKind
338	Counts     map[string]int
339	FolderName string
340}
341
342// --- Folder Messages ---
343
344// FoldersFetchedMsg signals that IMAP folders have been fetched for all accounts.
345type FoldersFetchedMsg struct {
346	FoldersByAccount map[string][]fetcher.Folder // accountID -> folders
347	MergedFolders    []fetcher.Folder            // unique folders across all accounts
348}
349
350// SwitchFolderMsg signals switching to a different IMAP folder.
351type SwitchFolderMsg struct {
352	FolderName string
353	AccountID  string
354}
355
356// FolderEmailsFetchedMsg signals that emails from a folder have been fetched.
357type FolderEmailsFetchedMsg struct {
358	Emails     []fetcher.Email
359	AccountID  string
360	FolderName string
361}
362
363// FolderEmailsAppendedMsg signals that more emails from a folder have been fetched (pagination).
364type FolderEmailsAppendedMsg struct {
365	Emails     []fetcher.Email
366	AccountID  string
367	FolderName string
368}
369
370// MoveEmailMsg signals a request to show the move-to-folder picker.
371type MoveEmailMsg struct {
372	UID          uint32
373	AccountID    string
374	SourceFolder string
375}
376
377// MoveEmailToFolderMsg signals that an email should be moved to a folder.
378type MoveEmailToFolderMsg struct {
379	UID          uint32
380	AccountID    string
381	SourceFolder string
382	DestFolder   string
383}
384
385// EmailMovedMsg signals that an email was moved to a folder.
386type EmailMovedMsg struct {
387	UID          uint32
388	AccountID    string
389	SourceFolder string
390	DestFolder   string
391	Err          error
392}
393
394// MarkEmailAsReadMsg signals that an email should be marked as read on the server.
395type MarkEmailAsReadMsg struct {
396	UID        uint32
397	AccountID  string
398	FolderName string
399}
400
401// EmailMarkedReadMsg signals that an email was marked as read.
402type EmailMarkedReadMsg struct {
403	UID       uint32
404	AccountID string
405	Err       error
406}
407
408// FetchFolderMoreEmailsMsg signals a request to fetch more emails from a folder (pagination).
409type FetchFolderMoreEmailsMsg struct {
410	Offset     uint32
411	AccountID  string
412	FolderName string
413	Limit      uint32
414}
415
416// --- External Editor Messages ---
417
418// OpenEditorMsg signals that the composer body should be opened in $EDITOR.
419type OpenEditorMsg struct{}
420
421// EditorFinishedMsg signals that the external editor has closed.
422type EditorFinishedMsg struct {
423	Body string
424	Err  error
425}
426
427// --- IDLE Messages ---
428
429// IdleNewMailMsg signals that IMAP IDLE detected new mail for an account/folder.
430type IdleNewMailMsg struct {
431	AccountID  string
432	FolderName string
433}
434
435// --- Plugin Messages ---
436
437// PluginNotifyMsg signals that a plugin wants to show a notification.
438type PluginNotifyMsg struct {
439	Message  string
440	Duration float64 // Duration in seconds (default 2)
441}