NAME
Mail::Message::Field::Full - one line of a message header
CLASS INHERITANCE
Mail::Message::Field::Full
is a Mail::Message::Field
is a Mail::Reporter
Mail::Message::Field::Full is extended by
Mail::Message::Field::Addresses
Mail::Message::Field::Unstructured
SYNOPSIS
!! THE IMPLEMENTATION OF THIS MODULE IS NOT COMPLETELY FINISHED YET!!
# Getting to understand the complexity of a header field ...
my $fast = $msg->head->get('subject');
my $full = Mail::Message::Field::Full->from($fast);
my $full = $msg->head->get('subject')->study; # same
my $full = $msg->head->study('subject'); # same
my $full = $msg->get('subject'); # same
# ... or build a complex header field yourself
my @encode = (charset => 'jp', use_continuations => 1);
my $f = Mail::Message::Field::Full->new('Content-Type' => 'text/html');
$f->addExtra(" and more", @encode);
$f->addPhrase("text ", @encode);
$f->addPhrase(" and more text", language => 'en-GB' );
$f->addAttribute('filename=passwd');
$f->addAttribute(filename => 'passwd', @encode);
my $attr = Mail::Message::Field::Attribute->new(...);
$f->addAttribute($attr);
$f->addComment('just me', $encode);
DESCRIPTION
This is the full implementation of a header field: it will be quite slow, because header fields can be very complex. Of course, this class delivers the optimal result, but for a quite large penalty in performance and memory consumption.
This class supports the common header description from RFC2822 (formerly RFC822), the extensions with respect to character-set encodings as specified in RFC2047, and the extensions on language specification and long parameter wrapping from RFC2231. If you do not need the latter two, then the Mail::Message::Field::Fast and Mail::Message::Field::Flex are enough for your application.
METHODS
Initiation
- from FIELD, OPTIONS
-
(Class method) Convert any FIELD (a Mail::Message::Field object) into a new Mail::Message::Field::Full object. This conversion is done the hard way: the string which is produced by the original object is parsed again. Usually, the string which is parsed is exactly the line (or lines) as found in the original input source, which is a good thing because Full fields are much more carefull with the actual content.
OPTIONS are passed to the constructor (see new()). In any case, some extensions of this Full field class is returned. It depends on which field is created what kind of class we get.
Examples:
my $fast = $msg->head->get('subject'); my $full = Mail::Message::Field::Full->from($fast); my $full = $msg->head->get('subject')->study; # same my $full = $msg->head->study('subject'); # same my $full = $msg->get('subject'); # same
- new DATA
-
(Class method) Creating a new field object the correct way is a lot of work, because there is so much freedom in the RFCs, but at the same time so many restrictions. Most fields are implemented, but if you have your own field (and do no want to contribute it to Mail::Box), then simply call new on your own package.
You have the choice to instantiate the object as string or in prepared parts:
new LINE
new NAME, BODY, [ATTRIBUTES], OPTIONS
The NAME is a wellformed header name (you may use wellformedName()) to be sure about the casing. The BODY is a string, one object, or an ref-array of objects. In case of objects, they must fit to the constructor of the field: the types which are accepted may differ. The optional ATTRIBUTE list contains Mail::Message::Field::Attribute objects. Finally, there are some OPTIONS.
OPTION DEFAULT attributes [] charset C<undef> encoding 'q' extra undef force false is_structured C<depends> language C<undef> log 'WARNINGS' trace 'WARNINGS'
- attributes => ATTRS
-
There are various ways to specify these attributes: pass a reference to an array which list of key-value pairs representing attributes, or reference to a hash containing these pairs, or an array with Mail::Message::Field::Attribute objects.
- charset => STRING
-
The body is specified in utf8, and must become 7bits ascii to be transmited. Specify a charset to which the multi-byte utf8 is converted before it gets encoded. See encode(), which does the job.
- encoding => 'q'|'Q'|'b'|'B'
-
Non-ascii characters are encoded using Quoted-Printable ('q' or 'Q') or Base64 ('b' or 'B') encoding.
- extra => STRING
-
Text which is appended after the line (preceded by a semicolon).
- force => BOOLEAN
-
Enforce encoding in the specified charset, even when it is not needed because the body does not contain any non-ascii characters.
- is_structured => BOOLEAN
-
If the name of the field is known, than the internals know whether the field is structured or not. If you call the constructor on your own class which is derived from Mail::Message::Field::Full, the default is
true
. If you have no own implementation for an unknown field, the boolean is consideredfalse
.For fields which are not known,
true
means that a Mail::Message::Field::Structured will be created. Thefalse
value will create a Mail::Message::Field::Unstructured. - language => STRING
-
The language used can be specified, however is rarely used my mail clients.
- log => LEVEL
-
See Mail::Reporter::new(log)
- trace => LEVEL
-
See Mail::Reporter::new(trace)
Examples:
my $s = Mail::Message::Field::Full->new('Subject: Hello World'); my $s = Mail::Message::Field::Full->new('Subject', 'Hello World'); my @attrs = (Mail::Message::Field::Attribute->new(...), ...); my @options = (extra => 'the color blue'); my $t = Mail::Message::Field::Full->new(To => \@addrs, @attrs, @options);
The Field
- addAttribute OBJECT|(STRING, OPTIONS)|(NAME,VALUE,OPTIONS)
-
Add an attribute to the field. The attributes are added left-to-right into the string representation of the field, although the order of the attributes is un-important, according to the RFCs.
You may pass a fully prepared Mail::Message::Field::Attribute OBJECT, if you like to do all preparations for correct representation of the data yourself. You may also pass one STRING, which is a fully prepared attribute. This STRING will not be changed, so be careful about quoting and encodings.
As third possibility, you can specify an attribute NAME and its VALUE. An attribute object will be created for you implicitly in both cases where such object is not supplied, passing the OPTIONS. See Mail::Message::Field::Attributes::new() about the available OPTIONS.
The attribute object is returned, however, when continuations are used this may be an object you already know about.
undef
is returned when construction fails (when the attribute is incorrect).Examples:
$f->addAttribute('filename=passwd'); $f->addAttribute(filename => 'passwd', use_continuations => 0); my $attr = Mail::Message::Field::Attribute->new(...); $f->addAttribute($attr);
- addComment COMMENT, OPTIONS
-
Creates a comment (see createComment()) and adds it immediately to this field. Empty or undefined COMMENTs are ignored. The created comment is returned.
- addExtra STRING
-
Adds a string to the line, which is not an attribute however does start with a semi-colon. Empty or undefined STRINGs are ignored.
- addPhrase STRING, OPTIONS
-
Create a phrase (see createPhrase()) and immediately add it to this field. Empty or undefined values of STRING are ignored. The created phrase is returned.
- attributes
-
Returns a list with all attributes, which are all Mail::Message::Field::Attribute objects. The attributes are not ordered in any way. The list may be empty. Double attributes or continuations are folded into one.
- clone
-
See Mail::Message::Field::clone()
- createComment STRING, OPTIONS
-
(Class or Instance method) Create a comment to become part in a field. Comments are automatically included within parenthesis. Matching pairs of parenthesis are permitted within the STRING. When a non-matching parenthesis are used, it is only permitted with an escape (a backslash) in front of them. These backslashes will be added automatically if needed (don't worry!). Backslashes will stay, except at the end, where it will be doubled.
The OPTIONS are
charset
,language
, andencoding
as always. See addComment(). The created comment is returned. - createPhrase STRING, OPTIONS
-
(Class or Instance method) A phrase is a text which plays a well defined role. This is the main difference with comments, which have do specified meaning. Some special characters in the phrase will cause it to be surrounded with double quotes: do not specify them yourself.
The OPTIONS are
charset
,language
, andencoding
as always. See addPhrase(). - isStructured
-
See Mail::Message::Field::isStructured()
- length
-
See Mail::Message::Field::length()
Access to the Field
- Name
-
See Mail::Message::Field::Name()
- addresses
-
See Mail::Message::Field::addresses()
- attribute NAME [, VALUE]
-
See Mail::Message::Field::attribute()
- body
-
See Mail::Message::Field::body()
- comment [STRING]
-
See Mail::Message::Field::comment()
- dateToTimestamp STRING
-
See Mail::Message::Field::dateToTimestamp()
- decodedBody OPTIONS
-
Returns the unfolded body of the field, where encodings are resolved. The returned line will still contain comments and such. The OPTIONS are passed to the decoder, see decode().
BE WARNED: if the field is a structured field, the content may change syntax, because of encapsulated special characters. By default, the body is decoded as text, which results in a small difference within comments as well (read the RFC).
- folded
-
See Mail::Message::Field::folded()
- foldedBody [BODY]
-
See Mail::Message::Field::foldedBody()
- name
-
See Mail::Message::Field::name()
- nrLines
-
See Mail::Message::Field::nrLines()
- print [FILEHANDLE]
-
See Mail::Message::Field::print()
- size
-
See Mail::Message::Field::size()
- string [WRAP]
-
See Mail::Message::Field::string()
- stripCFWS [STRING]
-
See Mail::Message::Field::stripCFWS()
- toDate [TIME]
-
See Mail::Message::Field::toDate()
- toDisclose
-
See Mail::Message::Field::toDisclose()
- toInt
-
See Mail::Message::Field::toInt()
- unfoldedBody [BODY, [WRAP]]
-
See Mail::Message::Field::unfoldedBody()
- wellformedName [STRING]
-
See Mail::Message::Field::wellformedName()
Reading and Writing [internals]
- consume LINE | (NAME,BODY|OBJECTS)
-
See Mail::Message::Field::consume()
- consumeComment STRING
-
(Class or Instance method) Try to read a comment from the STRING. When successful, the comment without encapsulation parenthesis is returned, together with the rest of the string.
- consumeDotAtom STRING
-
Returns three elemens: the atom-text, the rest string, and the concatenated comments. Both atom and comments can be undef.
- consumePhrase STRING
-
(Class or Instance method) Take the STRING, and try to strip-off a valid phrase. In the obsolete phrase syntax, any sequence of words is accepted as phrase (as long as certain special characters are not used). RFC2882 is stricter: only one word or a quoted string is allowed. As always, the obsolete syntax is accepted, and the new syntax is produced.
This method returns two elements: the phrase (or undef) followed by the resulting string. The phrase will be removed from the optional quotes. Be warned that
""
will return an empty, valid phrase.Examples:
my ($phrase, $rest) = $field->consumePhrase( q["hi!" <sales@example.com>] );
- decode STRING, OPTIONS
-
(Class or Instance method) Decode field encoded STRING to an utf8 string. The input STRING is part of a header field, and as such, may contain encoded words in
=?...?.?...?=
format defined by RFC2047. The STRING may contain multiple encoded parts, maybe using different character sets.Be warned: you MUST first interpret the field into parts, like phrases and comments, and then decode each part separately, otherwise the decoded text may interfere with your markup characters.
Be warned: language information, which is defined in RFC2231, is ignored.
OPTION DEFAULT is_text => 1
- is_text => => BOOLEAN
-
Encoding on text is slightly more complicated than encoding structured data, because it contains blanks. Visible blanks have to be ignored between two encoded words in the text, but not when an encoded word follows or preceeds an unencoded word. Phrases and comments are texts.
Examples:
print Mail::Message::Field::Full->decode('=?iso-8859-1?Q?J=F8rgen?='); # prints JE<0slash>rgen
- defaultWrapLength [LENGTH]
-
See Mail::Message::Field::defaultWrapLength()
- encode STRING, OPTIONS
-
Encode the (possibly utf8 encoded) STRING to a string which is acceptable to the RFC2047 definition of a header: only containing us-ascii characters.
OPTION DEFAULT charset 'us-ascii' encoding 'q' force 0 language C<undef>
- charset => STRING
-
STRING is an utf8 string which has to be translated into any byte-wise character set for transport, because MIME-headers can only contain ascii characters.
- encoding => 'q'|'Q'|'b'|'B'
-
The character encoding to be used. With
q
orQ
, quoted-printable encoding will be used. Withb
orB
, base64 encoding will be taken. - force => BOOLEAN
-
Encode the string, even when it only contains us-ascii characters. By default, this is off because it decreases readibility of the produced header fields.
- language => STRING
-
RFC2231 defines how to specify language encodings in encoded words. The STRING is a strandard iso language name.
- fold NAME, BODY, [MAXCHARS]
-
See Mail::Message::Field::fold()
- setWrapLength [LENGTH]
-
See Mail::Message::Field::setWrapLength()
- unfold STRING
-
See Mail::Message::Field::unfold()
Logging and Tracing
- defaultTrace [LEVEL, [LEVEL]
-
See Mail::Reporter::defaultTrace()
- errors
-
See Mail::Reporter::errors()
- log [LEVEL [,STRINGS]]
-
See Mail::Reporter::log()
- report [LEVEL]
-
See Mail::Reporter::report()
- reportAll [LEVEL]
-
See Mail::Reporter::reportAll()
- trace [LEVEL]
-
See Mail::Reporter::trace()
- warnings
-
See Mail::Reporter::warnings()
Other Methods
- AUTOLOAD
-
See Mail::Reporter::AUTOLOAD()
- DESTROY
-
See Mail::Reporter::DESTROY()
- inGlobalDestruction
-
See Mail::Reporter::inGlobalDestruction()
- logPriority LEVEL
-
See Mail::Reporter::logPriority()
- logSettings
-
See Mail::Reporter::logSettings()
- notImplemented
-
See Mail::Reporter::notImplemented()
SEE ALSO
A good start to read is Mail::Box-Overview. More documentation and a mailinglist are available from the project's website at http://perl.overmeer.net/mailbox/.
AUTHOR
Written by Mark Overmeer (mark@overmeer.net) with the help of many. See the ChangeLog for details.
VERSION
This code is beta, version 2.039.
Copyright (c) 2001-2003 by the authors. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.