Harden mail receival

This commit is contained in:
Samuel Cochran 2010-10-26 12:16:04 +08:00
parent 90d781bec2
commit a93f750c40
1 changed files with 25 additions and 14 deletions

View File

@ -87,21 +87,32 @@ module MailCatcher
end end
def receive_message def receive_message
mail = Mail.new(current_message.source) MailCatcher.db.transaction do
result = insert_message.execute(current_message.sender, current_message.recipients.inspect, mail.subject, current_message.source, current_message.source.length) mail = Mail.new(current_message.source)
mail_id = MailCatcher.db.last_insert_row_id result = insert_message.execute(current_message.sender, current_message.recipients.inspect, mail.subject, current_message.source, current_message.source.length)
if mail.multipart? mail_id = MailCatcher.db.last_insert_row_id
mail.all_parts.each do |part| if mail.multipart?
body = part.body.to_s mail.all_parts.each do |part|
insert_part.execute(mail_id, part.cid, part.mime_type, part.attachment? ? 1 : 0, part.filename, body, body.length) body = part.body.to_s
insert_part.execute(mail_id, part.cid, part.mime_type, part.attachment? ? 1 : 0, part.filename, body, body.length)
end
else
body = mail.body.to_s
insert_part.execute(mail_id, nil, mail.mime_type, 0, mail.filename, body, body.length)
end end
else puts "==> SMTP: Received message '#{mail.subject}' from '#{current_message.sender}'"
body = mail.body.to_s true
insert_part.execute(mail_id, nil, mail.mime_type, 0, mail.filename, body, body.length)
end end
puts "==> SMTP: Received message '#{mail.subject}' from '#{current_message.sender}'" rescue
puts "*** Error receiving message: #{current_message.inspect}"
puts " Exception: #{$!}"
puts " Backtrace:"
$!.backtrace.each do |line|
puts " #{line}"
end
puts " Please submit this as an issue at http://github.com/sj26/mailcatcher/issues"
ensure
@current_message = nil @current_message = nil
true
end end
end end
@ -209,8 +220,8 @@ module MailCatcher
puts "==> http://#{options[:http_ip]}:#{options[:http_port]}" puts "==> http://#{options[:http_ip]}:#{options[:http_port]}"
Thin::Logging.silent = true Thin::Logging.silent = true
EM::run do EM.run do
EM::start_server options[:smtp_ip], options[:smtp_port], SmtpServer EM.start_server options[:smtp_ip], options[:smtp_port], SmtpServer
Thin::Server.start WebApp, options[:http_ip], options[:http_port] Thin::Server.start WebApp, options[:http_ip], options[:http_port]
end end
end end