I am trying to figure out how to manage an attachment of a mail that has the filename chunked. I am on java 1.6 with javamail 1.5.1 and my code can manage all kind of mails but when I receive one from a specific adress(i can't talk with those guys) it doesn't import some attachments properly. When I open those atachments(assuming that this one's name is filename without extension.extension) with notepad I find this:
Content-Type: application/octet-stream;
name*0="filename without extension"; name*1=.extension
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename*0="filename without extension"; filename*1=.extension
before the base64 content. I tried to search for similar problems but I have the exact filename but it's splitted and the BodyPart.getFilename() method returns null. I was thinking about taking the whole header and work on that.
This should be supported by your version of Javamail.
System.setProperty("mail.mime.decodeparameters", "true");
For more info, search for "RFC 2231" on the package documentation of javax.mail.internet:
https://docs.oracle.com/javaee/6/api/javax/mail/internet/package-summary.html
Related
With Spring 3.0.5, I can generate emails by calling VelocityEngineUtils.mergeTemplateIntoString(VelocityEngine velocityEngine, String templateLocation, Map model). This method generates a string that is fully compliant with MIME mail.
With Spring 3.2.11, that method is unsupported: one must use VelocityEngineUtils.mergeTemplate(VelocityEngine velocityEngine, String templateLocation, String encoding, Map model, Writer writer) with an additional encoding parameter.
Being a mailing context, I tried org.apache.commons.codec.CharEncoding.US_ASCII (which equals to US-ASCII) but it totally break my mails. All clients I tried (Outlook web mail, Outlook 2013, Windows 8's Mail) don't see subject and display all the MIME parts like the following:
------=_Part_0_1846461141.1413184892265
Content-Type: multipart/related; boundary="----=_Part_1_249771572.1413184892276"
------=_Part_1_249771572.1413184892276
Content-Type: multipart/alternative; boundary="----=_Part_2_861087694.1413184892311"
------=_Part_2_861087694.1413184892311
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
(Look at UTF-8!)
The question is: what is the correct way to invoke mergeTemplateIntoString with encoding argument?
Is any special handling required to parse the eps attachment in the eml using javamail
I dont have any issue other types of attachments. only eps attachment gives problem
When i send the eps attachment using outlook 2010 it converts encoding from base64 to quoted-printable.
Below is the header of the eps attachment i am trying to parse.
Content-Type: application/postscript;
name="LOGO.eps"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="LOGO.eps"
The attachment is extracted. But when i open it with document viewer it says loading forever
JavaMail tries to guess the best Content-Transfer-Encoding for the data by looking at the actual data. If JavaMail guesses that the data is text, it's likely to use quoted-printable. In some cases, the guess can be wrong, in which case you'll need to specify the encoding yourself. If you're using JavaMail 1.5, there's a new attachFile method that makes this easier.
i've a plugin that should process some mails, so i need to get attachments from an imap mail and do some stuff.
All seem to work but i've a single mail that have a strange attachment header and i'm not able to get it correctly, here the attachment header:
--_01d0aeb2-3f01-4153-9121-66b7af6924f1_
Content-Type: application/msword
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=
"=?iso-8859-1?Q?Atto_Aziendale_(xxx=E0_del_xxx_xxx_-_xxx)=2C_Pr?=
=?iso-8859-1?Q?of.xxx_xxx_-_Dr.xxx_xxx.doc?="
"x" are for privacy but that should not be important, the problem is that when i try to get the filename of this attachment with javaMail:
Attachment att = new Attachment(mailPart);
String filename = att.getFilename();
i get only this: "Atto Aziendale (xxx del xxx xxx - xxx), Pr"
seem that it doesn't read the second line.
I've also tried to get the filename in another way:
mailPart.getHeader("Content-Disposition").getAttribute("filename").toString();
and that return: filename="=?iso-8859-1?Q?Atto_Aziendale_(xxx=E0_del_xxx_xxx_-_xxx)=2C_Pr?==?iso-8859-1?Q?of.xxx_xxx_-_Dr.xxx_xxx.doc?="
so it seem that the attribute is correctly readed, but if i try to get:
mailPart.getHeader("Content-Disposition").getAttribute("filename").getValue();
then i get again a truncated filename: "Atto Aziendale (xxx del xxx xxx - xxx), Pr"
anyone know how to get the complete filename or how i should decode the filename attribute?
thanks for any help
If you're using IMAP, the IMAP server is parsing the mail headers and returning the parsed values to the JavaMail client. Your Content-Disposition header has several continuation lines. The IMAP server needs to properly combine those continuation lines and return the parameter values. It looks like the server is omitting the whitespace implied by the continuation line and joining the "?=" with the "=?". Without whitespace between them, they appear to be one encoded word instead of two, which likely explains why you're getting the wrong results when decoding them.
Try setting the System property "mail.mime.decodetext.strict" to "false"; this may allow JavaMail to decode the value. See the javadocs for the javax.mail.internet package for details.
I get this error while parsing an xml file using JDOM.
What is happening is, I receive a stream of data which is an xml combined with a pdf as an attachment within it. So when I try to create a document of it, this error is thrown.
I tried to print this stream and on the console I get the following, It is with lot of junk chars(the pdf contents) but in Wordpad it looks like -
------=_Part_2_23286828.1296553488632
Content-Type: text/xml; charset=utf-8
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
....
....
....
<Attachment>
<URI>Filename.pdf</URI>
</Attachment>
</SOAP-ENV:Envelope>
------=_Part_2_23286828.1296553488632
Content-Type: application/pdf; name="Filename.pdf"
Content-Transfer-Encoding: binary
Content-ID: </Attachment[1]/URI[1]>
Content-Disposition: attachment; filename="Filename.pdf"
%PDF-1.4
%âãÏÓ
4 0 obj <</Type/XObject/ColorSpace/DeviceRGB/Subtype/Image/BitsPerComponent 8/Width 579/Length 52722/Height 480/Filter/DCTDecode>>stream
ÿØÿà
Please note that the xml between <SOAP-ENV:Envelope> and </SOAP-ENV:Envelope> is well-formed.
How could I go about and create a JDOM document out of it? I guess, by removing the content before and after the xml start/end tags but how in a clean way?
I read that BOMInputStream from Apache IO Commons is helpful but I believe it is in version 2.* and I am using version 1.3.1
I hope this explains my problem, if not pls let me know.
Thank you.
UPDATE
At first I didnt realize it would be this cumbersome.
Actually, I am making a call from one servlet to another(doPost) using HttpURLConnection. The return is in the form of this stream.
Now, I am also trying to explore if in any way I can extract the xml part using some of the methods provided by Http/URLConnection.
Appreciate if anyone could shed some more light on this.
This message conforms to the SOAP with Attachment specification (http://www.w3.org/TR/SOAP-attachments). In java the way to parse these messages is to use an implementation of the SAAJ (Soap with Attachments API for Java: http://download.oracle.com/javaee/5/tutorial/doc/bnbhf.html.) There are a couple of different implementations of SAAJ out there. My personal favorite is the Spring-WS implementation another option is Apache Axiom.
My suggestion to you would be use either Spring-WS or Apache Axis to process this message rather than trying to do it manually from an input stream. Are you trying to do this on the server side or on the client side?
Obeying NDA restrictions I have to be vague.
I've been tasked to evaluate the feasibility of forcing a .dm file from my client's system to a cellular device. So far I know I can send a smil payload with a txt & gif|jpg payload but not a .dm file.
Inside of the DRM wrapper there is a header prefix before the payload starts.
Content-Type: audio/mpeg
Content-Transfer-Encoding: binary
The bridge from our stuff to the cellphone is via a SOAP bridge and what's screwing things up right now is that I have no idea what to tell it I'm sending.
I found this from a quick search, and it recommends using "application/vnd.oma.drm.message".
http://discussion.forum.nokia.com/forum/showthread.php?t=87421
http://discussion.forum.nokia.com/forum/showthread.php?t=51823