Defect #17096 » mail-17096-01.diff
app/models/mailer.rb | ||
---|---|---|
34 | 34 |
'Issue-Author' => issue.author.login |
35 | 35 |
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to |
36 | 36 |
message_id issue |
37 |
references issue |
|
38 | 37 |
@author = issue.author |
39 | 38 |
@issue = issue |
40 | 39 |
@users = to_users + cc_users |
... | ... | |
398 | 397 |
end |
399 | 398 | |
400 | 399 |
if @message_id_object |
401 |
headers[:message_id] = "<#{self.class.message_id_for(@message_id_object)}>" |
|
400 |
headers[:message_id] = "<#{self.class.message_id_for(@message_id_object, @users)}>"
|
|
402 | 401 |
end |
403 | 402 |
if @references_objects |
404 |
headers[:references] = @references_objects.collect {|o| "<#{self.class.references_for(o)}>"}.join(' ') |
|
403 |
headers[:references] = |
|
404 |
@references_objects.collect {|o| "<#{self.class.references_for(o, @users)}>"}.join(' ') |
|
405 | 405 |
end |
406 | 406 | |
407 | 407 |
m = if block_given? |
... | ... | |
454 | 454 |
h.each { |k,v| headers["X-Redmine-#{k}"] = v.to_s } |
455 | 455 |
end |
456 | 456 | |
457 |
def self.token_for(object, rand=true)
|
|
457 |
def self.token_for(object, users)
|
|
458 | 458 |
timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on) |
459 | 459 |
hash = [ |
460 | 460 |
"redmine", |
461 | 461 |
"#{object.class.name.demodulize.underscore}-#{object.id}", |
462 | 462 |
timestamp.strftime("%Y%m%d%H%M%S") |
463 | 463 |
] |
464 |
if rand
|
|
465 |
hash << Redmine::Utils.random_hex(8)
|
|
464 |
if users && users.present?
|
|
465 |
hash << Digest::SHA1.hexdigest(users.sort_by{|u| u.id}.first.id.to_s)[0, 8]
|
|
466 | 466 |
end |
467 | 467 |
host = Setting.mail_from.to_s.strip.gsub(%r{^.*@|>}, '') |
468 | 468 |
host = "#{::Socket.gethostname}.redmine" if host.empty? |
... | ... | |
470 | 470 |
end |
471 | 471 | |
472 | 472 |
# Returns a Message-Id for the given object |
473 |
def self.message_id_for(object) |
|
474 |
token_for(object, true)
|
|
473 |
def self.message_id_for(object, users)
|
|
474 |
token_for(object, users)
|
|
475 | 475 |
end |
476 | 476 | |
477 | 477 |
# Returns a uniq token for a given object referenced by all notifications |
478 | 478 |
# related to this object |
479 |
def self.references_for(object) |
|
480 |
token_for(object, false)
|
|
479 |
def self.references_for(object, users)
|
|
480 |
token_for(object, users)
|
|
481 | 481 |
end |
482 | 482 | |
483 | 483 |
def message_id(object) |
test/unit/mailer_test.rb | ||
---|---|---|
245 | 245 |
Mailer.deliver_issue_add(issue) |
246 | 246 |
mail = last_email |
247 | 247 |
assert_match /^redmine\.issue-2\.20060719190421\.[a-f0-9]+@example\.net/, mail.message_id |
248 |
assert_include "redmine.issue-2.20060719190421@example.net", mail.references |
|
249 | 248 |
end |
250 | 249 | |
251 | 250 |
def test_issue_edit_message_id |
... | ... | |
255 | 254 |
Mailer.deliver_issue_edit(journal) |
256 | 255 |
mail = last_email |
257 | 256 |
assert_match /^redmine\.journal-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id |
258 |
assert_include "redmine.issue-2.20060719190421@example.net", mail.references
|
|
257 |
assert_match /^redmine\.issue-2\.20060719190421\.[a-f0-9]+@example\.net/, mail.references
|
|
259 | 258 |
assert_select_email do |
260 | 259 |
# link to the update |
261 | 260 |
assert_select "a[href=?]", |
... | ... | |
267 | 266 |
message = Message.find(1) |
268 | 267 |
Mailer.message_posted(message).deliver |
269 | 268 |
mail = last_email |
270 |
assert_match /^redmine\.message-1\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
|
|
269 |
assert_include "redmine.message-1.20070512151532@example.net", mail.message_id
|
|
271 | 270 |
assert_include "redmine.message-1.20070512151532@example.net", mail.references |
272 | 271 |
assert_select_email do |
273 | 272 |
# link to the message |
... | ... | |
281 | 280 |
message = Message.find(3) |
282 | 281 |
Mailer.message_posted(message).deliver |
283 | 282 |
mail = last_email |
284 |
assert_match /^redmine\.message-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
|
|
283 |
assert_include "redmine.message-3.20070512151802@example.net", mail.message_id
|
|
285 | 284 |
assert_include "redmine.message-1.20070512151532@example.net", mail.references |
286 | 285 |
assert_select_email do |
287 | 286 |
# link to the reply |
... | ... | |
652 | 651 | |
653 | 652 |
def test_token_for_should_strip_trailing_gt_from_address_with_full_name |
654 | 653 |
with_settings :mail_from => "Redmine Mailer<no-reply@redmine.org>" do |
655 |
assert_match /\Aredmine.issue-\d+\.\d+\.[0-9a-f]+@redmine.org\z/, Mailer.token_for(Issue.generate!) |
|
654 |
assert_match /\Aredmine.issue-\d+\.\d+\.[0-9a-f]+@redmine.org\z/, |
|
655 |
Mailer.token_for(Issue.generate!, [User.find(1)]) |
|
656 | 656 |
end |
657 | 657 |
end |
658 | 658 |