3

Using the System.Net.Mail.MailMessage class I created an email. The email was in german and needed to contain the umlaut ü. For this reason I declared the SubjectEncoding property of the object as Encoding.UTF8. On receiving the email I noticed that the ü had been subsituted by two specials character in one of three mail applications (GMX webmail). It worked in Office Outlook and the apple mail app.

When plugging the subject line from below into this decoder the problem is reproducible.

I started investigating and found the subject line in the meta data of the email.

Subject: =?utf-8?B?Qk9PVCBUZXN0OiBFcmZvbGdyZWljaGUgQW5tZWxkdW5nIGbD?=
  =?utf-8?B?vHIgZGllIEJlcnVmc2Vya3VuZHVuZw==?=

The subject contains two parts which encode the first and second part of the header. Curiously the point where it split the subject in two is at the location of the ü.

I am now not quite sure who is at fault in this scenario. Is .Net incorrectly building the encoded subject line or is there an error in the webmail/decoder website? Is it just more or less strict interpretation of the RFC?

AnFi
  • 10,493
  • 3
  • 23
  • 47
Wolter
  • 143
  • 1
  • 10

2 Answers2

2

Update (thanks to AnFi's answer): You just happened to break the base64 inside the ü multibyte character, making this invalid.

The RFC you're looking for is RFC 2047, “MIME (Multipurpose Internet Mail Extensions) Part Three: Message Header Extensions for Non-ASCII Text”.

A note about that test system: It doesn't try to enforce the spec (you can enter a raw ü character and it displays without warnings despite violating RFC 5322; this is noted in the “not intended to be used as a validator” paragraph on that page).

Here's a base64 encoding that is broken outside of your multibyte character:

Subject: =?utf-8?B?Qk9PVCBUZXN0OiBFcmZvbGdyZWljaGUgQW5tZWxk?=
        =?utf-8?B?dW5nIGbDvHIgZGllIEJlcnVmc2Vya3VuZHVuZwo=?=

Here's a Quoted-Printable encoding for you. I find these far more legible for languages like German that only occasionally use non-ASCII characters:

Subject: BOOT Test: Erfolgreiche Anmeldung =?utf-8?Q?f=C3=BCr?= die
        Berufserkundung
Community
  • 1
  • 1
Adam Katz
  • 14,455
  • 5
  • 68
  • 83
  • 1
    Thanks not only for the answer to my question but also for providing a functioning workaround! – Wolter Feb 27 '18 at 20:56
0

It looks like a bug to report [I do not use net/vb.net]

RFC2047 : Message Header Extensions for Non-ASCII Text

Each 'encoded-word' MUST represent an integral number of characters. A multi-octet character may not be split across adjacent 'encoded- word's.

AnFi
  • 10,493
  • 3
  • 23
  • 47