django/django

View on GitHub
django/core/mail/message.py

Summary

Maintainability
F
3 days
Test Coverage

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

import mimetypes
from email import (
    charset as Charset, encoders as Encoders, generator, message_from_string,
)
from email.errors import HeaderParseError
Severity: Minor
Found in django/core/mail/message.py - About 4 hrs to fix

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

        def __init__(self, subject='', body='', from_email=None, to=None, bcc=None,
                     connection=None, attachments=None, headers=None, cc=None,
                     reply_to=None):
            """
            Initialize a single email message (which can be sent to multiple
    Severity: Minor
    Found in django/core/mail/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

    Function attach has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def attach(self, filename=None, content=None, mimetype=None):
            """
            Attach a file with the given filename and content. The filename can
            be omitted and the mimetype is guessed, if not provided.
    
    
    Severity: Minor
    Found in django/core/mail/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 __init__ has 11 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, subject='', body='', from_email=None, to=None, bcc=None,
    Severity: Major
    Found in django/core/mail/message.py - About 1 hr to fix

      Function __init__ has 10 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, subject='', body='', from_email=None, to=None, bcc=None,
      Severity: Major
      Found in django/core/mail/message.py - About 1 hr to fix

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

            def _create_attachments(self, msg):
                if self.attachments:
                    encoding = self.encoding or settings.DEFAULT_CHARSET
                    body_msg = msg
                    msg = SafeMIMEMultipart(_subtype=self.mixed_subtype, encoding=encoding)
        Severity: Minor
        Found in django/core/mail/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 sanitize_address has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def sanitize_address(addr, encoding):
            """
            Format a pair of (name, address) or an email address string.
            """
            address = None
        Severity: Minor
        Found in django/core/mail/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

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

        def forbid_multi_line_headers(name, val, encoding):
            """Forbid multi-line headers to prevent header injection."""
            encoding = encoding or settings.DEFAULT_CHARSET
            val = str(val)  # val may be lazy
            if '\n' in val or '\r' in val:
        Severity: Minor
        Found in django/core/mail/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

        Function __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(self, _subtype='mixed', boundary=None, _subparts=None, encoding=None, **_params):
        Severity: Minor
        Found in django/core/mail/message.py - About 35 mins to fix

          Function _create_mime_attachment has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def _create_mime_attachment(self, content, mimetype):
                  """
                  Convert the content, mimetype pair into a MIME attachment object.
          
                  If the mimetype is message/rfc822, content may be an
          Severity: Minor
          Found in django/core/mail/message.py - About 35 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

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

              def as_bytes(self, unixfrom=False, linesep='\n'):
                  """Return the entire formatted message as bytes.
                  Optional `unixfrom' when True, means include the Unix From_ envelope
                  header.
          
          
          Severity: Major
          Found in django/core/mail/message.py and 1 other location - About 2 hrs to fix
          django/core/mail/message.py on lines 112..123

          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 59.

          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 as_string(self, unixfrom=False, linesep='\n'):
                  """Return the entire formatted message as a string.
                  Optional `unixfrom' when True, means include the Unix From_ envelope
                  header.
          
          
          Severity: Major
          Found in django/core/mail/message.py and 1 other location - About 2 hrs to fix
          django/core/mail/message.py on lines 125..136

          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 59.

          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 4 locations. Consider refactoring.
          Open

                  if bcc:
                      if isinstance(bcc, str):
                          raise TypeError('"bcc" argument must be a list or tuple')
                      self.bcc = list(bcc)
                  else:
          Severity: Major
          Found in django/core/mail/message.py and 3 other locations - About 1 hr to fix
          django/core/mail/message.py on lines 193..198
          django/core/mail/message.py on lines 199..204
          django/core/mail/message.py on lines 211..216

          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 39.

          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 4 locations. Consider refactoring.
          Open

                  if reply_to:
                      if isinstance(reply_to, str):
                          raise TypeError('"reply_to" argument must be a list or tuple')
                      self.reply_to = list(reply_to)
                  else:
          Severity: Major
          Found in django/core/mail/message.py and 3 other locations - About 1 hr to fix
          django/core/mail/message.py on lines 193..198
          django/core/mail/message.py on lines 199..204
          django/core/mail/message.py on lines 205..210

          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 39.

          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 4 locations. Consider refactoring.
          Open

                  if cc:
                      if isinstance(cc, str):
                          raise TypeError('"cc" argument must be a list or tuple')
                      self.cc = list(cc)
                  else:
          Severity: Major
          Found in django/core/mail/message.py and 3 other locations - About 1 hr to fix
          django/core/mail/message.py on lines 193..198
          django/core/mail/message.py on lines 205..210
          django/core/mail/message.py on lines 211..216

          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 39.

          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 4 locations. Consider refactoring.
          Open

                  if to:
                      if isinstance(to, str):
                          raise TypeError('"to" argument must be a list or tuple')
                      self.to = list(to)
                  else:
          Severity: Major
          Found in django/core/mail/message.py and 3 other locations - About 1 hr to fix
          django/core/mail/message.py on lines 199..204
          django/core/mail/message.py on lines 205..210
          django/core/mail/message.py on lines 211..216

          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 39.

          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 __setitem__(self, name, val):
                  name, val = forbid_multi_line_headers(name, val, self.encoding)
                  MIMEMultipart.__setitem__(self, name, val)
          Severity: Minor
          Found in django/core/mail/message.py and 1 other location - About 45 mins to fix
          django/core/mail/message.py on lines 153..155

          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 35.

          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 __setitem__(self, name, val):
                  name, val = forbid_multi_line_headers(name, val, self.encoding)
                  MIMEText.__setitem__(self, name, val)
          Severity: Minor
          Found in django/core/mail/message.py and 1 other location - About 45 mins to fix
          django/core/mail/message.py on lines 175..177

          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 35.

          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

          There are no issues that match your filters.

          Category
          Status