diff --git a/bin/pop.js b/bin/pop.js index a1124af..b8c2d79 100755 --- a/bin/pop.js +++ b/bin/pop.js @@ -11,14 +11,6 @@ var _helper = require("../lib/helper"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } -function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } - -function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } - -function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } - -function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } - function _await(value, then, direct) { if (direct) { return then ? then(value) : value; @@ -89,6 +81,14 @@ function _async(f) { }; } +function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } + +function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } + +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } + +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } + function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } diff --git a/bin/pop.js.map b/bin/pop.js.map index d9e10c6..6677ab4 100644 --- a/bin/pop.js.map +++ b/bin/pop.js.map @@ -1 +1 @@ -{"version":3,"sources":["index.mjs"],"names":[],"mappings":"AAAA;;;;;AACA;;AACA;;AAEA;;;;;;;;;;;;AAgFO,gB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AC,KAAR,CAAc,GAAd;AACA,IAAA,OAAO,CAAC,IAAR;AACD,GArBY;AAuBb,IAAA,OAAO,CAAC,GAAR,CAAY,MAAZ;AACA,IAAA,OAAO,CAAC,IAAR,CAAa,CAAb;AAxBa;AA0BZ,CA1BD","file":"pop.js","sourcesContent":["#!/usr/bin/env node\nimport {resolve as pathResolve} from 'path';\nimport Pop3Command from '../lib/Command';\n\nimport {stream2String} from '../lib/helper';\n\nconst {argv} = process,\n options = {},\n alias = {\n c: 'config',\n u: 'user',\n p: 'password',\n h: 'host',\n m: 'method',\n },\n requiredOptionNames = ['user', 'password', 'host', 'method'],\n mailStructure = {\n port: 110,\n tls: false,\n },\n mailStructureOptionNames = ['user', 'password', 'host', 'port', 'tls', 'timeout'];\n\nfunction printHelpAndExit() {\n const text = 'Usage: pop [options]\\r\\n'\n + '\\r\\n'\n + 'Example: pop -u example@gmail.com -p pwd -h example.pop3.com -m UIDL\\r\\n'\n + '\\r\\n'\n + 'Options:\\r\\n'\n + ' -c, --config config file (in place of options below)\\r\\n'\n + ' -u, --user username\\r\\n'\n + ' -p, --password password\\r\\n'\n + ' -h, --host host of server\\r\\n'\n + ' --port port of server. Defaults to 110 or 995 if tls is used.\\r\\n'\n + ' --tls whether to use TLS(SSL). Defaults to false.\\r\\n'\n + ' --no-tls disables previously set TLS(SSL).\\r\\n'\n + ' -m, --method method and arguments of API in node-pop3. e.g. \\'UIDL\\', \\'RETR 100\\' or \\'command USER example@gmail.com\\'\\r\\n'\n + ' --help print help';\n console.log(text);\n process.exit(0);\n}\n\nlet optionName;\nif (argv.slice(2).some(function(arg, i, args) {\n if (arg.charAt(0) === '-') {\n optionName = arg.replace(/^-+/g, '');\n if ((optionName || '').length === 1) {\n if (!{}.hasOwnProperty.call(alias, optionName)) {\n console.error('Invalid alias', optionName);\n return true;\n }\n optionName = alias[optionName];\n }\n if (\n optionName &&\n (i === args.length - 1 || args[i + 1].charAt(0) === '-')\n ) {\n options[optionName] = [true];\n }\n } else if (!optionName) {\n console.error('Invalid argument', arg);\n return true;\n } else if (options[optionName]) {\n options[optionName].push(arg);\n } else {\n options[optionName] = [arg];\n }\n})) {\n process.exit();\n}\n\nif (options.help) {\n printHelpAndExit();\n}\n\nif (options.config) {\n const configOptions = require(pathResolve(process.cwd(), options.config[0]));\n ['method', ...mailStructureOptionNames].forEach((optionName) => {\n if (!(optionName in options) && optionName in configOptions) {\n options[optionName] = [configOptions[optionName]];\n }\n });\n}\n\nfor (const requiredOptionName of requiredOptionNames) {\n if (!options[requiredOptionName]) {\n console.error(requiredOptionName + ' is required!');\n printHelpAndExit();\n }\n}\n\nif (options.timeout) {\n options.timeout[0] = parseFloat(options.timeout[0]);\n}\n\nif ('no-tls' in options) {\n options.tls = [false];\n} else if (options.tls && options.tls[0]) {\n // By using `mailStructure`, can still be overridden below\n mailStructure.port = '995';\n}\nfor (const _optionName of mailStructureOptionNames) {\n mailStructure[_optionName] = (\n options[_optionName] || []\n )[0] || mailStructure[_optionName];\n}\n\nconst pop3Command = new Pop3Command(mailStructure);\nconst [methodName] = options.method;\n\n// Todo: Might want to report this to Istnabul as nyc doesn't seem to pick\n// this up, despite it running\n// istanbul ignore next\n(async () => {\n\nlet result;\ntry {\n if (['UIDL', 'TOP', 'QUIT', 'RETR'].includes(methodName)) {\n result = await pop3Command[methodName](...options.method.slice(1));\n } else {\n await pop3Command._connect();\n result = await pop3Command.command(...options.method);\n if (result[1]) {\n const [info, stream] = result;\n const str = await stream2String(stream);\n result = [info, str];\n }\n }\n if (methodName !== 'QUIT') {\n await pop3Command.QUIT();\n }\n} catch (err) {\n console.error(err);\n process.exit();\n}\n\nconsole.dir(result);\nprocess.exit(0);\n\n})();\n"]} \ No newline at end of file +{"version":3,"sources":["index.mjs"],"names":[],"mappings":"AAAA;;;;;AACA;;AACA;;AAEA;;;;AAgFO,gBAAgB,KAAhB,EAAuB,IAAvB,EAA6B,MAA7B,EAAqC;AAC3C,MAAI,MAAJ,EAAY;AACX,WAAO,IAAI,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AC,GAAR,CAAY,MAAZ;AACA,IAAA,OAAO,CAAC,IAAR,CAAa,CAAb;AAxBa;AA0BZ,CA1BD","file":"pop.js","sourcesContent":["#!/usr/bin/env node\nimport {resolve as pathResolve} from 'path';\nimport Pop3Command from '../lib/Command';\n\nimport {stream2String} from '../lib/helper';\n\nconst {argv} = process,\n options = {},\n alias = {\n c: 'config',\n u: 'user',\n p: 'password',\n h: 'host',\n m: 'method',\n },\n requiredOptionNames = ['user', 'password', 'host', 'method'],\n mailStructure = {\n port: 110,\n tls: false,\n },\n mailStructureOptionNames = ['user', 'password', 'host', 'port', 'tls', 'timeout'];\n\nfunction printHelpAndExit() {\n const text = 'Usage: pop [options]\\r\\n'\n + '\\r\\n'\n + 'Example: pop -u example@gmail.com -p pwd -h example.pop3.com -m UIDL\\r\\n'\n + '\\r\\n'\n + 'Options:\\r\\n'\n + ' -c, --config config file (in place of options below)\\r\\n'\n + ' -u, --user username\\r\\n'\n + ' -p, --password password\\r\\n'\n + ' -h, --host host of server\\r\\n'\n + ' --port port of server. Defaults to 110 or 995 if tls is used.\\r\\n'\n + ' --tls whether to use TLS(SSL). Defaults to false.\\r\\n'\n + ' --no-tls disables previously set TLS(SSL).\\r\\n'\n + ' -m, --method method and arguments of API in node-pop3. e.g. \\'UIDL\\', \\'RETR 100\\' or \\'command USER example@gmail.com\\'\\r\\n'\n + ' --help print help';\n console.log(text);\n process.exit(0);\n}\n\nlet optionName;\nif (argv.slice(2).some(function(arg, i, args) {\n if (arg.charAt(0) === '-') {\n optionName = arg.replace(/^-+/g, '');\n if ((optionName || '').length === 1) {\n if (!{}.hasOwnProperty.call(alias, optionName)) {\n console.error('Invalid alias', optionName);\n return true;\n }\n optionName = alias[optionName];\n }\n if (\n optionName &&\n (i === args.length - 1 || args[i + 1].charAt(0) === '-')\n ) {\n options[optionName] = [true];\n }\n } else if (!optionName) {\n console.error('Invalid argument', arg);\n return true;\n } else if (options[optionName]) {\n options[optionName].push(arg);\n } else {\n options[optionName] = [arg];\n }\n})) {\n process.exit();\n}\n\nif (options.help) {\n printHelpAndExit();\n}\n\nif (options.config) {\n const configOptions = require(pathResolve(process.cwd(), options.config[0]));\n ['method', ...mailStructureOptionNames].forEach((optionName) => {\n if (!(optionName in options) && optionName in configOptions) {\n options[optionName] = [configOptions[optionName]];\n }\n });\n}\n\nfor (const requiredOptionName of requiredOptionNames) {\n if (!options[requiredOptionName]) {\n console.error(requiredOptionName + ' is required!');\n printHelpAndExit();\n }\n}\n\nif (options.timeout) {\n options.timeout[0] = parseFloat(options.timeout[0]);\n}\n\nif ('no-tls' in options) {\n options.tls = [false];\n} else if (options.tls && options.tls[0]) {\n // By using `mailStructure`, can still be overridden below\n mailStructure.port = '995';\n}\nfor (const _optionName of mailStructureOptionNames) {\n mailStructure[_optionName] = (\n options[_optionName] || []\n )[0] || mailStructure[_optionName];\n}\n\nconst pop3Command = new Pop3Command(mailStructure);\nconst [methodName] = options.method;\n\n// Todo: Might want to report this to Istnabul as nyc doesn't seem to pick\n// this up, despite it running\n// istanbul ignore next\n(async () => {\n\nlet result;\ntry {\n if (['UIDL', 'TOP', 'QUIT', 'RETR'].includes(methodName)) {\n result = await pop3Command[methodName](...options.method.slice(1));\n } else {\n await pop3Command._connect();\n result = await pop3Command.command(...options.method);\n if (result[1]) {\n const [info, stream] = result;\n const str = await stream2String(stream);\n result = [info, str];\n }\n }\n if (methodName !== 'QUIT') {\n await pop3Command.QUIT();\n }\n} catch (err) {\n console.error(err);\n process.exit();\n}\n\nconsole.dir(result);\nprocess.exit(0);\n\n})();\n"]} \ No newline at end of file diff --git a/lib/Command.js b/lib/Command.js index cf5b55e..157fe98 100644 --- a/lib/Command.js +++ b/lib/Command.js @@ -1,6 +1,6 @@ "use strict"; -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } +function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } Object.defineProperty(exports, "__esModule", { value: true @@ -13,6 +13,18 @@ var _helper = require("./helper.js"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } +function _await(value, then, direct) { + if (direct) { + return then ? then(value) : value; + } + + if (!value || !value.then) { + value = Promise.resolve(value); + } + + return then ? value.then(then) : value; +} + function _empty() {} function _awaitIgnored(value, direct) { @@ -33,29 +45,17 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } -function _await(value, then, direct) { - if (direct) { - return then ? then(value) : value; - } - - if (!value || !value.then) { - value = Promise.resolve(value); - } - - return then ? value.then(then) : value; -} - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } -function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); } +function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } @@ -83,7 +83,8 @@ var Pop3Command = /*#__PURE__*/function (_Pop3Connection) { port = _ref.port, tls = _ref.tls, timeout = _ref.timeout, - tlsOptions = _ref.tlsOptions; + tlsOptions = _ref.tlsOptions, + servername = _ref.servername; _classCallCheck(this, Pop3Command); @@ -92,7 +93,8 @@ var Pop3Command = /*#__PURE__*/function (_Pop3Connection) { port: port, tls: tls, timeout: timeout, - tlsOptions: tlsOptions + tlsOptions: tlsOptions, + servername: servername }); _this.user = user; _this.password = password; @@ -107,7 +109,7 @@ var Pop3Command = /*#__PURE__*/function (_Pop3Connection) { var _this3 = this; if (_this3._socket) { - return _this3._PASSInfo; + return _await(_this3._PASSInfo); } return _await(_get(_getPrototypeOf(Pop3Command.prototype), "connect", _this3).call(_this3), function () { @@ -284,7 +286,7 @@ var Pop3Command = /*#__PURE__*/function (_Pop3Connection) { if (!_this21._socket) { _this21._PASSInfo = '' || 'Bye'; - return _this21._PASSInfo; + return _await(_this21._PASSInfo); } return _await(_get(_getPrototypeOf(Pop3Command.prototype), "command", _this21).call(_this21, 'QUIT'), function (_ref18) { diff --git a/lib/Command.js.map b/lib/Command.js.map index 2e9106d..45a3b3c 100644 --- a/lib/Command.js.map +++ b/lib/Command.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/Command.mjs"],"names":["value","direct","then","Promise","resolve","Pop3Command","user","password","host","port","tls","timeout","tlsOptions","_PASSInfo","_socket","info","msgNumber","_connect","stream","str","list","n","Pop3Connection","stream2String","listify"],"mappings":";;;;;;;;;AAAA;;AAEA;;;;AA8lBO,kBAAkB,CACxB;;AAlgBM,uBAAuBA,KAAvB,EAA8BC,MAA9B,EAAsC;AAC5C,MAAI,CAACA,MAAL,EAAa;AACZ,WAAOD,KAAK,IAAIA,KAAK,CAACE,IAAf,GAAsBF,KAAK,CAACE,IAAN,QAAtB,GAA2CC,OAAO,CAACC,OAAR,EAAlD;AACA;AACD;;;;;;;;;;;;;;AAfM,gBAAgBJ,KAAhB,EAAuBE,IAAvB,EAA6BD,MAA7B,EAAqC;AAC3C,MAAIA,MAAJ,EAAY;AACX,WAAOC,IAAI,GAAGA,IAAI,CAACF,KAAD,CAAP,GAAiBA,KAA5B;AACA;;AACD,MAAI,CAACA,KAAD,IAAU,CAACA,KAAK,CAACE,IAArB,EAA2B;AAC1BF,IAAAA,KAAK,GAAGG,OAAO,CAACC,OAAR,CAAgBJ,KAAhB,CAAR;AACA;;AACD,SAAOE,IAAI,GAAGF,KAAK,CAACE,IAAN,CAAWA,IAAX,CAAH,GAAsBF,KAAjC;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;IAxFKK,W;;;;;AACJ,6BAQG;AAAA;;AAAA,QAPDC,IAOC,QAPDA,IA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AAH0B;AAAA;AAI3B,O;;;;;;;UAEY;AAAA,sBACN,IADM;;AACX,YAAI,CAAC,QAAKJ,OAAV,EAAmB;AACjB,kBAAKD,SAAL,GAAiB,MAAM,KAAvB;AACA,iBAAO,QAAKA,SAAZ;AACD;;AAJU,qGAKwB,MALxB;AAAA;AAAA,cAKJE,IALI;;AAMX,kBAAKF,SAAL,GAAiBE,IAAI,IAAI,EAAzB;AACA,iBAAO,QAAKF,SAAZ;AAPW;AAQZ,O;;;;;;;EAvFuBS,sB;;AA0F1BjB,WAAW,CAACkB,aAAZ,GAA4BA,qBAA5B;AACAlB,WAAW,CAACmB,OAAZ,GAAsBA,eAAtB;eAEenB,W","sourcesContent":["import Pop3Connection from './Connection.mjs';\n\nimport { stream2String, listify } from './helper.mjs';\n\nclass Pop3Command extends Pop3Connection {\n constructor({\n user,\n password,\n host,\n port,\n tls,\n timeout,\n tlsOptions,\n }) {\n super({ host, port, tls, timeout, tlsOptions });\n this.user = user;\n this.password = password;\n this._PASSInfo = '';\n }\n\n async _connect() {\n if (this._socket) {\n return this._PASSInfo;\n }\n await super.connect();\n await super.command('USER', this.user);\n const [info] = await super.command('PASS', this.password);\n this._PASSInfo = info;\n return this._PASSInfo;\n }\n\n async UIDL(msgNumber = '') {\n await this._connect();\n const [, stream] = await super.command('UIDL', msgNumber);\n const str = await stream2String(stream);\n const list = listify(str);\n return msgNumber ? list[0] : list;\n }\n\n async NOOP() {\n await this._connect();\n await super.command('NOOP');\n return;\n }\n\n async LIST(msgNumber = '') {\n await this._connect();\n const [, stream] = await super.command('LIST', msgNumber);\n const str = await stream2String(stream);\n const list = listify(str);\n return msgNumber ? list[0] : list;\n }\n\n async RSET() {\n await this._connect();\n const [info] = await super.command('RSET');\n return info;\n }\n\n async RETR(msgNumber) {\n await this._connect();\n const [, stream] = await super.command('RETR', msgNumber);\n return stream2String(stream);\n }\n\n async DELE(msgNumber) {\n await this._connect();\n const [info] = await super.command('DELE', msgNumber);\n return info;\n }\n\n async STAT() {\n await this._connect();\n const [info] = await super.command('STAT');\n return info;\n }\n\n async TOP(msgNumber, n = 0) {\n await this._connect();\n const [, stream] = await super.command('TOP', msgNumber, n);\n return stream2String(stream);\n }\n\n async QUIT() {\n if (!this._socket) {\n this._PASSInfo = '' || 'Bye';\n return this._PASSInfo;\n }\n const [info] = await super.command('QUIT');\n this._PASSInfo = info || '';\n return this._PASSInfo;\n }\n}\n\nPop3Command.stream2String = stream2String;\nPop3Command.listify = listify;\n\nexport default Pop3Command;\n"],"file":"Command.js"} \ No newline at end of file +{"version":3,"sources":["../src/Command.mjs"],"names":["value","then","direct","Promise","resolve","Pop3Command","user","password","host","port","tls","timeout","tlsOptions","servername","_PASSInfo","_socket","info","msgNumber","_connect","stream","str","list","n","Pop3Connection","stream2String","listify"],"mappings":";;;;;;;;;AAAA;;AAEA;;;;AAkFO,gBAAgBA,KAAhB,EAAuBC,IAAvB,EAA6BC,MAA7B,EAAqC;AAC3C,MAAIA,MAAJ,EAAY;AACX,WAAOD,IAAI,GAAGA,IAAI,CAACD,KAAD,CAAP,GAAiBA,KAA5B;AACA;;AACD,MAAI,CAACA,KAAD,IAAU,CAACA,KAAK,CAACC,IAArB,EAA2B;AAC1BD,IAAAA,KAAK,GAAGG,OAAO,CAACC,OAAR,CAAgBJ,KAAhB,CAAR;AACA;;AACD,SAAOC,IAAI,GAAGD,KAAK,CAACC,IAAN,CAAWA,IAAX,CAAH,GAAsBD,KAAjC;AACA;;AAogBM,kBAAkB,CACxB;;AAlgBM,uBAAuBA,KAAvB,EAA8BE,MAA9B,EAAsC;AAC5C,MAAI,CAACA,MAAL,EAAa;AACZ,WAAOF,KAAK,IAAIA,KAAK,CAACC,IAAf,GAAsBD,KAAK,CAACC,IAAN,QAAtB,GAA2CE,OAAO,CAACC,OAAR,EAAlD;AACA;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA/FKC,W;;;;;AACJ,6BASG;AAAA;;AAAA,QARDC,IAQC,QARDA,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/B;AAAA;AAAA,gBAEjBH,MAFiB;;AAG1B,mBAAO,2BAAcA,MAAd,CAAP;AAH0B;AAAA;AAI3B,O;;;;;;;UAEY;AAAA,sBACN,IADM;;AACX,YAAI,CAAC,QAAKJ,OAAV,EAAmB;AACjB,kBAAKD,SAAL,GAAiB,MAAM,KAAvB;AACA,wBAAO,QAAKA,SAAZ;AACD;;AAJU,qGAKwB,MALxB;AAAA;AAAA,cAKJE,IALI;;AAMX,kBAAKF,SAAL,GAAiBE,IAAI,IAAI,EAAzB;AACA,iBAAO,QAAKF,SAAZ;AAPW;AAQZ,O;;;;;;;EAxFuBS,sB;;AA2F1BlB,WAAW,CAACmB,aAAZ,GAA4BA,qBAA5B;AACAnB,WAAW,CAACoB,OAAZ,GAAsBA,eAAtB;eAEepB,W","sourcesContent":["import Pop3Connection from './Connection.mjs';\n\nimport { stream2String, listify } from './helper.mjs';\n\nclass Pop3Command extends Pop3Connection {\n constructor({\n user,\n password,\n host,\n port,\n tls,\n timeout,\n tlsOptions,\n servername\n }) {\n super({ host, port, tls, timeout, tlsOptions, servername });\n this.user = user;\n this.password = password;\n this._PASSInfo = '';\n }\n\n async _connect() {\n if (this._socket) {\n return this._PASSInfo;\n }\n await super.connect();\n await super.command('USER', this.user);\n const [info] = await super.command('PASS', this.password);\n this._PASSInfo = info;\n return this._PASSInfo;\n }\n\n async UIDL(msgNumber = '') {\n await this._connect();\n const [, stream] = await super.command('UIDL', msgNumber);\n const str = await stream2String(stream);\n const list = listify(str);\n return msgNumber ? list[0] : list;\n }\n\n async NOOP() {\n await this._connect();\n await super.command('NOOP');\n return;\n }\n\n async LIST(msgNumber = '') {\n await this._connect();\n const [, stream] = await super.command('LIST', msgNumber);\n const str = await stream2String(stream);\n const list = listify(str);\n return msgNumber ? list[0] : list;\n }\n\n async RSET() {\n await this._connect();\n const [info] = await super.command('RSET');\n return info;\n }\n\n async RETR(msgNumber) {\n await this._connect();\n const [, stream] = await super.command('RETR', msgNumber);\n return stream2String(stream);\n }\n\n async DELE(msgNumber) {\n await this._connect();\n const [info] = await super.command('DELE', msgNumber);\n return info;\n }\n\n async STAT() {\n await this._connect();\n const [info] = await super.command('STAT');\n return info;\n }\n\n async TOP(msgNumber, n = 0) {\n await this._connect();\n const [, stream] = await super.command('TOP', msgNumber, n);\n return stream2String(stream);\n }\n\n async QUIT() {\n if (!this._socket) {\n this._PASSInfo = '' || 'Bye';\n return this._PASSInfo;\n }\n const [info] = await super.command('QUIT');\n this._PASSInfo = info || '';\n return this._PASSInfo;\n }\n}\n\nPop3Command.stream2String = stream2String;\nPop3Command.listify = listify;\n\nexport default Pop3Command;\n"],"file":"Command.js"} \ No newline at end of file diff --git a/lib/Connection.js b/lib/Connection.js index a823ecf..d92498e 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -1,6 +1,6 @@ "use strict"; -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } +function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } Object.defineProperty(exports, "__esModule", { value: true @@ -47,9 +47,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } @@ -75,7 +75,8 @@ var Pop3Connection = /*#__PURE__*/function (_EventEmitter) { port = _ref.port, tls = _ref.tls, timeout = _ref.timeout, - tlsOptions = _ref.tlsOptions; + tlsOptions = _ref.tlsOptions, + servername = _ref.servername; _classCallCheck(this, Pop3Connection); @@ -88,6 +89,7 @@ var Pop3Connection = /*#__PURE__*/function (_EventEmitter) { _this._stream = null; _this._command; _this.tlsOptions = tlsOptions || {}; + _this.servername = servername || host; return _this; } @@ -135,7 +137,8 @@ var Pop3Connection = /*#__PURE__*/function (_EventEmitter) { var host = this.host, port = this.port, - tlsOptions = this.tlsOptions; + tlsOptions = this.tlsOptions, + servername = this.servername; var socket = new _net.Socket(); socket.setKeepAlive(true); return new Promise(function (resolve, reject) { @@ -163,7 +166,8 @@ var Pop3Connection = /*#__PURE__*/function (_EventEmitter) { var options = Object.assign({ host: host, port: port, - socket: socket + socket: socket, + servername: servername }, tlsOptions); _this2._socket = _tls2["default"].connect(options); } else { diff --git a/lib/Connection.js.map b/lib/Connection.js.map index 64d1ebd..c963300 100644 --- a/lib/Connection.js.map +++ b/lib/Connection.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/Connection.mjs"],"names":["value","then","direct","Promise","resolve","Pop3Connection","host","port","tls","timeout","tlsOptions","_socket","_stream","_command","Readable","read","buffer","TERMINATOR_BUFFER_ARRAY","some","_buffer","equals","_endStream","endBuffer","slice","TERMINATOR_BUFFER","push","err","emit","socket","Socket","setKeepAlive","reject","setTimeout","Error","eventName","listeners","length","end","options","Object","assign","_tls","connect","on","_pushStream","command","firstLineEndIndex","indexOf","CRLF_BUFFER","infoBuffer","split","commandName","stream","MULTI_LINE_COMMAND_NAME","includes","_updateStream","bodyBuffer","toString","once","args","join","rejectFn","info","removeListener","write","CRLF","EventEmitter"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;;;AA+EO,gBAAgBA,KAAhB,EAAuBC,IAAvB,EAA6BC,MAA7B,EAAqC;AAC3C,MAAIA,MAAJ,EAAY;AACX,WAAOD,IAAI,GAAGA,IAAI,CAACD,KAAD,CAAP,GAAiBA,KAA5B;AACA;;AACD,MAAI,CAACA,KAAD,IAAU,CAACA,KAAK,CAACC,IAArB,EAA2B;AAC1BD,IAAAA,KAAK,GAAGG,OAAO,CAACC,OAAR,CAAgBJ,KAAhB,CAAR;AACA;;AACD,SAAOC,IAAI,GAAGD,KAAK,CAACC,IAAN,CAAWA,IAAX,CAAH,GAAsBD,KAAjC;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA/EKK,c;;;;;AACJ,gCAMG;AAAA;;AAAA,QALDC,IAKC,QALDA,IAKC;AAAA,QAJDC,IAIC,QAJDA,IAIC;AAAA,QAHDC,GAGC,QAHDA,GAGC;AAAA,QAFDC,OAEC,QAFDA,OAEC;AAAA,QADDC,UACC,QADDA,UACC;;AAAA;;AACD;AACA,UAAKJ,IAAL,GAAYA,IAAZ;AACA,UAAKC,IAAL,GAAYA,IAAI,KAAKC,GAAG,GAAG,GAAH,GAAS,GAAjB,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KnD,QAA3B,SAAsCoD,cAAtC,GAA8C,MAA9C;AACD,WAXM,CAAP;AAhBqB;AA4BtB,O;;;;;;;EAhK0BC,oB;;eAmKd7D,c","sourcesContent":["import { Socket } from 'net';\nimport _tls from 'tls';\nimport { EventEmitter } from 'events';\nimport { Readable } from 'stream';\n\nimport {\n CRLF,\n CRLF_BUFFER,\n TERMINATOR_BUFFER,\n TERMINATOR_BUFFER_ARRAY,\n MULTI_LINE_COMMAND_NAME\n} from './constant.mjs';\n\nclass Pop3Connection extends EventEmitter {\n constructor({\n host,\n port,\n tls,\n timeout,\n tlsOptions,\n }) {\n super();\n this.host = host;\n this.port = port || (tls ? 995 : 110);\n this.tls = tls;\n this.timeout = timeout;\n this._socket = null;\n this._stream = null;\n this._command;\n this.tlsOptions = tlsOptions || {};\n }\n\n _updateStream() {\n this._stream = new Readable({\n read: () => {},\n });\n return this._stream;\n }\n\n _pushStream(buffer) {\n if (TERMINATOR_BUFFER_ARRAY.some((_buffer) => _buffer.equals(buffer))) {\n return this._endStream();\n }\n const endBuffer = buffer.slice(-5);\n if (endBuffer.equals(TERMINATOR_BUFFER)) {\n this._stream.push(buffer.slice(0, -5));\n return this._endStream();\n }\n this._stream.push(buffer);\n }\n\n _endStream(err) {\n if (this._stream) {\n this._stream.push(null);\n }\n this._stream = null;\n this.emit('end', err);\n }\n\n connect() {\n const { host, port, tlsOptions } = this;\n const socket = new Socket();\n socket.setKeepAlive(true);\n return new Promise((resolve, reject) => {\n if (typeof this.timeout !== 'undefined') {\n socket.setTimeout(this.timeout, () => {\n const err = new Error('timeout');\n err.eventName = 'timeout';\n reject(err);\n if (this.listeners('end').length) {\n this.emit('end', err);\n }\n if (this.listeners('error').length) {\n this.emit('error', err);\n }\n this._socket.end();\n this._socket = null;\n });\n }\n if (this.tls) {\n const options = Object.assign({ host, port, socket }, tlsOptions);\n this._socket = _tls.connect(options);\n } else {\n this._socket = socket;\n }\n\n this._socket.on('data', (buffer) => {\n if (this._stream) {\n return this._pushStream(buffer);\n }\n if (buffer[0] === 45) { // '-'\n const err = new Error(buffer.slice(5, -2));\n err.eventName = 'error';\n err.command = this._command;\n return this.emit('error', err);\n }\n if (buffer[0] === 43) { // '+'\n const firstLineEndIndex = buffer.indexOf(CRLF_BUFFER);\n const infoBuffer = buffer.slice(4, firstLineEndIndex);\n const [commandName] = (this._command || '').split(' ');\n let stream = null;\n if (MULTI_LINE_COMMAND_NAME.includes(commandName)) {\n this._updateStream();\n stream = this._stream;\n const bodyBuffer = buffer.slice(firstLineEndIndex + 2);\n if (bodyBuffer[0]) {\n this._pushStream(bodyBuffer);\n }\n }\n this.emit('response', infoBuffer.toString(), stream);\n resolve();\n return;\n }\n const err = new Error('Unexpected response');\n err.eventName = 'bad-server-response';\n reject(err);\n });\n this._socket.on('error', (err) => {\n err.eventName = 'error';\n if (this._stream) {\n this.emit('error', err);\n return;\n }\n reject(err);\n this._socket = null;\n });\n this._socket.once('close', () => {\n const err = new Error('close');\n err.eventName = 'close';\n reject(err);\n this._socket = null;\n });\n this._socket.once('end', () => {\n const err = new Error('end');\n err.eventName = 'end';\n reject(err);\n this._socket = null;\n });\n socket.connect({\n host,\n port,\n });\n });\n }\n\n async command(...args) {\n this._command = args.join(' ');\n if (!this._socket) {\n throw new Error('no-socket');\n }\n await new Promise((resolve, reject) => {\n if (!this._stream) {\n return resolve();\n }\n this.once('error', (err) => {\n return reject(err);\n });\n this.once('end', (err) => {\n return err ? reject(err) : resolve();\n });\n });\n return new Promise((resolve, reject) => {\n const rejectFn = (err) => reject(err);\n this.once('error', rejectFn);\n this.once('response', (info, stream) => {\n this.removeListener('error', rejectFn);\n resolve([info, stream]);\n });\n if (!this._socket) {\n reject(new Error('no-socket'));\n }\n this._socket.write(`${this._command}${CRLF}`, 'utf8');\n });\n }\n}\n\nexport default Pop3Connection;\n"],"file":"Connection.js"} \ No newline at end of file +{"version":3,"sources":["../src/Connection.mjs"],"names":["value","then","direct","Promise","resolve","Pop3Connection","host","port","tls","timeout","tlsOptions","servername","_socket","_stream","_command","Readable","read","buffer","TERMINATOR_BUFFER_ARRAY","some","_buffer","equals","_endStream","endBuffer","slice","TERMINATOR_BUFFER","push","err","emit","socket","Socket","setKeepAlive","reject","setTimeout","Error","eventName","listeners","length","end","options","Object","assign","_tls","connect","on","_pushStream","command","firstLineEndIndex","indexOf","CRLF_BUFFER","infoBuffer","split","commandName","stream","MULTI_LINE_COMMAND_NAME","includes","_updateStream","bodyBuffer","toString","once","args","join","rejectFn","info","removeListener","write","CRLF","EventEmitter"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;;;AA+EO,gBAAgBA,KAAhB,EAAuBC,IAAvB,EAA6BC,MAA7B,EAAqC;AAC3C,MAAIA,MAAJ,EAAY;AACX,WAAOD,IAAI,GAAGA,IAAI,CAACD,KAAD,CAAP,GAAiBA,KAA5B;AACA;;AACD,MAAI,CAACA,KAAD,IAAU,CAACA,KAAK,CAACC,IAArB,EAA2B;AAC1BD,IAAAA,KAAK,GAAGG,OAAO,CAACC,OAAR,CAAgBJ,KAAhB,CAAR;AACA;;AACD,SAAOC,IAAI,GAAGD,KAAK,CAACC,IAAN,CAAWA,IAAX,CAAH,GAAsBD,KAAjC;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA/EKK,c;;;;;AACJ,gCAOG;AAAA;;AAAA,QANDC,IAMC,QANDA,IAMC;AAAA,QALDC,IAKC,QALDA,IAKC;AAAA,QAJDC,GAIC,QAJDA,GAIC;AAAA,QAHDC,OAGC,QAHDA,OAGC;AAAA,QAFDC,UAEC,QAFDA,UAEC;AAAA,QADDC,UACC,QADDA,UACC;;AAAA;;AACD;AACA,UAAKL,IAAL,GAAYA,IAAZ;AACA,UAAKC,IAAL,GAAYA,IAAI,KAAKC,GAAG,GAAG,GAAH,GAAS,GAAjB,CAAhB;AACA,UAAKA,GAAL,GAAWA,GAAX;AACA,UAAKC,OAAL,GAAeA,OAAf;AACA,UAAKG,OAAL,GAAe,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;AACD,mBAAKtB,OAAL,CAAaqD,KAAb,WAAsB,OAAKnD,QAA3B,SAAsCoD,cAAtC,GAA8C,MAA9C;AACD,WAXM,CAAP;AAhBqB;AA4BtB,O;;;;;;;EAlK0BC,oB;;eAqKd9D,c","sourcesContent":["import { Socket } from 'net';\nimport _tls from 'tls';\nimport { EventEmitter } from 'events';\nimport { Readable } from 'stream';\n\nimport {\n CRLF,\n CRLF_BUFFER,\n TERMINATOR_BUFFER,\n TERMINATOR_BUFFER_ARRAY,\n MULTI_LINE_COMMAND_NAME\n} from './constant.mjs';\n\nclass Pop3Connection extends EventEmitter {\n constructor({\n host,\n port,\n tls,\n timeout,\n tlsOptions,\n servername\n }) {\n super();\n this.host = host;\n this.port = port || (tls ? 995 : 110);\n this.tls = tls;\n this.timeout = timeout;\n this._socket = null;\n this._stream = null;\n this._command;\n this.tlsOptions = tlsOptions || {};\n this.servername = servername || host;\n }\n\n _updateStream() {\n this._stream = new Readable({\n read: () => {},\n });\n return this._stream;\n }\n\n _pushStream(buffer) {\n if (TERMINATOR_BUFFER_ARRAY.some((_buffer) => _buffer.equals(buffer))) {\n return this._endStream();\n }\n const endBuffer = buffer.slice(-5);\n if (endBuffer.equals(TERMINATOR_BUFFER)) {\n this._stream.push(buffer.slice(0, -5));\n return this._endStream();\n }\n this._stream.push(buffer);\n }\n\n _endStream(err) {\n if (this._stream) {\n this._stream.push(null);\n }\n this._stream = null;\n this.emit('end', err);\n }\n\n connect() {\n const { host, port, tlsOptions, servername } = this;\n const socket = new Socket();\n socket.setKeepAlive(true);\n return new Promise((resolve, reject) => {\n if (typeof this.timeout !== 'undefined') {\n socket.setTimeout(this.timeout, () => {\n const err = new Error('timeout');\n err.eventName = 'timeout';\n reject(err);\n if (this.listeners('end').length) {\n this.emit('end', err);\n }\n if (this.listeners('error').length) {\n this.emit('error', err);\n }\n this._socket.end();\n this._socket = null;\n });\n }\n if (this.tls) {\n const options = Object.assign({ host, port, socket, servername }, tlsOptions);\n this._socket = _tls.connect(options);\n } else {\n this._socket = socket;\n }\n\n this._socket.on('data', (buffer) => {\n if (this._stream) {\n return this._pushStream(buffer);\n }\n if (buffer[0] === 45) { // '-'\n const err = new Error(buffer.slice(5, -2));\n err.eventName = 'error';\n err.command = this._command;\n return this.emit('error', err);\n }\n if (buffer[0] === 43) { // '+'\n const firstLineEndIndex = buffer.indexOf(CRLF_BUFFER);\n const infoBuffer = buffer.slice(4, firstLineEndIndex);\n const [commandName] = (this._command || '').split(' ');\n let stream = null;\n if (MULTI_LINE_COMMAND_NAME.includes(commandName)) {\n this._updateStream();\n stream = this._stream;\n const bodyBuffer = buffer.slice(firstLineEndIndex + 2);\n if (bodyBuffer[0]) {\n this._pushStream(bodyBuffer);\n }\n }\n this.emit('response', infoBuffer.toString(), stream);\n resolve();\n return;\n }\n const err = new Error('Unexpected response');\n err.eventName = 'bad-server-response';\n reject(err);\n });\n this._socket.on('error', (err) => {\n err.eventName = 'error';\n if (this._stream) {\n this.emit('error', err);\n return;\n }\n reject(err);\n this._socket = null;\n });\n this._socket.once('close', () => {\n const err = new Error('close');\n err.eventName = 'close';\n reject(err);\n this._socket = null;\n });\n this._socket.once('end', () => {\n const err = new Error('end');\n err.eventName = 'end';\n reject(err);\n this._socket = null;\n });\n socket.connect({\n host,\n port,\n });\n });\n }\n\n async command(...args) {\n this._command = args.join(' ');\n if (!this._socket) {\n throw new Error('no-socket');\n }\n await new Promise((resolve, reject) => {\n if (!this._stream) {\n return resolve();\n }\n this.once('error', (err) => {\n return reject(err);\n });\n this.once('end', (err) => {\n return err ? reject(err) : resolve();\n });\n });\n return new Promise((resolve, reject) => {\n const rejectFn = (err) => reject(err);\n this.once('error', rejectFn);\n this.once('response', (info, stream) => {\n this.removeListener('error', rejectFn);\n resolve([info, stream]);\n });\n if (!this._socket) {\n reject(new Error('no-socket'));\n }\n this._socket.write(`${this._command}${CRLF}`, 'utf8');\n });\n }\n}\n\nexport default Pop3Connection;\n"],"file":"Connection.js"} \ No newline at end of file diff --git a/src/Command.mjs b/src/Command.mjs index cd52afb..8d9b61d 100644 --- a/src/Command.mjs +++ b/src/Command.mjs @@ -11,8 +11,9 @@ class Pop3Command extends Pop3Connection { tls, timeout, tlsOptions, + servername }) { - super({ host, port, tls, timeout, tlsOptions }); + super({ host, port, tls, timeout, tlsOptions, servername }); this.user = user; this.password = password; this._PASSInfo = ''; diff --git a/src/Connection.mjs b/src/Connection.mjs index d9895ae..5523593 100644 --- a/src/Connection.mjs +++ b/src/Connection.mjs @@ -18,6 +18,7 @@ class Pop3Connection extends EventEmitter { tls, timeout, tlsOptions, + servername }) { super(); this.host = host; @@ -28,6 +29,7 @@ class Pop3Connection extends EventEmitter { this._stream = null; this._command; this.tlsOptions = tlsOptions || {}; + this.servername = servername || host; } _updateStream() { @@ -58,7 +60,7 @@ class Pop3Connection extends EventEmitter { } connect() { - const { host, port, tlsOptions } = this; + const { host, port, tlsOptions, servername } = this; const socket = new Socket(); socket.setKeepAlive(true); return new Promise((resolve, reject) => { @@ -78,7 +80,7 @@ class Pop3Connection extends EventEmitter { }); } if (this.tls) { - const options = Object.assign({ host, port, socket }, tlsOptions); + const options = Object.assign({ host, port, socket, servername }, tlsOptions); this._socket = _tls.connect(options); } else { this._socket = socket;