dispatch.go

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