[Rt-commit] r10661 - in rt/branches/3.999-DANGEROUS/lib/RT: ScripAction
ruz at bestpractical.com
ruz at bestpractical.com
Fri Feb 1 16:14:22 EST 2008
Author: ruz
Date: Fri Feb 1 16:14:22 2008
New Revision: 10661
Modified:
rt/branches/3.999-DANGEROUS/lib/RT/Interface/Email.pm
rt/branches/3.999-DANGEROUS/lib/RT/ScripAction/SendEmail.pm
Log:
* random changes
Modified: rt/branches/3.999-DANGEROUS/lib/RT/Interface/Email.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/Interface/Email.pm (original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/Interface/Email.pm Fri Feb 1 16:14:22 2008
@@ -289,18 +289,18 @@
}
- send_email( Entity => $entity, Bounce => 1 );
+ send_email( entity => $entity, Bounce => 1 );
}
-=head2 send_email Entity => undef, [ Bounce => 0, Ticket => undef, Transaction => undef ]
+=head2 send_email entity => undef, [ Bounce => 0, ticket => undef, transaction => undef ]
Sends an email (passed as a L<MIME::Entity> object C<ENTITY>) using
RT's outgoing mail configuration. If C<BOUNCE> is passed, and is a
true value, the message will be marked as an autogenerated error, if
possible. Sets date field of the head to now if it's not set.
-Ticket and Transaction arguments are optional. If Transaction is
-specified and Ticket is not then ticket of the transaction is
+Ticket and transaction arguments are optional. If transaction is
+specified and ticket is not then ticket of the transaction is
used, but only if the transaction belongs to a ticket.
Returns 1 on success, 0 on error or -1 if message has no recipients
@@ -310,7 +310,7 @@
This function as well signs and/or encrypts the message according to
headers of a transaction's attachment or properties of a ticket's queue.
-To get full access to the configuration Ticket and/or Transaction
+To get full access to the configuration ticket and/or transaction
arguments must be provided, but you can force behaviour using Sign
and/or encrypt arguments.
@@ -319,22 +319,22 @@
* if sign or encrypt argument is defined then its value is used
-* else if Transaction's first attachment has X-RT-Sign or X-RT-Encrypt
+* else if transaction's first attachment has X-RT-Sign or X-RT-Encrypt
header field then it's value is used
-* else properties of a queue of the Ticket are used.
+* else properties of a queue of the ticket are used.
=cut
sub send_email {
my (%args) = (
- Entity => undef,
+ entity => undef,
Bounce => 0,
- Ticket => undef,
- Transaction => undef,
+ ticket => undef,
+ transaction => undef,
@_,
);
- foreach my $arg (qw(Entity Bounce)) {
+ foreach my $arg (qw(entity Bounce)) {
next unless defined $args{ lc $arg };
Jifty->log->warn(
@@ -342,36 +342,36 @@
$args{$arg} = delete $args{ lc $arg };
}
- unless ( $args{'Entity'} ) {
- Jifty->log->fatal("Could not send mail without 'Entity' object");
+ unless ( $args{'entity'} ) {
+ Jifty->log->fatal("Could not send mail without 'entity' object");
return 0;
}
- my $msgid = $args{'Entity'}->head->get('Message-ID') || '';
+ my $msgid = $args{'entity'}->head->get('Message-ID') || '';
chomp $msgid;
# If we don't have any recipients to send to, don't send a message;
- unless ( $args{'Entity'}->head->get('To')
- || $args{'Entity'}->head->get('Cc')
- || $args{'Entity'}->head->get('Bcc') )
+ unless ( $args{'entity'}->head->get('To')
+ || $args{'entity'}->head->get('Cc')
+ || $args{'entity'}->head->get('Bcc') )
{
Jifty->log->info( $msgid . " No recipients found. Not sending.\n" );
return -1;
}
- if ( $args{'Transaction'}
- && !$args{'Ticket'}
- && $args{'Transaction'}->object_type eq 'RT::Model::Ticket' )
+ if ( $args{'transaction'}
+ && !$args{'ticket'}
+ && $args{'transaction'}->object_type eq 'RT::Model::Ticket' )
{
- $args{'Ticket'} = $args{'Transaction'}->object;
+ $args{'ticket'} = $args{'transaction'}->object;
}
if ( RT->config->get('GnuPG')->{'Enable'} ) {
my %crypt;
my $attachment;
- $attachment = $args{'Transaction'}->attachments->first
- if $args{'Transaction'};
+ $attachment = $args{'transaction'}->attachments->first
+ if $args{'transaction'};
foreach my $argument (qw(sign encrypt)) {
next if defined $args{$argument};
@@ -380,8 +380,8 @@
&& defined $attachment->get_header("X-RT-$argument") )
{
$crypt{$argument} = $attachment->get_header("X-RT-$argument");
- } elsif ( $args{'Ticket'} ) {
- $crypt{$argument} = $args{'Ticket'}->queue_obj->$argument();
+ } elsif ( $args{'ticket'} ) {
+ $crypt{$argument} = $args{'ticket'}->queue_obj->$argument();
}
}
@@ -389,18 +389,18 @@
return $res unless $res > 0;
}
- unless ( $args{'Entity'}->head->get('date') ) {
+ unless ( $args{'entity'}->head->get('date') ) {
require RT::Date;
my $date = RT::Date->new( current_user => RT->system_user );
$date->set_to_now;
- $args{'Entity'}
+ $args{'entity'}
->head->set( 'date', $date->rfc2822( timezone => 'server' ) );
}
my $mail_command = RT->config->get('MailCommand');
# if it is a sub routine, we just return it;
- return $mail_command->( $args{'Entity'} )
+ return $mail_command->( $args{'entity'} )
if UNIVERSAL::isa( $mail_command, 'CODE' );
if ( $mail_command eq 'sendmailpipe' ) {
@@ -410,11 +410,11 @@
if $args{'Bounce'};
# VERP
- if ( $args{'Transaction'}
+ if ( $args{'transaction'}
and my $prefix = RT->config->get('VERPPrefix')
and my $domain = RT->config->get('VERPDomain') )
{
- my $from = $args{'Transaction'}->creator_obj->email;
+ my $from = $args{'transaction'}->creator_obj->email;
$from =~ s/@/=/g;
$from =~ s/\s//g;
$args .= " -f $prefix$from\@$domain";
@@ -431,7 +431,7 @@
# if something wrong with $mail->print we will get PIPE signal, handle it
local $SIG{'PIPE'}
= sub { die "program unexpectedly closed pipe" };
- $args{'Entity'}->print($mail);
+ $args{'entity'}->print($mail);
unless ( close $mail ) {
die "close pipe failed: $!" if $!; # system error
@@ -466,13 +466,13 @@
}
# duplicate head as we want drop Bcc field
- my $head = $args{'Entity'}->head->dup;
+ my $head = $args{'entity'}->head->dup;
my @recipients = map $_->address,
Mail::Address->parse( map $head->get($_), qw(To Cc Bcc) );
$head->delete('Bcc');
my $sender = RT->config->get('SMTPFrom')
- || $args{'Entity'}->head->get('From');
+ || $args{'entity'}->head->get('From');
chomp $sender;
my $status = $smtp->mail($sender)
@@ -483,7 +483,7 @@
my $fh = $smtp->tied_fh;
$head->print($fh);
print $fh "\n";
- $args{'Entity'}->print_body($fh);
+ $args{'entity'}->print_body($fh);
$smtp->dataend;
}
$smtp->quit;
@@ -504,7 +504,7 @@
push @mailer_args, RT->config->get('MailParams');
}
- unless ( $args{'Entity'}->send(@mailer_args) ) {
+ unless ( $args{'entity'}->send(@mailer_args) ) {
Jifty->log->fatal("$msgid: Could not send mail.");
return 0;
}
@@ -512,7 +512,7 @@
return 1;
}
-=head2 prepare_email_using_template template => '', Arguments => {}
+=head2 prepare_email_using_template template => '', arguments => {}
Loads a template. Parses it using arguments if it's not empty.
Returns a tuple (L<RT::Model::Template> object, error message).
@@ -525,7 +525,7 @@
sub prepare_email_using_template {
my %args = (
template => '',
- Arguments => {},
+ arguments => {},
@_
);
@@ -538,13 +538,13 @@
}
return $template if $template->is_empty;
- my ( $status, $msg ) = $template->parse( %{ $args{'Arguments'} } );
+ my ( $status, $msg ) = $template->parse( %{ $args{'arguments'} } );
return ( undef, $msg ) unless $status;
return $template;
}
-=head2 send_email_using_template template => '', Arguments => {}, From => correspond_address, To => '', Cc => '', Bcc => ''
+=head2 send_email_using_template template => '', arguments => {}, From => correspond_address, To => '', Cc => '', Bcc => ''
Sends email using a template, takes name of template, arguments for it and recipients.
@@ -553,12 +553,12 @@
sub send_email_using_template {
my %args = (
template => '',
- Arguments => {},
- To => undef,
- Cc => undef,
- Bcc => undef,
- From => RT->config->get('correspond_address'),
- InReplyTo => undef,
+ arguments => {},
+ to => undef,
+ cc => undef,
+ bcc => undef,
+ from => RT->config->get('correspond_address'),
+ in_reply_to => undef,
@_
);
@@ -578,7 +578,7 @@
set_in_reply_to( Message => $mail, InReplyTo => $args{'InReplyTo'} );
- return send_email( Entity => $mail );
+ return send_email( entity => $mail );
}
=head2 ForwardTransaction TRANSACTION, To => '', Cc => '', Bcc => ''
@@ -645,9 +645,9 @@
my ( $template, $msg ) = prepare_email_using_template(
template => 'Forward',
- Arguments => {
- Transaction => $txn,
- Ticket => $txn->object,
+ arguments => {
+ transaction => $txn,
+ ticket => $txn->object,
},
);
my $mail;
@@ -697,13 +697,13 @@
my $status = RT->config->get('ForwardFromUser')
# never sign if we forward from User
- ? send_email( Entity => $mail, Transaction => $txn, sign => 0 )
- : send_email( Entity => $mail, Transaction => $txn );
+ ? send_email( entity => $mail, transaction => $txn, sign => 0 )
+ : send_email( entity => $mail, transaction => $txn );
return ( 0, $txn->_("Couldn't send email") ) unless $status;
return ( 1, $txn->_("Send email successfully") );
}
-=head2 sign_encrypt Entity => undef, sign => 0, encrypt => 0
+=head2 sign_encrypt entity => undef, sign => 0, encrypt => 0
Signs and encrypts message using L<RT::Crypt::GnuPG>, but as well
handle errors with users' keys.
@@ -721,14 +721,14 @@
sub sign_encrypt {
my %args = (
- Entity => undef,
+ entity => undef,
sign => 0,
encrypt => 0,
@_
);
return 1 unless $args{'sign'} || $args{'encrypt'};
- my $msgid = $args{'Entity'}->head->get('Message-ID') || '';
+ my $msgid = $args{'entity'}->head->get('Message-ID') || '';
chomp $msgid;
Jifty->log->debug("$msgid Signing message") if $args{'sign'};
@@ -765,12 +765,12 @@
foreach my $recipient (@bad_recipients) {
my $status = send_email_using_template(
- To => $recipient->{'AddressObj'}->address,
+ to => $recipient->{'AddressObj'}->address,
template => 'Error: public key',
- Arguments => {
+ arguments => {
%$recipient,
- ticket_obj => $args{'Ticket'},
- transaction_obj => $args{'Transaction'},
+ ticket_obj => $args{'ticket'},
+ transaction_obj => $args{'transaction'},
},
);
unless ($status) {
@@ -779,25 +779,25 @@
}
my $status = send_email_using_template(
- To => RT->config->get('OwnerEmail'),
+ to => RT->config->get('OwnerEmail'),
template => 'Error to RT owner: public key',
- Arguments => {
- BadRecipients => \@bad_recipients,
- ticket_obj => $args{'Ticket'},
- transaction_obj => $args{'Transaction'},
+ arguments => {
+ bad_recipients => \@bad_recipients,
+ ticket_obj => $args{'ticket'},
+ transaction_obj => $args{'transaction'},
},
);
unless ($status) {
Jifty->log->error("Couldn't send 'Error to RT owner: public key'");
}
- delete_recipients_from_head( $args{'Entity'}->head,
+ delete_recipients_from_head( $args{'entity'}->head,
map $_->{'AddressObj'}->address,
@bad_recipients );
- unless ( $args{'Entity'}->head->get('To')
- || $args{'Entity'}->head->get('Cc')
- || $args{'Entity'}->head->get('Bcc') )
+ unless ( $args{'entity'}->head->get('To')
+ || $args{'entity'}->head->get('Cc')
+ || $args{'entity'}->head->get('Bcc') )
{
Jifty->log->debug(
"$msgid No recipients that have public key, not sending");
@@ -997,14 +997,14 @@
sub gen_message_id {
my %args = (
- Ticket => undef,
+ ticket => undef,
Scrip => undef,
scrip_action => undef,
@_
);
my $org = RT->config->get('organization');
my $ticket_id
- = ( ref $args{'Ticket'} ? $args{'Ticket'}->id : $args{'Ticket'} )
+ = ( ref $args{'ticket'} ? $args{'ticket'}->id : $args{'ticket'} )
|| 0;
my $scrip_id
= ( ref $args{'Scrip'} ? $args{'Scrip'}->id : $args{'Scrip'} ) || 0;
@@ -1028,7 +1028,7 @@
my %args = (
Message => undef,
InReplyTo => undef,
- Ticket => undef,
+ ticket => undef,
@_
);
return unless $args{'Message'} && $args{'InReplyTo'};
@@ -1050,10 +1050,10 @@
@references = $get_header->('In-Reply-To');
}
push @references, @id, @rtid;
- if ( $args{'Ticket'} ) {
+ if ( $args{'ticket'} ) {
my $pseudo_ref
= '<RT-Ticket-'
- . $args{'Ticket'}->id . '@'
+ . $args{'ticket'}->id . '@'
. RT->config->get('organization') . '>';
push @references, $pseudo_ref
unless grep $_ eq $pseudo_ref, @references;
@@ -1332,7 +1332,7 @@
current_user => $CurrentUser,
AuthLevel => $AuthStat,
Action => $action,
- Ticket => $SystemTicket,
+ ticket => $SystemTicket,
queue => $Systemqueue_obj
);
@@ -1395,7 +1395,7 @@
# if plugin's updated SystemTicket then update arguments
$args{'ticket'} = $SystemTicket->id if $SystemTicket && $SystemTicket->id;
- my $Ticket = RT::Model::Ticket->new( current_user => $CurrentUser );
+ my $ticket = RT::Model::Ticket->new( current_user => $CurrentUser );
if ( !$args{'ticket'} && grep /^(comment|correspond)$/, @actions ) {
@@ -1410,7 +1410,7 @@
);
}
- my ( $id, $Transaction, $ErrStr ) = $Ticket->create(
+ my ( $id, $transaction, $ErrStr ) = $ticket->create(
queue => $Systemqueue_obj->id,
subject => $subject,
Requestor => \@Requestors,
@@ -1424,7 +1424,7 @@
Explanation => $ErrStr,
mime_obj => $Message
);
- return ( 0, "Ticket creation failed: $ErrStr", $Ticket );
+ return ( 0, "Ticket creation failed: $ErrStr", $ticket );
}
# strip comments&corresponds from the actions we don't need
@@ -1434,8 +1434,8 @@
} elsif ( $args{'ticket'} ) {
- $Ticket->load( $args{'ticket'} );
- unless ( $Ticket->id ) {
+ $ticket->load( $args{'ticket'} );
+ unless ( $ticket->id ) {
my $error = "Could not find a ticket with id " . $args{'ticket'};
mail_error(
To => $ErrorsTo,
@@ -1446,9 +1446,9 @@
return ( 0, $error );
}
- $args{'ticket'} = $Ticket->id;
+ $args{'ticket'} = $ticket->id;
} else {
- return ( 1, "Success", $Ticket );
+ return ( 1, "Success", $ticket );
}
# }}}
@@ -1459,7 +1459,7 @@
# If the action is comment, add a comment.
if ( $action =~ /^(?:comment|correspond)$/i ) {
my $method = lc $action;
- my ( $status, $msg ) = $Ticket->$method( mime_obj => $Message );
+ my ( $status, $msg ) = $ticket->$method( mime_obj => $Message );
unless ($status) {
#Warn the sender that we couldn't actually submit the comment.
@@ -1469,20 +1469,20 @@
Explanation => $msg,
mime_obj => $Message
);
- return ( 0, "Message not recorded: $msg", $Ticket );
+ return ( 0, "Message not recorded: $msg", $ticket );
}
} elsif ($unsafe_actions) {
my ( $status, $msg ) = _RunUnsafeAction(
Action => $action,
ErrorsTo => $ErrorsTo,
Message => $Message,
- Ticket => $Ticket,
+ ticket => $ticket,
current_user => $CurrentUser,
);
- return ( $status, $msg, $Ticket ) unless $status == 1;
+ return ( $status, $msg, $ticket ) unless $status == 1;
}
}
- return ( 1, "Success", $Ticket );
+ return ( 1, "Success", $ticket );
}
sub _run_unsafe_action {
@@ -1490,14 +1490,14 @@
Action => undef,
ErrorsTo => undef,
Message => undef,
- Ticket => undef,
+ ticket => undef,
current_user => undef,
@_
);
if ( $args{'Action'} =~ /^take$/i ) {
my ( $status, $msg )
- = $args{'Ticket'}->set_owner( $args{'CurrentUser'}->id );
+ = $args{'ticket'}->set_owner( $args{'CurrentUser'}->id );
unless ($status) {
mail_error(
To => $args{'ErrorsTo'},
@@ -1508,7 +1508,7 @@
return ( 0, "Ticket not taken" );
}
} elsif ( $args{'Action'} =~ /^resolve$/i ) {
- my ( $status, $msg ) = $args{'Ticket'}->set_status('resolved');
+ my ( $status, $msg ) = $args{'ticket'}->set_status('resolved');
unless ($status) {
#Warn the sender that we couldn't actually submit the comment.
@@ -1522,7 +1522,7 @@
}
} else {
return ( 0, "Not supported unsafe action $args{'Action'}",
- $args{'Ticket'} );
+ $args{'ticket'} );
}
return ( 1, "Success" );
}
Modified: rt/branches/3.999-DANGEROUS/lib/RT/ScripAction/SendEmail.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/ScripAction/SendEmail.pm (original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/ScripAction/SendEmail.pm Fri Feb 1 16:14:22 2008
@@ -311,9 +311,9 @@
. ( $self->scrip_obj->description || '' ) );
my $status = RT::Interface::Email::send_email(
- Entity => $mime_obj,
- Ticket => $self->ticket_obj,
- Transaction => $self->transaction_obj,
+ entity => $mime_obj,
+ ticket => $self->ticket_obj,
+ transaction => $self->transaction_obj,
);
return $status unless $status > 0;
@@ -474,7 +474,7 @@
my $ticket_mime = MIME::Entity->build(
Type => 'multipart/mixed',
Top => 0,
- description => "ticket #$tid",
+ Description => "ticket #$tid",
);
while ( my $attachment = $attachs->next ) {
$self->add_attachment( $attachment, $ticket_mime );
@@ -535,9 +535,9 @@
chomp $msgid;
my ( $id, $msg ) = $transaction->create(
- Ticket => $self->ticket_obj->id,
+ ticket => $self->ticket_obj->id,
type => $type,
- Data => $msgid,
+ data => $msgid,
mime_obj => $mime_obj,
activate_scrips => 0
);
@@ -593,9 +593,9 @@
} else {
$self->set_header(
'Message-ID' => RT::Interface::Email::gen_message_id(
- Ticket => $self->ticket_obj,
- Scrip => $self->scrip_obj,
- ScripAction => $self->scrip_action_obj
+ ticket => $self->ticket_obj,
+ scrip => $self->scrip_obj,
+ scrip_action => $self->scrip_action_obj
),
);
}
More information about the Rt-commit
mailing list