Topic: Can't download multipart message body to database?????? Pages that link to <a href="https://ozoneasylum.com/backlink?for=29570" title="Pages that link to Topic: Can&amp;#039;t download multipart message body to database??????" rel="nofollow" >Topic: Can&#039;t download multipart message body to database??????\

 
Author Thread
paritycheck
Bipolar (III) Inmate

From: you tell me
Insane since: Mar 2004

IP logged posted posted 09-29-2007 13:15 Edit Quote

Hi guys I need some help right here.. I'm tweaking roundcube mail so that at the click on a button a selected message is copied from the mail server into a table on my local database. SO far I've made a couple of tweaks so that it takes a copy of the mail headers from the mail server and it copies teh headers .. but I can't find the way to copy the message body and attachments and message parts as well to the database.

Which function is used to retrieve the message body and attachment information from the mail server? Right now what my patch does is that when the message is selected and my custom button clicked - it first takes a copy of the mail header with the code :

code:
$headers = $this->get_headers($one_uid, $key);



And then I make it insert into the database with own custom function. I've made my own little tweaks to retrieve the message headers from the database as well.

But I'm not so sure about how to retrieve the message body part and what should I do with messages that are mimetype or have multiparts. Currently the following code just returns raw basic text and doens't work for multipart emails.

code:
$headers->structure = &$this->get_body($one_uid);



What do I need to do to also download attachments and put the attachments in the database as well as download the whole mail structure?

Any help would be greatly appreciated...

(Edited by paritycheck on 09-29-2007 13:15)

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 09-30-2007 18:14 Edit Quote

Sorry, again I don't know roundcube - what other methods are defined in a message?
(Alternatively - do you have a direct link to the source?)

paritycheck
Bipolar (III) Inmate

From: you tell me
Insane since: Mar 2004

IP logged posted posted 10-01-2007 10:23 Edit Quote

Hmmmm ok I think I've figured this part out - roundcube mail apparently refers to a globally declared MESSAGE variable which contains in teh form of an array the information on th parts and structure of the message to be viewed..

I got it to download multipart emails so they're downloading great - YAHOOOO...

But then again I'm still having problems with the downloading atatchments part... I need a script that downloads attachments from an email and insert them into a database as a BLOB object or atlaest does the downloading part in the backend so that I can insert it into a database..... anyone has any idea or knows of any ready made code snippet that actually can help in this?

OOor do I need to start a new thread for this ...

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 10-01-2007 11:57 Edit Quote

Nah, keep it in this thread.


Your best bet is to start digging how roundcube itself retrieves an attachment - but I believe
it to be a better idea to not cache attachmens. They can be large (causing delay, if
you want to retrieve them "in the backend" before viewing a message the first time),
the user usually downloads them only once (within your cache expiry time, at least),
and large blobs in a mysql database are a no no (you're most likely to get better
performance just relaying for the IMAP like roundcube does, then relaying
for the mysql which in my expierence is measured in single kb/s...

So long,

->Tyberius Prime

paritycheck
Bipolar (III) Inmate

From: you tell me
Insane since: Mar 2004

IP logged posted posted 10-01-2007 12:24 Edit Quote

Hmmm you have a point but the thing is that we need to maintain a local db copy of the messages as well as all the attachments that come with it.. anyway I just discovered the function that donwloads the attachments and for testing fixed it so it dumps the attachments into a db as a BLOB [ sorry bout that ]. Its the function rcube_imap->get_message_part() just pass in the UID of teh message and part needed and it returns the entire content to be used as you wish ...

Although I was wondering on what you said about the Blob thing - what would be a better way to store my message attcahments on the local?

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 10-01-2007 13:17 Edit Quote

well, how about the file system?
Sure, it's a little bit of trouble to store the files with the id as filename (plu prefix,postfix, whatever),
but it works very much better than dumping them in a blob. (A binary large object (blob) is a opaque
data for a database... it can't do anything meaningful on a database level with it anyhow).


At least make sure you copy the attachments in an asyncronous request to retrieving the
mail text...

paritycheck
Bipolar (III) Inmate

From: you tell me
Insane since: Mar 2004

IP logged posted posted 10-01-2007 14:10 Edit Quote
quote:
At least make sure you copy the attachments in an asyncronous request to retrieving the
mail text...



Uh ok.. I got lost there... - if you meant that I should copy the attachments at the same time I retrieve the messages for copying then yeah I've set it to do that...

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 10-01-2007 22:18 Edit Quote

you should output javascript that retrieves the attachment 'in the background' by doing another request to your php server
that then retrieves the atachments.
Otherwise, your user won't see the message until you have slurped all of his 50 megabyte attachment
(btw, what happens if an attachment is so large that you can't retrieve in in the 30 seconds of php execution time you
usually have)?

paritycheck
Bipolar (III) Inmate

From: you tell me
Insane since: Mar 2004

IP logged posted posted 10-02-2007 11:26 Edit Quote

Hmmmm... right now what my logic is that I'm executing a loop for all the selected messages. Like the logic is

code:
Foreach(selected-uids as one_id)

     message = get_message(uid)   
     
     foreach(message->parts as one-part)
     
          if(one-part is attachment)
          {
               download one-part
               insert as attachment into db
          }else{
              insert as text message
          }
     
     Loop

Loop



its running pretty ok with a small attachment but now I just noticed that its dying prematurely when downloading huge attachments!!!! WHat do I do here guys ... how come its giving up like that?

paritycheck
Bipolar (III) Inmate

From: you tell me
Insane since: Mar 2004

IP logged posted posted 10-02-2007 11:28 Edit Quote

HMmm ok I'm getting this littel error.. what does this mean:

code:
PHP Fatal error:  Allowed memory size of 8388608 bytes exhausted (tried to allocate 1081697 bytes)

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 10-02-2007 13:19 Edit Quote

And that's where the fun starts...

PHP has all kinds of quirky little limits, probably implemented to prevent a run-away script from hosing your server.

The two most common ones are
a) a 'wall time limit', limiting your script to (by default) 30 seconds of runtime, as measured by 'a clock on the wall', but not including time spend in fopen, fread, and the like.. See http://de.php.net/manual/en/function.set-time-limit.php
b) The memory limit. This limits your script to 8 megs of memory (default) - see http://de.php.net/manual/en/ini.core.php under memory_limit.
This problem is confounded by PHPs bad memory managment that
pretty much relies on 'clean on end of request'. Even if you assign $var = NULL, the contents to var is freed, but you still loose a few bytes in free memory *each* time. Please note that that's PHP4 - I don't know about 5.

b) is what you're running into right now. You might get around it by loading the attachments in blocks and then using the sql engine to append those blocks to your blob (having a file is way easier in this case, though). Alternatively, you can try to extend the memory limit on your server, provided you control the php.ini... but it will serverely limit the cohosting accounts your software will run on.

So long,

->Tyberius Prime



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu