
=head1 NAME

Mail::Message::Replace::MailHeader - fake Mail::Header


=head1 INHERITANCE

 Mail::Message::Replace::MailHeader
   is a Mail::Message::Head::Complete
   is a Mail::Message::Head
   is a Mail::Reporter


=head1 SYNOPSIS

 !!! ALPHA CODE !!!

 # change
 use Mail::Internet;
 use Mail::Header;
 # into
 use Mail::Message::Replace::MailInternet;
 # in existing code, and the code should still work, but
 # with the Mail::Message features.


=head1 DESCRIPTION

This module is a wrapper around a L<Mail::Message::Head::Complete|Mail::Message::Head::Complete>,
which simulates a L<Mail::Header> object.  The name-space of that module
is hijacked and many methods are added.

Most methods will work without any change, but you should test your
software again.  Small changes have been made to L<fold_length()|Mail::Message::Replace::MailHeader/"Simulating Mail::Header">,
L<header_hashref()|Mail::Message::Replace::MailHeader/"Simulating Mail::Header">.


=head1 OVERLOADED


overload: B<"">

=over 4

See L<Mail::Message::Head/"OVERLOADED">

=back

overload: B<bool>

=over 4

See L<Mail::Message::Head/"OVERLOADED">

=back


=head1 METHODS


=head2 Constructors


$obj-E<gt>B<build>([PAIR|FIELD]-LIST)

=over 4

See L<Mail::Message::Head::Complete/"Constructors">

=back

$obj-E<gt>B<clone>([FIELDS])

=over 4

See L<Mail::Message::Head::Complete/"Constructors">

=back

Mail::Message::Replace::MailHeader-E<gt>B<new>([ARG], OPTIONS)

=over 4

The ARG is an array with header lines.

 Option      Defined in       Default                                                 
 FoldLength                   79                                                      
 MailFrom                     C<'KEEP'>                                               
 Modify                       <false>                                                 
 field_type  L<Mail::Message::Head>  L<Mail::Message::Field::Fast|Mail::Message::Field::Fast>
 log         L<Mail::Reporter>  C<'WARNINGS'>                                           
 message     L<Mail::Message::Head>  undef                                                   
 modified    L<Mail::Message::Head>  <false>                                                 
 trace       L<Mail::Reporter>  C<'WARNINGS'>                                           

. FoldLength INTEGER

. MailFrom 'IGNORE'|'ERROR'|'COERCE'|'KEEP'

=over 4

How to handle the C<From > lines.  See L<mail_from()|Mail::Message::Replace::MailHeader/"Simulating Mail::Header">.

=back

. Modify BOOLEAN

=over 4

Reformat all header lines when they come in: change the folding.

=back

. field_type CLASS

. log LEVEL

. message MESSAGE

. modified BOOLEAN

. trace LEVEL

=back

=head2 The header


$obj-E<gt>B<isDelayed>

=over 4

See L<Mail::Message::Head/"The header">

=back

$obj-E<gt>B<isEmpty>

=over 4

See L<Mail::Message::Head/"The header">

=back

$obj-E<gt>B<isModified>

=over 4

See L<Mail::Message::Head/"The header">

=back

$obj-E<gt>B<knownNames>

=over 4

See L<Mail::Message::Head/"The header">

=back

$obj-E<gt>B<message>([MESSAGE])

=over 4

See L<Mail::Message::Head/"The header">

=back

$obj-E<gt>B<modified>([BOOLEAN])

=over 4

See L<Mail::Message::Head/"The header">

=back

$obj-E<gt>B<nrLines>

=over 4

See L<Mail::Message::Head::Complete/"The header">

=back

$obj-E<gt>B<orderedFields>

=over 4

See L<Mail::Message::Head/"The header">

=back

$obj-E<gt>B<size>

=over 4

See L<Mail::Message::Head::Complete/"The header">

=back

$obj-E<gt>B<wrap>(INTEGER)

=over 4

See L<Mail::Message::Head::Complete/"The header">

=back

=head2 Access to the header


$obj-E<gt>B<add>(LINE, [INDEX])

=over 4

Add a header line, which simply calls C<Mail::Message::Head::add()> on
the header for the specified LINE.  The INDEX is ignored, the unfolded
body of the field is returned.

=back

$obj-E<gt>B<addListGroup>(OBJECT)

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<addResentGroup>(RESENT-GROUP|DATA)

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<addSpamGroup>(OBJECT)

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<count>(NAME)

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<delete>(TAG, [INDEX])

=over 4

Delete the fields with the specified TAG.  The deleted fields are
returned.  If no index is given, then all are removed.

=back

$obj-E<gt>B<get>(NAME, [INDEX])

=over 4

Get all the header fields with the specified NAME.  In scalar context,
only the first fitting NAME is returned.  Even when only one NAME is
specified, multiple lines may be returned in list context: some fields
appear more than once in a header.

=back

$obj-E<gt>B<grepNames>([NAMES|ARRAY-OF-NAMES|REGEXS])

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<listGroup>

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<names>

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<print>([FILEHANDLE])

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<printSelected>(FILEHANDLE, (STRING|REGEXP)s)

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<printUndisclosed>([FILEHANDLE])

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<removeContentInfo>

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<removeField>(FIELD)

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<removeFields>(STRING|REGEXP, [STRING|REGEXP, ...])

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<removeFieldsExcept>(STRING|REGEXP, [STRING|REGEXP, ...])

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<removeListGroup>

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<removeResentGroups>

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<removeSpamGroups>

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<replace>(TAG, LINE, [INDEX])

=over 4

Replace the field named TAG. from place INDEX (by default the first) by
the LINE.  When TAG is C<undef>, it will be extracted from the LINE first.
This calls L<Mail::Message::Head::Complete::reset()|Mail::Message::Head::Complete/"Access to the header"> on the message's head.

=back

$obj-E<gt>B<resentGroups>

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<reset>(NAME, FIELDS)

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<set>(FIELD | LINE | (NAME, BODY [,ATTRS]))

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<spamDetected>

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<spamGroups>([NAMES])

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<string>

=over 4

See L<Mail::Message::Head::Complete/"Access to the header">

=back

$obj-E<gt>B<study>(NAME [,INDEX])

=over 4

See L<Mail::Message::Head/"Access to the header">

=back

=head2 About the body


$obj-E<gt>B<guessBodySize>

=over 4

See L<Mail::Message::Head/"About the body">

=back

$obj-E<gt>B<guessTimeStamp>

=over 4

See L<Mail::Message::Head::Complete/"About the body">

=back

$obj-E<gt>B<isMultipart>

=over 4

See L<Mail::Message::Head/"About the body">

=back

$obj-E<gt>B<recvstamp>

=over 4

See L<Mail::Message::Head::Complete/"About the body">

=back

$obj-E<gt>B<timestamp>

=over 4

See L<Mail::Message::Head::Complete/"About the body">

=back

=head2 Internals


$obj-E<gt>B<addNoRealize>(FIELD)

=over 4

See L<Mail::Message::Head/"Internals">

=back

$obj-E<gt>B<addOrderedFields>(FIELDS)

=over 4

See L<Mail::Message::Head/"Internals">

=back

$obj-E<gt>B<createFromLine>

=over 4

See L<Mail::Message::Head::Complete/"Internals">

=back

$obj-E<gt>B<createMessageId>

=over 4

See L<Mail::Message::Head::Complete/"Internals">

=back

$obj-E<gt>B<fileLocation>

=over 4

See L<Mail::Message::Head/"Internals">

=back

$obj-E<gt>B<load>

=over 4

See L<Mail::Message::Head/"Internals">

=back

$obj-E<gt>B<messageIdPrefix>([PREFIX, [HOSTNAME]|CODE])

Mail::Message::Replace::MailHeader-E<gt>B<messageIdPrefix>([PREFIX, [HOSTNAME]|CODE])

=over 4

See L<Mail::Message::Head::Complete/"Internals">

=back

$obj-E<gt>B<moveLocation>(DISTANCE)

=over 4

See L<Mail::Message::Head/"Internals">

=back

$obj-E<gt>B<setNoRealize>(FIELD)

=over 4

See L<Mail::Message::Head/"Internals">

=back

=head2 Error handling


$obj-E<gt>B<AUTOLOAD>

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<addReport>(OBJECT)

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<defaultTrace>([LEVEL]|[LOGLEVEL, TRACELEVEL]|[LEVEL, CALLBACK])

Mail::Message::Replace::MailHeader-E<gt>B<defaultTrace>([LEVEL]|[LOGLEVEL, TRACELEVEL]|[LEVEL, CALLBACK])

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<errors>

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<log>([LEVEL [,STRINGS]])

Mail::Message::Replace::MailHeader-E<gt>B<log>([LEVEL [,STRINGS]])

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<logPriority>(LEVEL)

Mail::Message::Replace::MailHeader-E<gt>B<logPriority>(LEVEL)

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<logSettings>

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<notImplemented>

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<report>([LEVEL])

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<reportAll>([LEVEL])

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<trace>([LEVEL])

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<warnings>

=over 4

See L<Mail::Reporter/"Error handling">

=back

=head2 Cleanup


$obj-E<gt>B<DESTROY>

=over 4

See L<Mail::Reporter/"Cleanup">

=back

$obj-E<gt>B<inGlobalDestruction>

=over 4

See L<Mail::Reporter/"Cleanup">

=back

=head2 Access to the header


=head2 Simulating Mail::Header


$obj-E<gt>B<as_string>

=over 4

Returns the whole header as one big scalar.
Calls L<Mail::Message::Head::Complete::string()|Mail::Message::Head::Complete/"Access to the header">.

=back

$obj-E<gt>B<cleanup>

=over 4

Cleanup memory usage.  Not needed here.

=back

$obj-E<gt>B<combine>(TAG, [WITH])

=over 4

I do not see any valid reason for this command, so did not implement it.

=back

$obj-E<gt>B<dup>

=over 4

Duplicate the header, which is simply L<clone()|Mail::Message::Head::Complete/"Constructors">.

=back

$obj-E<gt>B<empty>

=over 4

Clean-out the whole hash. Better not use this (simply create another
header object), although it should work.

=back

$obj-E<gt>B<exists>

=over 4

Returns whether there are any fields.

=back

$obj-E<gt>B<extract>(ARRAY)

=over 4

Extract (and remove) header fields from the array.

=back

$obj-E<gt>B<fold>([LENGTH])

=over 4

Refold all fields in the header, to LENGTH or whatever L<fold_length()|Mail::Message::Replace::MailHeader/"Simulating Mail::Header">
returns.

=back

$obj-E<gt>B<fold_length>([[TAG], LENGTH])

=over 4

Returns the line wrap, optionally after setting it to LENGTH.  The
old value is returned.  The TAG argument is ignored, because it is
silly to have different lines fold in different ways.  This method
cannot be called statically anymore.

=back

$obj-E<gt>B<header>([ARRAY])

=over 4

Extract the fields from the ARRAY, if specified, and then fold the fields.
Returned is an array with all fields, produced via L<orderedFields()|Mail::Message::Head/"The header">.

=back

$obj-E<gt>B<header_hashref>(HASH)

=over 4

If you are using this method, you must be stupid... anyway: I do not want to
support it for now: use L<add()|Mail::Message::Replace::MailHeader/"Access to the header"> and friends.

=back

$obj-E<gt>B<mail_from>(['IGNORE'|'ERROR'|'COERCE'|'KEEP'])

=over 4

What to do when a header line in the form `From ' is encountered. Valid
values are C<IGNORE> - ignore and discard the header, C<ERROR> - invoke
an error (call die), C<COERCE> - rename them as Mail-From and C<KEEP>
- keep them.

=back

$obj-E<gt>B<modify>([BOOLEAN])

=over 4

Refold the headers when they are added.

=back

$obj-E<gt>B<read>(FILE)

=over 4

Read the header from the FILE.

=back

$obj-E<gt>B<tags>

=over 4

Returns all the names of fields, implemented by
L<Mail::Message::Head::Complete::names()|Mail::Message::Head::Complete/"Access to the header">.

=back

$obj-E<gt>B<unfold>([TAG])

=over 4

Remove the folding for all instances of TAG, or all fields at once.

=back

=head2 The nasty bits


$obj-E<gt>B<isa>(CLASS)

Mail::Message::Replace::MailHeader-E<gt>B<isa>(CLASS)

=over 4

Of course, the C<isa()> class inheritance check should not see our
nasty trick.

=back



=head1 DIAGNOSTICS

I<Warning:> Cannot remove field $name from header: not found.

You ask to remove a field which is not known in the header.  Using
L<delete()|Mail::Message::Replace::MailHeader/"Access to the header">, L<reset()|Mail::Message::Head::Complete/"Access to the header">, or L<set()|Mail::Message::Head::Complete/"Access to the header"> to do the job will not result
in warnings: those methods check the existence of the field first.

I<Warning:> Field objects have an implied name ($name)


I<Error:> Package $package does not implement $method.

Fatal error: the specific package (or one of its superclasses) does not
implement this method where it should. This message means that some other
related classes do implement this method however the class at hand does
not.  Probably you should investigate this and probably inform the author
of the package.


=head1 DETAILS






=head1 REFERENCES

See the MailBox website at L<http://perl.overmeer.net/mailbox/> for more details.

=head1 COPYRIGHTS

Distribution version 2.058.
Written by Mark Overmeer (mark@overmeer.net).  See the ChangeLog for
other contributors.

Copyright (c) 2001-2003 by the author(s). All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.


