unfuddle_my_email 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 1
4
- :patch: 4
3
+ :minor: 2
4
+ :patch: 0
5
5
  :build:
@@ -3,7 +3,7 @@ unfuddle_username: 'username'
3
3
  unfuddle_password: 'password'
4
4
  unfuddle_ssl: true # set to true only if enabled for your account, false otherwise
5
5
  unfuddle_project_id: 1234
6
- unfuddle_api_url: '/api/v1/'
6
+ unfuddle_api_url: '/api/v1' # No trailing '/'
7
7
  pop3_server: 'pop.example.com'
8
8
  pop3_port: 995
9
9
  pop3_ssl: true
@@ -1,10 +1,9 @@
1
1
  require 'net/pop3_ssl'
2
- require 'tmail'
3
2
 
4
3
  module UnfuddleMyEmail
5
4
  # Fetcher iterates through all emails in the given POP3 mailbox and
6
5
  # yields each one, optionally deleting the message after yield. The
7
- # message yielded is an instance of TMail::Mail.
6
+ # message yielded is an instance of TmailAdapter.
8
7
  #
9
8
  # Example:
10
9
  #
@@ -14,7 +13,7 @@ module UnfuddleMyEmail
14
13
  # end
15
14
  #
16
15
  # # Enumerable is included so you can use those features (except for sort,min,max) as well:
17
- # fetcher.to_a # => [#<TMail::Mail instance>]
16
+ # fetcher.to_a # => [#<TmailAdapter instance>]
18
17
  class Fetcher
19
18
  def initialize(server, port, ssl, username, password, delete=false)
20
19
  @pop3_server = server
@@ -31,7 +30,7 @@ module UnfuddleMyEmail
31
30
  end
32
31
  Net::POP3.start(@pop3_server, @pop3_port, @pop3_username, @pop3_password) do |pop|
33
32
  pop.each_mail { |message|
34
- mail_item = TMail::Mail.parse(message.pop)
33
+ mail_item = TmailAdapter.new(message.pop)
35
34
  yield mail_item
36
35
  message.delete if @pop3_delete
37
36
  }
@@ -0,0 +1,19 @@
1
+ require 'mail'
2
+
3
+ class TmailAdapter
4
+ def initialize(message)
5
+ @message = Mail.new(message)
6
+ end
7
+
8
+ def subject
9
+ @message.subject
10
+ end
11
+
12
+ def from
13
+ @message.from.first
14
+ end
15
+
16
+ def body
17
+ @message.body.decoded
18
+ end
19
+ end
@@ -1,5 +1,6 @@
1
1
  require 'unfuddle_my_email/configuration'
2
2
  require 'unfuddle_my_email/email_ticket'
3
+ require 'unfuddle_my_email/tmail_adapter'
3
4
  require 'unfuddle_my_email/fetcher'
4
5
  require 'unfuddle_my_email/poster'
5
6
  require 'unfuddle_my_email/runner'
data/test/fetcher_test.rb CHANGED
@@ -2,7 +2,6 @@ require 'flexmock/test_unit'
2
2
  require 'net/pop3_ssl'
3
3
  require 'shoulda'
4
4
  require 'test/unit'
5
- require 'tmail'
6
5
  require 'unfuddle_my_email'
7
6
 
8
7
  class FetcherTest < Test::Unit::TestCase
@@ -12,11 +11,11 @@ class FetcherTest < Test::Unit::TestCase
12
11
  setup do
13
12
  @fetcher = Fetcher.new('pop.example.com', 110, false, 'user', 'password')
14
13
 
15
- @message = flexmock('message', :test => true)
14
+ @message = flexmock('message', :tested => true)
16
15
  @message.should_receive(:pop).and_return(
17
16
  "From: john@example.com\n" +
18
17
  "Subject: Test subject\n\n" +
19
- "This is a test.\n.\n"
18
+ "This is a test.\n\n"
20
19
  )
21
20
 
22
21
  @pop3_int = flexmock('pop3_int')
@@ -24,17 +23,17 @@ class FetcherTest < Test::Unit::TestCase
24
23
 
25
24
  @pop3_lib = flexmock(Net::POP3)
26
25
  @pop3_lib.should_receive(:start).and_yield(@pop3_int)
27
-
28
- @tmail_lib = flexmock(TMail::Mail)
29
- @tmail_lib.should_receive(:parse).and_return(@message)
30
26
  end
31
27
 
32
28
  should "yield each message" do
33
- success = false
29
+ test_message = nil
34
30
  @fetcher.each do |message|
35
- success = message.test
31
+ test_message = message
36
32
  end
37
- assert success
33
+
34
+ assert_equal "john@example.com", test_message.from
35
+ assert_equal "Test subject", test_message.subject
36
+ assert_equal "This is a test.", test_message.body
38
37
  end
39
38
  end
40
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unfuddle_my_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Haley
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-15 00:00:00 -07:00
12
+ date: 2010-01-21 00:00:00 -07:00
13
13
  default_executable: unfuddle_my_email
14
14
  dependencies: []
15
15
 
@@ -34,6 +34,7 @@ files:
34
34
  - lib/unfuddle_my_email/fetcher.rb
35
35
  - lib/unfuddle_my_email/poster.rb
36
36
  - lib/unfuddle_my_email/runner.rb
37
+ - lib/unfuddle_my_email/tmail_adapter.rb
37
38
  - test/configuration_test.rb
38
39
  - test/email_ticket_test.rb
39
40
  - test/fetcher_test.rb
@@ -70,6 +71,6 @@ specification_version: 3
70
71
  summary: Post emails from POP server as Unfuddle Tickets.
71
72
  test_files:
72
73
  - test/poster_test.rb
73
- - test/configuration_test.rb
74
74
  - test/fetcher_test.rb
75
75
  - test/email_ticket_test.rb
76
+ - test/configuration_test.rb