eimap

EIMap - Easy access to your imap inbox
15 followers

Overview

The EIMap Class allows to have easy access to imap extension functions to read and parse messages from a mailbox.

Requirements

How to use

Extract and place the contents of the package into your extensions folder (you can place it where ever you wish, the extensions folder is for the sake of the example).

Examples

reading unseen emails

Yii::import('ext.EImap.EIMap', true);
 
// please replace the server path to the one of your
// inbox + your username and password
$imap = new EIMap('{imap.server.com:993}/imap/ssl}INBOX', 'yourusername', 'yourpassword');
 
if($imap->connect())
{
    // we are set lets search for unseen
    $unseen = $imap->searchmails( EIMap::SEARCH_UNSEEN );
 
    if($unseen && is_array($unseen)) // do we have any?
    {
        // put new ones first
        rsort($unseen);
 
        foreach($unseen as $msgId)
        {
            $mail = $imap->getMail( $msgId );
            echo '<pre>'.( CVarDumper::dumpAsString( $mail ) ).'</pre>';
        }
    }
    $imap->close(); // close connection     
}

reading mails overviews

Yii::import('ext.EImap.EIMap', true);
 
// please replace the server path to the one of your
// inbox + your username and password
$imap = new EIMap('{imap.server.com:993}/imap/ssl}INBOX', 'yourusername', 'yourpassword');
 
if($imap->connect())
{
    // get mailbox info
    $mailboxCheck = $imap->getCheck();
 
    // read all messages overviews
    $result = $imap->getMailboxOverview("1:{$mailboxCheck->Nmsgs}");
 
    // if we have any display them
    foreach($result as $overview)
    {
        echo "#{$overview->msgno} ({$overview->date}) - From: {$overview->from} {$overview->subject}\n";
        echo "size: {$overview->size}";
        echo '<pre>'.CVarDumper::dumpAsString($overview).'</pre>';
 
        // sender again please?
        echo '<pre>'.CVarDumper::dumpAsString($imap->getSender($overview->msgno)).'</pre>';
    }
    $imap->close(); // close connection     
}

====

Clevertech
well-built beautifully designed web applications
www.clevertech.biz

Total 7 comments

#11582 report it
ikary at 2013/01/21 06:20pm
bug

replace

if (($structure->ifdisposition && strtolower($part->disposition) == 'attachment' && $structure->ifdparameters) ||   (in_array(strtolower($part->subtype), $imgTypes))

by

if( property_exists($part, 'disposition') && strtolower($part->disposition)=='attachment')

if not, the code only worked when the attachments were images, a non sense, ifdisposition has nothing to do

.... modifying this extension to be usable, ....I'll upload the result

#11516 report it
ikary at 2013/01/18 04:00am
not work if php < 5.3.2

imap_open not work with 6 parameters if php<5.3.2, replace imap_open line, by this:

if (version_compare(PHP_VERSION, '5.3.2', '<') ) {
    $ev->stream = $this->stream = @imap_open($this->mailbox, $this->username, $this->password, $options, $retries);
}
else {
    $ev->stream = $this->stream = @imap_open($this->mailbox, $this->username, $this->password, $options, $retries,  $params);
}
#11398 report it
Ivo Renkema at 2013/01/11 03:33am
@dve, Nisanth thulasi

Good to hear. If there are any problems, please ask a question at Stackoverflow.

#11396 report it
dve at 2013/01/11 01:45am
thanks

Thans,it's working now.

#11379 report it
Nisanth thulasi at 2013/01/10 05:28am
bug for video attachment

HI Ivo Renkema

i changed my code with that you mentioned but not supporting any video formated file type

#10752 report it
dve at 2012/11/21 08:14am
Help

I try this extension but it 's not working for me .

I use this $imap = new EIMap('{imap.gmail.com:993/imap/ssl}INBOX', 'myemail@gmail.com', 'mypasswor')

but it's return blank page. I don't know why

I need help.

#10677 report it
Ivo Renkema at 2012/11/14 07:46am
bug for video attachments

Thanks for the extension!

It took me while to get it to work for video-file attachments.

First, I expanded $imgTypes to include 'mp4', et cetera. But even then the download of the attachment failed.

Secondly, I believe there is a bug in getAttachment(). The line:

    $data = $this->decodeValue($body, $part->type);

should actually be:

    $data = $this->decodeValue($body, $part->encoding);

Is that right? After the above changes, downloading video attachments seems to work.

Leave a comment

Please to leave your comment.

Create extension