Part of the EllisLab Network
This thread is a discussion for the wiki article: imap pop class
   
1 of 3
1
imap pop class
Posted: 13 November 2008 05:20 AM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  13
Joined  11-13-2008

Hi all!

I’m new to CI and trying to build my first app using it. I’d like to use the feature, which enable my users to add content to site via email. I discovered this wonderful imap pop class and tried to use it, but it returned a blank page after I called a function from the controller which was a copy of a func provided on imap pop class wiki-page. I tried to search in error log for error entries but there were none of them. So later Using mailhandler for drupal I discovered that my hoster won’t install IMAP module for PHP by default.

So my question/proposal that if it’ll be useful if imap pop class will return some error message in case IMAP module for PHP isn’t installed? Mailhandler for drupal provide such functionality and it’s very useful. Don’t you think that it’ll be nice to include it in imap pop class?

Profile
 
 
Posted: 21 November 2008 08:47 PM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  4
Joined  11-13-2008

Hello,

I tried using this class, but to doesn’t do much. I have a class from phpclasses that does work. Bart

Profile
 
 
Posted: 22 November 2008 05:31 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Avatar
Total Posts:  13
Joined  11-13-2008

2 wiibart

But for me it works fine!

Profile
 
 
Posted: 22 November 2008 06:42 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  4
Joined  11-13-2008

How can i debug this?

Profile
 
 
Posted: 03 December 2008 02:49 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Avatar
Total Posts:  13
Joined  11-13-2008
wiibart - 22 November 2008 06:42 AM

How can i debug this?

May be you should post here what you want to do, code you use and output you get, so community can see what’s going on?

Profile
 
 
Posted: 03 December 2008 04:14 PM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  4
Joined  11-13-2008

Ok, well, i tried it on my my laptop (WAMP), made a controller and nothin happened, now I copied the
files on my hosted server and it works fine.

Here’s the code I use for test

  $this->load->library(‘imap_pop’);
  $config[‘server’]=‘server:110’;
  $config[‘login’]=‘login’;
  $config[‘pass’]=‘pass’;
  $config[‘service_flags’] = ‘/pop3/notls’;
  $config[‘mailbox’]= ‘INBOX’;
  $msg_count = $this->imap_pop->connect_and_count($config);
 
  $em = $this->imap_pop->grab_emails_as_nested_array(0); 
 
  $this->imap_pop->close();
 
  foreach($em as $item)
  {
      echo “title
“;
      echo $item[‘strings’][‘subject’];
      echo “
“;     
      echo “body
“;
      echo $item[‘strings’][‘text’];
      echo “
“;
  }

Profile
 
 
Posted: 14 December 2008 08:35 PM   [ Ignore ]   [ # 6 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  08-06-2006

i returned here because someone was asking about license terms and i found that there is a discussion attached to this wiki page i made.

But, amazingly, but i was not automatically subscribed to it. seems like a feature request is in order for the EE forums… something like this:

“auto-subscribe me to any ensuing thread off of this wiki page”

anyhow, i’ve posted the license terms (X11 - commonly called MIT license).

regarding problems with code, always post code if you want help. as in, post your code if you want help. did i mention posting code is a good idea if you want help? grin this code has been working for me and others for over a year, so if you have problems, they can probably be worked out.

cheers.

 Signature 

imap_pop get email | site_migrate port sites | OOCalendar | PhotoBox2 gallery | CI/EE 2 word_limiter, yep, wrote it

Profile
 
 
Posted: 25 February 2009 11:57 PM   [ Ignore ]   [ # 7 ]  
Grad Student
Avatar
Rank
Total Posts:  55
Joined  12-19-2007

Well, not to seem like a total noob, but I’ve read through your class several times, and honestly am having a difficult time determining which functions are to be called from the controller and which are internal to the class.

For instance - in the first example function (http://codeigniter.com/wiki/IMAP_POP3_Wrapper_Class/), this line:

$msg_count = $this->imap_pop->connect_and_count($config);

does not actually retrieve the message count from the class function (function simply returns TRUE or FALSE), and these two functions, while similar, are not accessible from the controller:

/**
* Get the number of emails at server
* Calling this function updates msg_count var
*/
function count_messages()
{
    $this
->msg_count = imap_num_msg($this->IMAP_resource);
    return
$this->msg_count;
}

/**
* Get count of messages returned by latest
* call to the imap_num_msg() function that
* was stored in the property
* ACCESSOR method
*/
function get_message_count()
{
    
return $this->msg_count;
}

SO… the gist of this post is: could we get some documentation for this library? Failing that, is there an easy-to-use IMAP lib that could be “ported” into CI that has full documentation?


Thanks!

 Signature 

Bob Sawyer
Head Chef, Web Design & Development
Pixels and Code, LLC
http://www.pixelsandcode.net

Profile
 
 
Posted: 26 February 2009 08:30 AM   [ Ignore ]   [ # 8 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  08-06-2006

hi bob,

thanks for the feedback. i made this library precisely because i couldn’t find any IMAP or POP library that was just the right size for my needs (basically moblog functionality). you could check out squirrelmail or roundcube which are two fully-featured, interface laden webmail readers with open source. but, i looked at their code base and i felt exactly the way you feel about this attempt!

anyhow, i am working on a rebuild of this class into a more object-oriented format so i am not going to document this iteration of it; it’s sort of simple, really, just a few functions with variations. it looks like you’ve got stuck into it… one question: have you been able to get your emails from your mailserver?

to answer your specific notes: yes, the connect_and_count() function does return TRUE or FALSE. i am updating the wiki now. there. thanks for noticing grin

yes, the two message count functions are similar except one is used when you want to get the “freshest” number from the mailserver and one is when you just want the “stored” number from the most recent “fresh” count request. this design (while a little confusing on the surface) lets a developer avoid network chatter everytime they want to figure out how many messages are at the account. the idea is that you use the “fresh” count function once and then in other subsequent calls, you use the “stored” function.

let us know how it goes.

 Signature 

imap_pop get email | site_migrate port sites | OOCalendar | PhotoBox2 gallery | CI/EE 2 word_limiter, yep, wrote it

Profile
 
 
Posted: 26 February 2009 08:47 AM   [ Ignore ]   [ # 9 ]  
Grad Student
Avatar
Rank
Total Posts:  55
Joined  12-19-2007
sophistry - 26 February 2009 08:30 AM

i made this library precisely because i couldn’t find any IMAP or POP library that was just the right size for my needs (basically moblog functionality). you could check out squirrelmail or roundcube which are two fully-featured, interface laden webmail readers with open source. but, i looked at their code base and i felt exactly the way you feel about this attempt!

Yep! I’m also looking for similar functionality for a web app. Full-fledged readers like Squirrelmail, et.al. are too much for my needs. Basically I need to import all messages for a particular account into MySQL. I’ve looked at a number of similar libs (almost all found on PHPClasses, FWIW) but none are well-documented and I’ve had little success bringing them into CI.

sophistry - 26 February 2009 08:30 AM

anyhow, i am working on a rebuild of this class into a more object-oriented format so i am not going to document this iteration of it; it’s sort of simple, really, just a few functions with variations. it looks like you’ve got stuck into it… one question: have you been able to get your emails from your mailserver?

Yes, I was able to make your example work just fine, except that it only pulls a single message. I goofed around with it a bit to try to make it cycle through and open all (only 2 on the server at this time in a test account) but no luck.

sophistry - 26 February 2009 08:30 AM

to answer your specific notes: yes, the connect_and_count() function does return TRUE or FALSE. i am updating the wiki now. there. thanks for noticing grin

No problem! grin

sophistry - 26 February 2009 08:30 AM

yes, the two message count functions are similar except one is used when you want to get the “freshest” number from the mailserver and one is when you just want the “stored” number from the most recent “fresh” count request. this design (while a little confusing on the surface) lets a developer avoid network chatter everytime they want to figure out how many messages are at the account. the idea is that you use the “fresh” count function once and then in other subsequent calls, you use the “stored” function.

Sure, that makes total sense.

I look forward to your updated version. So far, what you’ve put together _looks_ like it might work perfectly for my needs. I’m a pretty good developer, IMHO, but just need a little more documentation to know what’s what. grin

Cheers,
Bob

 Signature 

Bob Sawyer
Head Chef, Web Design & Development
Pixels and Code, LLC
http://www.pixelsandcode.net

Profile
 
 
Posted: 26 February 2009 10:15 AM   [ Ignore ]   [ # 10 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  08-06-2006

hi bob,

i scoured the web a few years back and found some of the stuff i needed on PHPClasses but as you said, not very well documented.

so, if you want to pull multiple messages you can do two things:

1) run the single message grabber and then delete_and_expunge() the message. then, the next time you run the single message grabber, you will get the next single message, and so on until the INBOX is empty. after delete_and_expunge(), depending on the mail server (and the settings in it) you are pulling email from, the message could get deleted, archived or remain “in” the inbox (those are the three choices in gmail anyway).

2) run the grab_emails_as_nested_array() function (or the grab_emails_as_nested_array_and_store() function) to grab multiple emails.

i have been using the imap_pop class in my set up for about two years now and it’s fine. my suggestion is do not wait for the new OO classes because they are even more complicated (but more general purpose - e.g., i just buit a listserv using the new lib and the CI email lib). my suggestion is to just forge ahead with the simple imap_pop class. once you get it running and get the array it returns it just runs pretty much in the background.

here’s how i get the email ‘strings’ array into a table called email (note: the email table has the fieldnames specified in the strings array).

this is in a model, but the code could be in a controller too. the actual function in my email_model is more complicated because it deals with the addresses too, but you should be able to get the idea about how simple it is to get the $em array data into a sql table by looking at this simple code.

function insert_email($em)
    
{
        
// $em comes in as two arrays items 'strings' and 'arrays'
        // strings has all the data that is bound for email db
        // arrays has the data for the address table and emailaddress join table
        // insert the items that are not arrays
        // throw the whole thing at it first
        // so that we get an email_id to use for linking
        
$this->db->insert('email', $em['strings']);
        
$email_id = $this->db->insert_id();

i love good docs (it’s what CI’s reputation is built on), but haven’t had time to buckle down and do it - rather be coding! same old story right? wink

 Signature 

imap_pop get email | site_migrate port sites | OOCalendar | PhotoBox2 gallery | CI/EE 2 word_limiter, yep, wrote it

Profile
 
 
Posted: 26 February 2009 11:19 AM   [ Ignore ]   [ # 11 ]  
Grad Student
Avatar
Rank
Total Posts:  55
Joined  12-19-2007
sophistry - 26 February 2009 10:15 AM

if you want to pull multiple messages you can do two things:

1) run the single message grabber and then delete_and_expunge() the message. then, the next time you run the single message grabber, you will get the next single message, and so on until the INBOX is empty.

If this were a simple setup just for me, I might do it that way. However, I’m building a multi-user site, so that’s not going to work.

sophistry - 26 February 2009 10:15 AM

run the grab_emails_as_nested_array() function (or the grab_emails_as_nested_array_and_store() function) to grab multiple emails.

That’s a little more like it. grin If the user can grab all their mail at once, that’s the way to go. Once it’s in the DB they can do with it as they please.

sophistry - 26 February 2009 10:15 AM

i love good docs (it’s what CI’s reputation is built on), but haven’t had time to buckle down and do it - rather be coding! same old story right? wink

Absolutely! Thanks for the extra snippets there, too. Those are helpful.

I have a group of scripts that I found a few years ago and was able to cobble together a script that does basically what I need, except that it doesn’t handle attachments (other than to note that there was one, along with the name/size, etc.). The problem with those is that (a) again, no clear docs, and (b) no clear method of dealing with attachments.

I may yet end up taking everything I’ve found, and producing something that does exactly what I need. But like you said, who has the time? wink

Cheers,
Bob

 Signature 

Bob Sawyer
Head Chef, Web Design & Development
Pixels and Code, LLC
http://www.pixelsandcode.net

Profile
 
 
Posted: 26 February 2009 11:51 AM   [ Ignore ]   [ # 12 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  08-06-2006

so, is attachment writing working for you in this lib?

 Signature 

imap_pop get email | site_migrate port sites | OOCalendar | PhotoBox2 gallery | CI/EE 2 word_limiter, yep, wrote it

Profile
 
 
Posted: 26 February 2009 11:59 AM   [ Ignore ]   [ # 13 ]  
Grad Student
Avatar
Rank
Total Posts:  55
Joined  12-19-2007

It didn’t when I tested it last night, but it was a permissions issue more than anything else, IIRC.

No matter what I end up with, I’ll have to tweak that function to write to a different destination based on the user ID. Idea is to keep each user’s attachments in their own directory. Also probvably will want to rename attachments, and perform a few other tweaks like that.

 Signature 

Bob Sawyer
Head Chef, Web Design & Development
Pixels and Code, LLC
http://www.pixelsandcode.net

Profile
 
 
Posted: 26 February 2009 01:31 PM   [ Ignore ]   [ # 14 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1156
Joined  08-06-2006

so, you’ll use the set_IMAP_attachment_dir() function? the lib currently creates a directory made from the ‘fingerprint’ of the email and then just writes the files as named in the MIME parts.

if you come up with some nice utility code, please do share.

EDIT: oh yes, i just remembered that when i moved this lib to another platform, the chown() step failed because the lib assumes user www is running your webserver. you can just take out that chown() step and it will probably work because the directory is created by the webserver process regardless of the name so another webserver process can surely write to it..

 Signature 

imap_pop get email | site_migrate port sites | OOCalendar | PhotoBox2 gallery | CI/EE 2 word_limiter, yep, wrote it

Profile
 
 
Posted: 14 June 2009 06:33 PM   [ Ignore ]   [ # 15 ]  
Grad Student
Avatar
Rank
Total Posts:  31
Joined  07-14-2007

Hi

I developed a small app using the imap_pop lib to fetch gmail via pop3. The app works perfectly locally under MAMP…

PHP Version 5.2.6
Configure Command ‘./configure’ ‘—with-imap=shared,/Applications/MAMP/Library/lib/imap-2006i’

imap
IMAP c-Client Version   2007e
SSL Support   enabled
Kerberos Support   enabled

but much to my surprise the lib can’t connect and times out my remote host server (bluehost):

PHP Version 5.2.9
Configure Command ‘./configure’ ‘—with-imap=/opt/php_with_imap_client/’ ‘—with-imap-ssl=/opt/openssl’

imap
IMAP c-Client Version   2006k
SSL Support   enabled
Kerberos Support   enabled

The log file on the remote host shows the following:

ERROR - 2009-06-14 17:13:46—> Severity: Warning —> imap_open() [function.imap-open]: Couldn’t open stream {pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX /home/my_username/public_html/application/libraries/imap_pop.php 124
ERROR - 2009-06-14 17:13:46—> Severity: Notice —> Unknown: Can’t connect to gmail-pop.l.google.com,995: Connection timed out (errflg=1) Unknown 0

I have double checked both my local and host config and I can’t just seem to be able to debug this one. Very frustrating!

Any help/tips would be much appreciated!

 Signature 

feedbleed.com - Saving music… one download at a time.
mmmmail.com - Disposable Email to RSS service.

Profile
 
 
   
1 of 3
1
 
‹‹ Multiple Applications      Inflector ››
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 119812 Total Logged-in Users: 42
Total Topics: 125952 Total Anonymous Users: 3
Total Replies: 662645 Total Guests: 422
Total Posts: 788597    
Members ( View Memberlist )