2013-11-25 11:29:37 -05:00
|
|
|
# -*- encoding : utf-8 -*-
|
|
|
|
|
2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-06-10 16:46:08 -04:00
|
|
|
require 'email/receiver'
|
|
|
|
|
|
|
|
describe Email::Receiver do
|
|
|
|
|
2013-06-13 18:11:10 -04:00
|
|
|
before do
|
2014-07-31 04:46:02 -04:00
|
|
|
SiteSetting.reply_by_email_address = "reply+%{reply_key}@appmail.adventuretime.ooo"
|
|
|
|
SiteSetting.email_in = false
|
2014-08-26 20:08:53 -04:00
|
|
|
SiteSetting.title = "Discourse"
|
2013-06-13 18:11:10 -04:00
|
|
|
end
|
2013-06-10 16:46:08 -04:00
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
describe 'parse_body' do
|
|
|
|
def test_parse_body(mail_string)
|
|
|
|
Email::Receiver.new(nil).parse_body(Mail::Message.new mail_string)
|
|
|
|
end
|
|
|
|
|
2014-02-28 07:05:09 -05:00
|
|
|
it "raises EmptyEmailError if the message is blank" do
|
2014-08-26 20:08:53 -04:00
|
|
|
expect { test_parse_body("") }.to raise_error(Email::Receiver::EmptyEmailError)
|
2013-06-13 18:11:10 -04:00
|
|
|
end
|
2013-06-10 16:46:08 -04:00
|
|
|
|
2014-07-11 15:26:40 -04:00
|
|
|
it "raises EmptyEmailError if the message is not an email" do
|
2014-08-26 20:08:53 -04:00
|
|
|
expect { test_parse_body("asdf" * 30) }.to raise_error(Email::Receiver::EmptyEmailError)
|
2013-06-10 16:46:08 -04:00
|
|
|
end
|
2014-07-11 15:26:40 -04:00
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
it "raises EmptyEmailError if there is no reply content" do
|
|
|
|
expect { test_parse_body(fixture_file("emails/no_content_reply.eml")) }.to raise_error(Email::Receiver::EmptyEmailError)
|
2014-07-11 15:26:40 -04:00
|
|
|
end
|
2013-06-13 18:11:10 -04:00
|
|
|
|
2014-09-25 11:44:48 -04:00
|
|
|
skip "raises EmailUnparsableError if the headers are corrupted" do
|
2014-08-26 20:08:53 -04:00
|
|
|
expect { ; }.to raise_error(Email::Receiver::EmailUnparsableError)
|
|
|
|
end
|
2013-06-20 12:38:03 -04:00
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
it "can parse the html section" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/html_only.eml"))).to eq("The EC2 instance - I've seen that there tends to be odd and " +
|
|
|
|
"unrecommended settings on the Bitnami installs that I've checked out.")
|
2013-06-20 12:38:03 -04:00
|
|
|
end
|
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
it "supports a Dutch reply" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/dutch.eml"))).to eq("Dit is een antwoord in het Nederlands.")
|
2014-08-26 20:08:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "supports a Hebrew reply" do
|
2015-11-18 15:22:50 -05:00
|
|
|
I18n.stubs(:t).with('user_notifications.previous_discussion').returns('כלטוב')
|
2013-06-20 12:38:03 -04:00
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
# The force_encoding call is only needed for the test - it is passed on fine to the cooked post
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/hebrew.eml"))).to eq("שלום")
|
2013-06-20 12:38:03 -04:00
|
|
|
end
|
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
it "supports a BIG5-encoded reply" do
|
|
|
|
# The force_encoding call is only needed for the test - it is passed on fine to the cooked post
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/big5.eml"))).to eq("媽!我上電視了!")
|
2013-07-24 14:22:32 -04:00
|
|
|
end
|
2013-08-21 16:54:01 -04:00
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
it "removes 'via' lines if they match the site title" do
|
|
|
|
SiteSetting.title = "Discourse"
|
2013-11-04 15:30:24 -05:00
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/via_line.eml"))).to eq("Hello this email has content!")
|
2013-11-04 15:30:24 -05:00
|
|
|
end
|
|
|
|
|
2014-09-09 19:24:20 -04:00
|
|
|
it "removes an 'on date wrote' quoting line" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/on_wrote.eml"))).to eq("Sure, all you need to do is frobnicate the foobar and you'll be all set!")
|
2014-09-09 19:24:20 -04:00
|
|
|
end
|
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
it "removes the 'Previous Discussion' marker" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/previous.eml"))).to eq("This will not include the previous discussion that is present in this email.")
|
2014-08-26 20:08:53 -04:00
|
|
|
end
|
2014-01-16 21:24:32 -05:00
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
it "handles multiple paragraphs" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/paragraphs.eml"))).
|
|
|
|
to eq(
|
2014-08-26 20:08:53 -04:00
|
|
|
"Is there any reason the *old* candy can't be be kept in silos while the new candy
|
|
|
|
is imported into *new* silos?
|
|
|
|
|
|
|
|
The thing about candy is it stays delicious for a long time -- we can just keep
|
|
|
|
it there without worrying about it too much, imo.
|
|
|
|
|
|
|
|
Thanks for listening."
|
|
|
|
)
|
2014-01-16 21:24:32 -05:00
|
|
|
end
|
2014-08-28 15:09:42 -04:00
|
|
|
|
2014-10-08 10:15:46 -04:00
|
|
|
it "handles multiple paragraphs when parsing html" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/html_paragraphs.eml"))).
|
|
|
|
to eq(
|
2014-10-08 10:15:46 -04:00
|
|
|
"Awesome!
|
|
|
|
|
|
|
|
Pleasure to have you here!
|
|
|
|
|
|
|
|
:boom:"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2014-11-25 11:44:59 -05:00
|
|
|
it "handles newlines" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/newlines.eml"))).
|
|
|
|
to eq(
|
2014-11-25 11:44:59 -05:00
|
|
|
"This is my reply.
|
|
|
|
It is my best reply.
|
|
|
|
It will also be my *only* reply."
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2014-12-01 13:21:14 -05:00
|
|
|
it "handles inline reply" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/inline_reply.eml"))).
|
|
|
|
to eq(
|
2014-12-01 13:21:14 -05:00
|
|
|
"On Wed, Oct 8, 2014 at 11:12 AM, techAPJ <info@unconfigured.discourse.org> wrote:
|
|
|
|
|
|
|
|
> techAPJ <https://meta.discourse.org/users/techapj>
|
|
|
|
> November 28
|
|
|
|
>
|
|
|
|
> Test reply.
|
|
|
|
>
|
|
|
|
> First paragraph.
|
|
|
|
>
|
|
|
|
> Second paragraph.
|
|
|
|
>
|
|
|
|
> To respond, reply to this email or visit
|
|
|
|
> https://meta.discourse.org/t/testing-default-email-replies/22638/3 in
|
|
|
|
> your browser.
|
|
|
|
> ------------------------------
|
|
|
|
> Previous Replies codinghorror
|
|
|
|
> <https://meta.discourse.org/users/codinghorror>
|
|
|
|
> November 28
|
|
|
|
>
|
|
|
|
> We're testing the latest GitHub email processing library which we are
|
|
|
|
> integrating now.
|
|
|
|
>
|
|
|
|
> https://github.com/github/email_reply_parser
|
|
|
|
>
|
|
|
|
> Go ahead and reply to this topic and I'll reply from various email clients
|
|
|
|
> for testing.
|
|
|
|
> ------------------------------
|
|
|
|
>
|
|
|
|
> To respond, reply to this email or visit
|
|
|
|
> https://meta.discourse.org/t/testing-default-email-replies/22638/3 in
|
|
|
|
> your browser.
|
|
|
|
>
|
|
|
|
> To unsubscribe from these emails, visit your user preferences
|
|
|
|
> <https://meta.discourse.org/my/preferences>.
|
|
|
|
>
|
|
|
|
|
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
|
|
|
|
the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown
|
|
|
|
fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
|
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
|
|
|
|
the lazy dog. The quick brown fox jumps over the lazy dog."
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2015-11-18 15:22:50 -05:00
|
|
|
it "can retrieve the first part of multiple replies" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/inline_mixed.eml"))).to eq(
|
|
|
|
"The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
|
|
|
|
the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown
|
|
|
|
fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
|
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
|
|
|
|
the lazy dog. The quick brown fox jumps over the lazy dog.
|
|
|
|
|
|
|
|
> First paragraph.
|
|
|
|
>
|
|
|
|
> Second paragraph.
|
|
|
|
|
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
|
|
|
|
the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown"
|
|
|
|
)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-11-25 11:44:59 -05:00
|
|
|
it "should not include previous replies" do
|
2015-11-18 15:22:50 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/previous_replies.eml"))).not_to match(/Previous Replies/)
|
2014-11-25 11:44:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "strips iPhone signature" do
|
2015-11-18 15:22:50 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/iphone_signature.eml"))).not_to match(/Sent from my iPhone/)
|
2014-11-25 11:44:59 -05:00
|
|
|
end
|
|
|
|
|
2015-12-09 12:44:01 -05:00
|
|
|
it "strips regular signature" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/signature.eml"))).not_to match(/Arpit/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "strips 'original message' context" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/original_message_context.eml"))).not_to match(/Context/)
|
|
|
|
end
|
|
|
|
|
2014-11-25 11:44:59 -05:00
|
|
|
it "properly renders email reply from gmail web client" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/gmail_web.eml"))).
|
|
|
|
to eq(
|
2014-11-25 11:44:59 -05:00
|
|
|
"### This is a reply from standard GMail in Google Chrome.
|
|
|
|
|
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
|
|
|
|
the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown
|
|
|
|
fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
|
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
|
|
|
|
the lazy dog. The quick brown fox jumps over the lazy dog.
|
|
|
|
|
|
|
|
Here's some **bold** text in Markdown.
|
|
|
|
|
|
|
|
Here's a link http://example.com"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "properly renders email reply from iOS default mail client" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/ios_default.eml"))).
|
|
|
|
to eq(
|
2014-11-25 11:44:59 -05:00
|
|
|
"### this is a reply from iOS default mail
|
|
|
|
|
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
|
|
|
|
|
|
|
|
Here's some **bold** markdown text.
|
|
|
|
|
|
|
|
Here's a link http://example.com"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "properly renders email reply from Android 5 gmail client" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/android_gmail.eml"))).
|
|
|
|
to eq(
|
2014-11-25 11:44:59 -05:00
|
|
|
"### this is a reply from Android 5 gmail
|
|
|
|
|
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
|
|
|
|
the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown
|
|
|
|
fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
|
|
|
|
The quick brown fox jumps over the lazy dog.
|
|
|
|
|
|
|
|
This is **bold** in Markdown.
|
|
|
|
|
|
|
|
This is a link to http://example.com"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "properly renders email reply from Windows 8.1 Metro default mail client" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/windows_8_metro.eml"))).
|
|
|
|
to eq(
|
2014-11-25 11:44:59 -05:00
|
|
|
"### reply from default mail client in Windows 8.1 Metro
|
|
|
|
|
|
|
|
|
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
|
|
|
|
|
|
|
|
|
|
|
|
This is a **bold** word in Markdown
|
|
|
|
|
|
|
|
|
|
|
|
This is a link http://example.com"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2014-10-14 06:12:01 -04:00
|
|
|
it "properly renders email reply from MS Outlook client" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(test_parse_body(fixture_file("emails/outlook.eml"))).to eq("Microsoft Outlook 2010")
|
2014-10-14 06:12:01 -04:00
|
|
|
end
|
|
|
|
|
2014-08-28 15:09:42 -04:00
|
|
|
it "converts back to UTF-8 at the end" do
|
|
|
|
result = test_parse_body(fixture_file("emails/big5.eml"))
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(result.encoding).to eq(Encoding::UTF_8)
|
2014-08-28 15:09:42 -04:00
|
|
|
|
|
|
|
# should not throw
|
|
|
|
TextCleaner.normalize_whitespaces(
|
|
|
|
test_parse_body(fixture_file("emails/big5.eml"))
|
|
|
|
)
|
|
|
|
end
|
2014-01-16 21:24:32 -05:00
|
|
|
end
|
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
describe "posting replies" do
|
|
|
|
let(:reply_key) { raise "Override this in a lower describe block" }
|
|
|
|
let(:email_raw) { raise "Override this in a lower describe block" }
|
|
|
|
# ----
|
2015-12-15 18:43:05 -05:00
|
|
|
let(:to) { SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) }
|
2014-08-26 20:08:53 -04:00
|
|
|
let(:receiver) { Email::Receiver.new(email_raw) }
|
|
|
|
let(:post) { create_post }
|
|
|
|
let(:topic) { post.topic }
|
|
|
|
let(:posting_user) { post.user }
|
|
|
|
let(:replying_user_email) { 'jake@adventuretime.ooo' }
|
|
|
|
let(:replying_user) { Fabricate(:user, email: replying_user_email, trust_level: 2)}
|
|
|
|
let(:email_log) { EmailLog.new(reply_key: reply_key,
|
|
|
|
post: post,
|
|
|
|
post_id: post.id,
|
|
|
|
topic_id: post.topic_id,
|
|
|
|
email_type: 'user_posted',
|
|
|
|
user: replying_user,
|
|
|
|
user_id: replying_user.id,
|
|
|
|
to_address: replying_user_email
|
|
|
|
) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
email_log.save
|
|
|
|
end
|
|
|
|
|
|
|
|
# === Success Posting ===
|
|
|
|
|
|
|
|
describe "valid_reply.eml" do
|
|
|
|
let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' }
|
2015-12-15 18:43:05 -05:00
|
|
|
let!(:email_raw) { fill_email(fixture_file("emails/valid_reply.eml"), replying_user_email, to) }
|
2014-08-26 20:08:53 -04:00
|
|
|
|
|
|
|
it "creates a post with the correct content" do
|
|
|
|
start_count = topic.posts.count
|
|
|
|
|
|
|
|
receiver.process
|
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(topic.posts.count).to eq(start_count + 1)
|
2014-09-04 13:04:22 -04:00
|
|
|
created_post = topic.posts.last
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(created_post.via_email).to eq(true)
|
|
|
|
expect(created_post.cooked.strip).to eq(fixture_file("emails/valid_reply.cooked").strip)
|
2014-08-26 20:08:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "paragraphs.eml" do
|
|
|
|
let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' }
|
|
|
|
let!(:email_raw) { fixture_file("emails/paragraphs.eml") }
|
2013-08-21 16:54:01 -04:00
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
it "cooks multiple paragraphs with traditional Markdown linebreaks" do
|
|
|
|
start_count = topic.posts.count
|
|
|
|
|
|
|
|
receiver.process
|
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(topic.posts.count).to eq(start_count + 1)
|
|
|
|
expect(topic.posts.last.cooked.strip).to eq(fixture_file("emails/paragraphs.cooked").strip)
|
2015-11-18 15:22:50 -05:00
|
|
|
expect(topic.posts.last.cooked).not_to match(/<br/)
|
2014-08-26 20:08:53 -04:00
|
|
|
end
|
2013-08-21 16:54:01 -04:00
|
|
|
end
|
2013-07-24 14:22:32 -04:00
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
describe "attachment.eml" do
|
|
|
|
let!(:reply_key) { '636ca428858779856c226bb145ef4fad' }
|
|
|
|
let!(:email_raw) {
|
|
|
|
fixture_file("emails/attachment.eml")
|
|
|
|
.gsub("TO", "reply+#{reply_key}@appmail.adventuretime.ooo")
|
|
|
|
.gsub("FROM", replying_user_email)
|
|
|
|
}
|
|
|
|
|
|
|
|
let(:upload_sha) { '04df605be528d03876685c52166d4b063aabb78a' }
|
|
|
|
|
|
|
|
it "creates a post with an attachment" do
|
2015-07-15 11:15:43 -04:00
|
|
|
Upload.stubs(:fix_image_orientation)
|
|
|
|
ImageOptim.any_instance.stubs(:optimize_image!)
|
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
start_count = topic.posts.count
|
2015-07-15 11:15:43 -04:00
|
|
|
Upload.find_by(sha1: upload_sha).try(:destroy)
|
2014-08-26 20:08:53 -04:00
|
|
|
|
|
|
|
receiver.process
|
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(topic.posts.count).to eq(start_count + 1)
|
2015-11-18 15:22:50 -05:00
|
|
|
expect(topic.posts.last.cooked).to match(/<img src=['"](\/uploads\/default\/original\/.+\.png)['"] width=['"]289['"] height=['"]126['"]>/)
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(Upload.find_by(sha1: upload_sha)).not_to eq(nil)
|
2014-08-26 20:08:53 -04:00
|
|
|
end
|
2013-07-24 14:22:32 -04:00
|
|
|
|
2015-12-30 06:17:45 -05:00
|
|
|
describe 'Liking via email' do
|
|
|
|
let!(:reply_key) { '636ca428858779856c226bb145ef4fad' }
|
|
|
|
let(:replied_user_like_params) { { user: replying_user, post: post, post_action_type_id: PostActionType.types[:like] } }
|
|
|
|
let(:replied_user_like) { PostAction.find_by(replied_user_like_params) }
|
|
|
|
|
|
|
|
describe "plus_one.eml" do
|
|
|
|
let!(:email_raw) {
|
|
|
|
fixture_file("emails/plus_one.eml")
|
|
|
|
.gsub("TO", "reply+#{reply_key}@appmail.adventuretime.ooo")
|
|
|
|
.gsub("FROM", replying_user_email)
|
|
|
|
}
|
|
|
|
|
|
|
|
it "adds a user like to the post" do
|
|
|
|
expect { receiver.process }.to change { PostAction.count }.by(1)
|
|
|
|
expect(replied_user_like).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not create a duplicate like" do
|
|
|
|
PostAction.create(replied_user_like_params)
|
|
|
|
before_count = PostAction.count
|
|
|
|
expect { receiver.process }.to raise_error(Email::Receiver::InvalidPostAction)
|
|
|
|
expect(PostAction.count).to eq before_count
|
|
|
|
expect(replied_user_like).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "like.eml" do
|
|
|
|
let!(:email_raw) {
|
|
|
|
fixture_file("emails/like.eml")
|
|
|
|
.gsub("TO", "reply+#{reply_key}@appmail.adventuretime.ooo")
|
|
|
|
.gsub("FROM", replying_user_email)
|
|
|
|
}
|
|
|
|
|
|
|
|
it 'adds a user like to the post' do
|
|
|
|
expect { receiver.process }.to change { PostAction.count }.by(1)
|
|
|
|
expect(replied_user_like).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-07-24 14:22:32 -04:00
|
|
|
end
|
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
# === Failure Conditions ===
|
2013-07-24 14:22:32 -04:00
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
describe "too_short.eml" do
|
|
|
|
let!(:reply_key) { '636ca428858779856c226bb145ef4fad' }
|
|
|
|
let!(:email_raw) {
|
|
|
|
fixture_file("emails/too_short.eml")
|
|
|
|
.gsub("TO", "reply+#{reply_key}@appmail.adventuretime.ooo")
|
|
|
|
.gsub("FROM", replying_user_email)
|
|
|
|
.gsub("SUBJECT", "re: [Discourse Meta] eviltrout posted in 'Adventure Time Sux'")
|
|
|
|
}
|
|
|
|
|
|
|
|
it "raises an InvalidPost error" do
|
|
|
|
SiteSetting.min_post_length = 5
|
|
|
|
expect { receiver.process }.to raise_error(Email::Receiver::InvalidPost)
|
|
|
|
end
|
2013-07-24 14:22:32 -04:00
|
|
|
end
|
2014-08-26 20:08:53 -04:00
|
|
|
|
|
|
|
describe "too_many_mentions.eml" do
|
|
|
|
let!(:reply_key) { '636ca428858779856c226bb145ef4fad' }
|
|
|
|
let!(:email_raw) { fixture_file("emails/too_many_mentions.eml") }
|
|
|
|
|
|
|
|
it "raises an InvalidPost error" do
|
|
|
|
SiteSetting.max_mentions_per_post = 10
|
|
|
|
(1..11).each do |i|
|
|
|
|
Fabricate(:user, username: "user#{i}").save
|
|
|
|
end
|
|
|
|
|
|
|
|
expect { receiver.process }.to raise_error(Email::Receiver::InvalidPost)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-12-04 11:45:31 -05:00
|
|
|
describe "auto response email replies should not be accepted" do
|
|
|
|
let!(:reply_key) { '636ca428858779856c226bb145ef4fad' }
|
|
|
|
let!(:email_raw) { fixture_file("emails/auto_reply.eml") }
|
2015-02-18 08:23:51 -05:00
|
|
|
it "raises a AutoGeneratedEmailError" do
|
|
|
|
expect { receiver.process }.to raise_error(Email::Receiver::AutoGeneratedEmailError)
|
2014-12-04 11:45:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-24 14:22:32 -04:00
|
|
|
end
|
|
|
|
|
2014-10-25 10:36:59 -04:00
|
|
|
describe "posting reply to a closed topic" do
|
|
|
|
let(:reply_key) { raise "Override this in a lower describe block" }
|
|
|
|
let(:email_raw) { raise "Override this in a lower describe block" }
|
2015-12-15 18:43:05 -05:00
|
|
|
let(:to) { SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) }
|
2014-10-25 10:36:59 -04:00
|
|
|
let(:receiver) { Email::Receiver.new(email_raw) }
|
|
|
|
let(:topic) { Fabricate(:topic, closed: true) }
|
|
|
|
let(:post) { Fabricate(:post, topic: topic, post_number: 1) }
|
|
|
|
let(:replying_user_email) { 'jake@adventuretime.ooo' }
|
|
|
|
let(:replying_user) { Fabricate(:user, email: replying_user_email, trust_level: 2) }
|
|
|
|
let(:email_log) { EmailLog.new(reply_key: reply_key,
|
|
|
|
post: post,
|
|
|
|
post_id: post.id,
|
|
|
|
topic_id: topic.id,
|
|
|
|
email_type: 'user_posted',
|
|
|
|
user: replying_user,
|
|
|
|
user_id: replying_user.id,
|
|
|
|
to_address: replying_user_email
|
|
|
|
) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
email_log.save
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "should not create post" do
|
|
|
|
let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' }
|
2015-12-15 18:43:05 -05:00
|
|
|
let!(:email_raw) { fill_email(fixture_file("emails/valid_reply.eml"), replying_user_email, to) }
|
2014-10-25 10:36:59 -04:00
|
|
|
it "raises a TopicClosedError" do
|
|
|
|
expect { receiver.process }.to raise_error(Email::Receiver::TopicClosedError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-27 02:58:31 -04:00
|
|
|
describe "posting reply to a deleted topic" do
|
|
|
|
let(:reply_key) { raise "Override this in a lower describe block" }
|
|
|
|
let(:email_raw) { raise "Override this in a lower describe block" }
|
2015-12-15 18:43:05 -05:00
|
|
|
let(:to) { SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) }
|
2014-10-27 02:58:31 -04:00
|
|
|
let(:receiver) { Email::Receiver.new(email_raw) }
|
|
|
|
let(:deleted_topic) { Fabricate(:deleted_topic) }
|
|
|
|
let(:post) { Fabricate(:post, topic: deleted_topic, post_number: 1) }
|
|
|
|
let(:replying_user_email) { 'jake@adventuretime.ooo' }
|
|
|
|
let(:replying_user) { Fabricate(:user, email: replying_user_email, trust_level: 2) }
|
|
|
|
let(:email_log) { EmailLog.new(reply_key: reply_key,
|
|
|
|
post: post,
|
|
|
|
post_id: post.id,
|
|
|
|
topic_id: deleted_topic.id,
|
|
|
|
email_type: 'user_posted',
|
|
|
|
user: replying_user,
|
|
|
|
user_id: replying_user.id,
|
|
|
|
to_address: replying_user_email
|
|
|
|
) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
email_log.save
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "should not create post" do
|
|
|
|
let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' }
|
2015-12-15 18:43:05 -05:00
|
|
|
let!(:email_raw) { fill_email(fixture_file("emails/valid_reply.eml"), replying_user_email, to) }
|
2014-10-27 02:58:31 -04:00
|
|
|
it "raises a TopicNotFoundError" do
|
|
|
|
expect { receiver.process }.to raise_error(Email::Receiver::TopicNotFoundError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-21 11:54:02 -05:00
|
|
|
describe "posting reply as a inactive user" do
|
|
|
|
let(:reply_key) { raise "Override this in a lower describe block" }
|
|
|
|
let(:email_raw) { raise "Override this in a lower describe block" }
|
|
|
|
let(:to) { SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) }
|
|
|
|
let(:receiver) { Email::Receiver.new(email_raw) }
|
|
|
|
let(:topic) { Fabricate(:topic) }
|
|
|
|
let(:post) { Fabricate(:post, topic: topic, post_number: 1) }
|
|
|
|
let(:replying_user_email) { 'jake@adventuretime.ooo' }
|
|
|
|
let(:replying_user) { Fabricate(:user, email: replying_user_email, trust_level: 2, active: false) }
|
|
|
|
let(:email_log) { EmailLog.new(reply_key: reply_key,
|
|
|
|
post: post,
|
|
|
|
post_id: post.id,
|
|
|
|
topic_id: topic.id,
|
|
|
|
email_type: 'user_posted',
|
|
|
|
user: replying_user,
|
|
|
|
user_id: replying_user.id,
|
|
|
|
to_address: replying_user_email
|
|
|
|
) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
email_log.save
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "should not create post" do
|
|
|
|
let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' }
|
|
|
|
let!(:email_raw) { fill_email(fixture_file("emails/valid_reply.eml"), replying_user_email, to) }
|
|
|
|
it "raises a InactiveUserError" do
|
|
|
|
expect { receiver.process }.to raise_error(Email::Receiver::InactiveUserError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-07 11:01:08 -05:00
|
|
|
describe "posting a new topic in a category" do
|
2014-08-26 20:08:53 -04:00
|
|
|
let(:category_destination) { raise "Override this in a lower describe block" }
|
|
|
|
let(:email_raw) { raise "Override this in a lower describe block" }
|
|
|
|
let(:allow_strangers) { false }
|
|
|
|
# ----
|
|
|
|
let(:receiver) { Email::Receiver.new(email_raw) }
|
|
|
|
let(:user_email) { 'jake@adventuretime.ooo' }
|
|
|
|
let(:user) { Fabricate(:user, email: user_email, trust_level: 2)}
|
|
|
|
let(:category) { Fabricate(:category, email_in: category_destination, email_in_allow_strangers: allow_strangers) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.email_in = true
|
|
|
|
user.save
|
|
|
|
category.save
|
|
|
|
end
|
2013-06-25 14:05:14 -04:00
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
describe "too_short.eml" do
|
|
|
|
let!(:category_destination) { 'incoming+amazing@appmail.adventuretime.ooo' }
|
|
|
|
let(:email_raw) {
|
|
|
|
fixture_file("emails/too_short.eml")
|
|
|
|
.gsub("TO", category_destination)
|
|
|
|
.gsub("FROM", user_email)
|
|
|
|
.gsub("SUBJECT", "A long subject that passes the checks")
|
|
|
|
}
|
2013-06-25 14:05:14 -04:00
|
|
|
|
2014-08-26 20:08:53 -04:00
|
|
|
it "does not create a topic if the post fails" do
|
|
|
|
before_topic_count = Topic.count
|
|
|
|
|
|
|
|
expect { receiver.process }.to raise_error(Email::Receiver::InvalidPost)
|
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(Topic.count).to eq(before_topic_count)
|
2014-08-26 20:08:53 -04:00
|
|
|
end
|
2013-06-25 14:05:14 -04:00
|
|
|
|
|
|
|
end
|
2014-08-26 20:08:53 -04:00
|
|
|
|
2013-06-25 14:05:14 -04:00
|
|
|
end
|
|
|
|
|
2014-07-31 04:46:02 -04:00
|
|
|
def process_email(opts)
|
|
|
|
incoming_email = fixture_file("emails/valid_incoming.eml")
|
2015-12-10 17:49:16 -05:00
|
|
|
email = fill_email(incoming_email, opts[:from], opts[:to], opts[:body], opts[:subject], opts[:cc])
|
2014-07-31 04:46:02 -04:00
|
|
|
Email::Receiver.new(email).process
|
|
|
|
end
|
|
|
|
|
2013-06-13 18:11:10 -04:00
|
|
|
describe "with a valid email" do
|
|
|
|
let(:reply_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" }
|
2014-07-31 04:46:02 -04:00
|
|
|
let(:to) { SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) }
|
2015-12-15 18:43:05 -05:00
|
|
|
let(:user_email) { "test@test.com" }
|
|
|
|
let(:user) { Fabricate(:user, email: user_email, trust_level: 2)}
|
|
|
|
let(:post) { create_post(user: user) }
|
2014-07-31 04:46:02 -04:00
|
|
|
|
|
|
|
let(:valid_reply) {
|
|
|
|
reply = fixture_file("emails/valid_reply.eml")
|
2015-12-15 18:43:05 -05:00
|
|
|
fill_email(reply, user.email, to)
|
2014-07-31 04:46:02 -04:00
|
|
|
}
|
|
|
|
|
2013-06-13 18:11:10 -04:00
|
|
|
let(:receiver) { Email::Receiver.new(valid_reply) }
|
2014-07-31 04:46:02 -04:00
|
|
|
let(:email_log) { EmailLog.new(reply_key: reply_key,
|
|
|
|
post_id: post.id,
|
|
|
|
topic_id: post.topic_id,
|
|
|
|
user_id: post.user_id,
|
|
|
|
post: post,
|
|
|
|
user: user,
|
|
|
|
email_type: 'test',
|
2015-12-15 18:43:05 -05:00
|
|
|
to_address: user.email
|
2014-07-31 04:46:02 -04:00
|
|
|
) }
|
2013-06-13 18:11:10 -04:00
|
|
|
let(:reply_body) {
|
|
|
|
"I could not disagree more. I am obviously biased but adventure time is the
|
|
|
|
greatest show ever created. Everyone should watch it.
|
|
|
|
|
|
|
|
- Jake out" }
|
|
|
|
|
|
|
|
describe "with an email log" do
|
|
|
|
|
2014-07-31 04:46:02 -04:00
|
|
|
it "extracts data" do
|
2015-12-15 18:43:05 -05:00
|
|
|
expect { receiver.process }.to raise_error(Email::Receiver::EmailLogNotFound)
|
2013-06-13 18:11:10 -04:00
|
|
|
|
2014-07-31 04:46:02 -04:00
|
|
|
email_log.save!
|
|
|
|
receiver.process
|
2013-06-13 18:11:10 -04:00
|
|
|
|
|
|
|
expect(receiver.body).to eq(reply_body)
|
|
|
|
expect(receiver.email_log).to eq(email_log)
|
2014-03-28 09:57:12 -04:00
|
|
|
end
|
2014-04-14 16:55:57 -04:00
|
|
|
|
2014-03-28 09:57:12 -04:00
|
|
|
end
|
|
|
|
|
2013-06-10 16:46:08 -04:00
|
|
|
end
|
|
|
|
|
2015-12-15 18:43:05 -05:00
|
|
|
describe "with a valid email from a different user" do
|
|
|
|
let(:reply_key) { SecureRandom.hex(16) }
|
|
|
|
let(:to) { SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) }
|
|
|
|
let(:user) { Fabricate(:user, email: "test@test.com", trust_level: 2)}
|
|
|
|
let(:post) { create_post(user: user) }
|
|
|
|
let!(:email_log) { EmailLog.create(reply_key: reply_key,
|
|
|
|
post_id: post.id,
|
|
|
|
topic_id: post.topic_id,
|
|
|
|
user_id: post.user_id,
|
|
|
|
post: post,
|
|
|
|
user: user,
|
|
|
|
email_type: 'test',
|
|
|
|
to_address: user.email) }
|
|
|
|
|
|
|
|
it "raises ReplyUserNotFoundError when user doesn't exist" do
|
|
|
|
reply = fill_email(fixture_file("emails/valid_reply.eml"), "unknown@user.com", to)
|
|
|
|
receiver = Email::Receiver.new(reply)
|
|
|
|
expect { receiver.process }.to raise_error(Email::Receiver::ReplyUserNotFoundError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises ReplyUserNotMatchingError when user is not matching the reply key" do
|
|
|
|
another_user = Fabricate(:user, email: "existing@user.com")
|
|
|
|
reply = fill_email(fixture_file("emails/valid_reply.eml"), another_user.email, to)
|
|
|
|
receiver = Email::Receiver.new(reply)
|
|
|
|
expect { receiver.process }.to raise_error(Email::Receiver::ReplyUserNotMatchingError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-27 07:44:21 -05:00
|
|
|
describe "processes an email to a category" do
|
2015-12-10 17:49:16 -05:00
|
|
|
let(:to) { "some@email.com" }
|
|
|
|
|
2014-02-27 07:44:21 -05:00
|
|
|
before do
|
2014-07-31 04:46:02 -04:00
|
|
|
SiteSetting.email_in = true
|
2015-12-10 17:49:16 -05:00
|
|
|
SiteSetting.email_in_min_trust = TrustLevel[4].to_s
|
2014-02-27 07:44:21 -05:00
|
|
|
end
|
|
|
|
|
2014-07-31 04:46:02 -04:00
|
|
|
it "correctly can target categories" do
|
|
|
|
Fabricate(:category, email_in_allow_strangers: false, email_in: to)
|
2014-02-27 07:44:21 -05:00
|
|
|
|
2014-07-31 04:46:02 -04:00
|
|
|
# no email in for user
|
|
|
|
expect{
|
|
|
|
process_email(from: "cobb@dob.com", to: "invalid@address.com")
|
2014-08-13 14:06:17 -04:00
|
|
|
}.to raise_error(Email::Receiver::BadDestinationAddress)
|
2014-02-27 07:44:21 -05:00
|
|
|
|
2014-07-31 04:46:02 -04:00
|
|
|
# valid target invalid user
|
|
|
|
expect{
|
|
|
|
process_email(from: "cobb@dob.com", to: to)
|
|
|
|
}.to raise_error(Email::Receiver::UserNotFoundError)
|
2014-02-27 07:44:21 -05:00
|
|
|
|
2014-07-31 04:46:02 -04:00
|
|
|
# untrusted
|
|
|
|
user = Fabricate(:user)
|
|
|
|
expect{
|
|
|
|
process_email(from: user.email, to: to)
|
|
|
|
}.to raise_error(Email::Receiver::UserNotSufficientTrustLevelError)
|
2014-02-27 07:44:21 -05:00
|
|
|
|
2014-07-31 04:46:02 -04:00
|
|
|
# trusted
|
|
|
|
user.trust_level = 4
|
|
|
|
user.save
|
2014-02-24 11:36:53 -05:00
|
|
|
|
2014-07-31 04:46:02 -04:00
|
|
|
process_email(from: user.email, to: to)
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(user.posts.count).to eq(1)
|
2014-02-24 11:36:53 -05:00
|
|
|
|
2014-07-31 04:46:02 -04:00
|
|
|
# email too short
|
|
|
|
message = nil
|
|
|
|
begin
|
|
|
|
process_email(from: user.email, to: to, body: "x", subject: "this is my new topic title")
|
|
|
|
rescue Email::Receiver::InvalidPost => e
|
|
|
|
message = e.message
|
2014-02-24 11:36:53 -05:00
|
|
|
end
|
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(e.message).to include("too short")
|
2014-02-24 11:36:53 -05:00
|
|
|
end
|
|
|
|
|
2015-04-10 05:29:45 -04:00
|
|
|
|
|
|
|
it "blocks user in restricted group from creating topic" do
|
|
|
|
to = "some@email.com"
|
|
|
|
|
|
|
|
restricted_user = Fabricate(:user, trust_level: 4)
|
|
|
|
restricted_group = Fabricate(:group)
|
|
|
|
restricted_group.add(restricted_user)
|
|
|
|
restricted_group.save
|
|
|
|
|
|
|
|
category = Fabricate(:category, email_in_allow_strangers: false, email_in: to)
|
|
|
|
category.set_permissions(restricted_group => :readonly)
|
|
|
|
category.save
|
|
|
|
|
|
|
|
expect{
|
|
|
|
process_email(from: restricted_user.email, to: to)
|
|
|
|
}.to raise_error(Discourse::InvalidAccess)
|
|
|
|
end
|
|
|
|
|
2014-02-24 11:36:53 -05:00
|
|
|
end
|
2013-06-13 18:11:10 -04:00
|
|
|
|
2014-02-27 10:36:33 -05:00
|
|
|
describe "processes an unknown email sender to category" do
|
2015-12-07 11:01:08 -05:00
|
|
|
let(:email_in) { "bob@bob.com" }
|
|
|
|
let(:user_email) { "#{SecureRandom.hex(32)}@foobar.com" }
|
|
|
|
let(:body) { "This is a new topic created\n\ninside a category ! :)" }
|
|
|
|
|
2014-02-27 10:36:33 -05:00
|
|
|
before do
|
2014-07-31 04:46:02 -04:00
|
|
|
SiteSetting.email_in = true
|
2015-12-07 11:01:08 -05:00
|
|
|
SiteSetting.allow_staged_accounts = true
|
2014-02-27 10:36:33 -05:00
|
|
|
end
|
|
|
|
|
2014-07-31 04:46:02 -04:00
|
|
|
it "rejects anon email" do
|
2015-12-07 11:01:08 -05:00
|
|
|
Fabricate(:category, email_in_allow_strangers: false, email_in: email_in)
|
|
|
|
|
|
|
|
expect {
|
|
|
|
process_email(from: user_email, to: email_in, body: body)
|
|
|
|
}.to raise_error(Email::Receiver::UserNotFoundError)
|
2014-02-27 10:36:33 -05:00
|
|
|
end
|
|
|
|
|
2015-12-10 17:49:16 -05:00
|
|
|
it "creates a topic for matching category" do
|
2015-12-07 11:01:08 -05:00
|
|
|
Fabricate(:category, email_in_allow_strangers: true, email_in: email_in)
|
|
|
|
process_email(from: user_email, to: email_in, body: body)
|
|
|
|
|
|
|
|
staged_account = User.find_by_email(user_email)
|
|
|
|
expect(staged_account).to be
|
|
|
|
expect(staged_account.staged).to be(true)
|
|
|
|
expect(staged_account.posts.order(id: :desc).limit(1).pluck(:raw).first).to eq(body)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "processes an unknown email sender to group" do
|
|
|
|
let(:incoming_email) { "foo@bar.com" }
|
|
|
|
let(:user_email) { "#{SecureRandom.hex(32)}@foobar.com" }
|
|
|
|
let(:body) { "This is a message to\n\na group ;)" }
|
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.email_in = true
|
|
|
|
SiteSetting.allow_staged_accounts = true
|
|
|
|
end
|
|
|
|
|
2015-12-10 17:49:16 -05:00
|
|
|
it "creates a message for matching group" do
|
2015-12-07 11:01:08 -05:00
|
|
|
Fabricate(:group, incoming_email: incoming_email)
|
|
|
|
process_email(from: user_email, to: incoming_email, body: body)
|
2014-02-27 10:36:33 -05:00
|
|
|
|
2015-12-07 11:01:08 -05:00
|
|
|
staged_account = User.find_by_email(user_email)
|
|
|
|
expect(staged_account).to be
|
2015-12-10 17:52:20 -05:00
|
|
|
expect(staged_account.name).to eq("Jake the Dog")
|
2015-12-07 11:01:08 -05:00
|
|
|
expect(staged_account.staged).to be(true)
|
2014-02-27 10:36:33 -05:00
|
|
|
|
2015-12-07 11:01:08 -05:00
|
|
|
post = staged_account.posts.order(id: :desc).first
|
|
|
|
expect(post).to be
|
|
|
|
expect(post.raw).to eq(body)
|
|
|
|
expect(post.topic.private_message?).to eq(true)
|
2014-02-27 10:36:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-12-10 17:49:16 -05:00
|
|
|
describe "supports incoming mail in CC fields" do
|
|
|
|
|
|
|
|
let(:incoming_email) { "foo@bar.com" }
|
|
|
|
let(:user_email) { "#{SecureRandom.hex(32)}@foobar.com" }
|
|
|
|
let(:body) { "This is a message to\n\na group via CC ;)" }
|
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.email_in = true
|
|
|
|
SiteSetting.allow_staged_accounts = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a message for matching group" do
|
|
|
|
Fabricate(:group, incoming_email: incoming_email)
|
|
|
|
process_email(from: user_email, to: "some@email.com", body: body, cc: incoming_email)
|
|
|
|
|
|
|
|
staged_account = User.find_by_email(user_email)
|
|
|
|
expect(staged_account).to be
|
|
|
|
expect(staged_account.staged).to be(true)
|
|
|
|
|
|
|
|
post = staged_account.posts.order(id: :desc).first
|
|
|
|
expect(post).to be
|
|
|
|
expect(post.raw).to eq(body)
|
|
|
|
expect(post.topic.private_message?).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-06-10 16:46:08 -04:00
|
|
|
end
|