email_process_reply_to_test.rb 7.0 KB

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