~ubuntu-branches/ubuntu/utopic/spamassassin/utopic-updates

« back to all changes in this revision

Viewing changes to lib/Mail/SpamAssassin/HTML.pm

  • Committer: Package Import Robot
  • Author(s): Noah Meyerhans
  • Date: 2014-02-14 22:45:15 UTC
  • mfrom: (0.8.1) (0.6.2) (5.1.22 sid)
  • Revision ID: package-import@ubuntu.com-20140214224515-z1es2twos8xh7n2y
Tags: 3.4.0-1
* New upstream version! (Closes: 738963, 738872, 738867)
* Scrub the environment when switching to the debian-spamd user in
  postinst and cron.daily. (Closes: 738951)
* Enhancements to postinst to better manage ownership of
  /var/lib/spamassassin, via Iain Lane <iain.lane@canonical.com>
  (Closes: 738974)

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
 
53
53
# elements that change text style
54
54
my %elements_text_style = map {; $_ => 1 }
55
 
  qw( body font table tr th td big small basefont marquee span ),
 
55
  qw( body font table tr th td big small basefont marquee span p div ),
56
56
;
57
57
 
58
58
# elements that insert whitespace
82
82
$ok_attributes{th}{$_} = 1 for qw( bgcolor );
83
83
$ok_attributes{tr}{$_} = 1 for qw( bgcolor );
84
84
$ok_attributes{span}{$_} = 1 for qw( style );
 
85
$ok_attributes{p}{$_} = 1 for qw( style );
 
86
$ok_attributes{div}{$_} = 1 for qw( style );
85
87
 
86
88
sub new {
87
89
  my ($class) = @_;
541
543
 
542
544
  # invisibility
543
545
  if (substr($fg,-6) eq substr($bg,-6)) {
 
546
    $self->put_results(font_low_contrast => 1);
544
547
    return 1;
545
 
  }
546
548
  # near-invisibility
547
 
  elsif ($fg =~ /^\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/) {
 
549
  } elsif ($fg =~ /^\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/) {
548
550
    my ($r1, $g1, $b1) = (hex($1), hex($2), hex($3));
549
551
 
550
552
    if ($bg =~ /^\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/) {
569
571
    }
570
572
  }
571
573
 
 
574
  
 
575
  # invalid color
 
576
  if ($fg eq 'invalid' or $bg eq 'invalid') {
 
577
    $self->put_results(font_invalid_color => 1);
 
578
    return 1;
 
579
  }
 
580
 
572
581
  # size too small
573
582
  if ($size <= 1) {
574
583
    return 1;
933
942
  yellowgreen => 0x9acd32,
934
943
);
935
944
 
936
 
sub name_to_rgb {
 
945
sub name_to_rgb_old {
937
946
  my $color = lc $_[0];
938
947
 
939
948
  # note: Mozilla strips leading and trailing whitespace at this point,
963
972
  return "#" . $color;
964
973
}
965
974
 
 
975
sub name_to_rgb {
 
976
  my $color = lc $_[0];
 
977
  my $before = $color;
 
978
 
 
979
  # strip leading and ending whitespace
 
980
  $color =~ s/^\s*//;
 
981
  $color =~ s/\s*$//;
 
982
 
 
983
  # named colors
 
984
  my $hex = $html_color{$color};
 
985
  if (defined $hex) {
 
986
    return sprintf("#%06x", $hex);
 
987
  }
 
988
 
 
989
  # IF NOT A NAME, IT SHOULD BE A HEX COLOR, HEX SHORTHAND or rgb values
 
990
  if ($color =~ m/^[#a-f0-9]*$|rgb\([\d%, ]*\)/i) {
 
991
 
 
992
    #Convert the RGB values to hex values so we can fall through on the programming
 
993
 
 
994
    #RGB PERCENTS TO HEX
 
995
    if ($color =~ m/rgb\((\d+)%,\s*(\d+)%,\s*(\d+)%\s*\)/i) {
 
996
      $color = "#".dec2hex(int($1/100*255)).dec2hex(int($2/100*255)).dec2hex(int($3/100*255));
 
997
    }
 
998
 
 
999
    #RGB DEC TO HEX
 
1000
    if ($color =~ m/rgb\((\d+),\s*(\d+),\s*(\d+)\s*\)/i) {
 
1001
      $color = "#".dec2hex($1).dec2hex($2).dec2hex($3);
 
1002
    }
 
1003
 
 
1004
    #PARSE THE HEX
 
1005
    if ($color =~ m/^#/) {
 
1006
      # strip to hex only
 
1007
      $color =~ s/[^a-f0-9]//ig;
 
1008
 
 
1009
      # strip to 6 if greater than 6
 
1010
      if (length($color) > 6) {
 
1011
        $color=substr($color,0,6);
 
1012
      }
 
1013
 
 
1014
      # strip to 3 if length < 6)
 
1015
      if (length($color) > 3 && length($color) < 6) {
 
1016
        $color=substr($color,0,3);
 
1017
      }
 
1018
 
 
1019
      # pad right-hand-side to a multiple of three
 
1020
      $color .= "0" x (3 - (length($color) % 3)) if (length($color) % 3);
 
1021
 
 
1022
      #DUPLICATE SHORTHAND HEX
 
1023
      if (length($color) == 3) {
 
1024
        $color =~ m/(.)(.)(.)/;
 
1025
        $color = "$1$1$2$2$3$3";
 
1026
      }
 
1027
 
 
1028
    } else {
 
1029
      return "invalid";
 
1030
    } 
 
1031
 
 
1032
  } else {
 
1033
    #INVALID 
 
1034
 
 
1035
    #??RETURN BLACK SINCE WE DO NOT KNOW HOW THE MUA / BROWSER WILL PARSE
 
1036
    #$color = "000000";
 
1037
 
 
1038
    return "invalid";
 
1039
  }
 
1040
 
 
1041
  #print "DEBUG: before/after name_to_rgb new version: $before/$color\n";
 
1042
 
 
1043
  return "#" . $color;
 
1044
}
 
1045
 
 
1046
sub dec2hex {
 
1047
  my ($dec) = @_;
 
1048
  my ($pre) = '';
 
1049
 
 
1050
  if ($dec < 16) {
 
1051
    $pre = '0';
 
1052
  }
 
1053
 
 
1054
  return sprintf("$pre%lx", $dec);
 
1055
}
 
1056
 
 
1057
 
966
1058
use constant URI_STRICT => 0;
967
1059
 
968
1060
# resolving relative URIs as defined in RFC 2396 (steps from section 5.2)