diff --git a/etc/handle_action_pass_currentuser.patch b/etc/handle_action_pass_currentuser.patch new file mode 100644 index 0000000..0014aa2 --- /dev/null +++ b/etc/handle_action_pass_currentuser.patch @@ -0,0 +1,12 @@ +diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm +index 175805d..7ffba8e 100644 +--- a/lib/RT/Interface/Email.pm ++++ b/lib/RT/Interface/Email.pm +@@ -248,6 +248,7 @@ sub Gateway { + Action => $action, + Subject => $Subject, + Message => $Message, ++ CurrentUser => $CurrentUser, + Ticket => $Ticket, + TicketId => $args{ticket}, + Queue => $SystemQueueObj, diff --git a/lib/RT/Extension/CommandByMail.pm b/lib/RT/Extension/CommandByMail.pm index a0e6077..3e4b4fb 100644 --- a/lib/RT/Extension/CommandByMail.pm +++ b/lib/RT/Extension/CommandByMail.pm @@ -57,8 +57,24 @@ C<@MailPlugins> configuration, as follows: Set(@MailPlugins, qw(Auth::MailFrom Filter::TakeAction)); +For RT 4.4 or newer, the plugin code is in C, so +add this: + + Set(@MailPlugins, qw(Auth::MailFrom Action::CommandByMail)); + Be sure to include C in the list as well. +B The plugin name has changed for RT 4.4, so after upgrading you +must also update your C file to change +C to the new C. + +=item Patch RT + +For RT 4.4.0, apply the included patch: + + cd /opt/rt4 # Your location may be different + patch -p1 < /download/dir/RT-Extension-CommandByMail/etc/handle_action_pass_currentuser.patch + =item Restart your webserver =back @@ -225,6 +241,14 @@ If set, the body will not be examined, only the headers. This extension is incompatible with C RT option. +=head1 METHODS + +=head2 ProcessCommands + +This method provides the main email processing functionality. It supports +both RT 4.2 and earlier and 4.4 and later. To do this, the return hashes +contain some values used by 4.2 code and some used by 4.4. The return +values coexist and unused values are ignored by the different versions. =cut sub ProcessCommands { @@ -245,11 +269,19 @@ sub ProcessCommands { ."CurrentUser (actor) is not authorized. " ); return { CurrentUser => $args{'CurrentUser'}, - AuthLevel => $args{'AuthLevel'} }; + AuthLevel => $args{'AuthLevel'}, + MailError => 1, + ErrorSubject => "Permission Denied", + Explanation => "CurrentUser is not set when trying to " + . "process email command via CommandByMail", + Failure => 1 + }; } + $RT::Logger->debug("Running CommandByMail as ".$args{'CurrentUser'}->UserObj->Name); + # If the user isn't asking for a comment or a correspond, - # bail out + # bail out. Only relevant for pre-4.2. unless ( $args{'Action'} =~ /^(?:comment|correspond)$/i ) { return { CurrentUser => $args{'CurrentUser'}, AuthLevel => $args{'AuthLevel'} }; @@ -269,12 +301,16 @@ sub ProcessCommands { if (!$group->HasMemberRecursively($args{'CurrentUser'}->PrincipalObj)) { $RT::Logger->debug("CurrentUser not in CommandByMailGroup"); return { CurrentUser => $args{'CurrentUser'}, - AuthLevel => $args{'AuthLevel'} }; + AuthLevel => $args{'AuthLevel'}, + MailError => 1, + ErrorSubject => "Permission Denied", + Explanation => "User " . $args{'CurrentUser'}->UserObj->EmailAddress + . " is not in the configured CommandByMailGroup", + Failure => 1 + }; } } - $RT::Logger->debug("Running CommandByMail as ".$args{'CurrentUser'}->UserObj->Name); - my $headername = $new_config ? RT->Config->Get('CommandByMailHeader') : $RT::CommandByMailHeader; @@ -459,7 +495,13 @@ sub ProcessCommands { "Couldn't write $args{'Action'}." ." Fallback to standard mailgate. Error: $msg"); return { CurrentUser => $args{'CurrentUser'}, - AuthLevel => $args{'AuthLevel'} }; + AuthLevel => $args{'AuthLevel'}, + MailError => 1, + ErrorSubject => "Unable to execute $args{'Action'}", + Explanation => "Unable to execute $args{'Action'} on ticket " + . $args{'Ticket'}->Id . ": $msg", + Failure => 1 + }; } } @@ -853,7 +895,6 @@ sub _ReportResults { } - 1; __END__ diff --git a/lib/RT/Interface/Email/Action/CommandByMail.pm b/lib/RT/Interface/Email/Action/CommandByMail.pm new file mode 100644 index 0000000..6195345 --- /dev/null +++ b/lib/RT/Interface/Email/Action/CommandByMail.pm @@ -0,0 +1,56 @@ +package RT::Interface::Email::Action::CommandByMail; + +use warnings; +use strict; + +use Role::Basic 'with'; +with 'RT::Interface::Email::Role'; + +=head1 NAME + +RT::Interface::Email::Action::CommandByMail - Change metadata of ticket via email + +=head1 DESCRIPTION + +This action provides compatibility with the new mail plugin system introduced +in RT 4.4. It provides an alternate to the default comment and correspond +handlers provided by RT. + +=cut + +# To maintain compatibility with previous versions of CommandByMail, +# handle the standard comment and correspond actions. Follow the +# pattern from RT's default action handling for providing both. + +sub HandleComment { + _HandleEither( @_, Action => "Comment" ); +} + +sub HandleCorrespond { + _HandleEither( @_, Action => "Correspond" ); +} + +sub _HandleEither { + my %args = ( + Action => undef, + Message => undef, + Subject => undef, + Ticket => undef, + TicketId => undef, + Queue => undef, + @_, + ); + + my $return_ref = RT::Extension::CommandByMail::ProcessCommands(%args); + + if ( exists $return_ref->{'MailError'} and $return_ref->{'MailError'} ){ + MailError( + Subject => $return_ref->{'ErrorSubject'}, + Explanation => $return_ref->{'Explanation'}, + FAILURE => $return_ref->{'Failure'}, + ); + } + return; +} + +1;