Created
February 19, 2013 02:46
-
-
Save ericlathrop/4982676 to your computer and use it in GitHub Desktop.
Convert MH mail folders to MBOX files, which are used by Mozilla Thunderbird.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# mh2mbox.sh | |
# By Eric Lathrop <[email protected]> | |
# | |
# Convert MH mail folders to MBOX files | |
# Useful for switching to Mozilla Thunderbird | |
# | |
# Copy this script to ~/Mail/ and execute. | |
# | |
# Requires the "packf" command from the nmh package in Ubuntu | |
DEST="mbox" | |
# Note: in Ubuntu, packf gets installed under /usr/bin/mh/ so it's not normally in the $PATH | |
PACKF="/usr/bin/mh/packf" | |
(IFS=' | |
' | |
for DIR in `find . -type d`; do | |
if [ "$DIR" = "." ]; then | |
continue | |
fi | |
if [ "$DIR" = "./$DEST" ]; then | |
continue | |
fi | |
CONVDIR="." | |
if [ `dirname $DIR` != "." ]; then | |
CONVDIR=`dirname "$DIR" | sed -e "s/\.\///" | sed -e "s/\//.sbd\//"`'.sbd' | |
fi | |
mkdir -p "$DEST/$CONVDIR" | |
MAILBOX=`basename $DIR` | |
MBOXPATH="$DEST/$CONVDIR/$MAILBOX" | |
# create an empty file in case there aren't any messages | |
# this fixes a thunderbird problem where it won't show subfolders | |
# for a folder that doesn't have a matching file | |
touch $MBOXPATH | |
yes | $PACKF +"$DIR" -mbox -file $MBOXPATH | |
done | |
) |
I have found the error.
CONVDIR=
dirname "$DIR" | sed -e "s/.///" | sed -e "s///.sbd//"'.sbd'
You have to add g
at the end of the second regular expression used by sed to obtain a "global" substitution, now the directories tree can be deep without limitation. The new code should be something like that:
CONVDIR=
dirname "$DIR" | sed -e "s/.///" | sed -e "s///.sbd//g"'.sbd'
Regards
Alessandro "gallus" Gallieri
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have found some problems with folder tree deeper than 2 and with presence of spaces in folders name
Regard
gallus