Skip to content

Commit

Permalink
Merge pull request #18 from bensie/master
Browse files Browse the repository at this point in the history
Fix ReplyTo and Bcc so they accept a single address
  • Loading branch information
temochka committed Jan 31, 2012
2 parents 6500df9 + 37b9a82 commit 8ee7be9
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions lib/postmark.rb
Expand Up @@ -80,7 +80,7 @@ def sleep_between_retries
def configure
yield self
end

def send_through_postmark(message) #:nodoc:
@retries = 0
begin
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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|
Expand Down Expand Up @@ -175,7 +175,7 @@ def bogus_headers
attachment
]
end

end

self.response_parser_class = nil
Expand Down

0 comments on commit 8ee7be9

Please sign in to comment.