1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
=head1 NAME
Mail::Box::Tie::HASH - access an existing message folder as a hash
=head1 SYNOPSIS
tie my(%inbox), 'Mail::Box::Tie::HASH', $folder;
foreach my $msgid (keys %inbox)
{ print $inbox{$msgid};
delete $inbox{$msgid};
}
$inbox{$msg->messageId} = $msg;
=head1 DESCRIPTION
Certainly when you look at a folder as being a set of related messages
based on message-id, it is logical to access the folder through a hash.
For a tied hash, the message-id is used as the 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 be returned.
This implementation uses basic folder access routines which are related
to the message-id.
=head1 METHODS
=head2 Constructors
B<TIEHASH>('Mail::Box::Tie::HASH', FOLDER)
=over 4
Connects the FOLDER object to a HASH.
I<Example:>
my $mgr = Mail::Box::Manager->new;
my $folder = $mgr->open(access => 'rw');
tie my(%inbox), 'Mail::Box::Tie::HASH', $folder;
=back
=head2 Tied Interface
$obj-E<gt>B<CLEAR>
=over 4
Remove the contents of the hash. This is not really possible, but all
the messages will be flagged for deletion.
I<Example:>
%inbox = ();
%inbox = ($msg->messageId, $msg); #before adding msg
=back
$obj-E<gt>B<DELETE>(MESSAGE-ID)
=over 4
Remove the message with the specified MESSAGE-ID.
I<Example:>
delete $inbox{$msgid};
=back
$obj-E<gt>B<EXISTS>(MESSAGE-ID)
=over 4
Check whether a message with a certain MESSAGE-ID exists.
I<Example:>
if(exists $inbox{$msgid}) ...
=back
$obj-E<gt>B<FETCH>(MESSAGEID)
=over 4
Get the message with the specified id. The returned message may be
a dummy if message thread detection is used. Returns C<undef> when
there is no message with the specified id.
I<Example:>
my $msg = $inbox{$msgid};
if($inbox{$msgid}->isDummy) ...
=back
$obj-E<gt>B<FIRSTKEY>
=over 4
See L<NEXTKEY()|Mail::Box::Tie::HASH/"Tied Interface">.
=back
$obj-E<gt>B<NEXTKEY>(PREVIOUS)
=over 4
L<FIRSTKEY()|Mail::Box::Tie::HASH/"Tied Interface"> returns the first message-id/message pair from the folder,
and NEXTKEY returns the message-id/message pair for the next message,
in the order in which the message is stored in the folder.
Messages flagged for deletion will B<not> be returned. See the
L<Mail::Box::messages()|Mail::Box/"The messages"> method of the folder type for more information
about the folder message order.
I<Example:>
foreach my $msgid (keys %inbox) ...
foreach my $msg (values %inbox) ...
while(my ($msgid, $msg) = each %inbox) {
$msg->print unless $msg->isDeleted;
}
=back
$obj-E<gt>B<STORE>(undef, MESSAGE)
=over 4
Store a message in the folder. The key must be C<undef>, because the
message-id of the specified message is taken. This is shown in the
first example. However, as you see, it is a bit complicated to specify
C<undef>, therefore the string C<"undef"> is accepted as well.
The message may be converted into something which can be stored in the
folder type which is at stake. The added instance is returned.
I<Example:>
$inbox{ (undef) } = $msg;
$inbox{undef} = $msg;
=back
=head1 REFERENCES
See the MailBox website at L<http://perl.overmeer.net/mailbox/> for more details.
=head1 COPYRIGHTS
Distribution version 2.068.
Written by Mark Overmeer (mark@overmeer.net). See the ChangeLog for
other contributors.
Copyright (c) 2001-2006 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.
|