Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

Coldfusion Email Parser

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.

1 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]>
          . . . . . . . . . . . . . . . .

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


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now