email_process_auto_response_test.rb 34 KB

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