Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
343ac48f
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,发现更多精彩内容 >>
提交
343ac48f
编写于
1月 22, 2010
作者:
J
José Valim and Mikel Lindsaar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Moved deprecated_body.rb to deprecatead_api.rb
上级
8a6a2ca7
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
118 addition
and
161 deletion
+118
-161
actionmailer/lib/action_mailer.rb
actionmailer/lib/action_mailer.rb
+0
-1
actionmailer/lib/action_mailer/base.rb
actionmailer/lib/action_mailer/base.rb
+0
-61
actionmailer/lib/action_mailer/deprecated_api.rb
actionmailer/lib/action_mailer/deprecated_api.rb
+110
-31
actionmailer/lib/action_mailer/deprecated_body.rb
actionmailer/lib/action_mailer/deprecated_body.rb
+0
-53
actionmailer/lib/action_mailer/mail_helper.rb
actionmailer/lib/action_mailer/mail_helper.rb
+5
-0
actionmailer/lib/action_mailer/tmail_compat.rb
actionmailer/lib/action_mailer/tmail_compat.rb
+3
-3
actionmailer/test/mail_service_test.rb
actionmailer/test/mail_service_test.rb
+0
-12
未找到文件。
actionmailer/lib/action_mailer.rb
浏览文件 @
343ac48f
...
...
@@ -33,7 +33,6 @@ module ActionMailer
autoload
:AdvAttrAccessor
autoload
:Base
autoload
:DeliveryMethods
autoload
:DeprecatedBody
autoload
:DeprecatedApi
autoload
:MailHelper
autoload
:Quoting
...
...
actionmailer/lib/action_mailer/base.rb
浏览文件 @
343ac48f
...
...
@@ -263,7 +263,6 @@ class Base < AbstractController::Base
include
AbstractController
::
UrlFor
helper
ActionMailer
::
MailHelper
include
ActionMailer
::
DeprecatedBody
include
ActionMailer
::
DeprecatedApi
include
ActionMailer
::
DeliveryMethods
...
...
@@ -297,69 +296,11 @@ class Base < AbstractController::Base
@@default_implicit_parts_order
=
[
"text/plain"
,
"text/enriched"
,
"text/html"
]
cattr_accessor
:default_implicit_parts_order
@@protected_instance_variables
=
%w(@parts @message)
cattr_reader
:protected_instance_variables
# Specify the BCC addresses for the message
adv_attr_accessor
:bcc
# Specify the CC addresses for the message.
adv_attr_accessor
:cc
# Specify the charset to use for the message. This defaults to the
# +default_charset+ specified for ActionMailer::Base.
adv_attr_accessor
:charset
# Specify the content type for the message. This defaults to <tt>text/plain</tt>
# in most cases, but can be automatically set in some situations.
adv_attr_accessor
:content_type
# Specify the from address for the message.
adv_attr_accessor
:from
# Specify the address (if different than the "from" address) to direct
# replies to this message.
adv_attr_accessor
:reply_to
# Specify additional headers to be added to the message.
adv_attr_accessor
:headers
# Specify the order in which parts should be sorted, based on content-type.
# This defaults to the value for the +default_implicit_parts_order+.
adv_attr_accessor
:implicit_parts_order
# Defaults to "1.0", but may be explicitly given if needed.
adv_attr_accessor
:mime_version
# The recipient addresses for the message, either as a string (for a single
# address) or an array (for multiple addresses).
adv_attr_accessor
:recipients
# The date on which the message was sent. If not set (the default), the
# header will be set by the delivery agent.
adv_attr_accessor
:sent_on
# Specify the subject of the message.
adv_attr_accessor
:subject
# Specify the template name to use for current message. This is the "base"
# template name, without the extension or directory, and may be used to
# have multiple mailer methods share the same template.
adv_attr_accessor
:template
# Override the mailer name, which defaults to an inflected version of the
# mailer's class name. If you want to use a template in a non-standard
# location, you can use this to specify that location.
adv_attr_accessor
:mailer_name
# Expose the internal Mail message
attr_reader
:message
# Pass calls to headers and attachment to the Mail#Message instance
delegate
:headers
,
:attachments
,
:to
=>
:@message
# Alias controller_path to mailer_name so render :partial in views work.
alias
:controller_path
:mailer_name
class
<<
self
...
...
@@ -504,9 +445,7 @@ def initialize(method_name=nil, *args)
# rendered and a new Mail object created.
def
process
(
method_name
,
*
args
)
initialize_defaults
(
method_name
)
super
unless
@mail_was_called
# Create e-mail parts
create_parts
...
...
actionmailer/lib/action_mailer/deprecated_api.rb
浏览文件 @
343ac48f
...
...
@@ -3,8 +3,87 @@ module ActionMailer
# hooks in ActionMailer::Base are removed as well.
#
# Moved here to allow us to add the new Mail API
module
DeprecatedApi
extend
ActionMailer
::
AdvAttrAccessor
module
DeprecatedApi
#:nodoc:
extend
ActiveSupport
::
Concern
included
do
extend
ActionMailer
::
AdvAttrAccessor
@@protected_instance_variables
=
%w(@parts)
cattr_reader
:protected_instance_variables
# Specify the BCC addresses for the message
adv_attr_accessor
:bcc
# Specify the CC addresses for the message.
adv_attr_accessor
:cc
# Specify the charset to use for the message. This defaults to the
# +default_charset+ specified for ActionMailer::Base.
adv_attr_accessor
:charset
# Specify the content type for the message. This defaults to <tt>text/plain</tt>
# in most cases, but can be automatically set in some situations.
adv_attr_accessor
:content_type
# Specify the from address for the message.
adv_attr_accessor
:from
# Specify the address (if different than the "from" address) to direct
# replies to this message.
adv_attr_accessor
:reply_to
# Specify additional headers to be added to the message.
adv_attr_accessor
:headers
# Specify the order in which parts should be sorted, based on content-type.
# This defaults to the value for the +default_implicit_parts_order+.
adv_attr_accessor
:implicit_parts_order
# Defaults to "1.0", but may be explicitly given if needed.
adv_attr_accessor
:mime_version
# The recipient addresses for the message, either as a string (for a single
# address) or an array (for multiple addresses).
adv_attr_accessor
:recipients
# The date on which the message was sent. If not set (the default), the
# header will be set by the delivery agent.
adv_attr_accessor
:sent_on
# Specify the subject of the message.
adv_attr_accessor
:subject
# Specify the template name to use for current message. This is the "base"
# template name, without the extension or directory, and may be used to
# have multiple mailer methods share the same template.
adv_attr_accessor
:template
# Override the mailer name, which defaults to an inflected version of the
# mailer's class name. If you want to use a template in a non-standard
# location, you can use this to specify that location.
adv_attr_accessor
:mailer_name
# Define the body of the message. This is either a Hash (in which case it
# specifies the variables to pass to the template when it is rendered),
# or a string, in which case it specifies the actual text of the message.
adv_attr_accessor
:body
# Alias controller_path to mailer_name so render :partial in views work.
alias
:controller_path
:mailer_name
end
def
render
(
*
args
)
options
=
args
.
last
.
is_a?
(
Hash
)
?
args
.
last
:
{}
if
options
[
:body
]
ActiveSupport
::
Deprecation
.
warn
(
':body in render deprecated. Please call body '
<<
'with a hash instead'
,
caller
[
0
,
1
])
body
options
.
delete
(
:body
)
end
super
end
# 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,
...
...
@@ -13,8 +92,6 @@ 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
...
...
@@ -27,19 +104,38 @@ def part(params)
# 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
]
||=
params
.
delete
(
:data
)
||
params
.
delete
(
:body
)
if
params
[
:filename
]
params
=
normalize_file_hash
(
params
)
else
params
=
normalize_nonfile_hash
(
params
)
end
part
(
params
,
&
block
)
end
private
# Render a message but does not set it as mail body. Useful for rendering
# data for part and attachments.
#
# Examples:
#
# render_message "special_message"
# render_message :template => "special_message"
# render_message :inline => "<%= 'Hi!' %>"
#
def
render_message
(
object
)
case
object
when
String
render_to_body
(
:template
=>
object
)
else
render_to_body
(
object
)
end
end
private
def
normalize_nonfile_hash
(
params
)
content_disposition
=
"attachment;"
...
...
@@ -109,25 +205,6 @@ def create_mail #:nodoc:
@message
end
# Render a message but does not set it as mail body. Useful for rendering
# data for part and attachments.
#
# Examples:
#
# render_message "special_message"
# render_message :template => "special_message"
# render_message :inline => "<%= 'Hi!' %>"
#
# TODO Deprecate me
def
render_message
(
object
)
case
object
when
String
render_to_body
(
:template
=>
object
)
else
render_to_body
(
object
)
end
end
# Set up the default values for the various instance variables of this
# mailer. Subclasses may override this method to provide different
...
...
@@ -139,18 +216,20 @@ def initialize_defaults(method_name) #:nodoc:
@mime_version
||=
self
.
class
.
default_mime_version
.
dup
if
self
.
class
.
default_mime_version
@mailer_name
||=
self
.
class
.
mailer_name
.
dup
@delivery_method
=
self
.
class
.
delivery_method
@template
||=
method_name
@parts
||=
[]
@headers
||=
{}
@sent_on
||=
Time
.
now
super
# Run deprecation hooks
@body
||=
{}
end
def
create_parts
#:nodoc:
super
# Run deprecation hooks
if
String
===
@body
self
.
response_body
=
@body
elsif
@body
.
is_a?
(
Hash
)
&&
!
@body
.
empty?
@body
.
each
{
|
k
,
v
|
instance_variable_set
(
:"@
#{
k
}
"
,
v
)
}
end
if
String
===
response_body
@parts
.
unshift
create_inline_part
(
response_body
)
...
...
@@ -179,7 +258,7 @@ def create_inline_part(body, mime_type=nil) #:nodoc:
:body
=>
body
)
end
def
split_content_type
(
ct
)
#:nodoc:
ct
.
to_s
.
split
(
"/"
)
end
...
...
actionmailer/lib/action_mailer/deprecated_body.rb
已删除
100644 → 0
浏览文件 @
8a6a2ca7
module
ActionMailer
# TODO Remove this module all together in a next release. Ensure that super
# hooks in ActionMailer::Base are removed as well.
module
DeprecatedBody
extend
ActionMailer
::
AdvAttrAccessor
# Define the body of the message. This is either a Hash (in which case it
# specifies the variables to pass to the template when it is rendered),
# or a string, in which case it specifies the actual text of the message.
adv_attr_accessor
:body
def
initialize_defaults
(
method_name
)
@body
||=
{}
end
def
attachment
(
params
,
&
block
)
if
params
[
:data
]
ActiveSupport
::
Deprecation
.
warn
(
'attachment :data => "string" is deprecated. To set the body of an attachment '
<<
'please use :content instead, like attachment :content => "string"'
,
caller
[
0
,
10
])
params
[
:content
]
=
params
.
delete
(
:data
)
end
if
params
[
:body
]
ActiveSupport
::
Deprecation
.
warn
(
'attachment :data => "string" is deprecated. To set the body of an attachment '
<<
'please use :content instead, like attachment :content => "string"'
,
caller
[
0
,
10
])
params
[
:content
]
=
params
.
delete
(
:body
)
end
end
def
create_parts
if
String
===
@body
ActiveSupport
::
Deprecation
.
warn
(
'body(String) is deprecated. To set the body with a text '
<<
'call render(:text => "body")'
,
caller
[
0
,
10
])
self
.
response_body
=
@body
elsif
@body
.
is_a?
(
Hash
)
&&
!
@body
.
empty?
ActiveSupport
::
Deprecation
.
warn
(
'body(Hash) is deprecated. Use instance variables to define '
<<
'assigns in your view'
,
caller
[
0
,
10
])
@body
.
each
{
|
k
,
v
|
instance_variable_set
(
:"@
#{
k
}
"
,
v
)
}
end
end
def
render
(
*
args
)
options
=
args
.
last
.
is_a?
(
Hash
)
?
args
.
last
:
{}
if
options
[
:body
]
ActiveSupport
::
Deprecation
.
warn
(
':body in render deprecated. Please call body '
<<
'with a hash instead'
,
caller
[
0
,
1
])
body
options
.
delete
(
:body
)
end
super
end
end
end
actionmailer/lib/action_mailer/mail_helper.rb
浏览文件 @
343ac48f
...
...
@@ -20,5 +20,10 @@ def block_format(text)
def
mailer
#:nodoc:
@controller
end
# Access the message instance.
def
message
@message
end
end
end
actionmailer/lib/action_mailer/tmail_compat.rb
浏览文件 @
343ac48f
...
...
@@ -3,7 +3,7 @@ class Message
def
set_content_type
(
*
args
)
ActiveSupport
::
Deprecation
.
warn
(
'Message#set_content_type is deprecated, please just call '
<<
'Message#content_type with the same arguments
.
'
,
caller
[
0
,
10
])
'Message#content_type with the same arguments'
,
caller
[
0
,
10
])
content_type
(
*
args
)
end
...
...
@@ -11,7 +11,7 @@ def set_content_type(*args)
def
transfer_encoding
(
value
=
nil
)
if
value
ActiveSupport
::
Deprecation
.
warn
(
'Message#transfer_encoding is deprecated, please call '
<<
'Message#content_transfer_encoding with the same arguments
.
'
,
caller
[
0
,
10
])
'Message#content_transfer_encoding with the same arguments'
,
caller
[
0
,
10
])
content_transfer_encoding
(
value
)
else
old_transfer_encoding
...
...
@@ -20,7 +20,7 @@ def transfer_encoding(value = nil)
def
original_filename
ActiveSupport
::
Deprecation
.
warn
(
'Message#original_filename is deprecated, '
<<
'please call Message#filename
.
'
,
caller
[
0
,
10
])
'please call Message#filename'
,
caller
[
0
,
10
])
filename
end
...
...
actionmailer/test/mail_service_test.rb
浏览文件 @
343ac48f
...
...
@@ -301,13 +301,6 @@ def return_path
render
:text
=>
"testing"
end
def
body_ivar
(
recipient
)
recipients
recipient
subject
"Body as a local variable"
from
"test@example.com"
body
:body
=>
"foo"
,
:bar
=>
"baz"
end
def
subject_with_i18n
(
recipient
)
recipients
recipient
from
"system@loudthinking.com"
...
...
@@ -1080,11 +1073,6 @@ def test_return_path_with_deliver
assert_equal
"another@somewhere.test"
,
MockSMTP
.
deliveries
[
0
][
1
].
to_s
end
def
test_body_is_stored_as_an_ivar
mail
=
TestMailer
.
create_body_ivar
(
@recipient
)
assert_equal
"body: foo
\n
bar: baz"
,
mail
.
body
.
to_s
end
def
test_starttls_is_enabled_if_supported
ActionMailer
::
Base
.
delivery_settings
[
:smtp
].
merge!
(
:enable_starttls_auto
=>
true
)
MockSMTP
.
any_instance
.
expects
(
:respond_to?
).
with
(
:enable_starttls_auto
).
returns
(
true
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录