=encoding utf8 =head1 NAME Mail::Message::Head::Complete - the header of one message =head1 INHERITANCE Mail::Message::Head::Complete is a Mail::Message::Head is a Mail::Reporter Mail::Message::Head::Complete is extended by Mail::Message::Head::Partial Mail::Message::Replace::MailHeader Mail::Message::Head::Complete is realized by Mail::Message::Head::Delayed Mail::Message::Head::Subset =head1 SYNOPSIS my $head = Mail::Message::Head::Complete->new; See Mail::Message::Head =head1 DESCRIPTION E-mail's message can be in various states: unread, partially read, and fully read. The class stores a message of which all header lines are known for sure. Extends L<"DESCRIPTION" in Mail::Message::Head|Mail::Message::Head/"DESCRIPTION">. =head1 OVERLOADED Extends L<"OVERLOADED" in Mail::Message::Head|Mail::Message::Head/"OVERLOADED">. =over 4 =item overload: B<""> Inherited, see L =item overload: B Inherited, see L =back =head1 METHODS Extends L<"METHODS" in Mail::Message::Head|Mail::Message::Head/"METHODS">. =head2 Constructors Extends L<"Constructors" in Mail::Message::Head|Mail::Message::Head/"Constructors">. =over 4 =item Mail::Message::Head::Complete-EB( [PAIR|$field], ... ) Undefined values are interpreted as empty field values, and therefore skipped. =item $obj-EB( [@names|ARRAY|Regexps] ) Make a copy of the header, optionally limited only to the header lines specified by @names. See L on the way these fields can be used. example: my $newhead = $head->clone('Subject', 'Received'); =item Mail::Message::Head::Complete-EB(%options) Inherited, see L =back =head2 The header Extends L<"The header" in Mail::Message::Head|Mail::Message::Head/"The header">. =over 4 =item $obj-EB() Inherited, see L =item $obj-EB() Inherited, see L =item $obj-EB() Inherited, see L =item $obj-EB() Inherited, see L =item $obj-EB( [$message] ) Inherited, see L =item $obj-EB( [BOOLEAN] ) Inherited, see L =item $obj-EB() Return the number of lines needed to display this header (including the trailing newline) =item $obj-EB() Inherited, see L =item $obj-EB() Return the number of bytes needed to display this header (including the trailing newline). On systems which use CRLF as line separator, the number of lines in the header (see L) must be added to find the actual size in the file. =item $obj-EB($integer) Re-fold all fields from the header to contain at most $integer number of characters per line. example: re-folding a header $msg->head->wrap(78); =back =head2 Access to the header Extends L<"Access to the header" in Mail::Message::Head|Mail::Message::Head/"Access to the header">. =over 4 =item $obj-EB( $field | $line | <$name, $body, [$attrs]> ) Add a field to the header. If a field is added more than once, all values are stored in the header, in the order they are added. When a $field object is specified (some L instance), that will be added. Another possibility is to specify a raw header $line, or a header line nicely split-up in $name and $body, in which case the field constructor is called for you. $line or $body specifications which are terminated by a new-line are considered to be correctly folded. Lines which are not terminated by a new-line will be folded when needed: new-lines will be added where required. It is strongly advised to let MailBox do the folding for you. The return value of this method is the L object which is created (or was specified). example: my $head = Mail::Message::Head->new; $head->add('Subject: hi!'); $head->add(From => 'me@home'); my $field = Mail::Message::Field->new('To: you@there'); $head->add($field); my Mail::Message::Field $s = $head->add(Sender => 'I'); =item $obj-EB($object) A I is a set of header fields which contain data about a mailing list which was used to transmit the message. See L for details about the implementation of the $object. When you have a list group prepared, you can add it later using this method. You will get your private copy of the list group data in return, because the same group can be used for multiple messages. example: of adding a list group to a header my $lg = Mail::Message::Head::ListGroup->new(...); my $own_lg = $msg->head->addListGroup($lg); =item $obj-EB($resent_group|$data) Add a $resent_group (a L object) to the header. If you specify $data, that is used to create such group first. If no C line is specified, it will be created for you. These header lines have nothing to do with the user's sense of C or C actions: these lines trace the e-mail transport mechanism. example: my $rg = Mail::Message::Head::ResentGroup->new(head => $head, ...); $head->addResentGroup($rg); my $rg = $head->addResentGroup(From => 'me'); =item $obj-EB($object) A I is a set of header fields which contains data which is used to fight spam. See L for details about the implementation of the $object. When you have a spam group prepared, you can add it later using this method. You will get your private copy of the spam group data in return, because the same group can be used for multiple messages. example: of adding a spam group to a header my $sg = Mail::Message::Head::SpamGroup->new(...); my $own_sg = $msg->head->addSpamGroup($sg); =item $obj-EB($name) Count the number of fields with this $name. Most fields will return 1: only one occurrence in the header. As example, the C fields are usually present more than once. =item $obj-EB($name) Remove the field with the specified name. If the header contained multiple lines with the same name, they will be replaced all together. This method simply calls L without replacement fields. READ THE IMPORTANT WARNING IN L =item $obj-EB( $name, [$index] ) Inherited, see L =item $obj-EB( [@names|ARRAY|Regexps] ) Filter from all header fields those with names which start will any of the specified list. When no names are specified, all fields will be returned. The list is ordered as they where read from file, or added later. The @names are considered regular expressions, and will all be matched case insensitive and attached to the front of the string only. You may also specify one or more prepared regexes. example: my @f = $head->grepNames(); # same as $head->orderedFields my @f = $head->grepNames('X-', 'Subject', '); my @to = $head->grepNames('To\b'); # will only select To =item $obj-EB() Returns a I description: the set of headers which form the information about mailing list software used to transport the message. See also L and L. example: use of listGroup() if(my $lg = $msg->head->listGroup) { $lg->print(\*STDERR); $lg->delete; } $msg->head->removeListGroup; =item $obj-EB() Returns a full ordered list of known field names, as defined in the header. Fields which were reset() to be empty will still be listed here. =item $obj-EB( [$fh] ) Print all headers to the specified $fh, by default the selected filehandle. See L to limit the headers to include only the public headers. example: $head->print(\*OUT); $head->print; my $fh = IO::File->new(...); $head->print($fh); =item $obj-EB($fh, , ...) Like the usual L, the header lines are printed to the specified $fh. In this case, however, only the fields with names as specified by STRING (case insensative) or Regexp are printed. They will stay the in-order of the source header. example: printing only a subset of the fields $head->printSelected(STDOUT, qw/Subject From To/, qr/^x\-(spam|xyz)\-/i) =item $obj-EB( [$fh] ) Like the usual L, the header lines are printed to the specified $fh, by default the selected filehandle. In this case, however, C and C lines are included. =item $obj-EB() Remove all body related fields from the header. The header will become partial. =item $obj-EB($field) Remove the specified $field object from the header. This is useful when there are possible more than one fields with the same name, and you need to remove exactly one of them. Also have a look at L, L, and L. See also L (mind the 's' at the end of the name), which accepts a string or regular expression as argument to select the fields to be removed. WARNING WARNING WARNING: for performance reasons, the header administration uses weak references (see L method weaken()> to figure-out which fields have been removed. A header is a hash of field for fast search and an array of weak references to remember the order of the fields, required for printing. If the field is removed from the hash, the weak-ref is set to undef and the field not printed. However... it is easy to disturb this process. Example: my $msg = ....; # subject ref-count = 1 + 0 = 1 $msg->head->delete('Subject'); # subject ref-count = 0 = 0: clean-up $msg->print; # subject doesn't show: ok But my $msg = ....; # subject ref-count = 1 + 0 = 1 my $s = $msg->head->get('subject'); # ref-count = 1 + 1 + 0 = 2 $msg->head->delete('Subject'); # subject ref-count = 1 + 0 = 1: no clean-up $msg->print; # subject DOES show: not ok undef $s; # ref-count becomes 0: clean-up $msg->print; # subject doesn't show: ok To avoid the latter situation, do not catch the field object, but only the field content. SAVE are all methods which return the text: my $s = $msg->head->get('subject')->body; my $s = $msg->head->get('subject')->unfoldedBody; my $s = $msg->head->get('subject')->foldedBody; my $s = $msg->head->get('subject')->foldedBody; my $s = $msg->get('subject'); my $s = $msg->subject; my $s = $msg->string; =item $obj-EB( , ... ) The header object is turned into a L object which has a set of fields removed. Read about the implications and the possibilities in L. =item $obj-EB( , ... ) The header object is turned into a L object which has a set of fields removed. Read about the implications and the possibilities in L. =item $obj-EB() Removes all fields related to mailing list administration at once. The header object is turned into a L object. Read about the implications and the possibilities in L. =item $obj-EB() Removes all resent groups at once. The header object is turned into a L object. Read about the implications and the possibilities in L. =item $obj-EB() Removes all fields which were added by various spam detection software at once. The header object is turned into a L object. Read about the implications and the possibilities in L. =item $obj-EB() Returns a list of L objects which each represent one intermediate point in the message's transmission in the order as they appear in the header: the most recent one first. See also L and L. A resent group contains a set of header fields whose names start with C. Before the first C line is I information, which is composed of an optional C field and an required C field. =item $obj-EB($name, @fields) Replace the values in the header fields named by $name with the values specified in the list of @fields. A single name can correspond to multiple repeated fields. READ THE IMPORTANT WARNING IN L Removing fields which are part of one of the predefined field groups is not a smart idea. You can better remove these fields as group, all together. For instance, the C<'Received'> lines are part of resent groups, C<'X-Spam'> is past of a spam group, and C belongs to a list group. You can delete a whole group with L, or with methods which are provided by L. If FIELDS is empty, the corresponding $name fields will be removed. The location of removed fields in the header order will be remembered. Fields with the same name which are added later will appear at the remembered position. This is equivalent to the L method. example: # reduce number of 'Keywords' lines to last 5) my @keywords = $head->get('Keywords'); $head->reset('Keywords', @keywords[-5..-1]) if @keywords > 5; # Reduce the number of Received lines to only the last added one. my @rgs = $head->resentGroups; shift @rgs; # keep this one (later is added in front) $_->delete foreach @rgs; =item $obj-EB( $field | $line | <$name, $body, [$attrs]> ) The C method is similar to the L method, and takes the same options. However, existing values for fields will be removed before a new value is added. READ THE IMPORTANT WARNING IN L =item $obj-EB() Returns whether one of the spam groups defines a report about spam. If there are not header fields in the message which relate to spam-detection software, C is returned. The spamgroups which report spam are returned. example: $message->delete if $message->spamDetected; call_spamassassin($message) unless defined $message->spamDetected; =item $obj-EB( [$names] ) Returns a list of L objects, each collecting some lines which contain spam fighting information. When any $names are given, then only these groups are returned. See also L and L. In scalar context, with exactly one NAME specified, that group will be returned. With more $names or without $names, a list will be returned (which defaults to the length of the list in scalar context). example: use of listGroup() my @sg = $msg->head->spamGroups; $sg[0]->print(\*STDERR); $sg[-1]->delete; my $sg = $msg->head->spamGroups('SpamAssassin'); =item $obj-EB() Returns the whole header as one scalar (in scalar context) or list of lines (list context). Triggers completion. =item $obj-EB( $name, [$index] ) Inherited, see L =back =head2 About the body Extends L<"About the body" in Mail::Message::Head|Mail::Message::Head/"About the body">. =over 4 =item $obj-EB() Inherited, see L =item $obj-EB() Make a guess about when the message was origanally posted, based on the information found in the header's C field. For some kinds of folders, L may produce a better result, for instance by looking at the modification time of the file in which the message is stored. Also some protocols, like POP can supply that information. =item $obj-EB() Inherited, see L =item $obj-EB() Returns an indication about when the message was sent, but only using the C field in the header as last resort: we do not trust the sender of the message to specify the correct date. See L when you do trust the sender. Many spam producers fake a date, which mess up the order of receiving things. The timestamp which is produced is derived from the Received headers, if they are present, and C otherwise. The timestamp is encoded as C