$OpenBSD: patch-lib_Mail_SpamAssassin_Plugin_PDFInfo_pm,v 1.1 2018/03/08 07:30:00 giovanni Exp $

Index: lib/Mail/SpamAssassin/Plugin/PDFInfo.pm
--- lib/Mail/SpamAssassin/Plugin/PDFInfo.pm.orig
+++ lib/Mail/SpamAssassin/Plugin/PDFInfo.pm
@@ -31,7 +31,7 @@ This plugin helps detected spam using attached PDF fil
 
 =item See "Usage:" below - more documentation see 20_pdfinfo.cf
 
- Original info kept for history.
+ Original info kept for history. For later changes see SVN repo
  -------------------------------------------------------
  PDFInfo Plugin for SpamAssassin
  Version: 0.8
@@ -40,7 +40,6 @@ This plugin helps detected spam using attached PDF fil
  Modified: 2007-08-10
  By: Dallas Engelken
 
-
  Changes:
    0.8 - added .fdf detection (thanks John Lundin) [axb]
    0.7 - fixed empty body/pdf count buglet(thanks Jeremy) [axb]
@@ -76,7 +75,6 @@ This plugin helps detected spam using attached PDF fil
          - removed all support for png, gif, and jpg from the code.
          - prepended pdf_ to all function names to avoid conflicts with ImageInfo in SA 3.2.
 
-
  Usage:
 
   pdf_count()
@@ -144,14 +142,14 @@ package Mail::SpamAssassin::Plugin::PDFInfo;
 
 use Mail::SpamAssassin::Plugin;
 use Mail::SpamAssassin::Logger;
+use Mail::SpamAssassin::Util;
 use strict;
 use warnings;
-use bytes;
+# use bytes;
 use Digest::MD5 qw(md5_hex);
 use MIME::QuotedPrint;
 
-use vars qw(@ISA);
-@ISA = qw(Mail::SpamAssassin::Plugin);
+our @ISA = qw(Mail::SpamAssassin::Plugin);
 
 # constructor: register the eval rule
 sub new {
@@ -413,9 +411,9 @@ sub _find_pdf_mime_parts {
 
   foreach my $p (@parts) {
     my $type = $p->{'type'} =~ m@/([\w\-]+)$@;
-    my $name = $p->{'name'};
+    my $name = $p->{'name'} || '';
 
-    my $cte = lc $p->get_header('content-transfer-encoding') || '';
+    my $cte = lc( $p->get_header('content-transfer-encoding') || '' );
 
     dbg("pdfinfo: found part, type=".($type ? $type : '')." file=".($name ? $name : '')." cte=".($cte ? $cte : '')."");
 
@@ -441,7 +439,6 @@ sub _find_pdf_mime_parts {
 
 }
 
-
 # ----------------------------------------
 
 sub pdf_named {
@@ -476,8 +473,12 @@ sub pdf_name_regex {
 
   my $hit = 0;
   foreach my $name (keys %{$pms->{'pdfinfo'}->{"names_pdf"}}) {
-    my $eval = 'if (q{'.$name.'} =~  '.$re.') {  $hit = 1; } ';
-    eval $eval;
+    eval {
+        my $regex = Mail::SpamAssassin::Util::make_qr($re);
+        if ( $name =~ m/$regex/ ) {
+            $hit = 1;
+        }
+    };
     dbg("pdfinfo: error in regex $re - $@") if $@;
     if ($hit) {
       dbg("pdfinfo: pdf_name_regex hit on $name");
@@ -722,9 +723,12 @@ sub pdf_match_details {
   return unless $check_value;
 
   my $hit = 0;
-  $check_value =~ s/[\{\}\\]//g;
-  my $eval = 'if (q{'.$check_value.'} =~ '.$regex.') { $hit = 1; }';
-  eval $eval;
+  eval {
+      my $re = Mail::SpamAssassin::Util::make_qr($regex);
+      if ( $check_value =~ m/$re/ ) {
+          $hit = 1;
+      }
+  };
   dbg("pdfinfo: error in regex $regex - $@") if $@;
   if ($hit) {
     dbg("pdfinfo: pdf_match_details $detail $regex matches $check_value");
