diff --git a/app/builders/email/base_builder.rb b/app/builders/email/base_builder.rb index 6f79d6018..a6da58792 100644 --- a/app/builders/email/base_builder.rb +++ b/app/builders/email/base_builder.rb @@ -41,7 +41,7 @@ class Email::BaseBuilder end def business_name - inbox.business_name || inbox.sanitized_name + inbox.sanitized_business_name end def account_support_email diff --git a/app/mailers/conversation_reply_mailer.rb b/app/mailers/conversation_reply_mailer.rb index d9e6ec8e0..20e194fed 100644 --- a/app/mailers/conversation_reply_mailer.rb +++ b/app/mailers/conversation_reply_mailer.rb @@ -105,7 +105,7 @@ class ConversationReplyMailer < ApplicationMailer end def business_name - @inbox.business_name || @inbox.sanitized_name + @inbox.sanitized_business_name end def from_email diff --git a/app/models/inbox.rb b/app/models/inbox.rb index 0a26462ad..82b250560 100644 --- a/app/models/inbox.rb +++ b/app/models/inbox.rb @@ -102,7 +102,7 @@ class Inbox < ApplicationRecord # Sanitizes inbox name for balanced email provider compatibility # ALLOWS: /'._- and Unicode letters/numbers/emojis - # REMOVES: Forbidden chars (\<>@") + spam-trigger symbols (!#$%&*+=?^`{|}~) + # REMOVES: Forbidden chars (\<>@"()) + spam-trigger symbols (!#$%&*+=?^`{|}~) def sanitized_name return default_name_for_blank_name if name.blank? @@ -110,6 +110,10 @@ class Inbox < ApplicationRecord sanitized.blank? && email? ? display_name_from_email : sanitized end + def sanitized_business_name + sanitize_raw_name(business_name) || sanitized_name + end + def sms? channel_type == 'Channel::Sms' end @@ -209,8 +213,15 @@ class Inbox < ApplicationRecord email? ? display_name_from_email : '' end + def sanitize_raw_name(raw) + return nil if raw.blank? + + result = apply_sanitization_rules(raw) + result.presence + end + def apply_sanitization_rules(name) - name.gsub(/[\\<>@"!#$%&*+=?^`{|}~:;]/, '') # Remove forbidden chars + name.gsub(/[\\<>@"!#$%&*+=?^`{|}~:;()]/, '') # Remove forbidden chars .gsub(/[\x00-\x1F\x7F]/, ' ') # Replace control chars with spaces .gsub(/\A[[:punct:]]+|[[:punct:]]+\z/, '') # Remove leading/trailing punctuation .gsub(/\s+/, ' ') # Normalize spaces