From 38540786b3ad39f4f30ceb531c7dabb9b9673098 Mon Sep 17 00:00:00 2001 From: Zane Thomas Date: Fri, 1 Feb 2019 19:29:21 -0800 Subject: [PATCH 1/8] Update nntp.js --- lib/nntp.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/nntp.js b/lib/nntp.js index 88496e5..e756a23 100644 --- a/lib/nntp.js +++ b/lib/nntp.js @@ -159,7 +159,7 @@ NNTP.prototype.connect = function(options) { self.emit('error', new Error('Connection timeout')); }, this.options.connTimeout); - var socket = this._socket = new Socket(); + var socket = this._socket = Socket ? new Socket() : window.Socket; this._socket.setTimeout(0); if (this.options.secure) socket = tls.connect({ socket: this._socket }, onconnect); @@ -170,7 +170,7 @@ NNTP.prototype.connect = function(options) { self._state = 'connected'; self.connected = true; clearTimeout(connTimeout); - + var cmd, params; self._curReq = { cmd: '', @@ -672,7 +672,7 @@ NNTP.prototype._send = function(cmd, params, cb) { this._socket.write(''+this._curReq.params); } else if (this._debug) this._debug('> ' + this._curReq.cmd); - + this._socket.write(B_CRLF); } }; From 85afd6836de22f43fb468c79a6433457a160d635 Mon Sep 17 00:00:00 2001 From: Zane Thomas Date: Fri, 1 Feb 2019 20:05:21 -0800 Subject: [PATCH 2/8] Socket Hack --- lib/nntp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nntp.js b/lib/nntp.js index e756a23..f929df9 100644 --- a/lib/nntp.js +++ b/lib/nntp.js @@ -159,7 +159,7 @@ NNTP.prototype.connect = function(options) { self.emit('error', new Error('Connection timeout')); }, this.options.connTimeout); - var socket = this._socket = Socket ? new Socket() : window.Socket; + var socket = this._socket = Socket ? new Socket() : new window.Socket(); this._socket.setTimeout(0); if (this.options.secure) socket = tls.connect({ socket: this._socket }, onconnect); From 2cc2a36d54855e60c062e7934d5b359617a1e88d Mon Sep 17 00:00:00 2001 From: Zane Thomas Date: Sat, 2 Feb 2019 18:44:28 -0800 Subject: [PATCH 3/8] ensure active request at connection close --- lib/nntp.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/nntp.js b/lib/nntp.js index f929df9..236da14 100644 --- a/lib/nntp.js +++ b/lib/nntp.js @@ -259,9 +259,9 @@ NNTP.prototype.connect = function(options) { else self._stream.emit('end'); self._stream.emit('close', isErr); - } else if (isErr) + } else if (self._curReq && isErr) self._curReq.cb(makeError(ERRORS[code], code)); - else { + else if(self._curReq) { self._curReq.cb(undefined, code, retval, type); self._buffer = ''; } From 11551b0f1bf4d9682cc45ee244695d0b36daf3db Mon Sep 17 00:00:00 2001 From: Zane Thomas Date: Thu, 7 Feb 2019 20:26:10 -0800 Subject: [PATCH 4/8] provide for additional headers --- lib/nntp.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/nntp.js b/lib/nntp.js index 236da14..e3b4dfd 100644 --- a/lib/nntp.js +++ b/lib/nntp.js @@ -609,8 +609,13 @@ NNTP.prototype.groupsDesc = function(search, cb) { }); }; -NNTP.prototype.post = function(msg, cb) { +NNTP.prototype.post = function(msg, headers, cb) { var self = this, composing = true; + + if(typeof headers === 'function') { + cb = headers; + headers = []; + } this._send('POST', undefined, function reentry(err, code, r, type) { if (err || !composing) return cb(err); @@ -639,6 +644,11 @@ NNTP.prototype.post = function(msg, cb) { text += msg.subject; text += CRLF; + headers.forEach(header => { + text += header; + text += CRLF; + }); + text += CRLF; text += (Buffer.isBuffer(msg.body) From 7bf146d408a803e9cf52205ea329788ace92dd90 Mon Sep 17 00:00:00 2001 From: Zane Thomas Date: Sun, 24 Feb 2019 16:30:58 -0800 Subject: [PATCH 5/8] added QUIT to socket.end --- lib/nntp.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/nntp.js b/lib/nntp.js index e3b4dfd..77d6024 100644 --- a/lib/nntp.js +++ b/lib/nntp.js @@ -288,9 +288,9 @@ NNTP.prototype.connect = function(options) { }; NNTP.prototype.end = function() { - if (this._socket && this._socket.writable) - this._socket.end(); - + if (this._socket && this._socket.writable) { + this._socket.end('QUIT'); + } this._socket = undefined; }; From fb91a176ef69781a55eb28bb90fc289782d9d68b Mon Sep 17 00:00:00 2001 From: Zane Thomas Date: Sun, 24 Feb 2019 23:05:15 -0800 Subject: [PATCH 6/8] return posted article --- lib/nntp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nntp.js b/lib/nntp.js index 77d6024..67a61f0 100644 --- a/lib/nntp.js +++ b/lib/nntp.js @@ -618,7 +618,7 @@ NNTP.prototype.post = function(msg, headers, cb) { } this._send('POST', undefined, function reentry(err, code, r, type) { if (err || !composing) - return cb(err); + return cb(err,text); var CRLF = '\r\n', text; From 4794d701fb93690da6605180ef99b1e7551ba491 Mon Sep 17 00:00:00 2001 From: Zane Thomas Date: Sun, 24 Feb 2019 23:17:57 -0800 Subject: [PATCH 7/8] return posted --- lib/nntp.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/nntp.js b/lib/nntp.js index 67a61f0..8fdd6f0 100644 --- a/lib/nntp.js +++ b/lib/nntp.js @@ -611,6 +611,7 @@ NNTP.prototype.groupsDesc = function(search, cb) { NNTP.prototype.post = function(msg, headers, cb) { var self = this, composing = true; + let posted; if(typeof headers === 'function') { cb = headers; @@ -618,7 +619,7 @@ NNTP.prototype.post = function(msg, headers, cb) { } this._send('POST', undefined, function reentry(err, code, r, type) { if (err || !composing) - return cb(err,text); + return cb(err,posted); var CRLF = '\r\n', text; @@ -663,6 +664,7 @@ NNTP.prototype.post = function(msg, headers, cb) { text += '\r\n.'; composing = false; + posted = text; self._send(text, undefined, reentry); }); }; From 87d24d93f29768cc196b58de9444f88c4ea26634 Mon Sep 17 00:00:00 2001 From: Zane Thomas Date: Sun, 21 Jun 2020 10:28:43 -0700 Subject: [PATCH 8/8] made needed mods --- lib/nntp.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/nntp.js b/lib/nntp.js index 8fdd6f0..b378ab7 100644 --- a/lib/nntp.js +++ b/lib/nntp.js @@ -160,7 +160,7 @@ NNTP.prototype.connect = function(options) { }, this.options.connTimeout); var socket = this._socket = Socket ? new Socket() : new window.Socket(); - this._socket.setTimeout(0); + this._socket.setTimeout(this.options.timeout ? this.options.timeout : 0); if (this.options.secure) socket = tls.connect({ socket: this._socket }, onconnect); else @@ -322,6 +322,7 @@ NNTP.prototype.stat = function(id, cb) { }; NNTP.prototype.group = function(group, cb) { + debugger; var self = this; this._send('GROUP', group, function(err, code, r, type) { if (err)