-
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
22 changed files
with
897 additions
and
74 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,75 @@ | ||
// 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 { | ||
let msg = await session.server._getArticle(session, String(session.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; | ||
} | ||
}; |
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,41 @@ | ||
// https://tools.ietf.org/html/rfc3977#section-6.1.3 | ||
// | ||
'use strict'; | ||
|
||
|
||
const status = require('../status'); | ||
|
||
|
||
const CMD_RE = /^LAST$/i; | ||
|
||
|
||
module.exports = { | ||
head: 'LAST', | ||
validate: CMD_RE, | ||
pipeline: true, | ||
|
||
run(session/*, cmd*/) { | ||
if (!session.group.name) { | ||
return status._412_GRP_NOT_SLCTD; | ||
} | ||
|
||
let cursor = session.current_article; | ||
|
||
if (cursor < 0) { | ||
return status._420_ARTICLE_NOT_SLCTD; | ||
} | ||
|
||
return session.server._getNext(session, cursor, false) | ||
.then(msg => { | ||
if (!msg) { | ||
return status._422_NO_LAST_ARTICLE; | ||
} | ||
|
||
session.current_article = msg.index; | ||
|
||
let msg_id = session.server._buildHeaderField(session, msg, 'message-id'); | ||
|
||
return `${status._223_ARTICLE_EXISTS} ${msg.index} ${msg_id}`; | ||
}); | ||
} | ||
}; |
Oops, something went wrong.