Report.pm 24.3 KB
Newer Older
1
2
3
4
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4
# $Id$

5
# Sympa - SYsteme de Multi-Postage Automatique
6
7
8
9
10
#
# 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
# Copyright (c) 2011, 2012, 2013, 2014 GIP RENATER
11
12
13
14
15
16
17
18
19
20
21
22
#
# 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
23
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
24

25
package Sympa::Report;
26
27

use strict;
28
use warnings;
29

30
use Sympa::Bulk;
31
use Log;
32
33
use Sympa::Message;
use tools;
34

35
### MESSAGE DIFFUSION REPORT ###
36
37
38
39
40
41

############################################################
#  reject_report_msg
############################################################
#  Send a notification to the user about an error rejecting
#  its message diffusion, using mail_tt2/message_report.tt2
42
43
#
# IN : -$type (+): 'intern'||'intern_quiet'||'user'||auth' - the error type
44
45
#      -$error : scalar - the entry in message_report.tt2 if $type = 'user'
#                       - string error for listmaster if $type = 'intern'
46
47
#                       - the entry in authorization reject (called by
#                       message_report.tt2)
48
49
50
51
52
#                               if $type = 'auth'
#      -$user (+): scalar - the user to notify
#      -$param : ref(HASH) - var used in message_report.tt2
#         $param->msg_id (+) if $type='intern'
#      -$robot (+): robot
53
#      -$msg_string : string - rejected msg
54
55
56
57
#      -$list : ref(List)
#
# OUT : 1
#
58
##############################################################
59
sub reject_report_msg {
60
    my ($type, $error, $user, $param, $robot, $msg_string, $list) = @_;
61
    Log::do_log('debug2', '(%s, %s, %s)', $type, $error, $user);
62

63
64
    undef $list unless ref $list eq 'Sympa::List';

65
66
67
68
69
70
    unless ($type eq 'intern'
        or $type eq 'intern_quiet'
        or $type eq 'user'
        or $type eq 'auth'
        or $type eq 'plugin') {
        Log::do_log('err',
71
            "Sympa::Report::reject_report_msg(): error to prepare parsing 'message_report' template to $user : not a valid error type"
72
73
        );
        return undef;
74
75
    }

76
77
    unless ($user) {
        Log::do_log('err',
78
            "Sympa::Report::reject_report_msg(): unable to send template command_report.tt2 : no user to notify"
79
80
        );
        return undef;
81
    }
82
83
84

    unless ($robot) {
        Log::do_log('err',
85
            "Sympa::Report::reject_report_msg(): unable to send template command_report.tt2 : no robot"
86
87
        );
        return undef;
88
89
90
    }

    chomp($user);
91
92
    $param->{'to'}             = $user;
    $param->{'msg'}            = $msg_string;
93
    $param->{'auto_submitted'} = 'auto-replied';
94
    $param->{'entry'}          = $error;
95

96
97
98
99
100
    $param->{'type'} =
          $type eq 'user'   ? 'user_error'
        : $type eq 'auth'   ? 'authorization_reject'
        : $type eq 'plugin' ? 'plugin'
        :                     'intern_error';
101

102
103
    ## Prepare the original message if provided
    if (defined $param->{'message'}) {
104
105
        $param->{'original_msg'} = _get_msg_as_hash($param->{'message'});
    }
106

107
108
109
110
111
112
113
114
115
116
    my $report_message = Sympa::Message->new_from_template(($list || $robot),
        'message_report', $user, $param);
    if ($report_message) {
        # Ensure 1 second elapsed since last message
        $report_message->{'date'} = time + 1;
    }
    unless ($report_message
        and defined Sympa::Bulk::store($report_message, $user)) {
        Log::do_log('notice',
            'Unable to send template "message_report" to "%s"', $user);
117
    }
118

119
    if ($type eq 'intern') {
120
121
122
123
124
125
126
        chomp($param->{'msg_id'});

        $param ||= {};
        $param->{'error'}  = $error;
        $param->{'who'}    = $user;
        $param->{'action'} = 'message diffusion';
        $param->{'msg_id'} = $param->{'msg_id'};
127
128
        tools::send_notify_to_listmaster(($list || $robot),
            'mail_intern_error', $param);
129
130
131
132
    }
    return 1;
}

133
134
135
136
137
############################################################
#  _get_msg_as_hash
############################################################
#  Internal subroutine
#  Provide useful parts of a message as a hash entries
138
#
139
140
141
142
# IN : -$msg_object (+): ref(HASH) - the MIME::Entity or Message object
#
# OUT : $msg_hash : ref(HASH) - the hashref
#
143
##############################################################
144
#FIXME: Is returned value by this function actually used?
145
146
147
148

sub _get_msg_as_hash {
    my $msg_object = shift;

149
    my ($msg_entity, $msg_string, $msg_hash);
150

151
    if ($msg_object->isa('MIME::Entity')) {    ## MIME-Tools object
152
        $msg_entity = $msg_object;
153
        $msg_string = $msg_entity->as_string;
154
155
    } elsif (ref $msg_object eq 'Sympa::Message') {
        # Sympa's own Message object
156
157
        $msg_entity = $msg_object->as_entity;
        $msg_string = $msg_object->as_string;
158
    } else {
159
        Log::do_log('err', 'Wrong type for msg parameter');
160
    }
161
162

    my $head        = $msg_entity->head;
163
164
    my $body_handle = $msg_entity->bodyhandle;
    my $body_as_string;
165

166
    if (defined $body_handle) {
167
        $body_as_string = $body_handle->as_lines();
168
169
    }

170
171
    ## TODO : we should also decode headers + remove trailing \n + use these
    ## variables in default mail templates
172

173
    my $from    = $head->get('From');
174
    my $subject = $head->get('Subject');
175
176
    my $msg_id  = $head->get('Message-Id');
    $msg_hash = {
177
        'full'       => $msg_string,
178
179
180
181
182
        'body'       => $body_as_string,
        'from'       => $from,
        'subject'    => $subject,
        'message_id' => $msg_id
    };
183
184
185
186

    return $msg_hash;
}

187
188
189
190
191
############################################################
#  notice_report_msg
############################################################
#  Send a notification to the user about a success for its
#   message diffusion, using mail_tt2/message_report.tt2
192
#
193
194
195
196
197
198
199
200
# IN : -$entry (+): scalar - the entry in message_report.tt2
#      -$user (+): scalar - the user to notify
#      -$param : ref(HASH) - var used in message_report.tt2
#      -$robot (+) : robot
#      -$list : ref(List)
#
# OUT : 1
#
201
##############################################################
202
sub notice_report_msg {
203
    my ($entry, $user, $param, $robot, $list) = @_;
204

205
206
    undef $list unless ref $list eq 'Sympa::List';

207
208
209
    $param->{'to'}             = $user;
    $param->{'type'}           = 'success';
    $param->{'entry'}          = $entry;
210
    $param->{'auto_submitted'} = 'auto-replied';
211

212
213
    unless ($user) {
        Log::do_log('err',
214
            "Sympa::Report::notice_report_msg(): unable to send template message_report.tt2 : no user to notify"
215
216
        );
        return undef;
217
    }
218
219
220

    unless ($robot) {
        Log::do_log('err',
221
            "Sympa::Report::notice_report_msg(): unable to send template message_report.tt2 : no robot"
222
223
        );
        return undef;
224
225
    }

226
227
    ## Prepare the original message if provided
    if (defined $param->{'message'}) {
228
229
        $param->{'original_msg'} = _get_msg_as_hash($param->{'message'});
    }
230

231
232
233
234
235
236
237
238
239
240
    my $report_message = Sympa::Message->new_from_template(($list || $robot),
        'message_report', $user, $param);
    if ($report_message) {
        # Ensure 1 second elapsed since last message
        $report_message->{'date'} = time + 1;
    }
    unless ($report_message
        and defined Sympa::Bulk::store($report_message, $user)) {
        Log::do_log('notice',
            'Unable to send template "message_report" to "%s"', $user);
241
242
243
244
245
    }

    return 1;
}

246
### MAIL COMMAND REPORT ###
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263

# for rejected command because of internal error
my @intern_error_cmd;
# for rejected command because of user error
my @user_error_cmd;
# for errors no relative to a command
my @global_error_cmd;
# for rejected command because of no authorization
my @auth_reject_cmd;
# for command notice
my @notice_cmd;

#########################################################
# init_report_cmd
#########################################################
#  init arrays for mail command reports :
#
264
#
265
266
# IN : -
#
267
268
269
# OUT : -
#
#########################################################
270
271
272
273
274
275
276
277
278
279
280
281
282
sub init_report_cmd {

    undef @intern_error_cmd;
    undef @user_error_cmd;
    undef @global_error_cmd;
    undef @auth_reject_cmd;
    undef @notice_cmd;
}

#########################################################
# is_there_any_report_cmd
#########################################################
#  Look for some mail command report in one of arrays report
283
#
284
285
286
# IN : -
#
# OUT : 1 if there are some reports to send
287
288
#
#########################################################
289
290
sub is_there_any_report_cmd {

291
292
293
294
295
296
    return (   @intern_error_cmd
            || @user_error_cmd
            || @global_error_cmd
            || @auth_reject_cmd
            || @notice_cmd);
}
297
298
299
300

#########################################################
# send_report_cmd
#########################################################
301
#  Send the template command_report to $sender
302
303
304
305
#   with global arrays :
#  @intern_error_cmd,@user_error_cmd,@global_error_cmd,
#   @auth_reject_cmd,@notice_cmd.
#
306
#
307
308
309
310
# IN : -$sender (+): SCALAR
#      -$robot (+): SCALAR
#
# OUT : 1 if there are some reports to send
311
312
#
#########################################################
313
sub send_report_cmd {
314
    my ($sender, $robot) = @_;
315

316
317
    unless ($sender) {
        Log::do_log('err',
318
            "Sympa::Report::send_report_cmd(): unable to send template command_report.tt2 : no user to notify"
319
320
        );
        return undef;
321
    }
322
323
324

    unless ($robot) {
        Log::do_log('err',
325
            "Sympa::Report::send_report_cmd() : unable to send template command_report.tt2 : no robot"
326
327
        );
        return undef;
328
329
330
331
    }

    # for mail layout
    my $before_auth = 0;
332
    $before_auth = 1 if ($#notice_cmd + 1);
333
334

    my $before_user_err;
335
    $before_user_err = 1 if ($before_auth || ($#auth_reject_cmd + 1));
336
337

    my $before_intern_err;
338
    $before_intern_err = 1 if ($before_user_err || ($#user_error_cmd + 1));
339
340
341

    chomp($sender);

342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
    my $data = {
        'to'                => $sender,
        'nb_notice'         => $#notice_cmd + 1,
        'nb_auth'           => $#auth_reject_cmd + 1,
        'nb_user_err'       => $#user_error_cmd + 1,
        'nb_intern_err'     => $#intern_error_cmd + 1,
        'nb_global'         => $#global_error_cmd + 1,
        'before_auth'       => $before_auth,
        'before_user_err'   => $before_user_err,
        'before_intern_err' => $before_intern_err,
        'notices'           => \@notice_cmd,
        'auths'             => \@auth_reject_cmd,
        'user_errors'       => \@user_error_cmd,
        'intern_errors'     => \@intern_error_cmd,
        'globals'           => \@global_error_cmd,
    };

359
360
361
362
363
364
365
366
367
    my $report_message =
        Sympa::Message->new_from_template($robot, 'command_report', $sender,
        $data);
    if ($report_message) {
        # Ensure 1 second elapsed since last message
        $report_message->{'date'} = time + 1;
    }
    unless ($report_message
        and defined Sympa::Bulk::store($report_message, $sender)) {
368
        Log::do_log('notice',
369
            'Unable to send template "command_report" to %s', $sender);
370
    }
371

sikeda's avatar
sikeda committed
372
    init_report_cmd();
373
374
375
376
377
}

#########################################################
# global_report_cmd
#########################################################
378
379
#  puts global report of mail with commands in
#  @global_report_cmd  used to send message with template
380
381
382
#  mail_tt2/command_report.tt2
#  if $now , the template is sent now
#  if $type eq 'intern', the listmaster is notified
383
#
384
# IN : -$type (+): 'intern'||'intern_quiet||'user'
385
386
387
388
#      -$error : scalar - $glob.entry in command_report.tt2 if $type = 'user'
#                          - string error for listmaster if $type = 'intern'
#      -$data : ref(HASH) - var used in command_report.tt2
#      -$sender :  required if $type eq 'intern' or if $now
389
#                  scalar - the user to notify
390
391
392
393
#      -$robot :   required if $type eq 'intern' or if $now
#                  scalar - to notify useror listmaster
#      -$now : send now if true
#
394
395
396
# OUT : 1|| undef
#
#########################################################
397
sub global_report_cmd {
398
    my ($type, $error, $data, $sender, $robot, $now) = @_;
399
400
    my $entry;

401
    unless ($type eq 'intern' || $type eq 'intern_quiet' || $type eq 'user') {
402
        Log::do_log('err',
403
            "Sympa::Report::global_report_msg(): error to prepare parsing 'command_report' template to $sender : not a valid error type"
404
405
        );
        return undef;
406
    }
407

408
409
    if ($type eq 'intern') {

410
411
412
413
414
415
416
        if ($robot) {
            my $param = $data;
            $param ||= {};
            $param->{'error'}  = $error;
            $param->{'who'}    = $sender;
            $param->{'action'} = 'Command process';

417
418
            tools::send_notify_to_listmaster($robot, 'mail_intern_error',
                $param);
419
420
        } else {
            Log::do_log('notice',
421
                "Sympa::Report::global_report_cmd(): unable to send notify to listmaster : no robot"
422
423
            );
        }
424
425
426
    }

    if ($type eq 'user') {
427
        $entry = $error;
428
429

    } else {
430
        $entry = 'intern_error';
431
432
433
434
435
436
437
    }

    $data ||= {};
    $data->{'entry'} = $entry;
    push @global_error_cmd, $data;

    if ($now) {
438
439
        unless ($sender && $robot) {
            Log::do_log('err',
440
                "Sympa::Report::global_report_cmd(): unable to send template command_report now : no sender or robot"
441
442
443
444
445
            );
            return undef;
        }
        send_report_cmd($sender, $robot);

446
447
448
449
450
451
    }
}

#########################################################
# reject_report_cmd
#########################################################
452
453
454
#  puts errors reports of processed commands in
#  @user/intern_error_cmd, @auth_reject_cmd
#  used to send message with template
455
456
#  mail_tt2/command_report.tt2
#  if $type eq 'intern', the listmaster is notified
457
#
458
# IN : -$type (+): 'intern'||'intern_quiet||'user'||'auth'
459
#      -$error : scalar - $u_err.entry in command_report.tt2 if $type = 'user'
460
#                       - $auth.entry in command_report.tt2 if $type = 'auth'
461
462
463
#                       - string error for listmaster if $type = 'intern'
#      -$data : ref(HASH) - var used in command_report.tt2
#      -$cmd : SCALAR - the rejected cmd : $xx.cmd in command_report.tt2
464
465
#      -$sender :  required if $type eq 'intern'
#                  scalar - the user to notify
466
467
468
#      -$robot :   required if $type eq 'intern'
#                  scalar - to notify listmaster
#
469
470
471
# OUT : 1|| undef
#
#########################################################
472
sub reject_report_cmd {
473
474
475
476
477
478
479
    my ($type, $error, $data, $cmd, $sender, $robot) = @_;

    unless ($type eq 'intern'
        || $type eq 'intern_quiet'
        || $type eq 'user'
        || $type eq 'auth') {
        Log::do_log('err',
480
            "Sympa::Report::reject_report_cmd(): error to prepare parsing 'command_report' template to $sender : not a valid error type"
481
482
        );
        return undef;
483
    }
484

485
    if ($type eq 'intern') {
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
        if ($robot) {

            my $listname;
            if (defined $data->{'listname'}) {
                $listname = $data->{'listname'};
            }

            my $param = $data;
            $param ||= {};
            $param->{'error'}    = $error;
            $param->{'cmd'}      = $cmd;
            $param->{'listname'} = $listname;
            $param->{'who'}      = $sender;
            $param->{'action'}   = 'Command process';

501
502
            tools::send_notify_to_listmaster($robot, 'mail_intern_error',
                $param);
503
504
        } else {
            Log::do_log('notice',
505
                "Sympa::Report::reject_report_cmd(): unable to notify listmaster for error: '$error' : (no robot) "
506
507
            );
        }
508
    }
509

510
511
512
513
    $data ||= {};
    $data->{'cmd'} = $cmd;

    if ($type eq 'auth') {
514
515
        $data->{'entry'} = $error;
        push @auth_reject_cmd, $data;
516
517

    } elsif ($type eq 'user') {
518
519
        $data->{'entry'} = $error;
        push @user_error_cmd, $data;
520
521

    } else {
522
523
        $data->{'entry'} = 'intern_error';
        push @intern_error_cmd, $data;
524
525
526
527
528
529
530
531

    }

}

#########################################################
# notice_report_cmd
#########################################################
532
533
#  puts notices reports of processed commands in
#  @notice_cmd used to send message with template
534
#  mail_tt2/command_report.tt2
535
#
536
537
538
539
540
541
# IN : -$entry : $notice.entry to select string in
#               command_report.tt2
#      -$data : ref(HASH) - var used in command_report.tt2
#      -$cmd : SCALAR - the noticed cmd
#
# OUT : 1
542
543
#
#########################################################
544
sub notice_report_cmd {
545
546
    my ($entry, $data, $cmd) = @_;

547
    $data ||= {};
548
    $data->{'cmd'}   = $cmd;
549
550
551
552
    $data->{'entry'} = $entry;
    push @notice_cmd, $data;
}

553
### WEB COMMAND REPORT ###
554
555
556

# for rejected web command because of internal error
my @intern_error_web;
557
# for rejected web command because of system error
558
559
560
561
562
563
564
565
566
567
568
569
570
my @system_error_web;
# for rejected web command because of user error
my @user_error_web;
# for rejected web command because of no authorization
my @auth_reject_web;
# for web command notice
my @notice_web;

#########################################################
# init_report_web
#########################################################
#  init arrays for web reports :
#
571
#
572
573
# IN : -
#
574
575
576
# OUT : -
#
#########################################################
577
578
579
580
581
582
583
584
585
586
587
588
sub init_report_web {

    undef @intern_error_web;
    undef @system_error_web;
    undef @user_error_web;
    undef @auth_reject_web;
    undef @notice_web;
}

#########################################################
# is_there_any_reject_report_web
#########################################################
589
590
591
#  Look for some web reports in one of web
#  arrays reject report
#
592
593
594
# IN : -
#
# OUT : 1 if there are some reports to send
595
596
#
#########################################################
597
598
sub is_there_any_reject_report_web {

599
600
601
602
603
    return (   @intern_error_web
            || @system_error_web
            || @user_error_web
            || @auth_reject_web);
}
604
605
606
607
608

#########################################################
# get_intern_error_web
#########################################################
#  return array of web intern error
609
#
610
611
612
# IN : -
#
# OUT : ref(ARRAY) - clone of \@intern_error_web
613
614
#
#########################################################
615
616
sub get_intern_error_web {
    my @intern_err;
617

618
    foreach my $i (@intern_error_web) {
619
        push @intern_err, $i;
620
621
622
623
624
625
626
627
    }
    return \@intern_err;
}

#########################################################
# get_system_error_web
#########################################################
#  return array of web system error
628
#
629
630
631
# IN : -
#
# OUT : ref(ARRAY) - clone of \@system_error_web
632
633
#
#########################################################
634
635
sub get_system_error_web {
    my @system_err;
636

637
    foreach my $i (@system_error_web) {
638
        push @system_err, $i;
639
640
641
642
643
644
645
646
    }
    return \@system_err;
}

#########################################################
# get_user_error_web
#########################################################
#  return array of web user error
647
#
648
649
650
# IN : -
#
# OUT : ref(ARRAY) - clone of \@user_error_web
651
652
#
#########################################################
653
654
sub get_user_error_web {
    my @user_err;
655

656
    foreach my $u (@user_error_web) {
657
        push @user_err, $u;
658
659
660
661
662
663
664
665
    }
    return \@user_err;
}

#########################################################
# get_auth_reject_web
#########################################################
#  return array of web authorisation reject
666
#
667
668
669
# IN : -
#
# OUT : ref(ARRAY) - clone of \@auth_reject_web
670
671
#
#########################################################
672
673
sub get_auth_reject_web {
    my @auth_rej;
674

675
    foreach my $a (@auth_reject_web) {
676
        push @auth_rej, $a;
677
678
679
680
681
682
683
684
    }
    return \@auth_rej;
}

#########################################################
# get_notice_web
#########################################################
#  return array of web notice
685
#
686
687
688
# IN : -
#
# OUT : ref(ARRAY) - clone of \@notice_web
689
690
#
#########################################################
691
692
sub get_notice_web {
    my @notice;
693

694
    if (@notice_web) {
695
696
697
698
699
700
701
702

        foreach my $n (@notice_web) {
            push @notice, $n;
        }
        return \@notice;

    } else {
        return 0;
703
704
705
706
707
708
709
    }

}

#########################################################
# notice_report_web
#########################################################
710
711
#  puts notices reports of web commands in
#  @notice_web used to notice user with template
712
#  web_tt2/notice.tt2
713
#
714
715
716
# IN : -$msg : $notice.msg to select string in
#               web/notice.tt2
#      -$data : ref(HASH) - var used in web_tt2/notices.tt2
717
718
#      -$action : SCALAR - the noticed action $notice.action in
#      web_tt2/notices.tt2
719
720
#
# OUT : 1
721
722
#
#########################################################
723
sub notice_report_web {
724
725
    my ($msg, $data, $action) = @_;

726
727
    $data ||= {};
    $data->{'action'} = $action;
728
729
    $data->{'msg'}    = $msg;
    push @notice_web, $data;
730
731
732
733
734
735

}

#########################################################
# reject_report_web
#########################################################
736
#  puts errors reports of web commands in
737
738
#  @intern/user/system_error_web, @auth_reject_web
#   used to send message with template  web_tt2/error.tt2
739
740
#  if $type = 'intern'||'system', the listmaster is notified
#  (with 'web_intern_error' || 'web_system_error')
741
742
743
#
# IN : -$type (+):
# 'intern'||'intern_quiet||'system'||'system_quiet'||user'||'auth'
744
#      -$error (+): scalar  - $u_err.msg in error.tt2 if $type = 'user'
745
746
747
748
749
750
751
752
753
#                           - $auth.msg in error.tt2 if $type = 'auth'
#                           - $s_err.msg in error.tt2 if $type =
#                           'system'||'system_quiet'
#                           - $i_err.msg in error.tt2 if $type = 'intern' ||
#                           'intern_quiet'
#                           - $error in listmaster_notification if $type =
#                           'system'||'intern'
#      -$data : ref(HASH) - var used in web_tt2/error.tt2
#      -$action(+) : SCALAR - the rejected action :
754
755
#            $xx.action in web_tt2/error.tt2
#            $action in listmaster_notification.tt2 if needed
756
757
#      -$list : ref(List) || ''
#      -$user :  required if $type eq 'intern'||'system'
758
#                  scalar - the concerned user to notify listmaster
759
#      -$robot :   required if $type eq 'intern'||'system'
760
761
#                  scalar - the robot to notify listmaster
#
762
763
764
# OUT : 1|| undef
#
#########################################################
765
sub reject_report_web {
766
767
768
769
770
771
772
773
774
    my ($type, $error, $data, $action, $list, $user, $robot) = @_;

    unless ($type eq 'intern'
        || $type eq 'intern_quiet'
        || $type eq 'system'
        || $type eq 'system_quiet'
        || $type eq 'user'
        || $type eq 'auth') {
        Log::do_log('err',
775
            "Sympa::Report::reject_report_web(): error  to prepare parsing 'web_tt2/error.tt2' template to $user : not a valid error type"
776
777
        );
        return undef;
778
    }
779

780
    my $listname;
781
    if (ref($list) eq 'Sympa::List') {
782
        $listname = $list->{'name'};
783
784
    }

785
    ## Notify listmaster for internal or system errors
786
787
788
789
790
791
792
    if ($type eq 'intern' || $type eq 'system') {
        if ($robot) {
            my $param = $data || {};
            $param->{'error'} = $error;
            $param->{'who'}   = $user;
            $param->{'action'} ||= 'Command process';

793
794
            tools::send_notify_to_listmaster(($list || $robot),
                'web_' . $type . '_error', $param);
795
796
        } else {
            Log::do_log('notice',
797
                "Sympa::Report::reject_report_web(): unable to notify listmaster for error: '$error' : (no robot) "
798
799
            );
        }
800
    }
801

802
803
    $data ||= {};

804
805
    $data->{'action'}   = $action;
    $data->{'msg'}      = $error;
806
807
808
    $data->{'listname'} = $listname;

    if ($type eq 'auth') {
809
810
811
812
813
814
815
816
817
818
819
        push @auth_reject_web, $data;

    } elsif ($type eq 'user') {
        push @user_error_web, $data;

    } elsif ($type eq 'system' || $type eq 'system_quiet') {
        push @system_error_web, $data;

    } elsif ($type eq 'intern' || $type eq 'intern_quiet') {
        push @intern_error_web, $data;

820
821
822
823
    }
}

1;