<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,4 +1,5 @@
 #!/usr/bin/env ruby
+# vim:set ts=2 sw=2 et ai:
 require &quot;fileutils&quot;
 require &quot;socket&quot;
 
@@ -42,11 +43,13 @@ PROG_VER=&quot;0.1.0&quot;
 # usage - Print usage information and exit.
 #
 def usage
-    $stderr.puts &quot;osxmail2maildir v#{PROG_VER}&quot;
-    $stderr.puts &quot;Copyright (c) 2005 Toby DiPasquale &lt;toby@cbcg.net&gt;&quot;
-    $stderr.puts
-    $stderr.puts &quot;usage: #{__FILE__} &lt;target directory&gt; [ &lt;source directory&gt; ]&quot;
-    exit 1
+  $stderr.puts &lt;&lt;EOS
+osxmail2maildir v#{PROG_VER}
+Copyright (c) 2005-2008 Toby DiPasquale &lt;toby@cbcg.net&gt;
+
+Usage: #{__FILE__} &lt;target directory&gt; [ &lt;source directory&gt; ]
+EOS
+  exit 1
 end
 
 #
@@ -54,46 +57,45 @@ end
 #            a particular regular expression @expr to the associated
 #            code block.
 #
-def traverse( dir, expr=nil)
-    dirs = [ dir ]
-    until dirs.empty?
-        d = dirs.first
-	dirs.delete_at( 0)
-	Dir.entries( d).sort.each { |node|
-	    next if node == &quot;.&quot; or node == &quot;..&quot;
-	    name = &quot;#{d}/#{node}&quot;
-	    dirs &lt;&lt; name if File.lstat( name).directory?
-	    yield name if name =~ expr
-	}
-    end
+def traverse(dir, expr=nil)
+  dirs = [ dir ]
+  until dirs.empty?
+    d = dirs.first
+    dirs.delete_at(0)
+    Dir.entries(d).sort.each { |node|
+      next if node == &quot;.&quot; or node == &quot;..&quot;
+      name = &quot;#{d}/#{node}&quot;
+      dirs &lt;&lt; name if File.lstat(name).directory?
+      yield name if name =~ expr
+    }
+  end
 end
 
 #
 # new_maildir - Recursively create directories for a new Maildir mail store.
 #
-def new_maildir( target, source, name)
-    x = name.sub( /Messages$/, &quot;&quot;).sub( /\.mbox\/?.*/, &quot;&quot;)
-    x = x.sub( Regexp.new( source), &quot;&quot;).sub( /^\//, &quot;&quot;)
-    d = &quot;&quot;
-    x.split( &quot;/&quot;).each do |comp|
-        d &lt;&lt; &quot;/&quot; + comp.delete( &quot; &quot;)
-	unless FileTest.directory?( target + &quot;/&quot; + d)
-            FileUtils.mkdir( target + &quot;/&quot; + d)
-	end
+def new_maildir(target, source, name)
+  x = name.sub(/Messages$/, &quot;&quot;).sub(/\.mbox\/?.*/, &quot;&quot;)
+  x = x.sub(Regexp.new(source), &quot;&quot;).sub(/^\//, &quot;&quot;)
+  d = &quot;&quot;
+  x.split(&quot;/&quot;).each do |comp|
+    d &lt;&lt; &quot;/&quot; + comp.delete(&quot; &quot;)
+    unless FileTest.directory?(target + &quot;/&quot; + d)
+      FileUtils.mkdir(target + &quot;/&quot; + d)
     end
-    new_d = target + &quot;/&quot; + d
-    FileUtils.mkdir( new_d + &quot;/cur&quot;)
-    FileUtils.mkdir( new_d + &quot;/new&quot;)
-    FileUtils.mkdir( new_d + &quot;/tmp&quot;)
-    return new_d
+  end
+  new_d = target + &quot;/&quot; + d
+  FileUtils.mkdir(new_d + &quot;/cur&quot;)
+  FileUtils.mkdir(new_d + &quot;/new&quot;)
+  FileUtils.mkdir(new_d + &quot;/tmp&quot;)
+  new_d
 end
 
 #
-# set - Test a number against a bitmask to see if bits are set or cleared.
+# set? - Test a number against a bitmask to see if bits are set or cleared.
 #
-def set?( num, mask)
-    return true if (num &amp; mask) != 0
-    return false
+def set?(num, mask)
+  (num &amp; mask) != 0
 end
 
 #
@@ -103,25 +105,25 @@ end
 # &lt;snip&gt;
 # Update: An anonymous benefactor has the goods:
 #
-#      0	read				1 &lt;&lt; 0
-#      1	deleted				1 &lt;&lt; 1
-#      2	answered			1 &lt;&lt; 2
-#      3	encrypted			1 &lt;&lt; 3
-#      4	flagged				1 &lt;&lt; 4
-#      5	recent				1 &lt;&lt; 5
-#      6	draft				1 &lt;&lt; 6
-#      7	initial (no longer used)	1 &lt;&lt; 7
-#      8	forwarded			1 &lt;&lt; 8
-#      9	redirected			1 &lt;&lt; 9
-#      10-15  	attachment count		3F &lt;&lt; 10 (6 bits)
-#      16-22  	priority level			7F &lt;&lt; 16 (7 bits)
-#      23	signed				1 &lt;&lt; 23
-#      24	is junk				1 &lt;&lt; 24
-#      25	is not junk			1 &lt;&lt; 25
-#      26-28  	font size delta			7 &lt;&lt; 26  (3 bits)
-#      29	junk mail level recorded     	1 &lt;&lt; 29
-#      30	highlight text in toc		1 &lt;&lt; 30
-#      31	(unused)
+#      0  read                      1 &lt;&lt; 0
+#      1  deleted                   1 &lt;&lt; 1
+#      2  answered                  1 &lt;&lt; 2
+#      3  encrypted                 1 &lt;&lt; 3
+#      4  flagged                   1 &lt;&lt; 4
+#      5  recent                    1 &lt;&lt; 5
+#      6  draft                     1 &lt;&lt; 6
+#      7  initial (no longer used)  1 &lt;&lt; 7
+#      8  forwarded                 1 &lt;&lt; 8
+#      9  redirected                1 &lt;&lt; 9
+#      10-15    attachment count    3F &lt;&lt; 10 (6 bits)
+#      16-22    priority level      7F &lt;&lt; 16 (7 bits)
+#      23 signed                    1 &lt;&lt; 23
+#      24 is junk                   1 &lt;&lt; 24
+#      25 is not junk               1 &lt;&lt; 25
+#      26-28    font size delta     7 &lt;&lt; 26  (3 bits)
+#      29 junk mail level recorded  1 &lt;&lt; 29
+#      30 highlight text in toc     1 &lt;&lt; 30
+#      31 (unused)
 #
 # Thank you Mask Man!
 # &lt;/snip&gt;
@@ -133,101 +135,101 @@ end
 #
 # maildirname - Create a proper Maildir filename for this message.
 #
-def maildirname( deliveries, flags)
-    s = &quot;&quot;
-    s &lt;&lt; Time.now.to_i.to_s
-    s &lt;&lt; &quot;.&quot;
-    s &lt;&lt; &quot;P&quot; + Process.pid.to_s
-    s &lt;&lt; &quot;Q&quot; + deliveries.to_s
-    s &lt;&lt; &quot;R&quot; + rand( 2147483648).to_s
-    s &lt;&lt; &quot;.&quot;
-    s &lt;&lt; Socket.gethostname.sub( /\//, &quot;\\057&quot;).sub( /:/, &quot;\\072&quot;)
-    
-    # if this is a new message, we don't add the third part of the
-    # file name (the colon and after)
-    return &quot;/new/#{s}&quot; unless set?( flags, 0x00000001)
-    
-    # this message is not unread, so we add the :2,... part to it
-    # based on the flags in the XML at the bottom of the original
-    # Mail.app message file
-    s &lt;&lt; &quot;:2,&quot;
-    # draft (Mail.app: draft)
-    s &lt;&lt; &quot;D&quot; if set?( flags, 0x00000040)
-    # flagged (Mail.app: flagged)
-    s &lt;&lt; &quot;F&quot; if set?( flags, 0x00000010)
-    # passed (Mail.app: forwarded/redirected)
-    s &lt;&lt; &quot;P&quot; if set?( flags, 0x00000100) or set?( flags, 0x00000200)
-    # replied (Mail.app: answered)
-    s &lt;&lt; &quot;R&quot; if set?( flags, 0x00000004)
-    # seen (Mail.app: read)
-    s &lt;&lt; &quot;S&quot;
-    # trashed (Mail.app: deleted)
-    s &lt;&lt; &quot;T&quot; if set?( flags, 0x00000002)
-    return &quot;/cur/#{s}&quot;
+def maildirname(deliveries, flags)
+  s = &quot;&quot;
+  s &lt;&lt; Time.now.to_i.to_s
+  s &lt;&lt; &quot;.&quot;
+  s &lt;&lt; &quot;P&quot; + Process.pid.to_s
+  s &lt;&lt; &quot;Q&quot; + deliveries.to_s
+  s &lt;&lt; &quot;R&quot; + rand(2147483648).to_s
+  s &lt;&lt; &quot;.&quot;
+  s &lt;&lt; Socket.gethostname.sub(/\//, &quot;\\057&quot;).sub(/:/, &quot;\\072&quot;)
+
+  # if this is a new message, we don't add the third part of the
+  # file name (the colon and after)
+  return &quot;/new/#{s}&quot; unless set?(flags, 0x00000001)
+
+  # this message is not unread, so we add the :2,... part to it
+  # based on the flags in the XML at the bottom of the original
+  # Mail.app message file
+  s &lt;&lt; &quot;:2,&quot;
+  # draft (Mail.app: draft)
+  s &lt;&lt; &quot;D&quot; if set?(flags, 0x00000040)
+  # flagged (Mail.app: flagged)
+  s &lt;&lt; &quot;F&quot; if set?(flags, 0x00000010)
+  # passed (Mail.app: forwarded/redirected)
+  s &lt;&lt; &quot;P&quot; if set?(flags, 0x00000100) or set?(flags, 0x00000200)
+  # replied (Mail.app: answered)
+  s &lt;&lt; &quot;R&quot; if set?(flags, 0x00000004)
+  # seen (Mail.app: read)
+  s &lt;&lt; &quot;S&quot;
+  # trashed (Mail.app: deleted)
+  s &lt;&lt; &quot;T&quot; if set?(flags, 0x00000002)
+  &quot;/cur/#{s}&quot;
 end
 
 #
 # main - Main processing logic.
 #
 def main
-    # check those arguments
-    usage if ARGV[0].nil?
-    target = ARGV[0].strip
-    maildir = &quot;#{ENV['HOME']}/Library/Mail&quot;
-    maildir = ARGV[1].strip unless ARGV[1].nil?
-    puts &quot;Using source directory of '#{maildir}'...&quot;
-    puts &quot;Using target directory of '#{target}'...&quot;
-    deliveries = 0
-    
-    # make the target directory
-    File.umask( 077)
-    FileUtils.mkdir( target)
-    
-    # for each dir in source dir matching /\.mbox$/ (recursive)
-    $stdout.sync = true
-    traverse( maildir, /\.mbox$/) do |dir|
-	d = &quot;#{dir}/Messages&quot;
-	next unless FileTest.directory?( d)
-	new_d = new_maildir( target, maildir, d)
-	
-        # for each filename matching /\.emlx$/
-	msgs = 0
-	Dir.entries( d).each do |file|
-            next unless file =~ /\.emlx$/
-	    msgs += 1
-	    
-            # load all lines of source file into array
-            lines = IO.readlines( &quot;#{d}/#{file}&quot;)
-
-            # remove first line from array
-            lines.delete_at( 0)
-
-            # from the end of the array, look for &quot;&lt;/plist&gt;&quot;; until we find
-            # the matching &quot;&lt;?xml...&gt;&quot; line, we drop each line from the 
-            # array
-            raise &quot;Invalid file format&quot; unless lines[-1] =~ /^&lt;\/plist&gt;/
-	    last = &quot;&quot;
-	    flags = 0
-	    lines.reverse_each do |line|
-	        break if last =~ /^&lt;\?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;\?&gt;/
-		if line =~ /&lt;key&gt;flags&lt;\/key&gt;/
-		    flags = last.sub( /&lt;integer&gt;/, &quot;&quot;).sub( /&lt;\/integer&gt;.*/, &quot;&quot;).to_i
-		end
-		last = lines[-1].dup
-		lines.delete_at( -1)
-            end
-	    
-            # open new Maildir-formatted filename in target dir ($TARGET)
-	    deliveries += 1
-	    n = maildirname( deliveries, flags)
-	    File.open( new_d + &quot;/&quot; + n, &quot;w+&quot;) do |f|
-	        lines.each { |x| f.print x }
-            end
-
-	    print sprintf( &quot;\r%s %d&quot;, &quot;Converting #{dir}...&quot;, msgs)
+  # check those arguments
+  usage if ARGV[0].nil?
+  target = ARGV[0].strip
+  maildir = &quot;#{ENV['HOME']}/Library/Mail&quot;
+  maildir = ARGV[1].strip unless ARGV[1].nil?
+  puts &quot;Using source directory of '#{maildir}'...&quot;
+  puts &quot;Using target directory of '#{target}'...&quot;
+  deliveries = 0
+
+  # make the target directory
+  File.umask(077)
+  FileUtils.mkdir(target)
+
+  # for each dir in source dir matching /\.mbox$/ (recursive)
+  $stdout.sync = true
+  traverse(maildir, /\.mbox$/) do |dir|
+    d = &quot;#{dir}/Messages&quot;
+    next unless FileTest.directory?(d)
+    new_d = new_maildir(target, maildir, d)
+
+    # for each filename matching /\.emlx$/
+    msgs = 0
+    Dir.entries(d).each do |file|
+      next unless file =~ /\.emlx$/
+      msgs += 1
+
+      # load all lines of source file into array
+      lines = IO.readlines(&quot;#{d}/#{file}&quot;)
+
+      # remove first line from array
+      lines.delete_at(0)
+
+      # from the end of the array, look for &quot;&lt;/plist&gt;&quot;; until we find
+      # the matching &quot;&lt;?xml...&gt;&quot; line, we drop each line from the
+      # array
+      raise &quot;Invalid file format&quot; unless lines[-1] =~ /^&lt;\/plist&gt;/
+      last = &quot;&quot;
+      flags = 0
+      lines.reverse_each do |line|
+        break if last =~ /^&lt;\?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;\?&gt;/
+        if line =~ /&lt;key&gt;flags&lt;\/key&gt;/
+          flags = last.sub(/&lt;integer&gt;/, &quot;&quot;).sub( /&lt;\/integer&gt;.*/, &quot;&quot;).to_i
         end
-	puts unless msgs.zero?
+        last = lines[-1].dup
+        lines.delete_at(-1)
+      end
+
+      # open new Maildir-formatted filename in target dir ($TARGET)
+      deliveries += 1
+      n = maildirname(deliveries, flags)
+      File.open(new_d + &quot;/&quot; + n, &quot;w+&quot;) do |f|
+        lines.each { |x| f.print x }
+      end
+
+      print sprintf(&quot;\r%s %d&quot;, &quot;Converting #{dir}...&quot;, msgs)
     end
+    puts unless msgs.zero?
+  end
 end
 
 main if __FILE__ == $0</diff>
      <filename>osxmail2maildir</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>21f766e2ec7b1a37e7a63ccd48ef3ef2897561a0</id>
    </parent>
  </parents>
  <author>
    <name>Toby DiPasquale</name>
    <email>toby@cbcg.net</email>
  </author>
  <url>http://github.com/codeslinger/osxmail2maildir/commit/688718c7d2b38daa9997bbd5108516f81db6f887</url>
  <id>688718c7d2b38daa9997bbd5108516f81db6f887</id>
  <committed-date>2008-12-27T10:01:07-08:00</committed-date>
  <authored-date>2008-12-27T10:01:07-08:00</authored-date>
  <message>fixed up the formatting of the code to make it more readable</message>
  <tree>d0912bf1f9f492fdd8e232094560531b1df1fa36</tree>
  <committer>
    <name>Toby DiPasquale</name>
    <email>toby@cbcg.net</email>
  </committer>
</commit>
