tonioo / sievelib

Client-side Sieve and Managesieve library written in Python.
MIT License
46 stars 25 forks source link

Wrong newline encoding sievelib.managesieve.Client.getscript ? #95

Open tacruc opened 4 years ago

tacruc commented 4 years ago

Thanks for the nice library. Saved me some time in creating sieve scripts to handle my emails.

I had the follwing issue

c = Client(server)
c.connect(user, password, starttls=True)
script = c.getscript('Open-Xchange')
c.havespace('Open-Xchange',len(script))
c.putscript('Open-Xchange',script)

Was not working c.havespace returned true, but putscript failed. The Problem was solved by

c = Client(server)
c.connect(user, password, starttls=True)
script = c.getscript('Open-Xchange')
script.replace("\n","\r\n")
c.havespace('Open-Xchange',len(script))
c.putscript('Open-Xchange',script)

Therefore I'm wondering if this should be fixed in the library or if there is a good reason for this behavior.

tonioo commented 4 years ago

@tacruc With your fix, putscript works?

tacruc commented 4 years ago

Yes, but I only tested it against the sieve server of mailbox.org and have no broader background of how or why it works. It was just a good guess.

derula commented 4 years ago

Note: the parser isn't really set up to work with CRLF linebreaks, so if the getscript behavior is changed, the parser might break. I particularly noticed this with multi-line strings (parser only recognized them if they end on .\n, but with CRLF they would end on .\r\n), but there might be other issues.

It might be a quicker fix to make putscript just convert newlines back to CRLF automatically.

derula commented 3 years ago

Addendum: since the Sieve spec is pretty clear about only allowing \r\n linebreaks, I think the best way to comply would be to never convert it to Unix linebreaks to begin with. But this might require some non-trivial changes to the parser.