protocol.go

  1package daemonrpc
  2
  3import udsrpc "github.com/floatpane/go-uds-jsonrpc"
  4
  5// Wire-level message types and the discriminating decoder live in the shared
  6// go-uds-jsonrpc library. They are aliased here so matcha code keeps using the
  7// daemonrpc.* names while sharing a single implementation with the daemon's
  8// transport layer.
  9type (
 10	Request  = udsrpc.Request
 11	Response = udsrpc.Response
 12	Event    = udsrpc.Event
 13	Error    = udsrpc.Error
 14	Message  = udsrpc.Message
 15)
 16
 17// DecodeMessage discriminates a raw JSON object into a Request, Response, or
 18// Event.
 19var DecodeMessage = udsrpc.DecodeMessage
 20
 21// Standard error codes, re-exported from the shared library.
 22const (
 23	ErrCodeParse         = udsrpc.ErrCodeParse
 24	ErrCodeInvalidReq    = udsrpc.ErrCodeInvalidReq
 25	ErrCodeInvalidParams = udsrpc.ErrCodeInvalidParams
 26	ErrCodeNotFound      = udsrpc.ErrCodeNotFound
 27	ErrCodeInternal      = udsrpc.ErrCodeInternal
 28)
 29
 30// RPC method names.
 31const (
 32	MethodPing            = "Ping"
 33	MethodGetStatus       = "GetStatus"
 34	MethodGetAccounts     = "GetAccounts"
 35	MethodReloadConfig    = "ReloadConfig"
 36	MethodFetchEmails     = "FetchEmails"
 37	MethodFetchEmailBody  = "FetchEmailBody"
 38	MethodSendEmail       = "SendEmail"
 39	MethodDeleteEmails    = "DeleteEmails"
 40	MethodArchiveEmails   = "ArchiveEmails"
 41	MethodMoveEmails      = "MoveEmails"
 42	MethodMarkRead        = "MarkRead"
 43	MethodFetchFolders    = "FetchFolders"
 44	MethodRefreshFolder   = "RefreshFolder"
 45	MethodSubscribe       = "Subscribe"
 46	MethodUnsubscribe     = "Unsubscribe"
 47	MethodSendRSVP        = "SendRSVP"
 48	MethodGetCachedEmails = "GetCachedEmails"
 49	MethodGetCachedBody   = "GetCachedBody"
 50	MethodExportContacts  = "ExportContacts"
 51)
 52
 53// Event type names.
 54const (
 55	EventNewMail        = "NewMail"
 56	EventSyncStarted    = "SyncStarted"
 57	EventSyncComplete   = "SyncComplete"
 58	EventSyncError      = "SyncError"
 59	EventEmailsUpdated  = "EmailsUpdated"
 60	EventConfigReloaded = "ConfigReloaded"
 61)
 62
 63// Param/result types for RPC methods.
 64
 65type PingResult struct {
 66	Pong bool `json:"pong"`
 67}
 68
 69type StatusResult struct {
 70	Running  bool     `json:"running"`
 71	Uptime   int64    `json:"uptime_seconds"`
 72	Accounts []string `json:"accounts"`
 73	PID      int      `json:"pid"`
 74}
 75
 76type AccountInfo struct {
 77	ID       string `json:"id"`
 78	Name     string `json:"name"`
 79	Email    string `json:"email"`
 80	Protocol string `json:"protocol"`
 81}
 82
 83type FetchEmailsParams struct {
 84	AccountID string `json:"account_id"`
 85	Folder    string `json:"folder"`
 86	Limit     uint32 `json:"limit"`
 87	Offset    uint32 `json:"offset"`
 88}
 89
 90type FetchEmailBodyParams struct {
 91	AccountID string `json:"account_id"`
 92	Folder    string `json:"folder"`
 93	UID       uint32 `json:"uid"`
 94}
 95
 96type FetchEmailBodyResult struct {
 97	Body         string           `json:"body"`
 98	BodyMIMEType string           `json:"body_mime_type,omitempty"`
 99	Attachments  []AttachmentInfo `json:"attachments"`
100}
101
102type AttachmentInfo struct {
103	Filename         string `json:"filename"`
104	PartID           string `json:"part_id"`
105	Encoding         string `json:"encoding"`
106	MIMEType         string `json:"mime_type"`
107	IsCalendarInvite bool   `json:"is_calendar_invite,omitempty"`
108	CalendarData     []byte `json:"calendar_data,omitempty"`
109}
110
111type SendEmailParams struct {
112	AccountID    string            `json:"account_id"`
113	To           []string          `json:"to"`
114	Cc           []string          `json:"cc,omitempty"`
115	Bcc          []string          `json:"bcc,omitempty"`
116	Subject      string            `json:"subject"`
117	Body         string            `json:"body"`
118	HTMLBody     string            `json:"html_body,omitempty"`
119	Attachments  map[string][]byte `json:"attachments,omitempty"`
120	InReplyTo    string            `json:"in_reply_to,omitempty"`
121	References   []string          `json:"references,omitempty"`
122	SignSMIME    bool              `json:"sign_smime,omitempty"`
123	EncryptSMIME bool              `json:"encrypt_smime,omitempty"`
124	SignPGP      bool              `json:"sign_pgp,omitempty"`
125	EncryptPGP   bool              `json:"encrypt_pgp,omitempty"`
126}
127
128type DeleteEmailsParams struct {
129	AccountID string   `json:"account_id"`
130	Folder    string   `json:"folder"`
131	UIDs      []uint32 `json:"uids"`
132}
133
134type ArchiveEmailsParams struct {
135	AccountID string   `json:"account_id"`
136	Folder    string   `json:"folder"`
137	UIDs      []uint32 `json:"uids"`
138}
139
140type MoveEmailsParams struct {
141	AccountID    string   `json:"account_id"`
142	UIDs         []uint32 `json:"uids"`
143	SourceFolder string   `json:"source_folder"`
144	DestFolder   string   `json:"dest_folder"`
145}
146
147type MarkReadParams struct {
148	AccountID string   `json:"account_id"`
149	Folder    string   `json:"folder"`
150	UIDs      []uint32 `json:"uids"`
151	Read      bool     `json:"read"`
152}
153
154type FetchFoldersParams struct {
155	AccountID string `json:"account_id"`
156}
157
158type RefreshFolderParams struct {
159	AccountID string `json:"account_id"`
160	Folder    string `json:"folder"`
161}
162
163type SubscribeParams struct {
164	AccountID string `json:"account_id"`
165	Folder    string `json:"folder"`
166}
167
168type UnsubscribeParams struct {
169	AccountID string `json:"account_id"`
170	Folder    string `json:"folder"`
171}
172
173type SendRSVPParams struct {
174	AccountID   string   `json:"account_id"`
175	OriginalICS []byte   `json:"original_ics"`
176	Response    string   `json:"response"`
177	InReplyTo   string   `json:"in_reply_to,omitempty"`
178	References  []string `json:"references,omitempty"`
179}
180
181type GetCachedEmailsParams struct {
182	Folder string `json:"folder"`
183}
184
185type GetCachedBodyParams struct {
186	Folder    string `json:"folder"`
187	UID       uint32 `json:"uid"`
188	AccountID string `json:"account_id"`
189}
190
191type ExportContactsParams struct {
192	Format string `json:"format"` // "json" or "csv"
193}
194
195// Event data types.
196
197type NewMailEvent struct {
198	AccountID string `json:"account_id"`
199	Folder    string `json:"folder"`
200}
201
202type SyncStartedEvent struct {
203	AccountID string `json:"account_id"`
204	Folder    string `json:"folder"`
205}
206
207type SyncCompleteEvent struct {
208	AccountID  string `json:"account_id"`
209	Folder     string `json:"folder"`
210	EmailCount int    `json:"email_count"`
211}
212
213type SyncErrorEvent struct {
214	AccountID string `json:"account_id"`
215	Folder    string `json:"folder"`
216	Error     string `json:"error"`
217}