
### HTMLComments.cf:
# loadplugin Mail::SpamAssassin::Plugin::HTMLComments HTMLComments.pm
# body OVERSIZE_COMMENT eval:check_html_comment_length('32000')

package Mail::SpamAssassin::Plugin::HTMLComments;

use strict;
use warnings;
use Mail::SpamAssassin::Plugin;

use vars qw(@ISA);
@ISA = qw(Mail::SpamAssassin::Plugin);

sub dbg { Mail::SpamAssassin::Plugin::dbg ("HTMLComments: @_"); }

sub new {
    my $class = shift;
    my $mailsaobject = shift;

    $class = ref($class) || $class;
    my $self = $class->SUPER::new($mailsaobject);
    bless ($self, $class);

    $self->register_eval_rule("check_html_comment_length");

    return $self;
}

sub check_html_comment_length {
    my ($self, $pms, undef, $find_len) = @_;

    return 0 unless defined $find_len && $find_len =~ /^\d+$/;

    foreach my $p ($pms->{msg}->find_parts(qr{^text/html$},1,1)) {
        my $html = $p->{decoded} || '';
        next if length($html) < $find_len;
        while ($html =~ /<!--(.*?)-->/sg) {
            return 1 if length($1) >= $find_len;
        }
    }

    return 0;
}

1;
