Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@s-aska
Created November 16, 2010 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-aska/701692 to your computer and use it in GitHub Desktop.
Save s-aska/701692 to your computer and use it in GitHub Desktop.
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