diff options
author | Patrick Simianer <p@simianer.de> | 2017-04-02 22:51:07 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2017-04-02 22:51:07 +0200 |
commit | a46c4c54c21eea1c5545a250399385f163ae735f (patch) | |
tree | 153a573eadac846afea90d4fc07d6b666509e637 | |
parent | 833f7f1905bafb28574affc99056695c04390323 (diff) |
maildir-to-imap
-rwxr-xr-x | ruby/maildir-to-imap | 41 |
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) + |