Permission on the quarantine directories

Magda Hewryk mhewryk at SYMCOR.COM
Mon Jul 28 13:57:11 IST 2003


Hi,

Here is another good script.  You can run it from cron.
It detects emails qf/df in quarantine directory and emails to the
designated mailbox (e.g. on exchange or notes).  It can be modified to ssh
instead of emailing.


#!/bin/bash
#
# Purpose: - move quarantined qf/df files to the outbound queue, for
delivery
#          - edit the RECIPIENT field; all email goes to a single mailbox
#
PATH=/bin:/usr/bin; export PATH

OUTQ=/var/spool/mqueue
QUARANTINEDIR=/var/spool/MailScanner/quarantine
NEW_RECIP=attachment at notes.smpt.symcor.com

exec >/var/log/forward-attachments.log 2>&1

# The quarantined email is placed in directories with this format:
# $QUARANTINEDIR/YYYYMMDD/$MessageID/
# The files in the directory will be:
# - the qf file (which we will edit)
# - the df file (which contains the attachments(s))
# - one or more attachment files

# Algorithm:
#
# For each of the above type of directory, check that it has BOTH a
#   qf & df file; if it DOESN'T, ignore it (it's not ready). If it DOES,
then:
#
#   1) edit the qf (change the recipient field)
#   2) move the qf & df files into the OUTQ (for delivery)
#   3) delete the directory and any its contents (ie., attachments)
#   4) delete empty parent directories; this is
#      solely for the purpose of keeping QUARANTINEDIR tidy

cd $QUARANTINEDIR

# NOTE: We need to explicitly ignore the "./spam/" sub-directory,
# because we are only dealing with attachments here.
find ???????? -type d -mindepth 1 ! -name spam |
while read dir
do
   cd $QUARANTINEDIR/$dir
   if [ $? != 0 ]; then # couldn't chdir into that directory; that's bad
      continue
   fi
   echo "Current directory: $PWD"

   # verify that BOTH the df & qf files exist
   # ignore files that have a "." in the name
   qf_file=$(ls -1 qf* 2>/dev/null | grep -v "\.")
   df_file=$(ls -1 df* 2>/dev/null | grep -v "\.")
   if [ "$df_file" = "" -o "$qf_file" = "" ]; then
      echo -e "Skipping directory; it's not ready yet\n"
      continue
   fi
   echo "Directory $dir is ready to be processed..."

   echo "Changing recipient to '$NEW_RECIP'..."
   sed 's/^RPFD:<.*>/RPFD:<'$NEW_RECIP'>/' $qf_file > $qf_file.tmp
   mv $qf_file.tmp $qf_file

   echo "Moving the qf & df files into the OUTQ (for delivery)..."
   mv $qf_file $df_file $OUTQ

   echo "Removing any attachments left in directory..."
   rm *

   echo "Removing the directory, which should now be empty..."
   cd /
   rmdir $QUARANTINEDIR/$dir

   echo ""

done

# 4) Cleanup empty directories, where possible.
# Directories which aren't empty will generate errors; ignore these.
rmdir $QUARANTINEDIR/???????? 2>/dev/null



More information about the MailScanner mailing list