4

I would like to use javax.mail.internet.MimeUtility to decode a "quoted-printable" string. I do not need any other interface to a mail server. What's the best way to get at that class (and its dependencies)? Alternatively, is there a better way to parse "quoted-printable" strings?

Gene Golovchinsky
  • 6,101
  • 7
  • 53
  • 81
  • Not sure why this deserved a -2 without commment; it seems like a natural follow-on to an answer to another [question on "quoted-printable" encodings](http://stackoverflow.com/questions/7306432/how-to-decode-quotable-chars-from-quotable-to-a-char). – Gene Golovchinsky Oct 30 '12 at 06:39

3 Answers3

6

The Apache Commons Codec library also has support for quoted printable and is available under the more permissive apache license.

Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118
1

I don't know of anything in the standard J2SE API for this. However, a quick Google search turns up this decoder code. I can't vouch for it, but it looks reasonable. You can probably find others yourself.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • As it turns out, the code is not quite right... It doesn't seem to increment `retlen` correctly, and thus fails to compute the correct length for most test strings. – Gene Golovchinsky Oct 30 '12 at 07:07
  • @GeneGolovchinsky - It's good to know that that code has problems. Were you able to fix it or find something else that works? – Ted Hopp Oct 30 '12 at 07:26
  • Yeah, there is a spurious ‘else‘ due to commented-out code near the end of the main ‘decode‘ method. It prevents the next character from being copied and the buffer index from imcrementing. – Gene Golovchinsky Oct 30 '12 at 07:32
1

I found the Apache Commons Codec to be quite restrictive. It failed to decode a mail in quoted-printable format. The option I went with is MimeUtility#decode.

Example:

String(MimeUtility.decode(content.byteInputStream(), "quoted-printable").readAllBytes())
Markus Rohlof
  • 380
  • 3
  • 13