#946454 ClamAV::Client: decode path to byte array (charset problem)

#946454#5
Date:
2019-12-09 08:36:42 UTC
From:
To:
Dear Mantainer

Thank you for this helpfull package.

I use the ClamAV::Client as part of an email processing script.
This script uses MIME::Tools to extract attachements from emails
guess their file names and save them to disk.

This is when I call scan_path($path); $path containing the filename
returned by MIME::Tools. The file is created by perl 'open' right
before calling scan_path($path):

binmode STDOUT, ":utf8";
open(FILE,">$path");
print FILE $attachment;
close(FILE);
my ($path,$found) = $av->scan_path($path);

I believe, MIME::Tools returns an utf-8 string as filename.
I suppose 'open' correctly converts this utf-8 filename to a binary
string as Unix does not care about filename encoding.

Unfortunately scan_path does not seem to do this conversion and
does not find a file with utf-8 characters created this way.

So this is a feature request to make scan_path correctly handle
filename charset.

#946454#10
Date:
2019-12-17 14:02:57 UTC
From:
To:
Update on this issue. Found Work-Around, or maybe I did something
wrong. But this solves my problem:

Extract the Filename with MIME::Parser

my $filename = $part->head->recommended_filename;
my $content;

open(FILE,">$filename);
	my $io = $part->open("r")) {
		while (defined($_ = $io->getline)) {
			print FILE $_;
		}
		$io->close;
	}
close(FILE);

And then when it come to check that file:

if (utf8::is_utf8($filename)) {
	utf8::encode($filename);
}

my ($path,$found) = $av->scan_path("$filename");