Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix ReplyTo and Bcc so they accept a single address (String) or multi…

…ple addresses (Array)
  • Loading branch information...
commit 37b9a82323b26a6ab0e59b847f26568029db6c1c 1 parent 6500df9
@bensie bensie authored
Showing with 19 additions and 19 deletions.
  1. +19 −19 lib/postmark.rb
View
38 lib/postmark.rb
@@ -80,7 +80,7 @@ def sleep_between_retries
def configure
yield self
end
-
+
def send_through_postmark(message) #:nodoc:
@retries = 0
begin
@@ -94,26 +94,26 @@ def send_through_postmark(message) #:nodoc:
end
end
end
-
+
def convert_message_to_options_hash(message)
options = Hash.new
headers = extract_headers_according_to_message_format(message)
-
- options["From"] = message['from'].to_s if message.from
- options["ReplyTo"] = message.reply_to.to_a.join(", ") if message.reply_to
- options["To"] = message['to'].to_s if message.to
- options["Cc"] = message['cc'].to_s if message.cc
- options["Bcc"] = message.bcc.join(", ") if message.bcc
+
+ options["From"] = message['from'].to_s if message.from
+ options["ReplyTo"] = Array[message.reply_to].flatten.join(", ") if message.reply_to
+ options["To"] = message['to'].to_s if message.to
+ options["Cc"] = message['cc'].to_s if message.cc
+ options["Bcc"] = Array[message.bcc].flatten.join(", ") if message.bcc
options["Subject"] = message.subject
options["Attachments"] = message.postmark_attachments
- options["Tag"] = message.tag.to_s if message.tag
- options["Headers"] = headers if headers.size > 0
-
+ options["Tag"] = message.tag.to_s if message.tag
+ options["Headers"] = headers if headers.size > 0
+
options = options.delete_if{|k,v| v.nil?}
-
+
html = message.body_html
text = message.body_text
-
+
if message.multipart?
options["HtmlBody"] = html
options["TextBody"] = text
@@ -122,16 +122,16 @@ def convert_message_to_options_hash(message)
else
options["TextBody"] = text
end
-
+
options
end
-
+
def delivery_stats
HttpClient.get("deliverystats")
end
-
+
protected
-
+
def extract_headers_according_to_message_format(message)
if defined?(TMail) && message.is_a?(TMail::Mail)
headers = extract_tmail_headers(message)
@@ -141,7 +141,7 @@ def extract_headers_according_to_message_format(message)
raise "Can't convert message to a valid hash of API options. Unknown message format."
end
end
-
+
def extract_mail_headers(message)
headers = []
message.header.fields.each do |field|
@@ -175,7 +175,7 @@ def bogus_headers
attachment
]
end
-
+
end
self.response_parser_class = nil
Please sign in to comment.
Something went wrong with that request. Please try again.