Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Convert Windows mail to mbox format for import
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
joheirba
n00b
n00b


Joined: 17 Feb 2011
Posts: 6

PostPosted: Sun Apr 03, 2011 4:13 pm    Post subject: Convert Windows mail to mbox format for import Reply with quote

Hello,


I wrote some scripts some weeks ago to convert my Windows Live mail to mbox (for import into Claws, Evolution or Thunderbird).

In fact, the Windows Live mail stores its mails in separate files. The first line always starts with "From: ", so I only needed to remove the ':' and to concatenate the files. To keep my folders, I created one mbox-file for each Windows mail folder. Because this still left me with too many files to import (I had a lot of folders), I also wrote a second script that takes mbox files together in one file and puts the name of the folder in the Subject line.

The first script (copy past this to wm2mbox):
Code:
#!/bin/bash
if [ $# -ne 2 ]
then
  echo "Usage: wm2mbox <windowz-mail-dir> <output-dir>"
  echo "Converts Windowz mail to mbox-files"
  echo "First argument:  your Windows mail directory"
  echo "Second argument: output directory (must be different) !"
  echo "One mbox-file will be generated for each Windows Mail folder, e.g."
  echo "Inbox.mbox, Sent Items.mbox, ..."
  echo
  echo "Example: wm2mbox /mnt/vista/users/admin/"
  exit
fi

wmd="$1" # windows mail directory
oud="$2" # output directory

# Remove trailing /
export wmd="${wmd%/}"
export oud="${oud%/}"

# Create clean output directory
if [ -d "$oud" ]
then
  rm -v "$oud"/*.mbox
else
  mkdir "$oud"
fi

# Enumerate local folders
find "$wmd"/"Local Folders" -mindepth 1 -type d | while read dir
do
  fld=${dir##*/}
  nbr=0

  echo -n "Converting $fld... "
  # find "$dir" -maxdepth 1 -type f -name "*.eml" -size +1c |
  ls "$dir" | grep "eml$" |
  while read msg
  do
    ((nbr++))
    sed -e '1s/^Return-Path: //
            1s/^ */From /
            s/\r$//
    ' "$dir"/"$msg"
  done >>"$oud"/"$fld".mbox

  echo " $nbr done."
done


The second script concatenating different mbox files
Code:
#!/bin/bash
if [ $# -lt 2 ]
then
  echo "usage:   mboxsbj <mxob-files>"
  echo "purpose: add the name of each file to the subject, to import the different files at once"
  echo "The following will concatenate the Audit and Info mboxes to All.mbox and "
  echo "[Audit] or [Info] as first word on the Subject line:"
  echo "  \$ mboxsbj Audit.mbox Info.mbox >All.mbox"
  exit
fi

for f
do
  l=${f##*/}
  l=${l%.*}
  sed -e "s/^Subject:/Subject: [$l] /" "$f"
done


I hope this can help people within their transition from Windows to Linux.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software 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