mailcrate 0.0.1
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 +88 -0
- metadata +65 -0
data/lib/mailcrate.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
class Mailcrate
|
4
|
+
|
5
|
+
attr_reader :mails
|
6
|
+
|
7
|
+
def initialize(port)
|
8
|
+
@port = port
|
9
|
+
@mails = []
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def start
|
14
|
+
@service = TCPServer.new('localhost', @port )
|
15
|
+
Thread.new { accept(@service) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def stop
|
19
|
+
@service.close unless @service.nil? || @service.closed?
|
20
|
+
end
|
21
|
+
|
22
|
+
def accept( service )
|
23
|
+
while session = service.accept
|
24
|
+
|
25
|
+
class << session
|
26
|
+
def get_line
|
27
|
+
line = gets
|
28
|
+
line.chomp! unless line.nil?
|
29
|
+
line
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
serve( session )
|
35
|
+
rescue Exception => e
|
36
|
+
puts e.message
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def serve( connection )
|
42
|
+
connection.puts( "220 localhost mailcrate ready ESTMP" )
|
43
|
+
helo = connection.get_line
|
44
|
+
|
45
|
+
if helo =~ /^EHLO\s+/
|
46
|
+
connection.puts "250-localhost mailcrate here"
|
47
|
+
connection.puts "250 HELP"
|
48
|
+
end
|
49
|
+
|
50
|
+
from = connection.get_line
|
51
|
+
connection.puts( "250 ok" )
|
52
|
+
|
53
|
+
|
54
|
+
to_list = []
|
55
|
+
|
56
|
+
loop do
|
57
|
+
to = connection.get_line
|
58
|
+
break if to.nil?
|
59
|
+
|
60
|
+
if to =~ /^DATA/
|
61
|
+
connection.puts( "354 start" )
|
62
|
+
break
|
63
|
+
else
|
64
|
+
to_list << to
|
65
|
+
connection.puts( "250 ok" )
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
lines = []
|
70
|
+
loop do
|
71
|
+
line = connection.get_line
|
72
|
+
break if line.nil? || line == "."
|
73
|
+
lines << line
|
74
|
+
end
|
75
|
+
|
76
|
+
connection.puts "250 ok"
|
77
|
+
connection.gets
|
78
|
+
connection.puts "221 bye"
|
79
|
+
connection.close
|
80
|
+
|
81
|
+
@mails << {
|
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
|
+
end
|
87
|
+
|
88
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mailcrate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Adam Scott
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-02-12 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
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.
|
22
|
+
email: adam.d.scott@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/mailcrate.rb
|
31
|
+
homepage: https://github.com/adscott/mailcrate
|
32
|
+
licenses: []
|
33
|
+
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
requirements:
|
58
|
+
- none
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.10
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: A mock SMTP server that can be run and inspected from tests.
|
64
|
+
test_files: []
|
65
|
+
|