msimerson/Haraka

View on GitHub
server.js

Summary

Maintainability
F
4 days
Test Coverage

File server.js has 540 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';
// smtp network server

const daemon      = require('daemon');
const fs          = require('fs');
Severity: Major
Found in server.js - About 1 day to fix

    Function _graceful has 71 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    Server._graceful = shutdown => {
        if (!Server.cluster && shutdown) {
            ['outbound', 'cfreader', 'plugins'].forEach(module => {
                process.emit('message', {event: `${module  }.shutdown`});
            });
    Severity: Major
    Found in server.js - About 2 hrs to fix

      Function setup_http_listeners has 50 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      Server.setup_http_listeners = () => {
          if (!Server.http.cfg) return;
          if (!Server.http.cfg.listen) return;
      
          const listeners = Server.get_listen_addrs(Server.http.cfg, 80);
      Severity: Minor
      Found in server.js - About 2 hrs to fix

        Function get_listen_addrs has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

        Server.get_listen_addrs = (cfg, port) => {
            if (!port) port = 25;
            let listeners = [];
            if (cfg?.listen) {
                listeners = cfg.listen.split(/\s*,\s*/);
        Severity: Minor
        Found in server.js - 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 setup_smtp_listeners has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        Server.setup_smtp_listeners = (plugins2, type, inactivity_timeout) => {
        
            async.each(
                Server.get_listen_addrs(Server.cfg.main),  // array of listeners
        
        
        Severity: Minor
        Found in server.js - About 1 hr to fix

          Function get_smtp_server has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          Server.get_smtp_server = (ep, inactivity_timeout, done) => {
              let server;
          
              function onConnect (client) {
                  client.setTimeout(inactivity_timeout);
          Severity: Minor
          Found in server.js - About 1 hr to fix

            Function load_smtp_ini has 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            Server.load_smtp_ini = () => {
                Server.cfg = Server.config.get('smtp.ini', {
                    booleans: [
                        '-main.daemonize',
                        '-main.strict_rfc1869',
            Severity: Minor
            Found in server.js - About 1 hr to fix

              Function init_master_respond has 37 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              Server.init_master_respond = (retval, msg) => {
                  if (!(retval === constants.ok || retval === constants.cont)) {
                      Server.logerror(`init_master returned error${((msg) ? `: ${msg}` : '')}`);
                      return logger.dump_and_exit(1);
                  }
              Severity: Minor
              Found in server.js - About 1 hr to fix

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

                Server.setup_http_listeners = () => {
                    if (!Server.http.cfg) return;
                    if (!Server.http.cfg.listen) return;
                
                    const listeners = Server.get_listen_addrs(Server.http.cfg, 80);
                Severity: Minor
                Found in server.js - 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 setupListener has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        function setupListener (listen_address, listenerDone) {
                
                            const ep = endpoint(listen_address, 25);
                            if (ep instanceof Error) return listenerDone(
                                new Error(`Invalid "listen" format in smtp.ini: ${listen_address}`));
                Severity: Minor
                Found in server.js - About 1 hr to fix

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

                  Server.load_smtp_ini = () => {
                      Server.cfg = Server.config.get('smtp.ini', {
                          booleans: [
                              '-main.daemonize',
                              '-main.strict_rfc1869',
                  Severity: Minor
                  Found in server.js - 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 createServer has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                  Server.createServer = params => {
                      const c = Server.cfg.main;
                      for (const key in params) {
                          if (typeof params[key] === 'function') continue;
                          c[key] = params[key];
                  Severity: Minor
                  Found in server.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

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

                      if (c.user) {
                          Server.lognotice(`Switching from current uid: ${process.getuid()}`);
                          process.setuid(c.user);
                          Server.lognotice(`New uid: ${process.getuid()}`);
                      }
                  Severity: Major
                  Found in server.js and 1 other location - About 1 hr to fix
                  server.js on lines 606..610

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

                  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 (c.group) {
                          Server.lognotice(`Switching from current gid: ${process.getgid()}`);
                          process.setgid(c.group);
                          Server.lognotice(`New gid: ${process.getgid()}`);
                      }
                  Severity: Major
                  Found in server.js and 1 other location - About 1 hr to fix
                  server.js on lines 611..615

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

                  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

                      Server.cfg.headers.max_lines    = parseInt(Server.cfg.headers.max_lines) || parseInt(Server.config.get('max_header_lines')) || 1000;
                  Severity: Major
                  Found in server.js and 1 other location - About 1 hr to fix
                  server.js on lines 60..60

                  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

                      Server.cfg.headers.max_received = parseInt(Server.cfg.headers.max_received) || parseInt(Server.config.get('max_received_count')) || 100;
                  Severity: Major
                  Found in server.js and 1 other location - About 1 hr to fix
                  server.js on lines 61..61

                  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

                                  server
                                      .on('listening', function () {
                                          const addr = this.address();
                                          logger.lognotice(`Listening on ${endpoint(addr)}`);
                                          listenerDone();
                  Severity: Minor
                  Found in server.js and 1 other location - About 50 mins to fix
                  server.js on lines 488..492

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

                  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

                          Server.http.server.on('listening', function () {
                              const addr = this.address();
                              logger.lognotice(`Listening on ${endpoint(addr)}`);
                              cb();
                          });
                  Severity: Minor
                  Found in server.js and 1 other location - About 50 mins to fix
                  server.js on lines 414..419

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

                  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

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

                          ['outbound', 'cfreader', 'plugins'].forEach(module => {
                              process.emit('message', {event: `${module  }.shutdown`});
                          });
                  Severity: Minor
                  Found in server.js and 1 other location - About 40 mins to fix
                  server.js on lines 225..227

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

                  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

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

                              ['outbound', 'cfreader', 'plugins'].forEach(module => {
                                  process.emit('message', {event: `${module  }.shutdown`});
                              })
                  Severity: Minor
                  Found in server.js and 1 other location - About 40 mins to fix
                  server.js on lines 157..159

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

                  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