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	AttachmentPath 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}
 37
 38type Credentials struct {
 39	Provider   string
 40	Name       string
 41	Host       string // Host (this was the previous \"Email Address\" field in the UI)
 42	FetchEmail string // Single email address to fetch messages for. If empty, code should default this to Host when creating the account.
 43	Password   string
 44	IMAPServer string
 45	IMAPPort   int
 46	SMTPServer string
 47	SMTPPort   int
 48}
 49
 50type ChooseServiceMsg struct {
 51	Service string
 52}
 53
 54type EmailResultMsg struct {
 55	Err error
 56}
 57
 58type ClearStatusMsg struct{}
 59
 60type EmailsFetchedMsg struct {
 61	Emails    []fetcher.Email
 62	AccountID string
 63	Mailbox   MailboxKind
 64}
 65
 66type FetchErr error
 67
 68type GoToInboxMsg struct{}
 69
 70type GoToSentInboxMsg struct{}
 71
 72type GoToSendMsg struct {
 73	To      string
 74	Subject string
 75	Body    string
 76}
 77
 78type GoToSettingsMsg struct{}
 79
 80type GoToTrashArchiveMsg struct{}
 81
 82type GoToSignatureEditorMsg struct{}
 83
 84type FetchMoreEmailsMsg struct {
 85	Offset    uint32
 86	AccountID string
 87	Mailbox   MailboxKind
 88}
 89
 90type FetchingMoreEmailsMsg struct{}
 91
 92type EmailsAppendedMsg struct {
 93	Emails    []fetcher.Email
 94	AccountID string
 95	Mailbox   MailboxKind
 96}
 97
 98type ReplyToEmailMsg struct {
 99	Email fetcher.Email
100}
101
102type ForwardEmailMsg struct {
103	Email fetcher.Email
104}
105
106type SetComposerCursorToStartMsg struct{}
107
108type GoToFilePickerMsg struct{}
109
110type FileSelectedMsg struct {
111	Path string
112}
113
114type CancelFilePickerMsg struct{}
115
116type DeleteEmailMsg struct {
117	UID       uint32
118	AccountID string
119	Mailbox   MailboxKind
120}
121
122type ArchiveEmailMsg struct {
123	UID       uint32
124	AccountID string
125	Mailbox   MailboxKind
126}
127
128type EmailActionDoneMsg struct {
129	UID       uint32
130	AccountID string
131	Mailbox   MailboxKind
132	Err       error
133}
134
135type GoToChoiceMenuMsg struct{}
136
137type DownloadAttachmentMsg struct {
138	Index     int
139	Filename  string
140	PartID    string
141	Data      []byte
142	AccountID string
143	Encoding  string
144	Mailbox   MailboxKind
145}
146
147type AttachmentDownloadedMsg struct {
148	Path string
149	Err  error
150}
151
152type RestoreViewMsg struct{}
153
154type BackToInboxMsg struct{}
155
156type BackToMailboxMsg struct {
157	Mailbox MailboxKind
158}
159
160// --- Draft Messages ---
161
162// DiscardDraftMsg signals that a draft should be cached.
163type DiscardDraftMsg struct {
164	ComposerState *Composer
165}
166
167type EmailBodyFetchedMsg struct {
168	UID         uint32
169	Body        string
170	Attachments []fetcher.Attachment
171	Err         error
172	AccountID   string
173	Mailbox     MailboxKind
174}
175
176// --- Multi-Account Messages ---
177
178// GoToAddAccountMsg signals navigation to the add account screen.
179type GoToAddAccountMsg struct{}
180
181// AddAccountMsg signals that a new account should be added.
182type AddAccountMsg struct {
183	Credentials Credentials
184}
185
186// AccountAddedMsg signals that an account was successfully added.
187type AccountAddedMsg struct {
188	AccountID string
189	Err       error
190}
191
192// DeleteAccountMsg signals that an account should be deleted.
193type DeleteAccountMsg struct {
194	AccountID string
195}
196
197// AccountDeletedMsg signals that an account was successfully deleted.
198type AccountDeletedMsg struct {
199	AccountID string
200	Err       error
201}
202
203// SwitchAccountMsg signals switching to view a specific account's inbox.
204type SwitchAccountMsg struct {
205	AccountID string // Empty string means "ALL" accounts
206}
207
208// AllEmailsFetchedMsg signals that emails from all accounts have been fetched.
209type AllEmailsFetchedMsg struct {
210	EmailsByAccount map[string][]fetcher.Email
211	Mailbox         MailboxKind
212}
213
214// SwitchFromAccountMsg signals changing the "From" account in composer.
215type SwitchFromAccountMsg struct {
216	AccountID string
217}
218
219// GoToAccountListMsg signals navigation to the account list in settings.
220type GoToAccountListMsg struct{}
221
222// --- Draft Messages (persisted) ---
223
224// SaveDraftMsg signals that the current draft should be saved to disk.
225type SaveDraftMsg struct {
226	Draft config.Draft
227}
228
229// DraftSavedMsg signals that a draft was saved successfully.
230type DraftSavedMsg struct {
231	DraftID string
232	Err     error
233}
234
235// LoadDraftsMsg signals a request to load all saved drafts.
236type LoadDraftsMsg struct{}
237
238// DraftsLoadedMsg signals that drafts were loaded from disk.
239type DraftsLoadedMsg struct {
240	Drafts []config.Draft
241}
242
243// OpenDraftMsg signals that a specific draft should be opened in the composer.
244type OpenDraftMsg struct {
245	Draft config.Draft
246}
247
248// DeleteDraftMsg signals that a draft should be deleted.
249type DeleteSavedDraftMsg struct {
250	DraftID string
251}
252
253// DraftDeletedMsg signals that a draft was deleted.
254type DraftDeletedMsg struct {
255	DraftID string
256	Err     error
257}
258
259// GoToDraftsMsg signals navigation to the drafts list.
260type GoToDraftsMsg struct{}
261
262// --- Cache Messages ---
263
264// CachedEmailsLoadedMsg signals that cached emails were loaded from disk.
265type CachedEmailsLoadedMsg struct {
266	Cache *config.EmailCache
267}
268
269// RefreshingEmailsMsg signals that a background refresh is in progress.
270type RefreshingEmailsMsg struct {
271	Mailbox MailboxKind
272}
273
274// EmailsRefreshedMsg signals that fresh emails have been fetched in the background.
275type EmailsRefreshedMsg struct {
276	EmailsByAccount map[string][]fetcher.Email
277	Mailbox         MailboxKind
278}
279
280// RequestRefreshMsg signals a request to refresh emails from the server.
281type RequestRefreshMsg struct {
282	Mailbox MailboxKind
283}