-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed Mail collector rules #1566
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment')) | ||
CollectDataFromMailJob.perform_now | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
class CollectorHelper | ||
attr_reader :sender, :sender_container, :recipient | ||
|
||
def initialize(from, cc = nil) | ||
if from.is_a?(Device) && cc.is_a?(User) | ||
if (from.is_a?(Device) && cc.is_a?(User)) || (from.is_a?(User) && from == cc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/PerceivedComplexity: Perceived complexity for initialize is too high. [13/8] |
||
@sender = from | ||
@recipient = cc | ||
prepare_containers | ||
elsif cc | ||
@sender = Device.find_by email: from | ||
@sender = Device.find_by email: from.downcase unless @sender | ||
@sender ||= Device.find_by email: from.downcase | ||
@recipient = User.find_by email: cc | ||
@recipient = User.find_by email: cc.downcase unless @recipient | ||
@recipient ||= User.find_by email: cc.downcase | ||
prepare_containers if @sender && @recipient | ||
else | ||
@sender = User.find_by email: from | ||
@sender = User.find_by email: from.downcase unless @sender | ||
@sender ||= User.find_by email: from.downcase | ||
@recipient = @sender | ||
prepare_containers if @sender | ||
end | ||
|
@@ -26,19 +28,21 @@ def sender_recipient_known? | |
|
||
def prepare_new_dataset(subject) | ||
return nil unless sender_recipient_known? | ||
|
||
Container.create( | ||
name: subject, | ||
container_type: 'dataset', | ||
parent: @sender_container | ||
parent: @sender_container, | ||
) | ||
end | ||
|
||
def prepare_dataset(subject) | ||
return nil unless sender_recipient_known? | ||
|
||
Container.where( | ||
name: subject, | ||
container_type: 'dataset', | ||
parent: @sender_container | ||
parent: @sender_container, | ||
).first_or_create | ||
end | ||
|
||
|
@@ -65,14 +69,14 @@ def prepare_containers | |
unless @recipient.container | ||
@recipient.container = Container.create( | ||
name: 'inbox', | ||
container_type: 'root' | ||
container_type: 'root', | ||
) | ||
end | ||
sender_box_id = 'sender_box_' + @sender.id.to_s | ||
sender_box_id = "sender_box_#{@sender.id}" | ||
@sender_container = Container.where( | ||
name: @sender.first_name, | ||
container_type: sender_box_id, | ||
parent_id: @recipient.container.id | ||
parent_id: @recipient.container.id, | ||
).first_or_create | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
class CollectorHelperSet | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/FrozenStringLiteralComment: Missing frozen string literal comment. |
||
attr_reader :helper_set | ||
|
||
def initialize(from, cc_list) | ||
@helper_set = [] | ||
cc_list.each do |cc| | ||
h = CollectorHelper.new(from, cc) | ||
@helper_set.push(h) if h.sender_recipient_known? | ||
end | ||
end | ||
|
||
def sender_recipient_known? | ||
@helper_set.length.positive? | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/CyclomaticComplexity: Cyclomatic complexity for initialize is too high. [12/7]