From 1fd36cfc6aa35fd1cd42537ba61a2f3b5774e356 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 12 Apr 2016 09:25:20 +0200 Subject: [PATCH] Moved postmaster filter options to config. --- app/models/channel/email_parser.rb | 18 ++---- ...0412000001_add_config_postmaster_filter.rb | 59 +++++++++++++++++++ db/seeds.rb | 57 +++++++++++++++++- 3 files changed, 120 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20160412000001_add_config_postmaster_filter.rb diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index e449ea0b5..226e5cec1 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -346,16 +346,10 @@ retrns mail = parse(msg) # run postmaster pre filter - filters = { - '0010' => Channel::Filter::Trusted, - '0020' => Channel::Filter::AutoResponseCheck, - '0030' => Channel::Filter::OutOfOfficeCheck, - '0100' => Channel::Filter::FollowUpCheck, - '0900' => Channel::Filter::BounceCheck, - '1000' => Channel::Filter::Database, + filters = {} + Setting.where(area: 'Postmaster::PreFilter').each {|setting| + filters[setting.name] = Kernel.const_get(Setting.get(setting.name)) } - - # filter(channel, mail) filters.each {|_prio, backend| begin backend.run(channel, mail) @@ -511,11 +505,9 @@ retrns Observer::Ticket::Notification.transaction # run postmaster post filter - filters = { - # '0010' => Channel::Filter::Trusted, + Setting.where(area: 'Postmaster::PostFilter').each {|setting| + filters[setting.name] = Kernel.const_get(Setting.get(setting.name)) } - - # filter( channel, mail ) filters.each {|_prio, backend| begin backend.run(channel, mail, ticket, article, user) diff --git a/db/migrate/20160412000001_add_config_postmaster_filter.rb b/db/migrate/20160412000001_add_config_postmaster_filter.rb new file mode 100644 index 000000000..684f330a9 --- /dev/null +++ b/db/migrate/20160412000001_add_config_postmaster_filter.rb @@ -0,0 +1,59 @@ +class AddConfigPostmasterFilter < ActiveRecord::Migration + def up + Setting.create_if_not_exists( + title: 'Define postmaster filter.', + name: '0010_postmaster_filter_trusted', + area: 'Postmaster::PreFilter', + description: 'Define postmaster filter to remove X-Zammad-Headers from not trusted sources.', + options: {}, + state: 'Channel::Filter::Trusted', + frontend: false + ) + Setting.create_if_not_exists( + title: 'Define postmaster filter.', + name: '0020_postmaster_filter_auto_response_check', + area: 'Postmaster::PreFilter', + description: 'Define postmaster filter to identify auto responses to prevent auto replies from Zammad.', + options: {}, + state: 'Channel::Filter::AutoResponseCheck', + frontend: false + ) + Setting.create_if_not_exists( + title: 'Define postmaster filter.', + name: '0030_postmaster_filter_out_of_office_check', + area: 'Postmaster::PreFilter', + description: 'Define postmaster filter to identify out of office emails for follow up detection and keeping current ticket state.', + options: {}, + state: 'Channel::Filter::OutOfOfficeCheck', + frontend: false + ) + Setting.create_if_not_exists( + title: 'Define postmaster filter.', + name: '0100_postmaster_filter_follow_up_check', + area: 'Postmaster::PreFilter', + description: 'Define postmaster filter to identify follow ups (based on admin settings).', + options: {}, + state: 'Channel::Filter::FollowUpCheck', + frontend: false + ) + Setting.create_if_not_exists( + title: 'Define postmaster filter.', + name: '0900_postmaster_filter_bounce_check', + area: 'Postmaster::PreFilter', + description: 'Define postmaster filter to identify postmaster bounced - to handle it as follow up of origin ticket.', + options: {}, + state: 'Channel::Filter::BounceCheck', + frontend: false + ) + Setting.create_if_not_exists( + title: 'Define postmaster filter.', + name: '1000_postmaster_filter_database_check', + area: 'Postmaster::PreFilter', + description: 'Define postmaster filter for filters managed via admin interface.', + options: {}, + state: 'Channel::Filter::Database', + frontend: false + ) + + end +end diff --git a/db/seeds.rb b/db/seeds.rb index 05ea1c932..f64085ad0 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1516,6 +1516,61 @@ Setting.create_if_not_exists( frontend: false ) +Setting.create_if_not_exists( + title: 'Define postmaster filter.', + name: '0010_postmaster_filter_trusted', + area: 'Postmaster::PreFilter', + description: 'Define postmaster filter to remove X-Zammad-Headers from not trusted sources.', + options: {}, + state: 'Channel::Filter::Trusted', + frontend: false +) +Setting.create_if_not_exists( + title: 'Define postmaster filter.', + name: '0020_postmaster_filter_auto_response_check', + area: 'Postmaster::PreFilter', + description: 'Define postmaster filter to identify auto responses to prevent auto replies from Zammad.', + options: {}, + state: 'Channel::Filter::AutoResponseCheck', + frontend: false +) +Setting.create_if_not_exists( + title: 'Define postmaster filter.', + name: '0030_postmaster_filter_out_of_office_check', + area: 'Postmaster::PreFilter', + description: 'Define postmaster filter to identify out of office emails for follow up detection and keeping current ticket state.', + options: {}, + state: 'Channel::Filter::OutOfOfficeCheck', + frontend: false +) +Setting.create_if_not_exists( + title: 'Define postmaster filter.', + name: '0100_postmaster_filter_follow_up_check', + area: 'Postmaster::PreFilter', + description: 'Define postmaster filter to identify follow ups (based on admin settings).', + options: {}, + state: 'Channel::Filter::FollowUpCheck', + frontend: false +) +Setting.create_if_not_exists( + title: 'Define postmaster filter.', + name: '0900_postmaster_filter_bounce_check', + area: 'Postmaster::PreFilter', + description: 'Define postmaster filter to identify postmaster bounced - to handle it as follow up of origin ticket.', + options: {}, + state: 'Channel::Filter::BounceCheck', + frontend: false +) +Setting.create_if_not_exists( + title: 'Define postmaster filter.', + name: '1000_postmaster_filter_database_check', + area: 'Postmaster::PreFilter', + description: 'Define postmaster filter for filters managed via admin interface.', + options: {}, + state: 'Channel::Filter::Database', + frontend: false +) + signature = Signature.create_if_not_exists( id: 1, name: 'default', @@ -1740,7 +1795,7 @@ Overview.create_if_not_exists( }, 'ticket.owner_id' => { operator: 'is', - value: 1, + pre_condition: 'not_set', }, }, order: {