Search code examples
javaencodingmime

How to test if a text fragment is Quoted-printable encoded


I am looking for a robust way in Java to test if a text fragment is quoted-printable encoded. The most straightforward way would be to test whether a string contains char sequences which match the following regular expression: (=[A–F0-9][A–F0-9])|(=[\r][\n]) (encoded characters + = and soft break for a newline).


Solution

  • I would negate the test; text which contains = followed by anything other than newline or two hex digits is not QP; but this is still a weak heuristic - somebody could put =3D in unencoded text just for the heck of it (and I just did). Bottom line: if you don't know the encoding, you don't know the encoding.