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