File mail_backend.rb
has 382 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'mail'
require 'mapi/msg'
require 'mapi/convert'
require 'config_helper'
require 'alaveteli_file_types'
Method decode_attached_part
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def decode_attached_part(part, parent_mail)
if get_content_type(part) == 'message/rfc822'
# An email attached as text
part.rfc822_attachment = mail_from_raw_email(part.body)
if part.rfc822_attachment.nil?
- 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 expand_and_normalize_parts
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def expand_and_normalize_parts(part, parent_mail)
if part.multipart?
Mail::PartsList.new(part.parts.each { |sub_part| expand_and_normalize_parts(sub_part, parent_mail) })
else
part_filename = get_part_file_name(part)
- 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 attempt_to_find_original_attachment_attributes
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def attempt_to_find_original_attachment_attributes(mail, body:, nested: false)
all_attributes = get_attachment_attributes(mail)
def calculate_hexdigest(body)
# ensure bodies have the same line endings and are encoded the same
- 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 decode_attached_part
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def decode_attached_part(part, parent_mail)
if get_content_type(part) == 'message/rfc822'
# An email attached as text
part.rfc822_attachment = mail_from_raw_email(part.body)
if part.rfc822_attachment.nil?
Method attempt_to_find_original_attachment_attributes
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def attempt_to_find_original_attachment_attributes(mail, body:, nested: false)
all_attributes = get_attachment_attributes(mail)
def calculate_hexdigest(body)
# ensure bodies have the same line endings and are encoded the same
Method extract_attached_message_headers
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def extract_attached_message_headers(leaf)
body = get_part_body(leaf)
# Test to see if we are in the first part of the attached
# RFC822 message and it is text, if so add headers.
if leaf.within_rfc822_attachment == leaf && get_content_type(leaf) == 'text/plain'
- 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 _get_attachment_leaves_recursive
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def _get_attachment_leaves_recursive(part, within_rfc822_attachment, parent_mail)
leaves_found = []
if part.multipart?
if part.parts.empty?
# This is typically caused by a missing final
- 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 _get_attachment_leaves_recursive
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def _get_attachment_leaves_recursive(part, within_rfc822_attachment, parent_mail)
leaves_found = []
if part.multipart?
if part.parts.empty?
# This is typically caused by a missing final
Method get_all_addresses
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def get_all_addresses(mail, include_invalid: false)
addrs = []
addrs << mail.to
addrs << mail[:to].try(:value) if mail.to.nil? && include_invalid
addrs << mail.cc
- 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"