mysociety/alaveteli

View on GitHub
lib/mail_handler/backends/mail_backend.rb

Summary

Maintainability
D
2 days
Test Coverage

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'
Severity: Minor
Found in lib/mail_handler/backends/mail_backend.rb - About 5 hrs to fix

    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?
    Severity: Minor
    Found in lib/mail_handler/backends/mail_backend.rb - About 2 hrs to fix

    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)
    Severity: Minor
    Found in lib/mail_handler/backends/mail_backend.rb - About 1 hr to fix

    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
    Severity: Minor
    Found in lib/mail_handler/backends/mail_backend.rb - About 1 hr to fix

    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?
    Severity: Minor
    Found in lib/mail_handler/backends/mail_backend.rb - About 1 hr to fix

      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
      Severity: Minor
      Found in lib/mail_handler/backends/mail_backend.rb - About 1 hr to fix

        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'
        Severity: Minor
        Found in lib/mail_handler/backends/mail_backend.rb - About 1 hr to fix

        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
        Severity: Minor
        Found in lib/mail_handler/backends/mail_backend.rb - About 1 hr to fix

        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
        Severity: Minor
        Found in lib/mail_handler/backends/mail_backend.rb - About 1 hr to fix

          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
          Severity: Minor
          Found in lib/mail_handler/backends/mail_backend.rb - About 25 mins to fix

          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

          There are no issues that match your filters.

          Category
          Status