Add ParseHeaders() to library.
Signed-off-by: Thomas Hochstein <thh@thh.name>
This commit is contained in:
parent
0a0e615ede
commit
73a2d70f16
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
# 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
|
||||
# which Perl itself is published.
|
||||
|
@ -34,6 +34,7 @@ require Exporter;
|
|||
ListNewsgroups
|
||||
ParseHierarchies
|
||||
ReadGroupList
|
||||
ParseHeaders
|
||||
OutputData
|
||||
FormatOutput
|
||||
SQLHierarchies
|
||||
|
@ -254,6 +255,42 @@ sub ReadGroupList {
|
|||
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 ----------------------------#####
|
||||
|
|
Loading…
Reference in a new issue