Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4af2bbc6
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4af2bbc6
编写于
1月 26, 2010
作者:
J
José Valim and Mikel Lindsaar
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of github.com:mikel/rails
上级
65899765
74a5889a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
18 deletion
+36
-18
actionmailer/lib/action_mailer/base.rb
actionmailer/lib/action_mailer/base.rb
+22
-9
actionmailer/test/base_test.rb
actionmailer/test/base_test.rb
+14
-9
未找到文件。
actionmailer/lib/action_mailer/base.rb
浏览文件 @
4af2bbc6
...
...
@@ -50,7 +50,7 @@ module ActionMailer #:nodoc:
#
# The mail method, if not passed a block, will inspect your views and send all the views with
# the same name as the method, so the above action would send the +welcome.plain.erb+ view file
# as well as the +welcome.html.erb+ view file in a +multipart/alternate+ email.
# as well as the +welcome.html.erb+ view file in a +multipart/alternat
iv
e+ email.
#
# If you want to explicitly render only certain templates, pass a block:
#
...
...
@@ -177,7 +177,7 @@ module ActionMailer #:nodoc:
#
# Which will (if it had both a <tt>.text.erb</tt> and <tt>.html.erb</tt> tempalte in the view
# directory), send a complete <tt>multipart/mixed</tt> email with two parts, the first part being
# a <tt>multipart/alternate</tt> with the text and HTML email parts inside, and the second being
# a <tt>multipart/alternat
iv
e</tt> with the text and HTML email parts inside, and the second being
# a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book with the filename
# +free_book.pdf+.
#
...
...
@@ -456,7 +456,7 @@ def attachments
# format.html { render :text => "<h1>Hello Mikel!</h1>" }
# end
#
# Which will render a <tt>multipart/alternate</tt> email with <tt>text/plain</tt> and
# Which will render a <tt>multipart/alternat
iv
e</tt> email with <tt>text/plain</tt> and
# <tt>text/html</tt> parts.
#
# The block syntax also allows you to customize the part headers if desired:
...
...
@@ -484,10 +484,11 @@ def mail(headers={}, &block)
# Render the templates and blocks
responses
,
sort_order
=
collect_responses_and_sort_order
(
headers
,
&
block
)
content_type
||=
create_parts_from_responses
(
m
,
responses
,
charset
)
create_parts_from_responses
(
m
,
responses
,
charset
)
# Tidy up content type, charset, mime version and sort order
m
.
content_type
=
content_type
m
.
content_type
=
set_content_type
(
m
,
content_type
)
m
.
charset
=
charset
m
.
mime_version
=
mime_version
sort_order
=
headers
[
:parts_order
]
||
sort_order
||
self
.
class
.
default_implicit_parts_order
.
dup
...
...
@@ -504,6 +505,20 @@ def mail(headers={}, &block)
protected
def
set_content_type
(
m
,
user_content_type
)
params
=
m
.
content_type_parameters
||
{}
case
when
user_content_type
.
present?
user_content_type
when
m
.
has_attachments?
[
"multipart"
,
"mixed"
,
params
]
when
m
.
multipart?
[
"multipart"
,
"alternative"
,
params
]
else
self
.
class
.
default_content_type
.
dup
end
end
def
default_subject
#:nodoc:
mailer_scope
=
self
.
class
.
mailer_name
.
gsub
(
'/'
,
'.'
)
I18n
.
t
(
:subject
,
:scope
=>
[
:actionmailer
,
mailer_scope
,
action_name
],
:default
=>
action_name
.
humanize
)
...
...
@@ -563,16 +578,14 @@ def create_parts_from_responses(m, responses, charset) #:nodoc:
headers
=
responses
[
0
]
headers
.
each
{
|
k
,
v
|
m
[
k
]
=
v
}
return
responses
[
0
][
:content_type
]
elsif
responses
.
size
>
1
&&
m
.
has_attachments?
elsif
responses
.
size
>
1
&&
m
.
has_attachments?
container
=
Mail
::
Part
.
new
container
.
content_type
=
"multipart/alternate"
container
.
content_type
=
"multipart/alternat
iv
e"
responses
.
each
{
|
r
|
insert_part
(
container
,
r
,
charset
)
}
m
.
add_part
(
container
)
else
responses
.
each
{
|
r
|
insert_part
(
m
,
r
,
charset
)
}
end
m
.
has_attachments?
?
"multipart/mixed"
:
"multipart/alternate"
end
def
insert_part
(
container
,
response
,
charset
)
#:nodoc:
...
...
actionmailer/test/base_test.rb
浏览文件 @
4af2bbc6
...
...
@@ -207,7 +207,7 @@ def custom_block(include_html=false)
test
"implicit multipart"
do
email
=
BaseMailer
.
implicit_multipart
.
deliver
assert_equal
(
2
,
email
.
parts
.
size
)
assert_equal
(
"multipart/alternate"
,
email
.
mime_type
)
assert_equal
(
"multipart/alternat
iv
e"
,
email
.
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"TEXT Implicit Multipart"
,
email
.
parts
[
0
].
body
.
encoded
)
assert_equal
(
"text/html"
,
email
.
parts
[
1
].
mime_type
)
...
...
@@ -230,7 +230,7 @@ def custom_block(include_html=false)
test
"implicit multipart with attachments creates nested parts"
do
email
=
BaseMailer
.
implicit_multipart
(
:attachments
=>
true
).
deliver
assert_equal
(
"application/pdf"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"multipart/alternate"
,
email
.
parts
[
1
].
mime_type
)
assert_equal
(
"multipart/alternat
iv
e"
,
email
.
parts
[
1
].
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
1
].
parts
[
0
].
mime_type
)
assert_equal
(
"TEXT Implicit Multipart"
,
email
.
parts
[
1
].
parts
[
0
].
body
.
encoded
)
assert_equal
(
"text/html"
,
email
.
parts
[
1
].
parts
[
1
].
mime_type
)
...
...
@@ -242,7 +242,7 @@ def custom_block(include_html=false)
swap
BaseMailer
,
:default_implicit_parts_order
=>
order
do
email
=
BaseMailer
.
implicit_multipart
(
:attachments
=>
true
).
deliver
assert_equal
(
"application/pdf"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"multipart/alternate"
,
email
.
parts
[
1
].
mime_type
)
assert_equal
(
"multipart/alternat
iv
e"
,
email
.
parts
[
1
].
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
1
].
parts
[
1
].
mime_type
)
assert_equal
(
"text/html"
,
email
.
parts
[
1
].
parts
[
0
].
mime_type
)
end
...
...
@@ -251,7 +251,7 @@ def custom_block(include_html=false)
test
"implicit multipart with default locale"
do
email
=
BaseMailer
.
implicit_with_locale
.
deliver
assert_equal
(
2
,
email
.
parts
.
size
)
assert_equal
(
"multipart/alternate"
,
email
.
mime_type
)
assert_equal
(
"multipart/alternat
iv
e"
,
email
.
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"Implicit with locale TEXT"
,
email
.
parts
[
0
].
body
.
encoded
)
assert_equal
(
"text/html"
,
email
.
parts
[
1
].
mime_type
)
...
...
@@ -262,7 +262,7 @@ def custom_block(include_html=false)
swap
I18n
,
:locale
=>
:pl
do
email
=
BaseMailer
.
implicit_with_locale
.
deliver
assert_equal
(
2
,
email
.
parts
.
size
)
assert_equal
(
"multipart/alternate"
,
email
.
mime_type
)
assert_equal
(
"multipart/alternat
iv
e"
,
email
.
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"Implicit with locale PL TEXT"
,
email
.
parts
[
0
].
body
.
encoded
)
assert_equal
(
"text/html"
,
email
.
parts
[
1
].
mime_type
)
...
...
@@ -294,7 +294,7 @@ def custom_block(include_html=false)
test
"explicit multipart"
do
email
=
BaseMailer
.
explicit_multipart
.
deliver
assert_equal
(
2
,
email
.
parts
.
size
)
assert_equal
(
"multipart/alternate"
,
email
.
mime_type
)
assert_equal
(
"multipart/alternat
iv
e"
,
email
.
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"TEXT Explicit Multipart"
,
email
.
parts
[
0
].
body
.
encoded
)
assert_equal
(
"text/html"
,
email
.
parts
[
1
].
mime_type
)
...
...
@@ -317,7 +317,7 @@ def custom_block(include_html=false)
test
"explicit multipart with attachments creates nested parts"
do
email
=
BaseMailer
.
explicit_multipart
(
:attachments
=>
true
).
deliver
assert_equal
(
"application/pdf"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"multipart/alternate"
,
email
.
parts
[
1
].
mime_type
)
assert_equal
(
"multipart/alternat
iv
e"
,
email
.
parts
[
1
].
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
1
].
parts
[
0
].
mime_type
)
assert_equal
(
"TEXT Explicit Multipart"
,
email
.
parts
[
1
].
parts
[
0
].
body
.
encoded
)
assert_equal
(
"text/html"
,
email
.
parts
[
1
].
parts
[
1
].
mime_type
)
...
...
@@ -327,7 +327,7 @@ def custom_block(include_html=false)
test
"explicit multipart with templates"
do
email
=
BaseMailer
.
explicit_multipart_templates
.
deliver
assert_equal
(
2
,
email
.
parts
.
size
)
assert_equal
(
"multipart/alternate"
,
email
.
mime_type
)
assert_equal
(
"multipart/alternat
iv
e"
,
email
.
mime_type
)
assert_equal
(
"text/html"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"HTML Explicit Multipart Templates"
,
email
.
parts
[
0
].
body
.
encoded
)
assert_equal
(
"text/plain"
,
email
.
parts
[
1
].
mime_type
)
...
...
@@ -337,7 +337,7 @@ def custom_block(include_html=false)
test
"explicit multipart with any"
do
email
=
BaseMailer
.
explicit_multipart_with_any
.
deliver
assert_equal
(
2
,
email
.
parts
.
size
)
assert_equal
(
"multipart/alternate"
,
email
.
mime_type
)
assert_equal
(
"multipart/alternat
iv
e"
,
email
.
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"Format with any!"
,
email
.
parts
[
0
].
body
.
encoded
)
assert_equal
(
"text/html"
,
email
.
parts
[
1
].
mime_type
)
...
...
@@ -394,6 +394,11 @@ def custom_block(include_html=false)
BaseMailer
.
expects
(
:welcome
).
returns
(
mail
)
BaseMailer
.
welcome
.
deliver
end
test
"explicit multipart should be multipart"
do
mail
=
BaseMailer
.
explicit_multipart
assert_not_nil
(
mail
.
content_type_parameters
[
:boundary
])
end
protected
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录