797
my $found_end_boundary;
798
799
my $line_count = @{$body};
799
800
foreach ( @{$body} ) {
800
801
# if we're on the last body line, or we find any boundary marker,
801
802
# deal with the mime part
802
if ( --$line_count == 0 || (defined $boundary && /^--\Q$boundary\E(?:--)?\s*$/) ) {
803
$found_end_boundary = defined $boundary && /^--\Q$boundary\E(?:--)?\s*$/;
804
if ( --$line_count == 0 || $found_end_boundary ) {
803
805
my $line = $_; # remember the last line
807
# If at last line and no end boundary found, the line belongs to body
809
# Is $self->{mime_boundary_state}->{$boundary}-- needed here?
810
# Could "missing end boundary" be a useful rule? Mark it somewhere?
811
# If SA processed truncated message from amavis etc, this could also
812
# be hit legimately..
813
if (!$found_end_boundary) {
814
# TODO: This is duplicate code from few pages down below..
815
while (length ($_) > MAX_BODY_LINE_LENGTH) {
816
push (@{$part_array}, substr($_, 0, MAX_BODY_LINE_LENGTH)."\n");
817
substr($_, 0, MAX_BODY_LINE_LENGTH) = '';
819
push ( @{$part_array}, $_ );
805
821
# per rfc 1521, the CRLF before the boundary is part of the boundary:
806
822
# NOTE: The CRLF preceding the encapsulation line is conceptually
807
823
# attached to the boundary so that it is possible to have a part
810
826
# CRLFs preceding the encapsulation line, the first of which is part
811
827
# of the preceding body part, and the second of which is part of the
812
828
# encapsulation boundary.
829
elsif ($part_array) {
814
830
chomp( $part_array->[-1] ); # trim the CRLF that's part of the boundary
815
831
splice @{$part_array}, -1 if ( $part_array->[-1] eq '' ); # blank line for the boundary only ...