0

We have an ASSP (Antispam SMTP Proxy) v2.3.3.13217 (the last) installed (on Ubuntu Server 13.04). After some time it starts printing at console:

...
Wide character in print at sub main::mlogWrite line 30
Wide character in print at sub main::mlogWrite line 32
Wide character in print at sub main::mlogWrite line 30
Wide character in print at sub main::mlogWrite line 32
...

And so on.

Here is this sub from assp.pl:

sub mlogWrite {
    return if $WorkerNumber;
    my @m;
    my $items;
    threads->yield();
    &debugWrite();
    threads->yield;
    $items = $mlogQueue->pending();
    $refreshWait = (time - $lastmlogWrite) > 5 ? 5 : 1;
    return if (! $items);
    threads->yield();
    @m = $mlogQueue->dequeue_nb($items);
    threads->yield();
    my @tosyslog;
    while (@m) {
       my $logline = my $line = de8(shift @m);
       if ($Unidecode2Console) {
           eval{
               $line = Text::Unidecode::unidecode($line);
           } or print "con uni-decoding error: $@";
       } else {
           eval{
               Encode::from_to($line,'UTF-8',$ConsoleCharset,sub { return '?'; })
                   if $ConsoleCharset && $ConsoleCharset !~ /utf-?8/oi;
               1;
           } or print "con encoding error: $@";
       }
       push @tosyslog,substr($line,length($LogDateFormat)) if ($sysLog && ($CanUseSyslog || ($sysLogPort && $sysLogIp)));
       if ($line !~ /\*\*\*assp\&is\%alive\$\$\$/o) {
           print $line unless ($silent);
           w32dbg($line) if ($CanUseWin32Debug);
           print $LOG $logline if ($logfile && $asspLog && fileno($LOG));
           print $LOGBR $logline if ($logfile &&
                                     $asspLog &&
                                     fileno($LOGBR) &&
                                     $ExtraBlockReportLog &&
                                     $logline =~ /\[\s*spam\sfound\s*\]/io);
       }
       if ($logline !~ /page:\/maillog/o) {
           shift @RealTimeLog if (@RealTimeLog > 33);
           push @RealTimeLog, $logline;
           $lastmlogWrite = time;
       }
    }
    tosyslog('info', \@tosyslog) if (@tosyslog && $sysLog && ($CanUseSyslog || ($sysLogPort && $sysLogIp)));
    $MainThreadLoopWait = 1;
} 

I am very very sorry, but I don't know perl. Where is the error here?

Full assp.pl is at http://sourceforge.net/projects/assp/files/ASSP%20V2%20multithreading/2.3.3%2013217/ASSP_2.3.3_13217.zip

vladon
  • 8,158
  • 2
  • 47
  • 91

2 Answers2

4

This error normally indicates that you've output a non-ASCII character to a filehandle (such as STDOUT) to a filehandle which is not expecting it.

A quick and dirty fix would be to add no warnings 'utf8'; to the line above the offending print statement. The proper solution would be to ensure the filehandle is opened in the correct mode.

tobyink
  • 13,478
  • 1
  • 23
  • 35
3

My answer here will explain what is going on.

I don't think that just turning off the warning (as suggested in the answer that you've accepted) is a very good solution. You should make sure that your output filehandle is expecting data in the output encoding that you are using.

If you're always dealing with UTF8 output then the -C command line switch is a quick and easy way to set the standard filehandles (STDIN, STDOUT and STDERR) to expect UTF8 (see perldoc perlrun for details). But it looks like you have a variable called $ConsoleCharset which contains the name of the expected output encoding. You can therefore probably use the binmode function to set STDOUT to the correct encoding.

binmode STDOUT, ":encoding($ConsoleCharset)";

Character set support in Perl is a complex but important area. Just ignoring errors is just storing up more pain for the future.

Community
  • 1
  • 1
Dave Cross
  • 68,119
  • 3
  • 51
  • 97
  • I found parameter Console Charset in ASSP Admin Site, it was set to "System Default", I'd run `echo $LANG` and got `en_US.UTF-8`, so I changed var to "utf8" and warnings disappeared. Big thanks! – vladon Oct 03 '13 at 13:07
  • Upd. Some warnings disappeared, previously they was very often, and now they are rare but also displayed :-( – vladon Oct 03 '13 at 13:09
  • So, I found line `our $Unidecode2Console = 0; # (0/1) use Text::Unidecode to decode NONASCII characters to ASCII - if available - if set - 'ConsoleCharset' is ignored` and set it to 1, warnings totally disappeared. Thank you for tip! – vladon Oct 03 '13 at 13:15
  • I'm not sure why you're thanking me for the tip. You seem to have completely ignored my advice and gone off in a completely different direction. – Dave Cross Oct 03 '13 at 13:29