Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/gravity_mailbox/rails_cache_delivery_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def initialize(settings)
end

def deliver!(mail)
# https://github.com/mikel/mail/blob/d1d65b370b109b98e673a934e8b70a0c1f58cc59/lib/mail/network/delivery_methods/test_mailer.rb#L39
# Create the envelope to validate it
Mail::SmtpEnvelope.new(mail)

key = "#{KEY_PREFIX}#{mail.message_id}"
Rails.cache.write(key, mail.encoded, expires_in: 1.week) # TODO: setting for expiration
actual_list = self.class.mail_keys
Expand Down
44 changes: 44 additions & 0 deletions spec/gravity_mailbox/rails_cache_delivery_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
let(:mail) do
Mail.new.tap do |m|
m.message_id = '123'
m.from = 'sender@example.com'
m.to = 'recipient@example.com'
end
end

Expand All @@ -26,6 +28,48 @@
["gravity_mailbox/#{mail.message_id}"]
)
end

describe 'envelope validation' do
context 'when mail has no sender' do
let(:mail) do
Mail.new.tap do |m|
m.message_id = '123'
m.to = 'recipient@example.com'
end
end

it 'raises an error' do
expect { delivering }.to raise_error(ArgumentError, /SMTP From address may not be blank/)
end
end

context 'when mail has no recipients' do
let(:mail) do
Mail.new.tap do |m|
m.message_id = '123'
m.from = 'sender@example.com'
end
end

it 'raises an error' do
expect { delivering }.to raise_error(ArgumentError, /SMTP To address may not be blank/)
end
end

context 'when mail has invalid from address' do
let(:mail) do
Mail.new.tap do |m|
m.message_id = '123'
m.from = ''
m.to = 'recipient@example.com'
end
end

it 'raises an error' do
expect { delivering }.to raise_error(ArgumentError, /SMTP From address may not be blank/)
end
end
end
end

describe '#mails' do
Expand Down