forked from Silverfish/proton-bridge
fix(GODT-2419): Use connector.ErrOperationNotAllowed
Return this error when we detect operations that we know are not allowed so that gluon does not report them to sentry. Includes Gluon update for the connector error (https://github.com/ProtonMail/gluon/pull/309)
This commit is contained in:
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.18
|
||||
require (
|
||||
github.com/0xAX/notificator v0.0.0-20220220101646-ee9b8921e557
|
||||
github.com/Masterminds/semver/v3 v3.2.0
|
||||
github.com/ProtonMail/gluon v0.15.1-0.20230227132318-45c83ff156d7
|
||||
github.com/ProtonMail/gluon v0.15.1-0.20230301094306-3b1b90f01c0e
|
||||
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a
|
||||
github.com/ProtonMail/go-proton-api v0.4.1-0.20230228124441-781ee183e1b4
|
||||
github.com/ProtonMail/go-rfc5322 v0.11.0
|
||||
|
||||
4
go.sum
4
go.sum
@ -28,8 +28,8 @@ github.com/ProtonMail/bcrypt v0.0.0-20211005172633-e235017c1baf h1:yc9daCCYUefEs
|
||||
github.com/ProtonMail/bcrypt v0.0.0-20211005172633-e235017c1baf/go.mod h1:o0ESU9p83twszAU8LBeJKFAAMX14tISa0yk4Oo5TOqo=
|
||||
github.com/ProtonMail/docker-credential-helpers v1.1.0 h1:+kvUIpwWcbtP3WFv5sSvkFn/XLzSqPOB5AAthuk9xPk=
|
||||
github.com/ProtonMail/docker-credential-helpers v1.1.0/go.mod h1:mK0aBveCxhnQ756AmaTfXMZDeULvheYVhF/MWMErN5g=
|
||||
github.com/ProtonMail/gluon v0.15.1-0.20230227132318-45c83ff156d7 h1:4FL3ttMChrjXqmRHYaSMJZJeZZj/Xao4Mm5QnhTUSc4=
|
||||
github.com/ProtonMail/gluon v0.15.1-0.20230227132318-45c83ff156d7/go.mod h1:yA4hk6CJw0BMo+YL8Y3ckCYs5L20sysu9xseshwY3QI=
|
||||
github.com/ProtonMail/gluon v0.15.1-0.20230301094306-3b1b90f01c0e h1:uzpSucUnQsHs5zNTsCR3rYFU82PgqUyHR+UcyZ4nRvY=
|
||||
github.com/ProtonMail/gluon v0.15.1-0.20230301094306-3b1b90f01c0e/go.mod h1:yA4hk6CJw0BMo+YL8Y3ckCYs5L20sysu9xseshwY3QI=
|
||||
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a h1:D+aZah+k14Gn6kmL7eKxoo/4Dr/lK3ChBcwce2+SQP4=
|
||||
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a/go.mod h1:oTGdE7/DlWIr23G0IKW3OXK9wZ5Hw1GGiaJFccTvZi4=
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
|
||||
|
||||
@ -92,7 +92,7 @@ func (conn *imapConnector) CreateMailbox(ctx context.Context, name []string) (im
|
||||
defer conn.goPollAPIEvents(false)
|
||||
|
||||
if len(name) < 2 {
|
||||
return imap.Mailbox{}, fmt.Errorf("invalid mailbox name %q", name)
|
||||
return imap.Mailbox{}, fmt.Errorf("invalid mailbox name %q: %w", name, connector.ErrOperationNotAllowed)
|
||||
}
|
||||
|
||||
switch name[0] {
|
||||
@ -103,13 +103,13 @@ func (conn *imapConnector) CreateMailbox(ctx context.Context, name []string) (im
|
||||
return conn.createLabel(ctx, name[1:])
|
||||
|
||||
default:
|
||||
return imap.Mailbox{}, fmt.Errorf("invalid mailbox name %q", name)
|
||||
return imap.Mailbox{}, fmt.Errorf("invalid mailbox name %q: %w", name, connector.ErrOperationNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
func (conn *imapConnector) createLabel(ctx context.Context, name []string) (imap.Mailbox, error) {
|
||||
if len(name) != 1 {
|
||||
return imap.Mailbox{}, fmt.Errorf("a label cannot have children")
|
||||
return imap.Mailbox{}, fmt.Errorf("a label cannot have children: %w", connector.ErrOperationNotAllowed)
|
||||
}
|
||||
|
||||
return safe.LockRetErr(func() (imap.Mailbox, error) {
|
||||
@ -144,7 +144,7 @@ func (conn *imapConnector) createFolder(ctx context.Context, name []string) (ima
|
||||
}
|
||||
|
||||
if parentID == "" {
|
||||
return imap.Mailbox{}, fmt.Errorf("parent folder %q does not exist", name[:len(name)-1])
|
||||
return imap.Mailbox{}, fmt.Errorf("parent folder %q does not exist: %w", name[:len(name)-1], connector.ErrOperationNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ func (conn *imapConnector) UpdateMailboxName(ctx context.Context, labelID imap.M
|
||||
defer conn.goPollAPIEvents(false)
|
||||
|
||||
if len(name) < 2 {
|
||||
return fmt.Errorf("invalid mailbox name %q", name)
|
||||
return fmt.Errorf("invalid mailbox name %q: %w", name, connector.ErrOperationNotAllowed)
|
||||
}
|
||||
|
||||
switch name[0] {
|
||||
@ -182,14 +182,14 @@ func (conn *imapConnector) UpdateMailboxName(ctx context.Context, labelID imap.M
|
||||
return conn.updateLabel(ctx, labelID, name[1:])
|
||||
|
||||
default:
|
||||
return fmt.Errorf("invalid mailbox name %q", name)
|
||||
return fmt.Errorf("invalid mailbox name %q: %w", name, connector.ErrOperationNotAllowed)
|
||||
}
|
||||
}, conn.apiLabelsLock)
|
||||
}
|
||||
|
||||
func (conn *imapConnector) updateLabel(ctx context.Context, labelID imap.MailboxID, name []string) error {
|
||||
if len(name) != 1 {
|
||||
return fmt.Errorf("a label cannot have children")
|
||||
return fmt.Errorf("a label cannot have children: %w", connector.ErrOperationNotAllowed)
|
||||
}
|
||||
|
||||
label, err := conn.client.GetLabel(ctx, string(labelID), proton.LabelTypeLabel)
|
||||
@ -225,7 +225,7 @@ func (conn *imapConnector) updateFolder(ctx context.Context, labelID imap.Mailbo
|
||||
}
|
||||
|
||||
if parentID == "" {
|
||||
return fmt.Errorf("parent folder %q does not exist", name[:len(name)-1])
|
||||
return fmt.Errorf("parent folder %q does not exist: %w", name[:len(name)-1], connector.ErrOperationNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
@ -274,7 +274,7 @@ func (conn *imapConnector) CreateMessage(
|
||||
defer conn.goPollAPIEvents(false)
|
||||
|
||||
if mailboxID == proton.AllMailLabel {
|
||||
return imap.Message{}, nil, fmt.Errorf("not allowed")
|
||||
return imap.Message{}, nil, connector.ErrOperationNotAllowed
|
||||
}
|
||||
|
||||
// Compute the hash of the message (to match it against SMTP messages).
|
||||
@ -381,7 +381,7 @@ func (conn *imapConnector) AddMessagesToMailbox(ctx context.Context, messageIDs
|
||||
defer conn.goPollAPIEvents(false)
|
||||
|
||||
if isAllMailOrScheduled(mailboxID) {
|
||||
return fmt.Errorf("not allowed")
|
||||
return connector.ErrOperationNotAllowed
|
||||
}
|
||||
|
||||
return conn.client.LabelMessages(ctx, mapTo[imap.MessageID, string](messageIDs), string(mailboxID))
|
||||
@ -392,7 +392,7 @@ func (conn *imapConnector) RemoveMessagesFromMailbox(ctx context.Context, messag
|
||||
defer conn.goPollAPIEvents(false)
|
||||
|
||||
if isAllMailOrScheduled(mailboxID) {
|
||||
return fmt.Errorf("not allowed")
|
||||
return connector.ErrOperationNotAllowed
|
||||
}
|
||||
|
||||
if err := conn.client.UnlabelMessages(ctx, mapTo[imap.MessageID, string](messageIDs), string(mailboxID)); err != nil {
|
||||
@ -442,7 +442,7 @@ func (conn *imapConnector) MoveMessages(ctx context.Context, messageIDs []imap.M
|
||||
(labelFromID == proton.SentLabel && labelToID == proton.InboxLabel) ||
|
||||
isAllMailOrScheduled(labelFromID) ||
|
||||
isAllMailOrScheduled(labelToID) {
|
||||
return false, fmt.Errorf("not allowed")
|
||||
return false, connector.ErrOperationNotAllowed
|
||||
}
|
||||
|
||||
shouldExpungeOldLocation := func() bool {
|
||||
|
||||
Reference in New Issue
Block a user