Split MIME headers into multiple lines near a space

Hello, I recently used Python to automatically send messages to my gmail account. I was surprised to find out that some of the words in the subjects of messages were split by a space character which came from nowhere. It turns out that the international (Hebrew) subject was split into multiple lines by the email package, sometimes in the middle of words. Gmail treats these line breaks as spaces, so words gets cut into two. I've checked, and there are email clients which ignore the line breaks, so the subject looks ok. I added four lines to the _binsplit function of email.Header, so that if there is a space character in the string, it will be splitted there. This fixes the problem, and subjects look fine again. These four lines (plus a comment which I wrote) are: # Try to find a place in splittable[:i] which is near a space, # and split there, so that clients which interpret the line break # as a separator won't insert a space in the middle of a word. if splittable[i:i+1] != ' ': spacepos = splittable.rfind(' ', 0, i) if spacepos != -1: i = spacepos + 1 These lines should be added before the last three lines of _binsplit. Do you think it's ok? Could this be added to email.Header? (Should I send this as a patch? It's just that the patch list was full of IDLE patches, and this change is really small, so I thought that it would be easier to post it here. Please tell me if I was wrong.) Thank you, Noam Raphael

Noam Raphael wrote:
Do you think it's ok? Could this be added to email.Header?
Noam posted a patch to SF (#1210680), and I assigned it to Barry to have a look at. Noam's suggestion seems reasonable to me, but I'm not sure what the performance implications are. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.blogspot.com

On 5/30/05, Nick Coghlan <ncoghlan@gmail.com> wrote:
Noam's suggestion seems reasonable to me, but I'm not sure what the performance implications are.
I think that they are not critical. The number of lines can grow by at most twice, because shorter words would not have a line of their own. The added rfind call seems not very significant to me, since it is preceded by about log2n string encodings, to test if an encoded prefix fits the required line length. Have a good day, Noam

Noam Raphael wrote:
Do you think it's ok? Could this be added to email.Header?
Noam posted a patch to SF (#1210680), and I assigned it to Barry to have a look at. Noam's suggestion seems reasonable to me, but I'm not sure what the performance implications are. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.blogspot.com

On 5/30/05, Nick Coghlan <ncoghlan@gmail.com> wrote:
Noam's suggestion seems reasonable to me, but I'm not sure what the performance implications are.
I think that they are not critical. The number of lines can grow by at most twice, because shorter words would not have a line of their own. The added rfind call seems not very significant to me, since it is preceded by about log2n string encodings, to test if an encoded prefix fits the required line length. Have a good day, Noam
participants (2)
-
Nick Coghlan
-
Noam Raphael