🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #87424

Multiple occurences of header fields

#87424
From: dunno
Date: Mon, 09 May 2016 00:15
98 lines
3515 bytes
First I would like to show some code. Here is how my NNTP server works with
headers:

parse_headers ($) {
	my ($headers) = @_;
	my $hdr = {};
	my ($last_key, $last_cell);

	my @headers = split /\r\n/s, $$headers;

	foreach my $headerline (@headers) {
		return undef if length($headerline) > 998;
		return undef if $headerline =~ /^\s+$/;

		if ($headerline =~ m/^(\S+): (.+)$/) {
			my $header_name = lc $1;
			my $header_body = $2;

			return undef if $header_body =~ /^\s*$/;
			unless (exists $hdr->{$header_name}) {
				$last_key = $header_name;
				$last_cell = 0;
				$hdr->{$header_name} = [ $header_body ];
			} else {
				$last_key = $header_name;
				$last_cell = scalar @{ $hdr->{$header_name} };
				$hdr->{$header_name} = [ @{ $hdr->{$header_name} }, $header_body ];
			}
		} else {
			return undef unless ((defined $last_key) and (defined $last_cell));
			$hdr->{$last_key}[$last_cell] .= "\r\n$headerline";
		}
	}

	return $hdr;
}

sub stringify_headers ($) {
	my $hdr = shift;
	my $header = '';

	foreach my $header_name ( keys %$hdr ) {
		for (my $i = 0; $i < scalar @{ $hdr->{$header_name} }; $i++) {
			$header .= "$header_name: $hdr->{$header_name}[$i]\r\n";
		}
	}
	return \$header;
}

As you can see, initially all headers are treated as if they can occur more
than once. While validating article I also check that certain headers
mentioned in RFC 5536 do not occur more than once:

sub no_duplicate_headers ($) {
	my $hdr = shift;
	my @headers_names = qw(
		approved
		archive
		control
		distribution
		expires
		followup-to
		injection-date
		injection-info
		keywords
		lines
		message-id
		newsgroups
		organization
		path
		summary
		supersedes
		user-agent
	);

	foreach my $header_name ( @headers_names ) {
		if (exists $hdr->{$header_name}) {
			if (scalar @{ $hdr->{$header_name} } > 1) {
				return undef;
			}
		}
	}

	return 1;
}

That is my understanding of RFC: unless multiple occurrences of header
field are explicitly prohibited, they are allowed and therefore should be
preserved in injected article. However, it seems that nnrpd is stripping
every occurrence of header field except the last one. Am I missing
something? Is there any specific reason for that? I can tell that innd
allows multiple occurrences because I see multiple X-Abuse-And-DMCA-Info:
headers in articles propagated from Giganews.

-- 
dunno

Technical Details
Message-ID: <2116899503.484444288.248931.dunno-dunno.dunno@news.mixmin.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.(19219).mbox.7z!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <2116899503.484444288.248931.dunno-dunno.dunno@news.mixmin.net>
Subject: Multiple occurences of header fields
Date: Mon, 09 May 2016 00:15:58 +0000
From: dunno <dunno@dunno.dunno>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.(19219).mbox.7z!not-for-mail
Newsgroups: news.software.nntp
Organization: dunno
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 9 May 2016 00:15:58 -0000 (UTC)
Injection-Info: news.mixmin.net; posting-host="5561036253eb7a2644fe9496ece424342d5b692b";
 logging-data="14459"; mail-complaints-to="abuse@mixmin.net"
User-Agent: NewsTap/5.1.8 (iPhone/iPod Touch)
Cancel-Lock: sha1:0kWJQUfhcF3aI2L+jGze2JqDRQk=
X-Face: +Y@4$e3-8y^:[5%r>Y6xxT0FVGRQ%3F"zg9+i6@7@t0}rtq3S8)2":;YgvZ5~2cI}rUZ$X$ sYT%EO6}l1DF*"<0$clFtjHZYnH:ZAf3ShT.Ovq
X-Received-Body-CRC: 4134985696
X-Received-Bytes: 3450