Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

December 4, 2007

Extracting last email body and not all previous replies/forwards/etc.

Question:

Is there an easy (consistent) way to extract only the last message from the mail body and not all previous replies/forwards/etc.

Answer:
It depends on whether the structure has been maintained in the MIME source of the email. The email.Body property will return the first plain-text or HTML body encountered in the email. If the previous replies/forwards are maintained in the MIME as separate MIME parts, then the Body property will return only the last message. However, some email programs glob them together in a single MIME part. For example, have a look at this MIME:

Content-class: urn:content-classes:message
Subject: RE: This is a test email
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="<strong>—-_=_NextPart_003_01C8367E.40AA7030</strong>"
X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0
Date: Tue, 4 Dec 2007 14:02:05 -0000
Message-ID: <D89E01A7E08F08409310FE7A7DCAD30826480E@chilkatsoft.com>
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
Thread-Topic: This is a test email
Thread-Index: Acg2fbwxDsOq9q5TSuKKqphGKxZsVwAAAYLgAAAC2NAAAANy0A==
From: "Test Support" <testsupport@chilkatsoft.com>
To: "Chilkat" <admin@chilkatsoft.com>
	
This is a multi-part message in MIME format.
	
<strong>——_=_NextPart_003_01C8367E.40AA7030</strong>
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
	
This=20is=20a=20test=20message
	
—–Original=20Message—–
From:=20Chilkat=20Support=20
Sent:=2004=20December=202007=2014:02
To:=20Test=20Support
Subject:=20RE:=20This=20is=20a=20test=20email
	
So=20can=20you=20help?=20-=20message=203
	
—–Original=20Message—–
From:=20Test=20Support=20
Sent:=2004=20December=202007=2014:01
To:=20Chilkat=20Support
Subject:=20RE:=20This=20is=20a=20test=20email
	
Thankyou=20for=20this=20-=20message=202
	
—–Original=20Message—–
From:=20Chilkat=20Support=20
Sent:=2004=20December=202007=2014:01
To:=20Test=20Support
Subject:=20This=20is=20a=20test=20email
	
Please=20help=20me=20-=20message=201
	
=20
	

The boundary of the first MIME sub-part is —-_=_NextPart_003_01C8367E.40AA7030

The content looks as if it has multiple parts, but the string —–Original=20Message—– is not part of the MIME structure of this message. Therefore the Body property contains all of this text. The original replies have all been globbed into a single MIME part. Therefore, your application will need to parse it — if it so chooses. The reason Chilkat cannot parse it is because there is no way of knowing what separator string may have been used. There is nothing to programmatically indicate that "—–Original=20Message—–" is a separator.


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.