Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
971f4ff8
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,发现更多精彩内容 >>
提交
971f4ff8
编写于
12月 27, 2009
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
DRY ActionMailer code.
上级
4747a9a5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
61 addition
and
60 deletion
+61
-60
actionmailer/lib/action_mailer/base.rb
actionmailer/lib/action_mailer/base.rb
+61
-60
未找到文件。
actionmailer/lib/action_mailer/base.rb
浏览文件 @
971f4ff8
...
...
@@ -346,33 +346,6 @@ class Base < AbstractController::Base
# Alias controller_path to mailer_name so render :partial in views work.
alias
:controller_path
:mailer_name
# Add a part to a multipart message, with the given content-type. The
# part itself is yielded to the block so that other properties (charset,
# body, headers, etc.) can be set on it.
def
part
(
params
)
params
=
{
:content_type
=>
params
}
if
String
===
params
if
custom_headers
=
params
.
delete
(
:headers
)
ActiveSupport
::
Deprecation
.
warn
(
'Passing custom headers with :headers => {} is deprecated. '
<<
'Please just pass in custom headers directly.'
,
caller
[
0
,
10
])
params
.
merge!
(
custom_headers
)
end
part
=
Mail
::
Part
.
new
(
params
)
yield
part
if
block_given?
@parts
<<
part
end
# Add an attachment to a multipart message. This is simply a part with the
# content-disposition set to "attachment".
def
attachment
(
params
,
&
block
)
super
# Run deprecation hooks
params
=
{
:content_type
=>
params
}
if
String
===
params
params
=
{
:content_disposition
=>
"attachment"
,
:content_transfer_encoding
=>
"base64"
}.
merge
(
params
)
part
(
params
,
&
block
)
end
class
<<
self
attr_writer
:mailer_name
...
...
@@ -453,18 +426,45 @@ def matches_dynamic_method?(method_name) #:nodoc:
superclass_delegating_reader
:delivery_method
self
.
delivery_method
=
:smtp
# Add a part to a multipart message, with the given content-type. The
# part itself is yielded to the block so that other properties (charset,
# body, headers, etc.) can be set on it.
def
part
(
params
)
params
=
{
:content_type
=>
params
}
if
String
===
params
if
custom_headers
=
params
.
delete
(
:headers
)
ActiveSupport
::
Deprecation
.
warn
(
'Passing custom headers with :headers => {} is deprecated. '
<<
'Please just pass in custom headers directly.'
,
caller
[
0
,
10
])
params
.
merge!
(
custom_headers
)
end
part
=
Mail
::
Part
.
new
(
params
)
yield
part
if
block_given?
@parts
<<
part
end
# Add an attachment to a multipart message. This is simply a part with the
# content-disposition set to "attachment".
def
attachment
(
params
,
&
block
)
super
# Run deprecation hooks
params
=
{
:content_type
=>
params
}
if
String
===
params
params
=
{
:content_disposition
=>
"attachment"
,
:content_transfer_encoding
=>
"base64"
}.
merge
(
params
)
part
(
params
,
&
block
)
end
# Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
# will be initialized according to the named method. If not, the mailer will
# remain uninitialized (useful when you only need to invoke the "receive"
# method, for instance).
def
initialize
(
method_name
=
nil
,
*
args
)
#:nodoc:
def
initialize
(
method_name
=
nil
,
*
args
)
super
()
process
(
method_name
,
*
args
)
if
method_name
end
# Process the mailer via the given +method_name+. The body will be
# rendered and a new
TMail::
Mail object created.
def
process
(
method_name
,
*
args
)
#:nodoc:
# rendered and a new Mail object created.
def
process
(
method_name
,
*
args
)
initialize_defaults
(
method_name
)
super
...
...
@@ -506,7 +506,7 @@ def deliver!(mail = @mail)
# Set up the default values for the various instance variables of this
# mailer. Subclasses may override this method to provide different
# defaults.
def
initialize_defaults
(
method_name
)
def
initialize_defaults
(
method_name
)
#:nodoc:
@charset
||=
@@default_charset
.
dup
@content_type
||=
@@default_content_type
.
dup
@implicit_parts_order
||=
@@default_implicit_parts_order
.
dup
...
...
@@ -522,24 +522,14 @@ def initialize_defaults(method_name)
super
# Run deprecation hooks
end
def
create_parts
def
create_parts
#:nodoc:
super
# Run deprecation hooks
if
String
===
response_body
@parts
.
unshift
Mail
::
Part
.
new
(
:content_type
=>
[
"text"
,
"plain"
,
{
:charset
=>
charset
}],
:content_disposition
=>
"inline"
,
:body
=>
response_body
)
@parts
.
unshift
create_inline_part
(
response_body
)
else
self
.
class
.
template_root
.
find_all
(
@template
,
{},
mailer_name
).
each
do
|
template
|
ct
=
template
.
mime_type
?
template
.
mime_type
.
to_s
:
"text/plain"
main_type
,
sub_type
=
ct
.
split
(
"/"
)
@parts
<<
Mail
::
Part
.
new
(
:content_type
=>
[
main_type
,
sub_type
,
{
:charset
=>
charset
}],
:content_disposition
=>
"inline"
,
:body
=>
render_to_body
(
:_template
=>
template
)
)
@parts
<<
create_inline_part
(
render_to_body
(
:_template
=>
template
),
template
.
mime_type
)
end
if
@parts
.
size
>
1
...
...
@@ -553,7 +543,18 @@ def create_parts
end
end
def
sort_parts
(
parts
,
order
=
[])
def
create_inline_part
(
body
,
mime_type
=
nil
)
#:nodoc:
ct
=
mime_type
||
"text/plain"
main_type
,
sub_type
=
split_content_type
(
ct
.
to_s
)
Mail
::
Part
.
new
(
:content_type
=>
[
main_type
,
sub_type
,
{
:charset
=>
charset
}],
:content_disposition
=>
"inline"
,
:body
=>
body
)
end
def
sort_parts
(
parts
,
order
=
[])
#:nodoc:
order
=
order
.
collect
{
|
s
|
s
.
downcase
}
parts
=
parts
.
sort
do
|
a
,
b
|
...
...
@@ -582,7 +583,7 @@ def sort_parts(parts, order = [])
parts
end
def
create_mail
def
create_mail
#:nodoc:
m
=
Mail
.
new
m
.
subject
,
=
quote_any_if_necessary
(
charset
,
subject
)
...
...
@@ -596,13 +597,12 @@ def create_mail
headers
.
each
{
|
k
,
v
|
m
[
k
]
=
v
}
real_content_type
,
ctype_attrs
=
parse_content_type
main_type
,
sub_type
=
split_content_type
(
real_content_type
)
if
@parts
.
empty?
main_type
,
sub_type
=
split_content_type
(
real_content_type
)
m
.
content_type
([
main_type
,
sub_type
,
ctype_attrs
])
m
.
body
=
body
elsif
@parts
.
size
==
1
&&
@parts
.
first
.
parts
.
empty?
main_type
,
sub_type
=
split_content_type
(
real_content_type
)
m
.
content_type
([
main_type
,
sub_type
,
ctype_attrs
])
m
.
body
=
@parts
.
first
.
body
.
encoded
else
...
...
@@ -612,7 +612,6 @@ def create_mail
if
real_content_type
=~
/multipart/
ctype_attrs
.
delete
"charset"
main_type
,
sub_type
=
split_content_type
(
real_content_type
)
m
.
content_type
([
main_type
,
sub_type
,
ctype_attrs
])
end
end
...
...
@@ -620,21 +619,23 @@ def create_mail
@mail
=
m
end
def
split_content_type
(
ct
)
def
split_content_type
(
ct
)
#:nodoc:
ct
.
to_s
.
split
(
"/"
)
end
def
parse_content_type
(
defaults
=
nil
)
if
content_type
.
blank?
return
defaults
?
[
defaults
.
content_type
,
{
'charset'
=>
defaults
.
charset
}
]
:
[
nil
,
{}
]
end
ctype
,
*
attrs
=
content_type
.
split
(
/;\s*/
)
attrs
=
attrs
.
inject
({})
{
|
h
,
s
|
k
,
v
=
s
.
split
(
/=/
,
2
);
h
[
k
]
=
v
;
h
}
[
ctype
,
{
"charset"
=>
charset
||
defaults
&&
defaults
.
charset
}.
merge
(
attrs
)]
def
parse_content_type
(
defaults
=
nil
)
#:nodoc:
if
content_type
.
blank?
if
defaults
[
defaults
.
content_type
,
{
'charset'
=>
defaults
.
charset
}
]
else
[
nil
,
{}
]
end
else
ctype
,
*
attrs
=
content_type
.
split
(
/;\s*/
)
attrs
=
attrs
.
inject
({})
{
|
h
,
s
|
k
,
v
=
s
.
split
(
/\=/
,
2
);
h
[
k
]
=
v
;
h
}
[
ctype
,
{
"charset"
=>
charset
||
defaults
&&
defaults
.
charset
}.
merge
(
attrs
)]
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录