1Mail::Header(3) User Contributed Perl Documentation Mail::Header(3)
2
3
4
6 Mail::Header - manipulate mail RFC822 compliant headers
7
9 use Mail::Header;
10
11 $head = new Mail::Header;
12 $head = new Mail::Header \*STDIN;
13 $head = new Mail::Header [<>], Modify => 0;
14
16 This package provides a class object which can be used for reading,
17 creating, manipulating and writing RFC822 compliant headers.
18
20 new ( [ ARG ], [ OPTIONS ] )
21 "ARG" may be either a file descriptor (reference to a GLOB) or a
22 reference to an array. If given the new object will be initialized
23 with headers either from the array of read from the file descrip‐
24 tor.
25
26 "OPTIONS" is a list of options given in the form of key-value
27 pairs, just like a hash table. Valid options are
28
29 Modify If this value is true then the headers will be re-format‐
30 ted, otherwise the format of the header lines will remain
31 unchanged.
32
33 MailFrom
34 This option specifies what to do when a header in the form
35 `From ' is encountered. Valid values are "IGNORE" - ignore
36 and discard the header, "ERROR" - invoke an error (call
37 die), "COERCE" - rename them as Mail-From and "KEEP" - keep
38 them.
39
40 FoldLength
41 The default length of line to be used when folding header
42 lines
43
45 modify ( [ VALUE ] )
46 If "VALUE" is false then "Mail::Header" will not do any automatic
47 reformatting of the headers, other than to ensure that the line
48 starts with the tags given.
49
50 mail_from ( OPTION )
51 "OPTION" specifies what to do when a `From ' line is encountered.
52 Valid values are "IGNORE" - ignore and discard the header, "ERROR"
53 - invoke an error (call die), "COERCE" - rename them as Mail-From
54 and "KEEP" - keep them.
55
56 fold ( [ LENGTH ] )
57 Fold the header. If "LENGTH" is not given then "Mail::Header" uses
58 the following rules to determine what length to fold a line.
59
60 The fold length for the tag that is begin processed
61
62 The default fold length for the tag that is being processed
63
64 The default fold length for the object
65
66 extract ( ARRAY_REF )
67 Extract a header from the given array. "extract" will modify this
68 array. Returns the object that the method was called on.
69
70 read ( FD )
71 Read a header from the given file descriptor.
72
73 empty ()
74 Empty the "Mail::Header" object of all lines.
75
76 header ( [ ARRAY_REF ] )
77 "header" does multiple operations. First it will extract a header
78 from the array, if given. It will the reformat the header, if
79 reformatting is permitted, and finally return a reference to an
80 array which contains the header in a printable form.
81
82 header_hashref ( [ HASH_REF ] )
83 As "header", but it will eventually set headers from a hash refer‐
84 ence, and it will return the headers as a hash reference.
85
86 The values in the hash might either be a scalar or an array refer‐
87 ence, as an example:
88
89 $hashref->{From}='Tobias Brox <tobix@cpan.org>';
90 $hashref->{To}=['you@somewhere', 'me@localhost'];
91
92 add ( TAG, LINE [, INDEX ] )
93 Add a new line to the header. If "TAG" is undef the the tag will be
94 extracted from the beginning of the given line. If "INDEX" is given
95 the new line will be inserted into the header at the given point,
96 otherwise the new line will be appended to the end of the header.
97
98 replace ( TAG, LINE [, INDEX ] )
99 Replace a line in the header. If "TAG" is undef the the tag will
100 be extracted from the beginning of the given line. If "INDEX" is
101 given the new line will replace the Nth instance of that tag, oth‐
102 erwise the first instance of the tag is replaced. If the tag does
103 not appear in the header then a new line will be appended to the
104 header.
105
106 combine ( TAG [, WITH ] )
107 Combine all instances of "TAG" into one. The lines will be joined
108 togther with "WITH", or a single space if not given. The new item
109 will be positioned in the header where the first instance was, all
110 other instances of <TAG> will be removed.
111
112 get ( TAG [, INDEX ] )
113 Get the text from a line. If "INDEX" is given then the text of the
114 Nth instance will be returned. If it is not given the return value
115 depends on the context in which "get" was called. In an array con‐
116 text a list of all the text from all the instances of "TAG" will be
117 returned. In a scalar context the text for the first instance will
118 be returned.
119
120 The lines are unfolded, but still terminated with a new-line (see
121 "chomp")
122
123 delete ( TAG [, INDEX ] )
124 Delete a tag from the header. If "INDEX" id given then the Nth
125 instance of the tag will be removed. If "INDEX" is not given all
126 instances of tag will be removed.
127
128 count ( TAG )
129 Returns the number of times the given atg appears in the header
130
131 print ( [ FD ] )
132 Print the header to the given file descriptor, or "STDOUT" if no
133 file descriptor is given.
134
135 as_string ()
136 Returns the header as a single string.
137
138 fold_length ( [ TAG ], [ LENGTH ] )
139 Set the default fold length for all tags or just one. With no argu‐
140 ments the default fold length is returned. With two arguments it
141 sets the fold length for the given tag and returns the previous
142 value. If only "LENGTH" is given it sets the default fold length
143 for the current object.
144
145 In the two argument form "fold_length" may be called as a static
146 method, setting default fold lengths for tags that will be used by
147 all "Mail::Header" objects. See the "fold" method for a description
148 on how "Mail::Header" uses these values.
149
150 tags ()
151 Retruns an array of all the tags that exist in the header. Each tag
152 will only appear in the list once. The order of the tags is not
153 specified.
154
155 dup ()
156 Create a duplicate of the current object.
157
158 cleanup ()
159 Remove any header line that, other than the tag, only contains
160 whitespace
161
162 unfold ( [ TAG ] )
163 Unfold all instances of the given tag so that they do not spread
164 across multiple lines. IF "TAG" is not given then all lines are
165 unfolded.
166
167 The unfolding process is wrong but (for compatibility reasons) will
168 not be repaired: only one blank at the start of the line should be
169 removed, not all of them.
170
172 Graham Barr. Maintained by Mark Overmeer <mailtools@overmeer.net>
173
175 Copyright (c) 2002-2003 Mark Overmeer, 1995-2001 Graham Barr. All
176 rights reserved. This program is free software; you can redistribute it
177 and/or modify it under the same terms as Perl itself.
178
179
180
181perl v5.8.8 2007-05-11 Mail::Header(3)