mirror of
https://github.com/moparisthebest/mailcatcher
synced 2024-12-22 07:18:53 -05:00
Use plain old JSON
This commit is contained in:
parent
e2d89b65db
commit
d932eff261
@ -1,5 +1,5 @@
|
||||
require "active_support/json"
|
||||
require "eventmachine"
|
||||
require "json"
|
||||
require "mail"
|
||||
require "sqlite3"
|
||||
|
||||
@ -41,7 +41,7 @@ module MailCatcher::Mail extend self
|
||||
@add_message_query ||= db.prepare("INSERT INTO message (sender, recipients, subject, source, type, size, created_at) VALUES (?, ?, ?, ?, ?, ?, datetime('now'))")
|
||||
|
||||
mail = Mail.new(message[:source])
|
||||
@add_message_query.execute(message[:sender], message[:recipients].to_json, mail.subject, message[:source], mail.mime_type || "text/plain", message[:source].length)
|
||||
@add_message_query.execute(message[:sender], JSON.generate(message[:recipients]), mail.subject, message[:source], mail.mime_type || "text/plain", message[:source].length)
|
||||
message_id = db.last_insert_row_id
|
||||
parts = mail.all_parts
|
||||
parts = [mail] if parts.empty?
|
||||
@ -72,7 +72,7 @@ module MailCatcher::Mail extend self
|
||||
@messages_query ||= db.prepare "SELECT id, sender, recipients, subject, size, created_at FROM message ORDER BY created_at, id ASC"
|
||||
@messages_query.execute.map do |row|
|
||||
Hash[row.fields.zip(row)].tap do |message|
|
||||
message["recipients"] &&= ActiveSupport::JSON.decode message["recipients"]
|
||||
message["recipients"] &&= JSON.parse(message["recipients"])
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -81,7 +81,7 @@ module MailCatcher::Mail extend self
|
||||
@message_query ||= db.prepare "SELECT * FROM message WHERE id = ? LIMIT 1"
|
||||
row = @message_query.execute(id).next
|
||||
row && Hash[row.fields.zip(row)].tap do |message|
|
||||
message["recipients"] &&= ActiveSupport::JSON.decode message["recipients"]
|
||||
message["recipients"] &&= JSON.parse(message["recipients"])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -64,14 +64,14 @@ module MailCatcher
|
||||
if request.websocket?
|
||||
request.websocket!(
|
||||
:on_start => proc do |websocket|
|
||||
subscription = Events::MessageAdded.subscribe { |message| websocket.send_message message.to_json }
|
||||
subscription = Events::MessageAdded.subscribe { |message| websocket.send_message(JSON.generate(message)) }
|
||||
websocket.on_close do |websocket|
|
||||
Events::MessageAdded.unsubscribe subscription
|
||||
end
|
||||
end)
|
||||
else
|
||||
content_type :json
|
||||
Mail.messages.to_json
|
||||
JSON.generate(Mail.messages)
|
||||
end
|
||||
end
|
||||
|
||||
@ -84,7 +84,7 @@ module MailCatcher
|
||||
id = params[:id].to_i
|
||||
if message = Mail.message(id)
|
||||
content_type :json
|
||||
message.merge({
|
||||
JSON.generate(message.merge({
|
||||
"formats" => [
|
||||
"source",
|
||||
("html" if Mail.message_has_html? id),
|
||||
@ -93,7 +93,7 @@ module MailCatcher
|
||||
"attachments" => Mail.message_attachments(id).map do |attachment|
|
||||
attachment.merge({"href" => "/messages/#{escape(id)}/parts/#{escape(attachment["cid"])}"})
|
||||
end,
|
||||
}).to_json
|
||||
}))
|
||||
else
|
||||
not_found
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user