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