> Date: Tue, 24 Jul 2007 11:11:15 +0200
> From: Frederik Holljen <[EMAIL PROTECTED]>
> Subject: Re: [Components] Only Parsing text/plain part of message
> To: [email protected]
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain;  charset="iso-8859-1"
>
> On Tuesday 24 July 2007 02:02, Dave Fischetti wrote:
>> Hmm. I guess I'm a bit confused.
>>
>> As a test, I am trying to just display the text/plain part of the
>> message only. But my real goal is save that info into a database.
>>
>> I've tried manipulating the example in the link mentioned below to
>> try and just display that part of the message. For some messages it
>> works, but for others is showing still the HTML and plain text
>> versions. So I assume I'm parsing it wrong. I was hoping you might be
>> able to shed some light on the proper way to do that.
>>
>> Thanks for the response.
>
> I think you need to provide some code in order for us to see what  
> you're doing
> wrong. There is not a real "proper" way to do that as it depends on  
> what your
> application is trying to do.
>
> Cheers,
> Frederik
>

Yes, I agree thats probably the best next step. Here is what I"m  
working on:
I just feel that because I don't fully understand the process EZc  
goes through to gather these parts... I could probably be doing this  
more efficiently. All I really need is the plain/text part. (and  
later down the road I may have to see if there are any file  
attachments.)

Thanks for taking a look a this.



<?php
require ($_SERVER['DOCUMENT_ROOT'] . "/util/lib/functions.php");
require ($_SERVER['DOCUMENT_ROOT'] . "/util/db/db_config.inc.php");

set_include_path( "/usr/include/php/ezcomponents-2007.1:" . ini_get 
( "include_path" )  );

require_once "Base/src/base.php"; // dependent on installation  
method, see below
function __autoload( $className )
{
     ezcBase::autoload( $className );
}


// Create a new POP3 transport object by specifying the server name
$pop3 = new ezcMailPop3Transport( "mail.mydomain.com" );

// Authenticate to the POP3 server
$pop3->authenticate( "[EMAIL PROTECTED]", "mypass" );

// Fetch all messages on the server
$set = $pop3->fetchAll();

// Create a new mail parser object
$parser = new ezcMailParser();

// Parse the set of messages retrieved from the server
$mail = $parser->parseMail( $set );

// 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 );
        
        // CHECK MAIL BODY and if valid,
        // INSERT VALUES INTO DATABASE HERE


        // DELETE MAIL FROM SERVER
        
}
// END CYCLING THROUGH MAIL


// BEGIN MAIL FUNCTIONS

function formatToAddress( $addresses )
{
     foreach ( $addresses as $address )
     {
                  list($too,$ext) = split('@', formatAddress($address));
                  if ($ext == "mydomain.com") {
                        return formatAddress($address);
                  }
     }
}

function formatAddress( $address )
{
     return "{$address->email}";
}


function formatMailPart( $part )
{
        
     if ( $part instanceof ezcMailText )
         return formatMailText( $part );

     if ( $part instanceof ezcMailFile ) // do I need this?
         return;

     if ( $part instanceof ezcMailRfc822Digest ) // do I need this?
         return formatMailRfc822Digest( $part );

     if ( $part instanceof ezcMailMultiPart )
         return formatMailMultipart( $part );
                
         return;
}

function formatMailMultipart( $part )
{
     if ( $part instanceof ezcMailMultiPartAlternative )
         return formatMailMultipartAlternative( $part );

     if ( $part instanceof ezcMailMultiPartDigest )
         return formatMailMultipartDigest( $part );

     if ( $part instanceof ezcMailMultiPartRelated )
         return formatMailMultipartRelated( $part );

     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
         $t = '';
         $t .= formatMailPart( $alternativePart );
                  return $t;
                }
     }

}

function formatMailMultipartRelated( $part )
{
     foreach ( $part->getRelatedParts() as $key => $alternativePart )
     {
        if($alternativePart->subType == 'plain') { // only use the  
plain part
                  $t = '';
         $t .= formatMailPart( $alternativePart );
                  return $t;
                 }
     }
}

function formatMailMultipartDigest( $part )
{
     foreach ( $part->getParts() as $key => $alternativePart )
     {
         if($alternativePart->subType == 'plain') { // only use the  
plain part
                        $t = '';
                        $t .= formatMailPart( $alternativePart );
                        return $t;
                  }
     }
}

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
                        $t .= formatMailPart( $alternativePart );
                        return $t;
                }
         }
}

function formatMailText( $part )
{       
         if($part->subType == 'plain') {
                 $t = '';
                 $t .= "{$part->text}";
                 return $t;
         }
}


?>

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

Reply via email to