diff options
| author | fukachan <fukachan> | 2002-07-14 15:15:27 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2002-07-14 15:15:27 +0000 |
| commit | 791073bd93a78124f348ca70d045f671c2f4eabb (patch) | |
| tree | 9bf9ab513db02935a9a43e25851cca4b87efce91 /fml/lib | |
| parent | 4345159846ffb68770a0b6794decb84eb5eba9e9 (diff) | |
| download | fml8-791073bd93a78124f348ca70d045f671c2f4eabb.tar.gz fml8-791073bd93a78124f348ca70d045f671c2f4eabb.tar.bz2 fml8-791073bd93a78124f348ca70d045f671c2f4eabb.zip | |
copy message and send it to $maintainer too
use reply_message*() with $msg_args to copy the message if needed where
$msg_args = { always_cc => $maintainer } or
$msg_args = { recipient => $maintinaer } pertinently.
Diffstat (limited to 'fml/lib')
| -rw-r--r-- | fml/lib/FML/Command.pm | 35 | ||||
| -rw-r--r-- | fml/lib/FML/Command/User/confirm.pm | 16 | ||||
| -rw-r--r-- | fml/lib/FML/Command/UserControl.pm | 50 | ||||
| -rw-r--r-- | fml/lib/FML/Process/Command.pm | 47 | ||||
| -rw-r--r-- | fml/lib/FML/Process/Distribute.pm | 16 | ||||
| -rw-r--r-- | fml/lib/FML/Process/Kernel.pm | 39 |
6 files changed, 166 insertions, 37 deletions
diff --git a/fml/lib/FML/Command.pm b/fml/lib/FML/Command.pm index 204444b3..b3314cd4 100644 --- a/fml/lib/FML/Command.pm +++ b/fml/lib/FML/Command.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Command.pm,v 1.26 2002/06/30 14:27:47 fukachan Exp $ +# $FML: Command.pm,v 1.27 2002/06/30 14:30:12 fukachan Exp $ # package FML::Command; @@ -72,7 +72,8 @@ buffer. # Descriptions: rewrite prompt buffer -# Arguments: OBJ($self) OBJ($curproc) HASH_REF($command_args) STR_REF($rbuf) +# Arguments: OBJ($self) +# OBJ($curproc) HASH_REF($command_args) STR_REF($rbuf) # Side Effects: none # Return Value: none sub rewrite_prompt @@ -93,6 +94,36 @@ sub rewrite_prompt } + +=head2 C<notice_cc_recipient($curproc, $command_args, $rbuf)> + +return addresses to inform for the command reply. + +=cut + + +# Descriptions: return addresses to inform +# Arguments: OBJ($self) OBJ($curproc) HASH_REF($command_args) +# Side Effects: none +# Return Value: ARRAY_REF +sub notice_cc_recipient +{ + my ($self, $curproc, $command_args) = @_; + my $command = undef; + my $comname = $command_args->{ comname }; + my $mode = + $command_args->{'command_mode'} =~ /admin/i ? 'Admin' : 'User'; + my $pkg = "FML::Command::${mode}::${comname}"; + + eval qq{ use $pkg; \$command = new $pkg;}; + unless ($@) { + if ($command->can('notice_cc_recipient')) { + $command->notice_cc_recipient($curproc, $command_args); + } + } +} + + =head2 C<AUTOLOAD()> the command dispatcher. diff --git a/fml/lib/FML/Command/User/confirm.pm b/fml/lib/FML/Command/User/confirm.pm index 050a3d71..a5b28fee 100644 --- a/fml/lib/FML/Command/User/confirm.pm +++ b/fml/lib/FML/Command/User/confirm.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: confirm.pm,v 1.9 2002/04/06 14:46:28 fukachan Exp $ +# $FML: confirm.pm,v 1.10 2002/04/11 15:39:42 tmu Exp $ # package FML::Command::User::confirm; @@ -52,6 +52,20 @@ sub new sub need_lock { 1;} +# Descriptions: addresses to inform a message copy to +# Arguments: none +# Side Effects: none +# Return Value: ARREY_REF +sub notice_cc_recipient +{ + my ($self, $curproc, $command_args) = @_; + my $config = $curproc->{ config }; + my $maintainer = $config->{ maintainer }; + + return [ $maintainer ]; +} + + # Descriptions: execute the actual process if this confirmation succeeds. # run _switch_command() for real process. # Arguments: OBJ($self) OBJ($curproc) HASH_REF($command_args) diff --git a/fml/lib/FML/Command/UserControl.pm b/fml/lib/FML/Command/UserControl.pm index e5cc9f3d..7f66d2bf 100644 --- a/fml/lib/FML/Command/UserControl.pm +++ b/fml/lib/FML/Command/UserControl.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: UserControl.pm,v 1.10 2002/07/02 03:55:54 fukachan Exp $ +# $FML: UserControl.pm,v 1.11 2002/07/14 04:13:11 fukachan Exp $ # package FML::Command::UserControl; @@ -51,27 +51,29 @@ sub new sub useradd { my ($self, $curproc, $command_args, $uc_args) = @_; - my $address = $uc_args->{ address }; - my $maplist = $uc_args->{ maplist }; + my $address = $uc_args->{ address }; + my $maplist = $uc_args->{ maplist }; + my $msg_args = $command_args->{ msg_args }; + $msg_args->{ _arg_address } = $address; for my $map (@$maplist) { my $cred = new FML::Credential; unless ($cred->has_address_in_map($map, $address)) { - my $obj = new IO::Adapter $map; + $msg_args->{ _arg_map } = $curproc->which_map_nl($map); + + my $obj = new IO::Adapter $map; $obj->touch(); # create a new map entry (e.g. file) if needed. $obj->add( $address ); unless ($obj->error()) { Log("add $address to map=$map"); - $curproc->reply_message('command.add_ok', - "$address added.", - { _arg_address => $address,} - ); + $curproc->reply_message_nl('command.add_ok', + "$address added.", + $msg_args); } else { - $curproc->reply_message('command.add_fail', - "failed to add $address", - { _arg_address => $address,} - ); + $curproc->reply_message_nl('command.add_fail', + "failed to add $address", + $msg_args); croak("fail to add $address to map=$map"); } } @@ -91,27 +93,29 @@ sub useradd sub userdel { my ($self, $curproc, $command_args, $uc_args) = @_; - my $address = $uc_args->{ address }; - my $maplist = $uc_args->{ maplist }; + my $address = $uc_args->{ address }; + my $maplist = $uc_args->{ maplist }; + my $msg_args = $command_args->{ msg_args }; + $msg_args->{ _arg_address } = $address; for my $map (@$maplist) { my $cred = new FML::Credential; if ($cred->has_address_in_map($map, $address)) { - my $obj = new IO::Adapter $map; + $msg_args->{ _arg_map } = $curproc->which_map_nl($map); + + my $obj = new IO::Adapter $map; $obj->delete( $address ); unless ($obj->error()) { Log("removed $address from map=$map"); - $curproc->reply_message('command.del_ok', - "$address added.", - { _arg_address => $address,} - ); + $curproc->reply_message_nl('command.del_ok', + "$address removed.", + $msg_args); } else { + $curproc->reply_message_nl('command.del_fail', + "failed to remove $address", + $msg_args); croak("fail to remove $address from map=$map"); - $curproc->reply_message('command.del_ok', - "$address added.", - { _arg_address => $address,} - ); } } else { diff --git a/fml/lib/FML/Process/Command.pm b/fml/lib/FML/Process/Command.pm index 308e4133..0b6375bb 100644 --- a/fml/lib/FML/Process/Command.pm +++ b/fml/lib/FML/Process/Command.pm @@ -3,7 +3,7 @@ # Copyright (C) 2000,2001,2002 Ken'ichi Fukamachi # All rights reserved. # -# $FML: Command.pm,v 1.62 2002/06/27 08:25:49 fukachan Exp $ +# $FML: Command.pm,v 1.63 2002/07/02 03:58:32 fukachan Exp $ # package FML::Process::Command; @@ -324,6 +324,8 @@ sub _parse_command_args ml_name => $ml_name, argv => $argv, args => $args, + + msg_args => {}, }; return $cominfo; @@ -645,6 +647,8 @@ sub _evaluate_command_lines # the main loop to analyze each command at each line. my ($cominfo, $fixed_command); my ($num_total, $num_ignored, $num_processed) = (0, 0, 0); + my $is_cc_recipient = 1; + my %cc_recipient = (); COMMAND: for my $orig_command (@$command_lines) { next COMMAND if $orig_command =~ /^\s*$/; # ignore empty lines @@ -691,13 +695,28 @@ sub _evaluate_command_lines my $obj = new FML::Command; if (defined $obj) { # arguments to pass off into each method + my $sender = $curproc->{'credential'}->{'sender'}; my $command_args = $curproc->_gen_command_args($status, $cominfo); + my $msg_args = $command_args->{ msg_args }; + $msg_args->{ always_cc } = $sender; # rewrite prompt e.g. to hide the password $obj->rewrite_prompt($curproc, $command_args, \$orig_command); + # check if addresses to notice defined ? + # XXX The recipients are dependent on each command. + # XXX Defined in each command module (e.g. FML::Command::User::*) + { + my $a = $obj->notice_cc_recipient($curproc, $command_args); + if (defined $a) { + $msg_args->{ recipient } = $a; + $is_cc_recipient = 1; + $cc_recipient{ join("-", @$a) } = $a; + } + } + # reply buffer - $curproc->reply_message("\n$prompt $orig_command"); + $curproc->reply_message("\n$prompt $orig_command", $msg_args); Log($orig_command); # execute command ($comname method) under eval(). @@ -707,13 +726,13 @@ sub _evaluate_command_lines $obj->$comname($curproc, $command_args); }; unless ($@) { - $curproc->reply_message_nl('command.ok', "ok."); + $curproc->reply_message_nl('command.ok', "ok.", $msg_args); } else { # error trap my $reason = $@; Log($reason); - $curproc->reply_message_nl('command.fail', "fail."); + $curproc->reply_message_nl('command.fail', "fail.", $msg_args); LogError("command ${comname} fail"); if ($reason =~ /^(.*)\s+at\s+/) { @@ -733,11 +752,23 @@ sub _evaluate_command_lines $curproc->reply_message(" ignored = $num_ignored"); $curproc->reply_message(" total = $num_total"); - # in the case "confirm" - if ( $status->{ context }->{ under_confirmation } ) { - # send back original message as a reference + # send bak the original input message if needed + { my $msg = $curproc->{ incoming_message }->{ message }; - $curproc->reply_message( $msg ); + + # in the case "confirm" + if ($status->{ context }->{ under_confirmation }) { + # send back original message as a reference + $curproc->reply_message( $msg ); + } + + if (keys %cc_recipient) { + for my $k (keys %cc_recipient) { + my $ra_addr = $cc_recipient{ $k }; + Log("msg.cc: [ @$ra_addr ]"); + $curproc->reply_message( $msg , { recipient => $ra_addr }); + } + } } } diff --git a/fml/lib/FML/Process/Distribute.pm b/fml/lib/FML/Process/Distribute.pm index 00763ada..c119ec3e 100644 --- a/fml/lib/FML/Process/Distribute.pm +++ b/fml/lib/FML/Process/Distribute.pm @@ -3,7 +3,7 @@ # Copyright (C) 2000,2001,2002 Ken'ichi Fukamachi # All rights reserved. # -# $FML: Distribute.pm,v 1.81 2002/06/27 08:25:49 fukachan Exp $ +# $FML: Distribute.pm,v 1.82 2002/07/02 12:40:37 fukachan Exp $ # package FML::Process::Distribute; @@ -173,7 +173,9 @@ Lastly we unlock the current process. sub run { my ($curproc, $args) = @_; - my $config = $curproc->{ config }; + my $config = $curproc->{ config }; + my $maintainer = $config->{ maintainer }; + my $sender = $curproc->{'credential'}->{'sender'}; my $eval = $config->get_hook( 'distribute_run_start_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } @@ -208,6 +210,16 @@ sub run my $msg = $curproc->{ incoming_message }->{ message }; $curproc->reply_message( $msg ); + + # inform maintainer too. + my $msg_args = { + _arg_address => $sender, + recipient => $maintainer, + }; + $curproc->reply_message_nl("error.post_from_not_member", + "post from not a member", + $msg_args); + $curproc->reply_message( $msg, $msg_args ); } } else { diff --git a/fml/lib/FML/Process/Kernel.pm b/fml/lib/FML/Process/Kernel.pm index 38bcef0a..efb06ac3 100644 --- a/fml/lib/FML/Process/Kernel.pm +++ b/fml/lib/FML/Process/Kernel.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Kernel.pm,v 1.111 2002/07/13 13:08:08 fukachan Exp $ +# $FML: Kernel.pm,v 1.112 2002/07/14 04:13:58 fukachan Exp $ # package FML::Process::Kernel; @@ -864,6 +864,43 @@ sub reply_message } $curproc->_append_message_into_queue($msg, $args, $recipient); + + if (defined $args->{ always_cc }) { + # only if $recipient above != always_cc, duplicate $msg message. + my $sent = $recipient; + my $cc = $args->{ always_cc }; + + my $recipient = []; + if (ref($cc) eq 'ARRAY') { + $recipient = $cc; + } + else { + $recipient = [ $cc ]; + } + + if (_array_is_different($sent, $recipient)) { + Log("cc: [ @$recipient ]"); + $curproc->_append_message_into_queue($msg, $args, $recipient); + } + } +} + + +sub _array_is_different +{ + my ($a, $b) = @_; + my $diff = 0; + my $i = 0; + + # 1. number of array elements differs. + return 1 if $#$a != $#$b; + + # 2. some elements in arrays differ. + for ($i = 0; $i <= $#$a ; $i++) { + $diff++ if $a->[ $i ] ne $b->[ $i ]; + } + + return $diff; } |
