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