[Bps-public-commit] r17244 - in RT-Extension-ExtractCustomFieldValues: etc lib/RT/Action lib/RT/Extension

alexmv at bestpractical.com alexmv at bestpractical.com
Mon Dec 15 17:13:47 EST 2008


Author: alexmv
Date: Mon Dec 15 17:13:46 2008
New Revision: 17244

Modified:
   RT-Extension-ExtractCustomFieldValues/META.yml
   RT-Extension-ExtractCustomFieldValues/README
   RT-Extension-ExtractCustomFieldValues/etc/initialdata
   RT-Extension-ExtractCustomFieldValues/lib/RT/Action/ExtractCustomFieldValues.pm
   RT-Extension-ExtractCustomFieldValues/lib/RT/Extension/ExtractCustomFieldValues.pm

Log:
 * Add wildcard functionality
 * Documentation and example cleanups

Modified: RT-Extension-ExtractCustomFieldValues/META.yml
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/META.yml	(original)
+++ RT-Extension-ExtractCustomFieldValues/META.yml	Mon Dec 15 17:13:46 2008
@@ -2,7 +2,7 @@
 abstract: RT Extension-ExtractCustomFieldValues Extension
 author: ~
 distribution_type: module
-generated_by: Module::Install version 0.68
+generated_by: Module::Install version 0.70
 license: unknown
 meta-spec: 
   url: http://module-build.sourceforge.net/META-spec-v1.3.html
@@ -15,5 +15,4 @@
     - po
     - var
     - inc
-    - t
-version: 1.8
+version: 1.9

Modified: RT-Extension-ExtractCustomFieldValues/README
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/README	(original)
+++ RT-Extension-ExtractCustomFieldValues/README	Mon Dec 15 17:13:46 2008
@@ -1,7 +1,7 @@
 CONTACT:
 
-This is version 5 of ExtractCustomFieldValue which is a
-contribution to the RT System <http://www.bestpractical.com/rt/>, as
+This is version 1.9 of RT::Extension::ExtractCustomFieldValues, which
+is a contribution to RT <http://www.bestpractical.com/rt/>, as
 modified by Best Practical for customer use.
 
 All bug reports and support requests should be referred to Best
@@ -9,13 +9,13 @@
 
 ACKNOWLEDGEMENT:
 
-ExtractCustomFieldValue was originally written by Dirk Pape
+ExtractCustomFieldValues was originally written by Dirk Pape
 <pape at inf.fu-berlin.de>.
 
 PURPOSE:
 
-ExtractCustomFieldValue consists of a new ScripAction
-"ExtractCustomFieldValue", which can be used to scan incoming requests
+ExtractCustomFieldValues consists of a new ScripAction
+"ExtractCustomFieldValues", which can be used to scan incoming emails
 to set values of custom fields.
 
 INSTALL:
@@ -24,15 +24,21 @@
     make install
     make initdb
 
+When using this extension with RT 3.8, you will need to add
+"RT::Extension::ExtractCustomFieldValues" to the Plugins
+configuration:
+
+    Set( @Plugins, qw(RT::Extension::ExtractCustomFieldValues) );
+
 USE:
 
-To use the ScripAction you have to create a Template and a Scrip in
-RT. The Template consists of the lines which control the scanner. All
-non comment lines are of the following format:
+To use the ScripAction, create a Template and a Scrip in RT. The
+Template consists of the lines which control the scanner. All
+non-comment lines are of the following format:
 
 <cf-name>|<Headername>|<MatchString>|<Postcmd>|<Options>
 
-where
+where:
 
 <cf-name>     is the name of a custom field (must be created in RT)
               If this field is blank, the match will be run and Postcmd
@@ -43,24 +49,28 @@
               body of the email
 <MatchString> is a reg. expr. to find a match in the header or body
               if the MatchString matches a comma separated list
-	      and the cf is a multi value cf then each item in the
-	      list is added as a separate value
+              and the cf is a multi value cf then each item in the
+              list is added as a separate value
 <Postcmd>     is a perl command to be evaluated on $_, where $_ is either
               $1 or $& from the match performed with <MatchString>
 <Options>     is a string of letters which may control some aspects.
-	      In this time the only letter with a meaning is "q":
-	      q - (quiet) do not record a transaction when adding a CFV
+              Possible options include:
+                q - (quiet) Don't record a transaction when adding the
+                    custom field value
+                * - (wildcard) The MatchString regex should contain _two_
+                    capturing groups, the first of which is the CF name,
+                    the second of which is the value.  If this option is
+                    given, the <cf-name> field is ignored.
 
-you can change the Separator string (initially "\|") during the template with a line
+you can change the Separator string (initially "\|") during the
+template with:
 
 Separator=<anyregexp>
 
-e.g. Separator=\|--\|
-
-this may be necessary, if you want to use a "|" in one of the patterns in
-the controlling lines.
+Changing the separator may be necessary, if you want to use a "|" in
+one of the patterns in the controlling lines.
 
-an example template with some further explanations is installed on
+An example template with some further examples is installed during
 "make install" or "make insert-template".
 
 Your new Scrip should use a ScripAction of 'Extract Custom Field Values' with

Modified: RT-Extension-ExtractCustomFieldValues/etc/initialdata
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/etc/initialdata	(original)
+++ RT-Extension-ExtractCustomFieldValues/etc/initialdata	Mon Dec 15 17:13:46 2008
@@ -12,39 +12,52 @@
     {  Queue       => '0',
        Name        => 'CustomFieldScannerExample',                     # loc
        Description => 'Example Template for ExtractCustomFieldValues', # loc
-       Content     => '# Syntax:
-# cf-name | Headername or "Body" | MatchString(re) | Postcmd | Options
-#
-# allowed Options:
-# q - dont record a transaction for adding the CFV
-#
-# examples:
-# 1. put the content of Header X-MI-Test into the cf testcf
-# testcf|X-MI-Test|.*|
-#
-# 2. scan body for Host:name and put name into bodycf
-# bodycf|Body|Host:\s*(\w+)|
-#
-# 3. scan the Header X-MI-IP for an IP-Adresse and get the hostname out of it
+       Content     => <<EOTEXT
+#### Syntax:
+# CF Name | Header name or "Body" | MatchString(re) | Postcmd | Options
+
+#### Allowed Options:
+
+# q - (quiet) Don't record a transaction for adding the custom field
+#     value
+# * - (wildcard) The MatchString regex should contain _two_
+#     capturing groups, the first of which is the CF name,
+#     the second of which is the value.  If this option is
+#     given, the <cf-name> field is ignored.
+
+#### Examples:
+
+# 1. Put the content of the "X-MI-Test" header into the "testcf"
+#    custom field:
+# testcf|X-MI-Test|.*
+
+# 2. Scan the body for Host:name and put name into the "bodycf" custom
+#    field:
+# bodycf|Body|Host:\s*(\w+)
+
+# 3. Scan the "X-MI-IP" header for an IP-Adresse and get the hostname
+#    by reverse-resolving it:
 # Hostname|X-MI-IP|\d+\.\d+\.\d+\.\d+|use Socket; ($value) = gethostbyaddr(inet_aton($value),AF_INET);
 
-# scan X-Mailer into cf Mailer
-mailer|X-Mailer|.*|
+# 4. scan the "CC" header for an many email addresses, and add them to
+#    a custom field named "parsedCCs". If "parsedCCs" is a multivalue
+#    CF, then this should yield separate values for all email adress
+#    found.
+# parsedCCs|CC|.*|$value =~ s/^\s+//; $value =~ s/\s+$//;
+
+# 5. Looks for an "Email:" field in the body of the email, then loads
+#    up that user and makes them privileged The blank first field
+#    means the automatic CustomField setting is not invoked.
+# |Body|Email:\s*(.+)$|my $u = RT::User->new($RT::SystemUser); $u->LoadByEmail($value); $u->SetPrivileged(1)|
 
-# scan the Header X-REMOTE-IP for an IP-Address and get the hostname out of it
-host|X-REMOTE-IP|\d+\.\d+\.\d+\.\d+|use Socket; ($value) = gethostbyaddr(inet_aton($value),AF_INET); $value = "$value (remote-ip)";
+# 6. Looks for any text of the form "Set CF Name: Value" in the body,
+#    and sets the CF named "CF Name" to the given value, which may be
+#    multi-line.  The '*' option controls the wildcard nature of this
+#    example.
+# Separator=!
+# !Body!^Set ([^\n:]*?):\s*((?s).*?)(?:\Z|\n\Z|\n\n)!!*
 
-# scan the CC-Header for an many mail addresses and add them to a multivalued cf
-# !this is untested. If parsedCCs is a multi value CF, then this should yield to
-# separate values for all emailadresses found
-parsedCCs|CC|.*|$value =~ s/^\s+//; $value =~ s/\s+$//;
-
-# Looks for the email field in the body of the email
-# Loads up that user and makes them privileged
-# The blank first field means the automatic CustomField setting
-# is not invoked.
-|Body|Email:\s*(.+)$|my $u = RT::User->new($RT::SystemUser); $u->LoadByEmail($value); $u->SetPrivileged(1)|
-'
+EOTEXT
     }
 );
 

Modified: RT-Extension-ExtractCustomFieldValues/lib/RT/Action/ExtractCustomFieldValues.pm
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/lib/RT/Action/ExtractCustomFieldValues.pm	(original)
+++ RT-Extension-ExtractCustomFieldValues/lib/RT/Action/ExtractCustomFieldValues.pm	Mon Dec 15 17:13:46 2008
@@ -6,15 +6,15 @@
 
 use base qw(RT::Action::Generic);
 
-our $VERSION = 1.3;
+our $VERSION = 1.9;
 
 sub Describe  {
-  my $self = shift;
-  return (ref $self );
+    my $self = shift;
+    return (ref $self );
 }
 
 sub Prepare {
-  return (1);
+    return (1);
 }
 
 sub Commit {
@@ -39,6 +39,20 @@
         }
         my ($CustomFieldName,$InspectField,$MatchString,$PostEdit,$Options) = split(/$Separator/);
 
+        if ( $Options =~ /\*/ ) {
+            ProcessWildCard(
+                Field      => $InspectField,
+                Match      => $MatchString,
+                PostEdit   => $PostEdit,
+                Attachment => $FirstAttachment,
+                Queue      => $Queue,
+                Ticket     => $Ticket,
+                Transaction => $Transaction,
+                Options    => $Options,
+            );
+            next;
+        }
+
         my $cf;
         if ($CustomFieldName) {
             $cf = LoadCF( Field => $CustomFieldName, Queue => $Queue );
@@ -46,7 +60,8 @@
 
         my $match = FindMatch( Field           => $InspectField, 
                                Match           => $MatchString,
-                               FirstAttachment => $FirstAttachment );
+                               FirstAttachment => $FirstAttachment,
+                           );
 
         my %processing_args = (
             CustomField => $cf,
@@ -82,12 +97,30 @@
 
     if ( $cf->id ) {
         $RT::Logger->debug("load cf done: ". $cf->id );
-    } else {
+    } elsif (not $args{Quiet}) {
         $RT::Logger->error("couldn't load cf $CustomFieldName");
     }
 
     return $cf;
+}
 
+sub ProcessWildCard {
+    my %args = @_;
+
+    my $content
+        = lc $args{Field} eq "body"
+        ? $args{Attachment}->Content
+        : $args{Attachment}->GetHeader( $args{Field} );
+    while ($content =~ /$args{Match}/mg) {
+        my ($cf, $value) = ($1, $2);
+        $cf = LoadCF(Field => $cf, Queue => $args{Queue}, Quiet => 1);
+        next unless $cf;
+        ProcessCF(
+            %args,
+            CustomField => $cf,
+            Match => $value
+        );
+    }
 }
 
 sub FindMatch {
@@ -105,7 +138,7 @@
     } else {
         $RT::Logger->debug("look for match in Header $args{Field}");
         if ($args{FirstAttachment}->GetHeader("$args{Field}") =~ /$args{Match}/) {
-            $match = $1||$&;
+            $match = $1 || $&;
             $RT::Logger->debug("matched value: $match");
         }
     }

Modified: RT-Extension-ExtractCustomFieldValues/lib/RT/Extension/ExtractCustomFieldValues.pm
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/lib/RT/Extension/ExtractCustomFieldValues.pm	(original)
+++ RT-Extension-ExtractCustomFieldValues/lib/RT/Extension/ExtractCustomFieldValues.pm	Mon Dec 15 17:13:46 2008
@@ -3,6 +3,6 @@
 
 package RT::Extension::ExtractCustomFieldValues;
 
-our $VERSION = '1.8';
+our $VERSION = '1.9';
 
 1;



More information about the Bps-public-commit mailing list