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::Tie::HASH - Acces an existing message-folder as a hash

SYNOPSIS

   tie my(%inbox), 'Mail::Box::Tie', $folder;

   foreach my $msgid (keys %inbox)
   {   print $inbox{$msgid};
       delete $inbox{$msgid};
   }

   $inbox{$msg->messageID} = $msg;
   

DESCRIPTION

Read Mail::Box::Manager first.

Certainly when you look at a folder as being a set of related messages, based on message-id, folder-access through a hash is a logical step.

For a tied-hash, the message-id is used as key. The message-id is usually unique, but when two or more instances of the same message are in the same folder, one will be flagged for deletion and the other will show.

This implementation uses basic folder-access routines which are related to the message-id.

METHODS

#-------------------------------------------

TIEHASH FOLDERTYPE, INIT-PARAMETERS
TIEHASH 'Mail::Box::Tie', FOLDER

Connects the object to a hash.

Examples:

    my $mgr    = Mail::Box::Manager->new;
    my $folder = $mgr->open(access => 'rw');
    tie my(%inbox), 'Mail::Box::Tie', $folder;
FETCH MESSAGEID

Get the message with the specified id. The returned message may be a dummy, when message-thread detection is used. Returns undef when no message with the specified id is known.

Examples:

    my $msg = $inbox{$msgid};
    if($inbox{$msgid}->isDummy)  ...
STORE MESSAGEID, MESSAGE

Store a message in the hash, on the specified id. The message-id must be equivalent the message-id as contained in the message.

If the message does not have a message-id assigned yet, it will get the specified one. When message-id is undef, the key will be taken from the message.

Examples:

    $inbox{$msg->messageID} = $msg;
    $inbox{undef} = $msg;
FIRSTKEY
NEXTKEY

Returns the first respecitively sequential pair of message-id/message from the folder. The messages will be returned in the order as stored in the folder. Messages flagged for deletion WILL be taken.

Examples:

    foreach my $msgid (keys %inbox) ...
    foreach my $msg (values %inbox) ...

    while(my ($msgid, $msg) = each %inbox) {
        $msg->print unless $msg->deleted;
    }
EXISTS MESSAGE-ID

Check whether a message with a certain MESSAGE-ID exists.

Example:

    if(exists $inbox{$msgid}) ...
DELETE MESSAGE-ID

Remove the message with the specified MESSAGE-ID.

Example:

    delete $inbox{$msgid};
CLEAR

Remove the contents of the hash. Not really possible, but all the messages will be set to be deleted.

Example:

   %inbox = ();
   %inbox = ($msg->messageID, $msg); #before adding msg

AUTHOR

Mark Overmeer (Mark@Overmeer.net). All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

VERSION

This code is beta, version 1.321

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 43:

'=item' outside of any '=over'

Around line 209:

You forgot a '=back' before '=head1'