NAME

Mail::Cache - Caches mail info.

VERSION

Version 0.1.2

SYNOPSIS

use Mail::Cache;

my $mc = Mail::Cache->new();

#init for the module 'ZConf::Mail' for a IMAP account named 'foo@bar' for the box 'INBOX'
$mc->init('ZConf::Mail', 'imap', 'foo@bar', 'INBOX');

#populate a cache from a Mail::IMAPTalk object
$imap->select('INBOX');
my $sorted=$imap->sort('(subject)', 'UTF8', 'NOT', 'DELETED');
my $int=0;
while(defined($sorted->[$int])){
    my $headers=$imap->fetch($sorted->[$int], 'rfc822.header');
    my $size=$imap->fetch($sorted->[$int], 'rfc822.size');
    $mc->setUID($sorted->[$int], $headers->{$sorted->[$int]}{'rfc822.header'},
                $size->{$sorted->[$int]}{'rfc822.size'});
    if($mc->{error}){
        print "Error!\n";
    }
    $int++;
}

METHODS

new

getAccount

This sets the account that is currently being worked with.

my $account=$mc->getAccount;

getBox

This gets the current mail box being used.

my $box=$mc->getBox;

getCache

This gets the name of the current cache.

my $cache=$mc->getCache;

getDates

This fetches a parsed hash of the dates.

The returned hash has the UIDs as the keys and the value for each hash entry is the the date from the header.

my %dates=$mc->getDates;
if($mc->{error}){
    print "Error!\n";
}

getSizes

This fetches a parsed hash of the subjects.

The returned hash has the UIDs as the keys and the value for each hash entry is the the subject.

my %subjects=$mc->getSizes;
if($mc->{error}){
    print "Error!\n";
}

getFroms

This fetches a parsed hash of the froms.

The returned hash has the UIDs as the keys and the value for each hash entry is the the froms.

my %sizes=$mc->getSizes;
if($mc->{error}){
    print "Error!\n";
}

getSubjects

This fetches a parsed hash of the sizes.

The returned hash has the UIDs as the keys and the value for each hash entry is the the size.

my %sizes=$mc->getSizes;
if($mc->{error}){
    print "Error!\n";
}

getType

This gets the current type.

my $type=$mc->getType;

init

A short cut to calling the three different set methods.

$mc->init($cache, $type, $account, $box);
if($mc->{error}){
    print "Error!\n";
}

listUIDs

This gets a list of UIDs.

my @uids=$mc->listUIDs;
if($mc->{error}){
    print "Error!\n";
}

removeUIDs

This removes a array of specified UIDs. This is used for cleaning it up. See Mail::IMAPTalk::MailCache for a example of how to use this.

$mc->removeUIDs(\@uids);

setAccount

This sets the account that is currently being worked on. The default is 'default'.

A value of '' or undef will set it back to the default.

setBox

This sets the current box in use.

A value of '' or undef will set it back to the default, 'INBOX'.

setCache

This sets the name cache.

A value of '' or undef will set it back to the default, 'Mail::Cache'.

#set the cache name to ZConf::Mail
$mc->setCache('ZConf::Mail');
if($mc->{error}){
    print "Error!\n";
}

setType

This sets what source of what is being cached. The default is 'imap'.

Regardless of what it is set to, it will be converted to lower case.

A value of '' or undef will set it back to the default.

$mc->setType('imap');
if($mc->{error}){
    print "Error!\n";
}

setUID

This sets the cache for a message. If it does not already exist, it will be added. If it does exist, it will be overwritten.

$mc->setUID($uid, $headers, $size);
if($mc->{error}){
    print "Error!\n";
}

errorblank

A internal functions that blanks any previous error.

CACHE LAYOUT

The cache exists under "xdg_cache_home.'/Mail::Cache/'". So the default location would be "~/.cache/Mail::Cache/".

Under the cache home directory is the directories representing various caches. If none is specified it is 'Mail::Cache'. This would make the directory, "xdg_cache_home.'/Mail::Cache/Mail::Cache/'".

Under the cache directory is the type directory. The type should also always be lower case. Any upper case characters will be converted to lowercase. The default is 'imap', making the directory "xdg_cache_home.'/Mail::Cache/Mail::Cache/imap/'".

Under the account directory is the type directory. The default is 'default', making the directory "xdg_cache_home.'/Mail::Cache/Mail::Cache/imap/default/'".

Under the box directory is the account directory. The default is 'INBOX', making the directory "xdg_cache_home.'/Mail::Cache/Mail::Cache/imap/default/INBOX/'".

ERROR CODES

The error codes are stored in '$mc->{error}'. Any time it is true, an error is present. When no error is present, it is undefined.

A description of the error can be found in '$mc->{errorString}'.

1

Could not create xdg_cache_home.

2

Could not create xdg_cache_home.'/Mail::Cache/'.

3

Cache name contains a '/'.

4

Failed to create xdg_cache_home.'/'.$cache.'/'.

5

Type contains a '/'.

6

Account contains a '/'.

7

Failed to create create xdg_cache_home.'/'.$cache.'/'.$account.'/'.

8

No UID specified.

9

UID matches /^\./.

10

No headers given.

11

Size is not specified.

12

UID matches /\|/.

13

Box name matches /\//.

14

Failed to create create xdg_cache_home.'/'.$cache.'/'.$account.'/'.$box.'/'.

15

"xdg_cache_home.'/'.$cache.'/'.$account.'/'.$box.'/'" does not exist.

16

"xdg_cache_home.'/'.$cache.'/'.$account.'/'.$box.'/.Size'" does not exist.

17

The passed value for the headers was something other than a reference or a hash.

AUTHOR

Zane C. Bowers, <vvelox at vvelox.net>

BUGS

Please report any bugs or feature requests to bug-mail-cache at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Mail-Cache. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Mail::Cache

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2009 Zane C. Bowers, all rights reserved.

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