text: /*******************************************************************************
   * mailArchiver_ATD LICENSE************************
   *
   * The MIT License (MIT)
   *
   * Copyright (c) 2017 Claude Fauconnet claude.fauconnet@neuf.fr
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy
   * of this software and associated documentation files (the "Software"), to deal
   * in the Software without restriction, including without limitation the rights
   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   * copies of the Software, and to permit persons to whom the Software is
   * furnished to do so, subject to the following conditions:
   *
   * The above copyright notice and this permission notice shall be included in
   * all copies or substantial portions of the Software.
   *
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   * SOFTWARE.
   *
   ******************************************************************************/
  var common = {
      maxPdfSubjectLength: 33,//45 - date (10)- number(2)
      maxDirLength: 30,
  
  
      dateToString: function (date) {
          if (!date)
              return "---"
          var mm = date.getMonth() + 1; // getMonth() is zero-based
          var dd = date.getDate();
  
          return [date.getFullYear(),
              (mm > 9 ? '' : '0') + mm,
              (dd > 9 ? '' : '0') + dd
          ].join('-');
      },
      truncate: function (str, length) {
          if (str.length > length)
              str = str.substring(0, length)
          return str;
  
      },
  
      replaceNonLetterOrNumberChars: function (str, replaceBy) {
          return str.replace(/[^a-zA-Z0-9_.]/g, replaceBy);
  
      },
  
      toAscii: function getAscii(str) {
          var conversions = new Object();
          conversions['ae'] = 'ä|æ|ǽ';
          conversions['oe'] = 'ö|œ';
          conversions['ue'] = 'ü';
          conversions['Ae'] = 'Ä';
          conversions['Ue'] = 'Ü';
          conversions['Oe'] = 'Ö';
          conversions['A'] = 'À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ';
          conversions['a'] = 'à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª';
          conversions['C'] = 'Ç|Ć|Ĉ|Ċ|Č';
          conversions['c'] = 'ç|ć|ĉ|ċ|č';
          conversions['D'] = 'Ð|Ď|Đ';
          conversions['d'] = 'ð|ď|đ';
          conversions['E'] = 'È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě';
          conversions['e'] = 'è|é|ê|ë|ē|ĕ|ė|ę|ě';
          conversions['G'] = 'Ĝ|Ğ|Ġ|Ģ';
          conversions['g'] = 'ĝ|ğ|ġ|ģ';
          conversions['H'] = 'Ĥ|Ħ';
          conversions['h'] = 'ĥ|ħ';
          conversions['I'] = 'Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ';
          conversions['i'] = 'ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı';
          conversions['J'] = 'Ĵ';
          conversions['j'] = 'ĵ';
          conversions['K'] = 'Ķ';
          conversions['k'] = 'ķ';
          conversions['L'] = 'Ĺ|Ļ|Ľ|Ŀ|Ł';
          conversions['l'] = 'ĺ|ļ|ľ|ŀ|ł';
          conversions['N'] = 'Ñ|Ń|Ņ|Ň';
          conversions['n'] = 'ñ|ń|ņ|ň|ŉ';
          conversions['O'] = 'Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ';
          conversions['o'] = 'ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º';
          conversions['R'] = 'Ŕ|Ŗ|Ř';
          conversions['r'] = 'ŕ|ŗ|ř';
          conversions['S'] = 'Ś|Ŝ|Ş|Š';
          conversions['s'] = 'ś|ŝ|ş|š|ſ';
          conversions['T'] = 'Ţ|Ť|Ŧ';
          conversions['t'] = 'ţ|ť|ŧ';
          conversions['U'] = 'Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ';
          conversions['u'] = 'ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ';
          conversions['Y'] = 'Ý|Ÿ|Ŷ';
          conversions['y'] = 'ý|ÿ|ŷ';
          conversions['W'] = 'Ŵ';
          conversions['w'] = 'ŵ';
          conversions['Z'] = 'Ź|Ż|Ž';
          conversions['z'] = 'ź|ż|ž';
          conversions['AE'] = 'Æ|Ǽ';
          conversions['ss'] = 'ß';
          conversions['IJ'] = 'Ĳ';
          conversions['ij'] = 'ĳ';
          conversions['OE'] = 'Œ';
          conversions['f'] = 'ƒ';
          for (var i in conversions) {
              var re = new RegExp(conversions[i], "g");
              str = str.replace(re, i);
          }
          return str;
      },
      deleteFolderRecursive: function (path) {
          return;
          try {
              if (fs.existsSync(path)) {
                  fs.readdirSync(path).forEach(function (file, index) {
                      var curPath = path + "/" + file;
                      if (fs.lstatSync(curPath).isDirectory()) { // recurse
                          common.deleteFolderRecursive(curPath);
                      } else { // delete file
                          fs.unlinkSync(curPath);
                      }
                  });
                  fs.rmdirSync(path);
              }
          } catch (e) {
              archiveProcessor.consoleToFile(e);
          }
      },
      roundToMO:function(octets){
         return  Math.round(octets/1000000 * 100) / 100
      },
      roundToKO:function(octets){
          return  Math.round(octets/1000 * 10) / 10
      }
  
  
  }
  
  module.exports = common;
  