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