+{ # test setting NNTP headers in HEAD and ARTICLE requests
+ my $u = 'https://example.com/a/';
+ my $ibx = PublicInbox::Inbox->new({ name => 'test',
+ inboxdir => 'test.git',
+ address => 'a@example.com',
+ -primary_address => 'a@example.com',
+ newsgroup => 'test',
+ domain => 'example.com',
+ url => [ '//example.com/a' ]});
+ is($ibx->base_url, $u, 'URL expanded');
+ my $mid = 'a@b';
+ my $mime = PublicInbox::Eml->new("Message-ID: <$mid>\r\n\r\n");
+ my $hdr = $mime->header_obj;
+ my $mock_self = {
+ nntpd => {
+ servername => 'example.com',
+ pi_cfg => bless {}, 'PublicInbox::Config',
+ },
+ ibx => $ibx,
+ };
+ my $smsg = { num => 1, mid => $mid, nntp => $mock_self, -ibx => $ibx };
+ PublicInbox::NNTP::set_nntp_headers($hdr, $smsg);
+ is_deeply([ $mime->header('Message-ID') ], [ "<$mid>" ],
+ 'Message-ID unchanged');
+ is_deeply([ $mime->header('Newsgroups') ], [ 'test' ],
+ 'Newsgroups: set');
+ is_deeply([ $mime->header('Xref') ], [ 'example.com test:1' ],
+ 'Xref: set');
+
+ $smsg->{num} = 2;
+ PublicInbox::NNTP::set_nntp_headers($hdr, $smsg);
+ is_deeply([ $mime->header('Message-ID') ], [ "<$mid>" ],
+ 'Message-ID unchanged');
+ is_deeply([ $mime->header('Xref') ], [ 'example.com test:2' ],
+ 'Old Xref: clobbered');
+}
+