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