Add ParseHeaders() to library.

Signed-off-by: Thomas Hochstein <thh@thh.name>
This commit is contained in:
Thomas Hochstein 2025-05-10 21:09:25 +02:00
parent 0a0e615ede
commit 73a2d70f16

View file

@ -2,7 +2,7 @@
# #
# Library functions for the NewsStats package. # Library functions for the NewsStats package.
# #
# Copyright (c) 2010-2013 Thomas Hochstein <thh@thh.name> # Copyright (c) 2010-2013, 2025 Thomas Hochstein <thh@thh.name>
# #
# This module can be redistributed and/or modified under the same terms under # This module can be redistributed and/or modified under the same terms under
# which Perl itself is published. # which Perl itself is published.
@ -34,6 +34,7 @@ require Exporter;
ListNewsgroups ListNewsgroups
ParseHierarchies ParseHierarchies
ReadGroupList ReadGroupList
ParseHeaders
OutputData OutputData
FormatOutput FormatOutput
SQLHierarchies SQLHierarchies
@ -254,6 +255,42 @@ sub ReadGroupList {
return \%ValidGroups; return \%ValidGroups;
}; };
################################################################################
sub ParseHeaders {
################################################################################
### return a hash of all headers (ignoring duplicate headers)
### parsed from raw headers
### -> taken and modified from pgpverify
### -> Written April 1996, <tale@isc.org> (David C Lawrence)
### -> Currently maintained by Russ Allbery <eagle@eyrie.org>
### IN : $RawHeaders : raw headers as found in posting
### OUT: %Headers : hash containing header contents,
### keyed by lower-case header name
my (%Header, $Label, $Value);
foreach (@_) {
s/\r?\n$//;
last if /^$/;
if (/^(\S+):[ \t](.+)/) {
($Label, $Value) = ($1, $2);
# discard all duplicate headers
next if $Header{lc($Label)};
$Header{lc($Label)} = $Value;
} elsif (/^\s/) {
# continuation lines
if ($Label) {
$Header{lc($Label)} .= "\n$_";
} else {
warn (sprintf("Non-header line: %s\n",$_));
}
} else {
warn (sprintf("Non-header line: %s\n",$_));
}
}
return %Header;
};
################################################################################ ################################################################################
#####----------------------------- TimePeriods ----------------------------##### #####----------------------------- TimePeriods ----------------------------#####