dect
/
asterisk
Archived
13
0
Fork 0

Add message expiry from cron (bug #388)

git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1652 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
markster 2003-10-22 03:58:58 +00:00
parent 7f2e4db808
commit 4f3f03787f
4 changed files with 186 additions and 0 deletions

20
README.messages-expire Executable file
View File

@ -0,0 +1,20 @@
expire-messages.pl
expire-messages finds messages more than X days old and deletes them.
Because the older messages will be the lower numbers in the folder (msg0000
will be older than msg0005), just deleting msg0000 will not work.
expire-messages then runs a routine that goes into every folder in every
mailbox to reorganize. If the folder contains msg0000, no action is taken.
If the folder does not, the rename routine takes the oldest message and
names it msg0000, the next oldest message and names it msg0001 and so on.
The file deletion is done by the -exec parameter to 'find'. It would be far
more efficient to take the output from 'find' and just reorganize the
directories from which we deleted a file. Something for the future...
Keep in mind that messages are deleted at the beginning of the script you
will have mailbox trouble if you check messages before the script
reorganizes your mailbox.
To use it, make sure the paths are right. Adjust $age (originally set to
31) if necessary.

View File

@ -0,0 +1,20 @@
expire-messages.pl
expire-messages finds messages more than X days old and deletes them.
Because the older messages will be the lower numbers in the folder (msg0000
will be older than msg0005), just deleting msg0000 will not work.
expire-messages then runs a routine that goes into every folder in every
mailbox to reorganize. If the folder contains msg0000, no action is taken.
If the folder does not, the rename routine takes the oldest message and
names it msg0000, the next oldest message and names it msg0001 and so on.
The file deletion is done by the -exec parameter to 'find'. It would be far
more efficient to take the output from 'find' and just reorganize the
directories from which we deleted a file. Something for the future...
Keep in mind that messages are deleted at the beginning of the script you
will have mailbox trouble if you check messages before the script
reorganizes your mailbox.
To use it, make sure the paths are right. Adjust $age (originally set to
31) if necessary.

View File

@ -0,0 +1,73 @@
#!/usr/bin/perl
#
# Script to expire voicemail after a specified number of days
# by Steve Creel <screel@turbs.com>
#
# Directory housing the voicemail spool for asterisk
$dir = "/var/spool/asterisk/voicemail";
# Context for which the script should be running
$context = "default";
# Age (Delete files older than $age days old)
$age = 31;
# Delete all files older than $age (but named msg????.??? to be sure
# we don't delete greetings or the user's name)
system('find '.$dir.'/'.$context.' -name msg????.??? -mtime +'.$age.' -exec rm {} \; -exec echo Deleted {} \;');
# For testing - what number to we start when we renumber?
$start = "0";
# Rename to msg and a 4 digit number, 0 padded.
$fnbase = sprintf "msg%04d", $start;
# Make $dir include the context too
$dir.="/".$context;
( -d $dir ) || die "Can't read list of mailboxes ($dir): $!\n";
@mailboxes = `ls -A1 $dir`;
chomp(@mailboxes);
$save_fnbase = $fnbase;
foreach $mailbox (@mailboxes) {
( -d $dir."/".$mailbox) || die "Can't read list of folders (".$dir."/".$mailbox."): $!\n";
@folders = `ls -A1 $dir/$mailbox`;
chomp(@folders);
foreach $folder (@folders) {
if (-d $dir."/".$mailbox."/".$folder) {
( -d $dir."/".$mailbox."/".$folder) || die "Can't read list of messages (".$dir."/".$mailbox."/".$folder.") $!\n";
@files = `ls -A1 $dir/$mailbox/$folder/`;
# Sort so everything is in proper order.
@files = sort @files;
chomp(@files);
# If there is still (after deleting old files earlier in the
# script) a msg0000.txt, we don't need to shuffle anything
# in this folder.
if (-f $dir."/".$mailbox."/".$folder."/msg0000.txt") { next; }
foreach $ext (("WAV", "wav", "gsm", "txt")) {
# Reset the fnbase for each file type
$fnbase = $save_fnbase;
foreach $file (@files) {
if ( $file =~ /$ext/ ) {
chdir($dir."/".$mailbox."/".$folder."/") || die "Can't change folder: $!";
print "Renaming: ".$dir."/".$mailbox."/".$folder."/".$file." to ".$fnbase.".".$ext."\n";
rename($file, $fnbase.".".$ext) || die "Cannot rename: $!";
$fnbase++;
}
}
}
}
}
}
__END__

73
messages-expire.pl Executable file
View File

@ -0,0 +1,73 @@
#!/usr/bin/perl
#
# Script to expire voicemail after a specified number of days
# by Steve Creel <screel@turbs.com>
#
# Directory housing the voicemail spool for asterisk
$dir = "/var/spool/asterisk/voicemail";
# Context for which the script should be running
$context = "default";
# Age (Delete files older than $age days old)
$age = 31;
# Delete all files older than $age (but named msg????.??? to be sure
# we don't delete greetings or the user's name)
system('find '.$dir.'/'.$context.' -name msg????.??? -mtime +'.$age.' -exec rm {} \; -exec echo Deleted {} \;');
# For testing - what number to we start when we renumber?
$start = "0";
# Rename to msg and a 4 digit number, 0 padded.
$fnbase = sprintf "msg%04d", $start;
# Make $dir include the context too
$dir.="/".$context;
( -d $dir ) || die "Can't read list of mailboxes ($dir): $!\n";
@mailboxes = `ls -A1 $dir`;
chomp(@mailboxes);
$save_fnbase = $fnbase;
foreach $mailbox (@mailboxes) {
( -d $dir."/".$mailbox) || die "Can't read list of folders (".$dir."/".$mailbox."): $!\n";
@folders = `ls -A1 $dir/$mailbox`;
chomp(@folders);
foreach $folder (@folders) {
if (-d $dir."/".$mailbox."/".$folder) {
( -d $dir."/".$mailbox."/".$folder) || die "Can't read list of messages (".$dir."/".$mailbox."/".$folder.") $!\n";
@files = `ls -A1 $dir/$mailbox/$folder/`;
# Sort so everything is in proper order.
@files = sort @files;
chomp(@files);
# If there is still (after deleting old files earlier in the
# script) a msg0000.txt, we don't need to shuffle anything
# in this folder.
if (-f $dir."/".$mailbox."/".$folder."/msg0000.txt") { next; }
foreach $ext (("WAV", "wav", "gsm", "txt")) {
# Reset the fnbase for each file type
$fnbase = $save_fnbase;
foreach $file (@files) {
if ( $file =~ /$ext/ ) {
chdir($dir."/".$mailbox."/".$folder."/") || die "Can't change folder: $!";
print "Renaming: ".$dir."/".$mailbox."/".$folder."/".$file." to ".$fnbase.".".$ext."\n";
rename($file, $fnbase.".".$ext) || die "Cannot rename: $!";
$fnbase++;
}
}
}
}
}
}
__END__