drgoel
New Member
Joined: 08/08/08
Posts: 3 |
Edit Email Attributes - Enhanced code attached
08/19/08 2:28 PM
Hi Raymond,
I saw your blog entry about spoolmail and found it very useful. I had an interesting need to deploy it on our production server as opposed to a local dev server. For a variety of reasons we had bad email addresses and hence mails would go into the undelivered folder. Ideally we should have been fixing this issue at the source rather than at the end of the cycle. But this was not possible, and hence a modification/add-on to your spoolmail extension was made.
The modification now allows to edit the “Server”, “From”, “To”, “CC” and “BCC” attributes of the mail. There are two options upon making changes. “Edit”, saves the changes and keeps the file in the undelivr folder, “Resend” saves the changes and moves the file to the spool folder.
All details on changes and notes are given below and attached:
Files modified: bottom.cfm, index.cfm
File added: ReplaceAtNoCase.cfm (http://www.cflib.org/udf/ReplaceAtNoCase)
Testing done: On text emails with and without attachments
Special Notes: I used ColdFusion Standard 8.01 to test this out. When I re-spooled my edited email files, I came across error messages as described in the hotfix below. After applying the patch, the mails are successfully being sent out.
http://kb.adobe.com/selfservice/viewContent.do?externalId=kb403683&sliceId=1
Would love some feedback and possibility of you adding it to the spoolmail project.
index.cfm:
<cfif not directoryExists(application.maildir)>
<cfoutput>
<h2>Sorry!</h2>
<p>
Something has gone wrong. I cann't seem to find your undelivered folder at:<br />
#maildir#
</p>
</cfoutput>
<cfabort>
</cfif>
<cfoutput>
<html>
<head>
<frameset rows="250,*" resizeable="true" >
<frame src="top.cfm" marginheight="0" marginwidth="0" id="top">
<frame src="bottom.cfm" marginheight="0" marginwidth="0" name="bottom" id="bottom">
</frameset>
</head>
<body></body>
</html>
</cfoutput>
bottom.cfm:
<cfif not structKeyExists(url, "mail")>
<cfabort>
</cfif>
<cfset mail = getMail(url.mail)>
<!--- Only if Edit form action happens --->
<cfif StructKeyExists(Form, "Edit") OR StructKeyExists(Form, "Resend")>
<cfinclude template="ReplaceAtNoCase.cfm"> <!--- UDF --->
<cffile action="read" file="#application.maildir#/#url.mail#" variable="EditedMail">
<!--- Only if "server" address is changed --->
<cfif form.Mail_Server NEQ form.Mail_Server_orig>
<cfset MailServerPosition = reFindNoCase("(?m)^server: (.*?)\n", EditedMail, 1, 1)>
<cfset EditedMail = ReplaceAtNoCase(EditedMail, form.Mail_Server_orig, form.Mail_Server,MailServerPosition.pos[2], "ONE")>
</cfif>
<!--- Only if "from" address is changed --->
<cfif form.MailSender NEQ form.MailSender_orig>
<cfset MailSenderPosition = reFindNoCase("(?m)^from: (.*?)\n", EditedMail, 1, 1)>
<cfset EditedMail = ReplaceAtNoCase(EditedMail, form.MailSender_orig, form.MailSender,MailSenderPosition.pos[2], "ONE")>
</cfif>
<!--- Only if "to" address is changed --->
<cfif form.MailTo NEQ form.MailTo_orig>
<cfset MailToPosition = reFindNoCase("(?m)^to: (.*?)\n", EditedMail, 1, 1)>
<cfset EditedMail = ReplaceAtNoCase(EditedMail, form.MailTo_orig, form.MailTo,MailToPosition.pos[2], "ONE")>
</cfif>
<!--- Only if "cc" address exists and is changed --->
<cfif structKeyExists(Form, "MailCC")>
<cfif form.MailCC NEQ form.MailCC_orig>
<cfset MailCCPosition = reFindNoCase("(?m)^cc: (.*?)\n", EditedMail, 1, 1)>
<cfset EditedMail = ReplaceAtNoCase(EditedMail, form.MailCC_orig, form.MailCC,MailCCPosition.pos[2], "ONE")>
</cfif>
</cfif>
<!--- Only if "bcc" address exists and is changed --->
<cfif structKeyExists(Form, "MailBCC")>
<cfif form.MailBCC NEQ form.MailBCC_orig>
<cfset MailBCCPosition = reFindNoCase("(?m)^bcc: (.*?)\n", EditedMail, 1, 1)>
<cfset EditedMail = ReplaceAtNoCase(EditedMail, form.MailBCC_orig, form.MailBCC,MailBCCPosition.pos[2], "ONE")>
</cfif>
</cfif>
<cfif StructKeyExists(Form, "Edit")>
<cffile action="write" nameconflict="OVERWRITE" file="#application.maildir#/#url.mail#" output="#EditedMail#">
<cfset mail = getMail(url.mail)>
</cfif>
<cfif StructKeyExists(Form, "Resend")>
<cffile action="write" nameconflict="OVERWRITE" file="#application.spooldir#/#url.mail#" output="#EditedMail#">
<cffile action="delete" file="#application.maildir#/#url.mail#">
Mail has been resent!
<script language="javascript">
parent.document.getElementById('top').src='top.cfm';
</script>
<cfabort>
</cfif>
</cfif>
<cfif mail.type is "text">
<cfset mailbody = activateURL(trim(mail.body),"_new")>
<cfelse>
<cfset mailbody = trim(mail.body)>
</cfif>
<cfoutput>
<style>
h2 {
font-family: Arial;
}
p, td {
font-family: Arial;
}
pre {
font-family: Courier;
}
</style>
</cfoutput>
<!--- Display mail. --->
<cfoutput>
<form name="frmEditEmail" action="bottom.cfm?mail=#url.mail#" target="_self" method="post">
<table>
<tr>
<td><b>Filename:</b></td>
<td>#mail.filename#</td>
<td></td>
<td></td>
</tr>
<tr>
<td><b>Server:</b></td>
<td>#mail.server#</td>
<td></td>
<td>
<input type="Text" name="Mail_Server" value="#mail.server#">
<input type="hidden" name="Mail_Server_orig" value="#mail.server#">
</td>
</tr>
<tr>
<td><b>From:</b></td>
<td><a href="mailto:#mail.sender#">#HTMLEditFormat(mail.sender)#</a></td>
<td></td>
<td>
<input type="Text" name="MailSender" value="#mail.sender#">
<input type="hidden" name="MailSender_orig" value="#mail.sender#">
</td>
</tr>
<tr>
<td><b>Subject:</b></td>
<td>#HTMLEditFormat(mail.subject)#</td>
<td></td>
<td></td>
</tr>
<tr>
<td><b>To:</b></td>
<td><a href="mailto:#mail.to#">#HTMLEditFormat(mail.to)#</a></td>
<td></td>
<td>
<input type="Text" name="MailTo" value="#mail.to#">
<input type="hidden" name="MailTo_orig" value="#mail.to#">
</td>
</tr>
<cfif structKeyExists(mail, "cc")>
<tr>
<td><b>CC:</b></td>
<td>#HTMLEditFormat(mail.cc)#</td>
<td></td>
<td>
<input type="Text" name="MailCC" value="#mail.cc#">
<input type="hidden" name="MailCC_orig" value="#mail.cc#">
</td>
</tr>
</cfif>
<cfif structKeyExists(mail, "bcc")>
<tr>
<td><b>BCC:</b></td>
<td>#HTMLEditFormat(mail.bcc)#</td>
<td></td>
<td>
<input type="Text" name="MailBCC" value="#mail.bcc#">
<input type="hidden" name="MailBCC_orig" value="#mail.bcc#">
</td>
</tr>
</cfif>
<cfif structKeyExists(mail, "attachments") and arrayLen(mail.attachments)>
<tr valign="top">
<td><b>Attachments:</b></td>
<td>
<cfloop index="x" from="1" to="#arrayLen(mail.attachments)#">
<cfif application.allowdownload>
<a href="download.cfm?filename=#urlEncodedFormat(mail.attachments[x])#">#mail.attachments[x]#</a><br />
<cfelse>
#mail.attachments[x]#<br />
</cfif>
</cfloop>
</td>
<td></td>
<td></td>
</tr>
</cfif>
<tr>
<td><b>Sent:</b></td>
<td>#dateFormat(mail.sent)# #timeFormat(mail.sent)#</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td colspan="2"><input type="Submit" name="Edit" value="Edit"></td>
<td><input type="Submit" name="Resend" value="Resend"></td>
</tr>
</form>
</table>
<hr />
<cfif mail.type is "text">
<pre>
#mailbody#
</pre>
<cfelseif mail.type is "multipart">
#replace(activateURL(mail.plain,"_new"),"#chr(10)#","<br>","all")#
<hr>
#mail.html#
<cfelse>
#mailbody#
</cfif>
</cfoutput>
|