rails_mailersend 0.4.0 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b230567dfd55a4b5874d501dd4c25ff67cea0fc2cb80972001c97f37e81bde1
4
- data.tar.gz: c1cd9f9a8031b4457299aa5c5d38bb3e693efdbf2fed4284aa629f8f2df27a24
3
+ metadata.gz: 5b4c703aa4d7b7e591afbbd9057724fb3e095793b8f397440530574674c5aa27
4
+ data.tar.gz: ce5a58c4991426b929aa3803f4df5544cb7df3f32bf378521107008bb452bfe0
5
5
  SHA512:
6
- metadata.gz: e840f9652bfc94d57480738c8642b50be72af6dafc689f5e79c0ed41c1866b57ddc569c6d9de53d0bb3f854303ce7bb4c6b4f767886c8dc740f8bf615334e15f
7
- data.tar.gz: 0375b493a5bec2b0782c224d7fe74951426fc132a08888d78464d5f7beda3345d43e21a8109420803a88a1bf4ed0a458c80f5d269406e95fa2cc5f91539eb098
6
+ metadata.gz: 20eb45ed0f10c76612bc6ef36bf08bb7f2b9e593c91a2a9fc314c0c10846dc936386195e110449963ed7074c1e161195f2ac71ef1ba533afc67fe4fda9582008
7
+ data.tar.gz: 2cd89e459177774bafec016712206a9e22d3512b827be5c1cd8164900a1d2cdcc43860330565632793dbedfb9befd3c5555f3445f2efceed86e8d297d66cdc5c
data/README.md CHANGED
@@ -65,6 +65,21 @@ than returning quietly, so the enqueuing job retries and the failure is visible.
65
65
  For an app where sign-in is by magic link, a swallowed delivery error looks
66
66
  exactly like a broken app to the person waiting.
67
67
 
68
+ `In-Reply-To` and `References` are carried across to MailerSend's own
69
+ `in_reply_to` and `references` fields, so a reply lands under the message it
70
+ answers instead of opening a conversation of its own:
71
+
72
+ ```ruby
73
+ mail(to: person.email_address, subject: "Re: #{parent_subject}",
74
+ in_reply_to: parent_message_id, references: [parent_message_id])
75
+ ```
76
+
77
+ Angle brackets are put back on, since the `mail` gem strips them and MailerSend
78
+ validates against the RFC 5322 form. Every other header is dropped: the API takes
79
+ fields rather than a MIME message, and these are the two worth translating. Both
80
+ are paid-plan only at MailerSend, which answers a free account carrying them with
81
+ a 422 — loudly, rather than with an unthreaded reply nobody can account for.
82
+
68
83
  ## Inbound mail
69
84
 
70
85
  Optional, and only loads when the app has Action Mailbox. MailerSend posts the
@@ -55,10 +55,41 @@ module MailersendRails
55
55
  "reply_to" => Array(mail.reply_to).empty? ? {} : address_in(mail[:reply_to]),
56
56
  "subject" => mail.subject,
57
57
  "text" => mail.text_part&.body&.decoded,
58
- "html" => html_for(mail)
58
+ "html" => html_for(mail),
59
+ "in_reply_to" => message_ids_in(mail[:in_reply_to]).first,
60
+ "references" => message_ids_in(mail[:references])
59
61
  }.reject { |_, value| omit?(value) }
60
62
  end
61
63
 
64
+ # In-Reply-To and References, in the form MailerSend asks for them.
65
+ #
66
+ # Threading is what puts a reply under the message it answers rather than
67
+ # in a conversation of its own, and these two headers are the whole of it.
68
+ # They need carrying by hand because the API takes fields rather than a
69
+ # MIME message: every header Action Mailer set that isn't named in
70
+ # #payload_for is dropped here, and a mailer that sets In-Reply-To and
71
+ # then watches its reply arrive as a new thread has nowhere to look for
72
+ # where it went. Both fields are paid-plan only at MailerSend, which
73
+ # answers a request carrying them on a free account with a 422 -- loudly,
74
+ # like every other delivery failure.
75
+ #
76
+ # The `mail` gem hands ids back with the angle brackets stripped and
77
+ # MailerSend validates against the RFC 5322 form, so they go back on. A
78
+ # field too malformed to parse falls back to splitting on whitespace,
79
+ # which is the shape of both headers.
80
+ def message_ids_in(field)
81
+ return [] if field.nil?
82
+
83
+ ids = field.respond_to?(:message_ids) ? field.message_ids : field.to_s.split
84
+ Array(ids).filter_map { |id| bracketed(id) }
85
+ end
86
+
87
+ def bracketed(id)
88
+ id = id.to_s.strip.delete_prefix("<").delete_suffix(">").strip
89
+
90
+ "<#{id}>" unless id.empty?
91
+ end
92
+
62
93
  def html_for(mail)
63
94
  mail.html_part&.body&.decoded || mail.body.decoded
64
95
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MailersendRails
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_mailersend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Loman
@@ -58,12 +58,12 @@ files:
58
58
  - lib/mailersend_rails/railtie.rb
59
59
  - lib/mailersend_rails/version.rb
60
60
  - lib/rails_mailersend.rb
61
- homepage: https://github.com/namolnad/mailersend-rails
61
+ homepage: https://github.com/namolnad/rails_mailersend
62
62
  licenses:
63
63
  - MIT
64
64
  metadata:
65
- homepage_uri: https://github.com/namolnad/mailersend-rails
66
- source_code_uri: https://github.com/namolnad/mailersend-rails
65
+ homepage_uri: https://github.com/namolnad/rails_mailersend
66
+ source_code_uri: https://github.com/namolnad/rails_mailersend
67
67
  rdoc_options: []
68
68
  require_paths:
69
69
  - lib