bounce_fetcher 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,4 +21,6 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.add_dependency 'tmail', '~> 1.2'
23
23
  s.add_dependency 'bounce-email', '~> 0.0.1'
24
+
25
+ s.add_development_dependency 'eventmachine'
24
26
  end
@@ -4,8 +4,8 @@ module BounceFetcher
4
4
  BounceFetcher.new(*args, &block)
5
5
  end
6
6
 
7
- def self.pop3(host, username, password)
8
- fetcher = PopFetcher.new(host, username, password)
7
+ def self.pop3(host, username, password, port = 110)
8
+ fetcher = PopFetcher.new(host, username, password, port)
9
9
  extractor = EmailExtractor.new
10
10
  detector = BounceDetector.new
11
11
  new(fetcher, extractor, detector)
@@ -22,7 +22,7 @@ module BounceFetcher
22
22
  def each
23
23
  @fetcher.each do |e|
24
24
  if @detector.permanent_bounce?(e)
25
- @extractor.extract_emails(e).each do |email|
25
+ @extractor.extract_emails(e.body).each do |email|
26
26
  yield email
27
27
  end
28
28
  e.delete
@@ -1,6 +1,8 @@
1
1
  # lifted from the action_mailer_verp plugin:
2
2
  # http://github.com/jamesgolick/action_mailer_verp
3
3
 
4
+ require 'net/pop'
5
+
4
6
  module BounceFetcher
5
7
 
6
8
  class PopFetcher
@@ -25,10 +27,11 @@ module BounceFetcher
25
27
  end
26
28
  end
27
29
 
28
- def initialize(host, username, password)
30
+ def initialize(host, username, password, port = 110)
29
31
  @host = host
30
32
  @username = username
31
33
  @password = password
34
+ @port = port
32
35
  end
33
36
 
34
37
  def each
@@ -42,7 +45,7 @@ module BounceFetcher
42
45
 
43
46
  def connection
44
47
  if @connection.nil?
45
- @connection = Net::POP3.new(@host)
48
+ @connection = Net::POP3.new(@host, @port)
46
49
  @connection.start(@username, @password)
47
50
  end
48
51
 
@@ -1,3 +1,3 @@
1
1
  module BounceFetcher
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -24,8 +24,8 @@ class TestBounceFetcher < MiniTest::Unit::TestCase
24
24
  end
25
25
 
26
26
  class FakeExtractor
27
- def extract_emails(tmail)
28
- [tmail.body]
27
+ def extract_emails(string)
28
+ [string]
29
29
  end
30
30
  end
31
31
 
@@ -0,0 +1,53 @@
1
+ require 'minitest/autorun'
2
+ require 'bounce_fetcher'
3
+ require 'net/smtp'
4
+
5
+ class TestIntegration < MiniTest::Unit::TestCase
6
+
7
+ def start_server
8
+ child_pid = fork do
9
+ STDIN.reopen('/dev/null')
10
+ STDOUT.reopen('/dev/null', 'a')
11
+ STDERR.reopen(STDOUT)
12
+ Dir.chdir(File.dirname(__FILE__) + "/support/localpost")
13
+ system("ruby -I. localpost.rb")
14
+ end
15
+ end
16
+
17
+ def send_email(options = {})
18
+ mail = TMail::Mail.new
19
+
20
+ mail.to = options[:to] || 'blah@blah.com'
21
+ mail.from = options[:from] || 'postmaster@blah.com'
22
+ mail.subject = options[:subject] || 'mail delivery failed'
23
+ mail.body = options[:body] || 'foo@bar.com mailbox unavailable'
24
+ mail.date = options[:date] || Time.now
25
+
26
+ begin
27
+ Net::SMTP.start('127.0.0.1', 25000) do |smtp|
28
+ smtp.send_message(mail.to_s, mail.from, mail.to)
29
+ end
30
+ rescue Errno::ECONNREFUSED => e
31
+ sleep 0.1
32
+ retry
33
+ end
34
+ end
35
+
36
+ def setup
37
+ start_server
38
+ send_email # bounce
39
+ send_email(:subject => 'hi', :body => 'there') # not bounce
40
+ end
41
+
42
+ def test_bounce_fetcher
43
+ bounces = BounceFetcher.pop3('127.0.0.1', 'localpost', 'localpost', 11000)
44
+
45
+ emails = []
46
+ bounces.each do |email|
47
+ emails << email
48
+ end
49
+
50
+ assert_equal ['foo@bar.com'], emails
51
+ end
52
+
53
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bounce_fetcher
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
4
+ hash: 21
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Guterl
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-06 00:00:00 -04:00
18
+ date: 2011-04-07 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -49,6 +49,20 @@ dependencies:
49
49
  version: 0.0.1
50
50
  type: :runtime
51
51
  version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: eventmachine
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ type: :development
65
+ version_requirements: *id003
52
66
  description: A set of tools for processing email bounces in a flexible way.
53
67
  email:
54
68
  - michael@diminishing.org
@@ -73,6 +87,7 @@ files:
73
87
  - test/test_bounce_detector.rb
74
88
  - test/test_bounce_fetcher.rb
75
89
  - test/test_email_extractor.rb
90
+ - test/test_integration.rb
76
91
  has_rdoc: true
77
92
  homepage: http://github.com/mguterl/bounce_fetcher
78
93
  licenses: []
@@ -103,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
118
  requirements: []
104
119
 
105
120
  rubyforge_project: bounce_fetcher
106
- rubygems_version: 1.3.7
121
+ rubygems_version: 1.5.2
107
122
  signing_key:
108
123
  specification_version: 3
109
124
  summary: A set of tools for processing email bounces in a flexible way.
@@ -111,3 +126,4 @@ test_files:
111
126
  - test/test_bounce_detector.rb
112
127
  - test/test_bounce_fetcher.rb
113
128
  - test/test_email_extractor.rb
129
+ - test/test_integration.rb