Jonathan's Pancheria

dotcom Thousandaire

Ruby Script to Create an Empty Copy of Thunderbird's Folder Structure

I like to keep my work email sorted by year to keep the size of the various boxes small for perusal (oh for the day Google sells corporate gmail!). This script is part of a process to accomplish that. It mirrors your existing Thunderbird folder/mailbox structure to a different directory by creating the same directory hierarchy, creating empty mailbox folders, copying your filter rules and popstate files, and skipping the mailbox summary files.

This script may be generally useful for other purposes as well.

#!/usr/bin/env ruby

require ‘find’
require ‘ftools’

scriptname = File.basename(FILE)
unless ARGV.length == 2
$stderr.puts “Usage: #{scriptname} source_dir dest_dir”
exit 1
from_dir = ARGV0
to_dir = ARGV1
sub_start = from_dir.length

Find.find(from_dir) {|f|
action = ""

if (/\.dat$/ =~ f )
action = “copy”
elsif (/\.msf$/ !~ f )
File::directory?(f) ? action = “mkdir” : action = “touch”

if (action != "")
new_item = to_dir + f[sub_start..-1]
$stderr.print “#{action} #{new_item}…”

case action
when “copy”
File::copy f, new_item, true
when “mkdir”
File::makedirs new_item, true
when “touch”
File::open(new_item, File::CREAT|File::TRUNC|File::RDWR, File::stat(f).mode) {|file|
$stderr.puts “#{new_item} created”
puts “skipping #{f}”

Once you create this new tree, you can copy the insides of each account’s directory into a subfolder that you manually create inside the new tree.

As always, this recipe comes with NO WARRANTY. Always back up your data first. Etc., etc.

Published on 03/01/2006 at 04:01AM . Tags , ,

Comment Ruby Script to Create an Empty Copy of Thunderbird's Folder Structure

Powered by Typo – Thème Frédéric de Villamil | Photo L. Lemos