msimerson/Haraka

View on GitHub
plugins/messagesniffer.js

Summary

Maintainability
D
2 days
Test Coverage

Function hook_data_post has 183 lines of code (exceeds 25 allowed). Consider refactoring.
Open

exports.hook_data_post = function (next, connection) {
    const cfg = this.config.get('messagesniffer.ini');
    const txn = connection?.transaction;
    if (!txn) return next();

Severity: Major
Found in plugins/messagesniffer.js - About 7 hrs to fix

    File messagesniffer.js has 309 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    // messagesniffer
    
    const fs = require('fs');
    const net = require('net');
    const plugin = exports;
    Severity: Minor
    Found in plugins/messagesniffer.js - About 3 hrs to fix

      Function hook_connect has 68 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      exports.hook_connect = function (next, connection) {
          const cfg = this.config.get('messagesniffer.ini');
          // Skip any private IP ranges
          // Skip connection.transaction undefined
          if (connection?.remote?.is_private || !connection?.transaction) return next();
      Severity: Major
      Found in plugins/messagesniffer.js - About 2 hrs to fix

        Avoid deeply nested control flow statements.
        Open

                                else if (code === 20) {
                                    if (cfg.message.truncate) {
                                        action = cfg.message.truncate;
                                    }
                                    else {
        Severity: Major
        Found in plugins/messagesniffer.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                      switch (precedence) {
                                          case 'bulk':
                                          case 'list':
                                          case 'junk':
                                              // Leave these as they are
          Severity: Major
          Found in plugins/messagesniffer.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                        if (cfg.message.local_white) {
                                            action = cfg.message.local_white;
                                        }
                                        else {
                                            return next(OK);
            Severity: Major
            Found in plugins/messagesniffer.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                          if (headers[headers.length-1]) {
                                              headers[headers.length-1].value += `${line}\r\n`;
                                          }
              Severity: Major
              Found in plugins/messagesniffer.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                            if (match) {
                                                headers.push({ header: match[1], value: (match[2] ? `${match[2]}\r\n` : '\r\n') });
                                            }
                Severity: Major
                Found in plugins/messagesniffer.js - About 45 mins to fix

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

                  exports.hook_data_post = function (next, connection) {
                      const cfg = this.config.get('messagesniffer.ini');
                      const txn = connection?.transaction;
                      if (!txn) return next();
                  
                  
                  Severity: Minor
                  Found in plugins/messagesniffer.js - 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

                  Avoid too many return statements within this function.
                  Open

                              return next();
                  Severity: Major
                  Found in plugins/messagesniffer.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                        return next();
                    Severity: Major
                    Found in plugins/messagesniffer.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                              return next(DENY, `Poor GBUdb reputation for [${connection.remote.ip}]`);
                      Severity: Major
                      Found in plugins/messagesniffer.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                            return next();
                        Severity: Major
                        Found in plugins/messagesniffer.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                                      return next();
                          Severity: Major
                          Found in plugins/messagesniffer.js - About 30 mins to fix

                            There are no issues that match your filters.

                            Category
                            Status