Commit 516ccac3 authored by georg's avatar georg

Merge branch 'add-delivery-selfsent' into 'master'

Add deliver selfsent

See merge request schleuder/schleuder!302
parents bc6eee11 ca060c1c
Pipeline #33468 passed with stages
in 12 minutes and 44 seconds
......@@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
* New option for lists to include their public keys in the headers of outgoing emails (conforming with Autocrypt, https://autocrypt.org/). Defaults to true. (#335)
* Add visual separator (78 dashes) to the end of the 'pseudoheaders' block: This should help users of Apple Mail, which jams this block and the body together. Hopefully, this change makes it easier to dinstiguish both parts from each other. (#348)
* `deliver_selfsent` per-list option to control whether subscribers get a copy of mail they sent themselves. (#365)
### Fixed
......
class AddDeliverSelfsentToList < ActiveRecord::Migration
def up
if ! column_exists?(:lists, :deliver_selfsent)
add_column :lists, :deliver_selfsent, :boolean, default: true
end
end
def down
remove_column(:lists, :deliver_selfsent)
end
end
......@@ -37,6 +37,7 @@ ActiveRecord::Schema.define(version: 20190906194820) do
t.boolean "keep_msgid", default: true
t.boolean "bounces_drop_all", default: false
t.boolean "bounces_notify_admins", default: true
t.boolean "deliver_selfsent", default: true
t.boolean "include_list_headers", default: true
t.boolean "include_openpgp_header", default: true
t.integer "max_message_size_kb", default: 10240
......
......@@ -126,3 +126,8 @@ language: en
# Forward a raw copy of all incoming emails to the list-admins?
# Mainly useful for debugging.
forward_all_incoming_to_admins: false
# Should e-mails be delivered to the original subscribed sender?
# Disabling this only works for signed e-mails; any e-mail that is unsigned
# sent to the list is treated as coming from an unknown source
deliver_selfsent: true
......@@ -19,6 +19,7 @@ module Schleuder
:receive_admin_only,
:keep_msgid,
:bounces_drop_all,
:deliver_selfsent,
:bounces_notify_admins,
:include_list_headers,
:include_openpgp_header,
......@@ -350,16 +351,24 @@ module Schleuder
true
end
def send_to_subscriptions(mail)
def send_to_subscriptions(mail, incoming_mail=nil)
logger.debug "Sending to subscriptions."
mail.add_internal_footer!
self.subscriptions.each do |subscription|
begin
if subscription.delivery_enabled
subscription.send_mail(mail)
else
if ! subscription.delivery_enabled
logger.info "Not sending to #{subscription.email}: delivery is disabled."
next
end
if ! self.deliver_selfsent && incoming_mail.was_validly_signed? && ( subscription == incoming_mail.signer )
logger.info "Not sending to #{subscription.email}: delivery of self sent is disabled."
next
end
subscription.send_mail(mail)
rescue => exc
msg = I18n.t('errors.delivery_error',
{ email: subscription.email, error: exc.to_s })
......
......@@ -51,7 +51,7 @@ module Schleuder
# Subscriptions
logger.debug "Creating clean copy of message"
copy = @mail.clean_copy(list.headers_to_meta.any?)
list.send_to_subscriptions(copy)
list.send_to_subscriptions(copy, @mail)
nil
end
......
......@@ -22,6 +22,7 @@ FactoryBot.define do
keep_msgid { true }
bounces_drop_all { false }
bounces_notify_admins { true }
deliver_selfsent { true }
include_autocrypt_header { true }
include_list_headers { true }
include_openpgp_header { true }
......
......@@ -63,6 +63,7 @@ describe 'cli' do
expect(list.keep_msgid).to eq true
expect(list.bounces_drop_all).to eq false
expect(list.bounces_notify_admins).to eq true
expect(list.deliver_selfsent).to eq true
expect(list.include_list_headers).to eq true
expect(list.include_openpgp_header).to eq true
expect(list.openpgp_header_preference).to eq 'signencrypt'
......
......@@ -6,8 +6,8 @@ describe Schleuder::List do
:send_encrypted_only, :receive_encrypted_only, :receive_signed_only,
:receive_authenticated_only, :receive_from_subscribed_emailaddresses_only,
:receive_admin_only, :keep_msgid, :bounces_drop_all,
:bounces_notify_admins, :include_list_headers, :include_list_headers,
:include_openpgp_header, :forward_all_incoming_to_admins
:bounces_notify_admins, :deliver_selfsent, :include_list_headers,
:include_list_headers, :include_openpgp_header, :forward_all_incoming_to_admins
].freeze
it "has a valid factory" do
......@@ -39,6 +39,7 @@ describe Schleuder::List do
it { is_expected.to respond_to :keep_msgid }
it { is_expected.to respond_to :bounces_drop_all }
it { is_expected.to respond_to :bounces_notify_admins }
it { is_expected.to respond_to :deliver_selfsent }
it { is_expected.to respond_to :include_list_headers }
it { is_expected.to respond_to :include_openpgp_header }
it { is_expected.to respond_to :max_message_size_kb }
......@@ -196,7 +197,7 @@ describe Schleuder::List do
describe ".configurable_attributes" do
it "returns an array that contains the configurable attributes" do
expect(Schleuder::List.configurable_attributes).to eq [
:bounces_drop_all, :bounces_drop_on_headers, :bounces_notify_admins,
:bounces_drop_all, :bounces_drop_on_headers, :bounces_notify_admins, :deliver_selfsent,
:forward_all_incoming_to_admins, :headers_to_meta, :include_list_headers,
:include_openpgp_header, :internal_footer, :keep_msgid, :keywords_admin_notify, :keywords_admin_only,
:language, :log_level, :logfiles_to_keep, :max_message_size_kb, :openpgp_header_preference,
......@@ -755,5 +756,102 @@ describe Schleuder::List do
teardown_list_and_mailer(list)
end
it "sends the message to all subscribers including the sender, if deliver_selfsent is true and the mail is correctly signed" do
list = create(:list, send_encrypted_only: false, deliver_selfsent: true)
key_material = File.read("spec/fixtures/default_list_key.txt")
sub, msgs = list.subscribe("admin@example.org", nil, true, true, key_material)
key_material = File.read("spec/fixtures/example_key.txt")
sub, msgs = list.subscribe("user1@example.org", nil, false, true, key_material)
mail = Mail.new
mail.to = list.email
mail.from = 'user1@example.org'
mail.subject = 'Something'
mail.body = "Some content"
gpg_opts = {
sign: true,
sign_as: '59C71FB38AEE22E091C78259D06350440F759BD3'
}
mail.gpg(gpg_opts)
mail.deliver
signed_mail = Mail::TestMailer.deliveries.first
Mail::TestMailer.deliveries.clear
Schleuder::Runner.new().run(signed_mail.to_s, list.email)
messages = Mail::TestMailer.deliveries
recipients = messages.map { |m| m.to.first }.sort
expect(list.deliver_selfsent).to be(true)
expect(messages.size).to be(2)
expect(recipients).to eql(['admin@example.org', 'user1@example.org'])
expect(messages[0].parts.last.body.to_s).to include("-----BEGIN PGP MESSAGE-----")
expect(messages[0].subject).to eql("Something")
expect(messages[1].parts.last.body.to_s).to include("-----BEGIN PGP MESSAGE-----")
expect(messages[1].subject).to eql("Something")
teardown_list_and_mailer(list)
end
it "sends the message to all subscribers but not the sender, if deliver_selfsent is false and the mail is correctly signed" do
list = create(:list, send_encrypted_only: false, deliver_selfsent: false)
key_material = File.read("spec/fixtures/default_list_key.txt")
sub, msgs = list.subscribe("admin@example.org", nil, true, true, key_material)
key_material = File.read("spec/fixtures/example_key.txt")
sub, msgs = list.subscribe("user1@example.org", nil, false, true, key_material)
mail = Mail.new
mail.to = list.email
mail.from = 'admin@example.org'
mail.subject = 'Something'
mail.body = "Some content"
gpg_opts = {
sign: true,
sign_as: '59C71FB38AEE22E091C78259D06350440F759BD3'
}
mail.gpg(gpg_opts)
mail.deliver
signed_mail = Mail::TestMailer.deliveries.first
Mail::TestMailer.deliveries.clear
Schleuder::Runner.new().run(signed_mail.to_s, list.email)
messages = Mail::TestMailer.deliveries
recipients = messages.map { |m| m.to.first }.sort
expect(list.deliver_selfsent).to be(false)
expect(messages.size).to be(1)
expect(recipients).to eql(['user1@example.org'])
expect(messages[0].parts.last.body.to_s).to include("-----BEGIN PGP MESSAGE-----")
expect(messages[0].subject).to eql("Something")
teardown_list_and_mailer(list)
end
it "sends the message to all subscribers including the sender, if deliver_selfsent is false but the mail is not correctly signed" do
list = create(:list, send_encrypted_only: false, deliver_selfsent: false)
key_material = File.read("spec/fixtures/default_list_key.txt")
sub, msgs = list.subscribe("admin@example.org", nil, true, true, key_material)
key_material = File.read("spec/fixtures/example_key.txt")
sub, msgs = list.subscribe("user1@example.org", nil, false, true, key_material)
mail = Mail.new
mail.to = list.email
mail.from = 'admin@example.org'
mail.subject = 'Something'
mail.body = "Some content"
Schleuder::Runner.new().run(mail, list.email)
messages = Mail::TestMailer.deliveries
recipients = messages.map { |m| m.to.first }.sort
expect(list.deliver_selfsent).to be(false)
expect(messages.size).to be(2)
expect(recipients).to eql(['admin@example.org', 'user1@example.org'])
expect(messages[0].parts.last.body.to_s).to include("-----BEGIN PGP MESSAGE-----")
expect(messages[0].subject).to eql("Something")
teardown_list_and_mailer(list)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment