summaryrefslogtreecommitdiff
path: root/ruby/maildir-to-imap
diff options
context:
space:
mode:
Diffstat (limited to 'ruby/maildir-to-imap')
-rwxr-xr-xruby/maildir-to-imap41
1 files changed, 41 insertions, 0 deletions
diff --git a/ruby/maildir-to-imap b/ruby/maildir-to-imap
new file mode 100755
index 0000000..24d6194
--- /dev/null
+++ b/ruby/maildir-to-imap
@@ -0,0 +1,41 @@
+#!/usr/bin/env ruby
+# source: http://wiki.colar.net/ruby_script_to_upload_convert_a_maildir_inbox_to_an_imap_server
+
+require 'net/imap'
+
+if ARGV.length < 5 then
+ STDERR.write "args: <host> <user> <pass> <maildir> <imapdir> [test]"
+ exit
+end
+
+imap_host = ARGV[0]
+imap_user = ARGV[1]
+imap_pass = ARGV[2]
+mail_dir = ARGV[3]+"/"
+imap_dir = ARGV[4]
+TEST_MODE = ARGV[5]!=nil
+
+def upload_dir(imap, mail_dir, imap_dir)
+ imap.examine(imap_dir)
+ msgs = Dir.entries(mail_dir).each_with_index do |f,j|
+ if !File.directory?(f) then
+ STDERR.write "adding #{mail_dir+f} to: #{imap_dir}\n"
+ if !TEST_MODE then
+ imap.append(imap_dir, File.open(mail_dir+f).read,[:Seen])
+ STDERR.write "##{j}\n"
+ end
+ end
+ end
+end
+
+imap = Net::IMAP.new(imap_host, ssl:true)
+imap.authenticate('PLAIN', imap_user, imap_pass)
+
+begin
+ imap.create(imap_dir)
+rescue
+ STDERR.write "failed creating: #{imap_dir}, that's probably ok\n"
+end
+
+upload_dir(imap, mail_dir, imap_dir)
+