コード例 #1
0
 /**
  * @test
  */
 public function it_returns_false_when_the_given_filename_does_not_exist()
 {
     $connection = $this->getImapConnectionMock();
     $imap = $this->getImapMock($connection);
     $message = $this->getMessageMock();
     $messageService = new ImapMessageService($message, $imap);
     /**
      * @var Attachment $attachment
      */
     $attachment1 = $this->getAttachment('apple.png');
     $attachment2 = $this->getAttachment('orange.png');
     $attachments = $attachment = m::mock('Humps\\MailManager\\Collections\\ImapAttachmentCollection');
     $attachments->shouldReceive('count')->andReturn(2);
     $message->shouldReceive('getAttachments')->andReturn($attachments);
     $iterator = new ArrayIterator([$attachment1, $attachment2]);
     $attachments->shouldReceive('getIterator')->andReturn($iterator);
     $path = $messageService->downloadAttachmentByFilename('pear.png', 'attachments');
     $this->assertFalse($path);
 }
コード例 #2
0
<?php

use Humps\MailManager\Factories\ImapFactory;
use Humps\MailManager\Factories\ImapMessageFactory;
use Humps\MailManager\ImapMessageService;
set_time_limit(0);
require_once '../vendor/autoload.php';
$mid = $_REQUEST['mid'];
$folder = $_REQUEST['folder'];
$filename = $_REQUEST['filename'];
$imap = ImapFactory::create($folder);
$message = ImapMessageFactory::create($mid, $imap);
$messageService = new ImapMessageService($message, $imap);
if ($path = $messageService->downloadAttachmentByFilename($filename)) {
    // download to browser
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    readfile($path);
    $dir = dirname($path);
    unlink($path);
    rmdir($dir);
    rmdir($folder);
}