NAME
Mail::Header - manipulate mail RFC822 compliant headers
SYNOPSIS
use Mail::Header;
$head = new Mail::Header;
$head = new Mail::Header \*STDIN;
$head = new Mail::Header [<>], Modify => 0;
DESCRIPTION
This package provides a class object which can be used for reading, creating, manipulating and writing RFC822 compliant headers.
CONSTRUCTOR
- new ( [ ARG ], [ OPTIONS ] )
-
ARGmay be either a file descriptor (reference to a GLOB) or a reference to an array. If given the new object will be initialized with headers either from the array of read from the file descriptor.OPTIONSis a list of options given in the form of key-value pairs, just like a hash table. Valid options are- Modify
-
If this value is true then the headers will be re-formatted, otherwise the format of the header lines will remain unchanged.
- MailFrom
-
This option specifies what to do when a header in the form `From ' is encountered. Valid values are
IGNORE- ignore and discard the header,ERROR- invoke an error (call die),COERCE- rename them as Mail-From andKEEP- keep them. - FoldLength
-
The default length of line to be used when folding header lines
METHODS
- 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. - mail_from ( OPTION )
-
OPTIONspecifies what to do when a`From 'line is encountered. Valid values areIGNORE- ignore and discard the header,ERROR- invoke an error (call die),COERCE- rename them as Mail-From andKEEP- keep them. - fold ( [ LENGTH ] )
-
Fold the header. If
LENGTHis not given thenMail::Headeruses the following rules to determine what length to fold a line.The fold length for the tag that is begin processed
The default fold length for the tag that is being processed
The default fold length for the object
- extract ( ARRAY_REF )
-
Extract a header from the given array.
extractwill modify this array. Returns the object that the method was called on. - read ( FD )
-
Read a header from the given file descriptor.
- empty ()
-
Empty the
Mail::Headerobject of all lines. - header ( [ ARRAY_REF ] )
-
headerdoes multiple operations. First it will extract a header from the array, if given. It will the reformat the header, if reformatting is permitted, and finally return a reference to an array which contains the header in a printable form. - header_hashref ( [ HASH_REF ] )
-
As
header, but it will eventually set headers from a hash reference, and it will return the headers as a hash reference.The values in the hash might either be a scalar or an array reference, as an example:
$hashref->{From}='Tobias Brox <tobix@cpan.org>'; $hashref->{To}=['you@somewhere', 'me@localhost']; - add ( TAG, LINE [, INDEX ] )
-
Add a new line to the header. If
TAGis undef the the tag will be extracted from the beginning of the given line. IfINDEXis 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. - replace ( TAG, LINE [, INDEX ] )
-
Replace a line in the header. If
TAGis undef the the tag will be extracted from the beginning of the given line. IfINDEXis 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. - combine ( TAG [, WITH ] )
-
Combine all instances of
TAGinto one. The lines will be joined togther withWITH, 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 <TAG> will be removed. - get ( TAG [, INDEX ] )
-
Get the text form a line. If
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 ofTAGwill be returned. In a scalar context the text for the first instance will be returned. - delete ( TAG [, INDEX ] )
-
Delete a tag from the header. If
INDEXid given then the Nth instance of the tag will be removed. IfINDEXis not given all instances of tag will be removed. - count ( TAG )
-
Returns the number of times the given atg appears in the header
- print ( [ FD ] )
-
Print the header to the given file descriptor, or
STDOUTif no file descriptor is given. - as_string ()
-
Returns the header as a single string.
- 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_lengthmay be called as a static method, setting default fold lengths for tags that will be used by allMail::Headerobjects. See thefoldmethod for a description on howMail::Headeruses these values. -
Retruns 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.
- dup ()
-
Create a duplicate of the current object.
- cleanup ()
-
Remove any header line that, other than the tag, only contains whitespace
- 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.
AUTHOR
Graham Barr. Maintained by Mark Overmeer <mailtools@overmeer.net>
COPYRIGHT
Copyright (c) 1995-2001 Graham Barr. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.