malm 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -22,19 +22,21 @@ class MalmSMTPServer < GServer
22
22
  puts "Connected"
23
23
  io.print "220 hello\r\n"
24
24
  loop do
25
- if IO.select([io], nil, nil, 0.1)
26
- data = io.readpartial(4096)
27
- puts ">>" + data
28
- ok, op = process_line(data, session)
29
- break unless ok
30
- puts "<<" + op
31
- io.print op
32
- end
25
+ data = io.gets
26
+ puts ">>" + data
27
+ ok, op = process_line(data, session)
28
+ puts "<<" + op
29
+ io.print op
30
+ break unless ok
33
31
  break if io.closed?
34
32
  end
35
- db_insert(session)
36
- io.print "221 bye\r\n"
37
- io.close
33
+ begin
34
+ io.close
35
+ db_insert(session)
36
+ rescue => e
37
+ log "something screwed up..."
38
+ log e.backtrace
39
+ end
38
40
  end
39
41
 
40
42
  def process_line(line, session)
@@ -47,7 +49,7 @@ class MalmSMTPServer < GServer
47
49
  elsif (line =~ /^(HELO|EHLO)/)
48
50
  return true, "250 and..?\r\n"
49
51
  elsif (line =~ /^QUIT/)
50
- return false, "bye\r\n"
52
+ return false, "221 bye\r\n"
51
53
  elsif (line =~ /^MAIL FROM\:/)
52
54
  session.mail_from = (/^MAIL FROM\:<(.+)>.*$/).match(line)[1]
53
55
  return true, "250 OK\r\n"
@@ -65,7 +67,8 @@ class MalmSMTPServer < GServer
65
67
  def db_insert(session)
66
68
  subject_regex = /^Subject\: (.+)$/
67
69
 
68
- subject = subject_regex.match(session.email_body)[1] || ""
70
+ subject_match = subject_regex.match(session.email_body)
71
+ subject = subject_match ? subject_match[1] : ""
69
72
  subject.strip!
70
73
 
71
74
  message = {:subject => subject, :from => session.mail_from, :to => session.rcpt_to, :body => session.email_body}
@@ -86,4 +89,5 @@ class MalmSMTPServer < GServer
86
89
  @mail_log_fd.close if @mail_log_fd
87
90
  super
88
91
  end
92
+
89
93
  end
data/lib/malm_web.rb CHANGED
@@ -3,12 +3,18 @@ require 'sinatra/base'
3
3
  require 'json'
4
4
 
5
5
  class MalmWeb < Sinatra::Base
6
- get("/") do
6
+ get "/" do
7
7
  "Hello World\n"
8
8
  end
9
9
 
10
- get ("/messages") do
10
+ get "/messages" do
11
11
  content_type :json
12
12
  settings.message_db.find_all.to_json
13
13
  end
14
+
15
+ get "/messages/:id" do
16
+ content_type :json
17
+ id = Integer(params[:id])
18
+ settings.message_db.find(id).to_json
19
+ end
14
20
  end
data/lib/message_db.rb CHANGED
@@ -10,6 +10,7 @@ class MessageDb
10
10
 
11
11
  def create(message)
12
12
  @sempahore.synchronize do
13
+ message[:id] = @message_db.size
13
14
  @message_db << message
14
15
  @message_db.size
15
16
  end
@@ -20,5 +21,11 @@ class MessageDb
20
21
  @message_db.dup
21
22
  end
22
23
  end
24
+
25
+ def find(id)
26
+ @sempahore.synchronize do
27
+ @message_db[id]
28
+ end
29
+ end
23
30
 
24
31
  end
data/malm.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{malm}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{madlep}]
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "lib/malm_web.rb",
30
30
  "lib/message_db.rb",
31
31
  "malm.gemspec",
32
+ "spec/bin/malm_test_message",
32
33
  "spec/help_spec.rb",
33
34
  "spec/spec_helper.rb"
34
35
  ]
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'net/smtp'
4
+
5
+ message = <<-END_OF_MESSAGE
6
+ From: francis <francis@example.com>
7
+ To: bill <bill@example.com>
8
+ Subject: zombies
9
+ Date: Thu, 14 Jul 2011 15:16:43 +1000
10
+ Message-Id: <unique.message.id.string@example.com>
11
+
12
+ You know what I don't hate? I don't hate vests.
13
+ END_OF_MESSAGE
14
+
15
+ Net::SMTP.start('localhost', 2525) do |smtp|
16
+ smtp.send_message(message,'francis@example.com','bill@example.com')
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: malm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-07-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &2155923580 !ruby/object:Gem::Requirement
16
+ requirement: &2156099220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.5.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2155923580
24
+ version_requirements: *2156099220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: clamp
27
- requirement: &2155917200 !ruby/object:Gem::Requirement
27
+ requirement: &2156093140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.2.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2155917200
35
+ version_requirements: *2156093140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sinatra
38
- requirement: &2153512200 !ruby/object:Gem::Requirement
38
+ requirement: &2156089540 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - =
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.2.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2153512200
46
+ version_requirements: *2156089540
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: thin
49
- requirement: &2153511600 !ruby/object:Gem::Requirement
49
+ requirement: &2156079880 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - =
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.2.11
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2153511600
57
+ version_requirements: *2156079880
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &2153511100 !ruby/object:Gem::Requirement
60
+ requirement: &2156074560 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 2.3.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2153511100
68
+ version_requirements: *2156074560
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
- requirement: &2153510460 !ruby/object:Gem::Requirement
71
+ requirement: &2156068940 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.0.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2153510460
79
+ version_requirements: *2156068940
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: jeweler
82
- requirement: &2153509960 !ruby/object:Gem::Requirement
82
+ requirement: &2156057980 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.6.2
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2153509960
90
+ version_requirements: *2156057980
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rcov
93
- requirement: &2153509300 !ruby/object:Gem::Requirement
93
+ requirement: &2156054800 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2153509300
101
+ version_requirements: *2156054800
102
102
  description: SMTP server with web interface for easy local development. Sets up a
103
103
  little mail server that you can send messages to, and provides a web front end to
104
104
  let you see what your app did.
@@ -121,6 +121,7 @@ files:
121
121
  - lib/malm_web.rb
122
122
  - lib/message_db.rb
123
123
  - malm.gemspec
124
+ - spec/bin/malm_test_message
124
125
  - spec/help_spec.rb
125
126
  - spec/spec_helper.rb
126
127
  homepage: http://github.com/madlep/malm
@@ -138,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
139
  version: '0'
139
140
  segments:
140
141
  - 0
141
- hash: -4176688025386378385
142
+ hash: -3447905791693919556
142
143
  required_rubygems_version: !ruby/object:Gem::Requirement
143
144
  none: false
144
145
  requirements: