Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
122 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
rvm --create use 1.9.3-p0@mailbox | ||
rvm --create use 1.8.7-p352@mailbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ source :rubygems | |
|
||
gem 'rake' | ||
gem 'rspec' | ||
gem 'ruby-debug' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,88 @@ | ||
require 'socket' | ||
|
||
class Mailbox | ||
|
||
attr_reader :mails | ||
|
||
def initialize(port) | ||
@port = port | ||
@mails = [] | ||
end | ||
|
||
|
||
def start | ||
@service = TCPServer.new('localhost', @port ) | ||
Thread.new { accept(@service) } | ||
end | ||
|
||
def stop | ||
@service.close unless @service.nil? || @service.closed? | ||
end | ||
|
||
def accept( service ) | ||
while session = service.accept | ||
|
||
class << session | ||
def get_line | ||
line = gets | ||
line.chomp! unless line.nil? | ||
line | ||
end | ||
end | ||
|
||
begin | ||
serve( session ) | ||
rescue Exception => e | ||
puts e.message | ||
end | ||
end | ||
end | ||
|
||
def serve( connection ) | ||
connection.puts( "220 localhost mailbox ready ESTMP" ) | ||
helo = connection.get_line | ||
|
||
if helo =~ /^EHLO\s+/ | ||
connection.puts "250-localhost mailbox here" | ||
connection.puts "250 HELP" | ||
end | ||
|
||
from = connection.get_line | ||
connection.puts( "250 ok" ) | ||
|
||
|
||
to_list = [] | ||
|
||
loop do | ||
to = connection.get_line | ||
break if to.nil? | ||
|
||
if to =~ /^DATA/ | ||
connection.puts( "354 start" ) | ||
break | ||
else | ||
to_list << to | ||
connection.puts( "250 ok" ) | ||
end | ||
end | ||
|
||
lines = [] | ||
loop do | ||
line = connection.get_line | ||
break if line.nil? || line == "." | ||
lines << line | ||
end | ||
|
||
connection.puts "250 ok" | ||
connection.gets | ||
connection.puts "221 bye" | ||
connection.close | ||
|
||
@mails << { | ||
:from => from.gsub(/MAIL FROM:\s*/, ''), | ||
# :to_list => to_list.map { |to| to.gsub( /RCPT TO:\s*/, "" ) } | ||
# :body => lines.join( "\n" ) | ||
} | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters