mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-17 19:12:37 -05:00
FIX: reply by email can handle emails with attachments. Attachments are still ignored, but a post or topic can be created from the email now.
This commit is contained in:
parent
d23585e444
commit
fd504e741f
2 changed files with 19 additions and 18 deletions
|
@ -37,7 +37,7 @@ module Email
|
|||
def process
|
||||
raise EmptyEmailError if @raw.blank?
|
||||
|
||||
@message = Mail::Message.new(@raw)
|
||||
@message = Mail.new(@raw)
|
||||
|
||||
|
||||
# First remove the known discourse stuff.
|
||||
|
@ -92,15 +92,13 @@ module Email
|
|||
|
||||
# If the message is multipart, find the best type for our purposes
|
||||
if @message.multipart?
|
||||
@message.parts.each do |p|
|
||||
if p.content_type =~ /text\/plain/
|
||||
if p = @message.text_part
|
||||
@body = p.charset ? p.body.decoded.force_encoding(p.charset).encode("UTF-8").to_s : p.body.to_s
|
||||
return @body
|
||||
elsif p.content_type =~ /text\/html/
|
||||
elsif p = @message.html_part
|
||||
html = p.charset ? p.body.decoded.force_encoding(p.charset).encode("UTF-8").to_s : p.body.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if @message.content_type =~ /text\/html/
|
||||
if defined? @message.charset
|
||||
|
@ -109,6 +107,7 @@ module Email
|
|||
html = @message.body.to_s
|
||||
end
|
||||
end
|
||||
|
||||
if html.present?
|
||||
@body = scrub_html(html)
|
||||
return @body
|
||||
|
|
|
@ -43,16 +43,6 @@ stripped from my reply?")
|
|||
end
|
||||
end
|
||||
|
||||
describe "it ignores messages it can't parse due to containing weird terms" do
|
||||
let(:attachment) { File.read("#{Rails.root}/spec/fixtures/emails/attachment.eml") }
|
||||
let(:receiver) { Email::Receiver.new(attachment) }
|
||||
|
||||
it "processes correctly" do
|
||||
expect { receiver.process}.to raise_error(Email::Receiver::EmptyEmailError)
|
||||
expect(receiver.body).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
describe "it supports a dutch reply" do
|
||||
let(:dutch) { File.read("#{Rails.root}/spec/fixtures/emails/dutch.eml") }
|
||||
let(:receiver) { Email::Receiver.new(dutch) }
|
||||
|
@ -187,6 +177,18 @@ greatest show ever created. Everyone should watch it.
|
|||
|
||||
end
|
||||
|
||||
describe "email with attachments" do
|
||||
it "can find the message and create a post" do
|
||||
User.stubs(:find_by_email).returns(user)
|
||||
EmailLog.stubs(:for).returns(email_log)
|
||||
attachment_email = File.read("#{Rails.root}/spec/fixtures/emails/attachment.eml")
|
||||
r = Email::Receiver.new(attachment_email)
|
||||
r.expects(:create_reply)
|
||||
expect { r.process }.to_not raise_error
|
||||
expect(r.body).to eq("here is an image attachment")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "processes a valid incoming email" do
|
||||
|
|
Loading…
Reference in a new issue