my $l_start = length($q_start);
my $new_text = "$q_start";
- $chars_left -= $l_start;
+ $chars_left -= $l_start if (defined $chars_left);
for (my $i = 0; $i < length($text); $i++) {
my $char = ord(substr($text, $i, 1));
- if (($char < 32) || ($char > 127) ||
- ($char == ord('?')) || ($char == ord('_'))) {
- if ($chars_left < 5) {
+ if (($char < 32) || ($char > 127) || ($char == ord('?')) || ($char == ord('_'))) {
+ if ((defined $chars_left) && ($chars_left < 5)) {
$new_text .= "?=\n $q_start";
$chars_left = 75 - $l_start;
}
$new_text .= sprintf("=%02X", $char);
- $chars_left -= 3;
+ $chars_left -= 3 if (defined $chars_left);
} else {
$char = ord('_') if ($char == ord(' '));
- if ($chars_left < 5) {
+ if ((defined $chars_left) && ($chars_left < 5)) {
$new_text .= "?=\n $q_start";
$chars_left = 75 - $l_start;
}
$new_text .= chr($char);
- $chars_left--;
+ $chars_left-- if (defined $chars_left);
}
}
next unless (scalar @addr_objects);
foreach my $addr_obj (@addr_objects) {
- $addr_obj->phrase($self->mime_quote_text($addr_obj->phrase(), 60)) if ($addr_obj->phrase());
- $addr_obj->comment($self->mime_quote_text($addr_obj->comment(), 60)) if ($addr_obj->comment());
+ my $phrase = $addr_obj->phrase();
+ if ($phrase) {
+ $phrase =~ s/^\"//;
+ $phrase =~ s/\"$//;
+ $addr_obj->phrase($self->mime_quote_text($phrase));
+ }
$headers .= sprintf("%s: %s\n", ucfirst($item), $addr_obj->format());
}