1 ##--------------------------------------------------------------------------##
3 ## $Id: Namazu.pm,v 1.1 2002/09/03 16:30:47 ehood Exp $
6 ##--------------------------------------------------------------------------##
7 ## Copyright (C) 2002 Earl Hood <earl@earlhood.com>
9 ## This program is free software; you can redistribute it and/or modify
10 ## it under the terms of the GNU General Public License as published by
11 ## the Free Software Foundation; either version 2 of the License, or
12 ## (at your option) any later version.
14 ## This program is distributed in the hope that it will be useful,
15 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ## GNU General Public License for more details.
19 ## You should have received a copy of the GNU General Public License
20 ## along with this program; if not, write to the Free Software
21 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 ##--------------------------------------------------------------------------##
25 package MHArc
::Namazu
;
38 ##--------------------------------------------------------------------------##
44 ##--------------------------------------------------------------------------##
46 sub nmz_msg_id_search
{
47 my $index_dir = shift;
50 # check format of message-id
53 if ($id !~ /\A<[^>]>\Z/) {
57 # Pathname to nmz field message-id file
58 my $id_file = join('/', $index_dir, 'NMZ.field.message-id');
60 warn qq/"$id_file" does not exist\n/;
66 # see if message-id exists in archive
67 if (!open(F
, $id_file)) {
68 warn qq/Unable to open "$id_file": $!\n/;
75 # message-id in file not surrounded by <>'s
92 if (!open(NMZRC
, $file)) {
93 warn qq/Unable to open "$file": $!\n/;
105 my($opt, $value) = split(' ', $_, 2);
107 if ($opt eq 'index') {
109 push(@index, $value);
112 if ($opt eq 'replace') {
114 push(@replace, [ split(' ', $value, 2) ]);
118 $rc->{'index'} = [ @index ];
119 $rc->{'replace'} = [ @replace ];
124 my $index = shift; # Pathname of directory containing namazu index
125 my $docid = shift; # Document ID (i.e. Line number)
126 my $field = lc shift; # Field to get value for
129 my $field_file = join('/', $index, ('NMZ.field.'.$field));
130 my $field_file_i = $field_file . '.i';
133 if (!sysopen(F
, $field_file_i, (O_RDONLY
))) {
134 warn qq/Unable to open "$field_file_i": $!\n/;
137 if (!defined(sysseek(F
, (4*($docid-1)), SEEK_SET
))) {
138 warn qq/Unable to seek on "$field_file_i": $!\n/;
145 my $i = sysread(F
, $bytes, $n, 4-$n);
147 warn qq/sysread error for "$field_file_i": $!\n/;
152 warn qq/Unexpected of EOF for "$field_file_i"\n/;
160 my $offset = unpack('N', $bytes);
161 if (!open(F
, $field_file)) {
162 warn qq/Unable to open "$field_file": $!\n/;
165 if (!seek(F
, $offset, SEEK_SET
)) {
166 warn qq/Unable to seek to $offset on "$field_file": $!\n/;
170 $value = scalar(<F
>);
171 chomp $value if defined($value);
177 ##--------------------------------------------------------------------------##
183 MHArc::Namazu - General Namazu-related utilities for mail archiving system.
191 This module contains a collection of Namazu-related utility routines.
195 The following module variables can be set to affect the behavior
196 of the utility routines:
202 If set to a true value, routines will print out debugging information,
209 By default, no routines are exported into the calling namespace.
210 Routines in this module can be imported by explicitly listing the
211 routines to import in the C<use> declaration:
213 use MHArc::Namazu qw( nmz_get_field );
215 The following routines are availale:
219 =item C<nmz_get_field($index, $docid, $field)>
221 Retrieve the value of a field for a document. C<$index> is the
222 pathname of the directory containing Namazu index files. C<$docid>
223 is the ID of the document to retrieve a field value of. Document
224 ID correlate to the line numbers within C<NMZ.field.I<field-name>>
225 files. C<$field> is the field to retrieve the value of.
227 The return value of this function is the field value, or C<undef> if
228 the field value could not determined.
230 Any error messages generated by this function are printed via Perl's
233 =item C<nmz_load_rc($filename)>
235 Parse Namazu configuration file denoted by C<$filename>. The return
236 value is a hash reference where the keys are the option names (normalized
237 ot lowercases) and the values are the values associated with
238 the options. The actual value types depends on the option.
240 If the conf file cannot be loaded, C<undef> is returned.
250 C<$Id: Namazu.pm,v 1.1 2002/09/03 16:30:47 ehood Exp $>
254 Earl Hood, earl@earlhood.com
256 This module is part of the mharc archiving system and comes with
257 ABSOLUTELY NO WARRANTY and may be copied only under the terms of
258 the GNU General Public License, which may be found in the MHArc