=encoding utf8 =head1 NAME Mail::Message::Field - one line of a message header =head1 INHERITANCE Mail::Message::Field is a Mail::Reporter Mail::Message::Field is extended by Mail::Message::Field::Fast Mail::Message::Field::Flex Mail::Message::Field::Full =head1 SYNOPSIS my $field = Mail::Message::Field->new(From => 'fish@tux.aq'); print $field->name; print $field->body; print $field->comment; print $field->content; # body & comment $field->print(\*OUT); print $field->string; print "$field\n"; print $field->attribute('charset') || 'us-ascii'; =head1 DESCRIPTION This implementation follows the guidelines of rfc2822 as close as possible, and may there produce a different output than implementations based on the obsolete rfc822. However, the old output will still be accepted. These objects each store one header line, and facilitates access routines to the information hidden in it. Also, you may want to have a look at the added methods of a message: my @from = $message->from; my $sender = $message->sender; my $subject = $message->subject; my $msgid = $message->messageId; my @to = $message->to; my @cc = $message->cc; my @bcc = $message->bcc; my @dest = $message->destinations; my $other = $message->get('Reply-To'); Extends L<"DESCRIPTION" in Mail::Reporter|Mail::Reporter/"DESCRIPTION">. =head1 OVERLOADED =over 4 =item overload: B<""> (stringification) produces the unfolded body of the field, which may be what you expect. This is what makes what the field object seems to be a simple string. The string is produced by L. example: print $msg->get('subject'); # via overloading print $msg->get('subject')->unfoldedBody; # same my $subject = $msg->get('subject') || 'your mail'; print "Re: $subject\n"; =item overload: B<0+> (numification) When the field is numeric, the value will be returned. The result is produced by L. If the value is not correct, a C<0> is produced, to simplify calculations. =item overload: B<<=>> (numeric comparison) Compare the integer field contents with something else. example: if($msg->get('Content-Length') > 10000) ... if($msg->size > 10000) ... ; # same, but better =item overload: B Always true, to make it possible to say C. =item overload: B (string comparison) Compare the unfolded body of a field with another field or a string, using the buildin C. =back =head1 METHODS Extends L<"METHODS" in Mail::Reporter|Mail::Reporter/"METHODS">. =head2 Constructors Extends L<"Constructors" in Mail::Reporter|Mail::Reporter/"Constructors">. =over 4 =item $obj-EB() Create a copy of this field object. =item Mail::Message::Field-EB($data) See L, L, and L. By default, a C field is produced. -Option--Defined in --Default log Mail::Reporter 'WARNINGS' trace Mail::Reporter 'WARNINGS' =over 2 =item log => LEVEL =item trace => LEVEL =back =back =head2 The field =over 4 =item $obj-EB() =item Mail::Message::Field-EB() Some fields are described in the RFCs as being I: having a well described syntax. These fields have common ideas about comments and the like, what they do not share with unstructured fields, like the C field. example: my $field = Mail::Message::Field->new(From => 'me'); if($field->isStructured) Mail::Message::Field->isStructured('From'); =item $obj-EB() Returns the total length of the field in characters, which includes the field's name, body and folding characters. =item $obj-EB() Returns the number of lines needed to display this header-line. =item $obj-EB( [$fh] ) Print the whole header-line to the specified file-handle. One line may result in more than one printed line, because of the folding of long lines. The $fh defaults to the selected handle. =item $obj-EB() Returns the number of bytes needed to display this header-line, Same as L. =item $obj-EB( [$wrap] ) Returns the field as string. By default, this returns the same as L. However, the optional $wrap will cause to re-fold to take place (without changing the folding stored inside the field). =item $obj-EB() Returns whether this field can be disclosed to other people, for instance when sending the message to another party. Returns a C or C condition. See also L. =back =head2 Access to the name =over 4 =item $obj-EB() Returns the name of this field in original casing. See L as well. =item $obj-EB() Returns the name of this field, with all characters lower-cased for ease of comparison. See L as well. =item $obj-EB( [STRING] ) (Instance method class method) As instance method, the current field's name is correctly formatted and returned. When a STRING is used, that one is formatted. example: print Mail::Message::Field->Name('content-type') # --> Content-Type my $field = $head->get('date'); print $field->Name; # --> Date =back =head2 Access to the body =over 4 =item $obj-EB() This method may be what you want, but usually, the L and L are what you are looking for. This method is cultural heritage, and should be avoided. Returns the body of the field. When this field is structured, it will be B from everything what is behind the first semi-color (C<;>). In any case, the string is unfolded. Whether the field is structured is defined by L. =item $obj-EB() Returns the folded version of the whole header. When the header is shorter than the wrap length, a list of one line is returned. Otherwise more lines will be returned, all but the first starting with at least one blank. See also L to get the same information without the field's name. In scalar context, the lines are delived into one string, which is a little faster because that's the way they are stored internally... example: my @lines = $field->folded; print $field->folded; print scalar $field->folded; # faster =item $obj-EB( [$body] ) Returns the body as a set of lines. In scalar context, this will be one line containing newlines. Be warned about the newlines when you do pattern matching on the result of this method. The optional $body argument changes the field's body. The folding of the argument must be correct. =item $obj-EB( [STRING] ) =item Mail::Message::Field-EB( [STRING] ) Remove the I and I from the STRING. Without string and only as instance method, the L is being stripped and returned. WARNING: This operation is only allowed for structured header fields (which are defined by the various RFCs as being so. You don't want parts within braces which are in the Subject header line to be removed, to give an example. =item $obj-EB( [$body, [$wrap]] ) Returns the body as one single line, where all folding information (if available) is removed. This line will also NOT end on a new-line. The optional $body argument changes the field's body. The right folding is performed before assignment. The $wrap may be specified to enforce a folding size. example: my $body = $field->unfoldedBody; print "$field"; # via overloading =back =head2 Access to the content =over 4 =item $obj-EB() Returns a list of L objects, which represent the e-mail addresses found in this header line. example: my @addr = $message->head->get('to')->addresses; my @addr = $message->to; =item $obj-EB( $name, [$value] ) Get the value of an attribute, optionally after setting it to a new value. Attributes are part of some header lines, and hide themselves in the comment field. If the attribute does not exist, then C is returned. The attribute is still encoded. example: my $field = Mail::Message::Field->new( 'Content-Type: text/plain; charset="us-ascii"'); print $field->attribute('charset'); # --> us-ascii print $field->attribute('bitmap') || 'no' # --> no $field->atrribute(filename => '/tmp/xyz'); $field->print; # --> Content-Type: text/plain; charset="us-ascii"; # filename="/tmp/xyz" # Automatically folded, and no doubles created. =item $obj-EB() Returns a list of key-value pairs, where the values are not yet decoded. Keys may appear more than once. example: my @pairs = $head->get('Content-Disposition')->attributes; =item $obj-EB( [STRING] ) Returns the unfolded comment (part after a semi-colon) in a structureed header-line. optionally after setting it to a new STRING first. When C is specified as STRING, the comment is removed. Whether the field is structured is defined by L. The I part of a header field often contains C. Often it is preferred to use L on them. =item $obj-EB() Study the header field in detail: turn on the full parsing and detailed understanding of the content of the fields. L and L objects will be transformed into any L object. example: my $subject = $msg->head->get('subject')->study; my $subject = $msg->head->study('subject'); # same my $subject = $msg->study('subject'); # same =item $obj-EB( [$time] ) =item Mail::Message::Field-EB( [$time] ) Convert a timestamp into an rfc2822 compliant date format. This differs from the default output of C in scalar context. Without argument, the C is used to get the current time. $time can be specified as one numeric (like the result of C) and as list (like produced by c in list context). Be sure to have your timezone set right, especially when this script runs automatically. example: my $now = time; Mail::Message::Field->toDate($now); Mail::Message::Field->toDate(time); Mail::Message::Field->toDate(localtime); Mail::Message::Field->toDate; # same # returns something like: # Wed, 28 Aug 2002 10:40:25 +0200 =item $obj-EB() Returns the value which is related to this field as integer. A check is performed whether this is right. =back =head2 Other methods =over 4 =item $obj-EB(STRING) =item Mail::Message::Field-EB(STRING) Convert a STRING which represents and RFC compliant time string into a timestamp like is produced by the C