1package fetcher
2
3import (
4 "github.com/floatpane/matcha/backend"
5 _ "github.com/floatpane/matcha/backend/maildir" // register maildir backend
6 "github.com/floatpane/matcha/config"
7)
8
9// hasBackendProvider reports whether the account is served by a non-IMAP
10// backend (currently only "maildir") and should be routed through the
11// backend.Provider abstraction instead of the legacy IMAP code path.
12func hasBackendProvider(account *config.Account) bool {
13 return account != nil && account.Protocol == "maildir"
14}
15
16// newBackendProvider builds the backend.Provider for the account. Callers
17// must guard with hasBackendProvider before invoking it.
18func newBackendProvider(account *config.Account) (backend.Provider, error) {
19 return backend.New(account)
20}
21
22func backendFoldersToFetcher(in []backend.Folder) []Folder {
23 out := make([]Folder, len(in))
24 for i, f := range in {
25 out[i] = Folder{
26 Name: f.Name,
27 Delimiter: f.Delimiter,
28 Attributes: f.Attributes,
29 Unread: f.Unread,
30 }
31 }
32 return out
33}
34
35func backendEmailsToFetcher(in []backend.Email) []Email {
36 out := make([]Email, len(in))
37 for i, e := range in {
38 out[i] = Email{
39 UID: e.UID,
40 From: e.From,
41 To: e.To,
42 ReplyTo: e.ReplyTo,
43 Subject: e.Subject,
44 Body: e.Body,
45 Date: e.Date,
46 IsRead: e.IsRead,
47 MessageID: e.MessageID,
48 InReplyTo: e.InReplyTo,
49 References: e.References,
50 Attachments: backendAttachmentsToFetcher(e.Attachments),
51 AccountID: e.AccountID,
52 }
53 }
54 return out
55}
56
57func backendAttachmentsToFetcher(in []backend.Attachment) []Attachment {
58 out := make([]Attachment, len(in))
59 for i, a := range in {
60 out[i] = Attachment{
61 Filename: a.Filename,
62 PartID: a.PartID,
63 Data: a.Data,
64 Encoding: a.Encoding,
65 MIMEType: a.MIMEType,
66 ContentID: a.ContentID,
67 Inline: a.Inline,
68 IsSMIMESignature: a.IsSMIMESignature,
69 SMIMEVerified: a.SMIMEVerified,
70 IsSMIMEEncrypted: a.IsSMIMEEncrypted,
71 IsPGPSignature: a.IsPGPSignature,
72 PGPVerified: a.PGPVerified,
73 IsPGPEncrypted: a.IsPGPEncrypted,
74 }
75 }
76 return out
77}