PHP code example of granam / imap-download

1. Go to this page and download the library: Download granam/imap-download library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

granam / imap-download example snippets



namespace Heaven\Should\Has\Api;

use Granam\Mail\Download\ImapEmailAttachmentFetcher;
use Granam\Mail\Download\ImapReadOnlyConnection;
use Granam\Mail\Download\ImapSearchCriteria;

$imapConnection = new ImapReadOnlyConnection(
    '[email protected]',
    'Раѕѕword123',
    'imap.example.com'
);
$fetcher = new ImapEmailAttachmentFetcher($imapConnection, sys_get_temp_dir() /* dir to save attachments */);
$visaFilter = (new ImapSearchCriteria())->filterSubjectContains('Visa');
$attachments = $fetcher->fetchAttachments($visaFilter);

echo 'I have found ' . count($attachments) . ' attachments in emails about Visa to Heaven. Those are: ';
foreach ($attachments as $attachment) {
    echo "\n name: $attachment[name], size " . filesize($attachment['filepath']);
}