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