commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex O'Ree" <spyhunte...@gmail.com>
Subject [net] decoding quoted-printable?
Date Mon, 03 Feb 2014 16:48:48 GMT
I'm sending an email to a local mail server (hmail) using the standard
javax.mail api. Here's a snippit

MimeMessage message = new MimeMessage(session);
InternetAddress address = new InternetAddress("receiver@local.domain");
Address[] to = {address};
message.setRecipients(RecipientType.TO, to);
message.setFrom("sender@local.domain");
String subscriptionResultXML = ""; //some raw xml goes here
message.setContent(subscriptionResultXML, "text/xml; charset=UTF-8;");
message.setSubject("subject");
Transport.send(message);

When it sends, it appears to chop up the xml into roughly 80 chars,
adding a =\n (line break). The message is also flagged with
"quoted-printable" encoding with the following headers:
MIME-Version: 1.0
Content-Type: text/xml; charset=UTF-8;
Content-Transfer-Encoding: quoted-printable

On the receiving side, I'm using the commons POP3 Client and I've been
struggling with how to decode the text. Basically, I need to remove
the =\n line breaks and end up with just the XML. I've tried using
javax.mail.internet.MimeUtility.decode....
BufferedReader reader = (BufferedReader) pop3.retrieveMessage(msginfo.number);
String line = "";
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
          String lower = line.toLowerCase(Locale.ENGLISH);
          sb.append(lower);
}

String msg=sb.toString();
InputStream is = new ByteArrayInputStream(msg.getBytes("UTF8"));
 InputStream decode = javax.mail.internet.MimeUtility.decode(is,
"quoted-printable");
StringWriter writer = new StringWriter();
IOUtils.copy(decode, writer, "UTF8");
msg = writer.toString();

However, I still end up with a string that includes the line encoding.
Interestingly enough, outlook seems to decode it just fine and renders
the xml as an attachment which is valid XML. Any ideas?

Thanks!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message