Coldfusion, CFPOP , To & From Fields.

tomhwtt
tomhwtt used Ask the Experts™
on
Hi..

I am retrieving emails using CFPOP.

When it returns the "To" and "From" fields I want it to just be the email address so I can setup a reply action.

Right now I get:

to:<margesimpson@thesimpsons.com>
from:"Homer Simpson" <homersimpson@thesimpsons.com>

How can I make sure it returns just the email address instead?  ...or can I strip the stuff I don't need?

Can I just remove all characters before and after <  &  >   ??

The code is below.

Thank you for any assistance!

Tom



<cfpop action="getall" name="getMessage" server="myserver" username="myusername" password="mypassword" port="port>
 
<cfscript>
function pformat(str)
{
str = replace(str,chr(13)&chr(10),chr(10),"ALL");
str = replace(str,chr(13),chr(10),"ALL");
str = replace(str,chr(9),"&nbsp;&nbsp;&nbsp;","ALL");
return replace(str,chr(10),"<br>","ALL");
}
</cfscript>
 
 
<cfoutput query="getMessage">
to:#HTMLEditFormat(getMessage.to)#<br>
from:#HTMLEditFormat(getMessage.from)#<br>
UID:#HTMLEditFormat(getMessage.uid)#<br>
subject:#HTMLEditFormat(getMessage.subject)#<br><br>
BODY:<br><br>
#pformat(getMessage.body)#
 
</cfoutput>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
OK... I got it worked out.  Here is my crude attempt at it.  \

It works, but I am sure there is an easier way :)  Please feel free to post if you have one.

Thank You

Tom
<cfset rawStartFrom = replace(#getMessage.from#,"<","+","ALL")>
<cfset rawEndFrom = replace(#rawStartFrom#,">","-","ALL")>
<cfset startFrom = listFirst(#rawEndFrom#,'+')>
<cfset endFrom = listLast(#rawEndFrom#,'-')>
 
<cfset startNum = (#len(startFrom)#) + 1>
 
<cfset endNum = #len(endFrom)# - #len(startFrom)#>
 
<cfset startChar = removechars(#rawEndFrom#,1,#startNum#)>
 
<cfset endChar = removeChars(#startChar#,#endNum#,1)>
 
to:#HTMLEditFormat(getMessage.to)#<br>
from:<br>
subject:#HTMLEditFormat(getMessage.subject)#<br><br>
BODY:<br><br>
#pformat(getMessage.body)#
 
Start:#rawStartFrom#<br />
How many is Start: #len(startFrom)#<br />
Finish:#rawEndFrom#<br />
How many is End: #len(endFrom)#<br />
 
#endChar#  <!--- Final Outcome is just the email address --->

Open in new window

What are you trying to do here:

My Assumption:

1.You can use the reply parameter of the Coldfusion Cfmail tag and add the email address which you want to if it is dynamic you can adf the from value in the reply link. Whenever the user clicks the reply button it will send the email to the emailAddress specified by you in the cfmail reply parameter. The email will go no matter if it full address like the same you have in the FROM value.

Glad you made it work and now i understood what exactly you were trying to do:

You can also use the rereplace functionality to get only email address

Author

Commented:
Thanks, myselfrandhawa:..

I cleaned it up a little more today.  Not sure what I was thinking last night...I just needed to rest my brain maybe :)

Cleaned up code below.  I am going to try rereplace as you suggest as well. Thanks again.

Tom
<cfset startFrom = listFirst(#getMessage.from#,'<')>
<cfset endFrom = listFirst(#getMessage.from#,'>')>
 
<cfset startNum = (#len(startFrom)#) + 1>
<cfset endNum = #len(endFrom)# - #len(startFrom)#>
 
<cfset startChar = removechars(#getMessage.from#,1,#startNum#)>
<cfset endChar = removeChars(#startChar#,#endNum#,1)>
 
<cfset emailAddress = #trim(endChar)#><!---just email address--->

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial