-my %mutteval_charmap=( # WARNING: Don't use "" or "0" here, see below for "|| warn"!
- '\\'=>"\\",
- 'r'=>"\r",
- 'n'=>"\n",
- 't'=>"\t",
- 'f'=>"\f",
- 'e'=>"\e",
- );
-# mutt/init.c/mutt_extract_token()
-sub mutteval
-{
- local $_=$_[0];
- return $_ if !s/^"//;
- do { warn "Missing trailing quote in: $_"; return $_; } if !s/"$//;
- s/\\(.)/$mutteval_charmap{$1} || warn "Undefined '\\$1' sequence in: $_";/ges;
- return $_;
-}
-
-sub muttrc_get
-{
-my(@headers)=@_;
-
- my @r=map({ (ref $_ ? $_ : qr/^\s*set\s+\Q$_\E\s*=\s*(.*?)\s*$/si); } @headers);
- my %r=map(($_=>undef()),@r);
- for (muttrc()) {
- for my $ritem (@r) {
- /$ritem/si or next;
- $r{$ritem}=mutteval $1;
- }
- }
- for my $var (grep { !defined($r{$_}) } @r) {
- warn "Variable '$var' not found in muttrc";
- return undef();
- }
- return wantarray() ? %r : $r{$r[0]};
+# Returns true if IS virus; the message will contain the virus name
+sub clamscan
+{
+my($cmd)=@_;
+
+ $cmd||='nice clamscan --no-summary -';
+ # clamscan has exit code 1 if IS virus , code 0 if NOT virus
+ # Do not use IPC::Open2 as it would try to use our STDERR which is not valid by: local *STDERR;
+ local(*WR,*RD,*ERR);
+ local $SIG{"PIPE"}=sub { warn "clamscan '$cmd' gave me SIGPIPE: broken pipe"; };
+ my $pid=open3(\*WR,\*RD,\*ERR,$cmd.' 2>&1')
+ or do { cluck "IPC::Open3 $cmd: $!"; return 0; };
+ print WR $Message;
+ close WR or do { cluck "close WR of $cmd: $!"; return 0; };
+ my $status=do { local $/=undef(); <RD>; };
+ close RD or do { cluck "close RD of $cmd: $!"; return 0; };
+ # Do not: $status.=do { local $/=undef(); <ERR>; };
+ # close ERR or do { cluck "close ERR of $cmd: $!"; return 0; };
+ # (FIXME) as it causes: Use of uninitialized value in <HANDLE>
+ # waitpid fills $? for: &_spamchildcode
+ local $SIG{"ALRM"}=sub { warn "Timeout $clamscan_waitpid_timeout sec waiting for child $cmd"; };
+ alarm $clamscan_waitpid_timeout;
+ # Do not: WNOHANG
+ # as it would not be enough for clamscan(1) even after all close-s above.
+ my $pidcheck=waitpid($pid,0);
+ alarm 0;
+ my $err=$?;
+ $pidcheck && $pidcheck==$pid
+ or do { cluck "waitpid for $cmd returned $pidcheck!=$pid"; return 0; };
+ $status=~s/^stdin: //mg;
+ # Prevent: LibClamAV Warning: PGP encoded attachment not scanned
+ $status=~s/^.*\bwarning:.*\n//img;
+ $status=~s/\n$//;
+ return $status if $status ne "OK" && $status;
+ return _spamchildcode $err,$status;