This file is indexed.

/usr/share/perl5/EmailReminder/Event.pm is in email-reminder 0.7.7-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# This file is part of Email-Reminder.
#
# Email-Reminder 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 3 of the
# License, or (at your option) any later version.
#
# Email-Reminder 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 Email-Reminder; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

package EmailReminder::Event;

# Base class for all other events.
#
# This class should never be used directly, use a derived class instead.

use strict;
use warnings;

use Date::Manip;
use XML::DOM;

use EmailReminder::Utils;

# XML tags
__PACKAGE__->mk_accessors(qw(name));

sub mk_accessors {
    my ($self, @field_names) = @_;

    # get the classname since it might be a derived class calling this
    my $class = ref $self || $self;

    foreach my $field_name ( @field_names ) {
        my $get_method = sub {
            my ($self) = @_;
            my $valid_sub = "valid_$field_name";
            my $value = EmailReminder::Utils::get_node_value($self->{XML_NODE}, $field_name);
            return $self->$valid_sub( $value );
        };

        my $set_method = sub {
            my ($self, $new_value) = @_;
            return EmailReminder::Utils::set_node_value($self->{XML_NODE}, $field_name, $new_value);
        };

        {
            no strict 'refs';
            *{"${class}::get_$field_name"} = $get_method;
            *{"${class}::set_$field_name"} = $set_method;
        }
    }
    return 1;
}

# other XML tags, attributes and values
my $REMINDER_TAG = 'reminder';
my $REMINDERS_TAG = 'reminders';
my $RECIPIENT_TAG = 'recipient';
my $RECIPIENTS_TAG = 'recipients';

my $EMAIL_ATTR = 'email';
my $NAME_ATTR = 'name';
my $TYPE_ATTR = 'type';

my $DAYS_BEFORE_VAL = 'days before';
my $SAME_DAY_VAL = 'same day';

# Hard-coded value for this event's type (class method)
sub get_type
{
    return;
}

# Number of fields this event adds to its parent (class method)
sub get_nb_fields
{
    return 1;
}

sub valid_name {
    my ($class, $new_value) = @_;
    return $new_value;
}

sub new
{
    my $class = shift;
    my $event_node = shift;
    my $id = shift;

    my $self = { "OCCURRING" => 0,
                 "XML_NODE" => $event_node,
                 "ID" => $id,
                 "DATA" => [$id],
            };
    
    bless $self, $class;

    # Create empty data array
    my $count = $self->get_nb_fields() - 1;
    for (my $i = 0; $i < $count; $i++) {
        push(@{$self->{DATA}}, undef);
    }

    # Where to send this reminder email
    my $recipients = $self->{XML_NODE}->getElementsByTagName($RECIPIENTS_TAG)->item(0);
    if (defined($recipients)) {
        $self->{RECIPIENTS_NODE} = $recipients;
        $self->{RECIPIENTS_CACHE} = $self->get_recipients();
    }

    # Process reminders
    my $reminders = $self->{XML_NODE}->getElementsByTagName($REMINDERS_TAG)->item(0);
    if (defined($reminders)) {
        $self->{REMINDERS_NODE} = $reminders;
        $self->{REMINDERS_CACHE} = $self->get_reminders();
    }

    return $self;
}

sub unlink_event
{
    my $self = shift;
    my $node = $self->{XML_NODE};
    $node->getParentNode()->removeChild($node);
    $node->dispose();
    return 1;
}

sub get_recipients
{
    my $self = shift;

    if (!defined($self->{RECIPIENTS_CACHE})) {
        my @recipients = ();

        if (defined($self->{RECIPIENTS_NODE})) {
            foreach my $recipient ($self->{RECIPIENTS_NODE}->getElementsByTagName($RECIPIENT_TAG)) {
                my $email = $recipient->getAttribute($EMAIL_ATTR);
                if (defined($email)) {
                    my $fname = undef;
                    my $lname = undef;
                    my $fullname = $recipient->getAttribute($NAME_ATTR);

                    my @name_parts = split(/ /, $fullname);
                    $fname = $name_parts[0];
                    $lname = $name_parts[-1] if @name_parts > 1;

                    push(@recipients, [$email, $fname, $lname]);
                }
            }
        }
        
        $self->{RECIPIENTS_CACHE} = \@recipients;
    }
    return $self->{RECIPIENTS_CACHE};
}

sub get_reminders
{
    my $self = shift;

    if (!defined($self->{REMINDERS_CACHE})) {
        my @reminders = ();

        if (defined($self->{REMINDERS_NODE}))
        {
            foreach my $reminder ($self->{REMINDERS_NODE}->getElementsByTagName($REMINDER_TAG)){
                my $type = $reminder->getAttribute($TYPE_ATTR);
                
                if ($type eq $SAME_DAY_VAL) {
                    push(@reminders, 0);
                    
                    if ($self->will_occur("")) {
                        $self->{WHEN} = "today";
                        $self->{OCCURRING}++;
                    }
                }
                elsif (($type eq $DAYS_BEFORE_VAL) && 
                       ($reminder->getFirstChild()))
                {
                    my $days = $reminder->getFirstChild()->getNodeValue();
                    push(@reminders, $days);
                    
                    if ($self->will_occur($days)) {
                        if ($days > 1) {
                            my $upcoming_date = DateCalc("today", "+${days}days");
                            $self->{WHEN} = "in $days days (" . UnixDate($upcoming_date, "%A %b %e") . ")";
                        }
                        elsif ($days == 1) {
                            $self->{WHEN} = "tomorrow";
                        }
                        elsif ($days == 0) {
                            $self->{WHEN} = "today";
                        }
                        else { 
                            next; # Negative days are ignored
                        } 
                        
                        $self->{OCCURRING}++;
                    }
                }
            }
        }

        $self->{REMINDERS_CACHE} = \@reminders;
    }

    return $self->{REMINDERS_CACHE};
}

sub set_reminders
{
    my ($self, $new_reminders) = @_;

    my $event = $self->{XML_NODE};
    my $doc = $event->getOwnerDocument();
    my $reminders = $self->{REMINDERS_NODE};

    if (!defined($reminders)) {
        # Create a blank <reminders> tag
        $reminders = $doc->createElement($REMINDERS_TAG);
        $event->appendChild($reminders);

        $self->{REMINDERS_NODE} = $reminders;
    }
    else {
        # TODO: preserve extra reminders in the XML but not in the UI

        # Delete all current reminders
        foreach my $child ($reminders->getChildNodes()) {
            $reminders->removeChild($child);
        }
    }
    
    # Add all reminders to the <reminders> node
    foreach my $nb_days (@$new_reminders)
    {
        my $new_node = $doc->createElement($REMINDER_TAG);
        
        if ($nb_days == 0)
        {
            $new_node->setAttribute($TYPE_ATTR, $SAME_DAY_VAL);
        }
        elsif ($nb_days > 0)
        {
            $new_node->setAttribute($TYPE_ATTR, $DAYS_BEFORE_VAL);
            $new_node->addText($nb_days);
        }
        else
        {
            # Invalid number, ignore
                next;
            }
        
        $reminders->appendChild($new_node);
    }

    # Clear the cache
    undef $self->{REMINDERS_CACHE};

    return 1;
}

sub is_occurring
{
    my $self = shift;
    return $self->{OCCURRING};
}

sub get_message
{
    my $self = shift;

    # destination user
    my $first_name = shift || 'there';

    my $body = $self->get_message_body(@_);

    my $message = "";
    $message = <<"MESSAGEEND" if $body;
Hi $first_name,

$body
Have a good day!

--
Sent by Email-Reminder $EmailReminder::Utils::VERSION
https://launchpad.net/email-reminder
MESSAGEEND

    return $message;
}

sub data
{
    my $self = shift;
    return $self->{DATA};
}

sub get_id
{
    my $self = shift;
    return $self->{ID};
}

1;