Quoting Kristers Zariņš <sharrpeni...@gmail.com>:

I cannot figure out how to download attachments on my server. Below is the
code I'm using. getContents() soundes like the method I need, but it doesnt
return anything:

$Mime_Part = $Data_Fetch->getStructure();
$Mime_Parts = $Mime_Part->partIterator();

foreach ($Mime_Parts as $p) {
    if ( $this->isAttachment( $p ) ) {// This actually works. Copied from
IMP source

        // How do I download attachments and save them on my server here?

        $attachment_1 = $p->getContents(); // Always empty string
        $attachment_1 = $p->getContents(['stream' => true]); // Always NULL
        //What now?
    }
}

How can I actually download? Thanks.

You need to actually fetch the attachment part from the IMAP server. getStructure only contains the MIME structure of the message, not the actual contents. So, something like:

$q = new Horde_Imap_Fetch_Query();
$q->bodyPart($mime_id, array(
    'decode' => true,
    'peek' => true
));
$mbox = new Horde_Imap_Client_Mailbox('INBOX');
$ids = new Horde_Imap_Client_Ids(array($imap_message_uid));
$list = $client->fetch($mbox, $q, array('ids' => $ids));
$email = array_pop($list);
$part = $email->getBodyPart($mime_id);

$contents = $part->getContents();

IIRC, you might need to still transfer decode the contents...

if (!$email->getBodyPartDecode($mime_id)) {
    // Quick way to transfer decode contents
    $body->setContents($email->getBodyPart($id));
    $contents = $body->getContents();
}

Horde_ActiveSync_Imap_* (especially _Message and _Adapter) contains a whole bunch of imap/mime/fetching type code if you want to look around also.

--
mike
The Horde Project
http://www.horde.org
https://www.facebook.com/hordeproject
https://www.twitter.com/hordeproject

Attachment: smime.p7s
Description: S/MIME Signature

-- 
imp mailing list
Frequently Asked Questions: http://wiki.horde.org/FAQ
To unsubscribe, mail: imp-unsubscr...@lists.horde.org

Reply via email to