received 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/received/lmtp.rb CHANGED
@@ -44,7 +44,7 @@ module Received
44
44
  error
45
45
  end
46
46
  when :lhlo_received
47
- if ev =~ /^MAIL FROM:<?([^>]+)/
47
+ if ev =~ /^MAIL FROM:<?([^<>]*)/
48
48
  @from = $1
49
49
  ok
50
50
  :mail_from_received
@@ -52,7 +52,7 @@ module Received
52
52
  error
53
53
  end
54
54
  when :mail_from_received
55
- if ev =~ /^RCPT TO:<?([^>]+)/
55
+ if ev =~ /^RCPT TO:<?([^<>]*)/
56
56
  @rcpt << $1
57
57
  ok
58
58
  :rcpt_to_received
@@ -60,7 +60,7 @@ module Received
60
60
  error
61
61
  end
62
62
  when :rcpt_to_received
63
- if ev =~ /^RCPT TO:<?([^>]+)/
63
+ if ev =~ /^RCPT TO:<?([^<>]*)/
64
64
  @rcpt << $1
65
65
  ok
66
66
  elsif ev == "DATA"
@@ -1,3 +1,3 @@
1
1
  module Received
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
data/spec/lmtp_spec.rb CHANGED
@@ -2,14 +2,13 @@ require 'spec_helper'
2
2
  require 'logger'
3
3
 
4
4
  describe Received::LMTP do
5
- before :each do
6
- @mock = mock 'conn'
7
- @mock.should_receive(:send_data).with("220 localhost LMTP server ready\r\n")
8
- logger = Logger.new($stderr)
9
- @mock.stub!(:logger).and_return(logger)
10
- @mock.logger.debug "*** Starting test ***"
11
- @proto = Received::LMTP.new(@mock)
12
- @proto.start!
5
+ let(:conn) { mock(:conn, :logger => Logger.new(STDERR)) }
6
+ let(:proto) { Received::LMTP.new(conn) }
7
+
8
+ before do
9
+ conn.should_receive(:send_data).with("220 localhost LMTP server ready\r\n")
10
+ conn.logger.debug "*** Starting test ***"
11
+ proto.start!
13
12
  end
14
13
 
15
14
  describe "Full flow" do
@@ -18,28 +17,28 @@ describe Received::LMTP do
18
17
  def begin_flow!
19
18
  ["LHLO", "MAIL FROM:<spec1@example.com>", "RCPT TO:<spec2@example.com>",
20
19
  "RCPT TO:<spec3@example.com>", "DATA", "#{body}.", "QUIT"].each do |line|
21
- @mock.logger.debug "client: #{line}"
22
- @proto.on_data(line + "\r\n")
20
+ conn.logger.debug "client: #{line}"
21
+ proto.on_data(line + "\r\n")
23
22
  end
24
23
  end
25
24
 
26
25
  def common_expectations!
27
- @mock.should_receive(:send_data).with("250-localhost\r\n")
28
- @mock.should_receive(:send_data).with("250-8BITMIME\r\n250 PIPELINING\r\n")
29
- @mock.should_receive(:send_data).with("250 OK\r\n").exactly(3).times
30
- @mock.should_receive(:send_data).with("354 End data with <CR><LF>.<CR><LF>\r\n")
26
+ conn.should_receive(:send_data).with("250-localhost\r\n")
27
+ conn.should_receive(:send_data).with("250-8BITMIME\r\n250 PIPELINING\r\n")
28
+ conn.should_receive(:send_data).with("250 OK\r\n").exactly(3).times
29
+ conn.should_receive(:send_data).with("354 End data with <CR><LF>.<CR><LF>\r\n")
31
30
  end
32
31
 
33
32
  it "receives mail" do
34
33
  common_expectations!
35
- @mock.should_receive(:send_data).with("250 OK\r\n").exactly(2).times
36
- @mock.should_receive(:send_data).with("221 Bye\r\n")
37
- @mock.should_receive(:mail_received).with({
34
+ conn.should_receive(:send_data).with("250 OK\r\n").exactly(2).times
35
+ conn.should_receive(:send_data).with("221 Bye\r\n")
36
+ conn.should_receive(:mail_received).with({
38
37
  :from => 'spec1@example.com',
39
38
  :rcpt => ['spec2@example.com', 'spec3@example.com'],
40
39
  :body => body
41
40
  }).and_return(true)
42
- @mock.should_receive(:close_connection_after_writing)
41
+ conn.should_receive(:close_connection_after_writing)
43
42
 
44
43
  begin_flow!
45
44
  end
@@ -47,38 +46,53 @@ describe Received::LMTP do
47
46
 
48
47
  it "returns error when it cannot save email" do
49
48
  common_expectations!
50
- @mock.should_receive(:mail_received).once.and_return(false)
51
- @mock.should_receive(:send_data).with(/451/).exactly(2).times
52
- @mock.should_receive(:send_data).with("221 Bye\r\n")
53
- @mock.should_receive(:close_connection_after_writing)
49
+ conn.should_receive(:mail_received).once.and_return(false)
50
+ conn.should_receive(:send_data).with(/451/).exactly(2).times
51
+ conn.should_receive(:send_data).with("221 Bye\r\n")
52
+ conn.should_receive(:close_connection_after_writing)
54
53
 
55
54
  begin_flow!
56
55
  end
57
56
  end
58
57
 
59
58
  it "parses multiline" do
60
- @mock.should_receive(:send_data).with("250-localhost\r\n")
61
- @mock.should_receive(:send_data).with("250-8BITMIME\r\n250 PIPELINING\r\n")
62
- @mock.should_receive(:send_data).with("250 OK\r\n")
63
- @proto.on_data("LHLO\r\nMAIL FROM:<spec@example.com>\r\n")
59
+ conn.should_receive(:send_data).with("250-localhost\r\n")
60
+ conn.should_receive(:send_data).with("250-8BITMIME\r\n250 PIPELINING\r\n")
61
+ conn.should_receive(:send_data).with("250 OK\r\n")
62
+ proto.on_data("LHLO\r\nMAIL FROM:<spec@example.com>\r\n")
64
63
  end
65
64
 
66
65
  it "buffers commands up to CR/LF" do
67
- @mock.should_receive(:send_data).with("250-localhost\r\n")
68
- @mock.should_receive(:send_data).with("250-8BITMIME\r\n250 PIPELINING\r\n")
69
- @mock.should_receive(:send_data).with("250 OK\r\n")
70
- @proto.on_data("LHLO\r\nMAIL FROM")
71
- @proto.on_data(":<spec@example.com>\r\n")
66
+ conn.should_receive(:send_data).with("250-localhost\r\n")
67
+ conn.should_receive(:send_data).with("250-8BITMIME\r\n250 PIPELINING\r\n")
68
+ conn.should_receive(:send_data).with("250 OK\r\n")
69
+ proto.on_data("LHLO\r\nMAIL FROM")
70
+ proto.on_data(":<spec@example.com>\r\n")
72
71
  end
73
72
 
74
73
  it "passes CR/LF through" do
75
74
  body = "Subject: test\r\n\r\nTest\r\n"
76
- @mock.stub!(:send_data)
77
- @proto.on_data("LHLO\r\nMAIL FROM:<spec1@example.com>\r\nRCPT TO:<spec2@example.com>\r\nDATA\r\n")
78
- @proto.on_data(body)
79
- @mock.should_receive(:mail_received) do |r|
75
+ conn.stub!(:send_data)
76
+ proto.on_data("LHLO\r\nMAIL FROM:<spec1@example.com>\r\nRCPT TO:<spec2@example.com>\r\nDATA\r\n")
77
+ proto.on_data(body)
78
+ conn.should_receive(:mail_received) do |r|
80
79
  r[:body].should == body
81
80
  end
82
- @proto.on_data(".\r\n")
81
+ proto.on_data(".\r\n")
82
+ end
83
+
84
+ it "allows empty FROM" do
85
+ conn.stub(:send_data)
86
+ conn.stub(:close_connection_after_writing)
87
+ conn.should_receive(:mail_received) do |mail|
88
+ puts "RECEIVED '#{mail.inspect}'"
89
+ mail[:from].should be_empty
90
+ end
91
+
92
+ ["LHLO", "MAIL FROM:<>", "RCPT TO:<spec2@example.com>",
93
+ "RCPT TO:<spec3@example.com>", "DATA", "testing\r\n.", "QUIT"].each do |line|
94
+ proto.on_data(line + "\r\n")
95
+ end
96
+
83
97
  end
84
98
  end
metadata CHANGED
@@ -1,71 +1,88 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: received
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.2
4
5
  prerelease:
5
- version: 0.3.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Roman Shterenzon
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-02-10 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-09-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: daemons
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: eventmachine
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: eventmachine
32
+ requirement: !ruby/object:Gem::Requirement
30
33
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
35
38
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: mongo
39
39
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: mongo
48
+ requirement: !ruby/object:Gem::Requirement
41
49
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
45
53
  version: 1.3.0
46
54
  type: :runtime
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: bson_ext
50
55
  prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: bson_ext
64
+ requirement: !ruby/object:Gem::Requirement
52
65
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
56
69
  version: 1.3.0
57
70
  type: :runtime
58
- version_requirements: *id004
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.3.0
59
78
  description: Currently stores received mail in MongoDB
60
- email:
79
+ email:
61
80
  - romanbsd@yahoo.com
62
- executables:
81
+ executables:
63
82
  - received
64
83
  extensions: []
65
-
66
84
  extra_rdoc_files: []
67
-
68
- files:
85
+ files:
69
86
  - .gitignore
70
87
  - .rspec
71
88
  - Gemfile
@@ -83,34 +100,31 @@ files:
83
100
  - received.gemspec
84
101
  - spec/lmtp_spec.rb
85
102
  - spec/spec_helper.rb
86
- homepage: ""
103
+ homepage: ''
87
104
  licenses: []
88
-
89
105
  post_install_message:
90
106
  rdoc_options: []
91
-
92
- require_paths:
107
+ require_paths:
93
108
  - lib
94
- required_ruby_version: !ruby/object:Gem::Requirement
109
+ required_ruby_version: !ruby/object:Gem::Requirement
95
110
  none: false
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- version: "0"
100
- required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
116
  none: false
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: "0"
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
106
121
  requirements: []
107
-
108
122
  rubyforge_project:
109
- rubygems_version: 1.8.15
123
+ rubygems_version: 1.8.24
110
124
  signing_key:
111
125
  specification_version: 3
112
126
  summary: Receive mail from Postfix and store it somewhere
113
- test_files:
127
+ test_files:
114
128
  - spec/lmtp_spec.rb
115
129
  - spec/spec_helper.rb
116
130
  has_rdoc: