WOW alex. I KNEW their had to be a different and MUCH BETTER way to  
do this.
Now if I wanted to move the file from the /tmp folder to say an  
images directory or even into the database itself, Can I do that  
within the loop. or does it have to happen sooner before its parsed?

Thank you so much for this assistance!




On Jul 24, 2007, at 11:54 AM, Alexandru Stanoi wrote:

> Dave Fischetti wrote:
>>> 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.
>
> Hi Dave,
>
> To get the text/plain part of mails is easy:
>
> <code>
> $pop3 = new ezcMailPop3Transport( "mail.mydomain.com" );
> $pop3->authenticate( "[EMAIL PROTECTED]", "mypass" );
>
> $set = $pop3->fetchAll();
> $parser = new ezcMailParser();
> $mails = $parser->parseMail( $set );
>
> foreach ( $mails as $mail )
> {
>     $parts = $mail->fetchParts();
>     foreach ( $parts as $part )
>     {
>         if ( get_class( $part ) === 'ezcMailText' )
>         {
>             echo $part->text;
>         }
>     }
> }
> </code>
>
> This code will go through all the parts of all the mails and only  
> display the text part of each.
>
> Some messages have more text parts (for example one text part and  
> one html part), which are all seen as ezcMailText objects. To  
> differentiate between text and html parts you can analyze $part- 
> >subType. Html text parts have 'html' in $part->subType, and plain  
> text parts have 'plain'. The code will look like this:
>
> <code>
> // ...
>         if ( get_class( $part ) === 'ezcMailText' && $part->subType  
> === 'plain' )
>         {
>             echo $part->text;
>         }
> </code>
>
> To see if the mail has attachments, in the same loop you can check  
> for ezcMailFile objects:
>
> <code>
> foreach ( $mails as $mail )
> {
>     $parts = $mail->fetchParts();
>     foreach ( $parts as $part )
>     {
>         if ( get_class( $part ) === 'ezcMailText' )
>         {
>             echo $part->text;
>         }
>
>       if ( get_class( $part ) === 'ezcMailFile' )
>       {
>           echo "Attachment: " . $part->fileName;
>       }
>     }
> }
> </code>
>
> Hope this helps.
>
> Cheers,
> Alex.
>
> -- 
> Alexandru Stanoi
> eZ Components System Developer
> eZ Systems | http://ez.no

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

Reply via email to