Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
397693a5
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
397693a5
编写于
8月 19, 2020
作者:
A
Aaron Patterson
提交者:
GitHub
8月 19, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #26445 from dracos/multiparty
Correctly wrap inline attachments.
上级
35eb8c4e
c95e9809
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
52 addition
and
1 deletion
+52
-1
actionmailer/lib/action_mailer/base.rb
actionmailer/lib/action_mailer/base.rb
+23
-1
actionmailer/test/base_test.rb
actionmailer/test/base_test.rb
+14
-0
actionmailer/test/fixtures/base_mailer/inline_and_other_attachments.html.erb
...ixtures/base_mailer/inline_and_other_attachments.html.erb
+5
-0
actionmailer/test/fixtures/base_mailer/inline_and_other_attachments.text.erb
...ixtures/base_mailer/inline_and_other_attachments.text.erb
+4
-0
actionmailer/test/mailers/base_mailer.rb
actionmailer/test/mailers/base_mailer.rb
+6
-0
未找到文件。
actionmailer/lib/action_mailer/base.rb
浏览文件 @
397693a5
...
...
@@ -842,6 +842,7 @@ def mail(headers = {}, &block)
@_mail_was_called
=
true
create_parts_from_responses
(
message
,
responses
)
wrap_inline_attachments
(
message
)
# Set up content type, reapply charset and handle parts order
message
.
content_type
=
set_content_type
(
message
,
content_type
,
headers
[
:content_type
])
...
...
@@ -871,7 +872,7 @@ def set_content_type(m, user_content_type, class_default) # :doc:
when
user_content_type
.
present?
user_content_type
when
m
.
has_attachments?
if
m
.
attachments
.
detect
(
&
:inline?
)
if
m
.
attachments
.
all?
(
&
:inline?
)
[
"multipart"
,
"related"
,
params
]
else
[
"multipart"
,
"mixed"
,
params
]
...
...
@@ -969,6 +970,27 @@ def each_template(paths, name, &block)
end
end
def
wrap_inline_attachments
(
message
)
# If we have both types of attachment, wrap all the inline attachments
# in multipart/related, but not the actual attachments
if
message
.
attachments
.
detect
(
&
:inline?
)
&&
message
.
attachments
.
detect
{
|
a
|
!
a
.
inline?
}
related
=
Mail
::
Part
.
new
related
.
content_type
=
"multipart/related"
mixed
=
[
related
]
message
.
parts
.
each
do
|
p
|
if
p
.
attachment?
&&
!
p
.
inline?
mixed
<<
p
else
related
.
add_part
(
p
)
end
end
message
.
parts
.
clear
mixed
.
each
{
|
c
|
message
.
add_part
(
c
)
}
end
end
def
create_parts_from_responses
(
m
,
responses
)
if
responses
.
size
==
1
&&
!
m
.
has_attachments?
responses
[
0
].
each
{
|
k
,
v
|
m
[
k
]
=
v
}
...
...
actionmailer/test/base_test.rb
浏览文件 @
397693a5
...
...
@@ -186,6 +186,20 @@ class BaseTest < ActiveSupport::TestCase
assert_equal
(
"logo.png"
,
email
.
parts
[
1
].
filename
)
end
test
"can embed an inline attachment and other attachments"
do
email
=
BaseMailer
.
inline_and_other_attachments
# Need to call #encoded to force the JIT sort on parts
email
.
encoded
assert_equal
(
2
,
email
.
parts
.
length
)
assert_equal
(
"multipart/mixed"
,
email
.
mime_type
)
assert_equal
(
"multipart/related"
,
email
.
parts
[
0
].
mime_type
)
assert_equal
(
"multipart/alternative"
,
email
.
parts
[
0
].
parts
[
0
].
mime_type
)
assert_equal
(
"text/plain"
,
email
.
parts
[
0
].
parts
[
0
].
parts
[
0
].
mime_type
)
assert_equal
(
"text/html"
,
email
.
parts
[
0
].
parts
[
0
].
parts
[
1
].
mime_type
)
assert_equal
(
"logo.png"
,
email
.
parts
[
0
].
parts
[
1
].
filename
)
assert_equal
(
"certificate.pdf"
,
email
.
parts
[
1
].
filename
)
end
# Defaults values
test
"uses default charset from class"
do
with_default
BaseMailer
,
charset:
"US-ASCII"
do
...
...
actionmailer/test/fixtures/base_mailer/inline_and_other_attachments.html.erb
0 → 100644
浏览文件 @
397693a5
<h1>
Inline Image
</h1>
<%=
image_tag
attachments
[
'logo.png'
].
url
%>
<p>
This is an image that is inline
</p>
\ No newline at end of file
actionmailer/test/fixtures/base_mailer/inline_and_other_attachments.text.erb
0 → 100644
浏览文件 @
397693a5
Inline Image
No image for you
actionmailer/test/mailers/base_mailer.rb
浏览文件 @
397693a5
...
...
@@ -44,6 +44,12 @@ def inline_attachment
mail
end
def
inline_and_other_attachments
attachments
.
inline
[
"logo.png"
]
=
"
\312\213\254\232
"
attachments
[
"certificate.pdf"
]
=
"This is test File content"
mail
end
def
attachment_with_content
(
hash
=
{})
attachments
[
"invoice.pdf"
]
=
"This is test File content"
mail
(
hash
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录