From a46c4c54c21eea1c5545a250399385f163ae735f Mon Sep 17 00:00:00 2001
From: Patrick Simianer
Date: Sun, 2 Apr 2017 22:51:07 +0200
Subject: maildir-to-imap
---
ruby/maildir-to-imap | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
create mode 100755 ruby/maildir-to-imap
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: [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)
+
--
cgit v1.2.3