Changeset 417 for LATMOS-Accounts/lib


Ignore:
Timestamp:
09/03/09 17:31:29 (15 years ago)
Author:
nanardon
Message:
  • add testing options to la-warn-expire
File:
1 edited

Legend:

Unmodified
Added
Removed
  • LATMOS-Accounts/lib/LATMOS/Accounts/Maintenance.pm

    r413 r417  
    4040} 
    4141 
     42=head2 warn_next_expire_users(%options) 
     43 
     44Send a mail to user having account expiring soon 
     45 
     46C<%options are> 
     47 
     48=over 4 
     49 
     50=item users => [] 
     51 
     52Warn only this users (if need) 
     53 
     54=item to 
     55 
     56Send the only to this person. 
     57 
     58=back 
     59 
     60=cut 
     61 
    4262sub warn_next_expire_users { 
    43     my ($self) = @_; 
     63    my ($self, %options) = @_; 
    4464 
    4565    require Mail::Sendmail; 
     
    5272    ); 
    5373    foreach my $user ($self->find_next_expire_users) { 
     74        if ($options{users} && ! grep { $_ eq $user->{name} } @{$options{users}}) { 
     75            next; 
     76        } 
    5477        my %mail = ( 
    5578            From => ($self->val('_default_', 'mailFrom') || 
     
    6992        my ($to, @cc) = grep { $_ } ($mail, $managermail, $self->val('_default_', 
    7093            'allwayscc')); 
    71         $mail{to} = 'nanardon@nanardon.zarb.org'; 
    72  
     94        if ($options{to}) { 
     95            $mail{to} = $options{to}; 
     96        } else { 
     97            $mail{to} = $to; 
     98            $mail{cc} = join(', ', @cc); 
     99        } 
     100        $mail{to} or next; 
    73101        my $message; 
    74102        $template->process('account_expire.mail', $user, \$message) 
    75103            or die $template->error(); 
     104 
    76105        if (Mail::Sendmail::sendmail( 
    77106            %mail, 
    78107            Message => $message, 
    79108        )) { 
    80             warn "mail sent to " . ($to || '') . " cc " . (join(', ', @cc) || '') . "\n"; 
     109            printf("Mail normally set to %s; cc to %s\n", 
     110                $to, (join(', ', @cc) || '')); 
    81111        } else { 
    82112            warn $Mail::Sendmail::error 
Note: See TracChangeset for help on using the changeset viewer.