Skip to main content
Inspiring
March 10, 2008
Question

Parsing text file

  • March 10, 2008
  • 3 replies
  • 343 views
Greetings,

Could someone point me to a right direction, I am trying to grab To: email of the orignal email from Undeliverable Email text files which look like this:

Received: from scout.com by
with SMTP (Code-Crafters Ability Mail Server 2.61);
Sat, 08 Mar 2008 01:30:20 -0600
From: <admin@scout.com>
To: <admin@scout.com>
Subject: Mail System Error - Undeliverable Mail
Date: Sat, 08 Mar 2008 01:30:20 -0600
Message-ID: <5276787816.20080308013020@DOMAIN>
MIME-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

The following mail failed to be delivered...

From: admin@scout.com
Sent: Fri, 7 Mar 2008 22:30:20 -0600 CST
Subject: Search Results
To:-
Geston2@Juno.com - Rejected with: 550 Access denied...102da5f5dcf5454508c8dc=
48c8c9f861f8c9c14dd5b14c7d6d6549b16da1091c691cc51cc5a18c6c9c2525e5...

Thank you!
This topic has been closed for replies.

3 replies

Participating Frequently
March 13, 2008
Use regular expressions, much faster:

<cfset match=reFindNoCase("\sto:\s+([^\s]+)\s",fileContent,1,true)>
<cfif match.pos[1]>
<cfset email=mid(fileContent,match.pos[2],match.len[2])>
</cfif>
TiGGiAuthor
Inspiring
March 12, 2008
thanks I will give it a try.
Participant
March 11, 2008
Hi TiGGi

First read the textfile with cffile action="read"

After that, search for the Position of the "To: <" inside the String with FindNoCase. This will return the position of the first occurence of this substring.
If you're used to regular expressions, you can search for the Pattern of the "To: <admin@scout.com>" line with a regular expression. Use REFindNoCase. I think this is the better way, but more complicated.

If you have the position of the substring, you can extract the Email adress using the Mid function.

I hope this helps.