{"id":4799,"date":"2014-09-09T17:07:37","date_gmt":"2014-09-09T15:07:37","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=4799"},"modified":"2014-09-09T17:07:37","modified_gmt":"2014-09-09T15:07:37","slug":"process-binhex-email-attachments","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/process-binhex-email-attachments","title":{"rendered":"Process BinHex email attachments"},"content":{"rendered":"<p>One of the recent Mail.dll email component updates brings the ability to process BinHex encoded email attachments.<\/p>\n<p>BinHex is short for &#8220;binary-to-hexadecimal&#8221;. It is a binary to 7bit ASCII text encoding, that was used on the Mac OS for sending binary files through email. It is similar to Uuencode and Base64 encodings (both supported by Mail.dll), but it combines both &#8220;forks&#8221; (data and resources) of the Mac file. <\/p>\n<p>As with all other data-to-ASCII encodings, BinHex files usually take more space than the original files, however as BinHex includes very simple run-length compression, encoded files may be smaller under some circumstances.<\/p>\n<p>Below you can see such file inside a MIME entity:<\/p>\n<p><code>Content-type: application\/mac-binhex40; name=\"binhex.test.sit\"<br \/>\nContent-disposition: attachment; filename=\"binhex.test.sit\"<\/p>\n<p>(This file must be converted with BinHex 4.0)<\/p>\n<p>:$f*TEQKPH#jdCA0d,R0TG!\"6594%8dP8)3#3\"!&m!*!%EMa6593K!!%!!!&mFNa<br \/>\n[...]<br \/>\nZ\"`#3!fKi!!!:<\/code><\/p>\n<p>Mail.dll is going to extract data fork from such entity and put it in the IMail.Attachments collection, just like it was attached using standard MIME-way. <\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nbyte&#x5B;] eml = ...;\r\n\r\nIMail mail = new MailBuilder().CreateFromEml(eml);\r\nAssert.AreEqual(1, mail.Attachments.Count);\r\nMimeData att = (MimeData) mail.Attachments&#x5B;0];\r\n\r\nbyte&#x5B;] data = att.Data; \/\/ data fork\r\n<\/pre>\n<p>You can control, if BinHex attachments should be processed using <em>MailBuilder.ProcessBinHexAutomatically<\/em> property:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nbyte&#x5B;] eml = ...;\r\n\r\nMailBuilder builder = new MailBuilder();\r\nbuilder.ProcessBinHexAutomatically = false;\r\nIMail mail = builder.CreateFromEml(eml);\r\nAssert.AreEqual(1, mail.Attachments.Count);\r\nMimeBinHex binHex = (MimeBinHex) mail.Attachments&#x5B;0];\r\n\r\nbyte&#x5B;] data = binHex.BinHex.Data;\r\nbyte&#x5B;] resource = binHex.BinHex.Resource;\r\n\r\nstring name = binHex.BinHex.Name;\r\n<\/pre>\n<p>As you can see, data fork is not extracted automatically and you can use <em>MimeBinHex<\/em> instance to access both data and resource forks and other information stored inside the BinHex encoded attachment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the recent Mail.dll email component updates brings the ability to process BinHex encoded email attachments. BinHex is short for &#8220;binary-to-hexadecimal&#8221;. It is a binary to 7bit ASCII text encoding, that was used on the Mac OS for sending binary files through email. It is similar to Uuencode and Base64 encodings (both supported by [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[74,106,33],"class_list":["post-4799","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-attachments","tag-binhex","tag-email-component"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/4799"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=4799"}],"version-history":[{"count":4,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/4799\/revisions"}],"predecessor-version":[{"id":4803,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/4799\/revisions\/4803"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=4799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=4799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=4799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}