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

commands: Do not try to escape quotes #1622

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

guludo
Copy link
Contributor

@guludo guludo commented Jul 25, 2023

Using re.sub(r'"(.*)"', r'"\\"\1\\""', cmdline) is wrong, as it would not work if we have multiple quoted fragments in the command line, for example: search subject:"foo bar" and date:"this month".

Furthermore, there are other places using split_commandstring() - doing the escaping in just one place does not sound very consistent.

Just let shlex do its job. It is possible to use single quotes when needed. Using the example above, we can simply do search subject:'"foo bar"' and date:'"this month"', which is what we would normally do when using notmuch from a shell.

Using re.sub(r'"(.*)"', r'"\\"\1\\""', cmdline) is wrong, as it would
not work if we have multiple quoted fragments in the command line, for
example: `search subject:"foo bar" and date:"this month"`.

Furthermore, there are other places using split_commandstring() - doing
the escaping in just one place does not sound very consistent.

Just let shlex do its job. It is possible to use single quotes when
needed. Using the example above, we can simply do `search subject:'"foo
bar"' and date:'"this month"'`, which is what we would normally do when
using notmuch from a shell.
@pazz
Copy link
Owner

pazz commented Jul 26, 2023

I like this a lot and agree that we should just use the shlex tuff as is.
Let me just mention one use case that may be related, which has been annoying and may have led me to introduce this stuff. Perhaps you can find a nice solution:

I receive many mails with quoted name/mail pais like "Real Name" <[email protected]>. When editing such recipient in envelope mode, the quotes pop up unescaped in the prompt, so hitting enter would remove them and result in a non-RFC-conform header. Is there some convenient inverse escaping mechanism we shold call there?

@lucc
Copy link
Collaborator

lucc commented Jul 27, 2023

Is the edit address prompt even the same as the command prompt? Only the latter needs to be split at semicolons so it might make sense to just not use shlex at all for address prompt (or subject prompts,etc).

@lucc
Copy link
Collaborator

lucc commented Jul 28, 2023

I think we should (and do?) use email.utils.parseaddr() from the stdlib for to, from, etc prompts.

@pazz
Copy link
Owner

pazz commented Jul 28, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants