We help IT Professionals succeed at work.

Why is <0x21><CR><LF> inserted in MIME file?

snazzyrags
snazzyrags asked
on
Using 'sendmail', 'mail', and 'mailx' all result in the same problem. I am sending an MS-Excel spreadsheet as a MIME object (application/octet-stream and application/vnd.ms-excel act the same). When the spreadsheet is received, intermittently throughout the document the characters "0x21,0x0d,0x0a" are inserted. The first occurrance is at offset 01737 (octal), then at 011730, 13672, 15634, 17576, 21540, 23502, etc... After the first occurance, the are equally spaced 994 bytes apart.

The email statement is:

/usr/lib/sendmail -B 8BITMIME -t < inputfile

(The -B option makes no difference in the outcome)

The input file is:

To: doug.thomas@ps.bellhowell.com
Subject: Test
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="messagepartboundary"

--messagepartboundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

This is the body of the message.

--messagepartboundary
Content-Type: application/octet-stream; charset=us-ascii
Content-Transfer-Encoding: binary
Content-Disposition: attachment; filename="Book1.xls"

<Excel spreadsheet bianry code goes here>

--messagepartboundary--

Any thoughts out there? Try this code on your machine and let me know either way what the results are.

BTW: The input file was generated by 'cat hdr Book.xls trl', where hdr contains statements up to the binary code and trl contains the line '--messagepartboundary--'. Book.xls is the spreadsheet file.

Interesting point: This does not occur on an IRIX Unix computer. However, the IRIX machine converts any 0x0a characters found in the file to '\n'. This is irrelevant, since I'm not developing this for an IRIX system. Just an interesting point.
Comment
Watch Question

Top Expert 2005
Commented:
Off hand it seems to me that something is 'wrapping' the binary part when an internal buffer in sendmail is full (apparently at 994 bytes). Also it seems to me that the approach you are using isn't a very good way to transport binary files. It would be more appropriate to encode the binary file, say into base64 encoding, and transfer that via email. Using base64, uuencode, or any other binary encoding mechanism will result in a binary attachment with line lengths of less than 80 characters and you won't have this problem.
CERTIFIED EXPERT

Commented:
you need to encode the file first (uuencode, base64) as jlevie already said.
Sendmail does it not itself (see
   Content-Type: application/octet-stream; charset=us-ascii
), usually

Explore More ContentExplore courses, solutions, and other research materials related to this topic.