Overview ¶
The EIMap Class allows to have easy access to imap extension functions to read and parse messages from a mailbox.
Requirements ¶
- IMAP PHP Extension
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
}
====
well-built beautifully designed web applications
www.clevertech.biz
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.
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.
bug for video attachment
HI Ivo Renkema
i changed my code with that you mentioned but not supporting any video formated file type
thanks
Thans,it's working now.
@dve, Nisanth thulasi
Good to hear. If there are any problems, please ask a question at Stackoverflow.
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); }
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
Thank you !
Its working . I glad that I found it . Thank you !
How to get attached file's name
Hi friends
I have gotta problem using this extension while getting (extracting) attached file's name. Can anybody can? Would be great if found the way how to get file name through the extension.
server path
to make it work I use this server path :
$imap = new EIMap('{mydomain.com:995/pop3/ssl/novalidate-cert}INBOX', .. .....
MIME type proble
Hi everyone,
I've been working with this ext for a while, but I notice something: it seems that when an mail got a "text/plain" attachment (.txt, .cpp, .php, etc.) my app don't show it and in the wierd case that the email appears in the app, then the "text/plain" attachment is shown down as if it was part of the mail, for example:
Hi this is an email,
etc etc etc.....
The Email ends here.
int main(){return 0;}
(and here is the attachemnt to be downloaded)
main.cpp
I've been trying to solve this problem but with no success if anyone can help me I'll be really greatful
To connect to POP3 server with a self-signed certificate
For eg. gmail account -
$imap = new EIMap('{pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX', 'yourusername', 'yourpassword');
for more help check here
POP support
I read elsewhere in YII forum, that imap-php supports POP also. Any way to support POP also.
How to download atachement
$imap = new EIMap('{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX', 'xxxxxxx@gmail.com', 'xxxxxxx'); //echo $imap->getAttachmentsDirectory();exit; $imap->connect(); $unseen = $imap->searchmails(EIMap::SEARCH_UNSEEN); foreach ($unseen as $msgId) { //$imap->getMail($msgId); //attachement will save in runtime folder $imap->getAttachments($msgId); }
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.