Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I write exim filters to forward e-mail (like maillist). In filter condition I use header variables. And I faced with some difficultes with $h_subject encoding. Try to explain with example.

New e-mail sent from gmail with subject of few russian words. Of course, subject header is MIME-encoded. It looks like this:

Subject: =?utf-8?Q?[nr=5Fbill]=20=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20?=
 =?utf-8?Q?=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=20=D0=BE=D1=84=D0=BE=D1=80=D0=BC=D0=BB=D0=B5=D0=BD?=

In Exim filter I want to use next condition: $h_subject: contains "[nr_bill] Новый заказ оформлен"

The problem is that Exim decodes only the first line of header. Decoded header looks like this:

[nr_bill] \320\235\320\276\320\262\321\213\320\271 \n =?utf-8?Q?=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=20=D0=BE=D1=84=D0=BE=D1=80=D0=BC=D0=BB=D0=B5=D0=BD?=

The first line is successfully decoded and can be used in filters. But the second line is not decoded. And the worst: Exim saves spaces and newline carater beetween lines. As I know, new lines and leadind spaces in headers must be omitted in parsing time.

So $h_subject: contains "[nr_bill] Новый is working well, while $h_subject: contains "[nr_bill] Новый заказ оформлен" not.

Manual says that newline+spaces is normal practice. But it says nothins about multipart MIME-decoding.

Can anyone propound how to resolve this problem or just explain what is the point of those behavior?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

The answer was found. Thanks to Phil :)

Exim is being very carefully adherent to the MIME specification in RFC2047 which places a maximum length on each encoded-word.

----------------------------8< cut here >8------------------------------

encoded-word = "=?" charset "?" encoding "?" encoded-text "?=" [...]

An 'encoded-word' may not be more than 75 characters long, including 'charset', 'encoding', 'encoded-text', and delimiters. If it is desirable to encode more text than will fit in an 'encoded-word' of 75 characters, multiple 'encoded-word's (separated by CRLF SPACE) may be used.

----------------------------8< cut here >8------------------------------

So the MIME decoder is skipping those long strings and adding them literally.

...

If you set "check_rfc2047_length" false in Exim's main configuration, the header will be decoded correctly; I would assume (but haven't checked) that Exim would then re-encode things correctly as needed.

check_rfc2047_length = false

So after setting check_rfc2047_length = false all variations of problematic subjects are decoded correctly.

share|improve this answer
    
Although encoded words are limited to 75 characters, you are allowed to put multiple encoded words back to back, if you need to. –  james.garriss Mar 4 at 20:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.