Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mail Header Fast Get
my $header;
my $buf;
my $term = "\n\n";
my $term_buf = '';
open($fh, $path) || die "$path $!";
while (read($fh, $buf, 4096)) {
$buf=~tr/\r//;
my $pos = index($term_buf . $buf, $term);
if ($pos >= 0) {
my $pos2 = $pos - length($term_buf);
if ($pos2 > 0) {
$header.= substr($buf, 0, $pos2);
}
last;
} else {
$header.= $buf;
$term_buf = substr($buf, 0, (length($term) - 1) * -1);
}
}
close $fh;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.