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}
 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// SaveMailingListMsg signals that a new mailing list should be saved.
188type SaveMailingListMsg struct {
189	Name      string
190	Addresses string
191}
192
193// AddAccountMsg signals that a new account should be added.
194type AddAccountMsg struct {
195	Credentials Credentials
196}
197
198// AccountAddedMsg signals that an account was successfully added.
199type AccountAddedMsg struct {
200	AccountID string
201	Err       error
202}
203
204// DeleteAccountMsg signals that an account should be deleted.
205type DeleteAccountMsg struct {
206	AccountID string
207}
208
209// AccountDeletedMsg signals that an account was successfully deleted.
210type AccountDeletedMsg struct {
211	AccountID string
212	Err       error
213}
214
215// SwitchAccountMsg signals switching to view a specific account's inbox.
216type SwitchAccountMsg struct {
217	AccountID string // Empty string means "ALL" accounts
218}
219
220// AllEmailsFetchedMsg signals that emails from all accounts have been fetched.
221type AllEmailsFetchedMsg struct {
222	EmailsByAccount map[string][]fetcher.Email
223	Mailbox         MailboxKind
224}
225
226// SwitchFromAccountMsg signals changing the "From" account in composer.
227type SwitchFromAccountMsg struct {
228	AccountID string
229}
230
231// GoToAccountListMsg signals navigation to the account list in settings.
232type GoToAccountListMsg struct{}
233
234// --- Draft Messages (persisted) ---
235
236// SaveDraftMsg signals that the current draft should be saved to disk.
237type SaveDraftMsg struct {
238	Draft config.Draft
239}
240
241// DraftSavedMsg signals that a draft was saved successfully.
242type DraftSavedMsg struct {
243	DraftID string
244	Err     error
245}
246
247// LoadDraftsMsg signals a request to load all saved drafts.
248type LoadDraftsMsg struct{}
249
250// DraftsLoadedMsg signals that drafts were loaded from disk.
251type DraftsLoadedMsg struct {
252	Drafts []config.Draft
253}
254
255// OpenDraftMsg signals that a specific draft should be opened in the composer.
256type OpenDraftMsg struct {
257	Draft config.Draft
258}
259
260// DeleteDraftMsg signals that a draft should be deleted.
261type DeleteSavedDraftMsg struct {
262	DraftID string
263}
264
265// DraftDeletedMsg signals that a draft was deleted.
266type DraftDeletedMsg struct {
267	DraftID string
268	Err     error
269}
270
271// GoToDraftsMsg signals navigation to the drafts list.
272type GoToDraftsMsg struct{}
273
274// --- Cache Messages ---
275
276// CachedEmailsLoadedMsg signals that cached emails were loaded from disk.
277type CachedEmailsLoadedMsg struct {
278	Cache *config.EmailCache
279}
280
281// RefreshingEmailsMsg signals that a background refresh is in progress.
282type RefreshingEmailsMsg struct {
283	Mailbox MailboxKind
284}
285
286// EmailsRefreshedMsg signals that fresh emails have been fetched in the background.
287type EmailsRefreshedMsg struct {
288	EmailsByAccount map[string][]fetcher.Email
289	Mailbox         MailboxKind
290}
291
292// RequestRefreshMsg signals a request to refresh emails from the server.
293type RequestRefreshMsg struct {
294	Mailbox    MailboxKind
295	Counts     map[string]int
296	FolderName string
297}
298
299// --- Folder Messages ---
300
301// FoldersFetchedMsg signals that IMAP folders have been fetched for all accounts.
302type FoldersFetchedMsg struct {
303	FoldersByAccount map[string][]fetcher.Folder // accountID -> folders
304	MergedFolders    []fetcher.Folder            // unique folders across all accounts
305}
306
307// SwitchFolderMsg signals switching to a different IMAP folder.
308type SwitchFolderMsg struct {
309	FolderName string
310	AccountID  string
311}
312
313// FolderEmailsFetchedMsg signals that emails from a folder have been fetched.
314type FolderEmailsFetchedMsg struct {
315	Emails     []fetcher.Email
316	AccountID  string
317	FolderName string
318}
319
320// FolderEmailsAppendedMsg signals that more emails from a folder have been fetched (pagination).
321type FolderEmailsAppendedMsg struct {
322	Emails     []fetcher.Email
323	AccountID  string
324	FolderName string
325}
326
327// MoveEmailMsg signals a request to show the move-to-folder picker.
328type MoveEmailMsg struct {
329	UID          uint32
330	AccountID    string
331	SourceFolder string
332}
333
334// MoveEmailToFolderMsg signals that an email should be moved to a folder.
335type MoveEmailToFolderMsg struct {
336	UID          uint32
337	AccountID    string
338	SourceFolder string
339	DestFolder   string
340}
341
342// EmailMovedMsg signals that an email was moved to a folder.
343type EmailMovedMsg struct {
344	UID          uint32
345	AccountID    string
346	SourceFolder string
347	DestFolder   string
348	Err          error
349}
350
351// FetchFolderMoreEmailsMsg signals a request to fetch more emails from a folder (pagination).
352type FetchFolderMoreEmailsMsg struct {
353	Offset     uint32
354	AccountID  string
355	FolderName string
356	Limit      uint32
357}