File email_parser.rb
has 762 lines of code (exceeds 250 allowed). Consider refactoring. Open
class Channel::EmailParser
include Channel::EmailHelper
PROCESS_TIME_MAX = 180
EMAIL_REGEX = %r{.+@.+}
Method get_attachments
has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring. Open
def get_attachments(file, attachments, mail)
return file.parts.map { |p| get_attachments(p, attachments, mail) } if file.parts.any?
return [] if [mail.text_part&.body&.encoded, mail.html_part&.body&.encoded].include?(file.body.encoded)
return [] if file.content_type&.start_with?('text/plain') && !file.attachment?
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method _process
has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring. Open
def _process(channel, msg)
# parse email
mail = parse(msg)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method set_attributes_by_x_headers
has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring. Open
def set_attributes_by_x_headers(item_object, header_name, mail, suffix = false)
# loop all x-zammad-header-* headers
item_object.attributes.each_key do |key|
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method _process
has 146 lines of code (exceeds 25 allowed). Consider refactoring. Open
def _process(channel, msg)
# parse email
mail = parse(msg)
Method get_attachments
has 141 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_attachments(file, attachments, mail)
return file.parts.map { |p| get_attachments(p, attachments, mail) } if file.parts.any?
return [] if [mail.text_part&.body&.encoded, mail.html_part&.body&.encoded].include?(file.body.encoded)
return [] if file.content_type&.start_with?('text/plain') && !file.attachment?
Class EmailParser
has 27 methods (exceeds 20 allowed). Consider refactoring. Open
class Channel::EmailParser
include Channel::EmailHelper
PROCESS_TIME_MAX = 180
EMAIL_REGEX = %r{.+@.+}
Method message_header_hash
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def message_header_hash(mail)
imported_fields = mail.header.fields.to_h do |f|
begin
value = if f.value.match?(ISO2022JP_REGEXP)
value = header_field_unpack_japanese(f)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method message_body_hash
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def message_body_hash(mail)
if mail.html_part&.body.present?
content_type = mail.html_part.mime_type || 'text/plain'
body = body_text(mail.html_part, strict_html: true)
elsif mail.text_part.present? && mail.all_parts.any? { |elem| elem.inline? && elem.content_type&.start_with?('image') }
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method set_attributes_by_x_headers
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
def set_attributes_by_x_headers(item_object, header_name, mail, suffix = false)
# loop all x-zammad-header-* headers
item_object.attributes.each_key do |key|
Method sender_attributes
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.sender_attributes(from)
if from.is_a?(ActiveSupport::HashWithIndifferentAccess)
from = SENDER_FIELDS.filter_map { |f| from[f] }
.map(&:to_utf8).compact_blank
.partition { |address| address.match?(EMAIL_REGEX) }
Method message_header_hash
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def message_header_hash(mail)
imported_fields = mail.header.fields.to_h do |f|
begin
value = if f.value.match?(ISO2022JP_REGEXP)
value = header_field_unpack_japanese(f)
Method message_body_hash
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
def message_body_hash(mail)
if mail.html_part&.body.present?
content_type = mail.html_part.mime_type || 'text/plain'
body = body_text(mail.html_part, strict_html: true)
elsif mail.text_part.present? && mail.all_parts.any? { |elem| elem.inline? && elem.content_type&.start_with?('image') }
Method get_nonplaintext_body_as_attachment
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def get_nonplaintext_body_as_attachment(mail)
if !(mail.html_part&.body.present? || (!mail.multipart? && mail.mime_type.present? && mail.mime_type != 'text/plain'))
return
end
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method check_attributes_by_x_headers
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def self.check_attributes_by_x_headers(header_name, value)
class_name = nil
attribute = nil
# skip check attributes if it is tags
return true if header_name == 'x-zammad-ticket-tags'
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method sender_attributes
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.sender_attributes(from)
if from.is_a?(ActiveSupport::HashWithIndifferentAccess)
from = SENDER_FIELDS.filter_map { |f| from[f] }
.map(&:to_utf8).compact_blank
.partition { |address| address.match?(EMAIL_REGEX) }
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method reprocess_failed_articles
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.reprocess_failed_articles
articles = Ticket::Article.where(body: ::HtmlSanitizer::UNPROCESSABLE_HTML_MSG)
articles.reorder(id: :desc).as_batches do |article|
if !article.as_raw&.content
puts "No raw content for article id #{article.id}! Please verify manually via command: Ticket::Article.find(#{article.id}).as_raw" # rubocop:disable Rails/Output
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return false if !class_instance.association_id_validation(attribute, value)
Avoid too many return
statements within this method. Open
return if !class_object
Method gracefully_get_attachments
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def gracefully_get_attachments(part, attachments, mail)
get_attachments(part, attachments, mail).flatten.compact
rescue => e # Protect process to work with spam emails (see test/fixtures/mail15.box)
raise e if (fail_count ||= 0).positive?
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"