Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
576209b4
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 搜索 >>
提交
576209b4
编写于
9月 09, 2018
作者:
Y
Yoshiyuki Kinjo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add `perform_deliveries` to a payload of `deliver.action_mailer` notification.
上级
383b8bc8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
41 addition
and
27 deletion
+41
-27
actionmailer/CHANGELOG.md
actionmailer/CHANGELOG.md
+5
-1
actionmailer/lib/action_mailer/base.rb
actionmailer/lib/action_mailer/base.rb
+10
-10
actionmailer/lib/action_mailer/log_subscriber.rb
actionmailer/lib/action_mailer/log_subscriber.rb
+6
-1
actionmailer/test/log_subscriber_test.rb
actionmailer/test/log_subscriber_test.rb
+6
-3
guides/source/active_support_instrumentation.md
guides/source/active_support_instrumentation.md
+14
-12
未找到文件。
actionmailer/CHANGELOG.md
浏览文件 @
576209b4
*
Skip delivery notification when
`perform_deliveries`
is false.
*
Add
`perform_deliveries`
to a payload of
`deliver.action_mailer`
notification.
*Yoshiyuki Kinjo*
*
Change delivery logging message when
`perform_deliveries`
is false.
*Yoshiyuki Kinjo*
...
...
actionmailer/lib/action_mailer/base.rb
浏览文件 @
576209b4
...
...
@@ -579,7 +579,6 @@ def receive(raw_mail)
# calling +deliver_mail+ directly and passing a <tt>Mail::Message</tt> will do
# nothing except tell the logger you sent the email.
def
deliver_mail
(
mail
)
#:nodoc:
return
unless
mail
.
perform_deliveries
ActiveSupport
::
Notifications
.
instrument
(
"deliver.action_mailer"
)
do
|
payload
|
set_payload_for_mail
(
payload
,
mail
)
yield
# Let Mail do the delivery actions
...
...
@@ -589,15 +588,16 @@ def deliver_mail(mail) #:nodoc:
private
def
set_payload_for_mail
(
payload
,
mail
)
payload
[
:mailer
]
=
name
payload
[
:message_id
]
=
mail
.
message_id
payload
[
:subject
]
=
mail
.
subject
payload
[
:to
]
=
mail
.
to
payload
[
:from
]
=
mail
.
from
payload
[
:bcc
]
=
mail
.
bcc
if
mail
.
bcc
.
present?
payload
[
:cc
]
=
mail
.
cc
if
mail
.
cc
.
present?
payload
[
:date
]
=
mail
.
date
payload
[
:mail
]
=
mail
.
encoded
payload
[
:mailer
]
=
name
payload
[
:message_id
]
=
mail
.
message_id
payload
[
:subject
]
=
mail
.
subject
payload
[
:to
]
=
mail
.
to
payload
[
:from
]
=
mail
.
from
payload
[
:bcc
]
=
mail
.
bcc
if
mail
.
bcc
.
present?
payload
[
:cc
]
=
mail
.
cc
if
mail
.
cc
.
present?
payload
[
:date
]
=
mail
.
date
payload
[
:mail
]
=
mail
.
encoded
payload
[
:perform_deliveries
]
=
mail
.
perform_deliveries
end
def
method_missing
(
method_name
,
*
args
)
...
...
actionmailer/lib/action_mailer/log_subscriber.rb
浏览文件 @
576209b4
...
...
@@ -9,8 +9,13 @@ class LogSubscriber < ActiveSupport::LogSubscriber
# An email was delivered.
def
deliver
(
event
)
info
do
perform_deliveries
=
event
.
payload
[
:perform_deliveries
]
recipients
=
Array
(
event
.
payload
[
:to
]).
join
(
", "
)
"Sent mail to
#{
recipients
}
(
#{
event
.
duration
.
round
(
1
)
}
ms)"
if
perform_deliveries
"Sent mail to
#{
recipients
}
(
#{
event
.
duration
.
round
(
1
)
}
ms)"
else
"Skipped sending mail to
#{
recipients
}
as `perform_deliveries` is false"
end
end
debug
{
event
.
payload
[
:mail
]
}
...
...
actionmailer/test/log_subscriber_test.rb
浏览文件 @
576209b4
...
...
@@ -37,13 +37,16 @@ def test_deliver_is_notified
BaseMailer
.
deliveries
.
clear
end
def
test_deliver_
is_not_notified
_when_perform_deliveries_is_false
def
test_deliver_
message
_when_perform_deliveries_is_false
BaseMailer
.
welcome_without_deliveries
.
deliver_now
wait
assert_equal
(
0
,
@logger
.
logged
(
:info
).
size
)
assert_equal
(
1
,
@logger
.
logged
(
:debug
).
size
)
assert_equal
(
1
,
@logger
.
logged
(
:info
).
size
)
assert_match
(
"Skipped sending mail to system@test.lindsaar.net as `perform_deliveries` is false"
,
@logger
.
logged
(
:info
).
first
)
assert_equal
(
2
,
@logger
.
logged
(
:debug
).
size
)
assert_match
(
/BaseMailer#welcome_without_deliveries: processed outbound mail in [\d.]+ms/
,
@logger
.
logged
(
:debug
).
first
)
assert_match
(
"Welcome"
,
@logger
.
logged
(
:debug
).
second
)
ensure
BaseMailer
.
deliveries
.
clear
end
...
...
guides/source/active_support_instrumentation.md
浏览文件 @
576209b4
...
...
@@ -319,17 +319,18 @@ Action Mailer
### deliver.action_mailer
| Key | Value |
| ------------- | -------------------------------------------- |
|
`:mailer`
| Name of the mailer class |
|
`:message_id`
| ID of the message, generated by the Mail gem |
|
`:subject`
| Subject of the mail |
|
`:to`
| To address(es) of the mail |
|
`:from`
| From address of the mail |
|
`:bcc`
| BCC addresses of the mail |
|
`:cc`
| CC addresses of the mail |
|
`:date`
| Date of the mail |
|
`:mail`
| The encoded form of the mail |
| Key | Value |
| --------------------- | ---------------------------------------------------- |
|
`:mailer`
| Name of the mailer class |
|
`:message_id`
| ID of the message, generated by the Mail gem |
|
`:subject`
| Subject of the mail |
|
`:to`
| To address(es) of the mail |
|
`:from`
| From address of the mail |
|
`:bcc`
| BCC addresses of the mail |
|
`:cc`
| CC addresses of the mail |
|
`:date`
| Date of the mail |
|
`:mail`
| The encoded form of the mail |
|
`:perform_deliveries`
| Whether delivery of this message is performed or not |
```
ruby
{
...
...
@@ -339,7 +340,8 @@ Action Mailer
to:
[
"users@rails.com"
,
"dhh@rails.com"
],
from:
[
"me@rails.com"
],
date:
Sat
,
10
Mar
2012
14
:
18
:
09
+
0100
,
mail:
"..."
# omitted for brevity
mail:
"..."
,
# omitted for brevity
perform_deliveries:
true
}
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录