Coldfusion Email Parser

Posted on 2005-04-14
Last Modified: 2013-12-24
Hi All,

I am looking for some suggestions on what tags to use to create an email parser in Coldfusion.

I would like to do the following:

I have a mail script that sends information to an email address in the form of:

form_input_name1: data value1
form_input_name2: data value2
form_input_name3: data value3

I would like to write some Coldfusion code to check an email box and parse each email to discover where the email is from (it's sender address) and then get the data out of each line. Each email would obviously have the same layout (as far as form_input_name's go), with just the data values changing.

After an email has been parsed I will just use the CFMAIL tag to forward the email address on to its next home and then delete the email from the box on the server that I'm checking.

I would rate my CF coding skills at probably around intermediate but am unsure as to where to begin with this idea.

Thanks for your suggestions.

Question by:bradderick
    LVL 7

    Accepted Solution

    Start with splitting text into lines (assuming that lines end with CR-LF):

    <cfset emailText=Replace(emailText, chr(13), "", "ALL")>
    <cfset emaiText=ListToArray(emailText, chr(10))>

    Loop thru array and parse every line:

    <cfloop index="i" from="1" to="#ArrayLen(emailText)#">
       <!--- Check, if this is NAME:VAL format --->
       <cfset row=ListToArray(emailText[i], ":")>
       <cfif ArrayLen(row) EQ 2>
          <!--- Check first element for the value name --->
          <cfswitch expression="#row[1]#">
             <!--- PRocess keywords --->
             <cfcase value="form_field_1">
                <cfset form_field_1_value=row[2]>
              . . . . . . . . . . . . . . . .


    Author Comment

    Thanks thats really helpful. It has given me some great ideas to move forward with :o)


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
    Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
    The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
    The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now