Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / mhmsgfile.pl
CommitLineData
86530b38
AT
1##---------------------------------------------------------------------------##
2## File:
3## $Id: mhmsgfile.pl,v 1.6 2001/09/17 16:10:28 ehood Exp $
4## Author:
5## Earl Hood mhonarc@mhonarc.org
6## Description:
7## MHonArc library for dealing with HTML message files. Mainly
8## for parsing existing message files inorder to extract archive
9## related data.
10##---------------------------------------------------------------------------##
11## MHonArc -- Internet mail-to-HTML converter
12## Copyright (C) 1998-1999 Earl Hood, mhonarc@mhonarc.org
13##
14## This program is free software; you can redistribute it and/or modify
15## it under the terms of the GNU General Public License as published by
16## the Free Software Foundation; either version 2 of the License, or
17## (at your option) any later version.
18##
19## This program is distributed in the hope that it will be useful,
20## but WITHOUT ANY WARRANTY; without even the implied warranty of
21## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22## GNU General Public License for more details.
23##
24## You should have received a copy of the GNU General Public License
25## along with this program; if not, write to the Free Software
26## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27## 02111-1307, USA
28##---------------------------------------------------------------------------##
29
30package mhonarc;
31
32##---------------------------------------------------------------------------##
33## Dependent libraries:
34##---------------------------------------------------------------------------##
35require 'ewhutil.pl';
36require 'mhtime.pl';
37
38##---------------------------------------------------------------------------##
39## parse_data_from_msg(): Function to parse the initial comment
40## declarations of a MHonArc message file into a hash. A refernce
41## to resulting hash is returned. Keys are the field names, and
42## values are arrays of field values.
43##
44sub parse_data_from_msg {
45 my $fh = shift; # An open filehandle
46 my %field = ();
47 my($field, $value);
48 local($_);
49
50 while (<$fh>) {
51 last if /^<!--X-Head-End/; # All done
52 next unless s/^<!--X-//; # Skip non-field lines
53 chomp; # Drop EOL
54 s/ -->$//; # Remove comc
55 ($field, $value) = split(/: /, $_, 2);
56 push(@{$field{lc $field}}, uncommentize($value));
57 }
58 \%field;
59}
60
61##---------------------------------------------------------------------------##
62## load_date_from_msg_file(): Function to read db data from a
63## a MHonArc message file directly into db hashes.
64##
65sub load_data_from_msg_file {
66 my $filename = shift; # Name of file to read
67 my $msgnum = shift; # Message number for file
68 local(*MSGFILE);
69
70 if (!open(MSGFILE, $filename)) {
71 warn qq/Warning: Unable to open "$filename": $!\n/;
72 return 0;
73 }
74
75 my $href = parse_data_from_msg(\*MSGFILE);
76 close(MSGFILE);
77
78 if (!defined($href->{'subject'})) {
79 warn qq/Warning: Unable to find Subject for "$filename"\n/;
80 return 0;
81 }
82
83 my $index = "";
84 my $date = $href->{'date'}[0];
85
86 ## Determine date of message
87 if (($date =~ /\S/) && (@array = parse_date($date))) {
88 $index = get_time_from_date(@array[1..$#array]);
89 } else {
90 $index = time;
91 $date = &time2str("", $index, 1) unless $date =~ /\S/;
92 }
93 $index .= $X . int($msgnum);
94
95 ## Assign data to hashes
96 $Date{$index} = $date;
97 $Subject{$index} = $href->{'subject'}[0];
98 if (defined($href->{'from-r13'})) {
99 $From{$index} = &mrot13($href->{'from-r13'}[0]);
100 } elsif (defined($href->{'from'})) {
101 $From{$index} = $href->{'from'}[0];
102 } else {
103 $From{$index} = 'Anonymous';
104 }
105 if (defined($href->{'message-id'})) {
106 $Index2MsgId{$index} = $href->{'message-id'}[0];
107 $MsgId{$href->{'message-id'}[0]} = $index;
108 $NewMsgId{$href->{'message-id'}[0]} = $index;
109 }
110
111 if (defined($href->{'content-type'})) {
112 $ContentType{$index} = $href->{'content-type'}[0];
113 } elsif (defined($href->{'contenttype'})) { # older versions
114 $ContentType{$index} = $href->{'contenttype'}[0];
115 }
116
117 if (defined($href->{'reference'})) {
118 $Refs{$index} = $href->{'reference'};
119 } elsif (defined($href->{'reference-id'})) { # older versions
120 $Refs{$index} = $href->{'reference-id'};
121 }
122
123 if (defined($href->{'derived'})) {
124 $Derived{$index} = $href->{'derived'};
125 }
126
127 $IndexNum{$index} = int($msgnum);
128
129 1;
130}
131
132##---------------------------------------------------------------------------##
1331;