email_process_out_of_office_test.rb 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. require 'test_helper'
  2. class EmailProcessOutOfOfficeTest < ActiveSupport::TestCase
  3. test 'process with out of office check - ms' do
  4. ticket = Ticket.create(
  5. title: 'ooo check - ms',
  6. group: Group.lookup(name: 'Users'),
  7. customer_id: 2,
  8. state: Ticket::State.lookup(name: 'closed'),
  9. priority: Ticket::Priority.lookup(name: '2 normal'),
  10. updated_by_id: 1,
  11. created_by_id: 1,
  12. )
  13. article = Ticket::Article.create(
  14. ticket_id: ticket.id,
  15. from: 'some_sender@example.com',
  16. to: 'some_recipient@example.com',
  17. subject: 'ooo check',
  18. message_id: '<20150830145601.30.608881@edenhofer.zammad.com>',
  19. body: 'some message bounce check',
  20. internal: false,
  21. sender: Ticket::Article::Sender.lookup(name: 'Agent'),
  22. type: Ticket::Article::Type.lookup(name: 'email'),
  23. updated_by_id: 1,
  24. created_by_id: 1,
  25. )
  26. travel 1.second
  27. # exchange out of office example #1
  28. email_raw_string = "From: me@example.com
  29. To: customer@example.com
  30. Subject: #{ticket.subject_build('some new subject 1')}
  31. X-MS-Has-Attach:
  32. X-Auto-Response-Suppress: All
  33. X-MS-Exchange-Inbox-Rules-Loop: aaa.bbb@example.com
  34. X-MS-TNEF-Correlator:
  35. x-olx-disclaimer: Done
  36. x-tm-as-product-ver: SMEX-11.0.0.4179-8.000.1202-21706.006
  37. x-tm-as-result: No--39.689200-0.000000-31
  38. x-tm-as-user-approved-sender: Yes
  39. x-tm-as-user-blocked-sender: No
  40. Some Text"
  41. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  42. assert_equal(true, mail['x-zammad-out-of-office'.to_sym])
  43. ticket = Ticket.find(ticket.id)
  44. assert_equal(ticket.id, ticket_p.id)
  45. assert_equal('closed', ticket.state.name)
  46. # normal follow up
  47. email_raw_string = "From: me@example.com
  48. To: customer@example.com
  49. Subject: #{ticket.subject_build('some new subject - none')}
  50. X-MS-Exchange-Inbox-Rules-Loop: aaa.bbb@example.com
  51. Some Text 2"
  52. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  53. assert_equal(false, mail['x-zammad-out-of-office'.to_sym])
  54. ticket = Ticket.find(ticket.id)
  55. assert_equal(ticket.id, ticket_p.id)
  56. assert_equal('open', ticket_p.state.name)
  57. ticket = Ticket.find(ticket.id)
  58. ticket.state = Ticket::State.lookup(name: 'closed')
  59. ticket.save
  60. # exchange out of office example #2
  61. email_raw_string = "From: me@example.com
  62. To: customer@example.com
  63. Subject: #{ticket.subject_build('some new subject 2')}
  64. X-MS-Has-Attach:
  65. X-Auto-Response-Suppress: All
  66. X-MS-Exchange-Inbox-Rules-Loop: aaa.bbb@example.com
  67. X-MS-TNEF-Correlator:
  68. x-exclaimer-md-config: 8c10826d-4052-4c5c-a8e8-e09011276827
  69. Some Text"
  70. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  71. assert_equal(true, mail['x-zammad-out-of-office'.to_sym])
  72. ticket = Ticket.find(ticket.id)
  73. assert_equal(ticket.id, ticket_p.id)
  74. assert_equal('closed', ticket.state.name)
  75. travel_back
  76. end
  77. test 'process with out of office check - zimbra' do
  78. ticket = Ticket.create(
  79. title: 'ooo check - zimbra',
  80. group: Group.lookup(name: 'Users'),
  81. customer_id: 2,
  82. state: Ticket::State.lookup(name: 'closed'),
  83. priority: Ticket::Priority.lookup(name: '2 normal'),
  84. updated_by_id: 1,
  85. created_by_id: 1,
  86. )
  87. article = Ticket::Article.create(
  88. ticket_id: ticket.id,
  89. from: 'some_sender@example.com',
  90. to: 'some_recipient@example.com',
  91. subject: 'ooo check',
  92. message_id: '<20150830145601.30.608881@edenhofer.zammad.com>',
  93. body: 'some message bounce check',
  94. internal: false,
  95. sender: Ticket::Article::Sender.lookup(name: 'Agent'),
  96. type: Ticket::Article::Type.lookup(name: 'email'),
  97. updated_by_id: 1,
  98. created_by_id: 1,
  99. )
  100. travel 1.second
  101. # exchange out of office example #1
  102. email_raw_string = "From: me@example.com
  103. To: customer@example.com
  104. Subject: #{ticket.subject_build('some new subject 1')}
  105. Auto-Submitted: auto-replied (zimbra; vacation)
  106. Precedence: bulk
  107. X-Mailer: Zimbra 7.1.3_GA_3346
  108. Some Text"
  109. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  110. assert_equal(true, mail['x-zammad-out-of-office'.to_sym])
  111. ticket = Ticket.find(ticket.id)
  112. assert_equal(ticket.id, ticket_p.id)
  113. assert_equal('closed', ticket.state.name)
  114. # normal follow up
  115. email_raw_string = "From: me@example.com
  116. To: customer@example.com
  117. Subject: #{ticket.subject_build('some new subject - none')}
  118. X-Mailer: Zimbra 7.1.3_GA_3346
  119. Some Text 2"
  120. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  121. assert_equal(false, mail['x-zammad-out-of-office'.to_sym])
  122. ticket = Ticket.find(ticket.id)
  123. assert_equal(ticket.id, ticket_p.id)
  124. assert_equal('open', ticket_p.state.name)
  125. ticket = Ticket.find(ticket.id)
  126. ticket.state = Ticket::State.lookup(name: 'closed')
  127. ticket.save
  128. # exchange out of office example #2
  129. email_raw_string = "From: me@example.com
  130. To: customer@example.com
  131. Subject: #{ticket.subject_build('some new subject 2')}
  132. Auto-Submitted: auto-replied (zimbra; vacation)
  133. Precedence: bulk
  134. X-Mailer: Zimbra 7.1.3_GA_3346
  135. Some Text"
  136. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  137. assert_equal(true, mail['x-zammad-out-of-office'.to_sym])
  138. ticket = Ticket.find(ticket.id)
  139. assert_equal(ticket.id, ticket_p.id)
  140. assert_equal('closed', ticket.state.name)
  141. travel_back
  142. end
  143. test 'process with out of office check - cloud' do
  144. ticket = Ticket.create(
  145. title: 'ooo check - cloud',
  146. group: Group.lookup(name: 'Users'),
  147. customer_id: 2,
  148. state: Ticket::State.lookup(name: 'closed'),
  149. priority: Ticket::Priority.lookup(name: '2 normal'),
  150. updated_by_id: 1,
  151. created_by_id: 1,
  152. )
  153. article = Ticket::Article.create(
  154. ticket_id: ticket.id,
  155. from: 'some_sender@example.com',
  156. to: 'some_recipient@example.com',
  157. subject: 'ooo check',
  158. message_id: '<20150830145601.30.608881@edenhofer.zammad.com>',
  159. body: 'some message bounce check',
  160. internal: false,
  161. sender: Ticket::Article::Sender.lookup(name: 'Agent'),
  162. type: Ticket::Article::Type.lookup(name: 'email'),
  163. updated_by_id: 1,
  164. created_by_id: 1,
  165. )
  166. travel 1.second
  167. # exchange out of office example #1
  168. email_raw_string = "From: me@example.com
  169. To: customer@example.com
  170. Subject: #{ticket.subject_build('some new subject 1')}
  171. Auto-submitted: auto-replied; owner-email=\"me@example.com\"
  172. Some Text"
  173. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  174. assert_equal(true, mail['x-zammad-out-of-office'.to_sym])
  175. ticket = Ticket.find(ticket.id)
  176. assert_equal(ticket.id, ticket_p.id)
  177. assert_equal('closed', ticket.state.name)
  178. # normal follow up
  179. email_raw_string = "From: me@example.com
  180. To: customer@example.com
  181. Subject: #{ticket.subject_build('some new subject - none')}
  182. Some Text 2"
  183. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  184. assert_equal(false, mail['x-zammad-out-of-office'.to_sym])
  185. ticket = Ticket.find(ticket.id)
  186. assert_equal(ticket.id, ticket_p.id)
  187. assert_equal('open', ticket_p.state.name)
  188. ticket = Ticket.find(ticket.id)
  189. ticket.state = Ticket::State.lookup(name: 'closed')
  190. ticket.save
  191. # exchange out of office example #2
  192. email_raw_string = "From: me@example.com
  193. To: customer@example.com
  194. Subject: #{ticket.subject_build('some new subject 2')}
  195. Auto-submitted: auto-replied; owner-email=\"me@example.com\"
  196. Some Text"
  197. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  198. assert_equal(true, mail['x-zammad-out-of-office'.to_sym])
  199. ticket = Ticket.find(ticket.id)
  200. assert_equal(ticket.id, ticket_p.id)
  201. assert_equal('closed', ticket.state.name)
  202. travel_back
  203. end
  204. test 'process with out of office check - gmail' do
  205. ticket = Ticket.create(
  206. title: 'ooo check - gmail',
  207. group: Group.lookup(name: 'Users'),
  208. customer_id: 2,
  209. state: Ticket::State.lookup(name: 'closed'),
  210. priority: Ticket::Priority.lookup(name: '2 normal'),
  211. updated_by_id: 1,
  212. created_by_id: 1,
  213. )
  214. article = Ticket::Article.create(
  215. ticket_id: ticket.id,
  216. from: 'some_sender@example.com',
  217. to: 'some_recipient@example.com',
  218. subject: 'ooo check',
  219. message_id: '<20150830145601.30.608881@edenhofer.zammad.com>',
  220. body: 'some message bounce check',
  221. internal: false,
  222. sender: Ticket::Article::Sender.lookup(name: 'Agent'),
  223. type: Ticket::Article::Type.lookup(name: 'email'),
  224. updated_by_id: 1,
  225. created_by_id: 1,
  226. )
  227. travel 1.second
  228. # gmail out of office example #1
  229. email_raw_string = "From: me@example.com
  230. To: customer@example.com
  231. Subject: vacation: #{ticket.subject_build('some new subject 1')}
  232. Precedence: bulk
  233. X-Autoreply: yes
  234. Auto-Submitted: auto-replied
  235. Some Text"
  236. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  237. assert_equal(true, mail['x-zammad-out-of-office'.to_sym])
  238. ticket = Ticket.find(ticket.id)
  239. assert_equal(ticket.id, ticket_p.id)
  240. assert_equal('closed', ticket.state.name)
  241. # normal follow up
  242. email_raw_string = "From: me@example.com
  243. To: customer@example.com
  244. Subject: #{ticket.subject_build('some new subject - none')}
  245. Some Text 2"
  246. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  247. assert_equal(false, mail['x-zammad-out-of-office'.to_sym])
  248. ticket = Ticket.find(ticket.id)
  249. assert_equal(ticket.id, ticket_p.id)
  250. assert_equal('open', ticket_p.state.name)
  251. travel_back
  252. end
  253. end