diff options
author | Florent Villard <warly@mandriva.com> | 2006-08-04 16:45:06 +0000 |
---|---|---|
committer | Florent Villard <warly@mandriva.com> | 2006-08-04 16:45:06 +0000 |
commit | 0a7ef4aa1b338a6c23dccd0db15086596f05a22a (patch) | |
tree | 620105c88261aa086535f04d1ca5fba94cb4cbbf /lib/Youri/Upload/Action/Mail.pm | |
parent | 1fec4f0cac5732229070c4ad2e24c01ba2bab51b (diff) | |
download | mga-youri-core-0a7ef4aa1b338a6c23dccd0db15086596f05a22a.tar mga-youri-core-0a7ef4aa1b338a6c23dccd0db15086596f05a22a.tar.gz mga-youri-core-0a7ef4aa1b338a6c23dccd0db15086596f05a22a.tar.bz2 mga-youri-core-0a7ef4aa1b338a6c23dccd0db15086596f05a22a.tar.xz mga-youri-core-0a7ef4aa1b338a6c23dccd0db15086596f05a22a.zip |
imported initial version of youri svn
Diffstat (limited to 'lib/Youri/Upload/Action/Mail.pm')
-rw-r--r-- | lib/Youri/Upload/Action/Mail.pm | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/lib/Youri/Upload/Action/Mail.pm b/lib/Youri/Upload/Action/Mail.pm new file mode 100644 index 0000000..c895ec7 --- /dev/null +++ b/lib/Youri/Upload/Action/Mail.pm @@ -0,0 +1,115 @@ +# $Id: Mail.pm 901 2006-04-21 21:35:10Z guillomovitch $ +package Youri::Upload::Action::Mail; + +=head1 NAME + +Youri::Upload::Action::Mail - Mail notification + +=head1 DESCRIPTION + +This action plugin ensures mail notification of new package revisions. + +=cut + +use warnings; +use strict; +use MIME::Entity; +use Encode qw/from_to/; +use Carp; +use Youri::Package; +use base qw/Youri::Upload::Action/; + +sub _init { + my $self = shift; + my %options = ( + mta => '/usr/sbin/sendmail', + to => '', + from => '', + cc => '', + prefix => '', + encoding => 'quoted-printable', + charset => 'iso-8859-1', + @_ + ); + + croak "undefined mail MTA" unless $options{mta}; + croak "invalid mail MTA $options{mta}" unless -x $options{mta}; + croak "undefined to" unless $options{to}; + if ($options{cc}) { + croak "cc should be an hashref" unless ref $options{cc} eq 'HASH'; + } + croak "invalid charset $options{charset}" + unless Encode::resolve_alias($options{charset}); + + $self->{_mta} = $options{mta}; + $self->{_to} = $options{to}; + $self->{_from} = $options{from}; + $self->{_cc} = $options{cc}; + $self->{_prefix} = $options{prefix}; + $self->{_encoding} = $options{encoding}; + $self->{_charset} = $options{charset}; +} + +sub run { + my ($self, $package, $repository, $target, $define) = @_; + croak "Not a class method" unless ref $self; + + return unless $package->is_source(); + + my $from = $package->get_packager(); + + # force from adress if defined + $from =~ s/<.*>/<$self->{_from}>/ if $self->{_from}; + + my $subject = + ($self->{_prefix} ? '[' . $self->{_prefix} . '] ' : '' ) . + $package->get_revision_name(); + my $information = $package->get_information(); + my $last_change = $package->get_last_change(); + my $content = + $information . "\n" . + $last_change->[Youri::Package::CHANGE_AUTHOR] . ":\n" . + join( + '', map { "- $_\n" } @{$last_change->[Youri::Package::CHANGE_TEXT]} + ); + + # ensure proper codeset conversion + # for informations coming from package + my $charset = $repository->get_package_charset(); + from_to($content, $charset, $self->{_charset}); + from_to($subject, $charset, $self->{_charset}); + + my $mail = MIME::Entity->build( + Type => 'text/plain', + Charset => $self->{_charset}, + Encoding => $self->{_encoding}, + From => $from, + To => $self->{_to}, + Subject => $subject, + Data => $content, + ); + + if ($self->{_cc}) { + my $cc = $self->{_cc}->{$package->get_name()}; + $mail->head()->add('cc', $cc) if $cc; + } + + if ($self->{_test}) { + $mail->print(\*STDOUT); + } else { + open(MAIL, "| $self->{_mta} -t -oi -oem") or die "Can't open MTA program: $!"; + $mail->print(\*MAIL); + close MAIL; + } + +} + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2002-2006, YOURI project + +This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. + +=cut + +1; |