diff --git a/app/models/message_gateway.rb b/app/models/message_gateway.rb index 187a97f0c..a0ad2ca2b 100644 --- a/app/models/message_gateway.rb +++ b/app/models/message_gateway.rb @@ -2,7 +2,7 @@ class MessageGateway < ActionMailer::Base def receive(email) user = get_receiving_user_from_email_address(email) return false if user.nil? - return false unless check_sender_is_in_mailmap(user, email) + return false unless check_sender_is_in_mailmap(user, email.from[0]) context = user.prefs.sms_context todo_params = get_todo_params(email) @@ -90,29 +90,24 @@ def get_receiving_user_from_sms_email(address) return user end - def check_sender_is_in_mailmap(user, email) - if user.present? && !sender_is_in_mailmap?(user, email) - Rails.logger.warn "#{email.from[0]} not found in mailmap for #{user.login}" + def check_sender_is_in_mailmap(user, from) + if user.present? && SITE_CONFIG['email_dispatch'] == 'to' && !sender_is_in_mailmap?(user, from) + Rails.logger.warn "#{from} not found in mailmap for #{user.login}" return false end return true end - def sender_is_in_mailmap?(user, email) - if SITE_CONFIG['email_dispatch'] == 'to' - if SITE_CONFIG['mailmap'].is_a? Hash - # Look for the sender in the map of allowed senders - SITE_CONFIG['mailmap'][user.preference.sms_email].include? email.from[0] - else - # If the config mailmap isn't defined, use the values provided by the users. - pref_senders = user.prefs.sms_permitted_senders.split(',').collect(&:strip) - pref_senders.include? email.from[0] - end - else - # We can't check the map if it's not defined, or if the lookup is the - # wrong way round, so just allow it - true + def sender_is_in_mailmap?(user, from) + if SITE_CONFIG['mailmap'].is_a? Hash + # Look for the sender in the map of allowed senders + SITE_CONFIG['mailmap'][user.preference.sms_email].include? from + elif !(pref_senders = user.prefs.sms_permitted_senders).empty? + # If the config mailmap isn't defined, use the values provided by the users. + pref_senders.split(',').collect(&:strip).include? from end + # We can't check the map if it's not defined so just allow it + true end def get_text_or_nil(text) diff --git a/app/models/preference.rb b/app/models/preference.rb index 8e3d23ad9..f7cd7405f 100644 --- a/app/models/preference.rb +++ b/app/models/preference.rb @@ -2,7 +2,7 @@ class Preference < ApplicationRecord belongs_to :user belongs_to :sms_context, :class_name => 'Context' - validates_uniqueness_of :sms_email, :case_sensitive => false + validates :sms_email, uniqueness: { case_sensitive: false } def self.themes { :black => 'black', :light_blue => 'light_blue' } diff --git a/bin/rails b/bin/rails index 9d8f5bd1c..f5cab3d60 100755 --- a/bin/rails +++ b/bin/rails @@ -5,7 +5,7 @@ SCRIPT=$(readlink -f "$0") # Absolute path this script is in, thus /home/user/bin SCRIPTPATH=$(dirname "$SCRIPT") -if [ -e ../.use-docker -a ! -e /etc/app-env ]; +if [ -e $SCRIPTPATH/../.use-docker -a ! -e /etc/app-env ]; then $SCRIPTPATH/../script/docker-environment $0 "$@" else