diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 1ed7e0ce7..339638d80 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -23,4 +23,10 @@ class ApplicationMailer < ActionMailer::Base "BY MODEL OBJECT: id ##{model.try(:id)} deliver_emails returned false" true end + + def format(email) + local, host = email.split('@') + host = SimpleIDN.to_ascii(host) + "#{local}@#{host}" + end end diff --git a/app/mailers/contact_mailer.rb b/app/mailers/contact_mailer.rb index 42968fe5a..2f8de7248 100644 --- a/app/mailers/contact_mailer.rb +++ b/app/mailers/contact_mailer.rb @@ -6,7 +6,7 @@ class ContactMailer < ApplicationMailer return if whitelist_blocked?(email) begin - mail(to: email, subject: "#{I18n.t(:contact_email_update_subject)} [#{@contact.code}]") + mail(to: format(email), subject: "#{I18n.t(:contact_email_update_subject)} [#{@contact.code}]") rescue EOFError, IOError, TimeoutError, diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index 3e9b7c360..8544af6a7 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -19,7 +19,7 @@ class DomainMailer < ApplicationMailer @verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}" return if whitelist_blocked?(@old_registrant.email) - mail(to: @old_registrant.email, + mail(to: format(@old_registrant.email), subject: "#{I18n.t(:pending_update_request_for_old_registrant_subject, name: @domain.name)} [#{@domain.name}]") end @@ -42,7 +42,7 @@ class DomainMailer < ApplicationMailer @old_registrant = Registrant.find(@domain.registrant_id_was) return if whitelist_blocked?(@new_registrant.email) - mail(to: @new_registrant.email, + mail(to: format(@new_registrant.email), subject: "#{I18n.t(:pending_update_notification_for_new_registrant_subject, name: @domain.name)} [#{@domain.name}]") end @@ -52,7 +52,7 @@ class DomainMailer < ApplicationMailer return if delivery_off?(@domain) return if whitelist_blocked?(@domain.registrant_email) - mail(to: @domain.registrant_email, + mail(to: format(@domain.registrant_email), subject: "#{I18n.t(:registrant_updated_notification_for_new_registrant_subject, name: @domain.name)} [#{@domain.name}]") end @@ -64,7 +64,7 @@ class DomainMailer < ApplicationMailer @old_registrant_email = domain.registrant_email # Nb! before applying pending updates return if whitelist_blocked?(@old_registrant_email) - mail(to: @old_registrant_email, + mail(to: format(@old_registrant_email), subject: "#{I18n.t(:registrant_updated_notification_for_old_registrant_subject, name: @domain.name)} [#{@domain.name}]") end @@ -77,7 +77,7 @@ class DomainMailer < ApplicationMailer @new_registrant_name = @domain.pending_json['new_registrant_name'] return if whitelist_blocked?(@new_registrant_email) - mail(to: @new_registrant_email, + mail(to: format(@new_registrant_email), subject: "#{I18n.t(:pending_update_rejected_notification_for_new_registrant_subject, name: @domain.name)} [#{@domain.name}]") end @@ -94,7 +94,7 @@ class DomainMailer < ApplicationMailer logger.info "EMAIL NOT DELIVERED: no registrant email [pending_update_expired_notification_for_new_registrant]" return end - mail(to: @new_registrant_email, + mail(to: format(@new_registrant_email), subject: "#{I18n.t(:pending_update_expired_notification_for_new_registrant_subject, name: @domain.name)} [#{@domain.name}]") end @@ -119,7 +119,7 @@ class DomainMailer < ApplicationMailer @verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}" return if whitelist_blocked?(@old_registrant.email) - mail(to: @old_registrant.email, + mail(to: format(@old_registrant.email), subject: "#{I18n.t(:domain_pending_deleted_subject, name: @domain.name)} [#{@domain.name}]") end @@ -139,7 +139,7 @@ class DomainMailer < ApplicationMailer end return if whitelist_blocked?(@domain.registrant.email) - mail(to: @domain.registrant.email, + mail(to: format(@domain.registrant.email), subject: "#{I18n.t(:pending_delete_rejected_notification_subject, name: @domain.name)} [#{@domain.name}]") end @@ -149,7 +149,7 @@ class DomainMailer < ApplicationMailer # no delivery off control, driggered by cron, no epp request return if whitelist_blocked?(@domain.registrant.email) - mail(to: @domain.registrant.email, + mail(to: format(@domain.registrant.email), subject: "#{I18n.t(:pending_delete_expired_notification_subject, name: @domain.name)} [#{@domain.name}]") end @@ -158,7 +158,7 @@ class DomainMailer < ApplicationMailer @domain = domain return if whitelist_blocked?(@domain.registrant.email) - mail(to: @domain.registrant.email, + mail(to: format(@domain.registrant.email), subject: "#{I18n.t(:delete_confirmation_subject, name: @domain.name)} [#{@domain.name}]") end diff --git a/app/mailers/invoice_mailer.rb b/app/mailers/invoice_mailer.rb index e93269e8e..e78795b66 100644 --- a/app/mailers/invoice_mailer.rb +++ b/app/mailers/invoice_mailer.rb @@ -4,6 +4,6 @@ class InvoiceMailer < ApplicationMailer @invoice = invoice attachments[invoice.pdf_name] = pdf - mail(to: invoice.billing_email, subject: invoice) + mail(to: format(invoice.billing_email), subject: invoice) end end diff --git a/spec/mailers/contact_mailer_spec.rb b/spec/mailers/contact_mailer_spec.rb index 60699a2f9..033843b50 100644 --- a/spec/mailers/contact_mailer_spec.rb +++ b/spec/mailers/contact_mailer_spec.rb @@ -1,6 +1,10 @@ require 'rails_helper' describe ContactMailer do + before :all do + Fabricate(:zonefile_setting, origin: 'ee') + end + describe 'email changed notification when delivery turned off' do before :all do @contact = Fabricate(:contact, email: 'test@example.ee') @@ -26,7 +30,6 @@ describe ContactMailer do describe 'email changed notification' do before :all do - Fabricate(:zonefile_setting, origin: 'ee') @domain = Fabricate(:domain) @contact = @domain.registrant @contact.reload # until figured out why registrant_domains not loaded @@ -50,4 +53,30 @@ describe ContactMailer do @mail.body.encoded.should =~ /Kontaktandmed:/ end end + + describe 'email with pynicode' do + before :all do + @domain = Fabricate(:domain) + @contact = @domain.registrant + @contact.reload # until figured out why registrant_domains not loaded + @contact.deliver_emails = true + @mail = ContactMailer.email_updated('info@ääöü.org', @contact) + end + + it 'should render email subject' do + @mail.subject.should =~ /Teie domeenide kontakt epostiaadress on muutunud/ + end + + it 'should have sender email' do + @mail.from.should == ["noreply@internet.ee"] + end + + it 'should send to info email' do + @mail.to.should == ['info@xn--4caa8cya.org'] + end + + it 'should render body' do + @mail.body.encoded.should =~ /Kontaktandmed:/ + end + end end