-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement HDR, OVER, LAST, NEXT, NEWNEWS commands
- Loading branch information
Showing
20 changed files
with
846 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// https://tools.ietf.org/html/rfc3977#section-8.5 | ||
// | ||
'use strict'; | ||
|
||
|
||
const status = require('../status'); | ||
|
||
|
||
const CMD_RE = /^X?HDR ([^\s]+)(?: (?:(\d{1,15})(-(\d{1,15})?)?|(<[^\s<>]+>))?)?$/i; | ||
|
||
module.exports = { | ||
head: 'HDR', | ||
validate: CMD_RE, | ||
|
||
async run(session, cmd) { | ||
let [ , field, first, dash, last, message_id ] = cmd.match(CMD_RE); | ||
|
||
field = field.toLowerCase(); | ||
|
||
let result = [ status._225_HEADERS_FOLLOW ]; | ||
let list; | ||
|
||
if (typeof message_id !== 'undefined') { | ||
let msg = await session.server._getArticle(session, message_id); | ||
|
||
if (!msg) return status._430_NO_ARTICLE_BY_ID; | ||
|
||
list = [ msg ]; | ||
|
||
} else if (typeof first !== 'undefined') { | ||
first = +first; | ||
|
||
if (!dash) { | ||
last = first; | ||
} else { | ||
last = typeof last === 'undefined' ? session.group.max_index : +last; | ||
} | ||
|
||
if (!session.group.name) return status._412_GRP_NOT_SLCTD; | ||
|
||
list = await session.server._getRange(session, first, last); | ||
|
||
// TODO: status text is slightly wrong | ||
if (!list.length) return status._423_NO_ARTICLE_BY_NUM; | ||
|
||
} else { | ||
if (session.group.current_article <= 0) return status._420_ARTICLE_NOT_SLCTD; | ||
|
||
let msg = await session.server._getArticle(session, String(session.group.current_article)); | ||
|
||
if (!msg) return status._420_ARTICLE_NOT_SLCTD; | ||
|
||
list = [ msg ]; | ||
} | ||
|
||
result = result.concat(list.map(msg => { | ||
let index; | ||
|
||
if (typeof message_id !== 'undefined') { | ||
index = '0'; | ||
} else { | ||
index = msg.index.toString(); | ||
} | ||
|
||
let content = (session.server._buildHeaderField(session, msg, field) || ''); | ||
|
||
// unfolding + replacing invalid characters, see RFC 3977 section 8.3.2 | ||
content = content.replace(/\r?\n/g, '').replace(/[\0\t\r\n]/g, ' '); | ||
|
||
return index + ' ' + content; | ||
})); | ||
|
||
result.push('.'); | ||
|
||
return result; | ||
}, | ||
|
||
capability(session, report) { | ||
report.push('HDR'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// https://tools.ietf.org/html/rfc3977#section-7.6.6 | ||
// | ||
'use strict'; | ||
|
||
|
||
const status = require('../status'); | ||
const wildmat_re = require('../wildmat'); | ||
|
||
|
||
const CMD_RE = /^LIST NEWSGROUPS( ([^\s]+))?$/i; | ||
|
||
|
||
module.exports = { | ||
head: 'LIST NEWSGROUPS', | ||
validate: CMD_RE, | ||
pipeline: true, | ||
|
||
run(session, cmd) { | ||
let wildmat = null; | ||
|
||
if (cmd.match(CMD_RE)[2]) { | ||
try { | ||
wildmat = wildmat_re(cmd.match(CMD_RE)[2]); | ||
} catch (err) { | ||
return `501 ${err.message}`; | ||
} | ||
} | ||
|
||
return session.server._getGroups(session, 0, wildmat) | ||
.then(groups => | ||
[ status._215_INFO_FOLLOWS ] | ||
.concat(groups.map(g => `${g.name}\t${g.description || ''}`)) | ||
.concat([ '.' ]) | ||
); | ||
}, | ||
|
||
capability(session, report) { | ||
report.push([ 'LIST', 'NEWSGROUPS' ]); | ||
} | ||
}; |
Oops, something went wrong.