summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAntonio Terceiro <terceiro@debian.org>2013-08-13 01:01:59 +0200
committerAntonio Terceiro <terceiro@softwarelivre.org>2013-08-13 01:51:52 +0200
commit893eda640f3344adc08d77b475297a1353691d38 (patch)
treefbe706dcf7fdf4edef7d349e49f2aad95a7f568c /test
parentb55bf0a982752bf594dd25fb88b07222e45899a5 (diff)
downloadfeed2imap-893eda640f3344adc08d77b475297a1353691d38.tar.gz
feed2imap-893eda640f3344adc08d77b475297a1353691d38.tar.bz2
feed2imap-893eda640f3344adc08d77b475297a1353691d38.zip
Fix MaildirAccount class; add tests
Diffstat (limited to '')
-rw-r--r--test/maildir/cur/1376317520.15784_1.debian:2,S11
-rw-r--r--test/maildir/cur/1376319137.17850_1.debian:2,11
-rw-r--r--test/maildir/cur/1376320022.18396_5.debian:2,FS11
-rw-r--r--test/maildir/new/1376320099.18396_7.debian11
-rw-r--r--test/tc_maildir.rb93
5 files changed, 137 insertions, 0 deletions
diff --git a/test/maildir/cur/1376317520.15784_1.debian:2,S b/test/maildir/cur/1376317520.15784_1.debian:2,S
new file mode 100644
index 0000000..fc6aaab
--- /dev/null
+++ b/test/maildir/cur/1376317520.15784_1.debian:2,S
@@ -0,0 +1,11 @@
+Date: Mon, 12 Aug 2013 16:25:20 +0200
+From: Antonio Terceiro <terceiro@debian.org>
+To: terceiro@debian.org
+Subject: UTF-8 data: =?iso-8859-1?B?4ent8/o=?=
+Message-ID: <regular-message-id@debian.org>
+MIME-Version: 1.0
+Content-Type: text/plain; charset=us-ascii
+Content-Disposition: inline
+User-Agent: Mutt/1.5.21 (2010-09-15)
+
+This is a sample email
diff --git a/test/maildir/cur/1376319137.17850_1.debian:2, b/test/maildir/cur/1376319137.17850_1.debian:2,
new file mode 100644
index 0000000..0bff46a
--- /dev/null
+++ b/test/maildir/cur/1376319137.17850_1.debian:2,
@@ -0,0 +1,11 @@
+Date: Mon, 12 Aug 2013 16:52:17 +0200
+From: Antonio Terceiro <terceiro@debian.org>
+To: terceiro@debian.org
+Subject: an unread message
+Message-ID: <unread-message-id@debian.org>
+MIME-Version: 1.0
+Content-Type: text/plain; charset=us-ascii
+Content-Disposition: inline
+User-Agent: Mutt/1.5.21 (2010-09-15)
+
+This message was not read yet
diff --git a/test/maildir/cur/1376320022.18396_5.debian:2,FS b/test/maildir/cur/1376320022.18396_5.debian:2,FS
new file mode 100644
index 0000000..2547416
--- /dev/null
+++ b/test/maildir/cur/1376320022.18396_5.debian:2,FS
@@ -0,0 +1,11 @@
+Date: Mon, 12 Aug 2013 17:07:02 +0200
+From: Antonio Terceiro <terceiro@debian.org>
+To: terceiro@debian.org
+Subject: a flagged message
+Message-ID: <flagged-message-id@debian.org>
+MIME-Version: 1.0
+Content-Type: text/plain; charset=us-ascii
+Content-Disposition: inline
+User-Agent: Mutt/1.5.21 (2010-09-15)
+
+This message is flagged.
diff --git a/test/maildir/new/1376320099.18396_7.debian b/test/maildir/new/1376320099.18396_7.debian
new file mode 100644
index 0000000..ba54ddd
--- /dev/null
+++ b/test/maildir/new/1376320099.18396_7.debian
@@ -0,0 +1,11 @@
+Date: Mon, 12 Aug 2013 17:08:19 +0200
+From: Antonio Terceiro <terceiro@debian.org>
+To: terceiro@debian.org
+Subject: a new message
+Message-ID: <new-message-id@debian.org>
+MIME-Version: 1.0
+Content-Type: text/plain; charset=us-ascii
+Content-Disposition: inline
+User-Agent: Mutt/1.5.21 (2010-09-15)
+
+This message is new
diff --git a/test/tc_maildir.rb b/test/tc_maildir.rb
new file mode 100644
index 0000000..343e5f7
--- /dev/null
+++ b/test/tc_maildir.rb
@@ -0,0 +1,93 @@
+require 'test/unit'
+require 'fileutils'
+require 'tmpdir'
+require 'mocha/setup'
+
+require 'feed2imap/maildir'
+
+class TestMaildir < Test::Unit::TestCase
+
+ def setup
+ @tmpdirs = []
+ end
+
+ def tear_down
+ @tmpdirs.each do |dir|
+ FileUtils.rm_rf(dir)
+ end
+ end
+
+ def test_cleanup
+ folder = create_maildir
+ msgs = message_count(folder)
+
+ maildir_account.cleanup(folder)
+
+ assert_equal msgs - 1, message_count(folder)
+ end
+
+ def test_putmail
+ folder = create_maildir
+ msgs = message_count(folder)
+
+ mail = RMail::Message.new
+ mail.header['Subject'] = 'a message I just created'
+ mail.body = 'to test maildir'
+ maildir_account.putmail(folder, mail)
+
+ assert_equal msgs + 1, message_count(folder)
+ end
+
+ def test_updatemail
+ folder = create_maildir
+ path = maildir_account.send(
+ :find_mails,
+ folder,
+ 'regular-message-id@debian.org'
+ ).first
+ assert_not_nil path
+ mail = RMail::Message.new
+ mail.header['Subject'] = 'a different subject'
+ mail.header['Message-ID'] = 'regular-message-id@debian.org'
+ mail.body = 'This is the body of the message'
+ maildir_account.updatemail(folder, mail, 'regular-message-id@debian.org')
+
+ updated_path = maildir_account.send(
+ :find_mails,
+ folder,
+ 'regular-message-id@debian.org'
+ ).first
+ updated_mail = RMail::Parser.read(File.open(File.join(folder, updated_path)))
+
+ assert_equal 'a different subject', updated_mail.header['Subject']
+ end
+
+ def test_find_mails
+ folder = create_maildir
+ assert_equal 0, maildir_account.send(:find_mails, folder, 'SomeRandomMessageID').size
+ end
+
+ private
+
+ def create_maildir
+ parent = Dir.mktmpdir
+ @tmpdirs << parent
+ FileUtils.cp_r('test/maildir', parent)
+ return File.join(parent, 'maildir')
+ end
+
+ def message_count(folder)
+ Dir.glob(File.join(folder, '**', '*')).reject { |f| File.directory?(f) }.size
+ end
+
+ def maildir_account
+ @maildir_account ||=
+ begin
+ MaildirAccount.new.tap do |account|
+ account.stubs(:puts)
+ end
+ end
+ end
+
+end
+