sr / couchdb-mail

Playing around with CouchDB and Email

This URL has Read+Write access

Simon Rozet (author)
Mon Apr 06 08:17:07 -0700 2009
couchdb-mail / importer.rb
100644 23 lines (19 sloc) 0.581 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env ruby
require "tmail"
require "makura"
 
maildir = File.expand_path(ARGV[1] || "~/Mail")
server = Makura::Server.new
database = server.database("maildir")
headers = %w(From To Subject Date Message-Id In-Reply-To List-Id).map(&:downcase)
 
TMail::Maildir.new(maildir).each { |mail|
  begin
    mail = TMail::Mail.new(mail)
    doc = mail.keys.select { |k| headers.include?(k) }.inject({}) { |doc, header|
      doc.update(header => mail[header].to_s, "body" => mail.body)
    }
    database.save(doc)
  rescue => boom
    $stderr.puts boom.message
    next
  end
}