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 SetComposerCursorToStartMsg struct{}
101
102type GoToFilePickerMsg struct{}
103
104type FileSelectedMsg struct {
105	Path string
106}
107
108type CancelFilePickerMsg struct{}
109
110type DeleteEmailMsg struct {
111	UID       uint32
112	AccountID string
113	Mailbox   MailboxKind
114}
115
116type ArchiveEmailMsg struct {
117	UID       uint32
118	AccountID string
119	Mailbox   MailboxKind
120}
121
122type EmailActionDoneMsg struct {
123	UID       uint32
124	AccountID string
125	Mailbox   MailboxKind
126	Err       error
127}
128
129type GoToChoiceMenuMsg struct{}
130
131type DownloadAttachmentMsg struct {
132	Index     int
133	Filename  string
134	PartID    string
135	Data      []byte
136	AccountID string
137	Encoding  string
138	Mailbox   MailboxKind
139}
140
141type AttachmentDownloadedMsg struct {
142	Path string
143	Err  error
144}
145
146type RestoreViewMsg struct{}
147
148type BackToInboxMsg struct{}
149
150type BackToMailboxMsg struct {
151	Mailbox MailboxKind
152}
153
154// --- Draft Messages ---
155
156// DiscardDraftMsg signals that a draft should be cached.
157type DiscardDraftMsg struct {
158	ComposerState *Composer
159}
160
161type EmailBodyFetchedMsg struct {
162	UID         uint32
163	Body        string
164	Attachments []fetcher.Attachment
165	Err         error
166	AccountID   string
167	Mailbox     MailboxKind
168}
169
170// --- Multi-Account Messages ---
171
172// GoToAddAccountMsg signals navigation to the add account screen.
173type GoToAddAccountMsg struct{}
174
175// AddAccountMsg signals that a new account should be added.
176type AddAccountMsg struct {
177	Credentials Credentials
178}
179
180// AccountAddedMsg signals that an account was successfully added.
181type AccountAddedMsg struct {
182	AccountID string
183	Err       error
184}
185
186// DeleteAccountMsg signals that an account should be deleted.
187type DeleteAccountMsg struct {
188	AccountID string
189}
190
191// AccountDeletedMsg signals that an account was successfully deleted.
192type AccountDeletedMsg struct {
193	AccountID string
194	Err       error
195}
196
197// SwitchAccountMsg signals switching to view a specific account's inbox.
198type SwitchAccountMsg struct {
199	AccountID string // Empty string means "ALL" accounts
200}
201
202// AllEmailsFetchedMsg signals that emails from all accounts have been fetched.
203type AllEmailsFetchedMsg struct {
204	EmailsByAccount map[string][]fetcher.Email
205	Mailbox         MailboxKind
206}
207
208// SwitchFromAccountMsg signals changing the "From" account in composer.
209type SwitchFromAccountMsg struct {
210	AccountID string
211}
212
213// GoToAccountListMsg signals navigation to the account list in settings.
214type GoToAccountListMsg struct{}
215
216// --- Draft Messages (persisted) ---
217
218// SaveDraftMsg signals that the current draft should be saved to disk.
219type SaveDraftMsg struct {
220	Draft config.Draft
221}
222
223// DraftSavedMsg signals that a draft was saved successfully.
224type DraftSavedMsg struct {
225	DraftID string
226	Err     error
227}
228
229// LoadDraftsMsg signals a request to load all saved drafts.
230type LoadDraftsMsg struct{}
231
232// DraftsLoadedMsg signals that drafts were loaded from disk.
233type DraftsLoadedMsg struct {
234	Drafts []config.Draft
235}
236
237// OpenDraftMsg signals that a specific draft should be opened in the composer.
238type OpenDraftMsg struct {
239	Draft config.Draft
240}
241
242// DeleteDraftMsg signals that a draft should be deleted.
243type DeleteSavedDraftMsg struct {
244	DraftID string
245}
246
247// DraftDeletedMsg signals that a draft was deleted.
248type DraftDeletedMsg struct {
249	DraftID string
250	Err     error
251}
252
253// GoToDraftsMsg signals navigation to the drafts list.
254type GoToDraftsMsg struct{}
255
256// --- Cache Messages ---
257
258// CachedEmailsLoadedMsg signals that cached emails were loaded from disk.
259type CachedEmailsLoadedMsg struct {
260	Cache *config.EmailCache
261}
262
263// RefreshingEmailsMsg signals that a background refresh is in progress.
264type RefreshingEmailsMsg struct {
265	Mailbox MailboxKind
266}
267
268// EmailsRefreshedMsg signals that fresh emails have been fetched in the background.
269type EmailsRefreshedMsg struct {
270	EmailsByAccount map[string][]fetcher.Email
271	Mailbox         MailboxKind
272}
273
274// RequestRefreshMsg signals a request to refresh emails from the server.
275type RequestRefreshMsg struct {
276	Mailbox MailboxKind
277}