Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Javamail CRLF question on Transport.send()

843834Sep 20 2008 — edited Sep 24 2008
I use the Javamail sample 'sendfile' (and variants) with an input 'text'-file where each line is LF terminated (only). On receipt, each line in the attachment is CRLF terminated (usually, see below).
It seems that the extra CR is being added. I think its added at send time - to canonicalize the lines to end with CRLF to conform to RFC2045 (or RFC 822 requiring a CRLF pair as the standard line separator).
Saving the attachment to a file via MimeBodyPart saveFile() - prior to send has the content I want on the receivers side. How can I get this same content (as sent) at the receiver side.? Is it possible ?
A sample input file is below - with LF as line terminator i.e. 'Unix' style.

<?xml version="1.0" encoding="UTF-8"?>
<Root>
<level1>
some text
</level1>
</Root>

Further testing: if my test file itself is a MIME message (pasted below) with all lines terminated by CRLF ( 0d0a where 0d is diplayed as ^M below), I get different results depending on the mail server I send it to.
(1) if I send it to a gmail account via mail-server "smtp.gmail.com" the recipient (GMail mail-reader) receives an attachment with all CRLF's replaced by LF only.
(2) if I send it via an alternative mail-server the recipient receives an attachment with all lines terminated by CRLF ( and thus the attachment is larger than the sent file).

I need to preserve the content, and receive it exactly as sent. Any help would be appreciated.

MIME-Version: 1.0^M
Date: Tue, 26 Aug 2008 17:12:24 +2^M
Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg="SHA1"; boundary="35f306f58d834bfe92b1ca7c38c8555c"^M
^M
^M
--35f306f58d834bfe92b1ca7c38c8555c^M
Content-Type: text/xml; charset="utf-8"^M
^M
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<level1>
some text
</level1>
</Root>
^M
--35f306f58d834bfe92b1ca7c38c8555c^M
Content-Transfer-Encoding: base64^M
Content-Type: application/pkcs7-signature; name="smime.p7s"^M
Content-Disposition: attachment; filename="smime.p7s"^M
^M
MIJD1gYJKoZIhvcNAQcCoIJDxzCCQ8MCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCCDAYw^M
OqRwVeSVrDnOsZtquGH2NBXWGMTN31pb0wb96EiNTdjCbKCIIJOhAjAA^M
--35f306f58d834bfe92b1ca7c38c8555c--^M
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 22 2008
Added on Sep 20 2008
4 comments
868 views