Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | ##---------------------------------------------------------------------------## |
2 | ## File: | |
3 | ## $Id: mhindex.pl,v 1.10 2002/06/27 04:56:41 ehood Exp $ | |
4 | ## Author: | |
5 | ## Earl Hood mhonarc@mhonarc.org | |
6 | ## Description: | |
7 | ## Main index routines for mhonarc | |
8 | ##---------------------------------------------------------------------------## | |
9 | ## MHonArc -- Internet mail-to-HTML converter | |
10 | ## Copyright (C) 1995-2001 Earl Hood, mhonarc@mhonarc.org | |
11 | ## | |
12 | ## This program is free software; you can redistribute it and/or modify | |
13 | ## it under the terms of the GNU General Public License as published by | |
14 | ## the Free Software Foundation; either version 2 of the License, or | |
15 | ## (at your option) any later version. | |
16 | ## | |
17 | ## This program is distributed in the hope that it will be useful, | |
18 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ## GNU General Public License for more details. | |
21 | ## | |
22 | ## You should have received a copy of the GNU General Public License | |
23 | ## along with this program; if not, write to the Free Software | |
24 | ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
25 | ## 02111-1307, USA | |
26 | ##---------------------------------------------------------------------------## | |
27 | ||
28 | package mhonarc; | |
29 | ||
30 | ##--------------------------------------------------------------------------- | |
31 | ## write_main_index outputs main index of archive | |
32 | ## | |
33 | sub write_main_index { | |
34 | my $onlypg = shift; | |
35 | my($outhandle, $i, $i_p0, $filename, $tmpl, $isfirst, $tmp, | |
36 | $offstart, $offend); | |
37 | local($PageNum, $PageSize); # XXX: Use in replace_li_vars() | |
38 | my($totalpgs); | |
39 | local(*a); | |
40 | ||
41 | &compute_page_total(); | |
42 | $PageNum = $onlypg || 1; | |
43 | $totalpgs = $onlypg || $NumOfPages; | |
44 | if (!scalar(@MListOrder)) { | |
45 | @MListOrder = &sort_messages(); | |
46 | %Index2MLoc = (); | |
47 | @Index2MLoc{@MListOrder} = (0 .. $#MListOrder); | |
48 | } | |
49 | ||
50 | for ( ; $PageNum <= $totalpgs; ++$PageNum) { | |
51 | next if $PageNum < $IdxMinPg; | |
52 | ||
53 | $isfirst = 1; | |
54 | ||
55 | if ($MULTIIDX) { | |
56 | $offstart = ($PageNum-1) * $IDXSIZE; | |
57 | $offend = $offstart + $IDXSIZE-1; | |
58 | $offend = $#MListOrder if $#MListOrder < $offend; | |
59 | @a = @MListOrder[$offstart..$offend]; | |
60 | ||
61 | if ($PageNum > 1) { | |
62 | $IDXPATHNAME = join("", $OUTDIR, $DIRSEP, | |
63 | $IDXPREFIX, $PageNum, ".", $HtmlExt); | |
64 | } else { | |
65 | $IDXPATHNAME = join($DIRSEP, $OUTDIR, $IDXNAME); | |
66 | } | |
67 | ||
68 | } else { | |
69 | if ($IDXSIZE && (($i = ($#MListOrder+1) - $IDXSIZE) > 0)) { | |
70 | if ($REVSORT) { | |
71 | @a = @MListOrder[0..($IDXSIZE-1)]; | |
72 | } else { | |
73 | @a = @MListOrder[$i..$#MListOrder]; | |
74 | } | |
75 | } else { | |
76 | *a = *MListOrder; | |
77 | } | |
78 | $IDXPATHNAME = join($DIRSEP, $OUTDIR, $IDXNAME); | |
79 | } | |
80 | $PageSize = scalar(@a); | |
81 | ||
82 | ## Open/create index file | |
83 | if ($IDXONLY) { | |
84 | $outhandle = 'STDOUT'; | |
85 | ||
86 | } else { | |
87 | $outhandle = &file_create($IDXPATHNAME, $GzipFiles) || | |
88 | die("ERROR: Unable to create $IDXPATHNAME\n"); | |
89 | } | |
90 | print STDOUT "Writing $IDXPATHNAME ...\n" unless $QUIET; | |
91 | ||
92 | ## Print top part of index | |
93 | &output_maillist_head($outhandle); | |
94 | ||
95 | ## Output links to messages | |
96 | ||
97 | if ($NOSORT) { | |
98 | foreach $index (@a) { | |
99 | ($tmpl = $LITMPL) =~ s/$VarExp/&replace_li_var($1,$index)/geo; | |
100 | print $outhandle $tmpl; | |
101 | } | |
102 | ||
103 | } elsif ($SUBSORT) { | |
104 | my($prevsub) = ''; | |
105 | foreach $index (@a) { | |
106 | if (($tmp = get_base_subject($index)) ne $prevsub) { | |
107 | $prevsub = $tmp; | |
108 | if (!$isfirst) { | |
109 | ($tmpl = $SUBJECTEND) =~ | |
110 | s/$VarExp/&replace_li_var($1,$index)/geo; | |
111 | print $outhandle $tmpl; | |
112 | } else { | |
113 | $isfirst = 0; | |
114 | } | |
115 | ($tmpl = $SUBJECTBEG) =~ | |
116 | s/$VarExp/&replace_li_var($1,$index)/geo; | |
117 | print $outhandle $tmpl; | |
118 | } | |
119 | ($tmpl = $LITMPL) =~ s/$VarExp/&replace_li_var($1,$index)/geo; | |
120 | print $outhandle $tmpl; | |
121 | } | |
122 | ($tmpl = $SUBJECTEND) =~ s/$VarExp/&replace_li_var($1,$index)/geo; | |
123 | print $outhandle $tmpl; | |
124 | ||
125 | } elsif ($AUTHSORT) { | |
126 | local($prevauth) = ''; | |
127 | foreach $index (@a) { | |
128 | if (($tmp = &get_base_author($index)) ne $prevauth) { | |
129 | $prevauth = $tmp; | |
130 | if (!$isfirst) { | |
131 | ($tmpl = $AUTHEND) =~ | |
132 | s/$VarExp/&replace_li_var($1,$index)/geo; | |
133 | print $outhandle $tmpl; | |
134 | } else { | |
135 | $isfirst = 0; | |
136 | } | |
137 | ($tmpl = $AUTHBEG) =~ | |
138 | s/$VarExp/&replace_li_var($1,$index)/geo; | |
139 | print $outhandle $tmpl; | |
140 | } | |
141 | ($tmpl = $LITMPL) =~ s/$VarExp/&replace_li_var($1,$index)/geo; | |
142 | print $outhandle $tmpl; | |
143 | } | |
144 | ($tmpl = $AUTHEND) =~ s/$VarExp/&replace_li_var($1,$index)/geo; | |
145 | print $outhandle $tmpl; | |
146 | ||
147 | } else { | |
148 | my($prevdate) = ''; | |
149 | my($time); | |
150 | foreach $index (@a) { | |
151 | $time = &get_time_from_index($index); | |
152 | $tmp = join("", $UseLocalTime ? (localtime($time))[3,4,5] : | |
153 | (gmtime($time))[3,4,5]); | |
154 | if ($tmp ne $prevdate) { | |
155 | $prevdate = $tmp; | |
156 | if (!$isfirst) { | |
157 | ($tmpl = $DAYEND) =~ | |
158 | s/$VarExp/&replace_li_var($1,$index)/geo; | |
159 | print $outhandle $tmpl; | |
160 | } else { | |
161 | $isfirst = 0; | |
162 | } | |
163 | ($tmpl = $DAYBEG) =~ | |
164 | s/$VarExp/&replace_li_var($1,$index)/geo; | |
165 | print $outhandle $tmpl; | |
166 | } | |
167 | ($tmpl = $LITMPL) =~ s/$VarExp/&replace_li_var($1,$index)/geo; | |
168 | print $outhandle $tmpl; | |
169 | } | |
170 | ($tmpl = $DAYEND) =~ s/$VarExp/&replace_li_var($1,$index)/geo; | |
171 | print $outhandle $tmpl; | |
172 | } | |
173 | ||
174 | ## Print bottom part of index | |
175 | &output_maillist_foot($outhandle); | |
176 | close($outhandle) unless $IDXONLY; | |
177 | } | |
178 | } | |
179 | ||
180 | ##--------------------------------------------------------------------------- | |
181 | ## output_maillist_head() outputs the beginning of the index page. | |
182 | ## | |
183 | sub output_maillist_head { | |
184 | my $handle = shift; | |
185 | local $index = ""; | |
186 | my($tmp); | |
187 | ||
188 | $tmp = ($IDXPGSSMARKUP ne '') ? $IDXPGSSMARKUP : $SSMARKUP; | |
189 | if ($tmp ne '') { | |
190 | $tmp =~ s/$VarExp/&replace_li_var($1,'')/geo; | |
191 | print $handle $tmp; | |
192 | } | |
193 | ||
194 | print $handle "<!-- ", &commentize("MHonArc v$VERSION"), " -->\n"; | |
195 | ||
196 | ## Output title | |
197 | ($tmp = $IDXPGBEG) =~ s/$VarExp/&replace_li_var($1,'')/geo; | |
198 | print $handle $tmp; | |
199 | ||
200 | ## Output start of index | |
201 | ($tmp = $LIBEG) =~ s/$VarExp/&replace_li_var($1,'')/geo; | |
202 | print $handle $tmp; | |
203 | } | |
204 | ||
205 | ##--------------------------------------------------------------------------- | |
206 | ## output_maillist_foot() outputs the end of the index page. | |
207 | ## | |
208 | sub output_maillist_foot { | |
209 | my $handle = shift; | |
210 | local $index = ""; | |
211 | my($tmp); | |
212 | ||
213 | ## Close message listing | |
214 | ($tmp = $LIEND) =~ s/$VarExp/&replace_li_var($1,'')/geo; | |
215 | print $handle $tmp; | |
216 | ||
217 | &output_doclink($handle); | |
218 | ||
219 | ## Close document | |
220 | ($tmp = $IDXPGEND) =~ s/$VarExp/&replace_li_var($1,'')/geo; | |
221 | print $handle $tmp; | |
222 | ||
223 | print $handle "<!-- ", &commentize("MHonArc v$VERSION"), " -->\n"; | |
224 | } | |
225 | ||
226 | ##--------------------------------------------------------------------------- | |
227 | ## Output link to documentation, if specified | |
228 | ## | |
229 | sub output_doclink { | |
230 | local($handle) = ($_[0]); | |
231 | if (!$NODOC && $DOCURL) { | |
232 | print $handle "<hr>\n"; | |
233 | print $handle | |
234 | "<address>\n", | |
235 | "Mail converted by ", | |
236 | qq|<a href="$DOCURL">MHonArc</a> $VERSION\n|, | |
237 | "</address>\n"; | |
238 | } | |
239 | } | |
240 | ||
241 | ##--------------------------------------------------------------------------- | |
242 | 1; |