2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-26 16:26:18 -04:00
|
|
|
require 'yaml'
|
|
|
|
|
|
|
|
module ImportScripts::Mbox
|
|
|
|
class Settings
|
|
|
|
def self.load(filename)
|
|
|
|
yaml = YAML.load_file(filename)
|
|
|
|
Settings.new(yaml)
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :data_dir
|
|
|
|
attr_reader :split_regex
|
|
|
|
attr_reader :batch_size
|
|
|
|
attr_reader :trust_level
|
2017-11-18 07:53:21 -05:00
|
|
|
attr_reader :prefer_html
|
2018-01-04 03:17:35 -05:00
|
|
|
attr_reader :staged
|
2018-01-17 06:03:57 -05:00
|
|
|
attr_reader :index_only
|
|
|
|
attr_reader :group_messages_by_subject
|
2020-03-07 19:20:02 -05:00
|
|
|
attr_reader :subject_prefix_regex
|
|
|
|
attr_reader :automatically_remove_list_name_prefix
|
2020-03-13 18:59:14 -04:00
|
|
|
attr_reader :show_trimmed_content
|
2020-03-07 19:20:02 -05:00
|
|
|
attr_reader :tags
|
2017-05-26 16:26:18 -04:00
|
|
|
|
|
|
|
def initialize(yaml)
|
|
|
|
@data_dir = yaml['data_dir']
|
|
|
|
@split_regex = Regexp.new(yaml['split_regex']) unless yaml['split_regex'].empty?
|
|
|
|
@batch_size = 1000 # no need to make this actually configurable at the moment
|
|
|
|
@trust_level = yaml['default_trust_level']
|
2017-11-18 07:53:21 -05:00
|
|
|
@prefer_html = yaml['prefer_html']
|
2018-01-04 03:17:35 -05:00
|
|
|
@staged = yaml['staged']
|
2018-01-17 06:03:57 -05:00
|
|
|
@index_only = yaml['index_only']
|
|
|
|
@group_messages_by_subject = yaml['group_messages_by_subject']
|
2020-03-07 19:20:02 -05:00
|
|
|
|
2020-03-13 18:59:14 -04:00
|
|
|
if yaml['remove_subject_prefixes'].present?
|
2020-03-07 19:20:02 -05:00
|
|
|
prefix_regexes = yaml['remove_subject_prefixes'].map { |p| Regexp.new(p) }
|
|
|
|
@subject_prefix_regex = /^#{Regexp.union(prefix_regexes).source}/i
|
|
|
|
end
|
|
|
|
|
|
|
|
@automatically_remove_list_name_prefix = yaml['automatically_remove_list_name_prefix']
|
2020-03-13 18:59:14 -04:00
|
|
|
@show_trimmed_content = yaml['show_trimmed_content']
|
2020-03-07 19:20:02 -05:00
|
|
|
|
2020-03-26 11:40:34 -04:00
|
|
|
@tags = []
|
2020-03-13 18:59:14 -04:00
|
|
|
if yaml['tags'].present?
|
|
|
|
yaml['tags'].each do |tag_name, value|
|
|
|
|
prefixes = Regexp.union(value).source
|
|
|
|
@tags << {
|
|
|
|
regex: /^(?:(?:\[(?:#{prefixes})\])|(?:\((?:#{prefixes})\)))\s*/i,
|
|
|
|
name: tag_name
|
|
|
|
}
|
|
|
|
end
|
2020-03-07 19:20:02 -05:00
|
|
|
end
|
2017-05-26 16:26:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|