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