]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
splitmbox.pl: added and switched over to use it
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 14 Nov 2022 12:34:10 +0000 (13:34 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 14 Nov 2022 12:34:10 +0000 (13:34 +0100)
scripts/quilt-mail
scripts/splitmbox.pl [new file with mode: 0755]

index f78827b7e239603463a7f9d80f8a03895c3d219e..cab76296ba000bfae5e7dd613849dcdfb2735e55 100755 (executable)
@@ -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 (executable)
index 0000000..755da50
--- /dev/null
@@ -0,0 +1,54 @@
+#!/usr/bin/perl
+# perl version of splitmbox.py
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2022 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+#
+# 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;
+}
+
+