email_postmaster_test.rb 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  1. # rubocop:disable all
  2. require 'test_helper'
  3. class EmailPostmasterTest < ActiveSupport::TestCase
  4. test 'valid/invalid postmaster filter' do
  5. PostmasterFilter.create!(
  6. name: 'not used',
  7. match: {
  8. from: {
  9. operator: 'contains',
  10. value: 'nobody@example.com',
  11. },
  12. },
  13. perform: {
  14. 'X-Zammad-Ticket-priority' => {
  15. value: '3 high',
  16. },
  17. },
  18. channel: 'email',
  19. active: true,
  20. created_by_id: 1,
  21. updated_by_id: 1,
  22. )
  23. assert_raises(Exceptions::UnprocessableEntity) {
  24. PostmasterFilter.create!(
  25. name: 'empty filter should not work',
  26. match: {},
  27. perform: {
  28. 'X-Zammad-Ticket-priority' => {
  29. value: '3 high',
  30. },
  31. },
  32. channel: 'email',
  33. active: true,
  34. created_by_id: 1,
  35. updated_by_id: 1,
  36. )
  37. }
  38. assert_raises(Exceptions::UnprocessableEntity) {
  39. PostmasterFilter.create!(
  40. name: 'empty filter should not work',
  41. match: {
  42. from: {
  43. operator: 'contains',
  44. value: '',
  45. },
  46. },
  47. perform: {
  48. 'X-Zammad-Ticket-priority' => {
  49. value: '3 high',
  50. },
  51. },
  52. channel: 'email',
  53. active: true,
  54. created_by_id: 1,
  55. updated_by_id: 1,
  56. )
  57. }
  58. assert_raises(Exceptions::UnprocessableEntity) {
  59. PostmasterFilter.create!(
  60. name: 'invalid regex',
  61. match: {
  62. from: {
  63. operator: 'contains',
  64. value: 'regex:[]',
  65. },
  66. },
  67. perform: {
  68. 'X-Zammad-Ticket-priority' => {
  69. value: '3 high',
  70. },
  71. },
  72. channel: 'email',
  73. active: true,
  74. created_by_id: 1,
  75. updated_by_id: 1,
  76. )
  77. }
  78. assert_raises(Exceptions::UnprocessableEntity) {
  79. PostmasterFilter.create!(
  80. name: 'invalid regex',
  81. match: {
  82. from: {
  83. operator: 'contains',
  84. value: 'regex:??',
  85. },
  86. },
  87. perform: {
  88. 'X-Zammad-Ticket-priority' => {
  89. value: '3 high',
  90. },
  91. },
  92. channel: 'email',
  93. active: true,
  94. created_by_id: 1,
  95. updated_by_id: 1,
  96. )
  97. }
  98. assert_raises(Exceptions::UnprocessableEntity) {
  99. PostmasterFilter.create!(
  100. name: 'invalid regex',
  101. match: {
  102. from: {
  103. operator: 'contains',
  104. value: 'regex:*',
  105. },
  106. },
  107. perform: {
  108. 'X-Zammad-Ticket-priority' => {
  109. value: '3 high',
  110. },
  111. },
  112. channel: 'email',
  113. active: true,
  114. created_by_id: 1,
  115. updated_by_id: 1,
  116. )
  117. }
  118. PostmasterFilter.create!(
  119. name: 'use .*',
  120. match: {
  121. from: {
  122. operator: 'contains',
  123. value: '*',
  124. },
  125. },
  126. perform: {
  127. 'X-Zammad-Ticket-priority' => {
  128. value: '3 high',
  129. },
  130. },
  131. channel: 'email',
  132. active: true,
  133. created_by_id: 1,
  134. updated_by_id: 1,
  135. )
  136. end
  137. test 'process with postmaster filter with regex' do
  138. group_default = Group.lookup(name: 'Users')
  139. group1 = Group.create_if_not_exists(
  140. name: 'Test Group1',
  141. created_by_id: 1,
  142. updated_by_id: 1,
  143. )
  144. group2 = Group.create_if_not_exists(
  145. name: 'Test Group2',
  146. created_by_id: 1,
  147. updated_by_id: 1,
  148. )
  149. PostmasterFilter.destroy_all
  150. PostmasterFilter.create!(
  151. name: 'used - empty selector',
  152. match: {
  153. from: {
  154. operator: 'contains',
  155. value: 'regex:.*',
  156. },
  157. },
  158. perform: {
  159. 'X-Zammad-Ticket-group_id' => {
  160. value: group2.id,
  161. },
  162. 'X-Zammad-Ticket-priority_id' => {
  163. value: '1',
  164. },
  165. 'x-Zammad-Article-Internal' => {
  166. value: true,
  167. },
  168. },
  169. channel: 'email',
  170. active: true,
  171. created_by_id: 1,
  172. updated_by_id: 1,
  173. )
  174. data = 'From: Some Body <somebody@example.com>
  175. To: Bob <bod@example.com>
  176. Cc: any@example.com
  177. Subject: some subject - no selector
  178. Some Text'
  179. parser = Channel::EmailParser.new
  180. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  181. assert_equal('Test Group2', ticket.group.name)
  182. assert_equal('1 low', ticket.priority.name)
  183. assert_equal('some subject - no selector', ticket.title)
  184. assert_equal('Customer', article.sender.name)
  185. assert_equal('email', article.type.name)
  186. assert_equal(true, article.internal)
  187. PostmasterFilter.destroy_all
  188. PostmasterFilter.create!(
  189. name: 'used - empty selector',
  190. match: {
  191. from: {
  192. operator: 'contains',
  193. value: '*',
  194. },
  195. },
  196. perform: {
  197. 'X-Zammad-Ticket-group_id' => {
  198. value: group2.id,
  199. },
  200. 'X-Zammad-Ticket-priority_id' => {
  201. value: '1',
  202. },
  203. 'x-Zammad-Article-Internal' => {
  204. value: true,
  205. },
  206. },
  207. channel: 'email',
  208. active: true,
  209. created_by_id: 1,
  210. updated_by_id: 1,
  211. )
  212. data = 'From: Some Body <somebody@example.com>
  213. To: Bob <bod@example.com>
  214. Cc: any@example.com
  215. Subject: some subject - no selector
  216. Some Text'
  217. parser = Channel::EmailParser.new
  218. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  219. assert_equal('Test Group2', ticket.group.name)
  220. assert_equal('1 low', ticket.priority.name)
  221. assert_equal('some subject - no selector', ticket.title)
  222. assert_equal('Customer', article.sender.name)
  223. assert_equal('email', article.type.name)
  224. assert_equal(true, article.internal)
  225. PostmasterFilter.destroy_all
  226. PostmasterFilter.create!(
  227. name: 'used - empty selector',
  228. match: {
  229. subject: {
  230. operator: 'contains',
  231. value: '*me*',
  232. },
  233. },
  234. perform: {
  235. 'X-Zammad-Ticket-group_id' => {
  236. value: group2.id,
  237. },
  238. 'X-Zammad-Ticket-priority_id' => {
  239. value: '1',
  240. },
  241. 'x-Zammad-Article-Internal' => {
  242. value: true,
  243. },
  244. },
  245. channel: 'email',
  246. active: true,
  247. created_by_id: 1,
  248. updated_by_id: 1,
  249. )
  250. data = 'From: Some Body <somebody@example.com>
  251. To: Bob <bod@example.com>
  252. Cc: any@example.com
  253. Subject: *me*
  254. Some Text'
  255. parser = Channel::EmailParser.new
  256. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  257. assert_equal('Test Group2', ticket.group.name)
  258. assert_equal('1 low', ticket.priority.name)
  259. assert_equal('*me*', ticket.title)
  260. assert_equal('Customer', article.sender.name)
  261. assert_equal('email', article.type.name)
  262. assert_equal(true, article.internal)
  263. PostmasterFilter.destroy_all
  264. PostmasterFilter.create!(
  265. name: 'used - empty selector',
  266. match: {
  267. subject: {
  268. operator: 'contains not',
  269. value: '*me*',
  270. },
  271. },
  272. perform: {
  273. 'X-Zammad-Ticket-group_id' => {
  274. value: group2.id,
  275. },
  276. 'X-Zammad-Ticket-priority_id' => {
  277. value: '1',
  278. },
  279. 'x-Zammad-Article-Internal' => {
  280. value: true,
  281. },
  282. },
  283. channel: 'email',
  284. active: true,
  285. created_by_id: 1,
  286. updated_by_id: 1,
  287. )
  288. data = 'From: Some Body <somebody@example.com>
  289. To: Bob <bod@example.com>
  290. Cc: any@example.com
  291. Subject: *mo*
  292. Some Text'
  293. parser = Channel::EmailParser.new
  294. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  295. assert_equal('Test Group2', ticket.group.name)
  296. assert_equal('1 low', ticket.priority.name)
  297. assert_equal('*mo*', ticket.title)
  298. assert_equal('Customer', article.sender.name)
  299. assert_equal('email', article.type.name)
  300. assert_equal(true, article.internal)
  301. PostmasterFilter.destroy_all
  302. PostmasterFilter.create!(
  303. name: 'used - empty selector',
  304. match: {
  305. subject: {
  306. operator: 'contains not',
  307. value: '*me*',
  308. },
  309. },
  310. perform: {
  311. 'X-Zammad-Ticket-group_id' => {
  312. value: group2.id,
  313. },
  314. 'X-Zammad-Ticket-priority_id' => {
  315. value: '1',
  316. },
  317. 'x-Zammad-Article-Internal' => {
  318. value: true,
  319. },
  320. },
  321. channel: 'email',
  322. active: true,
  323. created_by_id: 1,
  324. updated_by_id: 1,
  325. )
  326. data = 'From: Some Body <somebody@example.com>
  327. To: Bob <bod@example.com>
  328. Cc: any@example.com
  329. Subject: *me*
  330. Some Text'
  331. parser = Channel::EmailParser.new
  332. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  333. assert_equal('Users', ticket.group.name)
  334. assert_equal('2 normal', ticket.priority.name)
  335. assert_equal('*me*', ticket.title)
  336. assert_equal('Customer', article.sender.name)
  337. assert_equal('email', article.type.name)
  338. assert_equal(false, article.internal)
  339. end
  340. test 'process with postmaster filter - message-id as match condition' do
  341. PostmasterFilter.create!(
  342. name: 'used - message-id',
  343. match: {
  344. 'message-id': {
  345. operator: 'contains',
  346. value: '@sombody.domain>',
  347. },
  348. },
  349. perform: {
  350. 'X-Zammad-Ticket-priority_id' => {
  351. value: '1',
  352. },
  353. 'x-Zammad-Article-Internal' => {
  354. value: true,
  355. },
  356. },
  357. channel: 'email',
  358. active: true,
  359. created_by_id: 1,
  360. updated_by_id: 1,
  361. )
  362. data = 'From: Some Body <somebody@example.com>
  363. To: Bob <bod@example.com>
  364. Cc: any@example.com
  365. Subject: *me*
  366. Message-Id: <1520781034.17887@sombody.domain>
  367. Some Text'
  368. parser = Channel::EmailParser.new
  369. ticket, article, user = parser.process({}, data)
  370. assert_equal('Users', ticket.group.name)
  371. assert_equal('1 low', ticket.priority.name)
  372. assert_equal('*me*', ticket.title)
  373. assert_equal('Customer', article.sender.name)
  374. assert_equal('email', article.type.name)
  375. assert_equal(true, article.internal)
  376. end
  377. test 'process with postmaster filter' do
  378. group_default = Group.lookup(name: 'Users')
  379. group1 = Group.create_if_not_exists(
  380. name: 'Test Group1',
  381. created_by_id: 1,
  382. updated_by_id: 1,
  383. )
  384. group2 = Group.create_if_not_exists(
  385. name: 'Test Group2',
  386. created_by_id: 1,
  387. updated_by_id: 1,
  388. )
  389. PostmasterFilter.destroy_all
  390. PostmasterFilter.create!(
  391. name: 'not used',
  392. match: {
  393. from: {
  394. operator: 'contains',
  395. value: 'nobody@example.com',
  396. },
  397. },
  398. perform: {
  399. 'X-Zammad-Ticket-priority' => {
  400. value: '3 high',
  401. },
  402. },
  403. channel: 'email',
  404. active: true,
  405. created_by_id: 1,
  406. updated_by_id: 1,
  407. )
  408. PostmasterFilter.create!(
  409. name: 'used',
  410. match: {
  411. from: {
  412. operator: 'contains',
  413. value: 'me@example.com',
  414. },
  415. },
  416. perform: {
  417. 'X-Zammad-Ticket-group_id' => {
  418. value: group1.id,
  419. },
  420. 'x-Zammad-Article-Internal' => {
  421. value: true,
  422. },
  423. },
  424. channel: 'email',
  425. active: true,
  426. created_by_id: 1,
  427. updated_by_id: 1,
  428. )
  429. PostmasterFilter.create!(
  430. name: 'used x-any-recipient',
  431. match: {
  432. 'x-any-recipient' => {
  433. operator: 'contains',
  434. value: 'any@example.com',
  435. },
  436. },
  437. perform: {
  438. 'X-Zammad-Ticket-group_id' => {
  439. value: group2.id,
  440. },
  441. 'x-Zammad-Article-Internal' => {
  442. value: true,
  443. },
  444. },
  445. channel: 'email',
  446. active: true,
  447. created_by_id: 1,
  448. updated_by_id: 1,
  449. )
  450. data = 'From: me@example.com
  451. To: customer@example.com
  452. Subject: some subject
  453. Some Text'
  454. parser = Channel::EmailParser.new
  455. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  456. assert_equal('Test Group1', ticket.group.name)
  457. assert_equal('2 normal', ticket.priority.name)
  458. assert_equal('some subject', ticket.title)
  459. assert_equal('Customer', article.sender.name)
  460. assert_equal('email', article.type.name)
  461. assert_equal(true, article.internal)
  462. data = 'From: Some Body <somebody@example.com>
  463. To: Bob <bod@example.com>
  464. Cc: any@example.com
  465. Subject: some subject
  466. Some Text'
  467. parser = Channel::EmailParser.new
  468. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  469. assert_equal('Test Group2', ticket.group.name)
  470. assert_equal('2 normal', ticket.priority.name)
  471. assert_equal('some subject', ticket.title)
  472. assert_equal('Customer', article.sender.name)
  473. assert_equal('email', article.type.name)
  474. assert_equal(true, article.internal)
  475. PostmasterFilter.create!(
  476. name: 'used x-any-recipient 2',
  477. match: {
  478. 'x-any-recipient' => {
  479. operator: 'contains not',
  480. value: 'any_not@example.com',
  481. },
  482. },
  483. perform: {
  484. 'X-Zammad-Ticket-group_id' => {
  485. value: group2.id,
  486. },
  487. 'X-Zammad-Ticket-priority_id' => {
  488. value: '1',
  489. },
  490. 'x-Zammad-Article-Internal' => {
  491. value: 'false',
  492. },
  493. },
  494. channel: 'email',
  495. active: true,
  496. created_by_id: 1,
  497. updated_by_id: 1,
  498. )
  499. data = 'From: Some Body <somebody@example.com>
  500. To: Bob <bod@example.com>
  501. Cc: any@example.com
  502. Subject: some subject2
  503. Some Text'
  504. parser = Channel::EmailParser.new
  505. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  506. assert_equal('Test Group2', ticket.group.name)
  507. assert_equal('1 low', ticket.priority.name)
  508. assert_equal('some subject2', ticket.title)
  509. assert_equal('Customer', article.sender.name)
  510. assert_equal('email', article.type.name)
  511. assert_equal(false, article.internal)
  512. PostmasterFilter.destroy_all
  513. # follow up with create post master filter test
  514. PostmasterFilter.create!(
  515. name: 'used - empty selector',
  516. match: {
  517. from: {
  518. operator: 'contains',
  519. value: 'example.com',
  520. },
  521. },
  522. perform: {
  523. 'X-Zammad-Ticket-group_id' => {
  524. value: group2.id,
  525. },
  526. },
  527. channel: 'email',
  528. active: true,
  529. created_by_id: 1,
  530. updated_by_id: 1,
  531. )
  532. data = 'From: Some Body <somebody@example.com>
  533. To: Bob <bod@example.com>
  534. Cc: any@example.com
  535. Subject: follow up with create post master filter test
  536. Some Text'
  537. parser = Channel::EmailParser.new
  538. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  539. assert_equal(group2.name, ticket.group.name)
  540. assert_equal('2 normal', ticket.priority.name)
  541. assert_equal('follow up with create post master filter test', ticket.title)
  542. assert_equal('Customer', article.sender.name)
  543. assert_equal('email', article.type.name)
  544. assert_equal(false, article.internal)
  545. # move ticket
  546. ticket.group = group1
  547. ticket.save
  548. Observer::Transaction.commit
  549. data = "From: me@example.com
  550. To: customer@example.com
  551. Subject: #{ticket.subject_build('some new subject')}
  552. Some Text"
  553. article_count = ticket.articles.count
  554. parser = Channel::EmailParser.new
  555. ticket_followup, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  556. # check if group is still the old one
  557. assert_equal(ticket.id, ticket_followup.id)
  558. assert_equal(group1.name, ticket_followup.group.name)
  559. assert_equal(group1.name, ticket_followup.group.name)
  560. assert_equal('2 normal', ticket_followup.priority.name)
  561. assert_equal('follow up with create post master filter test', ticket_followup.title)
  562. assert_equal('Customer', article.sender.name)
  563. assert_equal('email', article.type.name)
  564. assert_equal(false, article.internal)
  565. assert_equal(article_count+1, ticket_followup.articles.count)
  566. PostmasterFilter.destroy_all
  567. PostmasterFilter.create!(
  568. name: 'used',
  569. match: {
  570. from: {
  571. operator: 'contains',
  572. value: 'me@example.com',
  573. },
  574. },
  575. perform: {
  576. 'X-Zammad-Ticket-group_id' => {
  577. value: group1.id,
  578. },
  579. 'x-Zammad-Article-Internal' => {
  580. value: true,
  581. },
  582. 'x-Zammad-Ticket-customer_id' => {
  583. value: '',
  584. value_completion: '',
  585. },
  586. },
  587. channel: 'email',
  588. active: true,
  589. created_by_id: 1,
  590. updated_by_id: 1,
  591. )
  592. data = 'From: ME Bob <me@example.com>
  593. To: customer@example.com
  594. Subject: some subject
  595. Some Text'
  596. parser = Channel::EmailParser.new
  597. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  598. assert_equal(group1.name, ticket.group.name)
  599. assert_equal('2 normal', ticket.priority.name)
  600. assert_equal('some subject', ticket.title)
  601. assert_equal('me@example.com', ticket.customer.email)
  602. PostmasterFilter.destroy_all
  603. PostmasterFilter.create!(
  604. name: 'used',
  605. match: {
  606. from: {
  607. operator: 'contains',
  608. value: 'me@example.com',
  609. },
  610. },
  611. perform: {
  612. 'X-Zammad-Ticket-group_id' => {
  613. value: group1.id,
  614. },
  615. 'x-Zammad-Article-Internal' => {
  616. value: true,
  617. },
  618. 'x-Zammad-Ticket-customer_id' => {
  619. value: 999_999,
  620. value_completion: 'xxx',
  621. },
  622. },
  623. channel: 'email',
  624. active: true,
  625. created_by_id: 1,
  626. updated_by_id: 1,
  627. )
  628. data = 'From: ME Bob <me@example.com>
  629. To: customer@example.com
  630. Subject: some subject
  631. Some Text'
  632. parser = Channel::EmailParser.new
  633. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  634. assert_equal(group1.name, ticket.group.name)
  635. assert_equal('2 normal', ticket.priority.name)
  636. assert_equal('some subject', ticket.title)
  637. assert_equal('me@example.com', ticket.customer.email)
  638. PostmasterFilter.destroy_all
  639. PostmasterFilter.create!(
  640. name: 'used',
  641. match: {
  642. from: {
  643. operator: 'contains',
  644. value: 'me@example.com',
  645. },
  646. },
  647. perform: {
  648. 'X-Zammad-Ticket-group_id' => {
  649. value: group1.id,
  650. },
  651. 'X-Zammad-Ticket-priority_id' => {
  652. value: 888_888,
  653. },
  654. 'x-Zammad-Article-Internal' => {
  655. value: true,
  656. },
  657. 'x-Zammad-Ticket-customer_id' => {
  658. value: 999_999,
  659. value_completion: 'xxx',
  660. },
  661. },
  662. channel: 'email',
  663. active: true,
  664. created_by_id: 1,
  665. updated_by_id: 1,
  666. )
  667. data = 'From: ME Bob <me@example.com>
  668. To: customer@example.com
  669. Subject: some subject
  670. Some Text'
  671. parser = Channel::EmailParser.new
  672. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  673. assert_equal(group1.name, ticket.group.name)
  674. assert_equal('2 normal', ticket.priority.name)
  675. assert_equal('some subject', ticket.title)
  676. assert_equal('me@example.com', ticket.customer.email)
  677. assert_equal('2 normal', ticket.priority.name)
  678. PostmasterFilter.destroy_all
  679. PostmasterFilter.create!(
  680. name: 'Autoresponder',
  681. match: {
  682. 'auto-submitted' => {
  683. 'operator' => 'contains not',
  684. 'value' => 'auto-generated',
  685. },
  686. 'from' => {
  687. 'operator' => 'contains',
  688. 'value' => '@example.com',
  689. }
  690. },
  691. perform: {
  692. 'x-zammad-article-internal' => {
  693. 'value' => 'true',
  694. },
  695. 'x-zammad-article-type_id' => {
  696. 'value' => Ticket::Article::Type.find_by(name: 'note').id.to_s,
  697. },
  698. 'x-zammad-ignore' => {
  699. 'value' => 'false',
  700. },
  701. },
  702. channel: 'email',
  703. active: true,
  704. created_by_id: 1,
  705. updated_by_id: 1,
  706. )
  707. data = 'From: ME Bob <me@example.com>
  708. To: customer@example.com
  709. Subject: some subject
  710. Some Text'
  711. parser = Channel::EmailParser.new
  712. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  713. assert_equal('Users', ticket.group.name)
  714. assert_equal('2 normal', ticket.priority.name)
  715. assert_equal('some subject', ticket.title)
  716. assert_equal('me@example.com', ticket.customer.email)
  717. assert_equal('2 normal', ticket.priority.name)
  718. assert_equal('Customer', article.sender.name)
  719. assert_equal('note', article.type.name)
  720. assert_equal(true, article.internal)
  721. PostmasterFilter.destroy_all
  722. PostmasterFilter.create!(
  723. name: 'Autoresponder',
  724. match: {
  725. 'auto-submitted' => {
  726. 'operator' => 'contains',
  727. 'value' => 'auto-generated',
  728. },
  729. 'from' => {
  730. 'operator' => 'contains',
  731. 'value' => '@example.com',
  732. }
  733. },
  734. perform: {
  735. 'x-zammad-article-internal' => {
  736. 'value' => 'true',
  737. },
  738. 'x-zammad-article-type_id' => {
  739. 'value' => Ticket::Article::Type.find_by(name: 'note').id.to_s,
  740. },
  741. 'x-zammad-ignore' => {
  742. 'value' => 'false',
  743. },
  744. },
  745. channel: 'email',
  746. active: true,
  747. created_by_id: 1,
  748. updated_by_id: 1,
  749. )
  750. data = 'From: ME Bob <me@example.com>
  751. To: customer@example.com
  752. Subject: some subject
  753. Some Text'
  754. parser = Channel::EmailParser.new
  755. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  756. assert_equal('Users', ticket.group.name)
  757. assert_equal('2 normal', ticket.priority.name)
  758. assert_equal('some subject', ticket.title)
  759. assert_equal('me@example.com', ticket.customer.email)
  760. assert_equal('2 normal', ticket.priority.name)
  761. assert_equal('Customer', article.sender.name)
  762. assert_equal('email', article.type.name)
  763. assert_equal(false, article.internal)
  764. PostmasterFilter.destroy_all
  765. PostmasterFilter.create!(
  766. name: 'Autoresponder',
  767. match: {
  768. 'auto-submitted' => {
  769. 'operator' => 'contains not',
  770. 'value' => 'auto-generated',
  771. },
  772. 'to' => {
  773. 'operator' => 'contains',
  774. 'value' => 'customer@example.com',
  775. },
  776. 'from' => {
  777. 'operator' => 'contains',
  778. 'value' => '@example.com',
  779. }
  780. },
  781. perform: {
  782. 'x-zammad-article-internal' => {
  783. 'value' => 'true',
  784. },
  785. 'x-zammad-article-type_id' => {
  786. 'value' => Ticket::Article::Type.find_by(name: 'note').id.to_s,
  787. },
  788. 'x-zammad-ignore' => {
  789. 'value' => 'false',
  790. },
  791. },
  792. channel: 'email',
  793. active: true,
  794. created_by_id: 1,
  795. updated_by_id: 1,
  796. )
  797. data = 'From: ME Bob <me@example.com>
  798. To: customer@example.com
  799. Subject: some subject
  800. Some Text'
  801. parser = Channel::EmailParser.new
  802. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  803. assert_equal('Users', ticket.group.name)
  804. assert_equal('2 normal', ticket.priority.name)
  805. assert_equal('some subject', ticket.title)
  806. assert_equal('me@example.com', ticket.customer.email)
  807. assert_equal('2 normal', ticket.priority.name)
  808. assert_equal('Customer', article.sender.name)
  809. assert_equal('note', article.type.name)
  810. assert_equal(true, article.internal)
  811. PostmasterFilter.destroy_all
  812. PostmasterFilter.create!(
  813. name: 'Autoresponder',
  814. match: {
  815. 'auto-submitted' => {
  816. 'operator' => 'contains',
  817. 'value' => 'auto-generated',
  818. },
  819. 'to' => {
  820. 'operator' => 'contains',
  821. 'value' => 'customer1@example.com',
  822. },
  823. 'from' => {
  824. 'operator' => 'contains',
  825. 'value' => '@example.com',
  826. }
  827. },
  828. perform: {
  829. 'x-zammad-article-internal' => {
  830. 'value' => 'true',
  831. },
  832. 'x-zammad-article-type_id' => {
  833. 'value' => Ticket::Article::Type.find_by(name: 'note').id.to_s,
  834. },
  835. 'x-zammad-ignore' => {
  836. 'value' => 'false',
  837. },
  838. },
  839. channel: 'email',
  840. active: true,
  841. created_by_id: 1,
  842. updated_by_id: 1,
  843. )
  844. data = 'From: ME Bob <me@example.com>
  845. To: customer@example.com
  846. Subject: some subject
  847. Some Text'
  848. parser = Channel::EmailParser.new
  849. ticket, article, user = parser.process({ group_id: group_default.id, trusted: false }, data)
  850. assert_equal('Users', ticket.group.name)
  851. assert_equal('2 normal', ticket.priority.name)
  852. assert_equal('some subject', ticket.title)
  853. assert_equal('me@example.com', ticket.customer.email)
  854. assert_equal('2 normal', ticket.priority.name)
  855. assert_equal('Customer', article.sender.name)
  856. assert_equal('email', article.type.name)
  857. assert_equal(false, article.internal)
  858. end
  859. end