The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mail::Box::Message - manage one message within a mail-folder

INHERITANCE

 Mail::Box::Message
   is a Mail::Message
   is a Mail::Reporter

 Mail::Box::Message is extended by
   Mail::Box::Dir::Message
   Mail::Box::File::Message
   Mail::Box::Net::Message

SYNOPSIS

 # Usually these message objects are created indirectly
 use Mail::Box::Manager;
 my $manager = Mail::Box::Manager->new;
 my $folder  = $manager->open(folder => 'Mail/Drafts');
 my $msg     = $folder->message(1);
 $msg->delete;
 $msg->size;   # and much more

DESCRIPTION

These pages do only describe methods which relate to folders. If you access the knowledge of a message, then read Mail::Message.

During its life, a message will pass through certain stages. These stages were introduced to reduce the access-time to the folder. Changing from stage, the message's body and head objects may change.

METHODS

Constructors

$obj->clone

Mail::Box::Message->coerce(MESSAGE)

    Coerce a message to be included in a folder. The folder itself is not specified, but the type of the message is transformed correctly. The coerced version of the message is returned. When no changes had to be made, the original message is returned.

Mail::Box::Message->new(OPTIONS)

     Option      Defined in       Default                                                       
     body        L<Mail::Message>  undef                                                         
     body_type                    <from folder>                                                 
     deleted                      <false>                                                       
     field_type  L<Mail::Message>  undef                                                         
     folder                       <required>                                                    
     head        L<Mail::Message>  undef                                                         
     head_type   L<Mail::Message>  L<Mail::Message::Head::Complete|Mail::Message::Head::Complete>
     log         L<Mail::Reporter>  C<'WARNINGS'>                                                 
     messageId   L<Mail::Message>  undef                                                         
     modified    L<Mail::Message>  <false>                                                       
     size                         undef                                                         
     trace       L<Mail::Reporter>  C<'WARNINGS'>                                                 
     trusted     L<Mail::Message>  <false>                                                       

    . body OBJECT

    . body_type CODE|CLASS

      If the body of a message is used delay-loaded, the message must what type of message to become when it finally gets parsed. The folder which is delaying the load must specify the algorithm to determine that type.

    . deleted BOOLEAN

      Is the file deleted from the start?

    . field_type CLASS

    . folder FOLDER

      The folder where this message appeared in. The argument is an instance of (a sub-class of) a Mail::Box.

    . head OBJECT

    . head_type CLASS

    . log LEVEL

    . messageId STRING

    . modified BOOLEAN

    . size INTEGER

      The size of the message, which includes head and body, but without the message separators which may be used by the folder type.

    . trace LEVEL

    . trusted BOOLEAN

Constructing a message

$obj->bounce([RG-OBJECT|OPTIONS])

Mail::Box::Message->build([MESSAGE|BODY], CONTENT)

Mail::Box::Message->buildFromBody(BODY, [HEAD], HEADERS)

$obj->forward(OPTIONS)

$obj->forwardPostlude

$obj->forwardPrelude

$obj->forwardSubject(STRING)

Mail::Box::Message->read(FILEHANDLE|SCALAR|REF-SCALAR|ARRAY-OF-LINES, OPTIONS)

$obj->rebuild(OPTIONS)

$obj->reply(OPTIONS)

$obj->replyPrelude([STRING|FIELD|ADDRESS])

$obj->replySubject(STRING)

Mail::Box::Message->replySubject(STRING)

The Message

$obj->container

$obj->isDummy

$obj->isPart

$obj->messageId

$obj->print([FILEHANDLE])

$obj->send([MAILER], OPTIONS)

$obj->size

$obj->toplevel

$obj->write([FILEHANDLE])

The header

$obj->bcc

$obj->cc

$obj->date

$obj->destinations

$obj->from

$obj->get(FIELD)

$obj->guessTimestamp

$obj->head([HEAD])

$obj->nrLines

$obj->sender

$obj->subject

$obj->timestamp

$obj->to

The body

$obj->body([BODY])

$obj->decoded(OPTIONS)

$obj->encode(OPTIONS)

$obj->isMultipart

$obj->isNested

$obj->parts(['ALL'|'ACTIVE'|'DELETED'|'RECURSE'|FILTER])

The message

$obj->copyTo(FOLDER)

    Copy the message to the indicated opened FOLDER, without deleting the original. The coerced message (the copy in the desitnation folder) is returned.

    Example:

     my $draft = $mgr->open(folder => 'Draft');
     $message->copyTo($draft);

$obj->folder([FOLDER])

    In with folder did we detect this message/dummy? This is a reference to the folder-object.

$obj->moveTo(FOLDER)

    Move the message from this folder to the FOLDER specified. This will create a copy using clone() first, and flag this original message to be deleted. So until the source folder is closed, two copies of the message stay in memory. The newly created message (part of the destination folder) is returned.

$obj->seqnr([INTEGER])

    Get the number of this message is the current folder. It starts counting from zero. Do not change the number.

Flags

$obj->delete

    Flag the message to be deleted. The real deletion only takes place on a synchronization of the folder. See deleted() as well.

    The time stamp of the moment of deletion is stored as value. When the same message is deleted more than once, the first time stamp will stay.

    Example:

     $message->delete;
     $message->deleted(1);  # exactly the same
     delete $message;

$obj->deleted([BOOLEAN])

    Set the delete flag for this message. Without argument, the method returns the same as isDeleted(), which is prefered. When a true value is given, delete() is called.

    Example:

     $message->deleted(1);          # delete
     $message->delete;              # delete (prefered)
    
     $message->deleted(0);          # undelete
    
     if($message->deleted) {...}    # check
     if($message->isDeleted) {...}  # check (prefered)

$obj->isDeleted

    Returns the moment (as the time function returns) when the message was flagged for deletion, or undef when the message is not deleted.

    Example:

     next if $message->isDeleted;
    
     if(my $when = $message->isDeleted) {
        print scalar localtime $when;
     }

$obj->isModified

$obj->label(LABEL [,VALUE [LABEL, VALUE] ])

$obj->labels

$obj->labelsToStatus

$obj->modified([BOOLEAN])

$obj->statusToLabels

The whole message as text

$obj->file

$obj->lines

$obj->printStructure([FILEHANDLE][, INDENT])

$obj->string

Internals

$obj->diskDelete

    Remove a message from disk. This is not from the folder, but everything else, like parts of the message which are stored externally from the folder.

$obj->isDelayed

$obj->readBody(PARSER, HEAD [, BODYTYPE])

    Read the body of one message. The PARSER gives access to the folder file. The HEAD has been read with readHead(). The optional BODYTYPE supplies the class name of the body to be created, or a code reference to a routine which can produce a body type based on the head (passed as first argument).

    By default, the BODYTYPE will call Mail::Box::determineBodyType() where the message will be added to.

$obj->readFromParser(PARSER, [BODYTYPE])

$obj->readHead(PARSER [,CLASS])

$obj->recursiveRebuildPart(PART, OPTIONS)

$obj->storeBody(BODY)

$obj->takeMessageId([STRING])

Error handling

$obj->AUTOLOAD

$obj->defaultTrace([LEVEL, [LEVEL])

Mail::Box::Message->defaultTrace([LEVEL, [LEVEL])

$obj->errors

$obj->log([LEVEL [,STRINGS]])

Mail::Box::Message->log([LEVEL [,STRINGS]])

$obj->logPriority(LEVEL)

Mail::Box::Message->logPriority(LEVEL)

$obj->logSettings

$obj->notImplemented

$obj->report([LEVEL])

$obj->reportAll([LEVEL])

$obj->shortString

    Convert the message header to a short string, representing the most important facts (for debugging purposes only).

$obj->trace([LEVEL])

$obj->warnings

Cleanup

$obj->DESTROY

$obj->inGlobalDestruction

DIAGNOSTICS

Error: Cannot include forward source as $include.

Unknown alternative for the forward(include). Valid choices are NO, INLINE, and ATTACH.

Error: Cannot include reply source as $include.

Unknown alternative for the include option of reply(). Valid choices are NO, INLINE, and ATTACH.

Error: No address to create forwarded to.

If a forward message is created, a destination address must be specified.

Error: No default mailer found to send message.

The message send() mechanism had not enough information to automatically find a mail transfer agent to sent this message. Specify a mailer explicitly using the via options.

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.

Error: no rebuild rule $name defined.

DETAILS

REFERENCES

See the Mail::Box website at http://perl.overmeer.net/mailbox/ for more details.

COPYRIGHTS

Module version 2.042. 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.