PHP Classes

Saving body and attachments to database

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  Saving body and attachments to database  >  (Un) Subscribe thread alerts  
Subject:Saving body and attachments to database
Summary:How can pieces be saved to a database, rather than a file
Messages:12
Author:f
Date:2008-10-30 18:57:40
Update:2008-11-01 18:17:31
 
  1 - 10   11 - 12  

  1. Saving body and attachments to database   Reply   Report abuse  
Picture of f f - 2008-10-30 18:57:40
At the moment, 'SaveBody'=>'/tmp' allows the parts of the email to be saved to a folder.

How about if we want to save to a database instead?

  2. Re: Saving body and attachments to database   Reply   Report abuse  
Picture of f f - 2008-10-30 19:46:04 - In reply to message 1 from f
I don't mean to sound ungrateful, but isn't all of this done by the mail parse extension? http://www.php.net/manual/en/book.mailparse.php

  3. Re: Saving body and attachments to database   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-10-31 20:48:32 - In reply to message 1 from f
If you want to save the messages to the database, you need to add custom code for that using the message data returned as string or saved to files.

  4. Re: Saving body and attachments to database   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-10-31 20:50:34 - In reply to message 2 from f
Maybe or maybe not.

First the mailparse extension is not available in all PHP installations.

Second, I am not sure if the mailparse extensions provide all the message feature extraction and if it also tolerates malformed messages as this class does.

  5. Re: Saving body and attachments to database   Reply   Report abuse  
Picture of f f - 2008-11-01 01:15:06 - In reply to message 3 from Manuel Lemos
Adding custom code is not a problem. Can you just point me in the right direction (code wise) as I can't quite understand where data is returned in string format.

  6. Re: Saving body and attachments to database   Reply   Report abuse  
Picture of f f - 2008-11-01 01:16:29 - In reply to message 4 from Manuel Lemos
That's an interesting point.

1. In your experience, can a human-written email leaving an email client or web-based solution (e.g. gmail) ever be malformed?

2. How come the mailparse functions have no explanations in the manual?

Thanks

  7. Re: Saving body and attachments to database   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-11-01 11:17:17 - In reply to message 5 from f
When you call the Decode function, just do not pass the SkipBody or SaveBody parameters. That way the parsed message parts are returned as strings in the results array.

  8. Re: Saving body and attachments to database   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-11-01 11:20:08 - In reply to message 6 from f
Human written messages are not a problem. The problem is more with scripts and some Web mail programs that are buggy and do not encode messages properly.

I did not say that the mailparse extension is not well documented. What I said is that it is not available in all installations of PHP, in all Web hosting services, etc..


  9. Re: Saving body and attachments to database   Reply   Report abuse  
Picture of f f - 2008-11-01 12:10:53 - In reply to message 8 from Manuel Lemos
Thanks for the responses.

I have been using your script, but it fails to parse an email generated through thunderbird. I've posted the eml file over here:

smsslang.com/demo.eml

The script replies back with

"MIME message decoding error: multipart content-type header does not specify the boundary parameter at position 548"

Any suggestions?

  10. Re: Saving body and attachments to database   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-11-01 17:26:04 - In reply to message 9 from f
The problem is that long lines seem to have been broken in multiple lines with tabs in the beginning, but those tabs seem to have been removed probably during some copy and paste process.

 
  1 - 10   11 - 12