Most email clients can handle attachments that are not wrapped (meaning the base64 encoding is not wrapped at 76 charaters), but some, specifically MS Outlook (at least some versions) cannot, and report that the attachment is corrupt.
When sending binary attachments from MarkLogic via xdmp:email
, this wrapping does not occur - causing some recipients to report documents are corrupt.
In order to fix this, we created a function which wraps the base64 encoding prior to sending.
(: Function used for wrapping email attachments :)And it used when building the parameter list:
declare function local:wrap($wrapped, $unwrapped, $max){
let $remaining := string-length($unwrapped)
return if ($remaining <= $max) then concat($wrapped, " ", substring($unwrapped, 1, $max))
else local:wrap(concat($wrapped, " ", substring($unwrapped, 1, $max)), substring($unwrapped, $max+1, $remaining), $max)
};
let $attachment1 := local:wrap("", xs:string(xs:base64Binary(doc("/some/doc/path/doc.pdf"))), 76)See documentation on xdmp:email for complete example with attachments.