| [FrontPage] [TitleIndex] [WordIndex]

# TmdaPendingAsMaildirHowto

NOTE -- this page might be considered obsolete now that TMDA has native support for the TMDA Pending Queue as a Maildir!

# Introduction

First, let me appoligize in advance - my first time on a wiki as an author - correct my format if you like - I just want to share the info in case it helps...

Until this becomes a standard features (hopefully;-) I've come up with a kludge to allow access to the pending messages through an IMAP client without having to use the tmda-cgi to approve the messages or view the pending queue directly.

# Maildrop Script

In the beginning of my maildrop I do a bunch of setup stuff - can't really provide an equivalent for all users - I use a bunch of patches to set special environment variables to help me do a few extra central tricks, but in general, you need to have values for any variables I'm referencing in the part below that does the work - this should cover the basics though:

    FLD_INBOX=$UI_Maildir
    FLD_TRASH=$UI_Maildir/.Trash/
    FLD_SPAM=$UI_Maildir/.Spam/
    FLD_TMDA=$UI_Maildir/.TMDA

    DEFAULT=$FLD_INBOX

This maildrop code snipit is used to deliver a copy of messages into the maildrop folder and also to trigger removal on confirmation:

      LOCKTMDA=$HOME/.tmda.lock
      flock $LOCKTMDA {
        SH_SENDER=escape($SENDER)
        #can remove env call when Sam patches courier (next release?)
        cc "| env SENDER='$SH_SENDER' /usr/local/tmda/bin/tmda-filter"
        if ($EXITCODE != "0")
        {
          #initial submission of unconfirmed message
          if ($EXT =~ /^confirm-/)
          {
            #if this is a confirmation message, eat it
            EXITCODE=0
            exit
          }
          else
          {
            #if this is a message to pending, make it visible to user
            to $FLD_TMDA/
          }
        }
        else
        {
          /Message-ID: .*/
          MSG_ID=$MATCH
          # Get the portion of the confirmation number that prefixes the original file name
          /X-TMDA-Confirm-Done: ![0-9]+!\./
          MSG_FILE=$MATCH2
          #Call my cleanup script
          CMDRESULT=`/usr/local/bin/tmda-cleanup "$MSG_ID" "$FLD_TMDA" $MSG_FILE`
        }
      }

# Alterations to Courier config

Assuming you are using courier, you MAY want to add the pending folder name to the imapd config file. Doing so will result in an auto-purge of files in this folder older than the number of days you enter:

    IMAP_EMPTYTRASH=Trash:7,Pending:10

Would delete Trash after 7 days, Pending after 10.

# PHP Pending folder cleanup script

I know this isn't written in Python - sorry I've played with lots of languages over the years, and as I get older I realize most of them can do everything every other can do, but to simplify my life I want to concentrate on knowing a few of them well...

So - that said, PHP command line scripts run pretty much the same as any other... this should operate on any reasonably new version of PHP with either the CLI or CGI build.

Of course you will have to edit the `#!` to reference your own PHP - which MAY be determined by executing `which php` at a command shell.

    #!/usr/local/bin/php -q
    <?php

    #log file must be mode 666 for multi user logging!
    #as this script will run under the UID of the user for which maildrop
    #is being run, we have to be careful to chmod the file 666 if we want
    #it to work for multiple users...
    #error_log(print_r($_SERVER,TRUE),3,'/tmp/stuff');

    $MessageID = $_SERVER['argv'][1];
    $MailFolder = $_SERVER['argv'][2];
    $MailFilePrefix = $_SERVER['argv'][3];

    if (($MessageID == '') || ($MailFolder == '') || ($MailFilePrefix == '')) {
      die("usage: {$_SERVER['argv'][0]} 'MessageIDLine' 'TMDA_Folder_Root' 'MailFilePrefix'\n");
    }

    #SCAN FOR PATTERN MATCH & NUKE MATCHING FILES
    #in courier, files names are prefixed by a unixtime stamp
    #(number of seconds since epoch), so to avoid grepping a
    #potentially large folder, I try just a few after the delivery
    #time to save cycles... I WELCOME improvements on this idea
    #also note it may not work if you use a different MDA - in
    #which case just remove this outer loop, and change the glob:
    #  foreach (glob("$MailFolder/*/*") as $filename) {

    for ($i=0; $i<=2; $i++) {
      $MF = $MailFilePrefix + $i;
      foreach (glob("$MailFolder/*/$MF*") as $filename) {
        $f = fopen($filename, "r");
        $found = FALSE;
        while (!feof($f)) {
          $line = fgets($f,1024);
          $line = trim($line);
          if ($line == '') {
            #stop after reading the headers, which terminate on the first blank line
            break;
          }
          if ($line == $MessageID) {
            $found = TRUE;
            break;
          }
        }
        fclose($f);
        if ($found) {
          #delete the file we found a matching message ID in
          unlink($filename);
        }
      }
    }
    ?>

# Conclusion

Hope this helps.

All my mail addresses will soon be protected by TMDA, so I have no fear in leaving my bare address here! Thanks guys! 2004.01.26 Mitch Cant - Vancouver Canada <mitch@webcob.com>

2007-07-30 15:45