From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Message-ID: <41AF110E.4090504@mail.ru> Date: Thu, 02 Dec 2004 15:56:46 +0300 From: Kolotov Alexandr User-Agent: Mozilla Thunderbird 0.9 (X11/20041103) X-Accept-Language: ru-ru, ru MIME-Version: 1.0 To: community@altlinux.ru Subject: Re: [Comm] Mozilla Thunderbird References: <41AEEA42.3050901@narod.ru> <41AEEB63.7050604@tulanews.ru> In-Reply-To: <41AEEB63.7050604@tulanews.ru> Content-Type: text/plain; charset=KOI8-R; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: community@altlinux.ru X-Mailman-Version: 2.1.5 Precedence: list Reply-To: community@altlinux.ru List-Id: Mailing list for ALT Linux users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Dec 2004 12:56:03 -0000 Archived-At: List-Archive: List-Post: >> Кто-нибудь знает плагин для Mozilla Thunderbird который позволяет >> удалять копии сообщений? >> Просто при переходе с The Bat на Mozilla Thunderbird появилось >> несколько тысяч копий сообщений в разных папках и руками их удалять >> больно проблематично. >> Заранее спасибо. > > > Нету. Сам искал. > Нашёл только прогу для обработки UNIX ящиков. > Но в данный момент она утеряна. И как зовётся - не помню. > Но нашёл я её на сайте мозиллы (на форуме) где-то когда-то нашел... ---------------------------------------------------------------- #!/usr/bin/perl -w use strict; # mergebox [-h] [-d] # # Merge mboxen. First argument is taken to be the destination mbox, all # other arguments are asssumed to be source mboxen. If a message doesn't # have a Message-ID, construct one using MD5. Can read Maildirs as well. # Uses Mail::Folder::Mbox, which is nominally obsolete. Will optionally # delete messages older than date (ISO format YYYYMMDDhh:mm:ss) from # source mbox(en). # Performance - When reading the destination mbox, this program will look # out for duplicate messages and keeps the longer message (under the # assumption that truncation is the biggest source of duplicates). Not # the best, but who knows. Once the destination mbox has been parsed, # the program will read mbox (or maildir) looking out for duplicates. # If the duplicate is smaller, it is skipped. If it is longer, it is # appended (and a warning printed). The next time the destination is # processed, the duplicate should be picked up and dealt with. # # The applicable license for distributing this module, is that # which is common across much of the perl world, that being you get # to use your choice of either The Artistic License of perl, # or the GPL. You can find copies of the Artistic License at # perl.com (and other places), and you can find copies of the GNU # Public License at Gnu.org (and other places). # # Gordon Haverland, Matter Realisations, perl@materialisations.com # 2003/05/11 use Digest::MD5 qw(md5_base64); use Mail::Folder::Mbox; use Mail::Folder::Maildir; use Mail::Internet; use Getopt::Std; use Date::Manip; use vars qw($opt_h $opt_d); my( $date, $date_dm, $past ); getopts('hd:'); # Delete messages older than $opt_d in source(s) &usage() if( $opt_h ); if( $opt_d ) { die "Strange input (Date::Manip) format\n" unless( $opt_d =~ /^\d\d\d\d\d\d\d\d\d\d:\d\d:\d\d$/ ); } #use Data::Dumper; # For debugging my( %dest, # Cache of Message-ID's $dest_folder, $dest_mbox, # destination mbox/folder $email, # Mail::Internet email object $hdr, # Mail::Header header of $email $ID, # Message-ID of $email message $junk, # Flag to show if Message-ID present $size, # Size of message, as mbox message. $src_folder, $src_mbox, # (Temporary) source mbox/folder name. @list, # Array to stick message numbers into ); if( $#ARGV > 0 ) { $dest_mbox = shift( @ARGV ); } else { &usage(); } # Some email systems, have a placeholder first message, so create # one here too. The dummy message was sent at the origin of the # UNIX epoch (Jan 1, 1970). unless( -e $dest_mbox ) { # Grrrrr, now I find out that Mail::Folder is no longer supported, # and that Mail::Box is (sort of) preferred. Okay, create a # single message mbox by hand. &write_init_mbox(); } $dest_folder = new Mail::Folder('mbox', $dest_mbox ) || die "Error, $dest_mbox is NOT a mbox\n"; my $dmessages = 0; my $smessages = 0; my $amessages = 0; @list = []; # Empty list. # All our messages in destination mbox, are tidied, and have # Message-IDs. Get the first message, then iterate on the # folder until all messages are processed. @list = sort { $a <=> $b } $dest_folder->message_list; foreach (@list) { $email = $dest_folder->get_message( $_ ); $dmessages++; ($ID, $size, $junk) = &get_id( $email ); die "Bad destination folder:($ID,$size,$junk)\n" if( $junk ); if( exists( $dest{$ID} ) ) { # Message exists already if( $dest{$_}->{size} && ($dest{$_}->{size} >= $size) ) { # Truncation is the most common problem, assume newer message # (which is smaller or same size) can be ignored (with warning). print STDERR "Repeat message ($ID), keeping earlier one (bigger)\n"; $dest_folder->delete_message( $_ ); } else { # Later message is bigger, keep it. print STDERR "Repeat message ($ID), keeping later one (bigger)\n"; $dest_folder->delete_message( $dest{$ID}->{msg} ); $dest{$ID}->{msg} = $_; $dest{$ID}->{size} = $size; } } else { my $hash = {}; $hash->{msg} = $_; # $hash->{ID} = $ID; $hash->{size} = $size; $dest{$ID} = $hash; } } # Okay, we are initialized. Start to read in source folders and # process them. while( $src_mbox = shift( @ARGV ) ) { my( @del_messages ); if( -e $src_mbox ) { unless( $src_folder = new Mail::Folder('AUTODETECT', $src_mbox, ) ) { print "$src_mbox is NOT an mbox or maildir\n"; next; } } else { print "$src_mbox doesn't exist\n"; next; } eval { @list = sort { $a <=> $b } $src_folder->message_list; }; foreach (@list) { $email = $src_folder->get_message( $_ ); $hdr = $email->head(); if( $opt_d ) { $date = $hdr->get('Date'); if( $date_dm = &ParseDate($date) ) { $past = &Date_Cmp( $date_dm, $opt_d ); if( $past < 0 ) { push( @del_messages, $_ ); } } } $smessages++; ($ID, $size, $junk) = &get_id( $email ); if( $junk ) { # No Message-ID, so MD5 calculated. Make new email $email->tidy_body(); my $body = $email->body(); $hdr->add('Message-ID', $ID); $email = new Mail::Internet( Header => $hdr, Body => $body ); } unless( exists( $dest{$ID} ) ) { my $hash = {}; $hash->{msg} = -1; # Don't know message number $hash->{size} = $size; $dest{$ID} = $hash; $dest_folder->append_message( $email ); $amessages++; } else { # Message already exists if( $size > $dest{$ID}->{size} ) { print "Newer duplicate Message-ID ($ID), but bigger. Appending anyway\n"; $dest_folder->append_message( $email ); $amessages++; } else { print "Message $ID already exists in dest, skipping\n"; } } } if( $opt_d && ($#del_messages > 0) ) { $src_folder->delete_message( @del_messages ); $src_folder->sync; } $src_folder->close; } $dest_folder->sync; $dest_folder->close; #undef( $dest_folder ); print STDERR "$dmessages originally in $dest_mbox\n"; print STDERR "$smessages in source folders to process\n"; print STDERR "and $amessages of those were added to $dest_mbox\n"; exit( 0 ); sub get_id { my $email = shift; my $hdr = $email->head(); my @tags = $hdr->tags(); my @mids = grep( /Message-ID/i, @tags ); @mids = grep( !/Resent-Message-ID/i, @mids ); # Filter out Resent if( $#mids > -1 ) { # We have a Message-ID, use it my $mid; if( $#mids == 0 ) { $mid = $hdr->get( $mids[0] ); } else { print "Strange, more than 1 Message-ID here\n"; foreach (@mids) { print " $_\n"; } $mid = $hdr->get( $mids[0] ); } my $size = length( $email->as_mbox_string() ); return( $mid, $size, undef ); } else { # Make one from MD5 hash $email->tidy_body(); my $size = length( $email->as_mbox_string() ); my $md5 = md5_base64( $email->as_string() ); return( $md5, $size, $md5 ); } } sub write_init_mbox { my $hdr = new Mail::Header(MailFrom => "KEEP"); my @hdr_array = [ 'From nobody@nowhere.org', 'From: nobody@nowhere.org', 'To: nobody@nowhere.org', 'Date: Thur, 1 Jan 1970 00:00:01 -0700 (MST)', 'Subject: Dummy Message for Mbox', ]; my @bdy_array = [ "Don't delete this message, I need a stub message.\n", ]; $hdr->extract( @hdr_array ); my $email = new Mail::Internet( Header => $hdr, Body => @bdy_array ); my $email_as_string = $email->as_mbox_string; # Note, this is a constant. We could save time and just calculate # it once and then store that value here. my $ID = md5_base64( $email_as_string ); $hdr->add( 'Message-ID', $ID ); $email = new Mail::Internet( Header => $hdr, Body => @bdy_array ); $email_as_string = $email->as_mbox_string; open( MBOX, "> $dest_mbox" ) || die "Can't open $dest_mbox to write initial message to\n"; print MBOX $email_as_string; close( MBOX ); } ------------------------------------------------------------------------------ -- С уважением, Kolotov Alexandr aka mr. Эбола отвечать: akmypost@mail.ru ICQ: 100349254 --------------------------------------- | Registered Linux user # 236664 | ---------------------------------------