mail-expire-0.7/0000755000076400007640000000000010570412525011347 5ustar ededmail-expire-0.7/mail-expire0000755000076400007640000001630010570412015013503 0ustar eded#!/usr/bin/perl # SEE DEBIAN CHANGELOG FOR NEWER ENTRIES # mail-expire, Version 0.2; Fri, 16 Aug 2002 11:39:10 +0200 # Copyright: Eduard Bloch # # 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 forward the new # version to or # ---------------------------------------------------------- # # REQUIRED PACKAGES: # # libcompress-zlib-perl - Perl module for creation of gzip files # libdate-calc-perl - Perl library for accessing dates # # 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 # * append old mails to mailbox.month_year.gz # * added zlib to free some space:] # # Changes by Eduard Bloch # * small hack to vary the output filename to prevent overwritting # * some cosmetics, fixed typos # * dropped silly size comparison, trust return values of syswrite use strict; my $target="./"; sub help { die "Usage: $0 [ options ] DAYS FILES where DAYS is an integer specifying the maximum age of a mail in days and FILES one or more mbox file(s). Options: -u choose different filenames if the target file already exists --delete drops the old messages. Be warned, no backup will be made! -t DIR new target directory DIR "; } use Getopt::Long qw(:config no_ignore_case bundling pass_through); my $uoption=0; my $deloption=0; my $help; my %opts = ( "t=s", \$target, "delete", \$deloption, "help|h", \$help, "u", \$uoption ); &help if !GetOptions(%opts); &help if $help; my $days=shift(@ARGV); die "Please specify a valid day count!\n" if abs($days)<1; die "Please specify mbox file names!\n" if ! @ARGV; for(@ARGV) { die "Unable to read $_\n" if not -r $_ }; use Date::Calc qw(Parse_Date Today Delta_Days); use Compress::Zlib ; use Fcntl; use Mail::Mbox::MessageParser; my $c=-1; my @today = Today(); my $old_all = localtime(time - $days * 86400); $old_all =~ s/\ +/\ /g; my @splitdate=split(/\ /,$old_all); my $olddate=$splitdate[1] . "_" . $splitdate[4] . ".gz"; JOB: foreach my $filename (@ARGV) { my @st; my @time; my $c; my $oldsize = (stat($filename))[7]; if ($oldsize == 0) { syswrite(STDOUT,"Empty file $filename, skipping."); next JOB; }; if(-e "$filename.new") { syswrite(STDOUT,"Temporary file $filename.new already exists, skipping $filename.\n"); next JOB; }; if(!open(fh,$filename)) { syswrite(STDOUT,"$filename could not be opened, skipping"); next JOB; }; if(flock(fh,2|4)){ # lock when not locked already by another process flock(fh,2) || die "unexpected trouble on locking $filename"; } else { # skip file close(fh); syswrite(STDOUT,"$filename is locked by an other prozess, skipping."); next JOB; }; my $file_handle = new FileHandle($filename); my $folder_reader = new Mail::Mbox::MessageParser( { 'file_name' => $filename, 'file_handle' => $file_handle, 'enable_cache' => 0 } ); #die "he? ".ref($folder_reader); #die ref($folder_reader); if (ref($folder_reader) ne "Mail::Mbox::MessageParser::Grep" && ref($folder_reader) ne "Mail::Mbox::MessageParser::Perl" ) { syswrite STDERR, "Unable to parse contents of $filename, skipping.\n"; next JOB; } sysopen(neu,"$filename.new", O_RDWR|O_EXCL|O_CREAT) || die "Error creating temporary file, move $filename.new out of the way"; my $gzfilename="$target/$filename".".$olddate"; while(-s $gzfilename && $uoption) { my $modnumber += 0; # to preset a value $gzfilename="$target/$filename.".$splitdate[1] . "($modnumber)_" . $splitdate[4] . ".gz";; $modnumber++; } my $gzfile_ist_neu=1 if(!-e $gzfilename); my $alt; if(!$deloption) { $alt = gzopen($gzfilename, "ab") or die "cannot open file: $gzerrno\n"; } syswrite (STDOUT,"I: Reading and splitting $filename ($oldsize bytes)...\n"); syswrite(STDOUT, "I: Analyzing ages (days before expiration): "); my $alte=0; my $neue=0; while(!$folder_reader->end_of_file()) { my $email = $folder_reader->read_next_email(); my $isold; $$email=~/^From\s\S+\s+(.*)/m; my $date=$1; #syswrite (STDERR, "hm, $1\n"); if($1) { $c++; my @maildate = Parse_Date($date); @maildate = (1970,1,1) if scalar @maildate ==0; my $diff = Delta_Days(@maildate,@today); if ($#maildate != 2) { # mail header broken $neue++; syswrite(STDOUT, "(new: date could not be parsed!), "); } else # mail okay { syswrite(STDOUT, $diff); if ($diff > $days) { $isold = 1; $alte++; syswrite(STDOUT, "(old), "); } else { $neue++; syswrite(STDOUT, "(new), "); } } } if ($isold) { if(!$deloption) { $alt->gzwrite($$email) or die "error writing to gz buffer : $gzerrno\n"; } } else { defined(syswrite(neu, $$email)) || die "Failure while writting - disc full?"; } } $alt->gzclose if(!$deloption); flock(fh, 8); close(fh); close(neu); #die "ohje"; if($alte==0 && $gzfile_ist_neu==1 && !$deloption) { unlink($gzfilename)|| die "failed - removed gzip file [empty]\n"; } if( ($alte+$neue) < 1) { syswrite STDOUT, "No changes, ignoring file\n"; next JOB; } my $newsize = (stat($gzfilename))[7]; # no longer interessting, beautify it $gzfilename=~s!^\.//?!!; syswrite (STDOUT,"\n\nI: Wrote $neue new entries to $filename.new\n") if(!$deloption); syswrite (STDOUT,"\nI: Wrote $alte old entries to $gzfilename\n"); syswrite (STDOUT,"Deleting $filename... "); unlink($filename) || die "failed while deleting original mbox"; syswrite (STDOUT,"replacing with the new mailbox... "); rename("$filename.new", $filename) || die "failed"; syswrite (STDOUT,"done"); # syswrite (STDOUT," (saved $diff bytes)") if(!$deloption); syswrite (STDOUT,".\n"); if(-e "$filename.new"){unlink("$filename.new") || die "Could not remove temporary file... Odd things happen!";} } mail-expire-0.7/debian/0000755000076400007640000000000010570412525012571 5ustar ededmail-expire-0.7/debian/control0000644000076400007640000000105210570412515014171 0ustar ededSource: mail-expire Section: utils Priority: optional Maintainer: Eduard Bloch Build-Depends: debhelper (>> 3.0.0) Standards-Version: 3.7.2 Package: mail-expire Architecture: all Depends: ${perl:Depends}, libcompress-zlib-perl, libdate-calc-perl, libmail-mbox-messageparser-perl Description: Utility to extract outdated messages from mbox files mail-expire is a small and fast script that scans mbox files for messages that are older than given maximum age and moves them to another (compressed) mailbox file or just deletes them. mail-expire-0.7/debian/mail-expire.sgml0000644000076400007640000001004410444224624015671 0ustar eded manpage.1'. You may view the manual page with: `docbook-to-man manpage.sgml | nroff -man | less'. A typical entry in a Makefile or Makefile.am is: manpage.1: manpage.sgml docbook-to-man $< > $@ The docbook-to-man binary is found in the docbook-to-man package. Please remember that if you create the nroff version in one of the debian/rules file targets (such as build), you will need to include docbook-to-man in your Build-Depends control field. --> Eduard"> Bloch"> August 16, 2002"> 1"> blade@debian.org"> MAIL-EXPIRE"> Debian"> GNU"> ]>
&dhemail;
&dhfirstname; &dhsurname; 2002 &dhusername; &dhdate;
&dhucpackage; &dhsection; &dhpackage; program to extract outdated messages from mbox files &dhpackage;   AGE FILE FILES... DESCRIPTION &dhpackage; is a small utility which only purpose is to help on keeping the size of multiple mailboxes as small as needed (by removing outdated messages). The old messages are compressed with gzip and stored in the file with the name <MBOXNAME>.<MONTH>_<YEAR>.gz. OPTIONS If an existing archive file with the expected filename is found, another filename is to be choosen. For example: <MBOXNAME>(NUMBER).<MONTH>_<YEAR>.gz. Specify a different target directory for storing expired mailbox files. Default is the current directory. Drop the old messages. No backup will be made, be careful with this option. AUTHOR This manual page was written by &dhusername; &dhemail; for the &debian; system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts.
mail-expire-0.7/debian/rules0000755000076400007640000000334110444224624013653 0ustar eded#!/usr/bin/make -f # Sample debian/rules that uses debhelper. # GNU copyright 1997 to 1999 by Joey Hess. # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS))) CFLAGS += -g endif ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS))) INSTALL_PROGRAM += -s endif configure: configure-stamp configure-stamp: dh_testdir # Add here commands to configure the package. touch configure-stamp build: build-stamp build-stamp: configure-stamp dh_testdir # Add here commands to compile the package. #/usr/bin/docbook-to-man debian/mail-expire.sgml > mail-expire.1 touch build-stamp clean: dh_testdir dh_testroot rm -f build-stamp configure-stamp # Add here commands to clean up after the build process. -$(MAKE) clean dh_clean install: build dh_testdir dh_testroot dh_clean -k dh_installdirs # Add here commands to install the package into debian/mail-expire. #$(MAKE) install DESTDIR=$(CURDIR)/debian/mail-expire cp mail-expire debian/mail-expire/usr/bin # Build architecture-independent files here. binary-indep: build install # We have nothing to do by default. # Build architecture-dependent files here. binary-arch: build install dh_testdir dh_testroot # dh_installdebconf dh_installdocs dh_installexamples dh_installmenu # dh_installlogrotate # dh_installemacsen # dh_installpam # dh_installmime # dh_installinit dh_installcron dh_installman debian/mail-expire.1 dh_installinfo # dh_undocumented dh_installchangelogs dh_link dh_strip dh_compress dh_fixperms # dh_makeshlibs dh_installdeb dh_perl dh_shlibdeps dh_gencontrol dh_md5sums dh_builddeb binary: binary-indep binary-arch .PHONY: build clean binary-indep binary-arch binary install configure mail-expire-0.7/debian/changelog0000644000076400007640000000333510570412162014444 0ustar ededmail-expire (0.7) unstable; urgency=high * Consider the alternative object identification to make sure Mail::Mbox::MessageParser::Perl is created correctly which changed with libmail-mbox-messageparser-perl (1.4005-2) or so -- Eduard Bloch Sun, 25 Feb 2007 23:56:23 +0100 mail-expire (0.6) unstable; urgency=low * making code more robust: using Getopt for arguments, Mail::Mbox::MessageParser for input reading, and "strict" * diff size calculation removed, was incorrect anyways * various updates, Standards-Version, debhelper level -- Eduard Bloch Wed, 23 Nov 2005 19:22:09 +0100 mail-expire (0.5) unstable; urgency=low * Woot, I did really not expect to need to change anything on this package before the Sarge release... * s/utility which/tool whose/ in the manpage, closes: #279274 * workaround for a possible failure in a case which is very unlikely to happen (missing date in the initial line), closes: #300895 * cosmetic changes in debian/control and debian/copyright -- Eduard Bloch Tue, 29 Mar 2005 19:32:02 +0200 mail-expire (0.4) unstable; urgency=low * updated manpage, now enough... closes: #159566 * catch the undefined output of Date calculation, closes: #162484 -- Eduard Bloch Fri, 27 Sep 2002 20:03:38 +0200 mail-expire (0.3) unstable; urgency=low * Option to drop old messages and new target dir (closes: #159566). Rewrote the option parser. * Description improvement (closes: #159341) -- Eduard Bloch Wed, 4 Sep 2002 12:07:30 +0200 mail-expire (0.2-1) unstable; urgency=low * Initial Release. -- Eduard Bloch Fri, 16 Aug 2002 15:39:37 +0200 mail-expire-0.7/debian/dirs0000644000076400007640000000001010444224623013444 0ustar ededusr/bin mail-expire-0.7/debian/copyright0000644000076400007640000000033610444224623014526 0ustar ededThis package was debianized by Eduard Bloch on Fri, 16 Aug 2002 15:39:37 +0200. Upstream Authors: Eduard Bloch Copyright: GPL, see /usr/share/common-licenses/GPL on Debian systems. mail-expire-0.7/debian/compat0000644000076400007640000000000210444224623013767 0ustar eded4 mail-expire-0.7/debian/mail-expire.10000644000076400007640000000466310444224624015101 0ustar eded.\" This -*- nroff -*- file has been generated from .\" DocBook SGML with docbook-to-man on Debian GNU/Linux. ...\" ...\" transcript compatibility for postscript use. ...\" ...\" synopsis: .P! ...\" .de P! \\&. .fl \" force out current output buffer \\!%PB \\!/showpage{}def ...\" the following is from Ken Flowers -- it prevents dictionary overflows \\!/tempdict 200 dict def tempdict begin .fl \" prolog .sy cat \\$1\" bring in postscript file ...\" the following line matches the tempdict above \\!end % tempdict % \\!PE \\!. .sp \\$2u \" move below the image .. .de pF .ie \\*(f1 .ds f1 \\n(.f .el .ie \\*(f2 .ds f2 \\n(.f .el .ie \\*(f3 .ds f3 \\n(.f .el .ie \\*(f4 .ds f4 \\n(.f .el .tm ? font overflow .ft \\$1 .. .de fP .ie !\\*(f4 \{\ . ft \\*(f4 . ds f4\" ' br \} .el .ie !\\*(f3 \{\ . ft \\*(f3 . ds f3\" ' br \} .el .ie !\\*(f2 \{\ . ft \\*(f2 . ds f2\" ' br \} .el .ie !\\*(f1 \{\ . ft \\*(f1 . ds f1\" ' br \} .el .tm ? font underflow .. .ds f1\" .ds f2\" .ds f3\" .ds f4\" '\" t .ta 8n 16n 24n 32n 40n 48n 56n 64n 72n .TH "MAIL-EXPIRE" "1" .SH "NAME" mail-expire \(em program to extract outdated messages from mbox files .SH "SYNOPSIS" .PP \fBmail-expire\fP\ AGE FILE [FILES...] .SH "DESCRIPTION" .PP \fBmail-expire\fP is a small tool whose only purpose is to help on keeping the size of multiple mailboxes as small as needed (by moving outdated messages). .PP The old messages are compressed with gzip and stored in the file with the name ._.gz. .SH "OPTIONS" .IP "\fB-u\fP " 10 If an existing archive file with the expected filename is found, another filename is to be choosen. For example: (NUMBER)._.gz. .IP "\fB-t DIR\fP " 10 Specify a different target directory for storing expired mailbox files. Default is the current directory. .IP "\fB--delete\fP " 10 Drop the old messages. No backup will be made, be careful with this option. .SH "AUTHOR" .PP This manual page was written by Eduard Bloch blade@debian.org for the \fBDebian\fP system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. ...\" created by instant / docbook-to-man, Fri 27 Sep 2002, 20:11