Roundcube Community Forum

 

Need help for script to download emails from IMAP server into local database

Started by paritycheck, January 12, 2009, 08:26:31 AM

Previous topic - Next topic

paritycheck

Hi guys, I'm working on a project that uses roundcube and we've been tweaking it so now it reads emails from a local database. The thing is that we aim to use the interface of roundcube to read from a database as though it was an imap server. The thing is that we need to build a script that would download emails from the imap server and insert the emails into teh database on a periodic basis.

The idea I have is that we would have a script that would do the downloading on a periodic basis and at the same time on the application end we would set up the check recent function of the roundcube to check for emails that have been downloaded and marked as recent to be displayed in the interface. The thing is that we have built the code to download emails and it works quite well for single or multiple emails of small sizes - however the issue is that when it comes to having emails that are quite large and have huge attachments - we're also downloading the attachments btw the script dies midway must be due to losing connection or timeout. Considering the fact that we expect literally 100s of emails to come in every hour we would need to build the script so that it downloads without dying and making sure that we don't lose any emails. The idea is to download and delete emails from our imap server so our application functions something like a pop3.

How do we do this part I mean what kind of logic should we use to ensure that connections do not die or even if they do die there should be a way to resume from where we lost connection ???

rosali

#1-Execution time
ini_set("max_execution_time", "300");
set_time_limit(300);
--> 5 mins

#2-Download raw body
You could use ...

$message = $IMAP->get_raw_body($uid);

Your download script must be intregrated into RoundCube or a second installation of it to have the appropriate class object.

#3-I would save the message files on the filesystem and a pointer to the file in the database.
Regards,
Rosali

rosali

Second approach:

You could also have a look at ./bin/msgexport.sh. You can use this shell script as a starting point. If you run the imap import script from shell (on UNIX or as php script on windows - slightly modified) you will also be rid off timeout issues when running the script through a web server.
Regards,
Rosali