Hi,
        I wrote a script for myself to rotate the sent-mail folder. I
        guess you can easily to modify it to rotate other folders as
        well. 

        Just modify the variables at the beginning and put it in
        /etc/cron.monthly(debian only).

        Hope this helps...

Shao.

Chris Gushue [[EMAIL PROTECTED]] wrote:
> Is there a way to archive mailboxes at the beginning of every month (or
> some other period) like Pine does? Just after a couple weeks, my
> debian-user mailbox (mbox) is 3.6 MB with over 1200 messages. As the
> mailbox gets bigger, Mutt takes longer to open it.
> 
> Eg. move the contents of debian-user to debian-user-1999-aug
> 
> Any solution would be great, not necessarily a mutt-specific one
> (eg. procmail/crontab/scripts/etc). I'm sure I saw a message about this
> on a mailing list I am on, but couldn't find anything. Perhaps it was on
> a newsgroup somewhere...
> 
> -- 
> -- Chris Gushue --------- ICQ:409207 --------- [EMAIL PROTECTED] --
> GCS d- s+:- a23 C++>$ UL+++ P+>++ L+++ E---- W++ N++ o-- K- w--- O-
> M-- V-- PS+++ PE Y+ PGP+ t++ 5+ X++ R- tv+ b++ DI+ D+ G++ e h! r y+
> -- http://seymour.napalm.net ----------- http://owirc.napalm.net --



-- 
____________________________________________________________________________
Shao Zhang - Running Debian 2.1  ___ _               _____
Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: [EMAIL PROTECTED]                                                  |___/ 
_____________________________________________________________________________
#!/usr/bin/perl

#Mutt does not have the feature like pine
#which automatically backup the sent-mail
#folder each month.

#Mutt is designed to be small and effient.
#Therefore, this kind of feature will NEVER
#go into mutt. The standard answer is to
#use cron. And that is why I write this script

#Written by Shao Zhang <[EMAIL PROTECTED]>

#This program can be freely redistributed with
#ABSOULUTELY NO WANRANTY

# Program starts here

#hopefully, this is where your outgoing mail stores
$mail_dir = "/home/shao/mail";
$folder_prefix = "sent-mail";

$current_time = `date`;
chop($current_time);

$last_month = `date \'+%B\' --date \'last months\'`; 
chop($last_month);

$two_month_ago = `date \'+%B\' --date \'2 months ago\'`;
chop($two_month_ago);

$current_year = `date \'+%Y\'`;
chop($current_year);

$last_year = `date \'+%Y\' --date \'last year\'`;
chop($last_year);


#Let's check if sent-mail is there for update.
if (not -f "$mail_dir/$folder_prefix")
{
        print "Error: Cannot find a sent-mail folder in $mail_dir \n";
        print "Program exited abnormally \n";
        exit 0;
}

#Check if the old sent-mail folder exists -- eg. sent-mail-March-1999
if (-f "$mail_dir/$folder_prefix-$two_month_ago-$current_year") 
{
        #Easy job, we have an old sent-mail-folder saved two months ago.
        #Now, mv the current sent-mail folder to sent-mail-last_month
        #and then we can get rid of the old stuff, then we are done.
        $bool = not `mv $mail_dir/$folder_prefix 
$mail_dir/$folder_prefix-$last_month-$current_year`;

        if ($bool)
        {
                #Ok, if we have moved the file with no problem
                $bool = not `rm $mail_dir/$folder_prefix-$two_month_ago-$current_year`;

                if ($bool) 
                {
                        #Ok, if we have deleted the old stuff with no problem just 
return;
                        exit 0;
                }

                else
                {
                        #Ok, cannot delete
                        print "Cannot delete the old sent-mail folder\n";
                        print "Program exited abnormally\n";
                        exit 0;
                }

        }

        else
        {
                #Ok, cannot move, got a problem somehow, I will pass onto you to fix it
                print "Cannot move the current sent-mail folder to 
sent-mail-last_months\n";
                print "Program exited abnormally\n";
                exit 0;
        }
}

#Ok, it does not. No big deal, maybe  we are going into next year.
elsif (-f "$mail_dir/$folder_prefix-$two_month_ago-$last_year")
{
        #Indeed, this is a new year.
        #Now, we have to be very carefull. Two months ago could be November or 
December.

        if ($two_month_ago eq "November")
        {
                $bool = not `mv $mail_dir/$folder_prefix 
$mail_dir/$folder_prefix-$last_month-$last_year`;
        }

        elsif ($two_month_ago eq "December")
        {
                $bool = not `mv $mail_dir/$folder_prefix 
$mail_dir/$folder_prefix-$last_month-$current_year`;
        }

        else 
        {       #Now, we have stuffed up.
                print "The program is confused about your computer's time\n";
                print "Check you local settings\n";
                print "The program exited abnormally\n";
                exit 0;
        }

        if ($bool) 
        {
                #Ok, we have moved the files correctly
                $bool = not `rm $mail_dir/$folder_prefix-$two_month_ago-$last_year`;

                if ($bool)
                {
                        #Ok, we have deleted the file with no problem, just return
                        exit 0;
                }

                else
                {
                        #Ok, cannot delete
                        print "Cannot delete the old sent-mail folder\n";
                        print "Program exited abnormally\n";
                        exit 0;
                }
        }
        
        else
        {
                #Ok, cannot move, got a problem somehow, I will pass onto you to fix it
                print "Cannot move the current sent-mail folder to 
sent-mail-last_months\n";
                print "Program exited abnormally\n";
                exit 0;
        }
}

#Ok, it seems we have covered all the cases. What if the system does not have a old 
sent-mail folder?
#Doh! What next? No big deal again, just create a dummy old sent-mail folder for the 
next generation!

else
{
        #Let's create one then!
        if ($last_month eq "December")
        {
                #Be carefull again
                if (-f "$mail_dir/sent-mail-$last_month-$last_year")
                {
                        #Everything is fine. It is not the time yet to update.
                        exit 0;
                }
                open (OLD_SENT_MAIL, ">$mail_dir/sent-mail-$last_month-$last_year");
        }

        else 
        {
                if (-f "$mail_dir/sent-mail-$last_month-$current_year")
                {
                        #Everything is fine. It is not the time yet to update.
                        exit 0;
                }
                open (OLD_SENT_MAIL, ">$mail_dir/sent-mail-$last_month-$current_year");
        }

        #Let's write some rubbish in it!
        if (OLD_SENT_MAIL)
        {
                print OLD_SENT_MAIL "Dummy old sent-mail-folder created by 
update-sentmail. \n";
                print OLD_SENT_MAIL "This file was generated on $current_time.\n";

                close OLD_SENT_MAIL;
        }

        else
        {
                print "Error: Cannot create a dummy old-sent-mail folder\n";
                print "The program exited abnormally\n";
                exit 0;
        }
}


#End of the update-sentmail program

Reply via email to