forked from Silverfish/proton-bridge
GODT-1686: Add Label/Folder filtering to pmapi
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,6 +5,7 @@
|
|||||||
# Editor files
|
# Editor files
|
||||||
.*.sw?
|
.*.sw?
|
||||||
*~
|
*~
|
||||||
|
.idea
|
||||||
|
|
||||||
# Test files
|
# Test files
|
||||||
godog.test
|
godog.test
|
||||||
@ -29,3 +30,4 @@ vendor-cache
|
|||||||
/hasher
|
/hasher
|
||||||
cmd/Desktop-Bridge/deploy
|
cmd/Desktop-Bridge/deploy
|
||||||
cmd/Import-Export/deploy
|
cmd/Import-Export/deploy
|
||||||
|
proton-bridge
|
||||||
|
|||||||
@ -128,7 +128,7 @@ func (mc *mailboxCounts) getPMLabel() *pmapi.Label {
|
|||||||
Path: mc.LabelName,
|
Path: mc.LabelName,
|
||||||
Color: mc.Color,
|
Color: mc.Color,
|
||||||
Order: mc.Order,
|
Order: mc.Order,
|
||||||
Type: pmapi.LabelTypeMailbox,
|
Type: pmapi.LabelTypeMailBox,
|
||||||
Exclusive: pmapi.Boolean(mc.IsFolder),
|
Exclusive: pmapi.Boolean(mc.IsFolder),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,7 +59,7 @@ func (store *Store) createMailbox(name string) error {
|
|||||||
Name: name,
|
Name: name,
|
||||||
Color: color,
|
Color: color,
|
||||||
Exclusive: pmapi.Boolean(exclusive),
|
Exclusive: pmapi.Boolean(exclusive),
|
||||||
Type: pmapi.LabelTypeMailbox,
|
Type: pmapi.LabelTypeMailBox,
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ func (store *Store) createOrUpdateMailboxEvent(label *pmapi.Label) error {
|
|||||||
store.lock.Lock()
|
store.lock.Lock()
|
||||||
defer store.lock.Unlock()
|
defer store.lock.Unlock()
|
||||||
|
|
||||||
if label.Type != pmapi.LabelTypeMailbox {
|
if label.Type != pmapi.LabelTypeMailBox {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -64,6 +64,13 @@ type Client interface {
|
|||||||
DeleteLabel(ctx context.Context, labelID string) error
|
DeleteLabel(ctx context.Context, labelID string) error
|
||||||
EmptyFolder(ctx context.Context, labelID string, addressID string) error
|
EmptyFolder(ctx context.Context, labelID string, addressID string) error
|
||||||
|
|
||||||
|
// /core/V4/labels routes
|
||||||
|
ListLabelsOnly(ctx context.Context) ([]*Label, error)
|
||||||
|
ListFoldersOnly(ctx context.Context) ([]*Label, error)
|
||||||
|
CreateLabelV4(ctx context.Context, label *Label) (*Label, error)
|
||||||
|
UpdateLabelV4(ctx context.Context, label *Label) (*Label, error)
|
||||||
|
DeleteLabelV4(ctx context.Context, labelID string) error
|
||||||
|
|
||||||
GetMailSettings(ctx context.Context) (MailSettings, error)
|
GetMailSettings(ctx context.Context) (MailSettings, error)
|
||||||
GetContactEmailByEmail(context.Context, string, int, int) ([]ContactEmail, error)
|
GetContactEmailByEmail(context.Context, string, int, int) ([]ContactEmail, error)
|
||||||
GetContactByID(context.Context, string) (Contact, error)
|
GetContactByID(context.Context, string) (Contact, error)
|
||||||
|
|||||||
@ -38,7 +38,7 @@ const (
|
|||||||
DraftLabel = "8"
|
DraftLabel = "8"
|
||||||
StarredLabel = "10"
|
StarredLabel = "10"
|
||||||
|
|
||||||
LabelTypeMailbox = 1
|
LabelTypeMailBox = 1
|
||||||
LabelTypeContactGroup = 2
|
LabelTypeContactGroup = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ type Label struct { //nolint:maligned
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) ListLabels(ctx context.Context) (labels []*Label, err error) {
|
func (c *client) ListLabels(ctx context.Context) (labels []*Label, err error) {
|
||||||
return c.listLabelType(ctx, LabelTypeMailbox)
|
return c.listLabelType(ctx, LabelTypeMailBox)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) ListContactGroups(ctx context.Context) (labels []*Label, err error) {
|
func (c *client) ListContactGroups(ctx context.Context) (labels []*Label, err error) {
|
||||||
|
|||||||
@ -53,8 +53,8 @@ const testLabelsBody = `{
|
|||||||
`
|
`
|
||||||
|
|
||||||
var testLabels = []*Label{
|
var testLabels = []*Label{
|
||||||
{ID: "LLz8ysmVxwr4dF6mWpClePT0SpSWOEvzTdq17RydSl4ndMckvY1K63HeXDzn03BJQwKYvgf-eWT8Qfd9WVuIEQ==", Name: "CroutonMail is awesome :)", Color: "#7272a7", Order: 1, Display: 0, Type: LabelTypeMailbox},
|
{ID: "LLz8ysmVxwr4dF6mWpClePT0SpSWOEvzTdq17RydSl4ndMckvY1K63HeXDzn03BJQwKYvgf-eWT8Qfd9WVuIEQ==", Name: "CroutonMail is awesome :)", Color: "#7272a7", Order: 1, Display: 0, Type: LabelTypeMailBox},
|
||||||
{ID: "BvbqbySUPo9uWW_eR8tLA13NUsQMz3P4Zhw4UnpvrKqURnrHlE6L2Au0nplHfHlVXFgGz4L4hJ9-BYllOL-L5g==", Name: "Royal sausage", Color: "#cf5858", Order: 2, Display: 1, Type: LabelTypeMailbox},
|
{ID: "BvbqbySUPo9uWW_eR8tLA13NUsQMz3P4Zhw4UnpvrKqURnrHlE6L2Au0nplHfHlVXFgGz4L4hJ9-BYllOL-L5g==", Name: "Royal sausage", Color: "#cf5858", Order: 2, Display: 1, Type: LabelTypeMailBox},
|
||||||
}
|
}
|
||||||
|
|
||||||
var testLabelReq = LabelReq{&Label{
|
var testLabelReq = LabelReq{&Label{
|
||||||
@ -82,7 +82,7 @@ var testLabelCreated = &Label{
|
|||||||
Color: "#c26cc7",
|
Color: "#c26cc7",
|
||||||
Order: 3,
|
Order: 3,
|
||||||
Display: 1,
|
Display: 1,
|
||||||
Type: LabelTypeMailbox,
|
Type: LabelTypeMailBox,
|
||||||
}
|
}
|
||||||
|
|
||||||
const testDeleteLabelBody = `{
|
const testDeleteLabelBody = `{
|
||||||
|
|||||||
110
pkg/pmapi/labels_v4.go
Normal file
110
pkg/pmapi/labels_v4.go
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
// Copyright (c) 2022 Proton AG
|
||||||
|
//
|
||||||
|
// This file is part of Proton Mail Bridge.
|
||||||
|
//
|
||||||
|
// Proton Mail 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.
|
||||||
|
//
|
||||||
|
// Proton Mail 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 Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package pmapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LabelTypeV4 int
|
||||||
|
|
||||||
|
const (
|
||||||
|
LabelTypeV4Label = 1
|
||||||
|
LabelTypeV4ContactGroup = 2
|
||||||
|
LabelTypeV4Folder = 3
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *client) ListLabelsOnly(ctx context.Context) (labels []*Label, err error) {
|
||||||
|
return c.listLabelTypeV4(ctx, LabelTypeV4Label)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *client) ListFoldersOnly(ctx context.Context) (labels []*Label, err error) {
|
||||||
|
return c.listLabelTypeV4(ctx, LabelTypeV4Folder)
|
||||||
|
}
|
||||||
|
|
||||||
|
// listLabelType lists all labels created by the user.
|
||||||
|
func (c *client) listLabelTypeV4(ctx context.Context, labelType LabelTypeV4) (labels []*Label, err error) {
|
||||||
|
var res struct {
|
||||||
|
Labels []*Label
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
|
||||||
|
return r.SetQueryParam("Type", strconv.Itoa(int(labelType))).SetResult(&res).Get("/core/v4/labels")
|
||||||
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.Labels, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateLabel creates a new label.
|
||||||
|
func (c *client) CreateLabelV4(ctx context.Context, label *Label) (created *Label, err error) {
|
||||||
|
if label.Name == "" {
|
||||||
|
return nil, errors.New("name is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res struct {
|
||||||
|
Label *Label
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
|
||||||
|
return r.SetBody(&LabelReq{
|
||||||
|
Label: label,
|
||||||
|
}).SetResult(&res).Post("/core/v4/labels")
|
||||||
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.Label, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateLabel updates a label.
|
||||||
|
func (c *client) UpdateLabelV4(ctx context.Context, label *Label) (updated *Label, err error) {
|
||||||
|
if label.Name == "" {
|
||||||
|
return nil, errors.New("name is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res struct {
|
||||||
|
Label *Label
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
|
||||||
|
return r.SetBody(&LabelReq{
|
||||||
|
Label: label,
|
||||||
|
}).SetResult(&res).Put("/core/v4/labels/" + label.ID)
|
||||||
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.Label, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteLabel deletes a label.
|
||||||
|
func (c *client) DeleteLabelV4(ctx context.Context, labelID string) error {
|
||||||
|
if _, err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
|
||||||
|
return r.Delete("/core/v4/labels/" + labelID)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
170
pkg/pmapi/labels_v4_test.go
Normal file
170
pkg/pmapi/labels_v4_test.go
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
// Copyright (c) 2022 Proton AG
|
||||||
|
//
|
||||||
|
// This file is part of Proton Mail Bridge.
|
||||||
|
//
|
||||||
|
// Proton Mail 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.
|
||||||
|
//
|
||||||
|
// Proton Mail 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 Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package pmapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
r "github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
const testFoldersBody = `{
|
||||||
|
"Labels": [
|
||||||
|
{
|
||||||
|
"ID": "LLz8ysmVxwr4dF6mWpClePT0SpSWOEvzTdq17RydSl4ndMckvY1K63HeXDzn03BJQwKYvgf-eWT8Qfd9WVuIEQ==",
|
||||||
|
"Name": "CroutonMail is awesome :)",
|
||||||
|
"Color": "#7272a7",
|
||||||
|
"Display": 0,
|
||||||
|
"Order": 1,
|
||||||
|
"Type": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ID": "BvbqbySUPo9uWW_eR8tLA13NUsQMz3P4Zhw4UnpvrKqURnrHlE6L2Au0nplHfHlVXFgGz4L4hJ9-BYllOL-L5g==",
|
||||||
|
"Name": "Royal sausage",
|
||||||
|
"Color": "#cf5858",
|
||||||
|
"Display": 1,
|
||||||
|
"Order": 2,
|
||||||
|
"Type": 3
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Code": 1000
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
var testFolders = []*Label{
|
||||||
|
{ID: "LLz8ysmVxwr4dF6mWpClePT0SpSWOEvzTdq17RydSl4ndMckvY1K63HeXDzn03BJQwKYvgf-eWT8Qfd9WVuIEQ==", Name: "CroutonMail is awesome :)", Color: "#7272a7", Order: 1, Display: 0, Type: LabelTypeV4Folder},
|
||||||
|
{ID: "BvbqbySUPo9uWW_eR8tLA13NUsQMz3P4Zhw4UnpvrKqURnrHlE6L2Au0nplHfHlVXFgGz4L4hJ9-BYllOL-L5g==", Name: "Royal sausage", Color: "#cf5858", Order: 2, Display: 1, Type: LabelTypeV4Folder},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_ListLabelsOnly(t *testing.T) {
|
||||||
|
s, c := newTestClient(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
r.NoError(t, checkMethodAndPath(req, "GET", "/core/v4/labels?Type=1"))
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
fmt.Fprint(w, testLabelsBody)
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
labels, err := c.ListLabelsOnly(context.Background())
|
||||||
|
r.NoError(t, err)
|
||||||
|
r.Equal(t, testLabels, labels)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_ListFoldersOnly(t *testing.T) {
|
||||||
|
s, c := newTestClient(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
r.NoError(t, checkMethodAndPath(req, "GET", "/core/v4/labels?Type=3"))
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
fmt.Fprint(w, testFoldersBody)
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
folders, err := c.ListFoldersOnly(context.Background())
|
||||||
|
r.NoError(t, err)
|
||||||
|
r.Equal(t, testFolders, folders)
|
||||||
|
}
|
||||||
|
func TestClient_CreateLabelV4(t *testing.T) {
|
||||||
|
s, c := newTestClient(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
r.NoError(t, checkMethodAndPath(req, "POST", "/core/v4/labels"))
|
||||||
|
|
||||||
|
body := &bytes.Buffer{}
|
||||||
|
_, err := body.ReadFrom(req.Body)
|
||||||
|
r.NoError(t, err)
|
||||||
|
|
||||||
|
if bytes.Contains(body.Bytes(), []byte("Order")) {
|
||||||
|
t.Fatal("Body contains `Order`: ", body.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
var labelReq LabelReq
|
||||||
|
err = json.NewDecoder(body).Decode(&labelReq)
|
||||||
|
r.NoError(t, err)
|
||||||
|
r.Equal(t, testLabelReq.Label, labelReq.Label)
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
fmt.Fprint(w, testCreateLabelBody)
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
created, err := c.CreateLabelV4(context.Background(), testLabelReq.Label)
|
||||||
|
r.NoError(t, err)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(created, testLabelCreated) {
|
||||||
|
t.Fatalf("Invalid created label: expected %+v, got %+v", testLabelCreated, created)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_CreateEmptyLabelV4(t *testing.T) {
|
||||||
|
s, c := newTestClient(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
|
||||||
|
r.Fail(t, "API should not be called")
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
_, err := c.CreateLabelV4(context.Background(), &Label{})
|
||||||
|
r.EqualError(t, err, "name is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_UpdateLabelV4(t *testing.T) {
|
||||||
|
s, c := newTestClient(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
r.NoError(t, checkMethodAndPath(req, "PUT", "/core/v4/labels/"+testLabelCreated.ID))
|
||||||
|
|
||||||
|
var labelReq LabelReq
|
||||||
|
err := json.NewDecoder(req.Body).Decode(&labelReq)
|
||||||
|
r.NoError(t, err)
|
||||||
|
r.Equal(t, testLabelCreated, labelReq.Label)
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
fmt.Fprint(w, testCreateLabelBody)
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
updated, err := c.UpdateLabelV4(context.Background(), testLabelCreated)
|
||||||
|
r.NoError(t, err)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(updated, testLabelCreated) {
|
||||||
|
t.Fatalf("Invalid updated label: expected %+v, got %+v", testLabelCreated, updated)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_UpdateLabelToEmptyNameV4(t *testing.T) {
|
||||||
|
s, c := newTestClient(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
|
||||||
|
r.Fail(t, "API should not be called")
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
_, err := c.UpdateLabelV4(context.Background(), &Label{ID: "label"})
|
||||||
|
r.EqualError(t, err, "name is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_DeleteLabelV4(t *testing.T) {
|
||||||
|
s, c := newTestClient(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
r.NoError(t, checkMethodAndPath(req, "DELETE", "/core/v4/labels/"+testLabelCreated.ID))
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
fmt.Fprint(w, testDeleteLabelBody)
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
err := c.DeleteLabelV4(context.Background(), testLabelCreated.ID)
|
||||||
|
r.NoError(t, err)
|
||||||
|
}
|
||||||
@ -169,6 +169,21 @@ func (mr *MockClientMockRecorder) CreateLabel(arg0, arg1 interface{}) *gomock.Ca
|
|||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateLabel", reflect.TypeOf((*MockClient)(nil).CreateLabel), arg0, arg1)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateLabel", reflect.TypeOf((*MockClient)(nil).CreateLabel), arg0, arg1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateLabelV4 mocks base method.
|
||||||
|
func (m *MockClient) CreateLabelV4(arg0 context.Context, arg1 *pmapi.Label) (*pmapi.Label, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "CreateLabelV4", arg0, arg1)
|
||||||
|
ret0, _ := ret[0].(*pmapi.Label)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateLabelV4 indicates an expected call of CreateLabelV4.
|
||||||
|
func (mr *MockClientMockRecorder) CreateLabelV4(arg0, arg1 interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateLabelV4", reflect.TypeOf((*MockClient)(nil).CreateLabelV4), arg0, arg1)
|
||||||
|
}
|
||||||
|
|
||||||
// CurrentUser mocks base method.
|
// CurrentUser mocks base method.
|
||||||
func (m *MockClient) CurrentUser(arg0 context.Context) (*pmapi.User, error) {
|
func (m *MockClient) CurrentUser(arg0 context.Context) (*pmapi.User, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
@ -213,6 +228,21 @@ func (mr *MockClientMockRecorder) DeleteLabel(arg0, arg1 interface{}) *gomock.Ca
|
|||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteLabel", reflect.TypeOf((*MockClient)(nil).DeleteLabel), arg0, arg1)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteLabel", reflect.TypeOf((*MockClient)(nil).DeleteLabel), arg0, arg1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteLabelV4 mocks base method.
|
||||||
|
func (m *MockClient) DeleteLabelV4(arg0 context.Context, arg1 string) error {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "DeleteLabelV4", arg0, arg1)
|
||||||
|
ret0, _ := ret[0].(error)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteLabelV4 indicates an expected call of DeleteLabelV4.
|
||||||
|
func (mr *MockClientMockRecorder) DeleteLabelV4(arg0, arg1 interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteLabelV4", reflect.TypeOf((*MockClient)(nil).DeleteLabelV4), arg0, arg1)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// DeleteMessages mocks base method.
|
// DeleteMessages mocks base method.
|
||||||
func (m *MockClient) DeleteMessages(arg0 context.Context, arg1 []string) error {
|
func (m *MockClient) DeleteMessages(arg0 context.Context, arg1 []string) error {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
@ -465,6 +495,36 @@ func (mr *MockClientMockRecorder) ListLabels(arg0 interface{}) *gomock.Call {
|
|||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListLabels", reflect.TypeOf((*MockClient)(nil).ListLabels), arg0)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListLabels", reflect.TypeOf((*MockClient)(nil).ListLabels), arg0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListLabelsOnly mocks base method.
|
||||||
|
func (m *MockClient) ListLabelsOnly(arg0 context.Context) ([]*pmapi.Label, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "ListLabelsOnly", arg0)
|
||||||
|
ret0, _ := ret[0].([]*pmapi.Label)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListLabelsOnly indicates an expected call of ListLabelsOnly.
|
||||||
|
func (mr *MockClientMockRecorder) ListLabelsOnly(arg0 interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListLabelsOnly", reflect.TypeOf((*MockClient)(nil).ListLabelsOnly), arg0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListFoldersOnly mocks base method.
|
||||||
|
func (m *MockClient) ListFoldersOnly(arg0 context.Context) ([]*pmapi.Label, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "ListFoldersOnly", arg0)
|
||||||
|
ret0, _ := ret[0].([]*pmapi.Label)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListFoldersOnly indicates an expected call of ListFoldersOnly.
|
||||||
|
func (mr *MockClientMockRecorder) ListFoldersOnly(arg0 interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListFoldersOnly", reflect.TypeOf((*MockClient)(nil).ListFoldersOnly), arg0)
|
||||||
|
}
|
||||||
|
|
||||||
// ListMessages mocks base method.
|
// ListMessages mocks base method.
|
||||||
func (m *MockClient) ListMessages(arg0 context.Context, arg1 *pmapi.MessagesFilter) ([]*pmapi.Message, int, error) {
|
func (m *MockClient) ListMessages(arg0 context.Context, arg1 *pmapi.MessagesFilter) ([]*pmapi.Message, int, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
@ -596,6 +656,21 @@ func (mr *MockClientMockRecorder) UpdateLabel(arg0, arg1 interface{}) *gomock.Ca
|
|||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateLabel", reflect.TypeOf((*MockClient)(nil).UpdateLabel), arg0, arg1)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateLabel", reflect.TypeOf((*MockClient)(nil).UpdateLabel), arg0, arg1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateLabelV4 mocks base method.
|
||||||
|
func (m *MockClient) UpdateLabelV4(arg0 context.Context, arg1 *pmapi.Label) (*pmapi.Label, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "UpdateLabelV4", arg0, arg1)
|
||||||
|
ret0, _ := ret[0].(*pmapi.Label)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateLabelV4 indicates an expected call of UpdateLabelV4.
|
||||||
|
func (mr *MockClientMockRecorder) UpdateLabelV4(arg0, arg1 interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateLabelUpdateLabelV4", reflect.TypeOf((*MockClient)(nil).UpdateLabelV4), arg0, arg1)
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateUser mocks base method.
|
// UpdateUser mocks base method.
|
||||||
func (m *MockClient) UpdateUser(arg0 context.Context) (*pmapi.User, error) {
|
func (m *MockClient) UpdateUser(arg0 context.Context) (*pmapi.User, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
|
|||||||
@ -24,6 +24,11 @@ import (
|
|||||||
"github.com/ProtonMail/proton-bridge/v2/pkg/pmapi"
|
"github.com/ProtonMail/proton-bridge/v2/pkg/pmapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
route = "/labels"
|
||||||
|
routeV4 = "/core/v4/labels"
|
||||||
|
)
|
||||||
|
|
||||||
func (api *FakePMAPI) isLabelFolder(labelID string) bool {
|
func (api *FakePMAPI) isLabelFolder(labelID string) bool {
|
||||||
for _, label := range api.labels {
|
for _, label := range api.labels {
|
||||||
if label.ID == labelID {
|
if label.ID == labelID {
|
||||||
@ -42,15 +47,51 @@ func (api *FakePMAPI) isLabelFolder(labelID string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *FakePMAPI) ListLabels(context.Context) ([]*pmapi.Label, error) {
|
func (api *FakePMAPI) ListLabels(ctx context.Context) ([]*pmapi.Label, error) {
|
||||||
if err := api.checkAndRecordCall(GET, "/labels/1", nil); err != nil {
|
return api.listLabels(ctx, "1", route)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *FakePMAPI) CreateLabel(ctx context.Context, label *pmapi.Label) (*pmapi.Label, error) {
|
||||||
|
return api.createLabel(ctx, label, route)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *FakePMAPI) UpdateLabel(ctx context.Context, label *pmapi.Label) (*pmapi.Label, error) {
|
||||||
|
return api.updateLabel(ctx, label, route)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *FakePMAPI) DeleteLabel(ctx context.Context, labelID string) error {
|
||||||
|
return api.deleteLabel(ctx, labelID, route)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *FakePMAPI) ListLabelsOnly(ctx context.Context) ([]*pmapi.Label, error) {
|
||||||
|
return api.listLabels(ctx, "1", routeV4)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *FakePMAPI) ListFoldersOnly(ctx context.Context) ([]*pmapi.Label, error) {
|
||||||
|
return api.listLabels(ctx, "3", routeV4)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *FakePMAPI) CreateLabelV4(ctx context.Context, label *pmapi.Label) (*pmapi.Label, error) {
|
||||||
|
return api.createLabel(ctx, label, routeV4)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *FakePMAPI) UpdateLabelV4(ctx context.Context, label *pmapi.Label) (*pmapi.Label, error) {
|
||||||
|
return api.updateLabel(ctx, label, routeV4)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *FakePMAPI) DeleteLabelV4(ctx context.Context, labelID string) error {
|
||||||
|
return api.deleteLabel(ctx, labelID, routeV4)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *FakePMAPI) listLabels(_ context.Context, labeType string, route string) ([]*pmapi.Label, error) {
|
||||||
|
if err := api.checkAndRecordCall(GET, route+"/"+labeType, nil); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return api.labels, nil
|
return api.labels, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *FakePMAPI) CreateLabel(_ context.Context, label *pmapi.Label) (*pmapi.Label, error) {
|
func (api *FakePMAPI) createLabel(_ context.Context, label *pmapi.Label, route string) (*pmapi.Label, error) {
|
||||||
if err := api.checkAndRecordCall(POST, "/labels", &pmapi.LabelReq{Label: label}); err != nil {
|
if err := api.checkAndRecordCall(POST, route, &pmapi.LabelReq{Label: label}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, existingLabel := range api.labels {
|
for _, existingLabel := range api.labels {
|
||||||
@ -71,8 +112,8 @@ func (api *FakePMAPI) CreateLabel(_ context.Context, label *pmapi.Label) (*pmapi
|
|||||||
return label, nil
|
return label, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *FakePMAPI) UpdateLabel(_ context.Context, label *pmapi.Label) (*pmapi.Label, error) {
|
func (api *FakePMAPI) updateLabel(_ context.Context, label *pmapi.Label, route string) (*pmapi.Label, error) {
|
||||||
if err := api.checkAndRecordCall(PUT, "/labels", &pmapi.LabelReq{Label: label}); err != nil {
|
if err := api.checkAndRecordCall(PUT, route, &pmapi.LabelReq{Label: label}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for idx, existingLabel := range api.labels {
|
for idx, existingLabel := range api.labels {
|
||||||
@ -91,8 +132,8 @@ func (api *FakePMAPI) UpdateLabel(_ context.Context, label *pmapi.Label) (*pmapi
|
|||||||
return nil, fmt.Errorf("label %s does not exist", label.ID)
|
return nil, fmt.Errorf("label %s does not exist", label.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *FakePMAPI) DeleteLabel(_ context.Context, labelID string) error {
|
func (api *FakePMAPI) deleteLabel(_ context.Context, labelID string, route string) error {
|
||||||
if err := api.checkAndRecordCall(DELETE, "/labels/"+labelID, nil); err != nil {
|
if err := api.checkAndRecordCall(DELETE, route+labelID, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for idx, existingLabel := range api.labels {
|
for idx, existingLabel := range api.labels {
|
||||||
|
|||||||
@ -57,7 +57,7 @@ func thereIsUserWithMailbox(bddUserID, mailboxName string) error {
|
|||||||
}
|
}
|
||||||
err := ctx.GetPMAPIController().AddUserLabel(account.Username(), &pmapi.Label{
|
err := ctx.GetPMAPIController().AddUserLabel(account.Username(), &pmapi.Label{
|
||||||
Name: mailboxName,
|
Name: mailboxName,
|
||||||
Type: pmapi.LabelTypeMailbox,
|
Type: pmapi.LabelTypeMailBox,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return internalError(err, "adding label %s for %s", mailboxName, account.Username())
|
return internalError(err, "adding label %s for %s", mailboxName, account.Username())
|
||||||
|
|||||||
Reference in New Issue
Block a user