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
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
--- /dev/null
+#!/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;
+}
+
+