received 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,10 +22,12 @@ Installation
22
22
  Modify your [Postfix][4] configuration to deliver mail via LMTP to TCP or UNIX socket.
23
23
 
24
24
  Example main.cf:
25
+
25
26
  virtual_transport = lmtp:192.168.2.106:1111
26
27
  virtual_mailbox_domains = example.com
27
28
 
28
29
  Create a YAML configuration file which has the following parameters:
30
+
29
31
  {'production'=>{'host'=>hostname, 'database'=>db, 'collection'=>col}}
30
32
 
31
33
  The mongoid.yml will do, just add the name of collection, i.e.
@@ -60,4 +62,4 @@ Bugs and missing features
60
62
  [4]: http://www.postfix.org/
61
63
  [5]: http://tools.ietf.org/html/rfc2034
62
64
 
63
- Copyright (c) 2011 Roman Shterenzon, released under the MIT license
65
+ Copyright (c) 2011 Roman Shterenzon, released under the MIT license
@@ -4,10 +4,13 @@ module Received
4
4
  # Stores the data
5
5
  #
6
6
  # @abstract
7
- # @param [String] data
8
- def store(data)
7
+ # @param [Hash] mail
8
+ # @option mail [String] :from
9
+ # @option mail [Array] :rcpt
10
+ # @option mail [String] :body
11
+ def store(mail)
9
12
  raise NotImplementedError
10
13
  end
11
14
  end
12
15
  end
13
- end
16
+ end
@@ -33,9 +33,7 @@ module Received
33
33
  # Callback, called by protocol handler
34
34
  #
35
35
  # @param [Hash] mail
36
- # @option mail [String] :from
37
- # @option mail [Array] :rcpt
38
- # @option mail [String] :body
36
+ # @see Received::Backend::Base#store
39
37
  def mail_received(mail)
40
38
  begin
41
39
  @backend.store(mail)
data/lib/received/lmtp.rb CHANGED
@@ -4,30 +4,35 @@ module Received
4
4
 
5
5
  def initialize(conn)
6
6
  @conn = conn
7
+ @state = :start
8
+ @buf = ''
7
9
  end
8
10
 
9
11
  def on_data(data)
10
12
  @buf += data
11
- while line = @buf.slice!(/.+\r\n/)
13
+ while line = @buf.slice!(/.*\r\n/)
12
14
  line.chomp! unless @state == :data
13
15
  event(line)
14
16
  end
15
17
  end
16
18
 
17
19
  def start!
18
- @state = :start
20
+ event(nil)
21
+ end
22
+
23
+ private
24
+ def reset!
19
25
  @buf = ''
20
26
  @from = nil
21
27
  @rcpt = []
22
- event(nil)
28
+ @body = []
23
29
  end
24
30
 
25
- private
26
31
  def event(ev)
27
32
  @conn.logger.debug {"state was: #{@state.inspect}"}
28
33
  @state = case @state
29
34
  when :start
30
- @body = []
35
+ reset!
31
36
  banner
32
37
  :banner_sent
33
38
  when :banner_sent
@@ -39,7 +44,7 @@ module Received
39
44
  error
40
45
  end
41
46
  when :lhlo_received
42
- if ev =~ /MAIL FROM:<?([^>]+)/
47
+ if ev =~ /^MAIL FROM:<?([^>]+)/
43
48
  @from = $1
44
49
  ok
45
50
  :mail_from_received
@@ -47,7 +52,7 @@ module Received
47
52
  error
48
53
  end
49
54
  when :mail_from_received
50
- if ev =~ /RCPT TO:<?([^>]+)/
55
+ if ev =~ /^RCPT TO:<?([^>]+)/
51
56
  @rcpt << $1
52
57
  ok
53
58
  :rcpt_to_received
@@ -55,7 +60,7 @@ module Received
55
60
  error
56
61
  end
57
62
  when :rcpt_to_received
58
- if ev =~ /RCPT TO:<?([^>]+)/
63
+ if ev =~ /^RCPT TO:<?([^>]+)/
59
64
  @rcpt << $1
60
65
  ok
61
66
  elsif ev == "DATA"
@@ -107,7 +112,7 @@ module Received
107
112
  # FIXME: RFC2033 requires ENHANCEDSTATUSCODES,
108
113
  # but it's not used in Postfix
109
114
  def extensions
110
- emit "250-8BITMIME\r\n250 PIPELINING"
115
+ emit "250-8BITMIME\r\n250 PIPELINING"
111
116
  end
112
117
 
113
118
  def ok
@@ -1,3 +1,3 @@
1
1
  module Received
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/received.gemspec CHANGED
@@ -16,7 +16,6 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
- s.add_runtime_dependency 'activesupport'
20
19
  s.add_runtime_dependency 'daemons'
21
20
  s.add_runtime_dependency 'eventmachine'
22
21
  s.add_runtime_dependency 'mongo', '~>1.3.0'
data/spec/lmtp_spec.rb CHANGED
@@ -48,4 +48,15 @@ describe Received::LMTP do
48
48
  @proto.on_data("LHLO\r\nMAIL FROM")
49
49
  @proto.on_data(":<spec@example.com>\r\n")
50
50
  end
51
+
52
+ it "passes CR/LF through" do
53
+ body = "Subject: test\r\n\r\nTest\r\n"
54
+ @mock.stub!(:send_data)
55
+ @proto.on_data("LHLO\r\nMAIL FROM:<spec1@example.com>\r\nRCPT TO:<spec2@example.com>\r\nDATA\r\n")
56
+ @proto.on_data(body)
57
+ @mock.should_receive(:mail_received) do |r|
58
+ r[:body].should == body
59
+ end
60
+ @proto.on_data(".\r\n")
61
+ end
51
62
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Roman Shterenzon
@@ -14,11 +14,11 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-05-01 00:00:00 +03:00
17
+ date: 2011-06-02 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: activesupport
21
+ name: daemons
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
@@ -31,7 +31,7 @@ dependencies:
31
31
  type: :runtime
32
32
  version_requirements: *id001
33
33
  - !ruby/object:Gem::Dependency
34
- name: daemons
34
+ name: eventmachine
35
35
  prerelease: false
36
36
  requirement: &id002 !ruby/object:Gem::Requirement
37
37
  none: false
@@ -43,23 +43,10 @@ dependencies:
43
43
  version: "0"
44
44
  type: :runtime
45
45
  version_requirements: *id002
46
- - !ruby/object:Gem::Dependency
47
- name: eventmachine
48
- prerelease: false
49
- requirement: &id003 !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
- version: "0"
57
- type: :runtime
58
- version_requirements: *id003
59
46
  - !ruby/object:Gem::Dependency
60
47
  name: mongo
61
48
  prerelease: false
62
- requirement: &id004 !ruby/object:Gem::Requirement
49
+ requirement: &id003 !ruby/object:Gem::Requirement
63
50
  none: false
64
51
  requirements:
65
52
  - - ~>
@@ -70,11 +57,11 @@ dependencies:
70
57
  - 0
71
58
  version: 1.3.0
72
59
  type: :runtime
73
- version_requirements: *id004
60
+ version_requirements: *id003
74
61
  - !ruby/object:Gem::Dependency
75
62
  name: bson_ext
76
63
  prerelease: false
77
- requirement: &id005 !ruby/object:Gem::Requirement
64
+ requirement: &id004 !ruby/object:Gem::Requirement
78
65
  none: false
79
66
  requirements:
80
67
  - - ~>
@@ -85,7 +72,7 @@ dependencies:
85
72
  - 0
86
73
  version: 1.3.0
87
74
  type: :runtime
88
- version_requirements: *id005
75
+ version_requirements: *id004
89
76
  description: Currently stores received mail in MongoDB
90
77
  email:
91
78
  - romanbsd@yahoo.com