1=encoding utf8 2 3=head1 NAME 4 5Mail::Message::Field::Full - construct one smart line in a message header 6 7=head1 INHERITANCE 8 9 Mail::Message::Field::Full 10 is a Mail::Message::Field 11 is a Mail::Reporter 12 13 Mail::Message::Field::Full is extended by 14 Mail::Message::Field::Structured 15 Mail::Message::Field::Unstructured 16 17=head1 SYNOPSIS 18 19 # Getting to understand the complexity of a header field ... 20 21 my $fast = $msg->head->get('subject'); 22 my $full = Mail::Message::Field::Full->from($fast); 23 24 my $full = $msg->head->get('subject')->study; # same 25 my $full = $msg->head->study('subject'); # same 26 my $full = $msg->study('subject'); # same 27 28 # ... or build a complex header field yourself 29 30 my $f = Mail::Message::Field::Full->new('To'); 31 my $f = Mail::Message::Field::Full->new('Subject: hi!'); 32 my $f = Mail::Message::Field::Full->new(Subject => 'hi!'); 33 34=head1 DESCRIPTION 35 36This is the I<full> implementation of a header field: it has I<full> 37understanding of all predefined header fields. These objects will be 38quite slow, because header fields can be very complex. Of course, this 39class delivers the optimal result, but for a quite large penalty in 40performance and memory consumption. Are you willing to accept? 41 42This class supports the common header description from RFC2822 (formerly 43RFC822), the extensions with respect to character set encodings as specified 44in RFC2047, and the extensions on language specification and long parameter 45wrapping from RFC2231. If you do not need the latter two, then the 46L<Mail::Message::Field::Fast|Mail::Message::Field::Fast> and L<Mail::Message::Field::Flex|Mail::Message::Field::Flex> 47are enough for your application. 48 49Extends L<"DESCRIPTION" in Mail::Message::Field|Mail::Message::Field/"DESCRIPTION">. 50 51=head1 OVERLOADED 52 53Extends L<"OVERLOADED" in Mail::Message::Field|Mail::Message::Field/"OVERLOADED">. 54 55=over 4 56 57=item overload: B<""> 58 59Inherited, see L<Mail::Message::Field/"OVERLOADED"> 60 61=item overload: B<0+> 62 63Inherited, see L<Mail::Message::Field/"OVERLOADED"> 64 65=item overload: B<<=>> 66 67Inherited, see L<Mail::Message::Field/"OVERLOADED"> 68 69=item overload: B<bool> 70 71Inherited, see L<Mail::Message::Field/"OVERLOADED"> 72 73=item overload: B<cmp> 74 75Inherited, see L<Mail::Message::Field/"OVERLOADED"> 76 77=item overload: B<stringification> 78 79In string context, the decoded body is returned, as if L<decodedBody()|Mail::Message::Field::Full/"Access to the body"> 80would have been called. 81 82=back 83 84=head1 METHODS 85 86Extends L<"METHODS" in Mail::Message::Field|Mail::Message::Field/"METHODS">. 87 88=head2 Constructors 89 90Extends L<"Constructors" in Mail::Message::Field|Mail::Message::Field/"Constructors">. 91 92=over 4 93 94=item $obj-E<gt>B<clone>() 95 96Inherited, see L<Mail::Message::Field/"Constructors"> 97 98=item Mail::Message::Field::Full-E<gt>B<from>($field, %options) 99 100Convert any $field (a L<Mail::Message::Field|Mail::Message::Field> object) into a new 101L<Mail::Message::Field::Full|Mail::Message::Field::Full> object. This conversion is done the hard 102way: the string which is produced by the original object is parsed 103again. Usually, the string which is parsed is exactly the line (or lines) 104as found in the original input source, which is a good thing because Full 105fields are much more careful with the actual content. 106 107%options are passed to the constructor (see L<new()|Mail::Message::Field::Full/"METHODS">). In any case, some 108extensions of this Full field class is returned. It depends on which 109field is created what kind of class we get. 110 111example: 112 113 my $fast = $msg->head->get('subject'); 114 my $full = Mail::Message::Field::Full->from($fast); 115 116 my $full = $msg->head->get('subject')->study; # same 117 my $full = $msg->head->study('subject'); # same 118 my $full = $msg->get('subject'); # same 119 120=item Mail::Message::Field::Full-E<gt>B<new>($data) 121 122Creating a new field object the correct way is a lot of work, because 123there is so much freedom in the RFCs, but at the same time so many 124restrictions. Most fields are implemented, but if you have your own 125field (and do no want to contribute it to MailBox), then simply call 126new on your own package. 127 128You have the choice to instantiate the object as string or in prepared 129parts: 130 131=over 4 132 133=item * B<new> LINE, OPTIONS 134 135Pass a LINE as it could be found in a file: a (possibly folded) line 136which is terminated by a new-line. 137 138=item * B<new> NAME, [BODY], OPTIONS 139 140A set of values which shape the line. 141 142=back 143 144The NAME is a wellformed header name (you may use wellformedName()) to 145be sure about the casing. The BODY is a string, one object, or an 146ref-array of objects. In case of objects, they must fit to the 147constructor of the field: the types which are accepted may differ. 148The optional ATTRIBUTE list contains L<Mail::Message::Field::Attribute|Mail::Message::Field::Attribute> 149objects. Finally, there are some OPTIONS. 150 151 -Option --Defined in --Default 152 charset undef 153 encoding 'q' 154 force false 155 language undef 156 log Mail::Reporter 'WARNINGS' 157 trace Mail::Reporter 'WARNINGS' 158 159=over 2 160 161=item charset => STRING 162 163The body is specified in utf8, and must become 7-bits ascii to be 164transmited. Specify a charset to which the multi-byte utf8 is converted 165before it gets encoded. See L<encode()|Mail::Message::Field::Full/"Internals">, which does the job. 166 167=item encoding => 'q'|'Q'|'b'|'B' 168 169Non-ascii characters are encoded using Quoted-Printable ('q' or 'Q') or 170Base64 ('b' or 'B') encoding. 171 172=item force => BOOLEAN 173 174Enforce encoding in the specified charset, even when it is not needed 175because the body does not contain any non-ascii characters. 176 177=item language => STRING 178 179The language used can be specified, however is rarely used my mail clients. 180 181=item log => LEVEL 182 183=item trace => LEVEL 184 185=back 186 187example: 188 189 my $s = Mail::Message::Field::Full->new('Subject: Hello World'); 190 my $s = Mail::Message::Field::Full->new('Subject', 'Hello World'); 191 192 my @attrs = (Mail::Message::Field::Attribute->new(...), ...); 193 my @options = (extra => 'the color blue'); 194 my $t = Mail::Message::Field::Full->new(To => \@addrs, @attrs, @options); 195 196=back 197 198=head2 The field 199 200Extends L<"The field" in Mail::Message::Field|Mail::Message::Field/"The field">. 201 202=over 4 203 204=item $obj-E<gt>B<isStructured>() 205 206=item Mail::Message::Field::Full-E<gt>B<isStructured>() 207 208Inherited, see L<Mail::Message::Field/"The field"> 209 210=item $obj-E<gt>B<length>() 211 212Inherited, see L<Mail::Message::Field/"The field"> 213 214=item $obj-E<gt>B<nrLines>() 215 216Inherited, see L<Mail::Message::Field/"The field"> 217 218=item $obj-E<gt>B<print>( [$fh] ) 219 220Inherited, see L<Mail::Message::Field/"The field"> 221 222=item $obj-E<gt>B<size>() 223 224Inherited, see L<Mail::Message::Field/"The field"> 225 226=item $obj-E<gt>B<string>( [$wrap] ) 227 228Inherited, see L<Mail::Message::Field/"The field"> 229 230=item $obj-E<gt>B<toDisclose>() 231 232Inherited, see L<Mail::Message::Field/"The field"> 233 234=back 235 236=head2 Access to the name 237 238Extends L<"Access to the name" in Mail::Message::Field|Mail::Message::Field/"Access to the name">. 239 240=over 4 241 242=item $obj-E<gt>B<Name>() 243 244Inherited, see L<Mail::Message::Field/"Access to the name"> 245 246=item $obj-E<gt>B<name>() 247 248Inherited, see L<Mail::Message::Field/"Access to the name"> 249 250=item $obj-E<gt>B<wellformedName>( [STRING] ) 251 252Inherited, see L<Mail::Message::Field/"Access to the name"> 253 254=back 255 256=head2 Access to the body 257 258Extends L<"Access to the body" in Mail::Message::Field|Mail::Message::Field/"Access to the body">. 259 260=over 4 261 262=item $obj-E<gt>B<body>() 263 264Inherited, see L<Mail::Message::Field/"Access to the body"> 265 266=item $obj-E<gt>B<decodedBody>(%options) 267 268Returns the unfolded body of the field, where encodings are resolved. The 269returned line will still contain comments and such. The %options are passed 270to the decoder, see L<decode()|Mail::Message::Field::Full/"Internals">. 271 272BE WARNED: if the field is a structured field, the content may change syntax, 273because of encapsulated special characters. By default, the body is decoded 274as text, which results in a small difference within comments as well 275(read the RFC). 276 277=item $obj-E<gt>B<folded>() 278 279Inherited, see L<Mail::Message::Field/"Access to the body"> 280 281=item $obj-E<gt>B<foldedBody>( [$body] ) 282 283Inherited, see L<Mail::Message::Field/"Access to the body"> 284 285=item $obj-E<gt>B<stripCFWS>( [STRING] ) 286 287=item Mail::Message::Field::Full-E<gt>B<stripCFWS>( [STRING] ) 288 289Inherited, see L<Mail::Message::Field/"Access to the body"> 290 291=item $obj-E<gt>B<unfoldedBody>( [$body, [$wrap]] ) 292 293Inherited, see L<Mail::Message::Field/"Access to the body"> 294 295=back 296 297=head2 Access to the content 298 299Extends L<"Access to the content" in Mail::Message::Field|Mail::Message::Field/"Access to the content">. 300 301=over 4 302 303=item $obj-E<gt>B<addresses>() 304 305Inherited, see L<Mail::Message::Field/"Access to the content"> 306 307=item $obj-E<gt>B<attribute>( $name, [$value] ) 308 309Inherited, see L<Mail::Message::Field/"Access to the content"> 310 311=item $obj-E<gt>B<attributes>() 312 313Inherited, see L<Mail::Message::Field/"Access to the content"> 314 315=item $obj-E<gt>B<beautify>() 316 317For structured header fields, this removes the original encoding of the 318field's body (the format as it was offered to L<parse()|Mail::Message::Field::Full/"Parsing">), therefore the 319next request for the field will have to re-produce the read data clean 320and nice. For unstructured bodies, this method doesn't do a thing. 321 322=item $obj-E<gt>B<comment>( [STRING] ) 323 324Inherited, see L<Mail::Message::Field/"Access to the content"> 325 326=item $obj-E<gt>B<createComment>(STRING, %options) 327 328=item Mail::Message::Field::Full-E<gt>B<createComment>(STRING, %options) 329 330Create a comment to become part in a field. Comments are automatically 331included within parenthesis. Matching pairs of parenthesis are 332permitted within the STRING. When a non-matching parenthesis are used, 333it is only permitted with an escape (a backslash) in front of them. 334These backslashes will be added automatically if needed (don't worry!). 335Backslashes will stay, except at the end, where it will be doubled. 336 337The %options are C<charset>, C<language>, and C<encoding> as always. 338The created comment is returned. 339 340=item $obj-E<gt>B<createPhrase>(STRING, %options) 341 342=item Mail::Message::Field::Full-E<gt>B<createPhrase>(STRING, %options) 343 344A phrase is a text which plays a well defined role. This is the main 345difference with comments, which have do specified meaning. Some special 346characters in the phrase will cause it to be surrounded with double 347quotes: do not specify them yourself. 348 349The %options are C<charset>, C<language>, and C<encoding>, as always. 350 351=item $obj-E<gt>B<study>() 352 353Inherited, see L<Mail::Message::Field/"Access to the content"> 354 355=item $obj-E<gt>B<toDate>( [$time] ) 356 357=item Mail::Message::Field::Full-E<gt>B<toDate>( [$time] ) 358 359Inherited, see L<Mail::Message::Field/"Access to the content"> 360 361=item $obj-E<gt>B<toInt>() 362 363Inherited, see L<Mail::Message::Field/"Access to the content"> 364 365=back 366 367=head2 Other methods 368 369Extends L<"Other methods" in Mail::Message::Field|Mail::Message::Field/"Other methods">. 370 371=over 4 372 373=item $obj-E<gt>B<dateToTimestamp>(STRING) 374 375=item Mail::Message::Field::Full-E<gt>B<dateToTimestamp>(STRING) 376 377Inherited, see L<Mail::Message::Field/"Other methods"> 378 379=back 380 381=head2 Internals 382 383Extends L<"Internals" in Mail::Message::Field|Mail::Message::Field/"Internals">. 384 385=over 4 386 387=item $obj-E<gt>B<consume>( $line | <$name,<$body|$objects>> ) 388 389Inherited, see L<Mail::Message::Field/"Internals"> 390 391=item $obj-E<gt>B<decode>(STRING, %options) 392 393=item Mail::Message::Field::Full-E<gt>B<decode>(STRING, %options) 394 395Decode field encoded STRING to an utf8 string. The input STRING is part of 396a header field, and as such, may contain encoded words in C<=?...?.?...?=> 397format defined by RFC2047. The STRING may contain multiple encoded parts, 398maybe using different character sets. 399 400Be warned: you MUST first interpret the field into parts, like phrases and 401comments, and then decode each part separately, otherwise the decoded text 402may interfere with your markup characters. 403 404Be warned: language information, which is defined in RFC2231, is ignored. 405 406Encodings with unknown charsets are left untouched [requires v2.085, 407otherwise croaked]. Unknown characters within an charset are replaced by 408a '?'. 409 410 -Option --Default 411 is_text 1 412 413=over 2 414 415=item is_text => BOOLEAN 416 417Encoding on text is slightly more complicated than encoding structured data, 418because it contains blanks. Visible blanks have to be ignored between two 419encoded words in the text, but not when an encoded word follows or precedes 420an unencoded word. Phrases and comments are texts. 421 422=back 423 424example: 425 426 print Mail::Message::Field::Full->decode('=?iso-8859-1?Q?J=F8rgen?='); 427 # prints JE<0slash>rgen 428 429=item $obj-E<gt>B<defaultWrapLength>( [$length] ) 430 431Inherited, see L<Mail::Message::Field/"Internals"> 432 433=item $obj-E<gt>B<encode>(STRING, %options) 434 435Encode the (possibly utf8 encoded) STRING to a string which is acceptable 436to the RFC2047 definition of a header: only containing us-ascii characters. 437 438 -Option --Default 439 charset 'us-ascii' 440 encoding 'q' 441 force <flase> 442 language undef 443 name undef 444 445=over 2 446 447=item charset => STRING 448 449STRING is an utf8 string which has to be translated into any byte-wise 450character set for transport, because MIME-headers can only contain ascii 451characters. 452 453=item encoding => 'q'|'Q'|'b'|'B' 454 455The character encoding to be used. With C<q> or C<Q>, quoted-printable 456encoding will be used. With C<b > or C<B >, base64 encoding will be taken. 457 458=item force => BOOLEAN 459 460Encode the string, even when it only contains us-ascii characters. By 461default, this is off because it decreases readibility of the produced 462header fields. 463 464=item language => STRING 465 466RFC2231 defines how to specify language encodings in encoded words. The 467STRING is a strandard iso language name. 468 469=item name => STRING 470 471[3.002] When the name of the field is given, the first encoded line will 472be shorter. 473 474=back 475 476=item $obj-E<gt>B<fold>( $name, $body, [$maxchars] ) 477 478=item Mail::Message::Field::Full-E<gt>B<fold>( $name, $body, [$maxchars] ) 479 480Inherited, see L<Mail::Message::Field/"Internals"> 481 482=item $obj-E<gt>B<setWrapLength>( [$length] ) 483 484Inherited, see L<Mail::Message::Field/"Internals"> 485 486=item $obj-E<gt>B<stringifyData>(STRING|ARRAY|$objects) 487 488Inherited, see L<Mail::Message::Field/"Internals"> 489 490=item $obj-E<gt>B<unfold>(STRING) 491 492Inherited, see L<Mail::Message::Field/"Internals"> 493 494=back 495 496=head2 Parsing 497 498You probably do not want to call these parsing methods yourself: use 499the standard constructors (L<new()|Mail::Message::Field::Full/"METHODS">) and it will be done for you. 500 501=over 4 502 503=item $obj-E<gt>B<consumeComment>(STRING) 504 505=item Mail::Message::Field::Full-E<gt>B<consumeComment>(STRING) 506 507Try to read a comment from the STRING. When successful, the comment 508without encapsulation parenthesis is returned, together with the rest 509of the string. 510 511=item $obj-E<gt>B<consumeDotAtom>(STRING) 512 513Returns three elemens: the atom-text, the rest string, and the 514concatenated comments. Both atom and comments can be undef. 515 516=item $obj-E<gt>B<consumePhrase>(STRING) 517 518=item Mail::Message::Field::Full-E<gt>B<consumePhrase>(STRING) 519 520Take the STRING, and try to strip-off a valid phrase. In the obsolete 521phrase syntax, any sequence of words is accepted as phrase (as long as 522certain special characters are not used). RFC2822 is stricter: only 523one word or a quoted string is allowed. As always, the obsolete 524syntax is accepted, and the new syntax is produced. 525 526This method returns two elements: the phrase (or undef) followed 527by the resulting string. The phrase will be removed from the optional 528quotes. Be warned that C<""> will return an empty, valid phrase. 529 530example: 531 532 my ($phrase, $rest) = $field->consumePhrase( q["hi!" <sales@example.com>] ); 533 534=item $obj-E<gt>B<parse>(STRING) 535 536Get the detailed information from the STRING, and store the data found 537in the field object. The accepted input is very field type dependent. 538Unstructured fields do no parsing whatsoever. 539 540=item $obj-E<gt>B<produceBody>() 541 542Produce the text for the field, based on the information stored within the 543field object. 544 545Usually, you wish the exact same line as was found in the input source 546of a message. But when you have created a field yourself, it should get 547formatted. You may call L<beautify()|Mail::Message::Field::Full/"Access to the content"> on a preformatted field to enforce 548a call to this method when the field is needed later. 549 550=back 551 552=head2 Error handling 553 554Extends L<"Error handling" in Mail::Message::Field|Mail::Message::Field/"Error handling">. 555 556=over 4 557 558=item $obj-E<gt>B<AUTOLOAD>() 559 560Inherited, see L<Mail::Reporter/"Error handling"> 561 562=item $obj-E<gt>B<addReport>($object) 563 564Inherited, see L<Mail::Reporter/"Error handling"> 565 566=item $obj-E<gt>B<defaultTrace>( [$level]|[$loglevel, $tracelevel]|[$level, $callback] ) 567 568=item Mail::Message::Field::Full-E<gt>B<defaultTrace>( [$level]|[$loglevel, $tracelevel]|[$level, $callback] ) 569 570Inherited, see L<Mail::Reporter/"Error handling"> 571 572=item $obj-E<gt>B<errors>() 573 574Inherited, see L<Mail::Reporter/"Error handling"> 575 576=item $obj-E<gt>B<log>( [$level, [$strings]] ) 577 578=item Mail::Message::Field::Full-E<gt>B<log>( [$level, [$strings]] ) 579 580Inherited, see L<Mail::Reporter/"Error handling"> 581 582=item $obj-E<gt>B<logPriority>($level) 583 584=item Mail::Message::Field::Full-E<gt>B<logPriority>($level) 585 586Inherited, see L<Mail::Reporter/"Error handling"> 587 588=item $obj-E<gt>B<logSettings>() 589 590Inherited, see L<Mail::Reporter/"Error handling"> 591 592=item $obj-E<gt>B<notImplemented>() 593 594Inherited, see L<Mail::Reporter/"Error handling"> 595 596=item $obj-E<gt>B<report>( [$level] ) 597 598Inherited, see L<Mail::Reporter/"Error handling"> 599 600=item $obj-E<gt>B<reportAll>( [$level] ) 601 602Inherited, see L<Mail::Reporter/"Error handling"> 603 604=item $obj-E<gt>B<trace>( [$level] ) 605 606Inherited, see L<Mail::Reporter/"Error handling"> 607 608=item $obj-E<gt>B<warnings>() 609 610Inherited, see L<Mail::Reporter/"Error handling"> 611 612=back 613 614=head2 Cleanup 615 616Extends L<"Cleanup" in Mail::Message::Field|Mail::Message::Field/"Cleanup">. 617 618=over 4 619 620=item $obj-E<gt>B<DESTROY>() 621 622Inherited, see L<Mail::Reporter/"Cleanup"> 623 624=back 625 626=head1 DETAILS 627 628Extends L<"DETAILS" in Mail::Message::Field|Mail::Message::Field/"DETAILS">. 629 630=head1 DIAGNOSTICS 631 632=over 4 633 634=item Warning: Field content is not numerical: $content 635 636The numeric value of a field is requested (for instance the C<Lines> or 637C<Content-Length> fields should be numerical), however the data contains 638weird characters. 639 640=item Warning: Illegal character in charset '$charset' 641 642The field is created with an utf8 string which only contains data from the 643specified character set. However, that character set can never be a valid 644name because it contains characters which are not permitted. 645 646=item Warning: Illegal character in field name $name 647 648A new field is being created which does contain characters not permitted 649by the RFCs. Using this field in messages may break other e-mail clients 650or transfer agents, and therefore mutulate or extinguish your message. 651 652=item Warning: Illegal character in language '$lang' 653 654The field is created with data which is specified to be in a certain language, 655however, the name of the language cannot be valid: it contains characters 656which are not permitted by the RFCs. 657 658=item Warning: Illegal encoding '$encoding', used 'q' 659 660The RFCs only permit base64 (C<b > or C<B >) or quoted-printable 661(C<q> or C<Q>) encoding. Other than these four options are illegal. 662 663=item Error: Package $package does not implement $method. 664 665Fatal error: the specific package (or one of its superclasses) does not 666implement this method where it should. This message means that some other 667related classes do implement this method however the class at hand does 668not. Probably you should investigate this and probably inform the author 669of the package. 670 671=back 672 673=head1 SEE ALSO 674 675This module is part of Mail-Message distribution version 3.011, 676built on July 27, 2021. Website: F<http://perl.overmeer.net/CPAN/> 677 678=head1 LICENSE 679 680Copyrights 2001-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog. 681 682This program is free software; you can redistribute it and/or modify it 683under the same terms as Perl itself. 684See F<http://dev.perl.org/licenses/> 685 686