nuntius 1.3.20 → 1.3.21

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: 4c35384ba46c7a00cccf82ae49b6ecf09e5e6c2439196ba5cd03d6d508a4ff1d
4
- data.tar.gz: bf0e4bde69a856f82f37c205d15f3685d4da3eb612cd2eaf582642bdd388574a
3
+ metadata.gz: d75772fb2b03f8972790cc21ccc4bbffdc514e92e5020c2cfd3c1015a61550da
4
+ data.tar.gz: ee6a3397760d7f18ce525d40493894d0395b24861c3a6ca12f81f7c07cbb62ed
5
5
  SHA512:
6
- metadata.gz: ddc8ce1306965ac2306ca8ab1d7e258478868d669b34b9eb997cb6dee6f747f0e06ac5149b51afb02dcdc3bb3f50eecefe0f3dfe035e771089ade69241537098
7
- data.tar.gz: f64fc4ad0d78a90f8c1cac8fb99106322af707387d10d0b51af82d1879a0ef77a3fb4f7c46414c4a9551f77cb473e1cb3e04d8f8b3d26ecf1342b2ad019f0e70
6
+ metadata.gz: c17b0f252f59e5ed8da3d37db297b78f197b23cd5e349e168c2bab960b0e7bbc5563a9d2330e7802cba2945ce855e30f9cfead383f6c56541954f225b9ce7acb
7
+ data.tar.gz: 5335902adaf5342c364c2e1219877c8855bdf5c00ebc83eaf41a282dd7b884cb94736029af0022fb8888619d4fba683546c47e7e33b80a0cd69a86e0e7c6ecd0
@@ -9,14 +9,16 @@ module Nuntius
9
9
 
10
10
  define_callbacks :action, terminator: ->(_target, result_lambda) { result_lambda.call == false }
11
11
 
12
- attr_reader :attachments, :event, :object, :params
13
- attr_accessor :templates
12
+ attr_reader :attachments, :headers, :event, :object, :params
13
+ attr_accessor :templates, :smtp_envelope_from
14
14
 
15
15
  def initialize(object, event, params = {})
16
16
  @object = object
17
17
  @event = event
18
18
  @params = params
19
19
  @attachments = params.fetch(:attachments, [])
20
+ @headers = params.fetch(:headers, {})
21
+ @smtp_envelope_from = params[:smtp_envelope_from]
20
22
  end
21
23
 
22
24
  # Calls the event method on the messenger
@@ -35,6 +37,7 @@ module Nuntius
35
37
  @attachments.each do |attachment|
36
38
  msg.add_attachment(attachment)
37
39
  end
40
+ apply_mail_overrides(msg)
38
41
 
39
42
  transport = Nuntius::BaseTransport.class_from_name(template.transport).new
40
43
  transport.deliver(msg) if msg.to.present?
@@ -50,6 +53,12 @@ module Nuntius
50
53
  @attachments << attachment
51
54
  end
52
55
 
56
+ # Sets an extra header on the resulting message (currently applied by the
57
+ # mail transport). Useful for things like "Auto-Submitted" or "Precedence".
58
+ def header(key, value)
59
+ @headers[key.to_s] = value
60
+ end
61
+
53
62
  class << self
54
63
  #
55
64
  # Returns the variable name used in the liquid context
@@ -168,6 +177,19 @@ module Nuntius
168
177
 
169
178
  private
170
179
 
180
+ # Persists any messenger-provided mail overrides (extra headers and/or a
181
+ # custom SMTP envelope sender) onto the message so they survive the
182
+ # transport delivery job and can be applied by the provider.
183
+ def apply_mail_overrides(message)
184
+ return if @headers.blank? && @smtp_envelope_from.nil?
185
+
186
+ mail = {}
187
+ mail["headers"] = @headers if @headers.present?
188
+ mail["envelope_from"] = @smtp_envelope_from unless @smtp_envelope_from.nil?
189
+
190
+ message.metadata = (message.metadata || {}).merge("mail" => mail)
191
+ end
192
+
171
193
  # Returns the relevant templates for the object / event combination
172
194
  def select_templates
173
195
  return @templates if @templates
@@ -184,7 +206,7 @@ module Nuntius
184
206
 
185
207
  def liquid_context
186
208
  assigns = @params || {}
187
- instance_variables.reject { |i| %w[@params @object @locale @templates @template_scope].include? i.to_s }.each do |i|
209
+ instance_variables.reject { |i| %w[@params @object @locale @templates @template_scope @headers @smtp_envelope_from].include? i.to_s }.each do |i|
188
210
  assigns[i.to_s[1..]] = instance_variable_get(i)
189
211
  end
190
212
 
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mail"
4
+
5
+ module Nuntius
6
+ # A Mail::SMTP delivery method that sends with a null reverse-path
7
+ # (+MAIL FROM:<>+).
8
+ #
9
+ # The stock Mail::SmtpEnvelope refuses to emit an empty reverse-path
10
+ # (it raises on a blank From), and Net::SMTP wraps the address in angle
11
+ # brackets, so setting +smtp_envelope_from+ to +"<>"+ would produce the
12
+ # invalid +MAIL FROM:<<>>+. This delivery method bypasses Mail::SmtpEnvelope
13
+ # and hands an empty reverse-path straight to Net::SMTP, yielding the
14
+ # RFC 5321 null sender used by auto-generated/bounce notifications.
15
+ class NullSenderSmtp < ::Mail::SMTP
16
+ def deliver!(mail)
17
+ response = start_smtp_session do |smtp|
18
+ smtp.sendmail(mail.encoded, "", mail.smtp_envelope_to)
19
+ end
20
+
21
+ settings[:return_response] ? response : self
22
+ end
23
+ end
24
+ end
@@ -6,6 +6,9 @@ module Nuntius
6
6
  class SmtpMailProvider < BaseProvider
7
7
  transport :mail
8
8
 
9
+ # RFC 5321 null reverse-path, used for auto-generated/bounce notifications.
10
+ NULL_REVERSE_PATH = "<>"
11
+
9
12
  setting_reader :from_header, required: true, description: "From header (example: Nuntius Messenger <nuntius@entdec.com>)"
10
13
  setting_reader :host, required: true, description: "Host (example: smtp.soverin.net)"
11
14
  setting_reader :port, required: true, description: "Port (example: 578)"
@@ -24,16 +27,14 @@ module Nuntius
24
27
  Mail.new(from: from_header)
25
28
  end
26
29
 
30
+ null_sender = apply_mail_overrides(mail)
31
+
27
32
  if Rails.env.test?
28
33
  mail.delivery_method :test
34
+ elsif null_sender
35
+ mail.delivery_method Nuntius::NullSenderSmtp, smtp_settings
29
36
  else
30
- mail.delivery_method :smtp,
31
- address: host,
32
- port: port,
33
- user_name: username,
34
- password: password,
35
- return_response: true,
36
- ssl: ssl
37
+ mail.delivery_method :smtp, smtp_settings
37
38
  end
38
39
 
39
40
  mail.to = message.to
@@ -83,6 +84,45 @@ module Nuntius
83
84
 
84
85
  private
85
86
 
87
+ def smtp_settings
88
+ {
89
+ address: host,
90
+ port: port,
91
+ user_name: username,
92
+ password: password,
93
+ return_response: true,
94
+ ssl: ssl
95
+ }
96
+ end
97
+
98
+ # Applies any messenger-provided overrides stored on the message: extra
99
+ # headers and/or a custom SMTP envelope sender. Returns true when a null
100
+ # reverse-path (+MAIL FROM:<>+) was requested, so the caller can pick the
101
+ # delivery method that can actually emit it.
102
+ def apply_mail_overrides(mail)
103
+ overrides = message.metadata&.dig("mail")
104
+ return false if overrides.blank?
105
+
106
+ (overrides["headers"] || {}).each do |key, value|
107
+ mail.header[key] = value
108
+ end
109
+
110
+ return false unless overrides.key?("envelope_from")
111
+
112
+ envelope_from = overrides["envelope_from"]
113
+ if null_reverse_path?(envelope_from)
114
+ mail.smtp_envelope_from = NULL_REVERSE_PATH
115
+ true
116
+ else
117
+ mail.smtp_envelope_from = envelope_from
118
+ false
119
+ end
120
+ end
121
+
122
+ def null_reverse_path?(value)
123
+ value.blank? || value == NULL_REVERSE_PATH
124
+ end
125
+
86
126
  def message_url(message)
87
127
  Nuntius::Engine.routes.url_helpers.message_url(message.id, host: Nuntius.config.host(message))
88
128
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nuntius
4
- VERSION = "1.3.20"
4
+ VERSION = "1.3.21"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nuntius
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.20
4
+ version: 1.3.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Grunt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-28 00:00:00.000000000 Z
11
+ date: 2026-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apnotic
@@ -497,6 +497,7 @@ files:
497
497
  - app/providers/nuntius/firebase_push_provider.rb
498
498
  - app/providers/nuntius/houston_push_provider.rb
499
499
  - app/providers/nuntius/message_bird_sms_provider.rb
500
+ - app/providers/nuntius/null_sender_smtp.rb
500
501
  - app/providers/nuntius/slack_slack_provider.rb
501
502
  - app/providers/nuntius/smstools_sms_provider.rb
502
503
  - app/providers/nuntius/smtp_mail_provider.rb