[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Classpathx-discuss] Problems with MimeMessage.setSubject() and UTF8
From: |
Øyvind Harboe |
Subject: |
[Classpathx-discuss] Problems with MimeMessage.setSubject() and UTF8 |
Date: |
Fri, 07 Nov 2003 16:38:04 +0100 |
MimeMessage.setSubject() appears to not handle the case where a string
contains only e.g. Japaneese characters.
The culprit appears to be in MimeUntility.encodeWord().
asciiStatus() returns 1 on the string I pass in to setSubject()...
If I delete the check, the encoding happens correctly.
Øyvind
private static String encodeWord(String text, String charset,
String encoding, boolean word)
throws UnsupportedEncodingException
{
if (asciiStatus(text.getBytes())==1)
return text;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class Send
{
public static void main(String[] args)
{
try
{
/** Set up session props and session. */
Properties sessionProps = System.getProperties();
String m_host="smtp.netpower.no";
sessionProps.put("mail.smtp.host", m_host);
Session m_session =
Session.getDefaultInstance(sessionProps);
MimeMessage message = new MimeMessage(m_session);
String from="address@hidden";
message.setFrom(new InternetAddress(from));
String to="address@hidden";
message.addRecipients(Message.RecipientType.TO, to);
String subject="yvind spiser l";
String body="yvind spiser l ";
String str2="";
str2+=(char)0x79C1;
str2+=(char)0x306B;
str2+=(char)0x30D3;str2+=(char)0x30FC;str2+=(char)0x30EB;str2+=(char)0x304C;str2+=(char)0x3042;str2+=(char)0x3063;str2+=(char)0x3066;str2+=(char)0x3082;str2+=(char)0x3088;str2+=(char)0x3044;str2+=(char)0x304B;
subject+=str2;
body+=str2;
message.setSubject(subject, "UTF8");
message.setText(body, "UTF8");
Transport transport = m_session.getTransport("smtp");
transport.connect(m_host, "", "");
transport.sendMessage(message,
message.getAllRecipients());
transport.close();
}
catch (AddressException e)
{
e.printStackTrace();
}
catch (NoSuchProviderException e)
{
e.printStackTrace();
}
catch (MessagingException e)
{
e.printStackTrace();
}
}
}
- [Classpathx-discuss] Problems with MimeMessage.setSubject() and UTF8,
Øyvind Harboe <=