aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Youri/Submit/Action/Mail.pm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2007-06-29 13:30:24 +0000
committerPascal Rigaux <pixel@mandriva.com>2007-06-29 13:30:24 +0000
commit6cbb51a6bf5f4ccfc3388ce39a3bbd5b14a91217 (patch)
tree7e5723a41d828799e9759547bfd72c0133ba297f /lib/Youri/Submit/Action/Mail.pm
downloadmga-youri-submit-4189a356ec169f2fcc4938b40e6a082746fbf0dc.tar
mga-youri-submit-4189a356ec169f2fcc4938b40e6a082746fbf0dc.tar.gz
mga-youri-submit-4189a356ec169f2fcc4938b40e6a082746fbf0dc.tar.bz2
mga-youri-submit-4189a356ec169f2fcc4938b40e6a082746fbf0dc.tar.xz
mga-youri-submit-4189a356ec169f2fcc4938b40e6a082746fbf0dc.zip
prepare mergeupstream
Diffstat (limited to 'lib/Youri/Submit/Action/Mail.pm')
-rw-r--r--lib/Youri/Submit/Action/Mail.pm143
1 files changed, 143 insertions, 0 deletions
diff --git a/lib/Youri/Submit/Action/Mail.pm b/lib/Youri/Submit/Action/Mail.pm
new file mode 100644
index 0000000..4e39ef8
--- /dev/null
+++ b/lib/Youri/Submit/Action/Mail.pm
@@ -0,0 +1,143 @@
+# $Id: Mail.pm 1689 2007-06-28 22:44:24Z guillomovitch $
+package Youri::Submit::Action::Mail;
+
+=head1 NAME
+
+Youri::Submit::Action::Mail - Mail notification
+
+=head1 DESCRIPTION
+
+This action ensures mail notification of new package revisions. It assumes
+given package set is canonical, with source package first.
+
+=cut
+
+use warnings;
+use strict;
+use MIME::Entity;
+use Encode qw/from_to/;
+use Carp;
+use Youri::Package;
+use base qw/Youri::Submit::Step/;
+
+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 process_packages {
+ my ($self, $packages, $repository, $target, $context) = @_;
+ croak "Not a class method" unless ref $self;
+
+ my $package = $packages->[0];
+
+ my $from = $package->get_packager();
+
+ # force from adress if defined
+ $from =~ s/<.*>/<$self->{_from}>/ if $self->{_from};
+
+ my $subject = $self->get_subject($package, $repository, $target, $define);
+ my $content = $self->get_content($package, $repository, $target, $define);
+
+ # 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 {
+ my $command = "$self->{_mta} -t -oi -oem";
+ open(my $output, '|-', $command) or croak "Can't run $command: $!";
+ $mail->print($output);
+ close $output;
+ }
+
+}
+
+sub get_subject {
+ my ($self, $package, $repository, $target, $define) = @_;
+ croak "Not a class method" unless ref $self;
+
+ return
+ ($self->{_prefix} ? '[' . $self->{_prefix} . '] ' : '' ) .
+ $package->as_formated_string('%{name}-%{version}-%{release}');
+}
+
+sub get_content {
+ my ($self, $package, $repository, $target, $define) = @_;
+ croak "Not a class method" unless ref $self;
+
+ my $information = $package->as_formated_string(<<EOF);
+Name : %-27{NAME} Relocations: %|PREFIXES?{[%{PREFIXES} ]}:{(not relocatable)}|
+Version : %-27{VERSION} Vendor: %{VENDOR}
+Release : %-27{RELEASE} Build Date: %{BUILDTIME:date}
+Install Date: %|INSTALLTIME?{%-27{INSTALLTIME:date}}:{(not installed) }| Build Host: %{BUILDHOST}
+Group : %-27{GROUP} Source RPM: %{SOURCERPM}
+Size : %-27{SIZE}%|LICENSE?{ License: %{LICENSE}}|
+Signature : %|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{%|SIGGPG?{%{SIGGPG:pgpsig}}:{%|SIGPGP?{%{SIGPGP:pgpsig}}:{(none)}|}|}|}|
+%|PACKAGER?{Packager : %{PACKAGER}\n}|%|URL?{URL : %{URL}\n}|Summary : %{SUMMARY}
+Description :\n%{DESCRIPTION}
+EOF
+
+ my $last_change = $package->get_last_change();
+
+ return $last_change ?
+ $information . "\n" .
+ $last_change->get_author() . ":\n" .
+ $last_change->get_raw_text() :
+ $information;
+}
+
+
+=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;