If I add FetchProfile.Item.CONTENT_INFO to the FetchProfile a javax.mail.Folder, .getContent() and .getInputStream() only returns empty strings, as if the content is not fetched at all. If I don't set the CONTENT_INFO flag, the content is fetched just fine.
However it only happens if the message is text/plain; charset:us-ascii. If it's multipart or text/html, it works fine.
Can anyone tell me why this happens?
Related
I have a Spring and Jersey application and has that line:
return Response.ok().header("Content-Type", "application/xml; charset=UTF-8").entity(restTemplate.postForObject(baseURL, entity, String.class)).build();
However when I debug at server side I see that Content-Type header is just application/xml. Any ideas?
However when I debug at server side I see that Content-Type header is
just application/xml
I am getting this in my code and during debug I can see the header which is proper.
Please verify.
I don't know but Sorry if I went wrong.
You have to set a separate header with
.header("charset", "UTF-8")
Seems like Jersey is reading the header value only upto the semicolon.
I have some Java code which sends out an email with code somewhat like the following: Actually i got Mimemessage from Httprequest param and in that mimemessage i'm going to append some content to existing body.
If Mimemessage is of Multipart content-type , i'm not facing any issue while sending message.
If the message is of text/plain and text/html content-type, the content-transfer encoding which i set didn't applied to body.
Based on this docs
Q: Even though JavaMail does all the encoding and decoding for me, I need to manually control the encoding for some body parts. A: In the rare case that you need to control the encoding, there are several ways to override JavaMail's default behavior. A simple approach is as follows. After creating the entire message, call msg.saveChanges() and then use something like mbp.setHeader("Content-Transfer-Encoding", "base64") to force base64 encoding for the given body part.
Another approach is to subclass MimeBodyPart and override the updateHeaders method so that it first calls super.updateHeaders() and then sets the Content-Transfer-Encoding header as above.
Applied above also. But it doesn't works for me.
InputStream ins = request.getInputStream();
MimeMessage msg = new MimeMessage(session,ins);
msg.setContent("some non-Ascii content","text/plain; charset="UTF-8"");
//Tried setheader before saveChanges() method, also doesn't work for me
//msg.setHeader("Content-Transfer-Encoding","base64");
msg.saveChanges();
//Now tried based on above docs after saveChanges method, also doesn't work
msg.setHeader("Content-Transfer-Encoding","base64");
please help to solve this.
You duplicated most of this question in your other post, and I answered part of it there.
You would probably be better off sending the content for the mail message in the http request, then creating a new message on the server based on that content, instead of trying to send a complete MIME message to the server that you then edit.
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.
Can someone please point me to the Firefox source code where Set-Cookie header is parsed? I want to understand the exact behavior.
Read further if you want to know why?
For various constraint in my application, I need to pass multiple cookies inside single Set-Cookie header. RFC-2109 clearly mentions,
"Set-Cookie response header comprises the token Set-Cookie:, followed by a comma-separated list of one or more cookies. Each cookie begins with a NAME=VALUE pair, followed by zero or more semi-colon-separated attribute-value pairs."
So I should be able to pass following Set-Cookie header
Set-Cookie: name1=value1; attr11=attrval11; attr12=attrval12,name2=value2; attr21=attrval21; attr22=attrval22;
It doesn't work. However, following does work
Set-Cookie: name1=value1, name2=value2; attr1=attrval1; attr2=attrval2;
And, I want to give different attributes for different cookies.
[Update]
Real Examples:
Example#1-
Set-Cookie: cookie1=value1; Path=/,cookie2=value2; Path=/
In this case firefox parses and gets first cookie(whose name is "cookie1" and value is "value1") out of it(second one is completely ignored)
Example#2-
Set-Cookie: cookie1=value1,cookie2=value2; Path=/
In this case firefox believes there is one cookie whose name is "cookie1" and value is "value1,cookie2=value2". This, again, is not what was intended.
A quick walk through MXR indicates the main logic is in nsCookieService::SetCookieInternal. You can follow the links back and forth as needed. As far as your actual problem, it may help if you give a real example header.
My understanding is that browsers implement the standard somewhat differently in respect to multiple cookies per Set-Cookie header. However, you can send multiple Set-Cookie headers to set the value of multiple cookies:
Set-Cookie: name1=value1; attr11=attrval11; attr12=attrval12
Set-Cookie: name2=value2; attr21=attrval21; attr22=attrval22
Although is there any reason why you're manually headers to the response instead of using whatever your framework (PHP, ASP.NET, RoR, etc) provides?
well, reading from the source code its clear that firefox doesn't implement RFC-2109 in this regard and uses CR or LF instead of ',' as cookie separator(notice line#1934, 1959, 1990 in http://mxr.mozilla.org/mozilla-central/source/netwerk/cookie/nsCookieService.cpp). I tried both on Firefox v3.6.6, CR is working but LF is not.
Conclusion: on Firefox, I can use CR instead of ',' to separate cookies.
Glitch : None out of (CR, LF, ',') are working on Internet-Explorer. Now can someone point me to "source" code for IE where I can see what they're using as cookie separator :-)
Whenever I try to know the content type of multipart message by using javamail API, I'm getting the content type as:
multipart/mixed;
boundary="----=_Part_19_32879825.1271840022140"
I've already disable my antivirus, but I'm still not able to terminate that boundary.
I'm trying to send the message using IMAP protocol.
I'm using Hmail Server.
Could anyone please tell me the reason of it?
If the email that you're sending contains an attachment, this is not an error. It is how the message header is really supposed to be:
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="frontier"
This is a message with multiple parts
in MIME format.
--frontier
Content-Type: text/plain
This is the body of the message.
--frontier
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg
Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg==
--frontier--
From: http://en.wikipedia.org/wiki/MIME
The value of the boundary attribute indicates where each message part finishes and the next one begins.
EDIT:
If you're getting an error related to missing end boundary (is that your question?), then you may want to set the missing end boundary to false:
The
mail.mime.multipart.ignoremissingendboundary
property may be set to false to cause
a MessagingException to be thrown if
the multipart data does not end with
the required end boundary line. If
this property is set to true or not
set, missing end boundaries are not
considered an error and the final body
part ends at the end of the data
That's from the JavaMail API.