DEV: Improve mbox import script

* Better documentation of settings
* Add option to exclude trimmed parts of emails (enabled by default) to not revail email addresses
This commit is contained in:
Gerhard Schlager
2020-03-13 23:59:14 +01:00
parent 36062f43c8
commit 0a88232e87
4 changed files with 40 additions and 22 deletions

View File

@ -19,6 +19,7 @@ module ImportScripts::Mbox
attr_reader :group_messages_by_subject
attr_reader :subject_prefix_regex
attr_reader :automatically_remove_list_name_prefix
attr_reader :show_trimmed_content
attr_reader :tags
def initialize(yaml)
@ -31,20 +32,23 @@ module ImportScripts::Mbox
@index_only = yaml['index_only']
@group_messages_by_subject = yaml['group_messages_by_subject']
unless yaml['remove_subject_prefixes'].empty?
if yaml['remove_subject_prefixes'].present?
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']
@show_trimmed_content = yaml['show_trimmed_content']
@tags = []
yaml['tags'].each do |tag_name, value|
prefixes = Regexp.union(value).source
@tags << {
regex: /^(?:(?:\[(?:#{prefixes})\])|(?:\((?:#{prefixes})\)))\s*/i,
name: tag_name
}
if yaml['tags'].present?
@tags = []
yaml['tags'].each do |tag_name, value|
prefixes = Regexp.union(value).source
@tags << {
regex: /^(?:(?:\[(?:#{prefixes})\])|(?:\((?:#{prefixes})\)))\s*/i,
name: tag_name
}
end
end
end
end