Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Clean invalid utf-8 chars from subject
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinst committed Sep 29, 2015
1 parent f180df2 commit 5057367
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/griddler/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(params)

@to = recipients(:to)
@from = extract_address(params[:from])
@subject = params[:subject]
@subject = extract_subject

@body = extract_body
@raw_text = params[:text]
Expand Down Expand Up @@ -44,6 +44,10 @@ def extract_address(address)
EmailParser.parse_address(clean_text(address))
end

def extract_subject
clean_text(params[:subject])
end

def extract_body
EmailParser.extract_reply_body(text_or_sanitized_html)
end
Expand Down
26 changes: 26 additions & 0 deletions spec/griddler/email_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,32 @@ def header_from_email(header)
end
end

describe Griddler::Email, 'extracting email subject' do
before do
@address = '[email protected]'
@subject = 'A very interesting email'
end

it 'handles normal characters' do
email = Griddler::Email.new(
to: [@address],
from: @address,
subject: @subject,
)
expect(email.subject).to eq @subject
end

it 'handles invalid UTF-8 characters' do
email = Griddler::Email.new(
to: [@address],
from: @address,
subject: "\xc0\xc1\xf5\xfa\xfe\xff #{@subject}",
)
expected = "ÀÁõúþÿ #{@subject}"
expect(email.subject).to eq expected
end
end

describe Griddler::Email, 'extracting email addresses from CC field' do
before do
@address = '[email protected]'
Expand Down

0 comments on commit 5057367

Please sign in to comment.