Mailing List CGatePro@mail.stalker.com Message #92800
From: James Reynolds <james123@scl.utah.edu>
Subject: Approval perl script
Date: Tue, 02 Oct 2007 06:30:20 -0700
To: <CGatePro>
I found the perl script for finding if there is stuff in the approval folder.  I've modified it to check many lists.  The code is below.

--

Thanks,

James Reynolds - University of Utah - Student Computing Labs - 801-585-9811
james(a)scl.utah.edu - james(a)magnusviri.com - http://www.magnusviri.com




#!/usr/bin/perl

###################################################
# Program Name: approval_check
# Created: Nov 16, 2001
# Modified: February 5, 2002 (documentation added)
# Modified: October 1, 2007 (supported multiple lists) by James Reynolds james@scl.utah.edu
# Author: Russ Pagenkopf (jnrp@uas.alaska.edu)
# Purpose: This program is used to check if there are messages awaiting
#          list-mom approval. If so it sends an email to an external
#          account with notification.
#
# Special notes: All paths and addresses are hardcoded. Be careful to check
#          and make sure they match actual paths on your local machine
#          and that the remote email account is added correctly.
#
#          Also note that this script will only work against a mail folder
#          that is in the mbox format,
#
#          Last, note that this script must be triggered externally. I use
#          cron with the following entry.
#         #          * 9,17 * * * /root/scripts/approval_check
#
#          You should be able to run this program from anywhere you want
#          with the appropriate privileges. I'm a little lazy since the box
#          has only two accounts, mine and root. ;)
#
# Yes, I believe in quick, dirty and ugly if it gets the job done! :-)
#
# Freely released to the public domain, use at your own risk.
#
###################################################


my $logfile = "";

# If each list pretty much has the same info, you can set it all here.

my $account_name = 'maillists';
my $email_to_notify = 'you@example.com';
my $email_from = 'something@example.com';
my $account_path = '/var/CommuniGate/Accounts';

# Or if each list requires different settings, you can set them individually
# below (instead of using the above variables).

@lists = (
  {
    list_name => 'mmc',
    account_name => $account_name,
    email_to_notify => $email_to_notify,
    email_from => $email_from,
    account_path => $account_path,
  },
  {
    list_name => 'mac',
    account_name => $account_name,
    email_to_notify => $email_to_notify,
    email_from => $email_from,
    account_path => $account_path,
  }
);

foreach $list ( @lists ) {
  my %list1 = %$list;
  my $list_name = $list1{'list_name'};
  my $account_name = $list1{'account_name'};
  my $email_to_notify = $list1{'email_to_notify'};
  my $email_from = $list1{'email_from'};
  my $account_path = $list1{'account_path'};
  my $mailbox_path = "$account_path/$account_name.macnt/$list_name.folder/approval.mbox";

  check_list ( $list_name, $account_name, $email_to_notify, $email_from, $mailbox_path );
}


sub check_list {
  my ( $list_name, $account_name, $email_to_notify, $email_from, $mailbox_path ) = @_;

  #####
  # check if the size of the approval mbox is > zero.
  #####

  if (-s $mailbox_path ) {

    #####
    # We create the initial mail file with a .tmp extension instead of
    # a .sub extension to make sure CGPro doesn't try to process it
    # before we are done creating it.
    #####
   
    open(MAIL,">/var/CommuniGate/Submitted/approval.tmp");
   
    print MAIL "X-Priority: 1 (Highest)\\n";
    print MAIL "To: $email_to_notify\\n";
   
    #####
    # Enter the local sending email address here.
    # Notes: The @ symbol must be preceeded by a '\\' .
    #
    #        The account 'automated' doesn't really exist on my system and the
    #        user must know this, else if they try to reply, their email will
    #        bounce with 'unknown account'.
    #####
   
    print MAIL "From: $email_from\\n";
    print MAIL "Subject: Approval needed!\\n\\n";
   
    print MAIL "Message is awaiting your approval from: $list_name.\\n";
   
    #####
    # Close the Mail file.
    #####
   
    close (MAIL);
  }

  #####
  # Change the newly created file extension from .tmp to .sub so that CGPro
  # will process the file. Again the next command should be all on one line.
  #####

  rename ( "/var/CommuniGate/Submitted/approval.tmp" , "/var/CommuniGate/Submitted/approval.sub" );

  #####
  # This last section was added for my own peace of mind. All it does is append
  # to a file the time that this script is run. The file is created in the
  # same directory that this script is run from.
  #
  # This section could be commented out or deleted if you don't want/need it.
  #####

  if ( -e $logfile ) {
    open(TRACK,">>$logfile");
    $now = localtime;
    print TRACK $now . "\\n";
    close(TRACK);
  }
}
Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to Listmaster