Alright.. a few comments. I've removed some of the parts that are of no 
interest to the discussion. First of all, after ezcMail has parsed a message 
the mail is built up out of objects that correspond to the MIME parts of the 
mail message. Basically, the object structure is a tree structure that 
reflects the structure of the mail. A typical object structure is:

ezcMail
  |->TextPart (the message you want)

and 
ezcMail
  |->MultipartAlternative
       | -> TextPart text/plain (the message you want)
       | -> TextPart (text/html part, you don't want this)

If there are any attachments all of this will be wrapped in a MultipartMixed 
that also contain the attachments. I know all of this sounds complex, but 
this is because mail is in fact complex and simplifying this will make it 
impossible to parse mail properly.

> // BEGIN CYCLING THROUGH MAIL
> for ( $i = 0; $i < count( $mail ); $i++ ){
>       //echo formatMail( $mail[$i] );
>       //$pop3->delete( 1 );
>
>       $from = formatAddress( $mail[$i]->from );
>       $to = formatToAddress( $mail[$i]->to );  //should only be sent TO
> one person at specific domain.
>       $subject = $mail[$i]->subject;
>       //var_dump($mail[$i]->body);
>       $bodytext = formatMailPart( $mail[$i]->body );
formatMailPart is basically what you want to change. You only want to return 
the text from the text/plain part.

> function formatMailPart( $part )
> {
>
>      if ( $part instanceof ezcMailText )
>          return formatMailText( $part );
>
Cut away this.. you don't care about it..
>      if ( $part instanceof ezcMailFile ) // do I need this?
>          return;
>
>      if ( $part instanceof ezcMailRfc822Digest ) // do I need this?
>          return formatMailRfc822Digest( $part );
>

This one has to stay...
>      if ( $part instanceof ezcMailMultiPart )
>          return formatMailMultipart( $part );
>
>        return;
> }
>
> function formatMailMultipart( $part )
> {
>      if ( $part instanceof ezcMailMultiPartAlternative )
>          return formatMailMultipartAlternative( $part );
>
This is for mail sent inside a mail you can take it away.
>      if ( $part instanceof ezcMailMultiPartDigest )
>          return formatMailMultipartDigest( $part );
>
This one is for html messages etc. that have images inside it. You can take 
that away as well.
>      if ( $part instanceof ezcMailMultiPartRelated )
>          return formatMailMultipartRelated( $part );

This has to stay.
>      if ( $part instanceof ezcMailMultiPartMixed )
>          return formatMailMultipartMixed( $part );
>
>        return;
> }
>
> function formatMailMultipartMixed( $part )
> {
>      foreach ( $part->getParts() as $key => $alternativePart )
>      {
>               if($alternativePart->subType == 'plain') { // only use the 
> plain part
Yes, but you need to check that it is in fact a ezcMailTextPart before you 
check the subtype.
>          $t = '';
>          $t .= formatMailPart( $alternativePart );
>                 return $t;
>               }
>      }
>
> }
>
This method can go away.
> function formatMailMultipartRelated( $part )
> {
>      foreach ( $part->getRelatedParts() as $key => $alternativePart )
>      {
>         if($alternativePart->subType == 'plain') { // only use the
> plain part
>                 $t = '';
>          $t .= formatMailPart( $alternativePart );
>                 return $t;
>                }
>      }
> }
>
This one as well.
> function formatMailMultipartDigest( $part )
> {
>      foreach ( $part->getParts() as $key => $alternativePart )
>      {
>          if($alternativePart->subType == 'plain') { // only use the
> plain part
>                       $t = '';
>                       $t .= formatMailPart( $alternativePart );
>                       return $t;
>                 }
>      }
> }

And this one..
> function formatMailRfc822Digest( $part )
> {
>       if($alternativePart->subType == 'plain') { // only use the plain part
>               $t = '';
>               $t .= formatMailpart( $part->mail );
>               return $t;
>       }
>
> }

> function formatMailMultipartAlternative( $part )
> {
>      $t = '';
>      foreach ( $part->getParts() as $key => $alternativePart )
>      {
>               if($alternativePart->subType == 'plain') { // only use the 
> plain part
correct, but check that it is a ezcMailTextPart first....                       
 
>                       $t .= formatMailPart( $alternativePart );
>                       return $t;
>               }
>        }
> }
Yes..
> function formatMailText( $part )
> {
>        if($part->subType == 'plain') {
>                $t = '';
>                $t .= "{$part->text}";
>                return $t;
>        }
> }

In other words, it looks correct to me (I might be wrong though). In other 
words I fear that it might be the messages who are wrong in the first place. 
You can check this by taking a look at the message source of the messages 
that do not parse correctly. You can see how the HTML part is identified by 
the headers. If you still have problems it'd be nice if you could include the 
message source of a message that fails.

Cheers,
Frederik
-- 
Components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/components

Reply via email to