phpemailmimemime-messagemime-mail

PHP MailSo library and attachments


I'm trying to use MailSo library to create MIME message. I have got to the point where next step is to process attachments. Everything is fine when attachments are binary files but when I try to to add plain text attachment as follow

$rResource = "Some plain text goes here";
$sFileName = 'text.txt';
$iFileSize = \strlen("Some plain text goes here");
$bIsInline = false;
$bIsLinked = false;
$sCID = $metadataCID;
$aCustomContentTypeParams = array(\MailSo\Base\Enumerations\Encoding::QUOTED_PRINTABLE_LOWER);

$oMessage->Attachments()->Add(
    \MailSo\Mime\Attachment::NewInstance(
        $rResource,
        $sFileName,
        $iFileSize,
        $bIsInline,
        $bIsLinked,
        $sCID,
        $aCustomContentTypeParams
    )
);

I expect to see that attachment as

Content-Type: text/plain; charset="utf-8" 
Content-Transfer-Encoding: quoted-printable 
Content-Disposition: attachment; filename=text.txt 

but it always forcing to base64 neither adding charset to content-type part as

Content-Type: text/plain; name="text.txt" 
Content-Disposition: attachment; filename="text.txt" 
Content-Transfer-Encoding: base64 

Any tips on that?


Solution

  • It looks like MailSo library treats all attachments except message/rfc822 as binaries. It will require to rewrite or extend createNewMessageAttachmentBody() private function.