Hey Everyone...
Quick Question, I am parsing only the plain text part of the email
(ignoring everything else). But I noticed that with some senders
(specifically SprintPCS in the US) no PART is defined in the email.
For example this is the source of an email I received:
////// ////// ////// ////// START -- EMAIL RAW
SOURCE ////// ////// ////// //////
Return-Path: <[EMAIL PROTECTED]>
Delivered-To: [EMAIL PROTECTED]
Received: (qmail 15735 invoked from network); 14 Sep 2007 19:43:21 -0400
Received: from smtp1.mo.bulk.sprintpcs.com (HELO
mx.messaging.sprintpcs.com) (10.1.1.1)
by mydomain.com with SMTP; 14 Sep 2007 19:43:21 -0400
Received-SPF: none (mydomain.com: domain at messaging.sprintpcs.com
does not designate permitted sender hosts)
Received: from messaging.sprintpcs.com (lxnsmssf5-
vip.nmcc.sprintspectrum.com [10.1.1.1])
by mx.messaging.sprintpcs.com (Postfix) with SMTP id DDEC3F83CC
for <[EMAIL PROTECTED]>; Fri, 14 Sep 2007 18:40:49 -0500 (CDT)
From:[EMAIL PROTECTED]
To:[EMAIL PROTECTED]
Subject:
X-OPWV-Extra-Message-Type:MO
Message-Id: <[EMAIL PROTECTED]>
Date: Fri, 14 Sep 2007 18:40:49 -0500 (CDT)
Some message here
////// ////// ////// ////// END -- EMAIL RAW
SOURCE ////// ////// ////// //////
So using the following is ignoring the email all together. I would
like the body of the message above.
if ( get_class( $part ) === 'ezcMailText' && $part->subType ===
'plain' )
What would I do in a case like this?
Thanks,
Fish
><>
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