ProtonMail / proton-bridge

Proton Mail Bridge application
GNU General Public License v3.0
1.14k stars 152 forks source link

Unintended support for Contact Group labels? #410

Open mikeshappell opened 1 year ago

mikeshappell commented 1 year ago

It is unclear what support is intended for Contact group labels in the Bridge. They are processed by the handleLabelEvents function in user/events.go, but are not properly loaded when the Bridge starts from the constructor in user/user.go. So, I am not clear if the support that exists is intentional or just a byproduct of handling events from the API.

Expected Behavior

Events related to Contact Group adds, updates and deletes would be ignored by the handleLabelEvents function in the Bridge.

Current Behavior

On a Contact Group add, a new mailbox is created in the bridge, updates are applied and when a delete event occurs, the mailbox is removed. As a result of the fallthrough in getMailboxName in user/events.go, these labels are added without a parent, and should they show in the mail client, display alongside the system mailboxes.

Possible Solution

The solution depends on the intended support for these labels.

The lack of code related to these labels suggests that they are not supported. Therefore, the handleLabelEvents function could simply ignore these events by checking for the event.Label.Type. Delete comes without a type though, so ignoring it would either require more changes or, as letting it get processed does not have obvious negative effects, allow the delete event for these labels to get processed normally.

Alternatively, adding support to load this label type in the New constructor for a User in user/user.go, would at least get these reloaded into apiLabels on startup. Then, they could be dealt with like the All Mail label, with an option in the UI/CLI to control the display (or not) of this label type.

Possible Implementation

diff --git a/internal/user/events.go b/internal/user/events.go
index 1a7067fd..eb5c7952 100644
--- a/internal/user/events.go
+++ b/internal/user/events.go
@@ -349,6 +349,15 @@ func (user *User) handleDeleteAddressEvent(_ context.Context, event proton.Addre
// handleLabelEvents handles the given label events.
 func (user *User) handleLabelEvents(ctx context.Context, labelEvents []proton.LabelEvent) error {
        for _, event := range labelEvents {
+               if (event.Label.Type == proton.LabelTypeContactGroup) {
+                       user.log.WithFields(logrus.Fields{
+                               "labelID": event.ID,
+                               "name":    logging.Sensitive(event.Label.Name),
+                       }).Info("Ignoring Group Contact event")
+
+                       return nil
+               }
+
                switch event.Action {
                case proton.EventCreate:
                        updates, err := user.handleCreateLabelEvent(ctx, event)
LBeernaertProton commented 1 year ago

Hey @mikeshappell , thanks for your report. This is indeed an oversight on our part. Internally tracked as GODT-2805.