Mail::Box::IMAP4::Message(3pm)

NAME
Mail::Box::IMAP4::Message - one message on a IMAP4 server

INHERITANCE
 Mail::Box::IMAP4::Message
   is a Mail::Box::Net::Message
   is a Mail::Box::Message
   is a Mail::Message
   is a Mail::Reporter

SYNOPSIS
  my $folder = new Mail::Box::IMAP4 ...
  my $message = $folder->message(10);

DESCRIPTION
A "Mail::Box::IMAP4::Message" represents one message on a IMAP4 server, maintained by a Mail::Box::IMAP4 folder. Each message is stored as separate entity on the server, and maybe temporarily in your program as well.

Extends "DESCRIPTION" in Mail::Box::Net::Message.

METHODS
Extends "METHODS" in Mail::Box::Net::Message.

  Constructors
Extends "Constructors" in Mail::Box::Net::Message.

$obj->clone(%options)
    Inherited, see "Constructors" in Mail::Message

$class->new(%options)
    Inherited, see "Constructors" in Mail::Reporter

     -Option      --Defined in             --Default
      body          Mail::Message            undef
      body_type     Mail::Box::Message       Mail::Message::Body::Lines
      cache_body                             false
      cache_head                             false
      cache_labels                           false
      deleted       Mail::Message            false
      field_type    Mail::Message            undef
      folder        Mail::Box::Message       <required>
      head          Mail::Message            undef
      head_type     Mail::Message            Mail::Message::Head::Complete
      labels        Mail::Message            +{}
      messageId     Mail::Message            undef
      modified      Mail::Message            false
      size          Mail::Box::Message       undef
      trusted       Mail::Message            false
      unique        Mail::Box::Net::Message  <unique string>
      write_labels                           true

    body => $object
    body_type => CODE|$class
    cache_body => BOOLEAN
    cache_head => BOOLEAN
    cache_labels => BOOLEAN
        All standard IMAP labels can be cached on the local server to improve speed. This has the same dangers as setting "write_labels" to "false". The caching starts when the first label of the message was read.

    deleted => BOOLEAN
    field_type => $class
    folder => $folder
    head => $object
    head_type => $class
    labels => \@pairs|\%settings
    messageId => $id
    modified => BOOLEAN
    size => $bytes
    trusted => BOOLEAN
    unique => STRING
    write_labels => BOOLEAN
        When a label is changed or its value read, using label(), that info should be sent to the IMAP server. But, this action could be superfluous, for instance because the label was already set or clear, and communication is expensive. On the other hand, someone else may use IMAP to make changes in the same folder, and will get the updates too late or never...

  Attributes
Extends "Attributes" in Mail::Box::Net::Message.

$obj->folder( [$folder] )
    Inherited, see "Attributes" in Mail::Box::Message

$obj->seqnr( [$integer] )
    Inherited, see "Attributes" in Mail::Box::Message

$obj->unique( [STRING|undef] )
    Inherited, see "Attributes" in Mail::Box::Net::Message

  Constructing a message
Extends "Constructing a message" in Mail::Box::Net::Message.

$obj->bounce( [<$rg_object|%options>] )
    Inherited, see "Constructing a message" in Mail::Message::Construct::Bounce

$class->build( [$message|$part|$body], @fields, %options )
    Inherited, see "Constructing a message" in Mail::Message::Construct::Build

$class->buildFromBody($body, [$head], $headers)
    Inherited, see "Constructing a message" in Mail::Message::Construct::Build

$obj->forward(%options)
    Inherited, see "Constructing a message" in Mail::Message::Construct::Forward

$obj->forwardAttach(%options)
    Inherited, see "Constructing a message" in Mail::Message::Construct::Forward

$obj->forwardEncapsulate(%options)
    Inherited, see "Constructing a message" in Mail::Message::Construct::Forward

$obj->forwardInline(%options)
    Inherited, see "Constructing a message" in Mail::Message::Construct::Forward

$obj->forwardNo(%options)
    Inherited, see "Constructing a message" in Mail::Message::Construct::Forward

$obj->forwardPostlude()
    Inherited, see "Constructing a message" in Mail::Message::Construct::Forward

$obj->forwardPrelude()
    Inherited, see "Constructing a message" in Mail::Message::Construct::Forward

$obj->forwardSubject(STRING)
    Inherited, see "Constructing a message" in Mail::Message::Construct::Forward

$class->read($fh|$text|\$text|\@lines, %options)
    Inherited, see "Constructing a message" in Mail::Message::Construct::Read

$obj->rebuild(%options)
    Inherited, see "Constructing a message" in Mail::Message::Construct::Rebuild

$obj->reply(%options)
    Inherited, see "Constructing a message" in Mail::Message::Construct::Reply

$obj->replyPrelude( [STRING|$field|$address|\@addrs|\@fields] )
    Inherited, see "Constructing a message" in Mail::Message::Construct::Reply

$any->replySubject(STRING)
    Inherited, see "Constructing a message" in Mail::Message::Construct::Reply

  The message
Extends "The message" in Mail::Box::Net::Message.

$obj->container()
    Inherited, see "The message" in Mail::Message

$obj->copyTo($folder, %options)
    Inherited, see "The message" in Mail::Box::Message

$obj->endsOnNewline()
    Inherited, see "The message" in Mail::Message

$obj->isDummy()
    Inherited, see "The message" in Mail::Message

$obj->isPart()
    Inherited, see "The message" in Mail::Message

$obj->messageId()
    Inherited, see "The message" in Mail::Message

$obj->moveTo($folder, %options)
    Inherited, see "The message" in Mail::Box::Message

$obj->partNumber()
    Inherited, see "The message" in Mail::Message

$obj->print( [$fh] )
    Inherited, see "The message" in Mail::Message

$obj->send( [$mailer], %options )
    Inherited, see "The message" in Mail::Message

$obj->size()
    Returns the size of this message. If the message is still on the remote server, IMAP is used to ask for the size. When the message is already loaded onto the local system, the size of the parsed message is taken. These sizes can differ because the difference in line-ending representation. Improves base, see "The message" in Mail::Message

$obj->toplevel()
    Inherited, see "The message" in Mail::Message

$obj->write( [$fh] )
    Inherited, see "The message" in Mail::Message

  The header
Extends "The header" in Mail::Box::Net::Message.

$obj->bcc()
    Inherited, see "The header" in Mail::Message

$obj->cc()
    Inherited, see "The header" in Mail::Message

$obj->date()
    Inherited, see "The header" in Mail::Message

$obj->destinations()
    Inherited, see "The header" in Mail::Message

$obj->from()
    Inherited, see "The header" in Mail::Message

$obj->get($fieldname)
    Inherited, see "The header" in Mail::Message

$obj->guessTimestamp()
    Inherited, see "The header" in Mail::Message

$obj->head( [$head] )
    Inherited, see "The header" in Mail::Message

$obj->nrLines()
    Inherited, see "The header" in Mail::Message

$obj->sender()
    Inherited, see "The header" in Mail::Message

$obj->study($fieldname)
    Inherited, see "The header" in Mail::Message

$obj->subject()
    Inherited, see "The header" in Mail::Message

$obj->timestamp()
    Inherited, see "The header" in Mail::Message

$obj->to()
    Inherited, see "The header" in Mail::Message

  The body
Extends "The body" in Mail::Box::Net::Message.

$obj->body( [$body] )
    Inherited, see "The body" in Mail::Message

$obj->contentType()
    Inherited, see "The body" in Mail::Message

$obj->decoded(%options)
    Inherited, see "The body" in Mail::Message

$obj->encode(%options)
    Inherited, see "The body" in Mail::Message

$obj->isMultipart()
    Inherited, see "The body" in Mail::Message

$obj->isNested()
    Inherited, see "The body" in Mail::Message

$obj->parts( [<'ALL'|'ACTIVE'|'DELETED'|'RECURSE'|$filter>] )
    Inherited, see "The body" in Mail::Message

  Flags
Extends "Flags" in Mail::Box::Net::Message.

$obj->delete()
    Inherited, see "Flags" in Mail::Message

$obj->deleted( [BOOLEAN] )
    Inherited, see "Flags" in Mail::Message

$obj->isDeleted()
    Inherited, see "Flags" in Mail::Message

$obj->isModified()
    Inherited, see "Flags" in Mail::Message

$obj->label($label|PAIRS)
    With only one argument, the value related to $label is returned. With more that one argument, the list is interpreted a label-value "PAIRS" to be set.

    The IMAP protocol defines its own names for the labels, which must be set immediately to inform other IMAP clients which may have the same folder open. But that can be changed with new(write_labels). Some labels are translated to the corresponding IMAP system labels. Improves base, see "Flags" in Mail::Message

$obj->labels()
    Get the names of all labels (LIST context, not efficient in IMAP4), or a reference to a hash with labels. You should only use the returned hash to read the labels, because changes made to it will not be passed to the remote server. See labels() to set values. Improves base, see "Flags" in Mail::Message

$obj->labelsToStatus()
    Inherited, see "Flags" in Mail::Message

$obj->modified( [BOOLEAN] )
    Inherited, see "Flags" in Mail::Message

$obj->statusToLabels()
    Inherited, see "Flags" in Mail::Message

  The whole message as text
Extends "The whole message as text" in Mail::Box::Net::Message.

$obj->file()
    Inherited, see "The whole message as text" in Mail::Message::Construct::Text

$obj->lines()
    Inherited, see "The whole message as text" in Mail::Message::Construct::Text

$obj->printStructure( [$fh|undef],[$indent] )
    Inherited, see "The whole message as text" in Mail::Message::Construct::Text

$obj->string()
    Inherited, see "The whole message as text" in Mail::Message::Construct::Text

  Internals
Extends "Internals" in Mail::Box::Net::Message.

$obj->clonedFrom()
    Inherited, see "Internals" in Mail::Message

$class->coerce($message, %options)
    Inherited, see "Internals" in Mail::Message

$obj->diskDelete()
    Inherited, see "Internals" in Mail::Box::Message

$obj->fetch( [$info, ...] )
    Use the IMAP's "UID FETCH IMAP" command to get some data about this message. The $info request is passed to Mail::Box::IMAP4::fetch(). Without $info, "ALL" information is retrieved and returned as a HASH.

$obj->isDelayed()
    Inherited, see "Internals" in Mail::Message

$obj->loadBody()
    Inherited, see "Internals" in Mail::Box::Net::Message

$obj->readBody( $parser, $head, [$bodytype] )
    Inherited, see "Internals" in Mail::Box::Message

$obj->readFromParser( $parser, [$bodytype] )
    Inherited, see "Internals" in Mail::Message

$obj->readHead( $parser, [$class] )
    Inherited, see "Internals" in Mail::Message

$obj->recursiveRebuildPart($part, %options)
    Inherited, see "Internals" in Mail::Message::Construct::Rebuild

$obj->storeBody($body)
    Inherited, see "Internals" in Mail::Message

$obj->takeMessageId( [STRING] )
    Inherited, see "Internals" in Mail::Message

$obj->writeDelayed($imap)
    Write all delayed information, like label changes, to the server. This is done under force, so should even be done for folders opened without write-access. This method is called indirectly by a Mail::Box::write() or Mail::Box::close().

    The $imap argument is a Mail::IMAPClient which has the right folder already selected.

    Writing changes to the remote folder is not without hassle: IMAP4 (or is it only Mail::IMAPClient doesn't support replacing header or body. Therefore, when either of them change, the whole message is rewritten to the server (which is supported), and the original flagged for deletion.

  Error handling
Extends "Error handling" in Mail::Box::Net::Message.

$obj->AUTOLOAD()
    Inherited, see "METHODS" in Mail::Message::Construct

$obj->notImplemented()
    Inherited, see "Error handling" in Mail::Reporter

$any->shortSize( [$value] )
    Inherited, see "Error handling" in Mail::Message

$obj->shortString()
    Inherited, see "Error handling" in Mail::Message

  Cleanup
Extends "Cleanup" in Mail::Box::Net::Message.

$obj->DESTROY()
    Inherited, see "Cleanup" in Mail::Reporter

$obj->destruct()
    Inherited, see "Cleanup" in Mail::Box::Message

DETAILS
Extends "DETAILS" in Mail::Box::Net::Message.

  Structure of a Message
Extends "Structure of a Message" in Mail::Box::Net::Message.

  Message object implementation
Extends "Message object implementation" in Mail::Box::Net::Message.

  Message class implementation
Extends "Message class implementation" in Mail::Box::Net::Message.

  Labels
Extends "Labels" in Mail::Box::Net::Message.

Predefined labels

Extends "Predefined labels" in Mail::Box::Net::Message.

Status and X-Status fields

Extends "Status and X-Status fields" in Mail::Box::Net::Message.

IMAP protocol flags

Labels (or flags) are known to all folder formats, but differ how they are stored. Some folder types use message header lines to keep the labels, other use a separate file. The IMAP protocol does not specify how the labels are kept on the server, but does specify how they are named.

The label names as defined by the IMAP protocol are standardized into the MailBox standard to hide folder differences. The following translations are always performed:

  \Seen     => seen
  \Answered => replied
  \Flagged  => flagged
  \Deleted  => deleted
  \Draft    => draft
  \Recent   => NOT old

» Example: of label translations

  $imap->message(3)->label(replied => 1, draft => 0);

will result in a IMAP protocol statements like

  A003 STORE 4 +FLAGS (\Answered)
  A003 STORE 4 -FLAGS (\Draft)

Other labels

Of course, your program may be in need for more labels than those provided by the protocol. You can still use these: they stay locally (and are lost when the folder is closed). Some IMAP4 extensions permit more labels than the basic RFC, but that is not yet supported by this implementation.

Caching labels

When you ask for one or more flags of a message more than once, you may improve the overall performance by setting new(cache_labels) to "YES". However, this may cause inconsistencies when multiple clients use the same folder on the IMAP server.

You may also delay the label updates to the server until the folder is closed (or for ever when read-only is required). When Mail::Box::write() or Mail::Box::close() is called, it is decided whether to throw all changes away or write after all.

DIAGNOSTICS

Error: Cannot include forward source as $kind.
    Unknown alternative for the forward(include). Valid choices are "NO", "INLINE", "ATTACH", and "ENCAPSULATE". Cast by forward()

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. Cast by send()

Error: cannot coerce a $type object into a $me object.
    Cast by coerce()

Error: cannot include reply source as $kind.
    Unknown alternative for the "include" option of reply(). Valid choices are "NO", "INLINE", and "ATTACH". Cast by reply()

Error: cannot read message from a $source}.
    Cast by read()

Error: class $package does not implement method $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. Cast by notImplemented()

Error: coercion starts with some object, not '$type'.
    Cast by coerce()

Error: method bounce requires To, Cc, or Bcc.
    The message bounce() method forwards a received message off to someone else without modification; you must specified it's new destination. If you have the urge not to specify any destination, you probably are looking for reply(). When you wish to modify the content, use forward(). Cast by bounce()

Error: method forwardAttach requires a preamble.
    Cast by forwardAttach()

Error: method forwardEncapsulate requires a preamble.
    Cast by forwardEncapsulate()

Error: method forwardNo requires a To.
    Cast by forwardNo()

Error: method forwardNo requires a body.
    Cast by forwardNo()

Error: no rebuild rule $name defined.
    Cast by rebuild()

Error: only build() Mail::Message's; they are not in a folder yet.
    You may wish to construct a message to be stored in a some kind of folder, but you need to do that in two steps. First, create a normal Mail::Message, and then add it to the folder. During this Mail::Box::addMessage() process, the message will get coerce()-d into the right message type, adding storage information and the like. Cast by build()

Error: please install Email::Simple.
    Cast by coerce()

Error: please install MIME::Entity.
    Cast by coerce()

Error: please install Mail::Internet.
    Cast by coerce()

Error: select parts via '$what'?
    Cast by parts()

Warning: skipped unknown key '$key' in build.
    Cast by build()

Error: unable to read delayed body for $msgid.
    Cast by loadBody()

Error: unable to read delayed head for $msgid.
    Cast by loadBody()

SEE ALSO
This module is part of Mail-Box-IMAP4 version 4.01, built on December 13, 2025. Website: http://perl.overmeer.net/CPAN/

LICENSE
For contributors see file ChangeLog.

This software is copyright (c) 2001-2025 by Mark Overmeer.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.