From: Greg Kroah-Hartman Date: Mon, 14 Nov 2022 12:34:10 +0000 (+0100) Subject: splitmbox.pl: added and switched over to use it X-Git-Tag: v5.10.155~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f3cb88dc21b22102f8be856a5729e264a3c80910;p=thirdparty%2Fkernel%2Fstable-queue.git splitmbox.pl: added and switched over to use it --- diff --git a/scripts/quilt-mail b/scripts/quilt-mail index f78827b7e23..cab76296ba0 100755 --- a/scripts/quilt-mail +++ b/scripts/quilt-mail @@ -13,7 +13,7 @@ SCRIPT_NAME=`basename ${0}` DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # programs that we depend on in this script -REQUIREMENTS="kv splitmbox.py kup mbox2send filterdiff" +REQUIREMENTS="kv splitmbox.pl kup mbox2send filterdiff" # todo check dependancies using hash or something @@ -146,7 +146,7 @@ echo "mbox is now in ${TMP_DIR}/${MBOX}" cd ${TMP_DIR} ${STABLE_QUEUE}/scripts/mbox2send ${ROOT_VERSION} ${FULL_VERSION} ${MBOX} #< ${MBOX}.new formail -ds sh -c 'cat > msg.$FILENO' -splitmbox.py ${MBOX}.new . +splitmbox.pl ${MBOX}.new . # find the "0" email message if [ -f "msg.0" ]; then diff --git a/scripts/splitmbox.pl b/scripts/splitmbox.pl new file mode 100755 index 00000000000..755da501f9e --- /dev/null +++ b/scripts/splitmbox.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl +# perl version of splitmbox.py +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Greg Kroah-Hartman +# +# I didn't want to deal with the python2->3 transition so I rewrote it in perl... + +use Mail::Mbox::MessageParser; + +my ($mbox_file, $directory) = @ARGV; + +if ((not defined $mbox_file) or (not defined $directory)) { + print "splitmbox.pl mbox directory\n"; + exit; +} + +if (not -d $directory) { + print "directory $directory does not exist!\n"; + exit; +} + +my $mbox_reader = new Mail::Mbox::MessageParser( { + 'file_name' => $mbox_file, + 'enable_cache' => 0, + } ); + +die $mbox_reader unless ref $mbox_reader; + +# compute number of messages in mailbox +my $count = 0; +while (!$mbox_reader->end_of_file()) { + my $email = $mbox_reader->read_next_email(); + $count = $count + 1; +} +my $width_string = sprintf("%d", $count); +my $width = length $width_string; +print "mailbox count = $count\n"; +print "string width = $width\n"; + +$mbox_reader->reset(); + +$count = 0; +while (!$mbox_reader->end_of_file()) { + my $filename = sprintf("%s/msg.%0*d", $directory, $width, $count); + my $email = $mbox_reader->read_next_email(); + + print "filename = $filename\n"; + open(FILE, '>', $filename) or die $!; + print FILE $$email; + close(FILE); + $count = $count + 1; +} + +