PmWiki


TFMail

Extending the functionality of TFMail

Many, 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 File

Coding 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!

Usage

It 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 File

Configuration 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

  • Currently, this script attaches parts in a one-dimensional list under the main body of the message. It does not support nested attachments. Would we want this? How might it be achieved?
  • I need a good example of a nice, useful email which uses nested attachments properly.
  • Currently the reference to the config-file attachment names is hard-coded to contact. Find out the reference name to _config, and use this.
  • Parse attachments as required.

Example / Demo

  1. Patch your copy of tfmail.pl and edit the configuration to match your current install.
  2. Verify that your current system still works as normal. It should!
  3. untar the example config files in your working tfmail configuration directory (ie: where your *.tft files are!).
  4. Edit foobar.tft to send email to your own account
  5. Then, navigate to http://your-site.com/cgi-bin/tfmail.pl?_config=foo

MIME Structure

  • message/rfc822
    • multipart/mixed
      • tfmail attachments

Bugs

What bugs? They're quirks! ;-)

Thanks

To the London Perl Mongers, for providing the original script.
Simon Wistow, for providing a line of voodoo to get me to a stage where things actually work!

History - Print - Recent Changes - Search - Page last modified on 2009, January 31 @ 16:06:29
guestbook