I am internationalizing a BatchMail program that reads files from a
directory that are encoded using either ISO-8859-1, UTF-8, or Shift_JIS.
I have also tried reading unencoded files for testing.
The program reads the file and sends a mail.
// PARSE THE FILE - the program polls a mailbox dir for any new files
input = new RandomAccessFile( file,"r" );
counter = 0;
while ((line =input.readLine()) != null) {
get the message, subject, contentType,charset, sender, recipient etc ;
}
My first question is how could I create a japanese string within java,
rather than reading it from a file ?
I think that RandomAccessFile.readLine() is OK, but I'm not so sure. I
think this may be the source of my problem. I could be double
encoding/decoding somewhere here. I want to create a japanese string
within my english java environment, but don't know how. I need this
string for testing. At least I will narrow down the source of the
problem this way.
// SEND THE EMAIL
if ("".equals(charset) || charset == null) contentHeader = contentType;
else contentHeader = contentType + "; charset=\""+charset+"\"";
//set the content mime header
msg.setContent(msgText,contentHeader);
//I have tried the three following ways of encoding a subject, all unsucessfully:
1)MimeUtility.encodeText(vSubject,charset,null);
msg.setSubject(this.subject);
2) ((MimeMessage)msg).setSubject(this.subject,charset);
3) ((MimeMessage)msg).setSubject(new String(subject.getBytes(this.subject),charset));
So my second question is which of these three is best ? Should I use MimeUtility or setter methods that take a charset?
Do I need to set the Content-Transfer-Encoding and Content-Language MIME headers or are the defaults OK?
The best i could do was to ignore all javamail encoding altogether in
which case my email/browser could read the message (already encoded as
Shift_JIS or UTF-8). If I set my browser encoding to Shift_JIS or UTF-8
at least the message was viewable. This is similar to viewing the
original file in a browser. I have not used javamail to do any encoding.
The subject line is not readable.
But if I set the Content-Type: text/plain; charset="Shift_JIS" the
message looks wrong (no matter if I javamail encode it or not).
Thanks to all,
Tom