INN commit: trunk/control (controlchan.in modules/checkgroups.pl)

INN Commit Russ_Allbery at isc.org
Sun Mar 8 12:48:37 UTC 2009


    Date: Sunday, March 8, 2009 @ 05:48:36
  Author: iulius
Revision: 8375

Add encodings to checkgroups processing:  controlchan now looks
for the charset and try to convert the descriptions into
the local encoding.

Defaults are cp1252 for expected encodings (unless the charset
is properly set in the checkgroups message, or control.ctl
dictates another charset) and utf-8 for the local encoding.

close #4

Modified:
  trunk/control/controlchan.in
  trunk/control/modules/checkgroups.pl

------------------------+
 controlchan.in         |    2 +-
 modules/checkgroups.pl |   47 +++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 42 insertions(+), 7 deletions(-)

Modified: controlchan.in
===================================================================
--- controlchan.in	2009-03-05 20:02:54 UTC (rev 8374)
+++ controlchan.in	2009-03-08 12:48:36 UTC (rev 8375)
@@ -303,7 +303,7 @@
     # warnings from undefined values later on in permission checking).
     if ($type eq 'newgroup' or $type eq 'rmgroup') {
         unless ($newsgroup) {
-            return ('drop', undef, undef);
+            return ('drop', undef, undef, undef);
         }
     }
 

Modified: modules/checkgroups.pl
===================================================================
--- modules/checkgroups.pl	2009-03-05 20:02:54 UTC (rev 8374)
+++ modules/checkgroups.pl	2009-03-08 12:48:36 UTC (rev 8375)
@@ -19,12 +19,46 @@
 
 sub control_checkgroups {
     my ($par, $sender, $replyto, $site, $action, $log, $approved,
-        $article) = @_;
+        $article, $charset_from, $charset_to) = @_;
     my ($newsgrouppats) = @$par;
     my $head = $article->head;
     my @headers = split(/\r?\n/, $head->stringify);
     my @body = split(/\r?\n/, $article->stringify_body);
+    my @newbody;
 
+    my $charset_message;
+    if (defined $head->mime_attr('Content-Type.charset')) {
+        $charset_message = $head->mime_attr('Content-Type.charset');
+    }
+
+    foreach (@body) {
+        my ($ngname, $ngdesc) = split(/\s+/, $_, 2);
+        my $charset_newsgroup = $charset_message;
+
+        # Find the right charset if absent or forced by control.ctl.
+        foreach (@$charset_from) {
+            my ($group, $charset) = split /:/;
+            if ($ngname =~ /$group/) {
+                if (not defined $charset_newsgroup or $charset =~ /=force/) {
+                    $charset_newsgroup = $charset;
+                    $charset_newsgroup =~ s/\^(.+)\$/$1/;
+                    $charset_newsgroup =~ s/\\//g;
+                    $charset_newsgroup =~ s/=force//;
+                }
+                last;
+            }
+        }
+
+        if (not defined $charset_newsgroup
+            or not defined Encode::find_encoding($charset_newsgroup)) {
+            $charset_newsgroup = "cp1252";  # Default charset, when undefined.
+        }
+
+        # Properly encode the newsgroup description.
+        Encode::from_to($ngdesc, $charset_newsgroup, $charset_to);
+        push(@newbody, $ngname."\t".$ngdesc);
+    }
+
     if ($action eq 'mail') {
         my $mail = sendmail("checkgroups by $sender");
         print $mail "$sender posted the following checkgroups message:\n\n";
@@ -35,22 +69,23 @@
 of the message to docheckgroups while logged
 in as user ID "$INN::Config::newsuser":
 
-$INN::Config::pathbin/docheckgroups '$newsgrouppats' <<zRbJ
+$INN::Config::pathbin/docheckgroups -u '$newsgrouppats' <<zRbJ
 END
-        print $mail map { s/^~/~~/; "$_\n" } @body;
+        print $mail map { s/^~/~~/; "$_\n" } @newbody;
         print $mail "zRbJ\n";
         close $mail or logdie("Cannot send mail: $!");
     } elsif ($action eq 'log') {
         if ($log) {
+            # The checkgroups is written unprocessed (@body and not @newbody).
             logger($log, "checkgroups by $sender", $article);
         } else {
             logmsg("checkgroups by $sender");
         }
     } elsif ($action eq 'doit') {
         if (defined &local_docheckgroups) {
-            local_docheckgroups(\@body, $newsgrouppats, $log, $sender);
+            local_docheckgroups(\@newbody, $newsgrouppats, $log, $sender);
         } else {
-            docheckgroups(\@body, $newsgrouppats, $log, $sender);
+            docheckgroups(\@newbody, $newsgrouppats, $log, $sender);
         }
     }
 }
@@ -68,7 +103,7 @@
     open(OLDOUT, '>&STDOUT') or die $!;
     open(STDIN, "$tempfile.art") or die $!;
     open(STDOUT, ">$tempfile") or die $!;
-    my $st = system("$INN::Config::pathbin/docheckgroups", $newsgrouppats);
+    my $st = system("$INN::Config::pathbin/docheckgroups", "-u", $newsgrouppats);
     logdie('Cannot run docheckgroups: ' . $!) if $st == -1;
     logdie('docheckgroups returned status ' . ($st & 255)) if $st > 0;
     close(STDIN);




More information about the inn-committers mailing list