Re: [Debian] [Mutt] Alte mails rotieren
Moin Helmut!
Helmut Peters schrieb am Freitag, den 26. Oktober 2001:
> nach etwas längerer Recherche und einigem erfolglosem Herumprobieren
> wende ich mich mal an die Mutt-Gurus unter euch.
Ich habe für sowas ein handliches Scriptchen. Das bleibt an manchen
"komischen" Mails offensichtlich hängen, aber bei Mailing-Listen hat es
noch nie versagt.
Gruss/Regards,
Eduard.
--
(A)bort (R)etry (I)mJustJokingButYouShouldHaveSeenTheLookOnYourFace...
#!/usr/bin/perl
# mail-expire, Version 0.0.3, Mon Apr 16 14:40:40 CEST 2001
# Copyright: Eduard Bloch <blade@debian.org>
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details. The full text of GPL can be
# found on http://www.gnu.org or in /usr/share/common-licenses/GPL on
# modern Debian systems.
#
# -----------------------------------------------------------------------
# If you make changes to this script, please feel free to forward the new
# version to <blade@debian.org> or <eduard@bloch.com>
# -----------------------------------------------------------------------
die "Usage: $0 DAYS FILES\nwhere\nDAYS is an integer specifying the maximum age of a mail in days and\nFILES one or more mbox file(s).\n" if ($#ARGV < 1 | $ARGV[0]=~/[:^digit:]/);
use Date::Manip;
$c=-1;
$today = ParseDate("today");
$olddate = localtime(time - $ARGV[0] * 86400);
$olddate =~ s/\ /_/g;
JOB: foreach $file (1..$#ARGV) {
close(neu);
close(alt);
undef @st;
undef @time;
undef @data;
undef $c;
(undef,undef,undef,undef,undef,undef,undef,$oldsize)=stat("$ARGV[$file]");
if ($oldsize == 0) {
syswrite(STDOUT,"Empty file $ARGV[$file], skipping");
next JOB
};
if(!open(fh,"<$ARGV[$file]")) {
syswrite(STDOUT,"$ARGV[$file] could not be opened, skipping");
next JOB;
};
if(flock(fh,2|4)){
# lock when not locked allready by another process
flock(fh,2);
} else {
# skip file
close(fh);
syswrite(STDOUT,"$ARGV[$file] is locked by an other prozess, skipping.");
next JOB;
};
syswrite (STDOUT,"Reading $ARGV[$file] ($oldsize bytes) ");
while(<fh>) {
if(/^From\s.*\@.*\s(\S\S\S\s\S\S\S\s\d\d\s\d\d:\d\d:\d\d\s\d\d\d\d)/) {
$c++;
$time[$c]=$1; # grep and store time lines in time array, index-nr = c
syswrite (STDOUT,".");
}
$data[$c] = $data[$c] . $_; # store mail contents in data array, index-nr = c
}
syswrite (STDOUT,"\n");
close(fh);
open(neu,">$ARGV[$file]".".tmp");
open(alt,">$ARGV[$file]".".$olddate");
for(0..$c) {
@calc = split(/:/, &DateCalc(&ParseDate($time[$_]),$today));
$diff = ($calc[2] * 7) + $calc[3];
syswrite(STDOUT, $time[$_]." -> Age: $diff day".(($diff > 1) ? "s" :"")." -> ");
if ($diff > $ARGV[0]) {
print alt $data[$_];
$alte++;
syswrite(STDOUT, "old.\n");
}
else {
print neu $data[$_];
$neue++;
syswrite(STDOUT, "new.\n");
}
}
# MUST BE CLOSED BEFORE STAT'ING THEM
close(neu);
close(alt);
(undef,undef,undef,undef,undef,undef,undef,$newsize)=stat("$ARGV[$file]".".tmp");
@st = stat("$ARGV[$file]".".$olddate");
$newsize += $st[7];
syswrite (STDOUT,"Wrote $neue new entries to $ARGV[$file]".".tmp\n");
syswrite (STDOUT,"Wrote $alte old entries to $ARGV[$file]".".$olddate\n");
if($oldsize == $newsize) {
syswrite (STDOUT,"Deleting $ARGV[$file]... ");
unlink("$ARGV[$file]") || die "failed";
syswrite (STDOUT,"replacing with the new mailbox... ");
rename("$ARGV[$file]".".tmp", "$ARGV[$file]") || die "failed";
syswrite (STDOUT,"done.\n");
} else {
syswrite(STDOUT,"hm, $oldsize = $newsize?");
}
}
Reply to: