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