Maildir to Mailbox

      Nessun commento su Maildir to Mailbox

This is ok for every mdir to mbox conversion but it specially suited if you move from the evolution mail client to the thunderbird one.

Mdir 2 mbox

Mdir 2 mbox

STEP 0

 

a) retrieve required util from

https://github.com/jooooooon/maildir2mbox

(Also the perl helper file as in the instruction)

This perl script works for just a folder: if you have just one your done. I have many so I wrote a wrap for that script that automatically iterates from the folders with the intent to avoid manual working.

 

b.1) fix perl

(from http://www.livejournal.com/doc/server/lj.install.perl_setup.modules.html )

From the root prompt on your server, invoke the CPAN shell:

# perl -MCPAN -e shell

Once the Perl interpreter has loaded (and been configured), you can install modules with: install MODULENAME.

The first thing you should do is upgrade your CPAN:

cpan> install Bundle::CPAN

Once it is completed, type:

cpan> reload cpan

Now, enter the following command to retrieve the required modules:

CPAN> install DateTime::Format::Mail

 

Or

 

b.2)

As stated in the previous link simply do

apt-get install libdatetime-perl libdatetime-format-mail-perl

 

STEP 1

(Create files and dirs)

a)

mkdir /tmp/mymail

mkdir /tmp/mymail/mbox

cp -r ~/.local/share/evolution/mail/local /tmp/mymail

cd /tmp/mymail/local

find . -type d > /tmp/mymail/folderlist.txt

cd /tmp/mymail

The file /tmp/mymail/folderlist.txt contains lines such as.

./cur
./tmp
./new
./.IT
/.IT/cur
./.IT/tmp
./.IT/new
./.Tempo libero.Comics
./.Tempo libero.Comics/cur
./.Tempo libero.Comics/tmp
./.Tempo libero.Comics/new
./.IT.FSFE-europe
./.IT.FSFE-europe/cur
./.IT.FSFE-europe/tmp
./.IT.FSFE-europe/new
./.Societa.ATTAC
./.Societa.ATTAC/cur
./.Societa.ATTAC/tmp
./.Societa.ATTAC/new
./.Outbox
./.Outbox/cur
./.Outbox/tmp
./.Outbox/new

While in the /tmp/mymail dir and do

/tmp/mymail$ grep cur folderlist.txt > folderlist1.txt

/tmp/mymail$ awk -F”/” ‘{ print $2 }’ folderlist1.txt > folderlist.txt

Now the file /tmp/mymail/folderlist.txt contains in each line the name of the folder to be processed (all the folders are hidden as their names begin with a dot).

 

a.2)

This step is required ONLY if the name of at least one of the folders contains a blank (a space, like in “United Kingdom”).

My wrap script can’t handle directory names with spaces, so those have to be processed by hand.

To do that edit the file /tmp/mymail/folderlist.txt and cut that folder names one by one and paste them in a file named like /tmp/mymail/ToBeProcessedByHand.txt (what a name 🙂 )

(I end up processing 34 folders automatically and 4 by hand.)

 

b)

Edit the file /tmp/mymail/folderlist.txt and remove the line for “cur” (the wrap script takes care of it).

 

STEP 2

Download the script

OR

copy a paste in a file named md2mb_allfolder.sh this:

#! /bin/bash

FOLDERLIST=/tmp/mymail/folderlist.txt
DESTPATH=/tmp/mymail/mbox/
ABSOLUTE_EXE=/home/mune/bin/maildir2mbox
BASEDIR=/tmp/mymail/local

cd $BASEDIR
COUNTER=1

while IFS=” read -r FOLDERNAME; do
echo “Processing “$FOLDERNAME” “$COUNTER” ”
cd “$FOLDERNAME”
cd cur
MBOXNAME=`echo $FOLDERNAME | cut -d “.” -f2-`
$ABSOLUTE_EXE > $DESTPATH$MBOXNAME
cd ../new
$ABSOLUTE_EXE >> $DESTPATH$MBOXNAME
cd $BASEDIR
COUNTER=$((COUNTER + 1))
done <$FOLDERLIST

FOLDERNAME=”INBOX”
echo “Processing “$FOLDERNAME” “$COUNTER” ”
cd cur
MBOXNAME=$FOLDERNAME
$ABSOLUTE_EXE > $DESTPATH$MBOXNAME
cd ../new
$ABSOLUTE_EXE >> $DESTPATH$MBOXNAME

cd $BASEDIR

Customize the wrap string to suit your directory structure.

Make it executable (chmod a+x <path_to_script>/md2mb_allfolder.sh ).

 

STEP 3

cd /tmp/mymail/local

<path_to_script>/md2mb_allfolder.sh

Federico Munerotto Jan 2016

Lascia un commento