Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
10c509fb
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,发现更多精彩内容 >>
提交
10c509fb
编写于
1月 20, 2010
作者:
J
José Valim and Mikel Lindsaar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Moved old API into deprecated_api.rb in preparation for new Rails 3 Mailer API
上级
8b37fee2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
208 addition
and
153 deletion
+208
-153
actionmailer/lib/action_mailer.rb
actionmailer/lib/action_mailer.rb
+1
-0
actionmailer/lib/action_mailer/adv_attr_accessor.rb
actionmailer/lib/action_mailer/adv_attr_accessor.rb
+2
-0
actionmailer/lib/action_mailer/base.rb
actionmailer/lib/action_mailer/base.rb
+3
-153
actionmailer/lib/action_mailer/deprecated_api.rb
actionmailer/lib/action_mailer/deprecated_api.rb
+163
-0
actionmailer/test/base_test.rb
actionmailer/test/base_test.rb
+39
-0
未找到文件。
actionmailer/lib/action_mailer.rb
浏览文件 @
10c509fb
...
...
@@ -34,6 +34,7 @@ module ActionMailer
autoload
:Base
autoload
:DeliveryMethods
autoload
:DeprecatedBody
autoload
:DeprecatedApi
autoload
:MailHelper
autoload
:Quoting
autoload
:TestCase
...
...
actionmailer/lib/action_mailer/adv_attr_accessor.rb
浏览文件 @
10c509fb
module
ActionMailer
module
AdvAttrAccessor
#:nodoc:
def
adv_attr_accessor
(
*
names
)
# TODO: ActiveSupport::Deprecation.warn()
names
.
each
do
|
name
|
ivar
=
"@
#{
name
}
"
...
...
actionmailer/lib/action_mailer/base.rb
浏览文件 @
10c509fb
...
...
@@ -263,9 +263,11 @@ class Base < AbstractController::Base
helper
ActionMailer
::
MailHelper
include
ActionMailer
::
DeprecatedBody
include
ActionMailer
::
DeprecatedApi
include
ActionMailer
::
DeliveryMethods
private_class_method
:new
#:nodoc:
@@raise_delivery_errors
=
true
...
...
@@ -459,41 +461,13 @@ def matches_dynamic_method?(method_name) #:nodoc:
end
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,
# 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
)
super
()
@mail
=
Mail
.
new
process
(
method_name
,
*
args
)
if
method_name
end
...
...
@@ -521,129 +495,5 @@ def deliver!(mail = @mail)
self
.
class
.
deliver
(
mail
)
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!' %>"
#
# 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
# defaults.
def
initialize_defaults
(
method_name
)
#:nodoc:
@charset
||=
@@default_charset
.
dup
@content_type
||=
@@default_content_type
.
dup
@implicit_parts_order
||=
@@default_implicit_parts_order
.
dup
@mime_version
||=
@@default_mime_version
.
dup
if
@@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
end
def
create_parts
#:nodoc:
super
# Run deprecation hooks
if
String
===
response_body
@parts
.
unshift
create_inline_part
(
response_body
)
else
self
.
class
.
template_root
.
find_all
(
@template
,
{},
@mailer_name
).
each
do
|
template
|
@parts
<<
create_inline_part
(
render_to_body
(
:_template
=>
template
),
template
.
mime_type
)
end
if
@parts
.
size
>
1
@content_type
=
"multipart/alternative"
if
@content_type
!~
/^multipart/
end
# If this is a multipart e-mail add the mime_version if it is not
# already set.
@mime_version
||=
"1.0"
if
!
@parts
.
empty?
end
end
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
create_mail
#:nodoc:
m
=
Mail
.
new
m
.
subject
,
=
quote_any_if_necessary
(
charset
,
subject
)
m
.
to
,
m
.
from
=
quote_any_address_if_necessary
(
charset
,
recipients
,
from
)
m
.
bcc
=
quote_address_if_necessary
(
bcc
,
charset
)
unless
bcc
.
nil?
m
.
cc
=
quote_address_if_necessary
(
cc
,
charset
)
unless
cc
.
nil?
m
.
reply_to
=
quote_address_if_necessary
(
reply_to
,
charset
)
unless
reply_to
.
nil?
m
.
mime_version
=
mime_version
unless
mime_version
.
nil?
m
.
date
=
sent_on
.
to_time
rescue
sent_on
if
sent_on
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
.
size
==
1
&&
@parts
.
first
.
parts
.
empty?
m
.
content_type
([
main_type
,
sub_type
,
ctype_attrs
])
m
.
body
=
@parts
.
first
.
body
.
encoded
else
@parts
.
each
do
|
p
|
m
.
add_part
(
p
)
end
m
.
body
.
set_sort_order
(
@implicit_parts_order
)
m
.
body
.
sort_parts!
if
real_content_type
=~
/multipart/
ctype_attrs
.
delete
"charset"
m
.
content_type
([
main_type
,
sub_type
,
ctype_attrs
])
end
end
m
.
content_transfer_encoding
=
'8bit'
unless
m
.
body
.
only_us_ascii?
@mail
=
m
end
def
split_content_type
(
ct
)
#:nodoc:
ct
.
to_s
.
split
(
"/"
)
end
def
parse_content_type
(
defaults
=
nil
)
#:nodoc:
if
@content_type
.
blank?
[
nil
,
{}
]
else
ctype
,
*
attrs
=
@content_type
.
split
(
/;\s*/
)
attrs
=
attrs
.
inject
({})
{
|
h
,
s
|
k
,
v
=
s
.
split
(
/\=/
,
2
);
h
[
k
]
=
v
;
h
}
[
ctype
,
{
"charset"
=>
@charset
}.
merge
(
attrs
)]
end
end
end
end
actionmailer/lib/action_mailer/deprecated_api.rb
0 → 100644
浏览文件 @
10c509fb
module
ActionMailer
# TODO Remove this module all together in Rails 3.1. Ensure that super
# hooks in ActionMailer::Base are removed as well.
#
# Moved here to allow us to add the new Mail API
module
DeprecatedApi
extend
ActionMailer
::
AdvAttrAccessor
# 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
private
def
create_mail
#:nodoc:
m
=
@mail
m
.
subject
,
=
quote_any_if_necessary
(
charset
,
subject
)
m
.
to
,
m
.
from
=
quote_any_address_if_necessary
(
charset
,
recipients
,
from
)
m
.
bcc
=
quote_address_if_necessary
(
bcc
,
charset
)
unless
bcc
.
nil?
m
.
cc
=
quote_address_if_necessary
(
cc
,
charset
)
unless
cc
.
nil?
m
.
reply_to
=
quote_address_if_necessary
(
reply_to
,
charset
)
unless
reply_to
.
nil?
m
.
mime_version
=
mime_version
unless
mime_version
.
nil?
m
.
date
=
sent_on
.
to_time
rescue
sent_on
if
sent_on
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
.
size
==
1
&&
@parts
.
first
.
parts
.
empty?
m
.
content_type
([
main_type
,
sub_type
,
ctype_attrs
])
m
.
body
=
@parts
.
first
.
body
.
encoded
else
@parts
.
each
do
|
p
|
m
.
add_part
(
p
)
end
m
.
body
.
set_sort_order
(
@implicit_parts_order
)
m
.
body
.
sort_parts!
if
real_content_type
=~
/multipart/
ctype_attrs
.
delete
"charset"
m
.
content_type
([
main_type
,
sub_type
,
ctype_attrs
])
end
end
m
.
content_transfer_encoding
=
'8bit'
unless
m
.
body
.
only_us_ascii?
@mail
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
# defaults.
def
initialize_defaults
(
method_name
)
#:nodoc:
@charset
||=
self
.
class
.
default_charset
.
dup
@content_type
||=
self
.
class
.
default_content_type
.
dup
@implicit_parts_order
||=
self
.
class
.
default_implicit_parts_order
.
dup
@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
end
def
create_parts
#:nodoc:
super
# Run deprecation hooks
if
String
===
response_body
@parts
.
unshift
create_inline_part
(
response_body
)
else
self
.
class
.
template_root
.
find_all
(
@template
,
{},
@mailer_name
).
each
do
|
template
|
@parts
<<
create_inline_part
(
render_to_body
(
:_template
=>
template
),
template
.
mime_type
)
end
if
@parts
.
size
>
1
@content_type
=
"multipart/alternative"
if
@content_type
!~
/^multipart/
end
# If this is a multipart e-mail add the mime_version if it is not
# already set.
@mime_version
||=
"1.0"
if
!
@parts
.
empty?
end
end
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
split_content_type
(
ct
)
#:nodoc:
ct
.
to_s
.
split
(
"/"
)
end
def
parse_content_type
(
defaults
=
nil
)
#:nodoc:
if
@content_type
.
blank?
[
nil
,
{}
]
else
ctype
,
*
attrs
=
@content_type
.
split
(
/;\s*/
)
attrs
=
attrs
.
inject
({})
{
|
h
,
s
|
k
,
v
=
s
.
split
(
/\=/
,
2
);
h
[
k
]
=
v
;
h
}
[
ctype
,
{
"charset"
=>
@charset
}.
merge
(
attrs
)]
end
end
end
end
\ No newline at end of file
actionmailer/test/base_test.rb
0 → 100644
浏览文件 @
10c509fb
# class Notifier < ActionMailer::Base
# delivers_from 'notifications@example.com'
#
# def welcome(user)
# @user = user # available to the view
# mail(:subject => 'Welcome!', :to => user.email_address)
# # auto renders both welcome.text.erb and welcome.html.erb
# end
#
# def goodbye(user)
# headers["Reply-To"] = 'cancelations@example.com'
# mail(:subject => 'Goodbye', :to => user.email_address) do |format|
# format.html { render "shared_template "}
# format.text # goodbye.text.erb
# end
# end
#
# def surprise(user, gift)
# attachments[gift.name] = File.read(gift.path)
# mail(:subject => 'Surprise!', :to => user.email_address) do |format|
# format.html(:charset => "ascii") # surprise.html.erb
# format.text(:transfer_encoding => "base64") # surprise.text.erb
# end
# end
#
# def special_surprise(user, gift)
# attachments[gift.name] = { :content_type => "application/x-gzip", :content => File.read(gift.path) }
# mail(:to => 'special@example.com') # subject not required
# # auto renders both special_surprise.text.erb and special_surprise.html.erb
# end
# end
#
# Notifier.welcome(user) # => returns a Mail object
# Notifier.welcome(user).deliver # => creates and sends the Mail in one step
class
BaseTest
<
ActionMailer
::
Base
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录