If you need some examples for inspiration how to do a Quoted-Printable decoder:
– MujMail > Source > Decode.java > decodeHeaderField
– JavaMail
Although, I do not like any of these examples. If I am not mistaken, in JavaMail the QDecoderStream should call its super class QPDecoderStream after filtering the underscore, rather than doing the rest itself (different code in both classes for the same). In MujMail the data is not handled as binary in the first run and then applying the character set in a second; instead is mixed for UTF-8.
After decoding quoted printable, data is binary, then apply its encoding. Your example should look like:
Code:
String enc = "utf-8"; // should be created dynamically from between =? and ?
byte[] bytes = { 0xD7, 0x98, 0xD7, 0xA1, 0xD7, 0x98, 0x20 /* underscore gets a space */, 0xD7, 0x91, 0xD7, 0xA2, 0xD7, 0x99, 0xD7, 0x91 0xD7, 0xA8, 0xD7, 0x99, 0xD7, 0xAA };
String s = new String(bytes, enc);
However, this might throw an UnsupportedEncodingException if the encoding is not known to your MIDP implementation. Consequently, you should add encoding mapping† for unknown (but important) encodings yourself, if everything fails, use the platform encoding or better a Windows-Latin-1 to UTF-16BE mapping which is a super-set of ISO-8859-1 which is a super-set of US-ASCII – because of their importance the best character set for a fall-back in my opinion. Furthermore, your device might not display all characters correctly, as the glyph is missing. You cannot do much about that except to draw your own font or use substitutes for special characters (see Unicode tables which to use). However, first make sure your implementation is correct, for example with the Euro sign which is quite a good test whether everything is fine with your implementation.
Any further problem? Which problem do you face exactly then? These two RFC are complicated on the first glance. If you understand this above, make sure to read and understand these RFC completely as this example I gave is not complete (there could be more than one quoted printable stream per line, different character encodings, …, see the BNF grammars in those RFC). Happing coding. That is a lot of work, try partitioning your work and to prioritize these separate parts.
† These tables can easily be added by placing the Unicode.org mappings into your JAR, load them via Class.getResourceAsStream, parse them and use them to convert to UTF-16BE. The encodings names and their alias can be imported from the IANA list. For more details on character sets…last but not least do not use all that stuff for sending an email. I recommend to limit it to a few. Start with platform encoding and change that to its preferred MIME name, then use UTF-8, then use depending on content either UTF-8, ISO-8859-1 and US-ASCII. I would not go for much more.