Digest.pm 4.67 KB
Newer Older
1
2
3
4
5
6
7
8
9
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4
# $Id$

# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright (c) 1997, 1998, 1999 Institut Pasteur & Christophe Wolfhugel
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
10
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
11
12
13
# Copyright 2017 The Sympa Community. See the AUTHORS.md file at the top-level
# directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
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
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

package Sympa::Spool::Digest;

use strict;
use warnings;

use Conf;

use base qw(Sympa::Spool);

sub _directories {
    my $self    = shift;
    my %options = @_;

    my $list = ref($self) ? $self->{context} : $options{context};
    die 'bug in logic.  Ask developer' unless ref $list eq 'Sympa::List';

    return {
        parent_directory => $Conf::Conf{'queuedigest'},
46
47
        directory        => $list->get_digest_spool_dir,
        bad_directory    => $list->get_digest_spool_dir . '/bad',
48
49
50
51
52
53
54
55
56
57
58
    };
}

use constant _generator => 'Sympa::Message';

sub _init {
    my $self   = shift;
    my $status = shift;

    unless ($status) {
        # Get earliest time of messages in the spool.
59
60
61
62
63
64
65
66
        my $metadatas = $self->_load || [];
        my $metadata;
        while (my $marshalled = shift @$metadatas) {
            $metadata = Sympa::Spool::unmarshal_metadata(
                $self->{directory},     $marshalled,
                $self->_marshal_regexp, $self->_marshal_keys
            );
            last if $metadata;
67
        }
68
69
        $self->{time} = $metadata ? $metadata->{time} : undef;
        $self->{_metadatas} = undef;    # Rewind cache.
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
    }
    return 1;
}

use constant _marshal_format => '%ld.%f,%ld,%d';
use constant _marshal_keys   => [qw(date TIME PID RAND)];
use constant _marshal_regexp => qr{\A(\d+)\.(\d+\.\d+)(?:,.*)?\z};

sub next {
    my $self = shift;

    my ($message, $handle) = $self->SUPER::next();
    if ($message) {
        # Assign context which is not given by metadata.
        $message->{context} = $self->{context};
    }
    return ($message, $handle);
}

# Old name: Sympa::List::store_digest().
sub store {
    my $self    = shift;
    my $message = shift->dup;

    # Delete original message ID because it can be anonymized.
    delete $message->{message_id};

    return $self->SUPER::store($message);
}

sub get_id {
    my $self = shift;

    if ($self->{context}) {
        if (ref $self->{context} eq 'Sympa::List') {
            return $self->{context}->get_id;
        } else {
            return $self->{context};
        }
    } else {
        return '';
    }
}

1;
__END__

=encoding utf-8

=head1 NAME

Sympa::Spool::Digest - Spool for messages waiting for digest sending

=head1 SYNOPSIS

  use Sympa::Spool::Digest;
  my $spool = Sympa::Spool::Digest->new(context => $list);
  
  $spool->store($message);
  
  my ($message, $handle) = $spool->next;

=head1 DESCRIPTION

L<Sympa::Spool::Digest> implements the spool for messages waiting for
digest sending.

=head2 Methods

See also L<Sympa::Spool/"Public methods">.

=over

=item new ( context =E<gt> $list )

Creates new instance of L<Sympa::Spool::Digest> related to the list $list.

=item next ( )

149
Order is controlled by delivery date, then by reception date.
150

sikeda's avatar
sikeda committed
151
=back
152

sikeda's avatar
sikeda committed
153
=head2 Properties
154

sikeda's avatar
sikeda committed
155
See also L<Sympa::Spool/"Properties">.
156

sikeda's avatar
sikeda committed
157
=over
158
159
160

=item {time}

sikeda's avatar
sikeda committed
161
Earliest time of messages in the spool, or C<undef>.
162
163
164

=back

sikeda's avatar
sikeda committed
165
=head2 Context and metadata
166

sikeda's avatar
sikeda committed
167
See also L<Sympa::Spool/"Marshaling and unmarshaling metadata">.
168

sikeda's avatar
sikeda committed
169
This class particularly gives following metadata:
170
171
172

=over

sikeda's avatar
sikeda committed
173
174
175
176
=item {date}

Unix time when the message was delivered.

177
178
=item {time}

sikeda's avatar
sikeda committed
179
Unix time in floating point number when the message was stored.
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

=back

=head1 CONFIGURATION PARAMETERS

Following site configuration parameters in sympa.conf will be referred.

=over

=item queuedigest

Parent directory path of digest spools.

=back

=head1 SEE ALSO

L<sympa_msg(8)>,
L<Sympa::Message>, L<Sympa::Spool>, L<Sympa::Spool::Digest::Collection>.

=head1 HISTORY

L<Sympa::Spool::Digest> appeared on Sympa 6.2.6.

=cut