mhnote.pl untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 1 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 82 CC 10 SCAR 47.0
CC
10
Cov
0%
annotate
110.0
CRAP 110.0
1 ##---------------------------------------------------------------------------##
2 ## File:
3 ## $Id: mhnote.pl,v 1.3 2001/09/17 16:10:26 ehood Exp $
4 ## Author:
5 ## Earl Hood mhonarc@mhonarc.org
6 ## Description:
7 ## Annotation routine for MHonArc.
8 ##---------------------------------------------------------------------------##
9 ## MHonArc -- Internet mail-to-HTML converter
10 ## Copyright (C) 1995-1999 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 ## Function for annotating messages.
32 ##
33 sub annotate {
34 my $notetxt = pop(@_); # last arg is note data
35  
36 my (@numbers) = ();
37 my ($key, %Num2Index, $num, $i, $pg, $file);
38 local ($_);
39  
40 ## Create list of messages to annotate
41 foreach (@_) {
42 # range
43 if (/^(\d+)-(\d+)$/) {
44 push(@numbers, $1 .. $2); # range op removes leading zeros
45 next;
46 }
47 # single number
48 if (/^\d+$/) {
49 push(@numbers, int($_)); # int() removes leading zeros
50 next;
51 }
52 # probably message-id
53 push(@numbers, $_);
54 }
55  
56 if ($#numbers < 0) {
57 warn("Warning: No messages specified\n");
58 return 0;
59 }
60  
61 ## Make hash to perform deletions
62 foreach $key (keys %IndexNum) {
63 $Num2Index{$IndexNum{$key}} = $key;
64 }
65  
66 ## Define %Index2MLoc for determining min main index page update
67 $i = 0;
68 foreach $key (sort_messages()) {
69 $Index2MLoc{$key} = $i++;
70 }
71  
72 ## Make sure notes directory exists
73 my $notedir = get_note_dir();
74 if (!-d $notedir and !mkdir($notedir, 0777)) {
75 warn qq/Warning: Unable to create "$notedir": $!\n/;
76 return 0;
77 }
78  
79 ## Annotate messages
80 foreach $num (@numbers) {
81 if ($key = $Num2Index{$num} || $MsgId{$num}) {
82  
83 ## write note to file
84 $file = join($DIRSEP, $notedir,
85 msgid_to_filename($Index2MsgId{$key}));
86 if (!open(NOTEFILE, ">$file")) {
87 warn qq/Warning: Unable to create "$file": $!\n/;
88 next;
89 }
90 print NOTEFILE $notetxt;
91 close NOTEFILE;
92  
93 ## flag message to be updated
94 $Update{$IndexNum{$key}} = 1;
95  
96 ## mark where index page updates start
97 if ($MULTIIDX) {
98 $pg = int($Index2MLoc{$key} / $IDXSIZE) + 1;
99 $IdxMinPg = $pg if ($pg < $IdxMinPg || $IdxMinPg < 0);
100 $pg = int($Index2TLoc{$key} / $IDXSIZE) + 1;
101 $TIdxMinPg = $pg if ($pg < $TIdxMinPg || $TIdxMinPg < 0);
102 }
103  
104 next;
105 }
106  
107 # message not in archive
108 warn qq/Warning: Message "$num" not in archive\n/;
109 }
110  
111 ## Clear data that will get recomputed
112 %Index2MLoc = ();
113  
114 write_pages();
115 1;
116 }
117  
118 ##---------------------------------------------------------------------------##
119 1;