lib/railgun/mailer.rb in mailgun-ruby-1.1.8 vs lib/railgun/mailer.rb in mailgun-ruby-1.1.9
- old
+ new
@@ -21,11 +21,11 @@
[:api_key, :domain].each do |k|
raise Railgun::ConfigurationError.new("Config requires `#{k}` key", @config) unless @config.has_key?(k)
end
- @mg_client = Mailgun::Client.new(config[:api_key])
+ @mg_client = Mailgun::Client.new(config[:api_key], config[:api_host] || 'api.mailgun.net', config[:api_version] || 'v3', config[:api_ssl].nil? ? true : config[:api_ssl])
@domain = @config[:domain]
# To avoid exception in mail gem v2.6
@settings = { return_response: true }
@@ -136,11 +136,11 @@
# @param [Mail::Message] mail message to transform
#
# @return [String]
def extract_body_html(mail)
begin
- (mail.html_part || mail).body.decoded || nil
+ retrieve_html_part(mail).body.decoded || nil
rescue
nil
end
end
@@ -150,12 +150,36 @@
# @param [Mail::Message] mail message to transform
#
# @return [String]
def extract_body_text(mail)
begin
- (mail.text_part || mail).body.decoded || nil
+ retrieve_text_part(mail).body.decoded || nil
rescue
nil
end
+ end
+
+ # Returns the mail object from the Mail::Message object if text part exists,
+ # (decomposing multipart into individual format if necessary)
+ # otherwise nil.
+ #
+ # @param [Mail::Message] mail message to transform
+ #
+ # @return [Mail::Message] mail message with its content-type = text/plain
+ def retrieve_text_part(mail)
+ return mail.text_part if mail.multipart?
+ (mail.mime_type =~ /^text\/plain$/i) && mail
+ end
+
+ # Returns the mail object from the Mail::Message object if html part exists,
+ # (decomposing multipart into individual format if necessary)
+ # otherwise nil.
+ #
+ # @param [Mail::Message] mail message to transform
+ #
+ # @return [Mail::Message] mail message with its content-type = text/html
+ def retrieve_html_part(mail)
+ return mail.html_part if mail.multipart?
+ (mail.mime_type =~ /^text\/html$/i) && mail
end
end