123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- require 'test_helper'
- class EmailProcessOutOfOfficeTest < ActiveSupport::TestCase
- test 'process with out of office check - ms' do
- ticket = Ticket.create!(
- title: 'ooo check - ms',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'closed'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- article = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'ooo check',
- message_id: '<20150830145601.30.608881@edenhofer.zammad.com>',
- body: 'some message bounce check',
- internal: false,
- sender: Ticket::Article::Sender.lookup(name: 'Agent'),
- type: Ticket::Article::Type.lookup(name: 'email'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- travel 1.second
- # exchange out of office example #1
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: #{ticket.subject_build('some new subject 1')}
- X-MS-Has-Attach:
- X-Auto-Response-Suppress: All
- X-MS-Exchange-Inbox-Rules-Loop: aaa.bbb@example.com
- X-MS-TNEF-Correlator:
- x-olx-disclaimer: Done
- x-tm-as-product-ver: SMEX-11.0.0.4179-8.000.1202-21706.006
- x-tm-as-result: No--39.689200-0.000000-31
- x-tm-as-user-approved-sender: Yes
- x-tm-as-user-blocked-sender: No
- Some Text"
- ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail['x-zammad-out-of-office'.to_sym])
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.id, ticket_p.id)
- assert_equal('closed', ticket.state.name)
- # normal follow up
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: #{ticket.subject_build('some new subject - none')}
- X-MS-Exchange-Inbox-Rules-Loop: aaa.bbb@example.com
- Some Text 2"
- ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail['x-zammad-out-of-office'.to_sym])
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.id, ticket_p.id)
- assert_equal('open', ticket_p.state.name)
- ticket = Ticket.find(ticket.id)
- ticket.state = Ticket::State.lookup(name: 'closed')
- ticket.save
- # exchange out of office example #2
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: #{ticket.subject_build('some new subject 2')}
- X-MS-Has-Attach:
- X-Auto-Response-Suppress: All
- X-MS-Exchange-Inbox-Rules-Loop: aaa.bbb@example.com
- X-MS-TNEF-Correlator:
- x-exclaimer-md-config: 8c10826d-4052-4c5c-a8e8-e09011276827
- Some Text"
- ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail['x-zammad-out-of-office'.to_sym])
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.id, ticket_p.id)
- assert_equal('closed', ticket.state.name)
- travel_back
- end
- test 'process with out of office check - zimbra' do
- ticket = Ticket.create!(
- title: 'ooo check - zimbra',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'closed'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- article = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'ooo check',
- message_id: '<20150830145601.30.608881@edenhofer.zammad.com>',
- body: 'some message bounce check',
- internal: false,
- sender: Ticket::Article::Sender.lookup(name: 'Agent'),
- type: Ticket::Article::Type.lookup(name: 'email'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- travel 1.second
- # exchange out of office example #1
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: #{ticket.subject_build('some new subject 1')}
- Auto-Submitted: auto-replied (zimbra; vacation)
- Precedence: bulk
- X-Mailer: Zimbra 7.1.3_GA_3346
- Some Text"
- ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail['x-zammad-out-of-office'.to_sym])
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.id, ticket_p.id)
- assert_equal('closed', ticket.state.name)
- # normal follow up
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: #{ticket.subject_build('some new subject - none')}
- X-Mailer: Zimbra 7.1.3_GA_3346
- Some Text 2"
- ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail['x-zammad-out-of-office'.to_sym])
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.id, ticket_p.id)
- assert_equal('open', ticket_p.state.name)
- ticket = Ticket.find(ticket.id)
- ticket.state = Ticket::State.lookup(name: 'closed')
- ticket.save
- # exchange out of office example #2
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: #{ticket.subject_build('some new subject 2')}
- Auto-Submitted: auto-replied (zimbra; vacation)
- Precedence: bulk
- X-Mailer: Zimbra 7.1.3_GA_3346
- Some Text"
- ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail['x-zammad-out-of-office'.to_sym])
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.id, ticket_p.id)
- assert_equal('closed', ticket.state.name)
- travel_back
- end
- test 'process with out of office check - cloud' do
- ticket = Ticket.create!(
- title: 'ooo check - cloud',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'closed'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- article = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'ooo check',
- message_id: '<20150830145601.30.608881@edenhofer.zammad.com>',
- body: 'some message bounce check',
- internal: false,
- sender: Ticket::Article::Sender.lookup(name: 'Agent'),
- type: Ticket::Article::Type.lookup(name: 'email'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- travel 1.second
- # exchange out of office example #1
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: #{ticket.subject_build('some new subject 1')}
- Auto-submitted: auto-replied; owner-email=\"me@example.com\"
- Some Text"
- ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail['x-zammad-out-of-office'.to_sym])
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.id, ticket_p.id)
- assert_equal('closed', ticket.state.name)
- # normal follow up
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: #{ticket.subject_build('some new subject - none')}
- Some Text 2"
- ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail['x-zammad-out-of-office'.to_sym])
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.id, ticket_p.id)
- assert_equal('open', ticket_p.state.name)
- ticket = Ticket.find(ticket.id)
- ticket.state = Ticket::State.lookup(name: 'closed')
- ticket.save
- # exchange out of office example #2
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: #{ticket.subject_build('some new subject 2')}
- Auto-submitted: auto-replied; owner-email=\"me@example.com\"
- Some Text"
- ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail['x-zammad-out-of-office'.to_sym])
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.id, ticket_p.id)
- assert_equal('closed', ticket.state.name)
- travel_back
- end
- test 'process with out of office check - gmail' do
- ticket = Ticket.create!(
- title: 'ooo check - gmail',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'closed'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- article = Ticket::Article.create!(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'ooo check',
- message_id: '<20150830145601.30.608881@edenhofer.zammad.com>',
- body: 'some message bounce check',
- internal: false,
- sender: Ticket::Article::Sender.lookup(name: 'Agent'),
- type: Ticket::Article::Type.lookup(name: 'email'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- travel 1.second
- # gmail out of office example #1
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: vacation: #{ticket.subject_build('some new subject 1')}
- Precedence: bulk
- X-Autoreply: yes
- Auto-Submitted: auto-replied
- Some Text"
- ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(true, mail['x-zammad-out-of-office'.to_sym])
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.id, ticket_p.id)
- assert_equal('closed', ticket.state.name)
- # normal follow up
- email_raw_string = "From: me@example.com
- To: customer@example.com
- Subject: #{ticket.subject_build('some new subject - none')}
- Some Text 2"
- ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
- assert_equal(false, mail['x-zammad-out-of-office'.to_sym])
- ticket = Ticket.find(ticket.id)
- assert_equal(ticket.id, ticket_p.id)
- assert_equal('open', ticket_p.state.name)
- travel_back
- end
- end
|