Skip to content

Commit

Permalink
Add Xref to OVER information list
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Apr 25, 2017
1 parent 581dea7 commit c34bdd2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/commands/over.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ module.exports = {
result = session.server._buildHeaderField(session, msg, ':x-article-number') || '0';
}

for (let field of [ 'subject', 'from', 'date', 'message-id', 'references', ':bytes', ':lines' ]) {
for (let field of [ 'subject', 'from', 'date', 'message-id', 'references', ':bytes', ':lines', 'xref' ]) {
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, ' ');

// add xref field to over with 'xref:' prefix; not documented in RFC,
// but servers usually implement it like that
if (field === 'xref' && content) content = 'Xref: ' + content;

result += '\t' + content;
}

Expand Down
8 changes: 5 additions & 3 deletions test/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,11 @@ describe('commands', function () {


describe('OVER', function () {
let over_1_re_by_num = /^0\t\tJohn Doe <j\.doe@example\.org>\t\t<4c51f95eda05@lists\.example\.org>\t\t\d+\t\d+$/;
let over_1_re = /^1\t\tJohn Doe <j\.doe@example\.org>\t\t<4c51f95eda05@lists\.example\.org>\t\t\d+\t\d+$/;
let over_2_re = /^2\t\tRichard Roe <r\.roe@example\.org>\t\t<d417dea0c7a3@lists\.example\.org>\t\t\d+\t\d+$/;
/* eslint-disable max-len */
let over_1_re_by_num = /^0\t\tJohn Doe <j\.doe@example\.org>\t\t<4c51f95eda05@lists\.example\.org>\t\t\d+\t\d+\tXref: localhost test.groups.foo:1$/;
let over_1_re = /^1\t\tJohn Doe <j\.doe@example\.org>\t\t<4c51f95eda05@lists\.example\.org>\t\t\d+\t\d+\tXref: localhost test.groups.foo:1$/;
let over_2_re = /^2\t\tRichard Roe <r\.roe@example\.org>\t\t<d417dea0c7a3@lists\.example\.org>\t\t\d+\t\d+\t$/;
/* eslint-enable max-len */

it('should get overview by message id', function () {
return client
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ messages:
ts: 1997-01-15 2:59:43.10
head: |
From: John Doe <j.doe@example.org>
Xref: localhost test.groups.foo:1
body: |
first message in first group
-
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/mock_db.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ module.exports = function mock_db(nntp, fixture_path) {

default:
let match = msg.head.split('\n')
.map(str => str.split(/:\s*/, 2))
.filter(arr => arr[0].toLowerCase() === field);
.map(str => str.match(/^(.*?):\s*(.*)$/))
.filter(m => m && m[1].toLowerCase() === field);

return match.length ? match[0][1] : null;
return match.length ? match[0][2] : null;
}
};

Expand Down

0 comments on commit c34bdd2

Please sign in to comment.