1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
#-*- perl -*-
#
# Copyright (C) 2003,2004,2005 Ken'ichi Fukamachi
# All rights reserved. This program is free software; you can
# redistribute it and/or modify it under the same terms as Perl itself.
#
# $FML: Thread.pm,v 1.8 2005/08/25 13:39:45 fukachan Exp $
#
package Mail::Message::Thread;
use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
use Carp;
use File::Spec;
=head1 NAME
Mail::Message::Thread - Thread interface
=head1 SYNOPSIS
... lock by something ...
... unlock by something ...
This module itself provides no lock function.
please use flock() built in perl or CPAN lock modules for it.
=head1 DESCRIPTION
=head1 METHODS
=head2 new()
initialize DB (udb) interface.
=cut
# Descriptions: constructor.
# Arguments: OBJ($self) HASH_REF($args)
# Side Effects: none
# Return Value: OBJ
sub new
{
my ($self, $args) = @_;
my ($type) = ref($self) || $self;
my $me = {};
my $ndb = _init_db($me, $args);
$me->{ _ndb } = $ndb;
return bless $me, $type;
}
# Descriptions: initialize Mail::Message::DB object.
# Arguments: OBJ($self) HASH_REF($args)
# Side Effects: DB object created.
# Return Value: OBJ
sub _init_db
{
my ($self, $args) = @_;
my $db_type = $args->{ db_type } || 'AnyDBM_File';
my $db_base = $args->{ db_base_dir } || croak("specify db_base_dir\n");
my $db_name = $args->{ db_name } || croak("specify db_name\n");
my $id = $args->{ id } || 0;
use File::Spec;
my $db_dir = File::Spec->catfile($db_base, $db_name);
unless (-d $db_base) { mkdir($db_base, 0755);}
unless (-d $db_dir) { mkdir($db_dir, 0755);}
my $_db_args = {
db_module => $db_type, # AnyDBM_File
db_base_dir => $db_dir, # /var/spool/ml/@udb@/elena
db_name => $db_name, # elena
# old db_dir in non UDB age: ~fml/public_html/.../elena/
old_db_base_dir => $args->{ output_dir },
};
# Firstly, prepare db object.
use Mail::Message::DB;
my $db = new Mail::Message::DB $_db_args;
$db->set_key($id) if $id;
return $db;
}
=head2 db()
return database object.
=head2 analyze($msg)
top level dispatcher to run thread analyzer.
=cut
# Descriptions: get database object.
# Arguments: OBJ($self)
# Side Effects: none
# Return Value: OBJ
sub db
{
my ($self) = @_;
return( $self->{ _ndb } || undef );
}
# Descriptions: top level dispatcher to run thread analyzer.
# Arguments: OBJ($self) OBJ($msg) NUM($id)
# Side Effects: update database
# Return Value: none
sub analyze
{
my ($self, $msg, $id) = @_;
my $db = $self->db();
$db->add($msg);
}
=head2 get_thread_data($thread_args)
return thread data as HASH_REF.
=cut
# Descriptions: top level dispatcher to get thread data.
# Arguments: OBJ($self) HASH_REF($thread_args)
# Side Effects: update database
# Return Value: HASH_REF
sub get_thread_data
{
my ($self, $thread_args) = @_;
my $db = $self->db();
return $db->get_thread_data($thread_args);
}
=head2 get_thread_member_as_array_ref($head_id)
return id list within the thread specified by $head_id as ARRAY_REF
e.g.a [ $head_id, id1, id2, id3, ... ].
=cut
# Descriptions: return id list within the thread specified by $head_id
# as ARRAY_REF.
# Arguments: OBJ($self) NUM($head_id)
# Side Effects: update database
# Return Value: none
sub get_thread_member_as_array_ref
{
my ($self, $head_id) = @_;
my $db = $self->db();
return $db->get_as_array_ref('ref_key_list', $head_id);
}
=head1 UTILITY
=cut
# Descriptions: set thread status.
# Arguments: OBJ($self) NUM($head_id) STR($status)
# Side Effects: update UDB
# Return Value: none
sub set_thread_status
{
my ($self, $head_id, $status) = @_;
my $db = $self->db();
$db->set('thread_status', $head_id, $status);
}
# Descriptions: get thread status.
# Arguments: OBJ($self) NUM($head_id)
# Side Effects: none
# Return Value: STR
sub get_thread_status
{
my ($self, $head_id) = @_;
my $db = $self->db();
$db->get('thread_status', $head_id);
}
# Descriptions: set article status.
# Arguments: OBJ($self) NUM($id) STR($status)
# Side Effects: update UDB
# Return Value: none
sub set_article_status
{
my ($self, $id, $status) = @_;
my $db = $self->db();
$db->set('article_status', $id, $status);
}
# Descriptions: get article status.
# Arguments: OBJ($self) NUM($id)
# Side Effects: none
# Return Value: STR
sub get_article_status
{
my ($self, $id) = @_;
my $db = $self->db();
$db->get('article_status', $id);
}
# Descriptions: set article summary.
# Arguments: OBJ($self) NUM($id) STR($summary)
# Side Effects: update UDB
# Return Value: none
sub set_article_summary
{
my ($self, $id, $summary) = @_;
my $db = $self->db();
$db->set('article_summary', $id, $summary);
}
# Descriptions: get article summary.
# Arguments: OBJ($self) NUM($id)
# Side Effects: none
# Return Value: STR
sub get_article_summary
{
my ($self, $id) = @_;
my $db = $self->db();
$db->get('article_summary', $id);
}
# Descriptions: destructor.
# Arguments: OBJ($self)
# Side Effects: close db
# Return Value: none
sub DESTROY
{
my ($self) = @_;
my $db = $self->{ _ndb };
if (defined $db) {
$db->DESTROY();
}
}
=head1 TODO
=head1 CODING STYLE
See C<http://www.fml.org/software/FNF/> on fml coding style guide.
=head1 AUTHOR
Ken'ichi Fukamachi
=head1 COPYRIGHT
Copyright (C) 2003,2004,2005 Ken'ichi Fukamachi
All rights reserved. This program is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.
=head1 HISTORY
Mail::Message::Thread first appeared in fml8 mailing list driver package.
See C<http://www.fml.org/> for more details.
This class is renamed from C<Mail::HTML::Lite> 1.40 (2001-2002).
=cut
1;
|