| 1 | ##---------------------------------------------------------------------------## | ||
| 2 | ## File: | ||
| 3 | ## $Id: mhindex.pl,v 1.14 2009/05/03 20:11:27 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, $tmpfile, $i, $i_p0, $tmpl, | ||
| 36 | $isfirst, $tmp, $offstart, $offend | ||
| 37 | ); | ||
| 38 | local ($PageNum, $PageSize); # XXX: Use in replace_li_vars() | ||
| 39 | my ($totalpgs); | ||
| 40 | local (*a); | ||
| 41 | |||
| 42 | &compute_page_total(); | ||
| 43 | $PageNum = $onlypg || 1; | ||
| 44 | $totalpgs = $onlypg || $NumOfPrintedPages; | ||
| 45 | if (!scalar(@MListOrder)) { | ||
| 46 | @MListOrder = &sort_messages(); | ||
| 47 | %Index2MLoc = (); | ||
| 48 | @Index2MLoc{@MListOrder} = (0 .. $#MListOrder); | ||
| 49 | } | ||
| 50 | |||
| 51 | for (; $PageNum <= $totalpgs; ++$PageNum) { | ||
| 52 | next if $PageNum < $IdxMinPg; | ||
| 53 | |||
| 54 | $isfirst = 1; | ||
| 55 | |||
| 56 | if ($MULTIIDX) { | ||
| 57 | $offstart = ($PageNum - 1) * $IDXSIZE; | ||
| 58 | $offend = $offstart + $IDXSIZE - 1; | ||
| 59 | $offend = $#MListOrder if $#MListOrder < $offend; | ||
| 60 | @a = @MListOrder[$offstart .. $offend]; | ||
| 61 | |||
| 62 | if ($PageNum > 1) { | ||
| 63 | $IDXPATHNAME = join("", | ||
| 64 | $OUTDIR, $DIRSEP, $IDXPREFIX, $PageNum, ".", $HtmlExt); | ||
| 65 | } else { | ||
| 66 | $IDXPATHNAME = join($DIRSEP, $OUTDIR, $IDXNAME); | ||
| 67 | } | ||
| 68 | |||
| 69 | } else { | ||
| 70 | if ($IDXSIZE && (($i = ($#MListOrder + 1) - $IDXSIZE) > 0)) { | ||
| 71 | if ($REVSORT) { | ||
| 72 | @a = @MListOrder[0 .. ($IDXSIZE - 1)]; | ||
| 73 | } else { | ||
| 74 | @a = @MListOrder[$i .. $#MListOrder]; | ||
| 75 | } | ||
| 76 | } else { | ||
| 77 | *a = *MListOrder; | ||
| 78 | } | ||
| 79 | $IDXPATHNAME = join($DIRSEP, $OUTDIR, $IDXNAME); | ||
| 80 | } | ||
| 81 | $PageSize = scalar(@a); | ||
| 82 | |||
| 83 | ## Open/create index file | ||
| 84 | if ($IDXONLY) { | ||
| 85 | $outhandle = \*STDOUT; | ||
| 86 | } else { | ||
| 87 | ($outhandle, $tmpfile) = file_temp('midxXXXXXXXXXX', $OUTDIR); | ||
| 88 | } | ||
| 89 | print STDOUT "Writing $IDXPATHNAME ...\n" unless $QUIET; | ||
| 90 | |||
| 91 | ## Print top part of index | ||
| 92 | &output_maillist_head($outhandle); | ||
| 93 | |||
| 94 | ## Output links to messages | ||
| 95 | |||
| 96 | if ($NOSORT) { | ||
| 97 | foreach $index (@a) { | ||
| 98 | ($tmpl = $LITMPL) =~ s/$VarExp/&replace_li_var($1,$index)/geo; | ||
| 99 | print $outhandle $tmpl; | ||
| 100 | } | ||
| 101 | |||
| 102 | } elsif ($SUBSORT) { | ||
| 103 | my ($prevsub) = ''; | ||
| 104 | foreach $index (@a) { | ||
| 105 | if (($tmp = get_base_subject($index)) ne $prevsub) { | ||
| 106 | $prevsub = $tmp; | ||
| 107 | if (!$isfirst) { | ||
| 108 | ($tmpl = $SUBJECTEND) =~ | ||
| 109 | s/$VarExp/&replace_li_var($1,$index)/geo; | ||
| 110 | print $outhandle $tmpl; | ||
| 111 | } else { | ||
| 112 | $isfirst = 0; | ||
| 113 | } | ||
| 114 | ($tmpl = $SUBJECTBEG) =~ | ||
| 115 | s/$VarExp/&replace_li_var($1,$index)/geo; | ||
| 116 | print $outhandle $tmpl; | ||
| 117 | } | ||
| 118 | ($tmpl = $LITMPL) =~ s/$VarExp/&replace_li_var($1,$index)/geo; | ||
| 119 | print $outhandle $tmpl; | ||
| 120 | } | ||
| 121 | ($tmpl = $SUBJECTEND) =~ s/$VarExp/&replace_li_var($1,$index)/geo; | ||
| 122 | print $outhandle $tmpl; | ||
| 123 | |||
| 124 | } elsif ($AUTHSORT) { | ||
| 125 | local ($prevauth) = ''; | ||
| 126 | foreach $index (@a) { | ||
| 127 | if (($tmp = &get_base_author($index)) ne $prevauth) { | ||
| 128 | $prevauth = $tmp; | ||
| 129 | if (!$isfirst) { | ||
| 130 | ($tmpl = $AUTHEND) =~ | ||
| 131 | s/$VarExp/&replace_li_var($1,$index)/geo; | ||
| 132 | print $outhandle $tmpl; | ||
| 133 | } else { | ||
| 134 | $isfirst = 0; | ||
| 135 | } | ||
| 136 | ($tmpl = $AUTHBEG) =~ | ||
| 137 | s/$VarExp/&replace_li_var($1,$index)/geo; | ||
| 138 | print $outhandle $tmpl; | ||
| 139 | } | ||
| 140 | ($tmpl = $LITMPL) =~ s/$VarExp/&replace_li_var($1,$index)/geo; | ||
| 141 | print $outhandle $tmpl; | ||
| 142 | } | ||
| 143 | ($tmpl = $AUTHEND) =~ s/$VarExp/&replace_li_var($1,$index)/geo; | ||
| 144 | print $outhandle $tmpl; | ||
| 145 | |||
| 146 | } else { | ||
| 147 | my ($prevdate) = ''; | ||
| 148 | my ($time); | ||
| 149 | foreach $index (@a) { | ||
| 150 | $time = $Time{$index}; | ||
| 151 | $tmp = join("", | ||
| 152 | $UseLocalTime | ||
| 153 | ? (localtime($time))[3, 4, 5] | ||
| 154 | : (gmtime($time))[3, 4, 5]); | ||
| 155 | if ($tmp ne $prevdate) { | ||
| 156 | $prevdate = $tmp; | ||
| 157 | if (!$isfirst) { | ||
| 158 | ($tmpl = $DAYEND) =~ | ||
| 159 | s/$VarExp/&replace_li_var($1,$index)/geo; | ||
| 160 | print $outhandle $tmpl; | ||
| 161 | } else { | ||
| 162 | $isfirst = 0; | ||
| 163 | } | ||
| 164 | ($tmpl = $DAYBEG) =~ | ||
| 165 | s/$VarExp/&replace_li_var($1,$index)/geo; | ||
| 166 | print $outhandle $tmpl; | ||
| 167 | } | ||
| 168 | ($tmpl = $LITMPL) =~ s/$VarExp/&replace_li_var($1,$index)/geo; | ||
| 169 | print $outhandle $tmpl; | ||
| 170 | } | ||
| 171 | ($tmpl = $DAYEND) =~ s/$VarExp/&replace_li_var($1,$index)/geo; | ||
| 172 | print $outhandle $tmpl; | ||
| 173 | } | ||
| 174 | |||
| 175 | ## Print bottom part of index | ||
| 176 | &output_maillist_foot($outhandle); | ||
| 177 | if (!$IDXONLY) { | ||
| 178 | close($outhandle); | ||
| 179 | file_gzip($tmpfile) if $GzipFiles; | ||
| 180 | file_chmod(file_rename($tmpfile, $IDXPATHNAME)); | ||
| 181 | } | ||
| 182 | } | ||
| 183 | } | ||
| 184 | |||
| 185 | ##--------------------------------------------------------------------------- | ||
| 186 | ## output_maillist_head() outputs the beginning of the index page. | ||
| 187 | ## | ||
| 188 | sub output_maillist_head { | ||
| 189 | my $handle = shift; | ||
| 190 | local $index = ""; | ||
| 191 | my ($tmp); | ||
| 192 | |||
| 193 | $tmp = ($IDXPGSSMARKUP ne '') ? $IDXPGSSMARKUP : $SSMARKUP; | ||
| 194 | if ($tmp ne '') { | ||
| 195 | $tmp =~ s/$VarExp/&replace_li_var($1,'')/geo; | ||
| 196 | print $handle $tmp; | ||
| 197 | } | ||
| 198 | |||
| 199 | print $handle "<!-- ", &commentize("MHonArc v$VERSION"), " -->\n"; | ||
| 200 | |||
| 201 | ## Output title | ||
| 202 | ($tmp = $IDXPGBEG) =~ s/$VarExp/&replace_li_var($1,'')/geo; | ||
| 203 | print $handle $tmp; | ||
| 204 | |||
| 205 | ## Output start of index | ||
| 206 | ($tmp = $LIBEG) =~ s/$VarExp/&replace_li_var($1,'')/geo; | ||
| 207 | print $handle $tmp; | ||
| 208 | } | ||
| 209 | |||
| 210 | ##--------------------------------------------------------------------------- | ||
| 211 | ## output_maillist_foot() outputs the end of the index page. | ||
| 212 | ## | ||
| 213 | sub output_maillist_foot { | ||
| 214 | my $handle = shift; | ||
| 215 | local $index = ""; | ||
| 216 | my ($tmp); | ||
| 217 | |||
| 218 | ## Close message listing | ||
| 219 | ($tmp = $LIEND) =~ s/$VarExp/&replace_li_var($1,'')/geo; | ||
| 220 | print $handle $tmp; | ||
| 221 | |||
| 222 | &output_doclink($handle); | ||
| 223 | |||
| 224 | ## Close document | ||
| 225 | ($tmp = $IDXPGEND) =~ s/$VarExp/&replace_li_var($1,'')/geo; | ||
| 226 | print $handle $tmp; | ||
| 227 | |||
| 228 | print $handle "<!-- ", &commentize("MHonArc v$VERSION"), " -->\n"; | ||
| 229 | } | ||
| 230 | |||
| 231 | ##--------------------------------------------------------------------------- | ||
| 232 | ## Output link to documentation, if specified | ||
| 233 | ## | ||
| 234 | sub output_doclink { | ||
| 235 | local ($handle) = ($_[0]); | ||
| 236 | if (!$NODOC && $DOCURL) { | ||
| 237 | print $handle "<hr>\n"; | ||
| 238 | print $handle | ||
| 239 | "<address>\n", | ||
| 240 | "Mail converted by ", | ||
| 241 | qq|<a href="$DOCURL">MHonArc</a>\n|, | ||
| 242 | "</address>\n"; | ||
| 243 | } | ||
| 244 | } | ||
| 245 | |||
| 246 | ##--------------------------------------------------------------------------- | ||
| 247 | 1; |