aging mail in the mail spool

aging mail in the mail spool

Post by H. Paul Hamma » Wed, 23 Jun 1993 13:52:38



Hello,

   I have a question regarding aging mail in the mail spool.  As in how
do you do it?  I understand how to age files in the print spool, that's
easy, they are all seperate files, but a users mail is all kept in
usr/spool/mail/user_id.  I am on a NeXT machine running NeXTStep 2.1
If anyone could point me in the right direction, or if someone has some
scripts that they could send me I would be most appreciative. I am
sorry if this is a FAQ.  Please send any mail to

Sincerely,

H. Paul Hammann

 
 
 

aging mail in the mail spool

Post by Richard Off » Wed, 23 Jun 1993 22:34:35



>Hello,

>   I have a question regarding aging mail in the mail spool.  As in how
>do you do it?  I understand how to age files in the print spool, that's
>easy, they are all seperate files, but a users mail is all kept in
>usr/spool/mail/user_id.  I am on a NeXT machine running NeXTStep 2.1
>If anyone could point me in the right direction, or if someone has some
>scripts that they could send me I would be most appreciative. I am
>sorry if this is a FAQ.  Please send any mail to

>Sincerely,

>H. Paul Hammann


This would help me too, we have a number of users who insist on using
mail readers that do not remove mail from the spool area.

We are using sunos4.1.3 on a sun390.
--
 ____________________________________________________________________________
| richard Offer         | #include <job.h>                                     |

 ----------------------------------------------------------------------------

 
 
 

aging mail in the mail spool

Post by Rob Qui » Thu, 24 Jun 1993 03:39:07



Quote:>>   I have a question regarding aging mail in the mail spool.
>This would help me too, we have a number of users who insist on using
>mail readers that do not remove mail from the spool area.

 Installing quotas on the mailbox area might be the easiest method.

--
| To know recursion, you                                         Rob Quinn |


 
 
 

aging mail in the mail spool

Post by DS Curtis, ISB2 108, 375-21 » Fri, 25 Jun 1993 02:56:25


In article 23...@mont.cs.missouri.edu, c559...@monad.missouri.edu (H. Paul Hammann) writes:

>Hello,

>   I have a question regarding aging mail in the mail spool.  As in how
>do you do it?  I understand how to age files in the print spool, that's
>easy, they are all seperate files, but a users mail is all kept in
>usr/spool/mail/user_id.  I am on a NeXT machine running NeXTStep 2.1
>If anyone could point me in the right direction, or if someone has some
>scripts that they could send me I would be most appreciative. I am
>sorry if this is a FAQ.  Please send any mail to
>c559...@monad.missouri.edu.  Thanks to anyone who replies.

>Sincerely,

>H. Paul Hammann
>c559...@monad.missouri.edu

The attached is a *HARDCODED* perl script that reduces the number of mail messages
if there are more than 1500 (or the first argument to the script).  There is one
exception to deleting all but 1500 (or first argument) messages.  If all of the
messages are less than a month old, then no deletions take place.  This script
is provided *AS IS*.  With a little work you could modify it to take any number
of arguments and work on the whole mail directory or add a second argument and
write a shell script that performed a foreach on each file in /var/spool/mail.
The script was written in a couple hours so the documentation may not be the
best but at least it has some comments that you should be able to figure out
what the script is doing if you want to write a C program or shell script to
perform the same function.

I hope this can be of use to you.

+--------------------------------------------------------------------------+
| Name:     Darren Curtis        |  Disclaimer:  My opinion is my own!     |
| Company:  Battelle PNL         |  Theory:  If it is not broken then      |
| Phone:    (509) 375-2152       |           make it faster!               |
| E-mail:   ds_cur...@pnl.gov    |  This space left blank intentionally!   |
+--------------------------------------------------------------------------+

-------------------------------CUT HERE------------------------------------
#!/bin/perl

#$DEBUG      = 1;
#$EARLY_EXIT = 1;
#$SAVE_MESS  = 1;

;#
;#  $Id$
;#  Abstract:
;#    Keep the number of messages in the /var/spool/mail/opmail file under
;#    1500 or the number entered as the first argument to the script.
;#    The script will be run out of cron on a regular basis to keep the
;#    number of messages in the file under control.  This script will exit
;#    as fast as possible if the number of messages in the opmail file are
;#    less than 1500 or the command line argument.
;#  Usage:
;#    opslog_mail_monitor.pl [ number ]
;#      number - (integer), brief_desc
;#  Input file(s):
;#    /var/spool/mail/opmail
;#  Output file(s):
;#    /var/spool/mail/opmail
;#  Return Value(s);
;#    0 - (integer), Successfull execution.
;#    1 - (integer), Unsuccessfull execution.
;#  Manifest:
;#    NONE
;#  Operating system(s):
;#    SunOS 4.1.2
;#  Author:  3C572  Date of origin:  06-03-93
;#  $Log$
;#

@COMMAND       = split (/\//, $0);        ;# Parse command path and name.
$COMMAND       = $COMMAND[$#COMMAND];     ;# Assign $COMMAND to program name.
$CUSTODIAN     = "root";                  ;# Person to send mail to.
$ECHO          = "/bin/echo";             ;# Hardcoded shell echo program.
$MAIL          = "/usr/ucb/Mail";         ;# Hardcoded mail program.

#
#  Specify the number of messages to keep determined by the first argument
#  on the command line or default to 1500.
#
$SAVE_NUMBER = (defined ($ARGV[0]) && $ARGV[0] > 0) ? $ARGV[0] : 1500;

#
#  Build array of months in the year.
#
@MONTHS = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
           'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');

#
#  Find out what month and day is today.
#
($SEC, $MIN, $HOUR, $MDAY, $MON, $YEAR, $WDAY, $YDAY, $ISDST) = gmtime (time());

#
#  The file to be checked and possibly modified.
#
$CURR_MONTH = $MON;
$PREV_MONTH = $MON >= 1 ? $MON-1 : 11;
$TODAY      = $MON + 1;
$TODAY      = sprintf ("%.2d_%.2d_%.2d", $TODAY, $MDAY, $YEAR);
&DEBUG && print ("TODAY      = $TODAY\n");
exit 0;

$MAILDIR    = '/var/spool/mail';
$MAILFILE   = "$MAILDIR/opmail";
$SAVEDIR    = '/home/opslog';
$SAVEFILE   = "$SAVEDIR/logfiles_opmail_$TODAY";

$DEBUG && print ("MAILFILE   = $MAILFILE\n");
$DEBUG && print ("SAVEFILE   = $SAVEFILE\n");

#
#  Set the current month and previous month.  Special case for previous
#  month if the current month is January then the previous month is set
#  to December.
#
$CURR_MONTH = $MONTHS[$MON];
$PREV_MONTH = $MON >= 1 ? $MONTHS[$MON-1] : $MONTHS[11];

$DEBUG && print ("CURR_MONTH = $CURR_MONTH\n");
$DEBUG && print ("PREV_MONTH = $PREV_MONTH\n");

sub notify_custodian {
;#
;#  Description:
;#    Subroutine to build the body of a mail message that will be
;#    sent to $CUSTODIAN.
;#  Parameters:
;#    $SUBJECT - (string), subject of mail message.
;#  Return Value(s):
;#    NONE
;#  Author:  3C572  Date:  05-19-92
;#
  local ($SUBJECT) = @_;

  $DEBUG && print ("notify_custodian\n");
  push (@MAIL_FILE, "$SUBJECT\n");
  }

sub mail_custodian {
;#
;#  Description:
;#    Subroutine to send a mail message (if necessary) to $CUSTODIAN.
;#  Parameters:
;#    $SUBJECT - (string), subject of mail message.
;#  Return Value(s):
;#    NONE
;#  Author:  3C572  Date:  05-19-92
;#
  local ($SUBJECT) = @_;

  $DEBUG && print ("mail_custodian\n");
  $DEBUG && print ("$ECHO \" @MAIL_FILE\"\n");
  if ( (defined (@MAIL_FILE)) && (! defined ($DEBUG)) ) {
    system ("$ECHO \" @MAIL_FILE\" \| $MAIL -s \"$SUBJECT\" $CUSTODIAN");
    }
  }

#
#  Open the $MAILFILE and build and array of all the mail messages in the
#  file.  Note the special case at the end to get the last message.
#
open (FILE, $MAILFILE);# || &notify_custodian ("Can't open $MAILFILE: $!");
$LINE = <FILE>;
push (@MESSAGE, $LINE);
while (<FILE>) {
  if (/^From /) {
    #
    #  Start of a new message so join all the parts of the previous
    #  message and insert the previous message into the array of messages.
    #
    $MESSAGE = join ('', @MESSAGE);
    push (@FILE, $MESSAGE);
    undef (@MESSAGE);
    }
  push (@MESSAGE, $_);
  }
#
#  Special case to insert the last message into the array of messages.
#
$MESSAGE = join ('', @MESSAGE);
push (@FILE, $MESSAGE);
close (FILE);

#
#  Exit if the number of messages is less than $SAVE_NUMBER.
#
exit 0 if (($#FILE < $SAVE_NUMBER) && (defined ($EARLY_EXIT)));

#
#  Keep each message that is in the current month or that is less than
#  30 days old in the array @MESSAGES.  Keep the messages that are older
#  than 30 days in the array @DEL_MESSAGES.
#
foreach (@FILE) {
  ($FROM, $USER, $WDAY, $MONTH, $DAY, $TIME, $YEAR, @REST) = split(/\s+/, $_);
  if (($MONTH eq $CURR_MONTH) || (($MONTH eq $PREV_MONTH) && ($DAY >= $MDAY))) {
    push (@MESSAGES, $_);
    }
  else {
    push (@DEL_MESSAGES, $_);
    }
  }

#
#  Keep all messages if the number of messages is less than $SAVE_NUMBER,
#  otherwise only keep $SAVE_NUMBER messages.
#
$i = $#MESSAGES >= $SAVE_NUMBER ? $#MESSAGES - $SAVE_NUMBER : 0;

$DEBUG && print ("#MESSAGES  = $#MESSAGES\n");
$DEBUG && print ("i          = $i\n");

#
#  Notify the custodian if any messages were deleted.
#
&notify_custodian ("$i Messages were deleted from $MAILFILE") if ($i > 0);

#
#  Write out the messages to be deleted to $SAVEFILE.
#
open (FILE, ">$SAVEFILE") || &notify_custodian ("Can't open $SAVEFILE: $!");
foreach (@DEL_MESSAGES) {
  print (FILE $_);
  }
$j = 0;
while ($j < $i) {
  print (FILE $MESSAGES[$j]);
  $j++;
  }
close (FILE);

#
#  Write out the messages to $MAILFILE.
#
open (FILE, ">$MAILFILE") || &notify_custodian ("Can't open $MAILFILE: $!");
while ($i <= $#MESSAGES) {
  print (FILE $MESSAGES[$i]);
  $i++;
  }
close (FILE);

#
#  Send a summary message to the custodian.
#
&mail_custodian ("Site Data System - $COMMAND - Summary Report:");

exit 0;

 
 
 

aging mail in the mail spool

Post by Nigel Metheringh » Thu, 24 Jun 1993 16:43:47


Look for a utility called exmail - I think it was posted to a
comp.sources.* group a while back.  Archie will find it.

Before you start aging people's mail for them, make sure you know
the implications - people get vey jumpy about having mail fiddled
with, and it could be construed as a breach of privacy.  Why not
shunt the stuff into their home directory - as a mail folder of some
sort?? (NB exmail could be modified to do this - but a Perl script
might be better.  I have seen a perl script to do this, but can't
remember where).

        Nigel.
--

#   System Administrator, Electronics Dept, University of York    #
#   York YO1 5DD. Phone: +44 904 432374, Fax: +44 904 432335      #

 
 
 

aging mail in the mail spool

Post by Dave Shie » Fri, 25 Jun 1993 19:12:59




> >   I have a question regarding aging mail in the mail spool.  As in how
> >do you do it?

> The attached is a *HARDCODED* perl script that reduces the number of mail messages
> if there are more than 1500 (or the first argument to the script).

  There is a program called 'mailclean' which can be used to report on and optionally
act on a number of mail spool "problems" such as large mailboxes, old mailboxes,
unowned (or wrongly owned) mailboxes, etc.
  In the particular case of large mailboxes, it can truncate them down to a smaller size,
saving the overflow (e.g.) in the users' home directory.  All values are configurable.
It should be freely obtainable from your local friendly FTP archive, but I can supply it
to anyone who has problems finding it.
  Disclaimer - I didn't write it or anything, just a satisfied (sort-of) user.

Dave
-------------------------------------------------------------------------------


Liverpool University,           "I _order_ you to help!
PO Box 147,                      You're a machine and you must do
Liverpool, L69 3BX               what you're told."        T. Pratchett, _Diggers_

 
 
 

1. aging mail in the mail spool

Hello,

   I have a question regarding aging mail in the mail spool.  As in how
do you do it?  I understand how to age files in the print spool, that's
easy, they are all seperate files, but a users mail is all kept in
usr/spool/mail/user_id.  I am on a NeXT machine running NeXTStep 2.1
If anyone could point me in the right direction, or if someone has some
scripts that they could send me I would be most appreciative. I am
sorry if this is a FAQ.  Please send any mail to

Sincerely,

H. Paul Hammann

2. Source code for Marc Rochkind's book

3. /var/spool/mail vs. /usr/spool/mail

4. *** auto power off ***

5. Is there a mail program that can read mail (as root) from /var/spool/mail/xxx?

6. need sed help.

7. mail folder is in /var/mail or /var/spool/mail

8. Yggdrasil LGX: X window problems

9. Mail to /var/spool/mail/a/auser

10. More mail file locking questions (lockf, NFS, /var/spool/mail/*.lock)

11. Help for getting mail from ISP to my mail spool.

12. Mail problem because a perl script reads /var/spool/mail/login?

13. editing the root mail file in /var/spool/mail