/
client_types.go
83 lines (68 loc) · 3.4 KB
/
client_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2021 Proton Technologies AG
//
// This file is part of ProtonMail Bridge.
//
// ProtonMail Bridge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ProtonMail Bridge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
package pmapi
import (
"context"
"io"
"github.com/ProtonMail/gopenpgp/v2/crypto"
"github.com/go-resty/resty/v2"
)
// Client defines the interface of a PMAPI client.
type Client interface {
Auth2FA(context.Context, string) error
AuthSalt(ctx context.Context) (string, error)
AuthDelete(context.Context) error
AddAuthRefreshHandler(AuthRefreshHandler)
CurrentUser(ctx context.Context) (*User, error)
UpdateUser(ctx context.Context) (*User, error)
Unlock(ctx context.Context, passphrase []byte) (err error)
ReloadKeys(ctx context.Context, passphrase []byte) (err error)
IsUnlocked() bool
Addresses() AddressList
GetAddresses(context.Context) (addresses AddressList, err error)
ReorderAddresses(ctx context.Context, addressIDs []string) error
GetEvent(ctx context.Context, eventID string) (*Event, error)
SendMessage(context.Context, string, *SendMessageReq) (sent, parent *Message, err error)
CreateDraft(ctx context.Context, m *Message, parent string, action int) (created *Message, err error)
Import(context.Context, ImportMsgReqs) ([]*ImportMsgRes, error)
CountMessages(ctx context.Context, addressID string) ([]*MessagesCount, error)
ListMessages(ctx context.Context, filter *MessagesFilter) ([]*Message, int, error)
GetMessage(ctx context.Context, apiID string) (*Message, error)
DeleteMessages(ctx context.Context, apiIDs []string) error
LabelMessages(ctx context.Context, apiIDs []string, labelID string) error
UnlabelMessages(ctx context.Context, apiIDs []string, labelID string) error
MarkMessagesRead(ctx context.Context, apiIDs []string) error
MarkMessagesUnread(ctx context.Context, apiIDs []string) error
ListLabels(ctx context.Context) ([]*Label, error)
CreateLabel(ctx context.Context, label *Label) (*Label, error)
UpdateLabel(ctx context.Context, label *Label) (*Label, error)
DeleteLabel(ctx context.Context, labelID string) error
EmptyFolder(ctx context.Context, labelID string, addressID string) error
GetMailSettings(ctx context.Context) (MailSettings, error)
GetContactEmailByEmail(context.Context, string, int, int) ([]ContactEmail, error)
GetContactByID(context.Context, string) (Contact, error)
DecryptAndVerifyCards([]Card) ([]Card, error)
GetAttachment(ctx context.Context, id string) (att io.ReadCloser, err error)
CreateAttachment(ctx context.Context, att *Attachment, r io.Reader, sig io.Reader) (created *Attachment, err error)
KeyRingForAddressID(string) (kr *crypto.KeyRing, err error)
GetPublicKeysForEmail(context.Context, string) ([]PublicKey, bool, error)
}
type AuthRefreshHandler func(*AuthRefresh)
type clientManager interface {
r(context.Context) *resty.Request
authRefresh(context.Context, string, string) (*AuthRefresh, error)
}