Perl get all message headers from imap message
I use Mail::IMAPClient
Have multiple variables
$body = $imap->body_string($msg); $header = $imap->message_string($msg);
$ body contains the body of the message, but the $ header contains the header and body of the message. I haven't found a method in IMAPClient that only receives the message header.
I need to remove the body from the $ header. Separating $ body and $ header is not a good idea because the body can be very large. The body and header are separated by a blank line, but I don't know how to use it.
+3
source to share
1 answer
Please take a look at http://gagravarr.org/code/test-imap-headers.pl
It suggests the Mail::IMAPClient
package supports / supports the "ALL" keyword to get all headers at once:
my %headers = %{ $imap->parse_headers( $msg, "ALL" ) };
for my $h ( keys %headers ) {
my @hdrs = @{ $headers{$h} };
print "$h (" . scalar @hdrs . " entries)\n";
foreach (@hdrs) { print "\t$_\n"; }
}
+2
source to share