Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gmailctl should not try to create "INBOX" label #300

Closed
pprkut opened this issue Nov 6, 2022 · 6 comments
Closed

gmailctl should not try to create "INBOX" label #300

pprkut opened this issue Nov 6, 2022 · 6 comments
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity, has become stale and will be auto-closed. question Further information is requested

Comments

@pprkut
Copy link

pprkut commented Nov 6, 2022

I have a filter rule that sets the label INBOX/Jira/<Project>. When fetching emails via IMAP, this creates a folder hierarchy like Inbox -> Jira -> <Project>.
When using automatic management of labels with gmailctl, gmailctl tries to create the labels: INBOX, INBOX/Jira and INBOX/Jira/<Project>. However, the API complains that INBOX isn't a valid label:

Error: creating labels: creating label "INBOX": googleapi: Error 400: Invalid label name, invalidArgument

IMHO it shoud just skip that label, since it doesn't need to be created. For now the only way (that I can see) to work around it would be to manually list the labels, or at the very least, manually create the "toplevel" labels first.

@mbrt
Copy link
Owner

mbrt commented Nov 7, 2022

How do you create the Jira label to be under Inbox through the Gmail UI? I don't see a way to do it. I also can't create a label called INBOX through the UI, which matches the behavior of gmailctl.

If it's just a top level label you could just remove the INBOX part in the config.

@mbrt mbrt added the question Further information is requested label Nov 7, 2022
@pprkut
Copy link
Author

pprkut commented Nov 7, 2022

I just tried using the Gmail UI, though normally I do everything from within my mail client. IMAP doesn't know about "labels", it just knows folders and Gmail translates between the two internally.

In the UI, all subfolders of Inbox show up with INBOX/ as part of the label. So a Jira subfolder of Inbox would show up as INBOX/Jira.

@mbrt
Copy link
Owner

mbrt commented Nov 7, 2022

I see. As I suspected, the actual label is INBOX/Jira (i.e. a label with a slash within). I see a couple of ways forward:

You could manually list your labels like so:

labels: [
    { name: 'INBOX/Jira' },
    { name: 'INBOX/Jira/foo' },
    // ...
  ],

Or if you're currently using lib.rulesLabels(rules), you could just modify the library function (in gmailctl.libsonnet) to ignore the INBOX prefix or remove the extendWithParents part.

I'm hesitant to modify the behavior of existing functions, unless there's a very good reason as they tend to break existing users. I feel like your particular use case should be easy enough to handle on your side.

@pprkut
Copy link
Author

pprkut commented Nov 7, 2022

Generally, I'd agree.

My thought here is that this is a pretty simple case that would be broken for any user wanting to do this already, but also shouldn't impact anyone who doesn't need it.
All that's really needed would be some logic that prevents a plain INBOX label to show up in the labels list when using the library function. Like you mentioned earlier, there's no way to create such a label, through the API or through the UI.
It would break for people that rely on this throwing an error, like perhaps in tests? I'm not sure how common that would be.

I changed the library function to do

local flat = std.flattenArrays([extend(l) for l in labels]);
std.filter(function(f) f != 'INBOX', flat),

That seems to do what I'd want

@mbrt
Copy link
Owner

mbrt commented Nov 7, 2022

Yes, I agree that this seems like it would not be a big breaking change.

One thing to keep in mind is that there are a bunch of special labels, and some are not even documented: https://developers.google.com/gmail/api/guides/labels#types_of_labels. To fix this properly we would have to account for all these cases (and keep them in sync).

In general I feel like it's strange to have label names starting with INBOX/, so I'm reluctant to complicate things to accommodate this case.

Maybe one more potential way forward is to have a variant of rulesLabels that doesn't create sub-labels automatically. This seems like a generic enough use case.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2022

This issue is stale because it has been open for 30 days without activity.
This will be closed in 7 days, unless you add the 'lifecycle/keep-alive' label or comment.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity, has become stale and will be auto-closed. label Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity, has become stale and will be auto-closed. question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants