ses_api-rails 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ses_api/rails/api.rb +28 -5
- data/lib/ses_api/rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbc9437dc0c338b9dbd896f49e490c91434146c9
|
4
|
+
data.tar.gz: c1794cfaf066969298a913830928adf5513abddd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92eb2f7e7708052aa272a85de157892be39d8e519442454fb5af2b209ed48d085fbdccdf8079493f006800f84fa9329e79f9febab6a436d34a6c1847a94a876a
|
7
|
+
data.tar.gz: bb5380c00ec717c258892c31dc0bdcdeb0c926e3b3bc57da8333f833a536964b96edfa5a6ddaf94b3ba8388150b75e1639884159c15b58942803d57c6220cf22
|
data/lib/ses_api/rails/api.rb
CHANGED
@@ -54,10 +54,9 @@ module SesApi
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def create_payload
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
from = "&Source=#{CGI::escape(mail.from[0])}"
|
57
|
+
display_names = create_display_names
|
58
|
+
destinations = build_destination_addresses(display_names)
|
59
|
+
from = "&Source=#{format_email(mail.from[0], display_names)}"
|
61
60
|
subject = "&Message.Subject.Data=#{CGI::escape(mail.subject)}"
|
62
61
|
|
63
62
|
if mail.body.raw_source.present?
|
@@ -68,7 +67,31 @@ module SesApi
|
|
68
67
|
body << "&Message.Body.Text.Data=#{CGI::escape(mail.text_part.body.raw_source)}&Message.Body.Text.Charset=UTF-8"
|
69
68
|
end
|
70
69
|
|
71
|
-
payload = "AWSAccessKeyId=#{SesApi::Rails.configuration.access_key_id}&Action=SendEmail#{
|
70
|
+
payload = "AWSAccessKeyId=#{SesApi::Rails.configuration.access_key_id}&Action=SendEmail#{destinations}#{body}#{subject}#{from}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def create_display_names
|
74
|
+
display_names = {}
|
75
|
+
mail.header.fields.each do |f|
|
76
|
+
if %w[To From Cc Bcc].include? f.name
|
77
|
+
f.address_list.addresses.each do |a|
|
78
|
+
email = "#{a.local}@#{a.domain}"
|
79
|
+
display_names.[]=(email, a.display_name) ? a.display_name.present? : a.local
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
display_names
|
84
|
+
end
|
85
|
+
|
86
|
+
def build_destination_addresses(display_names)
|
87
|
+
to = mail.to.each_with_index.map { |email, i| "&Destination.ToAddresses.member.#{i+1}=#{format_email(email, display_names)}"}.join
|
88
|
+
cc = mail.cc.each_with_index.map { |email, i| "&Destination.CcAddresses.member.#{i+1}=#{format_email(email, display_names)}"}.join if mail.cc.present?
|
89
|
+
bcc = mail.bcc.each_with_index.map { |email, i| "&Destination.BccAddresses.member.#{i+1}=#{format_email(email, display_names)}"}.join if mail.bcc.present?
|
90
|
+
return "#{to}#{cc}#{bcc}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def format_email(email, display_names)
|
94
|
+
CGI::escape("#{display_names[email]}<#{email}>")
|
72
95
|
end
|
73
96
|
|
74
97
|
def create_canonical_request(headers, hashed_payload, signed_headers)
|