mailcrate 0.0.1 → 0.0.2
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.
- data/lib/mailcrate.rb +25 -25
- metadata +5 -5
data/lib/mailcrate.rb
CHANGED
@@ -2,26 +2,27 @@ require 'socket'
|
|
2
2
|
|
3
3
|
class Mailcrate
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(port)
|
8
|
-
@port = port
|
9
|
-
@mails = []
|
10
|
-
end
|
5
|
+
attr_reader :mails
|
11
6
|
|
7
|
+
def initialize(port)
|
8
|
+
@port = port
|
9
|
+
@mails = []
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
def start(opts = {})
|
13
|
+
@service = opts[:service] || TCPServer.new('localhost', @port)
|
14
|
+
@thread = Thread.new { accept(@service) }
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def stop
|
18
|
+
@service.close unless @service.nil? || @service.closed?
|
19
|
+
@thread.kill
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
21
23
|
|
22
|
-
|
24
|
+
def accept(service)
|
23
25
|
while session = service.accept
|
24
|
-
|
25
26
|
class << session
|
26
27
|
def get_line
|
27
28
|
line = gets
|
@@ -31,15 +32,15 @@ class Mailcrate
|
|
31
32
|
end
|
32
33
|
|
33
34
|
begin
|
34
|
-
serve(
|
35
|
+
serve(session)
|
35
36
|
rescue Exception => e
|
36
37
|
puts e.message
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
|
-
def serve(
|
42
|
-
|
42
|
+
def serve(connection)
|
43
|
+
connection.puts("220 localhost mailcrate ready ESTMP")
|
43
44
|
helo = connection.get_line
|
44
45
|
|
45
46
|
if helo =~ /^EHLO\s+/
|
@@ -48,8 +49,7 @@ class Mailcrate
|
|
48
49
|
end
|
49
50
|
|
50
51
|
from = connection.get_line
|
51
|
-
connection.puts(
|
52
|
-
|
52
|
+
connection.puts("250 ok")
|
53
53
|
|
54
54
|
to_list = []
|
55
55
|
|
@@ -79,10 +79,10 @@ class Mailcrate
|
|
79
79
|
connection.close
|
80
80
|
|
81
81
|
@mails << {
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
:from => from.gsub(/MAIL FROM:\s*/, ''),
|
83
|
+
:to_list => to_list.map { |to| to.gsub( /RCPT TO:\s*/, "" ) },
|
84
|
+
:body => lines.join( "\n" )
|
85
|
+
}
|
86
86
|
end
|
87
87
|
|
88
|
-
end
|
88
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailcrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adam Scott
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2014-09-25 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: A mock SMTP server that can be run and inspected from tests. The server runs in memory and received messages can be retrieved.
|
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
requirements:
|
58
58
|
- none
|
59
59
|
rubyforge_project:
|
60
|
-
rubygems_version: 1.8.
|
60
|
+
rubygems_version: 1.8.21
|
61
61
|
signing_key:
|
62
62
|
specification_version: 3
|
63
63
|
summary: A mock SMTP server that can be run and inspected from tests.
|