lib/sendgrid_actionmailer.rb in sendgrid-actionmailer-0.1.1 vs lib/sendgrid_actionmailer.rb in sendgrid-actionmailer-0.2.0
- old
+ new
@@ -24,13 +24,27 @@
m.to = mail[:to].addresses
m.cc = mail[:cc].addresses if mail[:cc]
m.bcc = mail[:bcc].addresses if mail[:bcc]
m.from = from.address
m.from_name = from.display_name
+ m.reply_to = mail[:reply_to].addresses.first if mail[:reply_to]
+ m.date = mail[:date].to_s if mail[:date]
m.subject = mail.subject
end
smtpapi = mail['X-SMTPAPI']
+
+ # If multiple X-SMTPAPI headers are present on the message, then pick the
+ # first one. This may happen when X-SMTPAPI is set with defaults at the
+ # class-level (using defaults()), as well as inside an individual method
+ # (using headers[]=). In this case, we'll defer to the more specific
+ # header set in the individual method, which is the first header
+ # (somewhat counter-intuitively:
+ # https://github.com/rails/rails/issues/15912).
+ if(smtpapi.kind_of?(Array))
+ smtpapi = smtpapi.first
+ end
+
if smtpapi && smtpapi.value
begin
data = JSON.parse(smtpapi.value)
if data['filters']