OfflineIMAP / offlineimap3

Read/sync your IMAP mailboxes (python3)
Other
455 stars 64 forks source link

first escape backslash, then quotes #175

Closed roboshim closed 3 months ago

roboshim commented 10 months ago

Hello,

I presume the function quote() in imaputil.py is incorrect. Please, see the Issue #174

Thank you for merging, if I am correct.

Regards,

Robo.

thekix commented 3 months ago

Hi,

you are right, this is the code for testing:

def quote(s):
    # s = s.replace('"', '\\"')  # Fails
    s = s.replace('\\', '\\\\')
    s = s.replace('"', '\\"')  # OK

    return '"%s"' % s

def test_quote():
    assert quote('"') == '"\\""'
    assert quote('foo"bar') == '"foo\\"bar"'

if __name__ == '__main__':
    test_quote()
    print('Test OK!')

Thanks a lot for your patch!