From 45fa700561d2dd27d5f9d6a42f10be427861559a Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 19 Apr 2024 10:59:04 +0200 Subject: [PATCH] fix: choose dolist sender depending on the mail domain --- app/lib/dolist/api.rb | 10 ++++++---- config/env.example.optional | 1 + config/secrets.yml | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/lib/dolist/api.rb b/app/lib/dolist/api.rb index 87e401a0a..cc0d44bae 100644 --- a/app/lib/dolist/api.rb +++ b/app/lib/dolist/api.rb @@ -190,9 +190,11 @@ module Dolist format(base, account_id: account_id) end - def sender_id - Rails.cache.fetch("dolist_api_sender_id", expires_in: 1.hour) do - senders.dig("ItemList", 0, "Sender", "ID") + def sender_id(domain) + if domain == "demarches.gouv.fr" + Rails.application.secrets.dolist[:gouv_sender_id] + else + Rails.application.secrets.dolist[:default_sender_id] end end @@ -267,7 +269,7 @@ module Dolist "Message": { "Name": mail['X-Dolist-Message-Name'].value, "Subject": mail.subject, - "SenderID": sender_id, + "SenderID": sender_id(mail.from_address.domain), "ForceHttp": false, # ForceHttp : force le tracking http non sécurisé (True/False). "Format": "html", "DisableOpenTracking": true, # DisableOpenTracking : désactivation du tracking d'ouverture (True/False). diff --git a/config/env.example.optional b/config/env.example.optional index df8621781..691b1b50e 100644 --- a/config/env.example.optional +++ b/config/env.example.optional @@ -137,6 +137,7 @@ MATOMO_IFRAME_URL="https://matomo.example.org/index.php?module=CoreAdminHome&act # DOLIST_ACCOUNT_ID="" # DOLIST_NO_REPLY_EMAIL="" # DOLIST_API_KEY="" +# DOLIST_DEFAULT_SENDER_ID="" # SMTP Provider: SIB (Brevo) # SENDINBLUE_SMTP_ADDRESS="" diff --git a/config/secrets.yml b/config/secrets.yml index efb986716..61cd28651 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -32,6 +32,8 @@ defaults: &defaults password: <%= ENV['DOLIST_PASSWORD'] %> account_id: <%= ENV['DOLIST_ACCOUNT_ID'] %> api_key: <%= ENV['DOLIST_API_KEY'] %> + default_sender_id: <%= ENV['DOLIST_DEFAULT_SENDER_ID'] || 1 %> + gouv_sender_id: <%= ENV['DOLIST_GOUV_SENDER_ID'] || 1 %> api_entreprise: key: <%= ENV['API_ENTREPRISE_KEY'] %> mailtrap: