email_process_out_of_office_test.rb 9.6 KB

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