PHP Classes

A few problems

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  A few problems  >  (Un) Subscribe thread alerts  
Subject:A few problems
Summary:Can't get inline attachments, special characters in body
Messages:14
Author:Michael Delle
Date:2012-08-25 21:58:16
Update:2012-08-28 04:56:08
 
  1 - 10   11 - 14  

  1. A few problems   Reply   Report abuse  
Picture of Michael Delle Michael Delle - 2012-08-25 21:58:16
Hello Manuel Lemos,

First of all, thank you for the amazing class!

I am having a couple issues which I am REALLY hoping you can help me with.

Here is the code I am using: http://pastebin.com/wJUW6iWk

An email get's sent, and I am piping to a PHP script then decoding it using your class. From there it inserts the data into the database which can be viewed on my website.

Problem #1: Doesn't get inline images from the body.

Problem #2: Sometimes displays � symbols on the website. I assume it's because the email is not UTF-8 format. There a way I can use your class to convert all emails to UTF-8?

Thank you,
Michael

  2. Re: A few problems   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2012-08-26 01:51:34 - In reply to message 1 from Michael Delle
The class extracts all message parts including inline images that are added as multipart/related.

You should be using the Analyze function instead of doing your own analysis implementation. It will provide you the message in an easier way for your application to digest.

The class returns the message headers and body encoding so you can convert to whatever encoding you need.

  3. Re: A few problems   Reply   Report abuse  
Picture of Michael Delle Michael Delle - 2012-08-26 16:24:54 - In reply to message 1 from Michael Delle
Thank you for pointing out the Analyze function. Sorry I did not see it before, I had used a tutorial to get what I had to work.

Here is my new EmailHandler Class: http://pastebin.com/ms5YfpHx
Here is the email I am sending: http://pastebin.com/Ngpi1kUL

But the only result I am getting is...

NULL
array(2) {
["Type"]=>
string(4) "text"
["Description"]=>
string(12) "Text message"
}

For some reason the $decoded[$message] var_dump() is NULL.

Am I using the function wrong?

  4. Re: A few problems   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2012-08-26 23:30:13 - In reply to message 3 from Michael Delle
You copied code but omitted some parts. The $message variable is not defined.

Other than that, functions have return values that need to be verified so you programs correctly. Error verification is not optional.

  5. Re: A few problems   Reply   Report abuse  
Picture of Michael Delle Michael Delle - 2012-08-27 01:53:58 - In reply to message 4 from Manuel Lemos
Ah, of course! For some reason I thought $message was defined in the Decode method.

Here is the new code in case you want to see it: http://pastebin.com/agmHEUFM

Two more questions:

1) Is there a way to remove quoted text using your class? I don't see a way but I am stuck.

I tried doing it this way: http://pastebin.com/VNGH9Sd6

But sometimes it gives me an empty email, not sure why.


2) Is there a way to filter out spam emails? The way I am doing it now is by having SpamAssassin running on the server and it adds "***SPAM***" to the subject line. Then I look for the string "***SPAM***" in the subject line and stopping the script. But SpamAssassin does not catch all the spam so some spam emails get through still. If there's not a better way of doing it I will just deal with what I have, and maybe add a filter to look for certain words in the email.

  6. Re: A few problems   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2012-08-27 05:08:04 - In reply to message 5 from Michael Delle
The class itself does not remove quoted text because there is no standard for quoted text. It may try to figure quoted text from common patterns but it may not work in all cases.

The same goes for spam. What constitutes a spam message is subjective. Even the best spam services, including spamassassin, trigger false positives.

Filtering spam would be a subject for a whole new package that in the end would probably duplicate spamassassin functionality.

  7. Re: A few problems   Reply   Report abuse  
Picture of Michael Delle Michael Delle - 2012-08-27 05:27:20 - In reply to message 6 from Manuel Lemos
Yeah, that's what I thought :)

Have you come across a better way to loop through "Related" and "Attachments" than this? http://pastebin.com/frP9uy7n

I send myself 2 inline images (Related array) and 2 attachment images (Attachments array) and I need it to loop through them to change the filename, insert into database, and copy it to the server.

I tried it this way but this didn't work because the count ends up being 2: http://pastebin.com/0Te1crNS

  8. Re: A few problems   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2012-08-27 06:13:26 - In reply to message 7 from Michael Delle
Your code does not make much sense. Attachments and related parts are independent. You can have both, none or just some of one. You need to process them in separate loops.

  9. Re: A few problems   Reply   Report abuse  
Picture of Michael Delle Michael Delle - 2012-08-27 06:23:54 - In reply to message 8 from Manuel Lemos
I do loop through them separate using array_walk().

The code in the first pastebin works: http://pastebin.com/frP9uy7n

  10. Re: A few problems   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2012-08-27 07:57:58 - In reply to message 9 from Michael Delle
I was talking about the last sample code.

Anyway, you seem to assume that related message parts have file names but that is not necessarily true. Related message parts are linked by the content-id header.

I would have to see a real message that you are processing to determine if is the only problem.

 
  1 - 10   11 - 14