-
Notifications
You must be signed in to change notification settings - Fork 8
Fix Reply-To problem #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3e979b0
13d18c9
1bf3b14
7ff1068
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,6 @@ | |
| let(:expected_headers) do | ||
| { | ||
| 'X-Special-Domain-Specific-Header' => 'SecretValue', | ||
| 'Reply-To' => 'Reply To <reply-to@railsware.com>', | ||
| 'One-more-custom-header' => 'CustomValue' | ||
| } | ||
| end | ||
|
|
@@ -53,6 +52,35 @@ | |
|
|
||
| it { is_expected.to eq(expected_headers) } | ||
| end | ||
|
|
||
| context 'when reply-to is added in varying formats' do | ||
| [ | ||
| ['"메일트랩" <support@mailtrap.io>', { email: 'support@mailtrap.io', name: '메일트랩' }], | ||
| ['"Mailtrap Team" <support@mailtrap.io>', { email: 'support@mailtrap.io', name: 'Mailtrap Team' }], | ||
| ['support@mailtrap.io', { email: 'support@mailtrap.io' }] | ||
| ].each do |reply_to, expected_reply_to| | ||
| it "maps '#{reply_to}' to structured field and excludes header copy" do | ||
| message.reply_to = reply_to | ||
|
|
||
| expect(mail.reply_to).to eq(expected_reply_to) | ||
| expect(headers).not_to have_key('Reply-To') | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'when custom header and reply-to variants are present' do | ||
| before do | ||
| message.header['Reply-To'] = 'Reply To <reply-to@railsware.com>' | ||
| message.header['REPLY-TO'] = 'Upper Case <upper-reply-to@railsware.com>' | ||
| message.header['reply-to'] = 'Lower Case <lower-reply-to@railsware.com>' | ||
| message.header['X-Special-Domain-Specific-Header'] = 'SecretValue' | ||
| end | ||
|
|
||
| it 'keeps only custom headers and strips all reply-to header variants' do | ||
| expect(mail.reply_to).to eq({ email: 'lower-reply-to@railsware.com', name: 'Lower Case' }) | ||
| expect(headers).to eq('X-Special-Domain-Specific-Header' => 'SecretValue') | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe '#attachment' do | ||
|
|
@@ -155,6 +183,19 @@ | |
| its(:template_variables) { is_expected.to eq('first_name' => 'John') } | ||
| end | ||
|
|
||
| context "when 'reply-to' is invalid" do | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the tests should be refactored. I can do that once merged.
|
||
| before do | ||
| message.header['Reply-To'] = 'invalid email@example.com' | ||
| end | ||
|
|
||
| it 'raises an error' do | ||
| expect { mail }.to raise_error( | ||
| Mailtrap::Error, | ||
| "failed to parse 'Reply-To': 'invalid email@example.com'" | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| %i[from to cc bcc].each do |header| | ||
| context "when '#{header}' is invalid" do | ||
| let(:message_params) { super().merge(header => 'invalid email@example.com') } | ||
|
|
@@ -167,5 +208,36 @@ | |
| end | ||
| end | ||
| end | ||
|
|
||
| context "when 'reply-to' is invalid" do | ||
| let(:invalid_reply_to) { 'invalid email@example.com' } | ||
|
|
||
| before do | ||
| message.header['Reply-To'] = invalid_reply_to | ||
| end | ||
|
|
||
| it 'raises an error' do | ||
| expect { mail }.to raise_error( | ||
| Mailtrap::Error, | ||
| "failed to parse 'Reply-To': 'invalid email@example.com'" | ||
| ) | ||
| end | ||
|
|
||
| context 'when address contains a folded line break' do | ||
| let(:invalid_reply_to) do | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you please explain this case? |
||
| encoded_name = ['메일트랩 팀'.encode('UTF-8')].pack('m0') | ||
| folded_domain = %w[exa mple.com].join("\r\n ") | ||
|
|
||
| "=?UTF-8?B?#{encoded_name}?= <no-reply@#{folded_domain}>" | ||
| end | ||
|
|
||
| it 'raises an error' do | ||
| expect { mail }.to raise_error( | ||
| Mailtrap::Error, | ||
| /failed to parse 'Reply-To': '.*no-reply@exa/m | ||
| ) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reply-to in the raw email.
Before:
After: