345
unless ($list->close()) {
346
print STDERR "Could not close list $main::options{'close_list'}\n";
423
if ($list->{'admin'}{'family_name'}) {
424
unless($list->set_status_family_closed('close_list',$list->{'name'})) {
425
print STDERR "Could not close list $main::options{'close_list'}\n";
429
unless ($list->close()) {
430
print STDERR "Could not close list $main::options{'close_list'}\n";
350
435
printf STDOUT "List %s has been closed, aliases have been removed\n", $list->{'name'};
438
}elsif ($main::options{'create_list'}) {
440
my $robot = $main::options{'robot'} || $Conf{'host'};
442
unless ($main::options{'input_file'}) {
443
print STDERR "Error : missing 'input_file' parameter\n";
447
unless (open INFILE, $main::options{'input_file'}) {
448
print STDERR "Unable to open $main::options{'input_file'}) file";
452
my $config = new Config_XML(\*INFILE);
453
unless (defined $config->createHash()) {
454
print STDERR "Error in representation data with these xml data\n";
458
my $hash = $config->getHash();
462
my $resul = &admin::create_list_old($hash->{'config'},$hash->{'type'},$robot);
463
unless (defined $resul) {
464
print STDERR "Could not create list with these xml data\n";
468
if ($resul->{'aliases'} == 1) {
469
printf STDOUT "List has been created \n";
472
printf STDOUT "List has been created, required aliases :\n $resul->{'aliases'} \n";
475
}elsif ($main::options{'instantiate_family'}) {
477
my $robot = $main::options{'robot'} || $Conf{'host'};
480
unless ($family_name = $main::options{'instantiate_family'}) {
481
print STDERR "Error : missing family parameter\n";
485
unless ($family = new Family($family_name,$robot)) {
486
print STDERR "The family $family_name does not exist, impossible instantiation\n";
490
unless ($main::options{'input_file'}) {
491
print STDERR "Error : missing input_file parameter\n";
495
unless (-r $main::options{'input_file'}) {
496
print STDERR "Unable to read $main::options{'input_file'}) file";
500
unless ($family->instantiate($main::options{'input_file'})) {
501
print STDERR "\nImpossible family instantiation : action stopped \n";
505
my $string = $family->get_instantiation_results();
507
print STDERR $string;
510
}elsif ($main::options{'add_list'}) {
512
my $robot = $main::options{'robot'} || $Conf{'host'};
515
unless ($family_name = $main::options{'add_list'}) {
516
print STDERR "Error : missing family parameter\n";
520
print STDOUT "\n************************************************************\n";
523
unless ($family = new Family($family_name,$robot)) {
524
print STDERR "The family $family_name does not exist, impossible to add a list\n";
528
unless ($main::options{'input_file'}) {
529
print STDERR "Error : missing 'input_file' parameter\n";
533
unless (open INFILE, $main::options{'input_file'}) {
534
print STDERR "\n Impossible to open input file : $! \n";
539
unless ($result = $family->add_list(\*INFILE)) {
540
print STDERR "\nImpossible to add a list to the family : action stopped \n";
544
print STDOUT "\n************************************************************\n";
546
unless (defined $result->{'ok'}) {
547
print STDERR "$result->{'string_info'}";
548
print STDERR "\n The action has been stopped because of error :\n";
549
print STDERR "$result->{'string_error'}";
555
print STDOUT $result->{'string_info'};
557
}elsif ($main::options{'sync_include'}) {
559
my $list = new List ($main::options{'sync_include'});
561
unless (defined $list) {
562
print STDERR "Incorrect list name $main::options{'sync_include'}\n";
566
unless (defined $list->sync_include()) {
567
print STDERR "Failed to synchronize list members\n";
571
printf "Members of list %s have been successfully update.\n", $list->get_list_address();
573
## Migration from one version to another
574
}elsif ($main::options{'upgrade'}) {
576
unless ($main::options{'from'}) {
577
print STDERR "Error : missing 'from' parameter\n";
581
unless ($main::options{'to'}) {
582
print STDERR "Error : missing 'to' parameter\n";
586
unless (&List::upgrade($main::options{'from'}, $main::options{'to'})) {
587
printf STDERR "Migration from %s to %s failed\n", $main::options{'from'}, $main::options{'to'};
593
## Reload binary list config files
594
}elsif ($main::options{'reload_list_config'}) {
596
if ($main::options{'list'}) {
598
&do_log('notice', "Loading list $main::options{'list'}...");
599
my $list = new List ($main::options{'list'}, '', {'reload_config' => 1});
600
unless (defined $list) {
601
print STDERR "Error : incorrect list name '$main::options{'list'}'\n";
605
&do_log('notice', "Loading ALL lists...");
606
my $all_lists = &List::get_lists('*',{'reload_config' => 1});
612
##########################################
613
elsif ($main::options{'modify_list'}) {
615
my $robot = $main::options{'robot'} || $Conf{'host'};
618
unless ($family_name = $main::options{'modify_list'}) {
619
print STDERR "Error : missing family parameter\n";
623
print STDOUT "\n************************************************************\n";
626
unless ($family = new Family($family_name,$robot)) {
627
print STDERR "The family $family_name does not exist, impossible to modify the list.\n";
631
unless ($main::options{'input_file'}) {
632
print STDERR "Error : missing input_file parameter\n";
636
unless (open INFILE, $main::options{'input_file'}) {
637
print STDERR "Unable to open $main::options{'input_file'}) file";
642
unless ($result = $family->modify_list(\*INFILE)) {
643
print STDERR "\nImpossible to modify the family list : action stopped. \n";
647
print STDOUT "\n************************************************************\n";
649
unless (defined $result->{'ok'}) {
650
print STDERR "$result->{'string_info'}";
651
print STDERR "\nThe action has been stopped because of error :\n";
652
print STDERR "$result->{'string_error'}";
658
print STDOUT $result->{'string_info'};
662
##########################################
663
elsif ($main::options{'close_family'}) {
665
my $robot = $main::options{'robot'} || $Conf{'host'};
668
unless ($family_name = $main::options{'close_family'}) {
669
print STDERR $usage_string;
673
unless ($family = new Family($family_name,$robot)) {
674
print STDERR "The family $family_name does not exist, impossible family closure\n";
679
unless ($string = $family->close()) {
680
print STDERR "\nImpossible family closure : action stopped \n";
684
print STDOUT $string;
690
## Update DB structure or content if required
691
&List::maintenance();
355
693
## Do we have right access in the directory
356
694
if ($main::options{'keepcopy'}) {
868
1296
if ($function eq "listmaster") {
869
1297
my $listmasters = &Conf::get_robot_conf($robot, 'listmasters');
870
1298
@rcpt = @{$listmasters};
871
do_log('notice', 'Warning : no listmaster defined in sympa.conf')
1299
&do_log('notice', 'Warning : no listmaster defined in sympa.conf')
874
1302
}elsif ($function eq "request") {
875
1303
@rcpt = $list->get_owners_email();
877
do_log('notice', 'Warning : no owner defined or all of them use nomail option in list %s', $name )
1305
&do_log('notice', 'Warning : no owner defined or all of them use nomail option in list %s', $name )
880
1308
}elsif ($function eq "editor") {
881
foreach my $i (@{$admin->{'editor'}}) {
882
next if ($i->{'reception'} eq 'nomail');
883
push(@rcpt, $i->{'email'}) if ($i->{'email'});
886
do_log('notice', 'No editor defined in list %s (unless they use NOMAIL), use owners', $name ) ;
887
@rcpt = $list->get_owners_email();
1309
@rcpt = $list->get_editors_email();
1311
&do_log('notice', 'Warning : no owner and editor defined or all of them use nomail option in list %s', $name )
891
1315
if ($#rcpt < 0) {
892
do_log('notice', "Message for %s-%s ignored, %s undefined in list %s", $name, $function, $function, $name);
1316
&do_log('err', "sympa::DoForward(): Message for %s-%s ignored, %s undefined in list %s", $name, $function, $function, $name);
1317
my $string = sprintf 'Impossible to forward a message to %s-%s : undefined in this list',$name,$function;
1318
my $sender = $hdr->get('From');
1319
&report::reject_report_msg('intern',$string,$sender,
1320
{'msg_id' => $messageid,
1321
'entry' => 'forward',
1322
'function' => $function}
1323
,$robot,$msg_string,$list);
897
1328
my $msg_copy = $msg->dup;
899
# if ($rc = &tools::virus_infected($msg_copy, $file)) {
900
# if ($Conf{'antivirus_notify'} eq 'sender') {
902
# $list->send_file('your_infected_msg', $sender, $robot,
903
# {'virus_name' => $rc,
904
# 'recipient' => $recepient.'@'.$host,
905
# 'lang' => $list->{'admin'}{'lang'}});
909
# $context{'virus_name'} = $rc ;
910
# $context{'recipient'} = $recepient.'@'.$host;
911
# $context{'lang'} = &Conf::get_robot_conf($robot, 'lang');
912
# &List::send_global_file('your_infected_msg', $sender, $robot, \%context );
915
# &do_log('notice', "Message for %s\@%s from %s ignored, virus %s found", $recepient, $host, $sender, $rc);
920
*SIZ = smtp::smtpto(&Conf::get_robot_conf($robot, 'request'), \@rcpt);
924
do_log('info',"Message for %s forwarded", $recepient);
1330
unless (&mail::mail_forward($msg,&Conf::get_robot_conf($robot, 'request'),\@rcpt,$robot)) {
1331
&do_log('err',"Impossible to forward mail for $name-$function ");
1332
my $string = sprintf 'Impossible to forward a message for %s-%s',$name,$function;
1333
my $sender = $hdr->get('From');
1334
&report::reject_report_msg('intern',$string,$sender,
1335
{'msg_id' => $messageid,
1336
'entry' => 'forward',
1337
'function' => $function}
1338
,$robot,$msg_string,$list);
930
## Handles a message sent to a list.
1345
####################################################
1347
####################################################
1348
# Handles a message sent to a list. (Those that can
1349
# make loop and those containing a command are
1352
# IN : -$which (+): 'listname@hostname' - concerned list
1353
# -$message (+): ref(Message) - sent message
1354
# -$robot (+): robot
1356
# OUT : 1 if ok (in order to remove the file from the queue)
1359
####################################################
932
1361
my($which, $message, $robot) = @_;
933
1362
&do_log('debug', 'DoMessage(%s, %s, %s, msg from %s, %s, %s,%s)', $which, $message->{'msg'}, $robot, $message->{'sender'}, $message->{'size'}, $message->{'msg_as_string'}, $message->{'smime_crypted'});
935
1364
## List and host.
936
1365
my($listname, $host) = split(/[@\s]+/, $which);
938
1367
my $hdr = $message->{'msg'}->head;
940
my $from_field = $hdr->get('From');
941
1369
my $messageid = $hdr->get('Message-Id');
943
my @sender_hdr = Mail::Address->parse($from_field);
945
my $sender = $sender_hdr[0]->address || '';
1370
my $msg_string = $message->{'msg'}->as_string;
1372
my $sender = $message->{'sender'};
947
1374
## Search for the list
948
my $list = new List ($listname);
1375
my $list = new List ($listname, $robot);
951
1378
unless ($list) {
952
1379
&do_log('notice', 'Unknown list %s', $listname);
953
&List::send_global_file('list_unknown', $sender, $robot,
955
'date' => &POSIX::strftime("%d %b %Y %H:%M", localtime(time)),
956
'boundary' => &Conf::get_robot_conf($robot, 'sympa').time,
957
'header' => $hdr->as_string()
1380
my $sympa_email = &Conf::get_robot_conf($robot, 'sympa');
1382
unless (&List::send_global_file('list_unknown', $sender, $robot,
1384
'date' => &POSIX::strftime("%d %b %Y %H:%M", localtime(time)),
1385
'boundary' => $sympa_email.time,
1386
'header' => $hdr->as_string()
1388
&do_log('notice',"Unable to send template 'list_unknown' to $sender");
962
1393
($listname, $host) = ($list->{'name'}, $list->{'admin'}{'host'});
964
1395
my $start_time = time;
966
1397
&Language::SetLang($list->{'admin'}{'lang'});
968
1399
## Now check if the sender is an authorized address.
970
do_log('info', "Processing message for %s with priority %s, %s", $listname,$list->{'admin'}{'priority'}, $messageid );
1401
&do_log('info', "Processing message for %s with priority %s, %s", $listname,$list->{'admin'}{'priority'}, $messageid );
972
1403
my $conf_email = &Conf::get_robot_conf($robot, 'sympa');
973
if ($sender =~ /^(mailer-daemon|sympa|listserv|majordomo|smartlist|mailman|$conf_email)(\@|$)/mio) {
1404
my $conf_loop_prevention_regex = $list->{'admin'}{'loop_prevention_regex'};
1405
if ($sender =~ /^($conf_loop_prevention_regex)(\@|$)/mio) {
974
1406
do_log('notice', 'Ignoring message which would cause a loop');
978
if ($msgid_table{$listname}{$messageid}) {
979
do_log('notice', 'Found known Message-ID, ignoring message which would cause a loop');
1410
if ($msgid_table{$list->get_list_id()}{$messageid}) {
1411
&do_log('notice', 'Found known Message-ID, ignoring message which would cause a loop');
983
1415
# Reject messages with commands
984
if ($Conf{'misaddressed_commands'} =~ /reject/i) {
1416
if ( &Conf::get_robot_conf($robot,'misaddressed_commands') =~ /reject/i) {
985
1417
## Check the message for commands and catch them.
986
if (tools::checkcommand($message->{'msg'}, $sender, $robot)) {
987
&do_log('notice', 'Found command in message, ignoring message');
1418
if (&tools::checkcommand($message->{'msg'}, $sender, $robot)) {
1419
&do_log('info', 'sympa::DoMessage(): Found command in message, ignoring message');
1420
&report::reject_report_msg('user','routing_error',$sender,{},$robot,$msg_string,$list);
993
1425
my $admin = $list->{'admin'};
994
return undef unless $admin;
1427
&do_log('err', 'sympa::DoMessage(): list config is undefined');
1428
&report::reject_report_msg('intern','',$sender,{'msg'=>$messageid},$robot,$msg_string,$list);
996
1432
my $customheader = $admin->{'custom_header'};
997
1433
# $host = $admin->{'host'} if ($admin->{'host'});
999
1435
## Check if the message is a return receipt
1000
1436
if ($hdr->get('multipart/report')) {
1001
do_log('notice', 'Message for %s from %s ignored because it is a report', $listname, $sender);
1437
&do_log('notice', 'Message for %s from %s ignored because it is a report', $listname, $sender);
1005
1441
## Check if the message is too large
1006
my $max_size = $list->get_max_size() || $Conf{'max_size'};
1442
# my $max_size = $list->get_max_size() || &Conf::get_robot_conf($robot,'max_size');
1443
my $max_size = $list->get_max_size();
1007
1445
if ($max_size && $message->{'size'} > $max_size) {
1008
do_log('notice', 'Message for %s from %s rejected because too large (%d > %d)', $listname, $sender, $message->{'size'}, $max_size);
1009
*SIZ = smtp::smtpto(&Conf::get_robot_conf($robot, 'request'), \$sender);
1010
print SIZ "From: " . sprintf (Msg(12, 4, 'SYMPA <%s>'), &Conf::get_robot_conf($robot, 'request')) . "\n";
1011
printf SIZ "To: %s\n", $sender;
1012
printf SIZ "Subject: " . Msg(4, 11, "Your message for list %s has been rejected") . "\n", $listname;
1013
printf SIZ "MIME-Version: %s\n", Msg(12, 1, '1.0');
1014
printf SIZ "Content-Type: text/plain; charset=%s\n", Msg(12, 2, 'us-ascii');
1015
printf SIZ "Content-Transfer-Encoding: %s\n\n", Msg(12, 3, '7bit');
1016
print SIZ Msg(4, 12, $msg::msg_too_large);
1017
$message->{'msg'}->print(\*SIZ);
1446
&do_log('info', 'sympa::DoMessage(): Message for %s from %s rejected because too large (%d > %d)', $listname, $sender, $message->{'size'}, $max_size);
1447
&report::reject_report_msg('user','message_too_large',$sender,{},$robot,$msg_string,$list);
1453
my $context = {'sender' => $sender,
1454
'message' => $message };
1457
if ($list->is_there_msg_topic()) {
1459
my $info_msg_topic = $list->load_msg_topic_file($messageid,$robot);
1461
# is msg already tagged ?
1462
if (ref($info_msg_topic) eq "HASH") {
1463
if ($info_msg_topic->{'method'} eq "sender") {
1464
$context->{'topic_sender'} = $info_msg_topic->{'topic'};
1466
}elsif ($info_msg_topic->{'method'} eq "editor") {
1467
$context->{'topic_editor'} = $info_msg_topic->{'topic'};
1469
}elsif ($info_msg_topic->{'method'} eq "auto") {
1470
$context->{'topic_auto'} = $info_msg_topic->{'topic'};
1473
# not already tagged
1475
$context->{'topic_auto'} = $list->automatic_tag($message->{'msg'},$robot);
1478
$context->{'topic'} = $context->{'topic_auto'} || $context->{'topic_sender'} || $context->{'topic_editor'};
1479
$context->{'topic_needed'} = (!$context->{'topic'} && $list->is_msg_topic_tagging_required());
1024
# if ($rc= &tools::virus_infected($message->{'msg'}, $message->{'filename'})) {
1025
# if ($Conf{'antivirus_notify'} eq 'sender') {
1026
# #printf "do message, virus= $rc \n";
1027
# $list->send_file('your_infected_msg', $sender, $robot, {'virus_name' => $rc,
1028
# 'recipient' => $listname.'@'.$host,
1029
# 'lang' => $list->{'admin'}{'lang'}});
1031
# &do_log('notice', "Message for %s\@%s from %s ignored, virus %s found", $listname, $host, $sender, $rc);
1035
1482
## Call scenarii : auth_method MD5 do not have any sense in send
1036
1483
## scenarii because auth is perfom by distribute or reject command.
1039
1487
if ($is_signed->{'body'}) {
1040
$action = &List::request_action ('send', 'smime',$robot,
1041
{'listname' => $listname,
1042
'sender' => $sender,
1043
'message' => $message });
1488
$result = $list->check_list_authz('send', 'smime',$context);
1489
$action = $result->{'action'} if (ref($result) eq 'HASH');
1045
$action = &List::request_action ('send', 'smtp',$robot,
1046
{'listname' => $listname,
1047
'sender' => $sender,
1048
'message' => $message });
1052
unless (defined $action);
1054
if ($action =~ /^do_it/) {
1056
my $numsmtp = $list->distribute_msg($message);
1058
## Keep track of known message IDs...if any
1059
$msgid_table{$listname}{$messageid}++
1062
unless (defined($numsmtp)) {
1063
do_log('info','Unable to send message to list %s', $listname);
1491
$result = $list->check_list_authz('send', 'smtp',$context);
1492
$action = $result->{'action'} if (ref($result) eq 'HASH');
1495
unless (defined $action) {
1496
&do_log('err', 'sympa::DoMessage(): message (%s) ignored because unable to evaluate scenario "send" for list %s',$messageid,$listname);
1497
&report::reject_report_msg('intern','Message ignored because scenario "send" cannot be evaluated',$sender,
1498
{'msg_id' => $messageid},
1499
$robot,$msg_string,$list);
1504
## message topic context
1505
if (($action =~ /^do_it/) && ($context->{'topic_needed'})) {
1506
$action = "editorkey";
1509
if (($action =~ /^do_it/) || ($main::daemon_usage eq 'message')) {
1512
if (($main::daemon_usage eq 'message') || ($main::daemon_usage eq 'command_and_message')) {
1513
my $numsmtp = $list->distribute_msg($message);
1515
## Keep track of known message IDs...if any
1516
$msgid_table{$list->get_list_id()}{$messageid}++ if ($messageid);
1518
unless (defined($numsmtp)) {
1519
&do_log('err','sympa::DoMessage(): Unable to send message to list %s', $listname);
1520
&report::reject_report_msg('intern','',$sender,{'msg_id' => $messageid},$robot,$msg_string,$list);
1523
&do_log('info', 'Message for %s from %s accepted (%d seconds, %d sessions, %d subscribers), message-id=%s, size=%d', $listname, $sender, time - $start_time, $numsmtp, $list->get_total(),$messageid, $message->{'size'});
1527
# this message is to be distributed but this daemon is dedicated to commands -> move it to distribution spool
1528
unless ($list->move_message($message->{'filename'})) {
1529
&do_log('err','sympa::DoMessage(): Unable to move in spool for distribution message to list %s (daemon_usage = command)', $listname);
1530
&report::reject_report_msg('intern','',$sender,{'msg_id' => $messageid},$robot,$msg_string,$list);
1533
&do_log('info', 'Message for %s from %s moved in spool %s for distribution message-id=%s', $listname, $sender, $Conf{'queuedistribute'},$messageid);
1067
do_log('info', 'Message for %s from %s accepted (%d seconds, %d sessions), size=%d', $listname, $sender, time - $start_time, $numsmtp, $message->{'size'});
1069
## Everything went fine, return TRUE in order to remove the file from
1072
1537
}elsif($action =~ /^request_auth/){
1073
1538
my $key = $list->send_auth($message);
1074
do_log('notice', 'Message for %s from %s kept for authentication with key %s', $listname, $sender, $key);
1540
unless (defined $key) {
1541
&do_log('err','sympa::DoMessage(): Calling to send_auth function failed for user %s in list %s', $sender, $list->{'name'});
1542
&report::reject_report_msg('intern','The request authentication sending failed',$sender,{'msg_id' => $messageid},$robot,$msg_string,$list);
1545
&do_log('notice', 'Message for %s from %s kept for authentication with key %s', $listname, $sender, $key);
1076
1547
}elsif($action =~ /^editorkey(\s?,\s?(quiet))?/){
1077
1548
my $key = $list->send_to_editor('md5',$message);
1078
do_log('info', 'Key %s for list %s from %s sent to editors, %s', $key, $listname, $sender, $message->{'filename'});
1079
$list->notify_sender($sender) unless ($2 eq 'quiet');
1550
unless (defined $key) {
1551
&do_log('err','sympa::DoMessage(): Calling to send_to_editor() function failed for user %s in list %s', $sender, $list->{'name'});
1552
&report::reject_report_msg('intern','The request moderation sending to moderator failed.',$sender,{'msg_id' => $messageid},$robot,$msg_string,$list);
1556
&do_log('info', 'Key %s for list %s from %s sent to editors, %s', $key, $listname, $sender, $message->{'filename'});
1558
unless ($2 eq 'quiet') {
1559
unless (&report::notice_report_msg('moderating_message',$sender,{},$robot,$list)) {
1560
&do_log('notice',"sympa::DoMessage(): Unable to send template 'message_report', entry 'moderating_message' to $sender");
1081
1564
}elsif($action =~ /^editor(\s?,\s?(quiet))?/){
1082
1565
my $key = $list->send_to_editor('smtp', $message);
1083
do_log('info', 'Message for %s from %s sent to editors', $listname, $sender);
1084
$list->notify_sender($sender) unless ($2 eq 'quiet');
1567
unless (defined $key) {
1568
&do_log('err','sympa::DoMessage(): Calling to send_to_editor() function failed for user %s in list %s', $sender, $list->{'name'});
1569
&report::reject_report_msg('intern','The request moderation sending to moderator failed.',$sender,{'msg_id' => $messageid},$robot,$msg_string,$list);
1573
&do_log('info', 'Message for %s from %s sent to editors', $listname, $sender);
1575
unless ($2 eq 'quiet') {
1576
unless (&report::notice_report_msg('moderating_message',$sender,{},$robot,$list)) {
1577
&do_log('notice',"sympa::DoMessage(): Unable to send template 'message_report', type 'success', entry 'moderating_message' to $sender");
1086
}elsif($action =~ /^reject(\(\'?(\w+)\'?\))?(\s?,\s?(quiet))?/) {
1088
do_log('notice', 'Message for %s from %s rejected(%s) because sender not allowed', $listname, $sender, $tpl);
1089
unless ($4 eq 'quiet') {
1091
$list->send_file($tpl, $sender, $robot, {});
1581
}elsif($action =~ /^reject(,(quiet))?/) {
1583
&do_log('notice', 'Message for %s from %s rejected(%s) because sender not allowed', $listname, $sender, $result->{'tt2'});
1584
unless ($2 eq 'quiet') {
1585
if (defined $result->{'tt2'}) {
1586
unless ($list->send_file($result->{'tt2'}, $sender, $robot, {})) {
1587
&do_log('notice',"sympa::DoMessage(): Unable to send template '$result->{'tt2'}' to $sender");
1093
*SIZ = smtp::smtpto(&Conf::get_robot_conf($robot, 'request'), \$sender);
1094
print SIZ "From: " . sprintf (Msg(12, 4, 'SYMPA <%s>'), &Conf::get_robot_conf($robot, 'request')) . "\n";
1095
printf SIZ "To: %s\n", $sender;
1096
printf SIZ "Subject: " . Msg(4, 11, "Your message for list %s has been rejected")."\n", $listname ;
1097
printf SIZ "MIME-Version: %s\n", Msg(12, 1, '1.0');
1098
printf SIZ "Content-Type: text/plain; charset=%s\n", Msg(12, 2, 'us-ascii');
1099
printf SIZ "Content-Transfer-Encoding: %s\n\n", Msg(12, 3, '7bit');
1100
printf SIZ Msg(4, 15, $msg::list_is_private), $listname;
1101
$message->{'msg'}->print(\*SIZ);
1590
unless (&report::reject_report_msg('auth',$result->{'reason'},$sender,{},$robot,$msg_string,$list)) {
1591
&do_log('notice',"sympa::DoMessage(): Unable to send template 'message_report', type 'auth' to $sender");
1107
&do_log('err','Unknown action %s returned by the scenario', $action);
1597
&do_log('err','sympa::DoMessage(): unknown action %s returned by the scenario "send"', $action);
1598
&report::reject_report_msg('intern','Unknown action returned by the scenario "send"',$sender,{'msg_id' => $messageid},$robot,$msg_string,$list);
1112
## Handles a message sent to a list.
1114
## Handles a command sent to the list manager.
1603
############################################################
1605
############################################################
1606
# Handles a command sent to the list manager.
1608
# IN : -$rcpt : recepient | <listname>-<subscribe|unsubscribe>
1609
# -$robot (+): robot
1610
# -$message : ref(Message) with :
1611
# ->msg (+): ref(MIME::Entity) : message containing command
1612
# ->filename (+): file containing message
1617
##############################################################
1115
1618
sub DoCommand {
1116
my($rcpt, $robot, $msg, $file) = @_;
1619
my($rcpt, $robot, $message) = @_;
1620
my $msg = $message->{'msg'};
1621
my $file = $message->{'filename'};
1117
1622
&do_log('debug', 'DoCommand(%s %s %s %s) ', $rcpt, $robot, $msg, $file);
1119
1627
## Now check if the sender is an authorized address.
1120
1628
my $hdr = $msg->head;
1122
1630
## Decode headers
1123
1631
#$hdr->decode();
1125
my $from_field = $hdr->get('From');
1126
1633
my $messageid = $hdr->get('Message-Id');
1127
1634
my ($success, $status);
1129
do_log('debug', "Processing command with priority %s, %s", $Conf{'sympa_priority'}, $messageid );
1636
&do_log('debug', "Processing command with priority %s, %s", $Conf{'sympa_priority'}, $messageid );
1131
my @sender_hdr = Mail::Address->parse($from_field);
1132
my $sender = $sender_hdr[0]->address;
1638
my $sender = $message->{'sender'};
1134
1640
## Detect loops
1135
if ($msgid_table{$robot}{$messageid}) {
1136
do_log('notice', 'Found known Message-ID, ignoring command which would cause a loop');
1641
if ($msgid_table{'sympa@'.$robot}{$messageid}) {
1642
&do_log('notice', 'Found known Message-ID, ignoring command which would cause a loop');
1644
}## Clean old files from spool
1140
1646
## Keep track of known message IDs...if any
1141
$msgid_table{$robot}{$messageid}++
1647
$msgid_table{'sympa@'.$robot}{$messageid}++
1142
1648
if ($messageid);
1144
1650
## If X-Sympa-To = <listname>-<subscribe|unsubscribe> parse as a unique command
1145
1651
if ($rcpt =~ /^(\S+)-(subscribe|unsubscribe)(\@(\S+))?$/o) {
1146
do_log('debug',"processing message for $1-$2");
1652
&do_log('debug',"processing message for $1-$2");
1147
1653
&Commands::parse($sender,$robot,"$2 $1");
1151
1657
## Process the Subject of the message
1152
1658
## Search and process a command in the Subject field
1153
my $subject_field = &MIME::Words::decode_mimewords($hdr->get('Subject'));
1154
chomp $subject_field;
1659
my $subject_field = $message->{'decoded_subject'};
1155
1660
$subject_field =~ s/\n//mg; ## multiline subjects
1156
1661
$subject_field =~ s/^\s*(Re:)?\s*(.*)\s*$/$2/i;
1158
1663
$success ||= &Commands::parse($sender, $robot, $subject_field, $is_signed->{'subject'}) ;
1665
unless ($success eq 'unknown_cmd') {
1160
1669
## Make multipart singlepart
1162
while ($msg->is_multipart()) {
1164
if (&tools::as_singlepart($msg, 'text/plain')) {
1165
do_log('notice', 'Multipart message changed to singlepart');
1168
do_log('notice', 'Could not change multipart to singlepart');
1670
if ($msg->is_multipart()) {
1671
my $status = &tools::as_singlepart($msg, 'text/plain');
1673
unless (defined $status) {
1674
&do_log('err', 'Could not change multipart to singlepart');
1675
&report::global_report_cmd('user','error_content_type',{});
1173
## check Content-type
1174
my $mime = $hdr->get('Mime-Version') ;
1175
my $content_type = $hdr->get('Content-type');
1176
my $transfert_encoding = $hdr->get('Content-transfer-encoding');
1178
unless (($content_type =~ /text/i and !$mime)
1180
or ($content_type =~ /text\/plain/i)) {
1181
do_log('notice', "Ignoring message body not in text/plain, Content-type: %s", $content_type);
1182
print Msg(4, 37, "Ignoring message body not in text/plain, please use text/plain only \n(or put your command in the subject).\n");
1680
&do_log('notice', 'Multipart message changed to singlepart');
1191
1687
## Process the body of the message
1192
1688
## unless subject contained commands or message has no body
1193
unless (defined($success) || (! defined $msg->bodyhandle)) {
1194
# foreach $i (@{$msg->body}) {
1689
if ( (!$cmd_found) && (defined $msg->bodyhandle)) {
1691
## check Content-type
1692
my $mime = $hdr->get('Mime-Version') ;
1693
my $content_type = $hdr->get('Content-type');
1694
my $transfert_encoding = $hdr->get('Content-transfer-encoding');
1695
unless (($content_type =~ /text/i and !$mime)
1697
or ($content_type =~ /text\/plain/i)) {
1698
&do_log('notice', "Ignoring message body not in text/plain, Content-type: %s", $content_type);
1699
&report::global_report_cmd('user','error_content_type',{});
1195
1703
my @body = $msg->bodyhandle->as_lines();
1196
1704
foreach $i (@body) {
1197
1705
if ($transfert_encoding =~ /quoted-printable/i) {
1198
1706
$i = MIME::QuotedPrint::decode($i);
1201
if ($i =~ /^(quit|end|stop)/io){
1204
# store the expire message in @msgexpire
1205
push(@msgexpire, $i);
1208
1709
$i =~ s/^\s*>?\s*(.*)\s*$/$1/g;
1209
1710
next if ($i =~ /^$/); ## skip empty lines
1210
1711
next if ($i =~ /^\s*\#/) ;
1212
# exception in the case of command expire
1213
if ($i =~ /^exp(ire)?\s/i){
1219
push @msg::report, "> $i\n\n";
1220
$size = $#msg::report;
1223
if ($i =~ /^(quit|end|stop|--)/io) {
1226
1713
&do_log('debug2',"is_signed->body $is_signed->{'body'}");
1228
unless ($status = Commands::parse($sender, $robot, $i, $is_signed->{'body'})) {
1229
push @msg::report, sprintf Msg(4, 19, "Command not understood: ignoring end of message.\n");
1715
$status = &Commands::parse($sender, $robot, $i, $is_signed->{'body'});
1716
$cmd_found = 1; # if problem no_cmd_understood is sent here
1717
if ($status eq 'unknown_cmd') {
1718
&do_log('notice', "Unknown command found :%s", $i);
1719
&report::reject_report_cmd('user','not_understood',{},$i);
1233
if ($#msg::report > $size) {
1234
## There is a command report
1235
push @msg::report, "\n";
1237
## No command report
1723
# if ($i =~ /^(qui|quit|end|stop|-)/io) {
1241
1727
$success ||= $status;
1243
pop @msg::report unless ($#msg::report > $size);
1246
1731
## No command found
1247
unless ($success == 1) {
1248
## No status => no command
1249
unless (defined $success) {
1250
do_log('info', "No command found in message");
1251
push @msg::report, sprintf Msg(4, 39, "No command found in message");
1732
unless ($cmd_found == 1) {
1733
&do_log('info', "No command found in message");
1734
&report::global_report_cmd('user','no_cmd_found',{});
1256
# processing the expire function
1258
print STDERR "expire\n";
1259
unless (&Commands::parse($sender, $robot, $expire, @msgexpire)) {
1260
print Msg(4, 19, "Command not understood: ignoring end of message.\n");
1264
1738
return $success;
1267
## Read the queue and send old digests to the subscribers with the digest option.
1741
############################################################
1743
############################################################
1744
# Read the queuedigest and send old digests to the subscribers
1745
# with the digest option.
1752
##############################################################
1268
1753
sub SendDigest{
1269
1754
&do_log('debug', 'SendDigest()');
1271
1756
if (!opendir(DIR, $Conf{'queuedigest'})) {
1272
fatal_err(Msg(3, 1, "Can't open dir %s: %m"), $Conf{'queuedigest'}); ## No return.
1757
fatal_err(gettext("Unable to access directory %s : %m"), $Conf{'queuedigest'}); ## No return.
1274
1759
my @dfile =( sort grep (!/^\./,readdir(DIR)));
1278
foreach my $listname (@dfile){
1280
my $filename = $Conf{'queuedigest'}.'/'.$listname;
1282
my $list = new List ($listname);
1763
foreach my $listaddress (@dfile){
1765
my $filename = $Conf{'queuedigest'}.'/'.$listaddress;
1767
my ($listname, $listrobot) = split /\@/, $listaddress;
1768
my $list = new List ($listname, $listrobot);
1283
1769
unless ($list) {
1284
1770
&do_log('info', 'Unknown list, deleting digest file %s', $filename);
1285
1771
unlink $filename;