mlist 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ *0.1.12 [Enhancement] (2010-03-26)
2
+
3
+ * Added footers to html parts of email. [aiwilliams]
4
+
1
5
  *0.1.10 [Enhancement] (2010-01-11)
2
6
 
3
7
  * Delegating back to the list the question of whether an email has been to the list before (X-BeenThere checking). [aiwilliams]
@@ -60,4 +64,4 @@
60
64
  * Including display_name in from address of EmailPost. [aiwilliams]
61
65
  * Improved extraction of text when it is nested inside parts. [aiwilliams]
62
66
 
63
- *0.1.1 [First Working Release] (January 5, 2009)
67
+ *0.1.1 [First Working Release] (January 5, 2009)
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :patch: 12
2
+ :patch: 13
3
3
  :major: 0
4
4
  :build:
5
5
  :minor: 1
@@ -0,0 +1,63 @@
1
+ require 'net/imap'
2
+
3
+ module MList
4
+ module EmailServer
5
+
6
+ class Imap < Base
7
+ def initialize(settings)
8
+ super(settings)
9
+ @imap = Net::IMAP.new(
10
+ settings[:server],
11
+ settings[:port],
12
+ settings[:ssl]
13
+ )
14
+ end
15
+
16
+ def deliver(tmail)
17
+ raise "Mail delivery is not presently supported by the Imap server. Please use the '#{MList::EmailServer::Default.name}' type."
18
+ end
19
+
20
+ def execute
21
+ connect { process_folders }
22
+ end
23
+
24
+ def archive_message_id(id)
25
+ @imap.copy(id, settings[:archive_folder])
26
+ @imap.store(id, '+FLAGS', [:Deleted])
27
+ end
28
+
29
+ def connect
30
+ @imap.login(settings[:username], settings[:password])
31
+ begin
32
+ yield
33
+ ensure
34
+ @imap.close
35
+ end
36
+ end
37
+
38
+ def process_folders
39
+ Array(settings[:source_folders]).each do |folder|
40
+ process_folder(folder)
41
+ end
42
+ end
43
+
44
+ def process_folder(folder)
45
+ @imap.select(folder)
46
+ @imap.search(['ALL']).each do |message_id|
47
+ process_message_id(message_id)
48
+ archive_message_id(message_id)
49
+ end
50
+ end
51
+
52
+ def process_message_id(id)
53
+ content = @imap.fetch(id, 'RFC822')[0].attr['RFC822']
54
+ process_message(content)
55
+ end
56
+
57
+ def process_message(content)
58
+ receive(TMail::Mail.parse(content))
59
+ end
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,72 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'mlist/email_server/imap'
3
+
4
+ describe MList::EmailServer::Imap, 'settings' do
5
+ it 'should use the provided credentials' do
6
+ mock(Net::IMAP).new('host', 993, true) { mock('imap') }
7
+ MList::EmailServer::Imap.new(:server => 'host', :port => 993, :ssl => true)
8
+ end
9
+
10
+ it 'should login with the provided credentials, process the folders, close on completion' do
11
+ imap_server = Object.new
12
+ stub(Net::IMAP).new { imap_server }
13
+
14
+ mock(imap_server).login('aahh', 'eeya')
15
+ mock(imap_server).close
16
+
17
+ imap = MList::EmailServer::Imap.new(
18
+ :username => 'aahh', :password => 'eeya'
19
+ )
20
+ mock(imap).process_folders
21
+ imap.execute
22
+ end
23
+
24
+ it 'should process the provided folders' do
25
+ imap_server = Object.new
26
+ stub(Net::IMAP).new { imap_server }
27
+ imap = MList::EmailServer::Imap.new(
28
+ :source_folders => ['Inbox', 'Spam']
29
+ )
30
+ mock(imap).process_folder('Inbox')
31
+ mock(imap).process_folder('Spam')
32
+ imap.process_folders
33
+ end
34
+ end
35
+
36
+ describe MList::EmailServer::Imap, 'processing' do
37
+ before do
38
+ @imap_server = 'mock_imap_server'
39
+ stub(Net::IMAP).new { @imap_server }
40
+ @imap = MList::EmailServer::Imap.new({:archive_folder => 'Archive'})
41
+ end
42
+
43
+ it 'should examine the specified folder and process all the messages' do
44
+ message_ids = [1,2]
45
+ mock(@imap_server).select('folder')
46
+ mock(@imap_server).search(['ALL']) { message_ids }
47
+ mock(@imap).process_message_id(1)
48
+ mock(@imap).archive_message_id(1)
49
+ mock(@imap).process_message_id(2)
50
+ mock(@imap).archive_message_id(2)
51
+ @imap.process_folder('folder')
52
+ end
53
+
54
+ it 'should process the RFC822 message content' do
55
+ mock(@imap_server).fetch(1, 'RFC822').mock![0].mock!.attr.mock!['RFC822'].returns('email content')
56
+ mock(@imap).process_message('email content')
57
+ @imap.process_message_id(1)
58
+ end
59
+
60
+ it 'should wrap up RFC822 content in a TMail::Mail object' do
61
+ tmail = 'mock_tmail'
62
+ mock(TMail::Mail).parse('email content') { tmail }
63
+ mock(@imap).receive(tmail)
64
+ @imap.process_message('email content')
65
+ end
66
+
67
+ it 'should archive to the specified folder' do
68
+ mock(@imap_server).copy(1, 'Archive')
69
+ mock(@imap_server).store(1, '+FLAGS', [:Deleted])
70
+ @imap.archive_message_id(1)
71
+ end
72
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 12
9
- version: 0.1.12
8
+ - 13
9
+ version: 0.1.13
10
10
  platform: ruby
11
11
  authors:
12
12
  - Adam Williams
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-26 00:00:00 -04:00
17
+ date: 2010-04-02 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -40,6 +40,7 @@ files:
40
40
  - lib/mlist/email_server/base.rb
41
41
  - lib/mlist/email_server/default.rb
42
42
  - lib/mlist/email_server/fake.rb
43
+ - lib/mlist/email_server/imap.rb
43
44
  - lib/mlist/email_server/pop.rb
44
45
  - lib/mlist/email_server/smtp.rb
45
46
  - lib/mlist/email_subscriber.rb
@@ -92,6 +93,7 @@ summary: A Ruby mailing list library designed to be integrated into other applic
92
93
  test_files:
93
94
  - spec/fixtures/schema.rb
94
95
  - spec/integration/date_formats_spec.rb
96
+ - spec/integration/imap_email_server_spec.rb
95
97
  - spec/integration/mlist_spec.rb
96
98
  - spec/integration/pop_email_server_spec.rb
97
99
  - spec/integration/proof_spec.rb