email_process_reply_to_test.rb 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'test_helper'
  3. class EmailProcessReplyToTest < ActiveSupport::TestCase
  4. test 'normal processing' do
  5. Setting.set('postmaster_sender_based_on_reply_to', '')
  6. email = "From: Bob Smith <marketing_tool@example.com>
  7. To: zammad@example.com
  8. Subject: some new subject
  9. Reply-To: replay_to_customer_process1@example.com
  10. Some Text"
  11. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email)
  12. assert_equal('Customer', article_p.sender.name)
  13. assert_equal('email', article_p.type.name)
  14. assert_equal('Bob Smith <marketing_tool@example.com>', article_p.from)
  15. assert_equal('replay_to_customer_process1@example.com', article_p.reply_to)
  16. assert_equal('marketing_tool@example.com', ticket_p.customer.email)
  17. assert_equal('Bob', ticket_p.customer.firstname)
  18. assert_equal('Smith', ticket_p.customer.lastname)
  19. assert_nil(mail[:'raw-origin_from'])
  20. assert_nil(mail[:origin_from])
  21. assert_nil(mail[:origin_from_email])
  22. assert_nil(mail[:origin_from_local])
  23. assert_nil(mail[:origin_from_domain])
  24. assert_nil(mail[:origin_from_display_name])
  25. end
  26. test 'normal processing - take reply to as customer' do
  27. Setting.set('postmaster_sender_based_on_reply_to', 'as_sender_of_email')
  28. email = "From: Bob Smith <marketing_tool@example.com>
  29. To: zammad@example.com
  30. Subject: some new subject
  31. Reply-To: replay_to_customer_process2@example.com
  32. Some Text"
  33. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email)
  34. assert_equal('replay_to_customer_process2@example.com', article_p.from)
  35. assert_equal('replay_to_customer_process2@example.com', article_p.reply_to)
  36. assert_equal('replay_to_customer_process2@example.com', ticket_p.customer.email)
  37. assert_equal('', ticket_p.customer.firstname)
  38. assert_equal('', ticket_p.customer.lastname)
  39. email = "From: Bob Smith <marketing_tool@example.com>
  40. To: zammad@example.com
  41. Subject: some new subject
  42. Reply-To: Some Name <replay_to_customer_process2-1@example.com>
  43. Some Text"
  44. ticket_p, article_p, _user_p = Channel::EmailParser.new.process({}, email)
  45. assert_equal('Customer', article_p.sender.name)
  46. assert_equal('email', article_p.type.name)
  47. assert_equal('Some Name <replay_to_customer_process2-1@example.com>', article_p.from)
  48. assert_equal('Some Name <replay_to_customer_process2-1@example.com>', article_p.reply_to)
  49. assert_equal('replay_to_customer_process2-1@example.com', ticket_p.customer.email)
  50. assert_equal('Some', ticket_p.customer.firstname)
  51. assert_equal('Name', ticket_p.customer.lastname)
  52. assert_equal('Bob Smith <marketing_tool@example.com>', mail[:'raw-origin_from'].to_s)
  53. assert_equal('Bob Smith <marketing_tool@example.com>', mail[:origin_from])
  54. assert_equal('marketing_tool@example.com', mail[:origin_from_email])
  55. assert_equal('marketing_tool', mail[:origin_from_local])
  56. assert_equal('example.com', mail[:origin_from_domain])
  57. assert_equal('Bob Smith', mail[:origin_from_display_name])
  58. end
  59. test 'normal processing - take reply to as customer and use from as realname' do
  60. Setting.set('postmaster_sender_based_on_reply_to', 'as_sender_of_email_use_from_realname')
  61. email = "From: Bob Smith <marketing_tool@example.com>
  62. To: zammad@example.com
  63. Subject: some new subject
  64. Reply-To: replay_to_customer_process3@example.com
  65. Some Text"
  66. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email)
  67. assert_equal('replay_to_customer_process3@example.com', article_p.from)
  68. assert_equal('replay_to_customer_process3@example.com', article_p.reply_to)
  69. assert_equal('replay_to_customer_process3@example.com', ticket_p.customer.email)
  70. assert_equal('Bob', ticket_p.customer.firstname)
  71. assert_equal('Smith', ticket_p.customer.lastname)
  72. assert_equal('Bob Smith <marketing_tool@example.com>', mail[:'raw-origin_from'].to_s)
  73. assert_equal('Bob Smith <marketing_tool@example.com>', mail[:origin_from])
  74. assert_equal('marketing_tool@example.com', mail[:origin_from_email])
  75. assert_equal('marketing_tool', mail[:origin_from_local])
  76. assert_equal('example.com', mail[:origin_from_domain])
  77. assert_equal('Bob Smith', mail[:origin_from_display_name])
  78. email = "From: Bob Smith <marketing_tool@example.com>
  79. To: zammad@example.com
  80. Subject: some new subject
  81. Reply-To: Some Name <replay_to_customer_process3-1@example.com>
  82. Some Text"
  83. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email)
  84. assert_equal('Customer', article_p.sender.name)
  85. assert_equal('email', article_p.type.name)
  86. assert_equal('Some Name <replay_to_customer_process3-1@example.com>', article_p.from)
  87. assert_equal('Some Name <replay_to_customer_process3-1@example.com>', article_p.reply_to)
  88. assert_equal('replay_to_customer_process3-1@example.com', ticket_p.customer.email)
  89. assert_equal('Bob', ticket_p.customer.firstname)
  90. assert_equal('Smith', ticket_p.customer.lastname)
  91. assert_equal('Bob Smith <marketing_tool@example.com>', mail[:'raw-origin_from'].to_s)
  92. assert_equal('Bob Smith <marketing_tool@example.com>', mail[:origin_from])
  93. assert_equal('marketing_tool@example.com', mail[:origin_from_email])
  94. assert_equal('marketing_tool', mail[:origin_from_local])
  95. assert_equal('example.com', mail[:origin_from_domain])
  96. assert_equal('Bob Smith', mail[:origin_from_display_name])
  97. end
  98. test 'normal processing - take reply to as customer and sender is system address' do
  99. Setting.set('postmaster_sender_based_on_reply_to', 'as_sender_of_email')
  100. EmailAddress.create!(
  101. realname: 'address #1',
  102. email: 'marketing_tool@example.com',
  103. active: true,
  104. updated_by_id: 1,
  105. created_by_id: 1,
  106. )
  107. email = "From: Marketing Tool <marketing_tool@example.com>
  108. To: zammad@example.com
  109. Subject: some new subject
  110. Reply-To: replay_to_customer_process2@example.com
  111. Some Text"
  112. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email)
  113. assert_equal('Customer', article_p.sender.name)
  114. assert_equal('email', article_p.type.name)
  115. assert_equal('replay_to_customer_process2@example.com', article_p.from)
  116. assert_equal('replay_to_customer_process2@example.com', article_p.reply_to)
  117. assert_equal('replay_to_customer_process2@example.com', ticket_p.customer.email)
  118. assert_equal('', ticket_p.customer.firstname)
  119. assert_equal('', ticket_p.customer.lastname)
  120. assert_equal('Marketing Tool <marketing_tool@example.com>', mail[:'raw-origin_from'].to_s)
  121. assert_equal('Marketing Tool <marketing_tool@example.com>', mail[:origin_from])
  122. assert_equal('marketing_tool@example.com', mail[:origin_from_email])
  123. assert_equal('marketing_tool', mail[:origin_from_local])
  124. assert_equal('example.com', mail[:origin_from_domain])
  125. assert_equal('Marketing Tool', mail[:origin_from_display_name])
  126. end
  127. end