Does MimeUtility.decodeText work ?
Hi Everyone,
I'm trying to write a super simple little program which decodes a Quoted Printable string and display it in the iso-8859-1 character set.Really it抯 a 1 line program (full code below)
subject = MimeUtility.decodeText(args[0]);
This is what it looks like when its working
java decode_subject =?iso-8859-1?Q?Deutsche_B=F6rse_Tops_NYSE_Bid_for_Euronext_by_?=
Deutsche B鰎se Tops NYSE Bid for Euronext by
On iso-8859-1 machines it works like the above (WinXP, old Linux boxes) but if I run it on a UTF-8 machine it doesn抰 work (and I抦 getting even worse results when I call it via .forward file in my mailer).
As far as I can tell this setting doesn't work at all
System.setProperty("mail.mime.charset", "ISO-8859-1");
Here is what I get on a UTF-8 default machine
Deutsche B枚rse Tops NYSE Bid for Euronext by
To do a little debugging I added a println to show me the JavaCharset() and this is the type of output that comes out
Deutsche B枚rse Tops NYSE Bid for Euronext by
ISO-8859-1
The program is claiming to be in ISO-8859-1 but the result it clearly 2 bytes wide.
Here is the code, I've put a string into the program for easy testing and // commented out the argv lines, you can swap them around if you want to play with it. For the life of me I can't see why this doesn't work, the idea was for it to be called by a mail forwarder, but that displays the ?as a ? so it seems the System.setProperty("mail.mime.charset", "iso-8859-1");
isn't doing what I expected it to.
Can anyone spot a bug in my code ? or does this JavaMail not actually work ?
import java.net.*;
import java.io.*;
import java.util.*;
import java.text.*;
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;
public class decode_subject {
public static void main(String args[])
{
System.setProperty("mail.mime.charset", "iso-8859-1");
//String subject = "";
String subject = "=?iso-8859-1?Q?Deutsche_B=F6rse_Tops_NYSE_Bid_for_Euronext_by_?=";
try {
//subject = MimeUtility.decodeText(args[0]);
subject = MimeUtility.decodeText(subject);
} catch (Exception ioEx) {
}
System.out.println(subject);
System.out.println(MimeUtility.getDefaultJavaCharset());
}

