clips / clips/pattern

gmail count returns "ValueError: invalid literal for int() with base 10: '[NONEXISTENT] Unknown Mailbox:"

Open
#82 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.9k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

I tried to count the messages in some of my gmail folders. This seems to work for e.g. the folder "inbox"

>>> inbox=gmail.folders.get("inbox")
>>> inbox.count
147

However when I do this for a folder with a more complex name "[google ]/alle nachrichten" counting fails with an error

>>> all=gmail.folders.get("[google ]/alle nachrichten")
>>> all.count
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pattern/web/imap/__init__.py", line 212, in count
    return len(self)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pattern/web/imap/__init__.py", line 280, in __len__
    return int(response[0])
ValueError: invalid literal for int() with base 10: '[NONEXISTENT] Unknown Mailbox: [google ]/alle nachrichten (now in authenticated state) (Failure)'

It seems to me, that there is a problem with folders, which have spaces, brackets or slashes in their path. Can this be fixed?
As a workaround I found the following solution

>>> len(all.search("", field=SUBJECT))
9496

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pattern/web/imap/init.py, especially the count path at lines 212 and 280 shown in the traceback. Reproduce the failure with an IMAP folder containing spaces, brackets, or slashes and inspect the server response handling. Done means counting works for the reported Gmail folder names without converting an error response to an integer.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.