SpamExperts/OrangeAssassin

View on GitHub
oa/message.py

Summary

Maintainability
F
5 days
Test Coverage

File message.py has 492 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Internal representation of email messages."""

from builtins import str
from builtins import set
from builtins import list
Severity: Minor
Found in oa/message.py - About 7 hrs to fix

    Function _parse_relays has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

        def _parse_relays(self, relays):
            """Walks though a relays list to extract
            [un]trusted/internal/external relays"""
            is_trusted = True
            is_internal = True
    Severity: Minor
    Found in oa/message.py - About 5 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

    Cyclomatic complexity is too high in method _parse_relays. (21)
    Open

        def _parse_relays(self, relays):
            """Walks though a relays list to extract
            [un]trusted/internal/external relays"""
            is_trusted = True
            is_internal = True
    Severity: Minor
    Found in oa/message.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Function _parse_sender has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        def _parse_sender(self):
            """Extract the envelope sender from the message."""
    
            always_trust_envelope_from = self.ctxt.conf[
                'always_trust_envelope_sender']
    Severity: Minor
    Found in oa/message.py - About 3 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

    Cyclomatic complexity is too high in method _parse_message. (14)
    Open

        def _parse_message(self):
            """Parse the message."""
            self._hook_check_start()
            # Dump the message raw headers
    
    
    Severity: Minor
    Found in oa/message.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Message has 26 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Message(oa.context.MessageContext):
        """Internal representation of an email message. Used for rule matching."""
    
        def __init__(self, global_context, raw_msg):
            """Parse the message, extracts and decode all headers and all
    Severity: Minor
    Found in oa/message.py - About 3 hrs to fix

      Function _parse_message has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          def _parse_message(self):
              """Parse the message."""
              self._hook_check_start()
              # Dump the message raw headers
      
      
      Severity: Minor
      Found in oa/message.py - 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

      Cyclomatic complexity is too high in method _parse_sender. (12)
      Open

          def _parse_sender(self):
              """Extract the envelope sender from the message."""
      
              always_trust_envelope_from = self.ctxt.conf[
                  'always_trust_envelope_sender']
      Severity: Minor
      Found in oa/message.py by radon

      Cyclomatic Complexity

      Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

      Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

      Construct Effect on CC Reasoning
      if +1 An if statement is a single decision.
      elif +1 The elif statement adds another decision.
      else +0 The else statement does not cause a new decision. The decision is at the if.
      for +1 There is a decision at the start of the loop.
      while +1 There is a decision at the while statement.
      except +1 Each except branch adds a new conditional path of execution.
      finally +0 The finally block is unconditionally executed.
      with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
      assert +1 The assert statement internally roughly equals a conditional statement.
      Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
      Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

      Source: http://radon.readthedocs.org/en/latest/intro.html

      Cyclomatic complexity is too high in method _iter_parts. (7)
      Open

          @staticmethod
          def _iter_parts(msg):
              """Extract and decode the text parts from the parsed email message.
              For non-text parts the payload will be None.
      
      
      Severity: Minor
      Found in oa/message.py by radon

      Cyclomatic Complexity

      Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

      Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

      Construct Effect on CC Reasoning
      if +1 An if statement is a single decision.
      elif +1 The elif statement adds another decision.
      else +0 The else statement does not cause a new decision. The decision is at the if.
      for +1 There is a decision at the start of the loop.
      while +1 There is a decision at the while statement.
      except +1 Each except branch adds a new conditional path of execution.
      finally +0 The finally block is unconditionally executed.
      with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
      assert +1 The assert statement internally roughly equals a conditional statement.
      Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
      Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

      Source: http://radon.readthedocs.org/en/latest/intro.html

      Function _iter_parts has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def _iter_parts(msg):
              """Extract and decode the text parts from the parsed email message.
              For non-text parts the payload will be None.
      
              Yields (payload, part)
      Severity: Minor
      Found in oa/message.py - 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

      Cyclomatic complexity is too high in method msgid. (6)
      Open

          @property
          def msgid(self):
              """Generate a unique ID for the message.
              
              If the message already has an ID that should be unique, in the
      Severity: Minor
      Found in oa/message.py by radon

      Cyclomatic Complexity

      Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

      Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

      Construct Effect on CC Reasoning
      if +1 An if statement is a single decision.
      elif +1 The elif statement adds another decision.
      else +0 The else statement does not cause a new decision. The decision is at the if.
      for +1 There is a decision at the start of the loop.
      while +1 There is a decision at the while statement.
      except +1 Each except branch adds a new conditional path of execution.
      finally +0 The finally block is unconditionally executed.
      with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
      assert +1 The assert statement internally roughly equals a conditional statement.
      Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
      Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

      Source: http://radon.readthedocs.org/en/latest/intro.html

      Cyclomatic complexity is too high in method _decode_header. (6)
      Open

          @staticmethod
          def _decode_header(header):
              """Decodes an email header and returns it as a string. Any  parts of
              the header that cannot be decoded are simply ignored.
              """
      Severity: Minor
      Found in oa/message.py by radon

      Cyclomatic Complexity

      Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

      Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

      Construct Effect on CC Reasoning
      if +1 An if statement is a single decision.
      elif +1 The elif statement adds another decision.
      else +0 The else statement does not cause a new decision. The decision is at the if.
      for +1 There is a decision at the start of the loop.
      while +1 There is a decision at the while statement.
      except +1 Each except branch adds a new conditional path of execution.
      finally +0 The finally block is unconditionally executed.
      with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
      assert +1 The assert statement internally roughly equals a conditional statement.
      Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
      Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

      Source: http://radon.readthedocs.org/en/latest/intro.html

      Function __init__ has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def __init__(self, global_context, raw_msg):
              """Parse the message, extracts and decode all headers and all
              text parts.
              """
              self.missing_boundary_header = False
      Severity: Minor
      Found in oa/message.py - About 1 hr to fix

        Function _decode_header has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def _decode_header(header):
                """Decodes an email header and returns it as a string. Any  parts of
                the header that cannot be decoded are simply ignored.
                """
                parts = list()
        Severity: Minor
        Found in oa/message.py - 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

        Function get_from_addresses has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_from_addresses(self):
                """Get addresses from 'Resent-From' header,
                and if there are no addresses, get from
                all FROM_HEADERS.
                """
        Severity: Minor
        Found in oa/message.py - About 55 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

        Function get_to_addresses has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_to_addresses(self):
                """Get addresses from 'Resent-To' and 'Resent-Cc'
                headers, ad if there are no addresses, get from
                all TO_HEADERS.
                """
        Severity: Minor
        Found in oa/message.py - About 55 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

        Function get_all_from_headers_addr has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_all_from_headers_addr(self):
                all_from_headers = ['From', 'Envelope-Sender',
                                    'Resent-Sender', 'X-Envelope-From',
                                    'EnvelopeFrom', 'Resent-From']
                sender_addr = self.sender_address
        Severity: Minor
        Found in oa/message.py - About 45 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

        Avoid deeply nested control flow statements.
        Open

                                if not in_trusted and not has_auth:
                                    is_trusted = False
                                    is_internal = False
        
                                else:
        Severity: Major
        Found in oa/message.py - About 45 mins to fix

          Avoid too many return statements within this function.
          Open

                  return
          Severity: Major
          Found in oa/message.py - About 30 mins to fix

            Function get_all_addr_header has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_all_addr_header(self, header_name):
                    """Get a list of all the addresses from this header."""
                    values = list()
                    for value in self.get_decoded_header(header_name):
                        for dummy, addr in email.utils.getaddresses([value]):
            Severity: Minor
            Found in oa/message.py - 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

            Function get_name_header has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_name_header(self, header_name):
                    """Get a list of the first names from this header."""
                    values = list()
                    for value in self.get_decoded_header(header_name):
                        for name, dummy in email.utils.getaddresses([value]):
            Severity: Minor
            Found in oa/message.py - 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

            Function msgid has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def msgid(self):
                    """Generate a unique ID for the message.
                    
                    If the message already has an ID that should be unique, in the
                    Message-ID header, then simply use that. Otherwise, generate an
            Severity: Minor
            Found in oa/message.py - 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

            Function get_addr_header has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_addr_header(self, header_name):
                    """Get a list of the first addresses from this header."""
                    values = list()
                    for value in self.get_decoded_header(header_name):
                        for dummy, addr in email.utils.getaddresses([value]):
            Severity: Minor
            Found in oa/message.py - 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

            XXX found
            Open

                    # XXX This is strange, but it's what SA does.
            Severity: Minor
            Found in oa/message.py by fixme

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                @_memoize("addr_headers")
                def get_addr_header(self, header_name):
                    """Get a list of the first addresses from this header."""
                    values = list()
                    for value in self.get_decoded_header(header_name):
            Severity: Major
            Found in oa/message.py and 1 other location - About 3 hrs to fix
            oa/message.py on lines 287..296

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 71.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                @_memoize("name_headers")
                def get_name_header(self, header_name):
                    """Get a list of the first names from this header."""
                    values = list()
                    for value in self.get_decoded_header(header_name):
            Severity: Major
            Found in oa/message.py and 1 other location - About 3 hrs to fix
            oa/message.py on lines 255..264

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 71.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                def get_from_addresses(self):
                    """Get addresses from 'Resent-From' header,
                    and if there are no addresses, get from
                    all FROM_HEADERS.
                    """
            Severity: Major
            Found in oa/message.py and 1 other location - About 2 hrs to fix
            oa/plugins/dkim.py on lines 85..97

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 54.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                        if self.untrusted_relays:
                            sender = self.untrusted_relays[0].get("envfrom")
                            if sender:
                                self.sender_address = sender.strip()
                                return
            Severity: Major
            Found in oa/message.py and 2 other locations - About 50 mins to fix
            oa/message.py on lines 332..336
            oa/message.py on lines 338..342

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 36.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                        if self.trusted_relays and not always_trust_envelope_from:
                            sender = self.trusted_relays[-1].get("envfrom")
                            if sender:
                                self.sender_address = sender.strip()
                                return
            Severity: Major
            Found in oa/message.py and 2 other locations - About 50 mins to fix
            oa/message.py on lines 332..336
            oa/message.py on lines 343..347

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 36.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                    if self.external_relays:
                        sender = self.external_relays[0].get("envfrom")
                        if sender:
                            self.sender_address = sender.strip()
                            return
            Severity: Major
            Found in oa/message.py and 2 other locations - About 50 mins to fix
            oa/message.py on lines 338..342
            oa/message.py on lines 343..347

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 36.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                            if is_trusted:
                                self.trusted_relays.append(relay)
                                self.last_trusted_relay_index = position
                            else:
                                self.untrusted_relays.append(relay)
            Severity: Minor
            Found in oa/message.py and 1 other location - About 40 mins to fix
            oa/message.py on lines 395..399

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 34.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                            if is_internal:
                                self.internal_relays.append(relay)
                                self.last_internal_relay_index = position
                            else:
                                self.external_relays.append(relay)
            Severity: Minor
            Found in oa/message.py and 1 other location - About 40 mins to fix
            oa/message.py on lines 401..405

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 34.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Blank line at end of file
            Open

            Severity: Minor
            Found in oa/message.py by pep8

            Trailing blank lines are superfluous.

            Okay: spam(1)
            W391: spam(1)\n
            
            However the last line should end with a new line (warning W292).

            Line too long (80 > 79 characters)
            Open

                                        if is_internal and not has_auth and not in_internal:
            Severity: Minor
            Found in oa/message.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            Blank line contains whitespace
            Open

                    
            Severity: Minor
            Found in oa/message.py by pep8

            Trailing whitespace is superfluous.

            The warning returned varies on whether the line itself is blank,
            for easier filtering for those who want to indent their blank lines.
            
            Okay: spam(1)\n#
            W291: spam(1) \n#
            W293: class Foo(object):\n    \n    bang = 12

            Line too long (90 > 79 characters)
            Open

                                    "ident={ident} envfrom={envfrom} intl={intl} id={id} auth={auth} "
            Severity: Minor
            Found in oa/message.py by pep8

            Limit all lines to a maximum of 79 characters.

            There are still many devices around that are limited to 80 character
            lines; plus, limiting windows to 80 characters makes it possible to
            have several windows side-by-side.  The default wrapping on such
            devices looks ugly.  Therefore, please limit all lines to a maximum
            of 79 characters. For flowing long blocks of text (docstrings or
            comments), limiting the length to 72 characters is recommended.
            
            Reports error E501.

            There are no issues that match your filters.

            Category
            Status