I'm not 100% sure all this code will work w/ CF5, but this is what I use. The 
JS is thanks to a UDF written by Ray Camden

this code pulls all emails from an inbox and searches for anything that I've 
identified as a bounceback. Then it uses the UDF to find the email and then I 
add that email address to a list. This also delete out of office emails from 
the inbox.

Hopefully this helps,
Matt

<cfpop server="" username="" password="" action="getAll" name="getAllMail">
<cfset DeleteOrder = ''>
<cfoutput>
        <cfset Email_List = '' /><!--- set a variable to hold the list of all 
the emails --->
        <cfloop query="getAllMail">
                <cfif FROM CONTAINS 'postmaster' OR FROM CONTAINS 
'MAILER-DAEMON' OR FROM CONTAINS 'Mail Delivery' OR Body CONTAINS 'Failed' OR 
Body CONTAINS 'no longer with' OR Body CONTAINS 'Notice'>
                        <cfset emailList = Body />
                        <cfscript>
                        function getEmails(str) {
                                var email = 
"(['_a-z0-9-]+(\.['_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name|jobs|travel)))";
                                var res = "";
                                var marker = 1;
                                var matches = "";
                                
                                matches = reFindNoCase(email,str,marker,marker);
                        
                                while(matches.len[1] gt 0) {
                                        res = 
listAppend(res,mid(str,matches.pos[1],matches.len[1]));
                                        marker = matches.pos[1] + 
matches.len[1];
                                        matches = 
reFindNoCase(email,str,marker,marker);                
                                }
                                return res;
                        }
                        </cfscript>
                        <cfloop list="#getEmails(emailList)#" index="k">        
        
                                <cfif NOT ListFind(Email_List,k)>
                                        <cfdump var="#k#"><br />        
                                        <cfquery 
datasource="Corporate_Production">
                                        INSERT INTO InvalidEmails (TextBody)
                                        VALUES ('#Trim(k)#')
                                        </cfquery>
                                        <cfset DeleteOrder = 
ListPrepend(DeleteOrder, MessageNumber)>
                                        <cfset Email_List = 
ListAppend(Email_List,k) />
                                </cfif>
                        </cfloop>
                <!--- Delete out of office emails --->
                <cfelseif Body CONTAINS 'Out of Office' OR Subject CONTAINS 
'Out of Office'>
                        <cfset DeleteOrder = ListPrepend(DeleteOrder, 
MessageNumber)>
                <cfelseif Body CONTAINS 'Out of the Office' OR Subject CONTAINS 
'Out of the Office'>
                        <cfset DeleteOrder = ListPrepend(DeleteOrder, 
MessageNumber)>
                <cfelseif Body CONTAINS 'Reply' OR Subject CONTAINS 'Reply'>
                        <cfset DeleteOrder = ListPrepend(DeleteOrder, 
MessageNumber)>
                <cfelseif Body CONTAINS 'Delay' OR Subject CONTAINS 'Delay'>
                        <cfset DeleteOrder = ListPrepend(DeleteOrder, 
MessageNumber)>
                </cfif>
        </cfloop>
</cfoutput>
<cfif DeleteOrder NEQ ''>
        <cfset Count = 0 />
        <cfloop list="#DeleteOrder#" delimiters="," index="i">
                <cfpop server="" username="" password="" action="delete" 
messagenumber="#i#" name="deleteMail">
                <cfset Count = Count + 1 />
        </cfloop>
        <br /><cfdump var="#Count#"> EMAILS FOUND
</cfif>
<cfquery>
DELETE FROM ML_EMAILS WHERE EMAIL IN (SELECT TEXTBODY FROM INVALIDEMAILS)
</cfquery>
<cfquery>
DELETE FROM INVALIDEMAILS
</cfquery>



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:346951
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to