Defect #12399 » receiving-mail-and-test.diff
| test/fixtures/mail_handler/gmail_with_attachment.eml | ||
|---|---|---|
|
Date: Mon, 19 Nov 2012 10:17:45 +0900
|
||
|
Message-ID: <CANBr5-U6cXMfLek5QiB2ZrBPR3vTThn9_Upvdkf3Dkod664+Xw@mail.gmail.com>
|
||
|
Subject: test
|
||
|
From: John Smith <JSmith@somenet.foo>
|
||
|
To: redmine@somenet.foo
|
||
|
Content-Type: multipart/mixed; boundary=bcaec54ee4ea84f77904cecee22e
|
||
|
|
||
|
--bcaec54ee4ea84f77904cecee22e
|
||
|
Content-Type: text/plain; charset=ISO-8859-1
|
||
|
|
||
|
test
|
||
|
|
||
|
--bcaec54ee4ea84f77904cecee22e
|
||
|
Content-Type: text/plain; charset=US-ASCII; name="=?ISO-2022-JP?B?GyRCJUYlOSVIGyhCLnR4dA==?="
|
||
|
Content-Disposition: attachment; filename="=?ISO-2022-JP?B?GyRCJUYlOSVIGyhCLnR4dA==?="
|
||
|
Content-Transfer-Encoding: base64
|
||
|
X-Attachment-Id: f_h9owndpv0
|
||
|
|
||
|
dGVzdAo=
|
||
|
--bcaec54ee4ea84f77904cecee22e--
|
||
| test/fixtures/mail_handler/thunderbird_with_attachment.eml | ||
|---|---|---|
|
Message-ID: <50AA00C6.4070108@gmail.com>
|
||
|
Date: Mon, 19 Nov 2012 18:49:58 +0900
|
||
|
From: John Smith <JSmith@somenet.foo>
|
||
|
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.15) Gecko/20101027 Fedora/3.0.10-1.fc12 Lightning/1.0b1 Thunderbird/3.0.10
|
||
|
MIME-Version: 1.0
|
||
|
To: redmine@somenet.foo
|
||
|
Subject: test
|
||
|
Content-Type: multipart/mixed;
|
||
|
boundary="------------030104060902010800050907"
|
||
|
|
||
|
This is a multi-part message in MIME format.
|
||
|
--------------030104060902010800050907
|
||
|
Content-Type: text/plain; charset=ISO-2022-JP
|
||
|
Content-Transfer-Encoding: 7bit
|
||
|
|
||
|
test
|
||
|
|
||
|
--------------030104060902010800050907
|
||
|
Content-Type: text/plain;
|
||
|
name="=?ISO-2022-JP?B?GyRCJUYlOSVIGyhCLnR4dA==?="
|
||
|
Content-Transfer-Encoding: base64
|
||
|
Content-Disposition: attachment;
|
||
|
filename*=ISO-2022-JP''%1B%24%42%25%46%25%39%25%48%1B%28%42%2E%74%78%74
|
||
|
|
||
|
dGVzdAo=
|
||
|
--------------030104060902010800050907--
|
||
| test/unit/mail_handler_test_1.rb | ||
|---|---|---|
|
# encoding: utf-8
|
||
|
require File.expand_path('../../test_helper', __FILE__)
|
||
|
class MailHandlerTest < ActiveSupport::TestCase
|
||
|
fixtures :users, :projects, :enabled_modules, :roles,
|
||
|
:members, :member_roles, :users,
|
||
|
:issues, :issue_statuses,
|
||
|
:workflows, :trackers, :projects_trackers,
|
||
|
:versions, :enumerations, :issue_categories,
|
||
|
:custom_fields, :custom_fields_trackers, :custom_fields_projects,
|
||
|
:boards, :messages
|
||
|
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
|
||
|
def setup
|
||
|
ActionMailer::Base.deliveries.clear
|
||
|
Setting.notified_events = Redmine::Notifiable.all.collect(&:name)
|
||
|
end
|
||
|
def teardown
|
||
|
Setting.clear_cache
|
||
|
end
|
||
|
def test_tb
|
||
|
issue = submit_email(
|
||
|
'thunderbird_with_attachment.eml',
|
||
|
:issue => {:project => 'ecookbook'}
|
||
|
)
|
||
|
assert_kind_of Issue, issue
|
||
|
assert_equal 1, issue.attachments.size
|
||
|
attachment = issue.attachments.first
|
||
|
assert_equal 'テスト.txt', attachment.filename
|
||
|
assert_equal 5, attachment.filesize
|
||
|
assert File.exist?(attachment.diskfile)
|
||
|
assert_equal 5, File.size(attachment.diskfile)
|
||
|
assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
|
||
|
end
|
||
|
def test_gmail
|
||
|
issue = submit_email(
|
||
|
'gmail_with_attachment.eml',
|
||
|
:issue => {:project => 'ecookbook'}
|
||
|
)
|
||
|
assert_kind_of Issue, issue
|
||
|
assert_equal 1, issue.attachments.size
|
||
|
attachment = issue.attachments.first
|
||
|
assert_equal 'テスト.txt', attachment.filename
|
||
|
assert_equal 5, attachment.filesize
|
||
|
assert File.exist?(attachment.diskfile)
|
||
|
assert_equal 5, File.size(attachment.diskfile)
|
||
|
assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest
|
||
|
end
|
||
|
private
|
||
|
def submit_email(filename, options={})
|
||
|
raw = IO.read(File.join(FIXTURES_PATH, filename))
|
||
|
yield raw if block_given?
|
||
|
MailHandler.receive(raw, options)
|
||
|
end
|
||
|
def assert_issue_created(issue)
|
||
|
assert issue.is_a?(Issue)
|
||
|
assert !issue.new_record?
|
||
|
issue.reload
|
||
|
end
|
||
|
end
|
||