Hallo Eduard, > > 4. Mails mit Mutt nach einer Woche/Monat automatisch ins Archiv > > verschieben. > > Skript im Anhang. Alternativ, mutt-Macros. ich hab das mail-expire script ein wenig veraendert ; - mails werden immer nur in eine datei pro monat verschoben/angehaengt - und das in gzippter form [spart ne ganze menge] ich hab keine grossartigen aenderungen gemacht, deswegen sollte es eigentlich keine fehler haben. aber man weiss ja nie ---> keine garantie, lieber an einer kopie ausprobieren siehe anhang. gruss florian Florian Krohs krohs@uni.de
#!/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> # ----------------------------------------------------------------------- # # Changes by Johannes Kolb: # * use Date::Calc instead of Date::Manip to increase performance # * no buffering of whole mailbox-files in memory # # Changes by Florian Krohs <krohs@uni.de> # * append old mails to mailbox.month_year.gz # * added zlib to free some space:] 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::Calc qw(Parse_Date Today Delta_Days); use Compress::Zlib ; $c=-1; @today = Today(); $old_all = localtime(time - $ARGV[0] * 86400); $old_all =~ s/\ +/\ /g; @splitdate=split(/\ /,$old_all); $olddate="@splitdate[1]" . "_" . "@splitdate[4]" . ".gz"; JOB: foreach $file (1..$#ARGV) { # close(neu); # close(alt); undef @st; undef @time; undef $c; $oldsize = (stat("$ARGV[$file]"))[7]; 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; }; open(neu,">$ARGV[$file]".".tmp"); if(!-e "$ARGV[$file]".".$olddate"){$neue_datei=1;print "datei neu angelegt\n";} $alt = gzopen("$ARGV[$file]".".$olddate", "ab") or die "cannot open file: $gzerrno\n"; syswrite (STDOUT,"Reading ans splitting $ARGV[$file] ($oldsize bytes)...\n"); while(<fh>) { if(/^From \S/) { $c++; @maildate = Parse_Date($_); $diff = Delta_Days(@maildate,@today); syswrite(STDOUT, "Age: $diff day".(($diff > 1) ? "s" :"")." -> "); if ($diff > $ARGV[0]) { $isold = 1; $alte++; syswrite(STDOUT, "old.\n"); } else { $isold = 0; $neue++; syswrite(STDOUT, "new.\n"); } } if ($isold) { $alt->gzwrite($_) or die "error writing to gz buffer : $gzerror\n"; } else { print neu $_; } } close(fh); # MUST BE CLOSED BEFORE STAT'ING THEM close(neu); $alt->gzclose ; if($alte==0 && $neue_datei==1){unlink("$ARGV[$file]".".$olddate")|| "failed";print "removed gzip file [empty]\n";} (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) { $diff=$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,"saved $diff bytes\n"); syswrite (STDOUT,"done.\n"); } else { syswrite(STDOUT,"hm, $oldsize = $newsize?"); } if(-e "$ARGV[$file]".".tmp"){unlink("$ARGV[$file]".".tmp") || die "failed";} }
Attachment:
pgpRN3x_iod04.pgp
Description: PGP signature