|
Grimoire /
TFMailExtending the functionality of TFMailMany, many years ago, there was a site called Matt's Script Archive, a repository of all sorts of interesting and useful CGI scripts in a developing web. Unfortunately, the scripts were buggy, poorly designed, and open to various exploits. May of these scripts were re-written from scratch by the London Perl Mongers, designed for the same functionality, but well coded, and much more secure. The script I make most use of is TFMail, a general HTML form to email script. It fulfills most form requirements, and is one that I trust. However, recently I had need to send a more elaborate email from my form. Rather than a simple text email, I needed to send a MIME attachment, and the data within that attachment needed to be generated using data contained within the HTML form. I had assumed that this would be easy, as TFMail uses MIME::Lite. I was wrong! The standard version cannot do this. Which is a bit like having a hybrid engine in your new motor car, and the manufacturers forgetting to install a fuel tank, so that it can only run on one fuel alone. Yes, it works, but it cannot fulfil it's full potential... So, this is my attempt to rectify this. WARNING: I, like the author of FormMail, cannot code perl well. The authors of TFMail have created a well designed and fully audited piece of code. This ammended version is a hack, probably contains bugs and bad coding practices, and should not be used without the user being aware that this is probably a retrograde step in terms of security. In particular, I am likely to code it so that it can be expressly configured to do bad things®. This is intentional. The Patch FileCoding is about 70% complete at the moment, so sadly there is nothing available to download yet. The remaining work required is code cleanup and formatting, and minor adjustments. There is 1 bug outstanding, related to the recursive descent of directories (Files are silently discarded). The cause of this has been isolated - the solution is not so simple! UsageIt is assumed that you have a fully working installation of TFMail, and simply want to extend the configuration to send attachments. The patch is designed to be a simple 'drop-in' replacement for the original TFmail.pl script. Obviously, in your TFmail.pl user configuration section, you will have the line: use constant USE_MIME_LITE => 1; Configuration FileConfiguration is (almost) non-existant - everything should work exactly as before. To add a MIME multipart container to an email, simply create a new directory in the directory where you store the config files, with the same name as the '_config' variable. Anything placed within this sub-directory will be included in your email. If there is a text-file called MIME.cfg (case sensitive), this will afect the various attachments. It takes the following form: File-1.txt: Id=abc123 Parse=email File-2.htm: Id=def456 Parse=html Additional containers can be created by creating a subdirectory with the name corresponding to the container type (suffixes are ignored, and can be used to differentiate multiple containers of the same type). For example: to create a multipate/alternative, mkdir alternative.001 Issues / ToDo
Example / Demo
MIME Structure
BugsWhat bugs? They're quirks! ;-) ThanksTo the London Perl Mongers, for providing the original script. |