afewmail / afew

an initial tagging script for notmuch mail
ISC License
325 stars 98 forks source link

Shell quote mail folder #218

Closed nicolasbock closed 5 years ago

nicolasbock commented 5 years ago

Follow on to PR #216:

In cases where the folder name contains characters that should be quoted, use the shlex.quote() function to properly format the folder name.

Signed-off-by: Nicolas Bock nicolasbock@gmail.com

flokli commented 5 years ago

@nicolasbock

self.query = 'folder:"{folder}" AND {subquery}'

need to be un-quoted again, as shlex.quote does add enclosing quotes automatically when necessary:

>>> import shlex
>>> print(shlex.quote("foo"))
foo
>>> print(shlex.quote("foo\""))
'foo"'
nicolasbock commented 5 years ago

You are right, I missed that. It's fixed now.

flokli commented 5 years ago

Thanks!

nicolasbock commented 5 years ago

@flokli For some reason this is not working. With this PR the search query does not return anything.

Running afew --move-mail --verbose --verbose fails to find matching emails:

DEBUG:root:query: folder:'xxx.gmail/[Gmail].Spam' AND NOT tag:spam
[NO RESULTS]

But running that query in the shell works:

$ notmuch search folder:'xxx.gmail/[Gmail].Spam' AND NOT tag:spam
[RESULTS]

Interestingly, when I revert the shlex.quote() call in line 58 but change the query string in line 26 to

self.query = "folder:'{folder}' AND {subquery}"

I get the same result as with this PR, i.e. the query does not return anything. The failure is reproducible with single quotes but I don't understand why.

Do you have any suggestions?