Skip Menu |

This queue is for tickets about the RT-Extension-CommandByMail CPAN distribution.

Report information
The Basics
Id: 58382
Status: new
Priority: 0/
Queue: RT-Extension-CommandByMail

People
Owner: Nobody in particular
Requestors: stefan [...] cae.wisc.edu
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: [PATCH] Read commands from headers, other patch integration
We wanted commands to be able to be read from headers so as to be more transparent to users. While the user-submitted patch to strip the commands from the e-mail body was nice, it didn't work in all situations. Here is a patch that allows commands to be read from headers. The default header is X-RT-Do: although it can be changed by a configuration option. To enable, set $CommandByMailDoHeaders to 1 in RT_SiteConfig.pm If you want to use a different header, for example X-RT-DoCommand or something, you can set that with $CommandByMailHeaderString in the file. If unset, it defaults to X-RT-Do: This is based off of the 0.08_01 source. A second patch will follow in a second message that integrates several patches, and is more robust. -stefan
Subject: ReadFromHeaders.diff
--- TakeAction.pm.orig 2010-06-14 13:28:32.000104000 -0500 +++ TakeAction.pm 2010-06-14 13:31:27.000182000 -0500 @@ -196,6 +196,19 @@ } } + if ($RT::Config->Get('CommandByMailDoHeaders')) { + my $header_string = RT::Config->Get('CommandByMailHeaderString'); + $header_string = (defined($header_string)) ? $header_string : 'X-RT-Do'; + # Read any X-RT-Do headers + my @command_headers = $args{'Message'}->get($header_string); + + foreach my $cmd (@command_headers) { + # make sure they follow the correct format, if good, put it at front + next if $cmd !~ /^(?:(\S+(?:{.*})?)\s*?:\s*?(.*)\s*?|)$/; + unshift @content, $cmd; + } + } + my @items; my $found_pseudoheaders = 0; foreach my $line (@content) {
From: stefan [...] cae.wisc.edu
As promised, here is the full patch for the our implementation of RT. This includes our header integration and also includes patches from: * Francois Deppierraz for Command Stripping from the body (Bug #31795) * Roderick Schertler for ignoring commands from unprivileged users (Bug #27333) * Bryan McLellan for e-mailing errors to a generic address (Bug #40480) as well as our modifications to those patches. The full list of variables available for use: * $CommandByMailStripOut - set to 1 to strip commands from the body * $CommandByMailErrorEmailAddress - set to whatever address you want error messages to go to * $CommandByMailErrorsToPrivileged - if set to 1, will e-mail errors to the user if the user is privileged. Use in conjunction with $CommandByMailErrorEmailAddress. * $CommandByMailDoHeaders - set to 1 to read commands from headers * $CommandByMailHeaderString - set to whatever you want to use for a header. If unset, defaults to X-RT-Do * $CommandByMailIgnoreBody - useful in conjunction with $CommandByMailDoHeaders, if set to 1 will not even attempt to read commands from the body * $CommandByMailOnlyPrivileged - if set to 1, will only try commands if the user is privileged If none of the options are set, the code should still work. Any combination of options should work together as well, although some don't make much sense (Ignoring the body while not telling it to do headers, for example, would make this extension unnecessary, and ErrorsToPrivileged makes no sense without the ErrorEmailAddress set) Please let me know if you have any comments or run into any bugs - it tested OK for us. -stefan On Mon Jun 14 14:35:26 2010, shortspecialbus wrote: Show quoted text
> A second patch will follow in > a second message that integrates several patches, and is more robust. > > -stefan
Subject: TakeActionAllChanges.diff
159a160,170 > > # If we have $RT::CommandByMailOnlyPrivileged set, then > # Non-privileged users can't use this extension. The main benefit > # here is they won't accidentally try to ("Guys: My computer is on > # fire!") and get errors. > if ($RT::CommandByMailOnlyPrivileged) { > unless ( $args{'CurrentUser'}->Privileged ) { > $RT::Logger->debug("Filter::TakeAction ignoring non-privileged user"); > return ( $args{'CurrentUser'}, $args{'AuthLevel'} ); > } > } 187a199,200 > my $body; > 190c203,205 < my $body = $part->bodyhandle or next; --- > # If we're ignoring the body, skip all this > last if (RT::Config->Get('CommandByMailIgnoreBody')); > $body = $part->bodyhandle or next; 198a214,226 > if ($RT::Config->Get('CommandByMailDoHeaders')) { > my $header_string = RT::Config->Get('CommandByMailHeaderString'); > $header_string = (defined($header_string)) ? $header_string : 'X-RT-Do'; > # Read any X-RT-Do headers > my @command_headers = $args{'Message'}->get($header_string); > > foreach my $cmd (@command_headers) { > # make sure they follow the correct format, if good, put it at front > next if $cmd !~ /^(?:(\S+(?:{.*})?)\s*?:\s*?(.*)\s*?|)$/; > unshift @content, $cmd; > } > } > 222a251,268 > # Strip out commands from content if configuration says so, > # but not if we ignore the body > if (($RT::CommandByMailStripOut) && !($RT::CommandByMailIgnoreBody)) { > my @content = $body->as_lines; > my $io = $body->open("w") or die "Cannot open body"; > > my $body_top = 1; > foreach my $line (@content) { > # Strip out commands only at the top > next if ($body_top && $line =~ /^(?:(\S+)\s*?:\s*?(.*)\s*?|)$/); > $body_top = 0; > > $io->print($line); > } > > $io->close() or die "Cannot close body"; > } > 696a743 > # default to mailing the user for errors 697a745,755 > if (defined ( $RT::CommandByMailErrorEmailAddress ) ) { > # If we want to mail privileged users their errors and the current > # user is privileged, mail it to them instead of the error address > if ( (defined($RT::CommandByMailErrorsToPrivileged)) && > ($args{'CurrentUser'}->Privileged) ) { > $ErrorsTo = RT::Interface::Email::ParseErrorsToAddressFromHead( $args{'Message'}->head ); > } else { > # We want to mail a generic address > $ErrorsTo = $RT::CommandByMailErrorEmailAddress; > } > }