Mail::Header(3)
okay so bestie, welcome to Mail::Header(3) β listed under User Contributed Perl Documentation β and it's all about manipulating MIME headers. π β¨
πΈ NAME πΈ
Mail::Header β manipulate MIME headers. π
β¨ SYNOPSIS β¨
No cap, these are the starter lines:
use Mail::Header;
my $head = Mail::Header->new;
my $head = Mail::Header->new( \*STDIN );
my $head = Mail::Header->new( [<>], Modify => 0);
π¦ DESCRIPTION π¦
Okay so this module lets you read, write, create, and manipulate MIME headers β aka the leading part of every modern e-mail message, but also used in other protocols like HTTP. The fields are kept in Mail::Field objects. π
Be aware that header fields each have a name part, which shall be treated case-insensitive, and a content part, which may be folded over multiple lines. iykyk.
Mail::Header does not always follow the RFCs strictly enough, and it does not help you with character encodings. π It does not use weak references where it could (because those did not exist when the module was written), which costs some performance and makes the implementation a little more complicated. The Mail::Message::Head implementation is much newer and therefore better. π
π οΈ METHODS π οΈ
π Constructors π
$obj->dup()β create a duplicate of the current object. π«Ά$obj->new( [$source], [%options] )/Mail::Header->new( [$source], [%options] )β the$sourcemay be either a file descriptor (reference to aGLOB) or a reference to an array. If given, the new object will be initialized with headers either from the array or read from the file descriptor. β¨
%options is a list of options given in the form of key-value pairs, just like a hash table. Valid options are:
-Option --Default
FoldLength 79
MailFrom 'KEEP'
Modify false
FoldLength => INTEGERβ the default length of line to be used when folding header lines. Seefold_length(). πMailFrom => 'IGNORE'|'COERCE'|'KEEP'|'ERROR'β see methodmail_from(). πModify => BOOLEANβ if this value is true, then the headers will be re-formatted; otherwise the format of the header lines will remain unchanged. π
πͺ "Fake" constructors πͺ
β οΈ Be warned: the next constructors all require an already created header object, and the original content of that object will be destroyed. π
$obj->empty()β empty an existingMail::Headerobject of all lines. π§Ή$obj->extract(ARRAY)β extract a header from the given array into an existingMail::Headerobject.extractwill modify this array. Returns the object that the method was called on. π«Ά$obj->header( [ARRAY] )βheaderdoes multiple operations. First it will extract a header from theARRAY, if given. It will then reformat the header (if reformatting is permitted), and finally return a reference to an array which contains the header in a printable form. β¨$obj->header_hashref( [HASH] )β asheader(), but it will eventually set headers from a hash reference, and it will return the headers as a hash reference.
example:
$fields->{From} = 'Tobias Brox <tobix@cpan.org>';
$fields->{To} = ['you@somewhere', 'me@localhost'];
$head->header_hashref($fields);
$obj->read($fh)β read a header from the given file descriptor into an existingMail::Headerobject. π₯
π Accessors π
$obj->fold_length( [$tag], [$length] )β set the default fold length for all tags or just one. With no arguments the default fold length is returned. With two arguments it sets the fold length for the given tag and returns the previous value. If only$lengthis given it sets the default fold length for the current object. π
In the two argument form fold_length may be called as a static method, setting default fold lengths for tags that will be used by all Mail::Header objects. See the "fold" method for a description on how Mail::Header uses these values. π
$obj->mail_from('IGNORE'|'COERCE'|'KEEP'|'ERROR')β this specifies what to do when aFrom 'line is encountered. Valid values are"IGNORE"β ignore and discard the header,"ERROR"β invoke an error (calldie),"COERCE"β rename them asMail-Fromand"KEEP"β keep them. π$obj->modify( [$value] )β if$valueis false thenMail::Headerwill not do any automatic reformatting of the headers, other than to ensure that the line starts with the tags given. π
π« Processing π«
$obj->add( $tag, $line [, $index] )β add a new line to the header. If$tagisundefthe tag will be extracted from the beginning of the given line. If$indexis given, the new line will be inserted into the header at the given point, otherwise the new line will be appended to the end of the header. β$obj->as_string()β returns the header as a single string. π§΅$obj->cleanup()β remove any header line that, other than the tag, only contains whitespace. π§Ό$obj->combine( $tag [, $with] )β combine all instances of$taginto one. The lines will be joined together$with, or a single space if not given. The new item will be positioned in the header where the first instance was, all other instances of$tagwill be removed. πͺ$obj->count($tag)β returns the number of times the givenatgappears in the header. π yes,atgβ I'm not fixing the page's typo, bestie.$obj->delete( $tag [, $index ] )β delete a tag from the header. If an$indexid is given, then the Nth instance of the tag will be removed. If no$indexis given, then all instances of tag will be removed. ποΈ$obj->fold( [$length] )β fold the header. If$lengthis not given, thenMail::Headeruses the following rules to determine what length to fold a line. π$obj->get( $tag [, $index] )β get the text from a line. If an$indexis given, then the text of the Nth instance will be returned. If it is not given the return value depends on the context in whichgetwas called. In an array context a list of all the text from all the instances of the$tagwill be returned. In a scalar context the text for the first instance will be returned. π
The lines are unfolded, but still terminated with a new-line (see "chomp"). π
$obj->print( [$fh] )β print the header to the given file descriptor, orSTDOUTif no file descriptor is given. π¨οΈ$obj->replace( $tag, $line [, $index ] )β replace a line in the header. If$tagisundefthe tag will be extracted from the beginning of the given line. If$indexis given the new line will replace the Nth instance of that tag, otherwise the first instance of the tag is replaced. If the tag does not appear in the header then a new line will be appended to the header. π$obj->tags()β returns an array of all the tags that exist in the header. Each tag will only appear in the list once. The order of the tags is not specified. π·οΈ$obj->unfold( [$tag] )β unfold all instances of the given tag so that they do not spread across multiple lines. If$tagis not given then all lines are unfolded. π¦
π The unfolding process is wrong but (for compatibility reasons) will not be repaired: only one blank at the start of the line should be removed, not all of them.
π SEE ALSO π
This module is part of the MailTools distribution, http://perl.overmeer.net/mailtools/. π
π AUTHORS π
The MailTools bundle was developed by Graham Barr. Later, Mark Overmeer took over maintenance without commitment to further development. π
Mail::Capby Gisle Aas<aas@oslonett.no>.Mail::Field::AddrListby Peter Orbaek<poe@cit.dk>.Mail::MailerandMail::Sendby Tim Bunce<Tim.Bunce@ig.co.uk>.- For other contributors see
ChangeLog.
π LICENSE π
Copyrights 1995-2000 Graham Barr <gbarr@pobox.com> and 2001-2024 Mark Overmeer <perl@overmeer.net>. π
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html.
π okay that's the whole Mail::Header(3) page, bestie β footer check: perl v5.42.0, dated 2024-12-12. Now go forth and fold those headers, icon! πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-MailTools 2.220.0-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms