Commit a590161c authored by sikeda's avatar sikeda
Browse files

[dev] Introducing Sympa::Spindle::ProcessTemplate and...

[dev] Introducing Sympa::Spindle::ProcessTemplate and Sympa::Spindle::ToOutgoing to send messages generated from template.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12599 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent cedf04a7
......@@ -93,6 +93,7 @@ nobase_modules_DATA = \
Sympa/Spindle/ProcessIncoming.pm \
Sympa/Spindle/ProcessModeration.pm \
Sympa/Spindle/ProcessOutgoing.pm \
Sympa/Spindle/ProcessTemplate.pm \
Sympa/Spindle/ResendArchive.pm \
Sympa/Spindle/ToArchive.pm \
Sympa/Spindle/ToDigest.pm \
......@@ -100,6 +101,7 @@ nobase_modules_DATA = \
Sympa/Spindle/ToHeld.pm \
Sympa/Spindle/ToList.pm \
Sympa/Spindle/ToModeration.pm \
Sympa/Spindle/ToOutgoing.pm \
Sympa/Spindle/TransformIncoming.pm \
Sympa/Spindle/TransformOutgoing.pm \
Sympa/Spool.pm \
......
......@@ -194,32 +194,30 @@ sub new {
}
# Set default envelope sender.
if ($list) {
$self->{envelope_sender} = $list->get_list_address('return_path');
if (exists $options{envelope_sender}) {
$self->{envelope_sender} = $options{envelope_sender};
} elsif ($list) {
$self->{envelope_sender} = Sympa::get_address($list, 'return_path');
} else {
$self->{envelope_sender} = Conf::get_robot_conf($robot_id, 'request');
$self->{envelope_sender} = Sympa::get_address($robot_id, 'owner');
}
# Set default delivery date.
$self->{date} = (exists $options{date}) ? $options{date} : time;
# Set priority if specified.
$self->{priority} = $options{priority}
if exists $options{priority};
# Shelve tracking if speficied.
$self->{shelved}{tracking} = $options{tracking}
if exists $options{tracking};
# Assign unique ID and log it.
my $marshalled =
Sympa::Spool::marshal_metadata($self, '%s@%s.%ld.%ld,%d',
[qw(localpart domainpart date PID RAND)]);
$self->{messagekey} = $marshalled;
$log->syslog(
'notice',
'Processing %s; message_id=%s; recipients=%s; sender=%s; template=%s; %s',
$self,
$self->{message_id},
$who,
$self->{sender},
$tpl,
join('; ',
map { $data->{$_} ? ("$_=$data->{$_}") : () }
qw(type action reason status))
);
return $self;
}
......@@ -450,6 +448,19 @@ sub _new_from_template {
return $self;
}
# Methods compatible to Sympa::Spool.
sub next {
my $self = shift;
return if delete $self->{_done_next};
$self->{_done_next} = 1;
return ($self, 1);
}
use constant quarantine => 1;
use constant remove => 1;
1;
__END__
......@@ -472,8 +483,7 @@ Sympa::Message::Template - Mail message generated from template
=over
=item new ( context =E<gt> $that, template =E<gt> $filename,
rcpt =E<gt> $rcpt, [ data =E<gt> $data ],
[ date =E<gt> $time ] )
rcpt =E<gt> $rcpt, [ data =E<gt> $data ], [ options... ] )
I<Constructor>.
Creates L<Sympa::Message> object from template.
......@@ -559,6 +569,19 @@ Below are optional parameters.
Delivery time of message.
By default current time will be used.
=item envelope_sender =E<gt> $email
Forces setting envelope sender.
C<'E<lt>E<gt>'> may be used for null envelope sender.
=item priority =E<gt> $priority
Forces setting priority if specified.
=item tracking =E<gt> $feature
Forces tracking if specified.
=back
Returns:
......
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4
# $Id$
# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright (c) 1997, 1998, 1999 Institut Pasteur & Christophe Wolfhugel
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015 GIP RENATER
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
package Sympa::Spindle::ProcessTemplate;
use strict;
use warnings;
use Sympa::Log;
use base qw(Sympa::Spindle);
my $log = Sympa::Log->instance;
use constant _distaff => 'Sympa::Message::Template';
sub _on_failure {
shift->{finish} = 'failure';
}
use constant _on_garbage => 1;
use constant _on_skip => 1;
sub _on_success {
shift->{finish} = 'success';
}
sub _twist {
my $self = shift;
my $message = shift;
$log->syslog(
'notice',
'Processing %s; envelope_sender=%s; message_id=%s; recipients=%s; sender=%s; template=%s; %s',
$message,
$message->{envelope_sender},
$message->{message_id},
$self->{rcpt},
$message->{sender},
$self->{template},
join('; ',
map { $self->{data}->{$_} ? ("$_=$self->{data}->{$_}") : () }
qw(type action reason status))
);
$message->{rcpt} = $self->{rcpt};
return $self->{splicing_to} || ['Sympa::Spindle::ToOutgoing'];
}
1;
__END__
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4
# $Id$
# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright (c) 1997, 1998, 1999 Institut Pasteur & Christophe Wolfhugel
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015 GIP RENATER
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
package Sympa::Spindle::ToOutgoing;
use strict;
use warnings;
use Sympa::Bulk;
use base qw(Sympa::Spindle);
sub _twist {
my $self = shift;
my $message = shift;
my $status =
Sympa::Bulk->new->store($message, $message->{rcpt},
tag => $message->{tag});
if ( $status
and ref $message->{context} eq 'Sympa::List'
and $self->{add_list_statistics}) {
my $list = $message->{context};
# Add number and size of digests sent to total in stats file.
my $numsent = scalar @{$message->{rcpt} || []};
my $bytes = length $message->as_string;
$list->{'stats'}[1] += $numsent;
$list->{'stats'}[2] += $bytes;
$list->{'stats'}[3] += $bytes * $numsent;
}
$status ? 1 : undef;
}
1;
__END__
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment