email_process_auto_response_test.rb 34 KB

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