0

I ran into a bug in a mime parsing library where it blows up on subject lines that contain foreign characters beyond a certain length. It turns out that it would convert the subject into a Quoted-Printable MIME "Encoded-Word" and then try to word-wrap the whole thing to 78 characters. Because MIME-Word encoding has no spaces (they are replaced with underscores) it failed to wrap.

Example line being wrapped:

Subject: =?UTF-8?Q?lalalla_=E7=84=A1=E6=AD=A4=E7=84=A1=E6=AD=A4=E9=A0=85=E7=9B=AE=AE=AE=AE=AE=AE=AE=AE=AE?=

I thought I might contribute a patch to the library to wrap the line correctly but I couldn't find a reference as to how to break up a MIME-Word as part of a word-wrapping algorithm.

The RFC 5322 says to word-wrap at spaces but doesn't provide any guidance about what to do if there's a string of characters with no white-space that exceeds the target width.

Anyone know the correct action to take here?

Community
  • 1
  • 1
Dobes Vandermeer
  • 8,463
  • 5
  • 43
  • 46

1 Answers1

0

Just split the line where you need to, and continue with a 2nd wrapped line. For example:

Subject: =?UTF-8?Q?lalalla_=E7=84=A1=E6=AD=A4=E7=84=A1=E6=AD=A4?=
 =?UTF-8?Q?=E9=A0=85=E7=9B=AE=AE=AE=AE=AE=AE=AE=AE=AE?=

Just be sure to make sure the 2nd (and following) wrapped lines start with either a space or a tab.

hth,
--Dave

dave wanta
  • 7,164
  • 3
  • 29
  • 29
  • So, it looks like what you are doing is decoding the Mime-Word, then doing some kind of splitting/word-wrapping, and re-encoding it? Or perhaps detecting splitting the mime-word at an arbitrary even triple and sticking \r\n\t=?UTF-8?Q? in as the separator? – Dobes Vandermeer Nov 16 '11 at 08:02
  • you should be able to split the line any place.Just make sure you begin and end the line correctly. – dave wanta Dec 06 '11 at 22:52