Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Here's a script to convert mh to maildir directory/names
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
jkcunningham
l33t
l33t


Joined: 28 Apr 2003
Posts: 649
Location: 47.49N 121.79W

PostPosted: Sat May 01, 2004 2:04 am    Post subject: Here's a script to convert mh to maildir directory/names Reply with quote

There's probably easier and better ways to do this, but I couldn't find one. So I wrote a little script that creates temporary procmailrc files and then pushes mail through procmail with a simple rule to write them in the correct place and format.

The problem I had was trying to convert a large volume of mh (Sylpheed) mail in a number of directories into maildir directories. The mail files themselves obviously don't change, but the naming systems and subdirectory structures are completely different. Here's the script:


    #!/bin/bash

    ## Script 'cnvtmail' transfers mail from OLDIR to NEWDIR in maildir format
    ## Builds a temporary procmailrc script
    ## Syntax:
    ## cnvtmail OLDIR NEWDIR

    OLDIR=$1
    NEWDIR=$2
    FILES=`/bin/ls -1 ${OLDIR}/*`
    RC="cnvt.rc"

    echo "VERBOSE=off" > $RC
    echo "LOCKEXT=.lock" >> $RC
    echo "MAILDIR='${HOME}/Mail'" >> $RC
    echo "DEFAULT='${MAILDIR}/inbox'" >> $RC
    echo "LINEBUF=4096" >> $RC
    echo ":0:.lck" >> $RC
    echo "${NEWDIR}/" >> $RC

    for M in ${FILES}; do
    procmail ./cnvt.rc < $M
    done

    rm $RC


Here are some comments about it:
(1) It would be easy to translate into other formats - just modify the cnvt.rc line accordingly. For example, to write mbox format, take off the trailing '/'
(2) I believe it the input files could just as easily be mbox format - but in that case you would only be inputting a file and not a directory - the modification should be obvious.
(3) It could easily be wrapped in another loop so it moved a directory tree from one format to another. I thought of doing this, but then didn't because I wanted to change some of the names and my structure as well as the format.

I hope someone else finds it useful.

-Jeff


Last edited by jkcunningham on Sat May 01, 2004 4:48 pm; edited 1 time in total
Back to top
View user's profile Send private message
amne
Bodhisattva
Bodhisattva


Joined: 17 Nov 2002
Posts: 6378
Location: Graz / EU

PostPosted: Sat May 01, 2004 10:24 am    Post subject: Reply with quote

Moved from Networking & Security to Documentation, Tips & Tricks.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum