Isisagate
asked on
JavaMail Seven-bit encoding error
We have an object that automatically checks an email address through a POP3/SMTP server about every 5 minutes. One email that was sent in had an encoding on it of sevenbit. As soon as that came it threw an error.
java.io.IOException: Unknown encoding: sevenbit
at javax.mail.internet.MimePa rtDataSour ce.getInpu tStream(Mi mePartData Source.jav a:70)
at com.sun.mail.handlers.text _plain.get Content(te xt_plain.j ava:64)
at javax.activation.DataSourc eDataConte ntHandler. getContent (DataHandl er.java:74 5)
at javax.activation.DataHandl er.getCont ent(DataHa ndler.java :501)
at javax.mail.internet.MimeMe ssage.getC ontent(Mim eMessage.j ava:1339)
What can I do to fix this or accommodate this assuming this one source constantly sends in that encoding format this could be an issue. I know my fall back would be to just move the email into a folder on the server or just delete it but I would prefer to be able to accommodate it.
java.io.IOException: Unknown encoding: sevenbit
at javax.mail.internet.MimePa
at com.sun.mail.handlers.text
at javax.activation.DataSourc
at javax.activation.DataHandl
at javax.mail.internet.MimeMe
What can I do to fix this or accommodate this assuming this one source constantly sends in that encoding format this could be an issue. I know my fall back would be to just move the email into a folder on the server or just delete it but I would prefer to be able to accommodate it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You'd need to explicitly handle the decoding
ASKER
Do you have an example?
No. Have to work on this incrementally. Can you do a debug of
((MimeMessage) msg[x]).getDataHandler().g etContentT ype()
((MimeMessage) msg[x]).getDataHandler().g
ASKER
Well I'm going to have a rough time debugging this I had to delete that email to get them back up and running quickly.
looking at the javadocs for JavaMail I see MimeUtility.decode(java.io .InputStre am is, java.lang.String encoding);
not the questions is how do we take a Message and convert it to an InputStream?
Second how do we convert the Content-Transfer-Encoding header value to a string to detect "sevenbit" or "7-bit" to be able to correct it manually.
how do we convert the iostream back to a Message object.
if we can get those piece I am sure it will work from there.
looking at the javadocs for JavaMail I see MimeUtility.decode(java.io
not the questions is how do we take a Message and convert it to an InputStream?
Second how do we convert the Content-Transfer-Encoding header value to a string to detect "sevenbit" or "7-bit" to be able to correct it manually.
how do we convert the iostream back to a Message object.
if we can get those piece I am sure it will work from there.
Well it could be fairly tricky. Any chance of forwarding me a bad mail? Just interested in the headers
ASKER
good thing it was still in the trash off the webmail... here are the headers...
Return-Path: <sales@vanline.com>
Received: from mail191.messagelabs.com [216.82.241.83] by mail48.safesecureweb.com with SMTP;
Mon, 22 Oct 2007 01:06:43 -0400
Received: (qmail 3390 invoked from network); 22 Oct 2007 05:06:42 -0000
Received: from mailweb.vanlines.com (HELO mail.vanlines.com) (69.60.139.132)
by server-10.tower-191.messag elabs.com with SMTP; 22 Oct 2007 05:06:42 -0000
Received: from nyc2-s1000 ([10.102.32.2])
by vanlines.com (mail.vanlines.com)
(MDaemon PRO v9.0.6)
with ESMTP id md50000082999.msg;
Mon, 22 Oct 2007 01:06:21 -0400
X-VirusChecked: Checked
X-Env-Sender: sales@vanline.com
X-Msg-Ref: server-10.tower-191.messag elabs.com! 1193029602 !10598479! 1
X-StarScan-Version: 5.5.12.14.2; banners=-,-,-
X-Originating-IP: [69.60.139.132]
mime-version: 1.0
from: sales@vanline.com
to: leads@CLIENT.com
reply-to: sales@vanline.com
date: 22 Oct 2007 01:08:01 -0400
Subject: Vanlines.com Lead. TX - TX
content-type: text/plain; charset=us-ascii
content-transfer-encoding: sevenbit
X-Spam-Processed: mail.vanlines.com, Mon, 22 Oct 2007 01:06:21 -0400
(not processed: spam filter heuristic analysis disabled)
X-MDRemoteIP: 10.102.32.2
X-Return-Path: sales@vanline.com
X-Envelope-From: sales@vanline.com
X-MDaemon-Deliver-To: leads@CLIENT.com
X-SmarterMail-Spam: SPF_None
Return-Path: <sales@vanline.com>
Received: from mail191.messagelabs.com [216.82.241.83] by mail48.safesecureweb.com with SMTP;
Mon, 22 Oct 2007 01:06:43 -0400
Received: (qmail 3390 invoked from network); 22 Oct 2007 05:06:42 -0000
Received: from mailweb.vanlines.com (HELO mail.vanlines.com) (69.60.139.132)
by server-10.tower-191.messag
Received: from nyc2-s1000 ([10.102.32.2])
by vanlines.com (mail.vanlines.com)
(MDaemon PRO v9.0.6)
with ESMTP id md50000082999.msg;
Mon, 22 Oct 2007 01:06:21 -0400
X-VirusChecked: Checked
X-Env-Sender: sales@vanline.com
X-Msg-Ref: server-10.tower-191.messag
X-StarScan-Version: 5.5.12.14.2; banners=-,-,-
X-Originating-IP: [69.60.139.132]
mime-version: 1.0
from: sales@vanline.com
to: leads@CLIENT.com
reply-to: sales@vanline.com
date: 22 Oct 2007 01:08:01 -0400
Subject: Vanlines.com Lead. TX - TX
content-type: text/plain; charset=us-ascii
content-transfer-encoding:
X-Spam-Processed: mail.vanlines.com, Mon, 22 Oct 2007 01:06:21 -0400
(not processed: spam filter heuristic analysis disabled)
X-MDRemoteIP: 10.102.32.2
X-Return-Path: sales@vanline.com
X-Envelope-From: sales@vanline.com
X-MDaemon-Deliver-To: leads@CLIENT.com
X-SmarterMail-Spam: SPF_None
Yes, as you i think know
>>content-transfer-encodin g: sevenbit
should be
content-transfer-encoding: 7bit
Now it's a question of either
a. filtering that out before it gets to JavaMail
b. creating a subclass of the correct class to make that change in the processing chain
>>content-transfer-encodin
should be
content-transfer-encoding:
Now it's a question of either
a. filtering that out before it gets to JavaMail
b. creating a subclass of the correct class to make that change in the processing chain
Actually 'they' are suggesting what i said originally. Look at the api notes for this method - it applies exactly to your situation:
http://java.sun.com/products/javamail/javadocs/javax/mail/internet/MimeBodyPart.html#getRawInputStream()
http://java.sun.com/products/javamail/javadocs/javax/mail/internet/MimeBodyPart.html#getRawInputStream()
ASKER
Well the desired result would be to compensate for the messed up header and still be able to proceed.
think this might do it? I'm not sure the header piece so I tried to do the rest...
Object ob =null;
try
{
ob = ((MimeMessage) msg[x]).getContent();
}
catch(Exception e)
{
String encoding = ""; //Convert the encoding header value to a string
encoding = encoding.toLowerCase();
if(encoding.indexOf("seven bit") >-1 || encoding.indexOf("7-bit") >-1 )
{
InputStream msgIS = msg[x].getInputStream(); //get Message input Stream
InputStream decodedIS = MimeUtility.decode(msgIS, "7bit"); //Decode as 7bit
ob = (new MimeMessage(mySession, decodedIS)).getContent(); //convert back to MimeMessage
}
}
think this might do it? I'm not sure the header piece so I tried to do the rest...
Object ob =null;
try
{
ob = ((MimeMessage) msg[x]).getContent();
}
catch(Exception e)
{
String encoding = ""; //Convert the encoding header value to a string
encoding = encoding.toLowerCase();
if(encoding.indexOf("seven
{
InputStream msgIS = msg[x].getInputStream(); //get Message input Stream
InputStream decodedIS = MimeUtility.decode(msgIS, "7bit"); //Decode as 7bit
ob = (new MimeMessage(mySession, decodedIS)).getContent(); //convert back to MimeMessage
}
}
>> InputStream msgIS = msg[x].getInputStream(); //get Message input Stream
Don't think that will work (see my last comment)
Don't think that will work (see my last comment)
ASKER
okay I will look at that, what about the header info?
Yes, it was what i expected. You've implemented that correctly in your last code afaics apart from the problem i mentioned
ASKER
well I mean I left it as a stub....
String encoding = ""; //Convert the encoding header value to a string
because I'm not sure where to pull the value from... Any idea how I go about it?
I think you are 100% right that it's their email script putting the wrong encoding name, the google searches after you suggested that seem to match up. I just need to try and get a working solution in the next 2 hours to try and get it included in this evening's build.
the current code I have is this... all I need is the string value of that header and this should work.. this code compiles. So almost there....
Object ob =null;
try
{
ob = ((MimeMessage) msg[x]).getContent();
}
catch(Exception e)
{
String encoding = ""; //Convert the encoding header value to a string
encoding = encoding.toLowerCase();
if(encoding.indexOf("seven bit") >-1 || encoding.indexOf("7-bit") >-1 )
{
InputStream msgIS = ((MimeMessage)msg[x]).getR awInputStr eam(); //get Message input Stream
InputStream decodedIS = MimeUtility.decode(msgIS, "7bit"); //Decode as 7bit
ob = (new MimeMessage(this.mySession , decodedIS)).getContent(); //convert back to MimeMessage
}
}
String encoding = ""; //Convert the encoding header value to a string
because I'm not sure where to pull the value from... Any idea how I go about it?
I think you are 100% right that it's their email script putting the wrong encoding name, the google searches after you suggested that seem to match up. I just need to try and get a working solution in the next 2 hours to try and get it included in this evening's build.
the current code I have is this... all I need is the string value of that header and this should work.. this code compiles. So almost there....
Object ob =null;
try
{
ob = ((MimeMessage) msg[x]).getContent();
}
catch(Exception e)
{
String encoding = ""; //Convert the encoding header value to a string
encoding = encoding.toLowerCase();
if(encoding.indexOf("seven
{
InputStream msgIS = ((MimeMessage)msg[x]).getR
InputStream decodedIS = MimeUtility.decode(msgIS, "7bit"); //Decode as 7bit
ob = (new MimeMessage(this.mySession
}
}
ASKER
That will return whatever is set even if it's a bad value right?
Should do
:-)
Let me know how you get on
Let me know how you get on
ASKER
Thought this would be a good thing to clearify.
We roled out the fix last night and it works great, except... Turns out the emails content may say "sevenbit" but it's really a dual encoding.. quoted-printable and 7bit. When it rolled out the following content was all that was unincoded from the body..
"_________________________ __________ __________ __________ __________ _____ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email __________________________ __________ __________ __________ __________ ____ "
however if you look at it in a webmail client it doesn't show this rather all the lead content. Turns out when I ran some tests with a php script sending in the faulty headers, that is says sevenbit but has a chunk as quoted-printable and appending on to the body that 7bit content. so when you specify which one it is it only grabs the chunk in the correct format. So it looks like their messagelabs.com setup if causing this. While I can justify putting in code to convert "sevenbit" and "7-bit" into "7bit" I definitely won't make it quoted-printable that's how IE quarks probably got so bad.
Thought you might like to know that.
We roled out the fix last night and it works great, except... Turns out the emails content may say "sevenbit" but it's really a dual encoding.. quoted-printable and 7bit. When it rolled out the following content was all that was unincoded from the body..
"_________________________
however if you look at it in a webmail client it doesn't show this rather all the lead content. Turns out when I ran some tests with a php script sending in the faulty headers, that is says sevenbit but has a chunk as quoted-printable and appending on to the body that 7bit content. so when you specify which one it is it only grabs the chunk in the correct format. So it looks like their messagelabs.com setup if causing this. While I can justify putting in code to convert "sevenbit" and "7-bit" into "7bit" I definitely won't make it quoted-printable that's how IE quarks probably got so bad.
Thought you might like to know that.
Thanks Isisagate - what trouble is caused by standards non-compliance!
ASKER
Yeah they need to reference RFC 2045... http://tools.ietf.org/html/rfc2045
I dug it up today when I was trying to figure out how to reply to a client about the new issue. Oh well I learned a lot about how JavaMail works and email in general dealing with this. Too bad it ate up so much of our time with less then desired results.
I dug it up today when I was trying to figure out how to reply to a client about the new issue. Oh well I learned a lot about how JavaMail works and email in general dealing with this. Too bad it ate up so much of our time with less then desired results.
Bounce it with a curt message about the encoding ;-)
ASKER
Object ob = ((MimeMessage) msg[x]).getContent();
how should I go about changing this to hopefully be able to get the message body?