patches to include/exclude based on From field in header

[email protected] Wed, 15 Jan 2003 17:37:28 -0500 (EST)
Newsgroups gmane.network.ubh
Message-ID <[email protected]>
This requires you add a column authors to your table headers 
which can be done with the following commands:

mysql> use ubhcache
mysql> alter table headers add authors char(255) not null after subject;
mysql> quit

It addes two new switches and two new ubhrc opts
-K or OPT_K include these authors
-N or OPT_N don't include these authors

Like -I/-X you can only have one of these not both.  You can have one of -I/-X and one of -K/-N.


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Flexible Keyboard is the ideal accessory for PDA users that are on the move.
http://us.click.yahoo.com/dCBVZC/WnCFAA/xGHJAA/IHFolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[email protected]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
ubh.newer.patch (text/plain, 8.1 KB)
--- ubh.old	2003-01-15 15:19:01.000000000 -0500
+++ ubh	2003-01-15 17:22:14.000000000 -0500
@@ -138,8 +138,10 @@
     -c <file> Use file as config file instead of default (ubhrc).
     -G <group> Process this one group.
     -a Process all articles (disregards whether article is marked read).
-    -I <regexp> Inclusion search filter (double quote on command line)
-    -X <regexp> Exclusion search filter (double quote on command line)
+    -I <regexp> Inclusion search filter for Subject (double quote on command line)
+    -X <regexp> Exclusion search filter for Subject (double quote on command line)
+    -K <regexp> Inclusion search filter for From (double quote on command line)
+    -N <regexp> Exclusion search filter for From (double quote on command line)
     -C Clean filenames (change all non alphanumeric to '_')
     -L Long filenames (use subject as the filename)
     -O [yes|no|skip] Overwrite strategy
@@ -186,6 +188,21 @@
         }
     }
 
+    if ($opt{'K'}) {
+        eval { "" =~ /$opt{'K'}/ };
+        if ($@) {
+            $log->fatal("invalid -K pattern: ", $@);
+            $error = 1;
+        }
+    }
+    
+    if ($opt{'N'}) {
+        eval { "" =~ /$opt{'N'}/ };
+        if ($@) {
+            $log->fatal("invalid -N pattern: ", $@);
+            $error = 1;
+        }
+
     if ($opt{'w'}) {
         print_warranty;
         exit(0);
@@ -288,6 +305,12 @@
             elsif ($keyword =~ /OPT_X/) {
                 $opt{'X'} = $value;
             }
+            elsif ($keyword =~ /OPT_K/) {
+                $opt{'K'} = $value;
+            }
+            elsif ($keyword =~ /OPT_N/) {
+                $opt{'N'} = $value;
+            }
             elsif ($keyword =~ /OPT_C/) {
                 $opt{'C'} = 1;
             }
@@ -555,7 +578,7 @@
             exit(-1);
         }
         else {
-            print DUMPARTICLE @{$body};
+            print DUMPARTICLE @{$body} or die "cannot print: $!";
             close DUMPARTICLE;
         }
     }
@@ -790,7 +813,7 @@
                         }
                         binmode(FH);
                         seek(FH, $offset, 0);
-                        print FH $decoded;
+                        print FH $decoded or die "cannot print: $!";
                         close(FH);
                         $log->debug("Finished decoding file.");
                     } 
@@ -815,7 +838,7 @@
                         }
                         else {
                             binmode(FH);
-                            print FH $decoded;
+                            print FH $decoded or die "cannot print: $!";
                             close(FH);
                             $log->info("Finished decoding.");
                         }
@@ -891,7 +914,7 @@
             else {
                 binmode YENCTEMP;
                 foreach (@{$article}) {
-                    print YENCTEMP;
+                    print YENCTEMP or die "cannot print: $!";
                 }
                 close YENCTEMP;
 
@@ -1242,7 +1265,7 @@
             my $mimefilename = $platform->get_tempfilename;
             open(SINGFILE, "> ".$mimefilename)
                 or die "ERROR: open(".$mimefilename.") failed.\n";       
-            print SINGFILE @{$article};
+            print SINGFILE @{$article} or die "cannot print: $!";
             close SINGFILE;
 
             if ($opt{'D'}) {
@@ -1569,7 +1592,7 @@
 
             # Part was successfully downloaded.
             if ($opt{'A'}) {
-                print PARTSFILE @{$p};
+                print PARTSFILE @{$p} or die "cannot print: $!";
             }
             else {
                 push(@parts, @{$p});
@@ -1722,7 +1745,7 @@
         $log->info("Begin processing single part articles.");
    
         my $stmt = 
-            "SELECT h.msgid, h.subject, h.category ".
+            "SELECT h.msgid, h.subject, h.authors, h.category ".
             "FROM headers h, xref_headers x ".
             "WHERE h.header_id = x.header_id ".
             "AND x.newsgroup_id = ".$group->{newsgroup_id}." ".
@@ -1752,7 +1775,7 @@
         $sth->execute;
 
         while (my @cols = $sth->fetchrow_array) {
-            my ($msgid, $subject, $category) = @cols;
+            my ($msgid, $subject, $authors, $category) = @cols;
 
             my $title;
             if (!$opt{'g'}) {
@@ -1790,6 +1813,20 @@
                 next;
             }
 
+            # Inclusion/exclusion filtering.
+            # Skip authors that don't match the inclusion filter.
+            # Skip authors that do match the exclusion filter.
+            if ((defined $opt{'K'} && $authors !~ /$opt{'K'}/o) ||
+                (defined $opt{'N'} && $authors =~ /$opt{'N'}/o)) {
+
+                # It was either not included or was excluded.
+                if ($opt{'z'}) {
+                    $dbh->do(
+                             "UPDATE headers SET status = 'READ' ".
+                             "WHERE msgid = ".$dbh->quote($msgid));
+                }
+                next;
+            }
             # Skip it if there is a batch file and it isn't mentioned.
             next if (defined $batchfile && !$batchfile->contains($title));
 
@@ -1837,7 +1874,7 @@
         $log->info("Begin processing multipart articles.");
 
         my $stmt = 
-            "SELECT a.assemble_id, h.msgid, h.subject, h.category ".
+            "SELECT a.assemble_id, h.msgid, h.subject, h.authors, h.category ".
             "FROM assemble a, headers h, xref_headers x ".
             "WHERE a.assemble_id = x.assemble_id ".
             "AND h.header_id = x.header_id ".
@@ -1863,7 +1900,7 @@
         $sth->execute;
 
         while (my @cols = $sth->fetchrow_array) {
-            my ($assemble_id, $msgid, $subject, $category) = @cols;
+            my ($assemble_id, $msgid, $subject, $authors, $category) = @cols;
 
             # Try to pick a title out of the subject using filename extension filter.
             my $title;
@@ -1898,6 +1935,21 @@
                 next;
             }
 
+            # Inclusion/exclusion filtering.
+            # Skip authors that don't match the inclusion filter.
+            # Skip authors that do match the exclusion filter.
+            if ((defined $opt{'K'} && $authors !~ /$opt{'K'}/o) ||
+                (defined $opt{'N'} && $authors =~ /$opt{'N'}/o)) {
+
+                # It was either not included or was excluded.
+                if ($opt{'z'}) {
+                    $dbh->do(
+                             "UPDATE headers SET status = 'READ' ".
+                             "WHERE msgid = ".$dbh->quote($msgid));
+                }
+                next;
+            }
+
             # Skip it if there is a batch file and it isn't mentioned.
             next if (defined $batchfile && !$batchfile->contains($title));
 
@@ -1969,7 +2021,7 @@
 
 =head1 SYNOPSIS
 
-ubh [-c file] [(-S|-M)] [-A] [-b file] [-C] [-d] [-D] [-g] [-a] [(-I|-X) pattern] [-L] [-O (yes|no|skip)] [-u] [-w] [-y] [-z]
+ubh [-c file] [(-S|-M)] [-A] [-b file] [-C] [-d] [-D] [-g] [-a] [(-I|-X) pattern] [(-K|-N) pattern] [-L] [-O (yes|no|skip)] [-u] [-w] [-y] [-z]
 
 =head1 DESCRIPTION
 
@@ -2024,6 +2076,7 @@
 C<ubhcatalog>), one per line, to be downloaded.
 
 Mutually exclusive with B<-I> and B<-X>.
+Mutually exclusive with B<-K> and B<-N>.
 
 =item -d
 
@@ -2075,12 +2128,22 @@
 
 =item -I I<regexp>
 
-Inclusion search filter (double quote on command line).
+Inclusion search filter for Subject field(double quote on command line).
+I<regexp> is any valid Perl regular expression.
+
+=item -K I<regexp>
+
+Inclusion search filter for From field(double quote on command line).
 I<regexp> is any valid Perl regular expression.
 
 =item -X I<regexp>
 
-Exclusion search filter (double quote on command line).
+Exclusion search filter for Subject field(double quote on command line).
+I<regexp> is any valid Perl regular expression.
+
+=item -N I<regexp>
+
+Exclusion search filter for From field(double quote on command line).
 I<regexp> is any valid Perl regular expression.
 
 =item -C
ubhdb.newer.patch (text/plain, 1.4 KB)
--- ubhdb.old	2003-01-15 15:02:32.000000000 -0500
+++ ubhdb	2003-01-15 17:07:45.000000000 -0500
@@ -58,7 +58,7 @@
     my $log = get_logger("ubhdb::add_articles");
 
     my %headers;
-    foreach my $h (qw(Subject Message-ID Date)) {
+    foreach my $h (qw(Subject From Message-ID Date)) {
         $headers{$h} = $nntp->xhdr($h, "$first-$last");
     }
 
@@ -70,7 +70,8 @@
                                  str2time($headers{'Date'}->{$i}),
                                  "GMT"));
         my $number   = $i;
-        my $subject  = $headers{'Subject'}->{$i};
+	my $subject  = $headers{'Subject'}->{$i};
+	my $authors = $headers{'From'}->{$i};
 	next if (!$subject || $subject =~ /^\s+$/);
 
         # Categorize this header based on its subject.
@@ -150,13 +151,14 @@
         # until it has been assembled.
         my $stmt = 
             "INSERT IGNORE INTO headers ".
-            "(msgid,date,subject,category,status".
+            "(msgid,date,subject,authors,category,status".
             (defined $part && defined $total ? ",part,totalparts" : '').
             ") ".
             "VALUES (".
             $msgid.",".
             $date.",".
             $dbh->quote($subject).",".
+            $dbh->quote($authors).",".
             $dbh->quote($category).",".
             $dbh->quote('IMPORTING').
             (defined $part && defined $total ? ",".$part.",".$total : '').