Skip to content

Instantly share code, notes, and snippets.

@lsloan
Forked from ericlathrop/mh2mbox.sh
Created October 5, 2018 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsloan/4a822a2c4739247918678c0b94fb12bc to your computer and use it in GitHub Desktop.
Save lsloan/4a822a2c4739247918678c0b94fb12bc to your computer and use it in GitHub Desktop.
Convert MH mail folders to MBOX files, which are used by Mozilla Thunderbird.
#!/bin/bash
#
# mh2mbox.sh
# By Eric Lathrop <eric@ericlathrop.com>
#
# 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\//g"`'.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
)
@lsloan
Copy link
Author

lsloan commented Oct 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment