Copy link to clipboard
Copied
I have a big string that I want to remove a part of it and save it as a new string? I've tried replace, find ect...and I dont think there is a function that allow me to do that. any ideas?
thanks
Add any lines not matching the To and From lines to a new variable.
<cfset newText="" />
<cfloop list="#email_list.body#" delimiters="#chr(13)##chr(10)#" index="line">
//* replace the whole from line with empty *//
<cfif REFindNoCase("From:.*",line)>
<cfset from_line = line />
<cfset from_line = #REReplaceNoCase("#from_line#", "From:.*", "")# />
//* replace the whole To line with empty *//
<celsefif REFindNoCase(
...Copy link to clipboard
Copied
Can you provide an explanation, with samples, of what you are trying to do? Please provide the code you've already tried. Explain what did not work: what was the expected result versus what was the actual result. Please include any error messages you received.
Copy link to clipboard
Copied
Thanks. I do not know if there is a tag or function that will work. Basically, I have text email that I use cfpop to pull out the email body
The text content as follow, So I want to get the From and the Sent out the this text and save as its own string. After I save those, I can delete them.
Thanks.
From: jane doe [mailto:jdoe@mail.com]
Sent: Thursday, September 10, 2009 1:01 PM
To: jdoe@mail.com
Subject: this is the subject line
Dear Jon Doe,
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eget varius enim. Ut nec erat quis est dignissim tincidunt. Sed ac lacus dolor. Curabitur id fringilla metus. Phasellus in justo non lacus malesuada semper quis eu libero. Donec in libero ut augue ultricies lobortis. Mauris porttitor tristique cursus. Vivamus neque leo, iaculis tincidunt tristique a, lacinia vitae sem. Nunc eget vulputate ligula. Phasellus ut arcu risus, et luctus elit. Vestibulum eu ante neque. Curabitur at massa nec lectus vehicula pretium. Nunc id eros est, sit amet pellentesque tortor. Integer et ante magna. Donec pellentesque odio vitae augue adipiscing non vestibulum nibh porttitor.
Vestibulum consectetur ligula eu elit egestas eu luctus erat bibendum. Vivamus pellentesque eleifend luctus. Curabitur id nibh id lacus adipiscing iaculis vel at neque. Ut sit amet enim sem, dignissim posuere urna. Maecenas ac elit vitae turpis sagittis tempus. Aliquam aliquam velit vitae urna tempor hendrerit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut non ligula nec tellus egestas ultricies sed eu ante. Aliquam quam mauris, bibendum id varius id, iaculis at lectus. Fusce nunc sapien, cursus sit amet consectetur vel, eleifend ac diam. Aliquam dictum tempor accumsan.
Copy link to clipboard
Copied
Try treating the entire string as a list delimited by chr(13). Output the first couple of elements. If they are the To and Sent lines, treat those lines as lists delimited by a colon. You want listrest().
Copy link to clipboard
Copied
<cfloop list="#mail_content#" delimiters="#chr(13)##chr(10)#" index="line">
<cfif REFindNoCase("from:.*",line)>
<cfset from_line = line>
</cfif>
<cfif REFindNoCase("sent:.*",line)>
<cfset sent_line = line>
</cfif>
</cfloop>
<cfoutput>
#from_line#<br>
#sent_line#
</cfoutput>
Copy link to clipboard
Copied
Thanks a lot. I am going to try this out to see what I got. After I got the 'from' and the 'sent' line, can you just remove those lines using REReplaceNoCase everything with an empty space or is there a function to remove those lines and leaving just the body of the email? Thanks again. I am going to try now.
Copy link to clipboard
Copied
Yes, you can use ReReplace or ReReplaceNoCase to remove the targeted patterns.
Copy link to clipboard
Copied
This maybe a stupid but I can't think right now. With the same idea as above, I want to remove the From and the To.
<cfloop list="#email_list.body#" delimiters="#chr(13)##chr(10)#" index="line">
//* replace the whole from line with empty *//
<cfif REFindNoCase("From:.*",line)>
<cfset from_line = line />
<cfset from_line = #REReplaceNoCase("#from_line#", "From:.*", "")# />
</cfif>
//* replace the whole To line with empty *//
<cfif REFindNoCase("To:.*",line)>
<cfset to_line = line />
<cfset to_line = #REReplaceNoCase("#to_line#", "To:.*", "")# />
</cfif>
</cfloop>
My question is how do I save the email body text with now 2 empty lines? The body text should be the same as before, minus the To and the From line.
thanks.
Copy link to clipboard
Copied
Add any lines no matching the To and From lines to a new variable.
<cfset newText="" ></cfset> <cfloop list="#email_list.body#" delimiters="#chr(13)##chr(10)#" index="line"> //* replace the whole from line with empty *// <cfif REFindNoCase("From:.*",line)> <cfset from_line = line ></cfset> <cfset from_line = #REReplaceNoCase("#from_line#", "From:.*", "")# ></cfset> //* replace the whole To line with empty *// <celsefif REFindNoCase("To:.*",line)> <cfset to_line = line ></cfset> <cfset to_line = #REReplaceNoCase("#to_line#", "To:.*", "")# ></cfset> <cfelse> <!--- if not removing line add to newText string ---> <cfset newText=newText & line & chr(13) & chr(10) ></cfset> </cfif> </cfloop> <cfoutput>#newText#</cfoutput> <!--- email text without to and from lines ---
Copy link to clipboard
Copied
can you clarify a little bit more? thanks.
Copy link to clipboard
Copied
Add any lines not matching the To and From lines to a new variable.
<cfset newText="" />
<cfloop list="#email_list.body#" delimiters="#chr(13)##chr(10)#" index="line">
//* replace the whole from line with empty *//
<cfif REFindNoCase("From:.*",line)>
<cfset from_line = line />
<cfset from_line = #REReplaceNoCase("#from_line#", "From:.*", "")# />
//* replace the whole To line with empty *//
<celsefif REFindNoCase("To:.*",line)>
<cfset to_line = line />
<cfset to_line = #REReplaceNoCase("#to_line#", "To:.*", "")# />
<cfelse>
<!--- if not removing line add to newText string --->
<cfset newText=newText & line & chr(13) & chr(10) />
</cfif>
</cfloop>
<cfoutput>#newText#</cfoutput> <!--- email text without to and from lines --->
This was truncated when I posted it previously.
Copy link to clipboard
Copied
<!--- obtain from-line and to-line as before --->
<cfloop list="#mail_content#" delimiters="#chr(13)##chr(10)#" index="line">
<cfif REFindNoCase("from:.*",line)>
<cfset from_line = line>
</cfif>
<cfif REFindNoCase("to:.*",line)>
<cfset to_line = line>
</cfif>
</cfloop>
<!--- delete from-line and to-line from the text --->
<cfset mail_content1 = replaceNoCase(mail_content,from_line,"")>
<cfset mail_content2 = replaceNoCase(mail_content1,to_line,"")>
<cfoutput>
<strong>from-line:</strong> #from_line#<br>
<strong>to-line:</strong> #to_line#<br><br>
<strong>Mail text without from-line and to-line:</strong><br>
<!--- Use pre tag to get a display close to the original --->
<pre>#mail_content2#</pre>
</cfoutput>
Copy link to clipboard
Copied
another method to correctly get the content, but a bit tricky. See code below.
<cfset emailvar = "From: jane doe Sent: Thursday, September 10, 2009 1:01 PM">
<cfset fromPos = findnocase("From:",emailvar)>
<cfset toPos = findnocase("Sent:",emailvar) - (fromPos + 5)>
<cfoutput>
between from and to : #mid(emailvar,fromPos+5,toPos)#<br />
</cfoutput>
using the findnocase you can get the position and use mid get the characters between the two points.
-Prasanth
Copy link to clipboard
Copied
You could also use regular expression match lines starting with "From" and containing text that looks like an email address.
<cfsavecontent variable="emailText">
From: jane doe [mailto:jdoe@mail.com]
Sent: Thursday, September 10, 2009 1:01 PM
To: jdoe@mail.com
Subject: this is the subject line
Dear Jon Doe,
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eget varius enim. Ut nec erat quis est dignissim tincidunt. Sed ac lacus dolor. Curabitur id fringilla metus. Phasellus in justo non lacus malesuada semper quis eu libero. Donec in libero ut augue ultricies lobortis. Mauris porttitor tristique cursus. Vivamus neque leo, iaculis tincidunt tristique a, lacinia vitae sem. Nunc eget vulputate ligula. Phasellus ut arcu risus, et luctus elit. Vestibulum eu ante neque. Curabitur at massa nec lectus vehicula pretium. Nunc id eros est, sit amet pellentesque tortor. Integer et ante magna. Donec pellentesque odio vitae augue adipiscing non vestibulum nibh porttitor.
Vestibulum consectetur ligula eu elit egestas eu luctus erat bibendum. Vivamus pellentesque eleifend luctus. Curabitur id nibh id lacus adipiscing iaculis vel at neque. Ut sit amet enim sem, dignissim posuere urna. Maecenas ac elit vitae turpis sagittis tempus. Aliquam aliquam velit vitae urna tempor hendrerit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut non ligula nec tellus egestas ultricies sed eu ante. Aliquam quam mauris, bibendum id varius id, iaculis at lectus. Fusce nunc sapien, cursus sit amet consectetur vel, eleifend ac diam. Aliquam dictum tempor accumsan.
</cfsavecontent>
<cfset fromMatches=ReMatch(".{0,1}From\: [ \w\[\]\:@\.,;]*", emailText) />
<cfif ArrayLen(fromMatches) gt 0>
<cfoutput>
<cfloop from="1" to="#ArrayLen(fromMatches)#" index="idx">
#Trim(Right(fromMatches[idx], Len(fromMatches[idx]) - 6))# <!--- omit "From: " to get the name and email address --->
</cfloop>
</cfoutput>
<cfelse>
NO MATCHES FOUND
</cfif>