email_process_reply_to_test.rb 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 = 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. end
  19. test 'normal processing - take reply to as customer' do
  20. Setting.set('postmaster_sender_based_on_reply_to', 'as_sender_of_email')
  21. email = "From: Bob Smith <marketing_tool@example.com>
  22. To: zammad@example.com
  23. Subject: some new subject
  24. Reply-To: replay_to_customer_process2@example.com
  25. Some Text"
  26. ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email)
  27. assert_equal('replay_to_customer_process2@example.com', article_p.from)
  28. assert_equal('replay_to_customer_process2@example.com', article_p.reply_to)
  29. assert_equal('replay_to_customer_process2@example.com', ticket_p.customer.email)
  30. assert_equal('', ticket_p.customer.firstname)
  31. assert_equal('', ticket_p.customer.lastname)
  32. email = "From: Bob Smith <marketing_tool@example.com>
  33. To: zammad@example.com
  34. Subject: some new subject
  35. Reply-To: Some Name <replay_to_customer_process2-1@example.com>
  36. Some Text"
  37. ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email)
  38. assert_equal('Customer', article_p.sender.name)
  39. assert_equal('email', article_p.type.name)
  40. assert_equal('Some Name <replay_to_customer_process2-1@example.com>', article_p.from)
  41. assert_equal('Some Name <replay_to_customer_process2-1@example.com>', article_p.reply_to)
  42. assert_equal('replay_to_customer_process2-1@example.com', ticket_p.customer.email)
  43. assert_equal('Some', ticket_p.customer.firstname)
  44. assert_equal('Name', ticket_p.customer.lastname)
  45. end
  46. test 'normal processing - take reply to as customer and use from as realname' do
  47. Setting.set('postmaster_sender_based_on_reply_to', 'as_sender_of_email_use_from_realname')
  48. email = "From: Bob Smith <marketing_tool@example.com>
  49. To: zammad@example.com
  50. Subject: some new subject
  51. Reply-To: replay_to_customer_process3@example.com
  52. Some Text"
  53. ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email)
  54. assert_equal('replay_to_customer_process3@example.com', article_p.from)
  55. assert_equal('replay_to_customer_process3@example.com', article_p.reply_to)
  56. assert_equal('replay_to_customer_process3@example.com', ticket_p.customer.email)
  57. assert_equal('Bob', ticket_p.customer.firstname)
  58. assert_equal('Smith', ticket_p.customer.lastname)
  59. email = "From: Bob Smith <marketing_tool@example.com>
  60. To: zammad@example.com
  61. Subject: some new subject
  62. Reply-To: Some Name <replay_to_customer_process3-1@example.com>
  63. Some Text"
  64. ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email)
  65. assert_equal('Customer', article_p.sender.name)
  66. assert_equal('email', article_p.type.name)
  67. assert_equal('Some Name <replay_to_customer_process3-1@example.com>', article_p.from)
  68. assert_equal('Some Name <replay_to_customer_process3-1@example.com>', article_p.reply_to)
  69. assert_equal('replay_to_customer_process3-1@example.com', ticket_p.customer.email)
  70. assert_equal('Bob', ticket_p.customer.firstname)
  71. assert_equal('Smith', ticket_p.customer.lastname)
  72. end
  73. test 'normal processing - take reply to as customer and sender is system address' do
  74. Setting.set('postmaster_sender_based_on_reply_to', 'as_sender_of_email')
  75. EmailAddress.create!(
  76. realname: 'address #1',
  77. email: 'marketing_tool@example.com',
  78. active: true,
  79. updated_by_id: 1,
  80. created_by_id: 1,
  81. )
  82. email = "From: Marketing Tool <marketing_tool@example.com>
  83. To: zammad@example.com
  84. Subject: some new subject
  85. Reply-To: replay_to_customer_process2@example.com
  86. Some Text"
  87. ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email)
  88. assert_equal('Customer', article_p.sender.name)
  89. assert_equal('email', article_p.type.name)
  90. assert_equal('replay_to_customer_process2@example.com', article_p.from)
  91. assert_equal('replay_to_customer_process2@example.com', article_p.reply_to)
  92. assert_equal('replay_to_customer_process2@example.com', ticket_p.customer.email)
  93. assert_equal('', ticket_p.customer.firstname)
  94. assert_equal('', ticket_p.customer.lastname)
  95. end
  96. end