Merge branch 'new_messagebus_api'
This commit is contained in:
commit
e7b9dd8b8a
4 changed files with 28 additions and 56 deletions
2
Gemfile
2
Gemfile
|
|
@ -26,7 +26,7 @@ gem 'twitter', '2.0.2'
|
|||
gem 'cloudfiles', '1.4.10', :require => false
|
||||
|
||||
# mail
|
||||
gem 'messagebus_ruby_api', '0.4.8'
|
||||
gem 'messagebus_ruby_api', '1.0.1'
|
||||
|
||||
|
||||
# web sockets
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ GEM
|
|||
i18n (>= 0.4.0)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
messagebus_ruby_api (0.4.8)
|
||||
messagebus_ruby_api (1.0.1)
|
||||
mime-types (1.17.2)
|
||||
mini_magick (3.3)
|
||||
subexec (~> 0.1.0)
|
||||
|
|
@ -479,7 +479,7 @@ DEPENDENCIES
|
|||
json (= 1.5.2)
|
||||
jwt (= 0.1.3)
|
||||
linecache (= 0.46)
|
||||
messagebus_ruby_api (= 0.4.8)
|
||||
messagebus_ruby_api (= 1.0.1)
|
||||
mini_magick (= 3.3)
|
||||
mobile-fu
|
||||
mock_redis
|
||||
|
|
|
|||
|
|
@ -1,16 +1,19 @@
|
|||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require File.join(Rails.root, 'lib/messagebus/mailer')
|
||||
|
||||
Diaspora::Application.configure do
|
||||
config.action_mailer.default_url_options = {:protocol => AppConfig[:pod_uri].scheme,
|
||||
:host => AppConfig[:pod_uri].authority }
|
||||
|
||||
unless Rails.env == 'test' || AppConfig[:mailer_on] != true
|
||||
if AppConfig[:mailer_method] == 'messagebus'
|
||||
if AppConfig[:messagebus_api_key].present?
|
||||
config.action_mailer.delivery_method = Messagebus::Mailer.new(AppConfig[:messagebus_api_key])
|
||||
|
||||
if AppConfig[:message_bus_api_key].present?
|
||||
|
||||
config.action_mailer.delivery_method = Messagebus::Mailer.new(AppConfig[:message_bus_api_key])
|
||||
config.action_mailer.raise_delivery_errors = true
|
||||
else
|
||||
puts "You need to set your messagebus api key if you are going to use the message bus service. no mailer is now configured"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
module Messagebus
|
||||
class Mailer
|
||||
unless defined?(MessagebusRubyApi::VERSION)
|
||||
MessagebusRubyApi::VERSION = '0.4.8'
|
||||
end
|
||||
|
||||
def initialize(api_key)
|
||||
@client = MessagebusRubyApi::Client.new(api_key)
|
||||
@client = MessagebusApi::Messagebus.new(api_key)
|
||||
end
|
||||
|
||||
attr_accessor :settings
|
||||
|
|
@ -14,49 +10,22 @@ module Messagebus
|
|||
self
|
||||
end
|
||||
|
||||
def from_header_parse(string)
|
||||
string.split('<')[0].delete('"')
|
||||
end
|
||||
|
||||
def deliver!(message)
|
||||
deliver(message)
|
||||
end
|
||||
|
||||
def message_parse(string)
|
||||
string.split('<')[0]
|
||||
end
|
||||
|
||||
def from_header_parse(message)
|
||||
AppConfig[:smtp_sender_address]
|
||||
'no-reply@joindiaspora.com'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def deliver(message)
|
||||
# here we want = {:fromEmail => message['from'].to_s}
|
||||
#this is required due to weird bug in action mailer
|
||||
from_header = from_header_parse(message)
|
||||
|
||||
@client.send_common_info = {:fromEmail => from_header, :customHeaders => {"sender"=> from_header}}
|
||||
message.to.each do |addressee|
|
||||
m = {:toEmail => addressee, :fromEmail => from_header, :subject => message.subject, :fromName => message_parse(from_header)}
|
||||
@things = []
|
||||
msg = {:toEmail => message.to.first, :subject => message.subject, :fromEmail =>message.from.first, :fromName => from_header_parse(message[:from].to_s)}
|
||||
|
||||
if message.multipart?
|
||||
m[:plaintextBody] = message.text_part.body.to_s if message.text_part
|
||||
m[:htmlBody] = message.html_part.body.to_s if message.html_part
|
||||
else
|
||||
m[:plaintextBody] = message.body.to_s
|
||||
m[:htmlBody] = message.body.to_s
|
||||
msg[:plaintextBody] = message.text_part.body.to_s if message.text_part
|
||||
msg[:htmlBody] = message.html_part.body.to_s if message.html_part
|
||||
end
|
||||
|
||||
@client.add_message(m)
|
||||
@things << m
|
||||
end
|
||||
begin
|
||||
status = @client.flush
|
||||
rescue Exception => e
|
||||
raise "message bus failures: #{e.message} #{@things.map{|x| x[:fromEmail]}.inspect}, #{message['from']}"
|
||||
end
|
||||
if status[:failureCount] && status[:failureCount] > 0
|
||||
raise "Messagebus failure. failureCount=#{status[:failureCount]}, message=#{message.inspect}"
|
||||
@client.add_message(msg, true)
|
||||
rescue => message_bus_api_error
|
||||
raise "Messagebus API error=#{message_bus_api_error}, message=#{msg.inspect}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue