node-nntp の例を試してみました。次の例は misc.test で機能しますが、他のグループを試すと、メッセージ ID または記事番号が渡されない場合、記事関数は最初の記事の取得に失敗します。有効な記事番号をパラメーターとして渡すと機能することがわかりました。 .
高い記事数をパラメーター firstArticle として渡そうとしましたが、これは失敗します。NodeとJavascriptは初めてなので、なぜそうなのかわかりません。c.article の最初のパラメーターを同じ記事番号でハードコーディングすると機能しますが、記事番号をパラメーターとして渡して記事を取得したいのは明らかです。
var NNTP = require('nntp'),
inspect = require('util').inspect;
var c = new NNTP();
c.on('ready', function() {
var firstArticle;
c.group('test.group', function(err, count, low, high) {
console.log(count);
console.log(low);
console.log(high);
firstArticle = high;
if (err) throw err;
});
c.article(firstArticle,function(err, n, id, headers, body) {
console.log('firstArticle: ' + firstArticle);
if (err) throw err;
console.log('Article #' + n);
console.log('Article ID: ' + id);
console.log('Article headers: ' + inspect(headers));
console.log('Article body: ' + inspect(body.toString()));
});
});
c.on('error', function(err) {
console.log('Error: ' + err);
});
c.on('close', function(had_err) {
console.log('Connection closed');
});
c.connect({
host: 'news,test.com',
user: 'username',
password: 'password'
});