email_process_auto_response_test.rb 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'test_helper'
  3. class EmailProcessAutoResponseTest < ActiveSupport::TestCase
  4. test 'process auto reply check - 1' do
  5. roles = Role.where(name: 'Agent')
  6. agent1 = User.create!(
  7. login: 'ticket-auto-responder-agent1@example.com',
  8. firstname: 'AutoReponder',
  9. lastname: 'Agent1',
  10. email: 'ticket-auto-responder-agent1@example.com',
  11. password: 'agentpw',
  12. active: true,
  13. roles: roles,
  14. groups: Group.all,
  15. updated_by_id: 1,
  16. created_by_id: 1,
  17. )
  18. Trigger.create!(
  19. name: '002 auto reply',
  20. condition: {
  21. 'ticket.action' => {
  22. 'operator' => 'is',
  23. 'value' => 'create',
  24. },
  25. 'ticket.state_id' => {
  26. 'operator' => 'is',
  27. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  28. }
  29. },
  30. perform: {
  31. 'notification.email' => {
  32. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  33. 'recipient' => 'ticket_customer',
  34. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  35. },
  36. 'ticket.priority_id' => {
  37. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  38. },
  39. 'ticket.tags' => {
  40. 'operator' => 'add',
  41. 'value' => 'aa, kk, auto-reply',
  42. },
  43. },
  44. disable_notification: true,
  45. active: true,
  46. created_by_id: 1,
  47. updated_by_id: 1,
  48. )
  49. email_raw_string = "From: me@example.com
  50. To: customer@example.com
  51. Subject: some new subject
  52. Some Text"
  53. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  54. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  55. Scheduler.worker(true)
  56. assert_equal(2, article_p.ticket.articles.count)
  57. email_raw_string = "From: me@example.com
  58. To: customer@example.com
  59. Subject: some new subject
  60. X-Loop: yes
  61. Some Text"
  62. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  63. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  64. Scheduler.worker(true)
  65. assert_equal(1, article_p.ticket.articles.count)
  66. email_raw_string = "From: me@example.com
  67. To: customer@example.com
  68. Subject: some new subject
  69. Precedence: Bulk
  70. Some Text"
  71. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  72. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  73. email_raw_string = "From: me@example.com
  74. To: customer@example.com
  75. Subject: some new subject
  76. Auto-Submitted: auto-generated
  77. Some Text"
  78. Scheduler.worker(true)
  79. assert_equal(1, article_p.ticket.articles.count)
  80. _ticket_p, _article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  81. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  82. email_raw_string = "From: me@example.com
  83. To: customer@example.com
  84. Subject: some new subject
  85. X-Auto-Response-Suppress: All
  86. Some Text"
  87. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  88. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  89. Scheduler.worker(true)
  90. assert_equal(1, article_p.ticket.articles.count)
  91. fqdn = Setting.get('fqdn')
  92. email_raw_string = "From: me@example.com
  93. To: customer@example.com
  94. Subject: some new subject
  95. Message-ID: <1234@#{fqdn}>
  96. Some Text"
  97. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  98. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  99. Scheduler.worker(true)
  100. assert_equal(1, article_p.ticket.articles.count)
  101. fqdn = Setting.get('fqdn')
  102. email_raw_string = "From: me@example.com
  103. To: customer@example.com
  104. Subject: some new subject
  105. Message-ID: <1234@not_matching.#{fqdn}>
  106. Some Text"
  107. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  108. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  109. Scheduler.worker(true)
  110. assert_equal(2, article_p.ticket.articles.count)
  111. email_raw_string = "Return-Path: <XX@XX.XX>
  112. X-Original-To: sales@znuny.com
  113. Received: from mail-qk0-f170.example.com (mail-qk0-f170.example.com [209.1.1.1])
  114. by arber.znuny.com (Postfix) with ESMTPS id C3AED5FE2E
  115. for <sales@znuny.com>; Mon, 22 Aug 2016 19:03:15 +0200 (CEST)
  116. Received: by mail-qk0-f170.example.com with SMTP id t7so87721720qkh.1
  117. for <sales@znuny.com>; Mon, 22 Aug 2016 10:03:15 -0700 (PDT)
  118. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
  119. d=XX.XX; s=example;
  120. h=to:from:date:message-id:subject:mime-version:precedence
  121. :auto-submitted:content-transfer-encoding:content-disposition;
  122. bh=SL5tTVvGdxsKjLic38irxzlP439P3jixJH0QTG1HJ5I=;
  123. b=CIk3PLELgjOCagyiFFbd6rlb8ZRDGYRUrg5Dntxa7e5X+PT4cgL+IE13N9TFkK8ZUJ
  124. GohlaPLGiBymIYLTtYMKUpcf22oiX8ZgGiSu1aEMC1Gsa1ZDf+vpy4kd4+7EecRT3IWF
  125. 4RafQxeaqe67budhQpO1Z6UAel6BdJj0xguKM=
  126. X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
  127. d=1e100.net; s=20130820;
  128. h=x-gm-message-state:to:from:date:message-id:subject:mime-version
  129. :precedence:auto-submitted:content-transfer-encoding
  130. :content-disposition;
  131. bh=SL5tTVvGdxsKjLic38irxzlP439P3jixJH0QTG1HJ5I=;
  132. b=PYULo3xigc4O/cuNZ79OathQ5HDMFWWIwUxz6CHbpXDQR5k3EPy/skJU1992hVz9Rl
  133. xiGwScBCkMqOjlxHjQSWhFJIxNtdvMk4m0bixBZ79IEvRuQa9cEbqjf6efnV58br5ftQ
  134. 2osHrtQczoSqLE/d61/o102RfQ0avVyX8XNJik0iepg8MiCY7LTOE9hrbnuDDLxgQecH
  135. rMEfkR7bafcUj1YEto5Vd7uV11cVZYx8UIQqVAVbfygv8dTSFeOzz3NyM0M41rRexfYH
  136. 79Yi5i7z/Wk6q2427wkJ3FIR1B7VQVQEmcq/Texbch+gAXPGBNPUHdg2WHt7NXGktrHL
  137. d3DA==
  138. X-Gm-Message-State: AE9vXwMCTnihGiG/tc7xNNlhFLcEK6DPp7otypJg5e4alD3xGK2R707BP29druIi/mcdNyaHg1vP5lSZ8EvrwvOF8iA0HNFhECGjBTJ40YrSJAR8E89xVwxFv/er+U3vEpqmPmt+hL4QhxK/+D2gKOcHSxku
  139. X-Received: by 10.1.1.1 with SMTP id 17mr25015996qkf.279.1471885393931;
  140. Mon, 22 Aug 2016 10:03:13 -0700 (PDT)
  141. To: sales@znuny.com
  142. From: \"XXX\" <XX@XX.XX>
  143. Date: Mon, 22 Aug 2016 10:03:13 -0700
  144. Message-ID: <CA+kqV8PH1DU+zcSx3M00Hrm_oJedRLjbgAUdoi9p0+sMwYsyUg@mail.gmail.com>
  145. Subject: XX PieroXXway - vacation response RE: Callback Request: XX XX [Ticket#1118974]
  146. MIME-Version: 1.0
  147. Precedence: bulk
  148. X-Autoreply: yes
  149. Auto-Submitted: auto-replied
  150. Content-Type: text/html; charset=UTF-8
  151. Content-Transfer-Encoding: quoted-printable
  152. Content-Disposition: inline
  153. test"
  154. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  155. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  156. Scheduler.worker(true)
  157. assert_equal(1, article_p.ticket.articles.count)
  158. # add an agent notification
  159. Trigger.create!(
  160. name: '001 additional agent notification',
  161. condition: {
  162. 'ticket.state_id' => {
  163. 'operator' => 'is',
  164. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  165. }
  166. },
  167. perform: {
  168. 'notification.email' => {
  169. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  170. 'recipient' => 'ticket_agents',
  171. 'subject' => 'New Ticket add. info (#{ticket.title})!',
  172. },
  173. 'ticket.priority_id' => {
  174. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  175. },
  176. 'ticket.tags' => {
  177. 'operator' => 'add',
  178. 'value' => 'aa, kk, agent-notification',
  179. },
  180. },
  181. disable_notification: true,
  182. active: true,
  183. created_by_id: 1,
  184. updated_by_id: 1,
  185. )
  186. email_raw_string = "From: me@example.com
  187. To: customer@example.com
  188. Subject: some new subject
  189. X-Loop: yes
  190. Some Text"
  191. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  192. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  193. Scheduler.worker(true)
  194. tags = ticket_p.tag_list
  195. assert_equal('new', ticket_p.state.name)
  196. assert_equal('3 high', ticket_p.priority.name)
  197. assert(tags.include?('aa'))
  198. assert(tags.include?('kk'))
  199. assert(tags.include?('agent-notification'))
  200. assert_equal(3, tags.count)
  201. assert_equal(2, article_p.ticket.articles.count)
  202. article_customer = article_p.ticket.articles.first
  203. assert_equal('me@example.com', article_customer.from)
  204. assert_equal('customer@example.com', article_customer.to)
  205. assert_equal('Customer', article_customer.sender.name)
  206. assert_equal('email', article_customer.type.name)
  207. article_notification = article_p.ticket.articles[1]
  208. assert_match(%r{New Ticket add. info}, article_notification.subject)
  209. assert_no_match(%r{me@example.com}, article_notification.to)
  210. assert_match(%r{#{agent1.email}}, article_notification.to)
  211. assert_equal('System', article_notification.sender.name)
  212. assert_equal('email', article_notification.type.name)
  213. Setting.set('ticket_trigger_recursive', true)
  214. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  215. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  216. Scheduler.worker(true)
  217. tags = ticket_p.tag_list
  218. assert_equal('new', ticket_p.state.name)
  219. assert_equal('3 high', ticket_p.priority.name)
  220. assert(tags.include?('aa'))
  221. assert(tags.include?('kk'))
  222. assert(tags.include?('agent-notification'))
  223. assert_equal(3, tags.count)
  224. assert_equal(2, article_p.ticket.articles.count)
  225. article_customer = article_p.ticket.articles.first
  226. assert_equal('me@example.com', article_customer.from)
  227. assert_equal('customer@example.com', article_customer.to)
  228. assert_equal('Customer', article_customer.sender.name)
  229. assert_equal('email', article_customer.type.name)
  230. article_notification = article_p.ticket.articles[1]
  231. assert_match(%r{New Ticket add. info}, article_notification.subject)
  232. assert_no_match(%r{me@example.com}, article_notification.to)
  233. assert_match(%r{#{agent1.email}}, article_notification.to)
  234. assert_equal('System', article_notification.sender.name)
  235. assert_equal('email', article_notification.type.name)
  236. Setting.set('ticket_trigger_recursive', false)
  237. email_raw_string = "From: me@example.com
  238. To: customer@example.com
  239. Subject: some new subject
  240. Some Text"
  241. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  242. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  243. Scheduler.worker(true)
  244. tags = ticket_p.tag_list
  245. assert_equal('new', ticket_p.state.name)
  246. assert_equal('3 high', ticket_p.priority.name)
  247. assert(tags.include?('aa'))
  248. assert(tags.include?('kk'))
  249. assert(tags.include?('agent-notification'))
  250. assert(tags.include?('auto-reply'))
  251. assert_equal(3, article_p.ticket.articles.count)
  252. article_customer = article_p.ticket.articles[0]
  253. assert_equal('me@example.com', article_customer.from)
  254. assert_equal('customer@example.com', article_customer.to)
  255. assert_equal('Customer', article_customer.sender.name)
  256. assert_equal('email', article_customer.type.name)
  257. article_notification = article_p.ticket.articles[1]
  258. assert_match(%r{New Ticket add. info}, article_notification.subject)
  259. assert_no_match(%r{me@example.com}, article_notification.to)
  260. assert_match(%r{#{agent1.email}}, article_notification.to)
  261. assert_equal('System', article_notification.sender.name)
  262. assert_equal('email', article_notification.type.name)
  263. article_auto_reply = article_p.ticket.articles[2]
  264. assert_match(%r{Thanks for your inquiry}, article_auto_reply.subject)
  265. assert_match(%r{me@example.com}, article_auto_reply.to)
  266. assert_equal('System', article_auto_reply.sender.name)
  267. assert_equal('email', article_auto_reply.type.name)
  268. Setting.set('ticket_trigger_recursive', true)
  269. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  270. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  271. Scheduler.worker(true)
  272. tags = ticket_p.tag_list
  273. assert_equal('new', ticket_p.state.name)
  274. assert_equal('3 high', ticket_p.priority.name)
  275. assert(tags.include?('aa'))
  276. assert(tags.include?('kk'))
  277. assert(tags.include?('agent-notification'))
  278. assert(tags.include?('auto-reply'))
  279. assert_equal(3, article_p.ticket.articles.count)
  280. article_customer = article_p.ticket.articles[0]
  281. assert_equal('me@example.com', article_customer.from)
  282. assert_equal('customer@example.com', article_customer.to)
  283. assert_equal('Customer', article_customer.sender.name)
  284. assert_equal('email', article_customer.type.name)
  285. article_notification = article_p.ticket.articles[1]
  286. assert_match(%r{New Ticket add. info}, article_notification.subject)
  287. assert_no_match(%r{me@example.com}, article_notification.to)
  288. assert_match(%r{#{agent1.email}}, article_notification.to)
  289. assert_equal('System', article_notification.sender.name)
  290. assert_equal('email', article_notification.type.name)
  291. article_auto_reply = article_p.ticket.articles[2]
  292. assert_match(%r{Thanks for your inquiry}, article_auto_reply.subject)
  293. assert_match(%r{me@example.com}, article_auto_reply.to)
  294. assert_equal('System', article_auto_reply.sender.name)
  295. assert_equal('email', article_auto_reply.type.name)
  296. end
  297. test 'process auto reply check - 2' do
  298. roles = Role.where(name: 'Agent')
  299. agent1 = User.create!(
  300. login: 'ticket-auto-responder-agent1@example.com',
  301. firstname: 'AutoReponder',
  302. lastname: 'Agent1',
  303. email: 'ticket-auto-responder-agent1@example.com',
  304. password: 'agentpw',
  305. active: true,
  306. roles: roles,
  307. groups: Group.all,
  308. updated_by_id: 1,
  309. created_by_id: 1,
  310. )
  311. Trigger.create!(
  312. name: '001 auto reply',
  313. condition: {
  314. 'ticket.action' => {
  315. 'operator' => 'is',
  316. 'value' => 'create',
  317. },
  318. 'ticket.state_id' => {
  319. 'operator' => 'is',
  320. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  321. }
  322. },
  323. perform: {
  324. 'notification.email' => {
  325. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  326. 'recipient' => 'ticket_customer',
  327. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  328. },
  329. 'ticket.priority_id' => {
  330. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  331. },
  332. 'ticket.tags' => {
  333. 'operator' => 'add',
  334. 'value' => 'aa, kk, auto-reply',
  335. },
  336. },
  337. disable_notification: true,
  338. active: true,
  339. created_by_id: 1,
  340. updated_by_id: 1,
  341. )
  342. email_raw_string = "From: me@example.com
  343. To: customer@example.com
  344. Subject: some new subject
  345. Some Text"
  346. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  347. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  348. Scheduler.worker(true)
  349. assert_equal(2, article_p.ticket.articles.count)
  350. email_raw_string = "From: me@example.com
  351. To: customer@example.com
  352. Subject: some new subject
  353. X-Loop: yes
  354. Some Text"
  355. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  356. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  357. Scheduler.worker(true)
  358. assert_equal(1, article_p.ticket.articles.count)
  359. email_raw_string = "From: me@example.com
  360. To: customer@example.com
  361. Subject: some new subject
  362. Precedence: Bulk
  363. Some Text"
  364. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  365. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  366. email_raw_string = "From: me@example.com
  367. To: customer@example.com
  368. Subject: some new subject
  369. Auto-Submitted: auto-generated
  370. Some Text"
  371. Scheduler.worker(true)
  372. assert_equal(1, article_p.ticket.articles.count)
  373. _ticket_p, _article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  374. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  375. email_raw_string = "From: me@example.com
  376. To: customer@example.com
  377. Subject: some new subject
  378. X-Auto-Response-Suppress: All
  379. Some Text"
  380. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  381. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  382. Scheduler.worker(true)
  383. assert_equal(1, article_p.ticket.articles.count)
  384. fqdn = Setting.get('fqdn')
  385. email_raw_string = "From: me@example.com
  386. To: customer@example.com
  387. Subject: some new subject
  388. Message-ID: <1234@#{fqdn}>
  389. Some Text"
  390. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  391. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  392. Scheduler.worker(true)
  393. assert_equal(1, article_p.ticket.articles.count)
  394. fqdn = Setting.get('fqdn')
  395. email_raw_string = "From: me@example.com
  396. To: customer@example.com
  397. Subject: some new subject
  398. Message-ID: <1234@not_matching.#{fqdn}>
  399. Some Text"
  400. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  401. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  402. Scheduler.worker(true)
  403. assert_equal(2, article_p.ticket.articles.count)
  404. email_raw_string = "Return-Path: <XX@XX.XX>
  405. X-Original-To: sales@znuny.com
  406. Received: from mail-qk0-f170.example.com (mail-qk0-f170.example.com [209.1.1.1])
  407. by arber.znuny.com (Postfix) with ESMTPS id C3AED5FE2E
  408. for <sales@znuny.com>; Mon, 22 Aug 2016 19:03:15 +0200 (CEST)
  409. Received: by mail-qk0-f170.example.com with SMTP id t7so87721720qkh.1
  410. for <sales@znuny.com>; Mon, 22 Aug 2016 10:03:15 -0700 (PDT)
  411. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
  412. d=XX.XX; s=example;
  413. h=to:from:date:message-id:subject:mime-version:precedence
  414. :auto-submitted:content-transfer-encoding:content-disposition;
  415. bh=SL5tTVvGdxsKjLic38irxzlP439P3jixJH0QTG1HJ5I=;
  416. b=CIk3PLELgjOCagyiFFbd6rlb8ZRDGYRUrg5Dntxa7e5X+PT4cgL+IE13N9TFkK8ZUJ
  417. GohlaPLGiBymIYLTtYMKUpcf22oiX8ZgGiSu1aEMC1Gsa1ZDf+vpy4kd4+7EecRT3IWF
  418. 4RafQxeaqe67budhQpO1Z6UAel6BdJj0xguKM=
  419. X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
  420. d=1e100.net; s=20130820;
  421. h=x-gm-message-state:to:from:date:message-id:subject:mime-version
  422. :precedence:auto-submitted:content-transfer-encoding
  423. :content-disposition;
  424. bh=SL5tTVvGdxsKjLic38irxzlP439P3jixJH0QTG1HJ5I=;
  425. b=PYULo3xigc4O/cuNZ79OathQ5HDMFWWIwUxz6CHbpXDQR5k3EPy/skJU1992hVz9Rl
  426. xiGwScBCkMqOjlxHjQSWhFJIxNtdvMk4m0bixBZ79IEvRuQa9cEbqjf6efnV58br5ftQ
  427. 2osHrtQczoSqLE/d61/o102RfQ0avVyX8XNJik0iepg8MiCY7LTOE9hrbnuDDLxgQecH
  428. rMEfkR7bafcUj1YEto5Vd7uV11cVZYx8UIQqVAVbfygv8dTSFeOzz3NyM0M41rRexfYH
  429. 79Yi5i7z/Wk6q2427wkJ3FIR1B7VQVQEmcq/Texbch+gAXPGBNPUHdg2WHt7NXGktrHL
  430. d3DA==
  431. X-Gm-Message-State: AE9vXwMCTnihGiG/tc7xNNlhFLcEK6DPp7otypJg5e4alD3xGK2R707BP29druIi/mcdNyaHg1vP5lSZ8EvrwvOF8iA0HNFhECGjBTJ40YrSJAR8E89xVwxFv/er+U3vEpqmPmt+hL4QhxK/+D2gKOcHSxku
  432. X-Received: by 10.1.1.1 with SMTP id 17mr25015996qkf.279.1471885393931;
  433. Mon, 22 Aug 2016 10:03:13 -0700 (PDT)
  434. To: sales@znuny.com
  435. From: \"XXX\" <XX@XX.XX>
  436. Date: Mon, 22 Aug 2016 10:03:13 -0700
  437. Message-ID: <CA+kqV8PH1DU+zcSx3M00Hrm_oJedRLjbgAUdoi9p0+sMwYsyUg@mail.gmail.com>
  438. Subject: XX PieroXXway - vacation response RE: Callback Request: XX XX [Ticket#1118974]
  439. MIME-Version: 1.0
  440. Precedence: bulk
  441. X-Autoreply: yes
  442. Auto-Submitted: auto-replied
  443. Content-Type: text/html; charset=UTF-8
  444. Content-Transfer-Encoding: quoted-printable
  445. Content-Disposition: inline
  446. test"
  447. _ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  448. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  449. Scheduler.worker(true)
  450. assert_equal(1, article_p.ticket.articles.count)
  451. # add an agent notification
  452. Trigger.create!(
  453. name: '002 additional agent notification',
  454. condition: {
  455. 'ticket.state_id' => {
  456. 'operator' => 'is',
  457. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  458. }
  459. },
  460. perform: {
  461. 'notification.email' => {
  462. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  463. 'recipient' => 'ticket_agents',
  464. 'subject' => 'New Ticket add. info (#{ticket.title})!',
  465. },
  466. 'ticket.priority_id' => {
  467. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  468. },
  469. 'ticket.tags' => {
  470. 'operator' => 'add',
  471. 'value' => 'aa, kk, agent-notification',
  472. },
  473. },
  474. disable_notification: true,
  475. active: true,
  476. created_by_id: 1,
  477. updated_by_id: 1,
  478. )
  479. email_raw_string = "From: me@example.com
  480. To: customer@example.com
  481. Subject: some new subject
  482. X-Loop: yes
  483. Some Text"
  484. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  485. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  486. Scheduler.worker(true)
  487. tags = ticket_p.tag_list
  488. assert_equal('new', ticket_p.state.name)
  489. assert_equal('3 high', ticket_p.priority.name)
  490. assert(tags.include?('aa'))
  491. assert(tags.include?('kk'))
  492. assert(tags.include?('agent-notification'))
  493. assert_equal(3, tags.count)
  494. assert_equal(2, article_p.ticket.articles.count)
  495. article_customer = article_p.ticket.articles.first
  496. assert_equal('me@example.com', article_customer.from)
  497. assert_equal('customer@example.com', article_customer.to)
  498. assert_equal('Customer', article_customer.sender.name)
  499. assert_equal('email', article_customer.type.name)
  500. article_notification = article_p.ticket.articles[1]
  501. assert_match(%r{New Ticket add. info}, article_notification.subject)
  502. assert_no_match(%r{me@example.com}, article_notification.to)
  503. assert_match(%r{#{agent1.email}}, article_notification.to)
  504. assert_equal('System', article_notification.sender.name)
  505. assert_equal('email', article_notification.type.name)
  506. Setting.set('ticket_trigger_recursive', true)
  507. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  508. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  509. Scheduler.worker(true)
  510. tags = ticket_p.tag_list
  511. assert_equal('new', ticket_p.state.name)
  512. assert_equal('3 high', ticket_p.priority.name)
  513. assert(tags.include?('aa'))
  514. assert(tags.include?('kk'))
  515. assert(tags.include?('agent-notification'))
  516. assert_equal(3, tags.count)
  517. assert_equal(2, article_p.ticket.articles.count)
  518. article_customer = article_p.ticket.articles.first
  519. assert_equal('me@example.com', article_customer.from)
  520. assert_equal('customer@example.com', article_customer.to)
  521. assert_equal('Customer', article_customer.sender.name)
  522. assert_equal('email', article_customer.type.name)
  523. article_notification = article_p.ticket.articles[1]
  524. assert_match(%r{New Ticket add. info}, article_notification.subject)
  525. assert_no_match(%r{me@example.com}, article_notification.to)
  526. assert_match(%r{#{agent1.email}}, article_notification.to)
  527. assert_equal('System', article_notification.sender.name)
  528. assert_equal('email', article_notification.type.name)
  529. Setting.set('ticket_trigger_recursive', false)
  530. email_raw_string = "From: me@example.com
  531. To: customer@example.com
  532. Subject: some new subject
  533. Some Text"
  534. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  535. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  536. Scheduler.worker(true)
  537. tags = ticket_p.tag_list
  538. assert_equal('new', ticket_p.state.name)
  539. assert_equal('3 high', ticket_p.priority.name)
  540. assert(tags.include?('aa'))
  541. assert(tags.include?('kk'))
  542. assert(tags.include?('agent-notification'))
  543. assert(tags.include?('auto-reply'))
  544. assert_equal(3, article_p.ticket.articles.count)
  545. article_customer = article_p.ticket.articles[0]
  546. assert_equal('me@example.com', article_customer.from)
  547. assert_equal('customer@example.com', article_customer.to)
  548. assert_equal('Customer', article_customer.sender.name)
  549. assert_equal('email', article_customer.type.name)
  550. article_auto_reply = article_p.ticket.articles[1]
  551. assert_match(%r{Thanks for your inquiry}, article_auto_reply.subject)
  552. assert_match(%r{me@example.com}, article_auto_reply.to)
  553. assert_equal('System', article_auto_reply.sender.name)
  554. assert_equal('email', article_auto_reply.type.name)
  555. article_notification = article_p.ticket.articles[2]
  556. assert_match(%r{New Ticket add. info}, article_notification.subject)
  557. assert_no_match(%r{me@example.com}, article_notification.to)
  558. assert_match(%r{#{agent1.email}}, article_notification.to)
  559. assert_equal('System', article_notification.sender.name)
  560. assert_equal('email', article_notification.type.name)
  561. Setting.set('ticket_trigger_recursive', true)
  562. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  563. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  564. Scheduler.worker(true)
  565. tags = ticket_p.tag_list
  566. assert_equal('new', ticket_p.state.name)
  567. assert_equal('3 high', ticket_p.priority.name)
  568. assert(tags.include?('aa'))
  569. assert(tags.include?('kk'))
  570. assert(tags.include?('agent-notification'))
  571. assert(tags.include?('auto-reply'))
  572. assert_equal(3, article_p.ticket.articles.count)
  573. article_customer = article_p.ticket.articles[0]
  574. assert_equal('me@example.com', article_customer.from)
  575. assert_equal('customer@example.com', article_customer.to)
  576. assert_equal('Customer', article_customer.sender.name)
  577. assert_equal('email', article_customer.type.name)
  578. article_auto_reply = article_p.ticket.articles[1]
  579. assert_match(%r{Thanks for your inquiry}, article_auto_reply.subject)
  580. assert_match(%r{me@example.com}, article_auto_reply.to)
  581. assert_equal('System', article_auto_reply.sender.name)
  582. assert_equal('email', article_auto_reply.type.name)
  583. article_notification = article_p.ticket.articles[2]
  584. assert_match(%r{New Ticket add. info}, article_notification.subject)
  585. assert_no_match(%r{me@example.com}, article_notification.to)
  586. assert_match(%r{#{agent1.email}}, article_notification.to)
  587. assert_equal('System', article_notification.sender.name)
  588. assert_equal('email', article_notification.type.name)
  589. end
  590. test 'process auto reply check - recursive' do
  591. roles = Role.where(name: 'Agent')
  592. agent1 = User.create!(
  593. login: 'ticket-auto-responder-agent1@example.com',
  594. firstname: 'AutoReponder',
  595. lastname: 'Agent1',
  596. email: 'ticket-auto-responder-agent1@example.com',
  597. password: 'agentpw',
  598. active: true,
  599. roles: roles,
  600. groups: Group.all,
  601. updated_by_id: 1,
  602. created_by_id: 1,
  603. )
  604. Trigger.create!(
  605. name: '001 auto reply',
  606. condition: {
  607. 'ticket.action' => {
  608. 'operator' => 'is',
  609. 'value' => 'create',
  610. },
  611. 'ticket.state_id' => {
  612. 'operator' => 'is',
  613. 'value' => Ticket::State.lookup(name: 'open').id.to_s,
  614. }
  615. },
  616. perform: {
  617. 'notification.email' => {
  618. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  619. 'recipient' => 'ticket_customer',
  620. 'subject' => 'Thanks for your inquiry (#{ticket.title})!',
  621. },
  622. 'ticket.priority_id' => {
  623. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  624. },
  625. 'ticket.tags' => {
  626. 'operator' => 'add',
  627. 'value' => 'aa, kk, auto-reply',
  628. },
  629. },
  630. disable_notification: true,
  631. active: true,
  632. created_by_id: 1,
  633. updated_by_id: 1,
  634. )
  635. # add an agent notification
  636. Trigger.create!(
  637. name: '002 additional agent notification',
  638. condition: {
  639. 'ticket.state_id' => {
  640. 'operator' => 'is',
  641. 'value' => Ticket::State.lookup(name: 'new').id.to_s,
  642. }
  643. },
  644. perform: {
  645. 'notification.email' => {
  646. 'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
  647. 'recipient' => 'ticket_agents',
  648. 'subject' => 'New Ticket add. info (#{ticket.title})!',
  649. },
  650. 'ticket.priority_id' => {
  651. 'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
  652. },
  653. 'ticket.state_id' => {
  654. 'value' => Ticket::State.lookup(name: 'open').id.to_s,
  655. },
  656. 'ticket.tags' => {
  657. 'operator' => 'add',
  658. 'value' => 'aa, kk, agent-notification',
  659. },
  660. },
  661. disable_notification: true,
  662. active: true,
  663. created_by_id: 1,
  664. updated_by_id: 1,
  665. )
  666. email_raw_string = "From: me@example.com
  667. To: customer@example.com
  668. Subject: some new subject
  669. X-Loop: yes
  670. Some Text"
  671. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  672. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  673. Scheduler.worker(true)
  674. tags = ticket_p.tag_list
  675. assert_equal('open', ticket_p.state.name)
  676. assert_equal('3 high', ticket_p.priority.name)
  677. assert(tags.include?('aa'))
  678. assert(tags.include?('kk'))
  679. assert(tags.include?('agent-notification'))
  680. assert_equal(3, tags.count)
  681. assert_equal(2, article_p.ticket.articles.count)
  682. article_customer = article_p.ticket.articles.first
  683. assert_equal('me@example.com', article_customer.from)
  684. assert_equal('customer@example.com', article_customer.to)
  685. assert_equal('Customer', article_customer.sender.name)
  686. assert_equal('email', article_customer.type.name)
  687. article_notification = article_p.ticket.articles[1]
  688. assert_match(%r{New Ticket add. info}, article_notification.subject)
  689. assert_no_match(%r{me@example.com}, article_notification.to)
  690. assert_match(%r{#{agent1.email}}, article_notification.to)
  691. assert_equal('System', article_notification.sender.name)
  692. assert_equal('email', article_notification.type.name)
  693. Setting.set('ticket_trigger_recursive', true)
  694. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  695. assert_equal(false, mail[:'x-zammad-send-auto-response'])
  696. Scheduler.worker(true)
  697. tags = ticket_p.tag_list
  698. assert_equal('open', ticket_p.state.name)
  699. assert_equal('3 high', ticket_p.priority.name)
  700. assert(tags.include?('aa'))
  701. assert(tags.include?('kk'))
  702. assert(tags.include?('agent-notification'))
  703. assert_equal(3, tags.count)
  704. assert_equal(2, article_p.ticket.articles.count)
  705. article_customer = article_p.ticket.articles.first
  706. assert_equal('me@example.com', article_customer.from)
  707. assert_equal('customer@example.com', article_customer.to)
  708. assert_equal('Customer', article_customer.sender.name)
  709. assert_equal('email', article_customer.type.name)
  710. article_notification = article_p.ticket.articles[1]
  711. assert_match(%r{New Ticket add. info}, article_notification.subject)
  712. assert_no_match(%r{me@example.com}, article_notification.to)
  713. assert_match(%r{#{agent1.email}}, article_notification.to)
  714. assert_equal('System', article_notification.sender.name)
  715. assert_equal('email', article_notification.type.name)
  716. Setting.set('ticket_trigger_recursive', false)
  717. email_raw_string = "From: me@example.com
  718. To: customer@example.com
  719. Subject: some new subject
  720. Some Text"
  721. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  722. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  723. Scheduler.worker(true)
  724. tags = ticket_p.tag_list
  725. assert_equal('open', ticket_p.state.name)
  726. assert_equal('3 high', ticket_p.priority.name)
  727. assert(tags.include?('aa'))
  728. assert(tags.include?('kk'))
  729. assert(tags.include?('agent-notification'))
  730. assert_equal(2, article_p.ticket.articles.count)
  731. article_customer = article_p.ticket.articles[0]
  732. assert_equal('me@example.com', article_customer.from)
  733. assert_equal('customer@example.com', article_customer.to)
  734. assert_equal('Customer', article_customer.sender.name)
  735. assert_equal('email', article_customer.type.name)
  736. article_notification = article_p.ticket.articles[1]
  737. assert_match(%r{New Ticket add. info}, article_notification.subject)
  738. assert_no_match(%r{me@example.com}, article_notification.to)
  739. assert_match(%r{#{agent1.email}}, article_notification.to)
  740. assert_equal('System', article_notification.sender.name)
  741. assert_equal('email', article_notification.type.name)
  742. Setting.set('ticket_trigger_recursive', true)
  743. ticket_p, article_p, _user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  744. assert_equal(true, mail[:'x-zammad-send-auto-response'])
  745. Scheduler.worker(true)
  746. tags = ticket_p.tag_list
  747. assert_equal('open', ticket_p.state.name)
  748. assert_equal('3 high', ticket_p.priority.name)
  749. assert(tags.include?('aa'))
  750. assert(tags.include?('kk'))
  751. assert(tags.include?('agent-notification'))
  752. assert(tags.include?('auto-reply'))
  753. assert_equal(3, article_p.ticket.articles.count)
  754. article_customer = article_p.ticket.articles[0]
  755. assert_equal('me@example.com', article_customer.from)
  756. assert_equal('customer@example.com', article_customer.to)
  757. assert_equal('Customer', article_customer.sender.name)
  758. assert_equal('email', article_customer.type.name)
  759. article_notification = article_p.ticket.articles[1]
  760. assert_match(%r{New Ticket add. info}, article_notification.subject)
  761. assert_no_match(%r{me@example.com}, article_notification.to)
  762. assert_match(%r{#{agent1.email}}, article_notification.to)
  763. assert_equal('System', article_notification.sender.name)
  764. assert_equal('email', article_notification.type.name)
  765. article_auto_reply = article_p.ticket.articles[2]
  766. assert_match(%r{Thanks for your inquiry}, article_auto_reply.subject)
  767. assert_match(%r{me@example.com}, article_auto_reply.to)
  768. assert_equal('System', article_auto_reply.sender.name)
  769. assert_equal('email', article_auto_reply.type.name)
  770. end
  771. end