Mail::...:Locker(3pm)
π Mail::Box::Locker β manage the locking of mail folders π
okay bestie, welcome to Mail::Box::Locker, aka the little bodyguard that keeps other programs from messing with your mail folders while you're in them. it's part of the Mail::...:Locker manual page family, and honestly? it's giving security π
πΈ INHERITANCE πΈ
here's the family tree, no cap:
Mail::Box::Locker
is a Mail::Reporter
Mail::Box::Locker is extended by
Mail::Box::Locker::DotLock
Mail::Box::Locker::FcntlLock
Mail::Box::Locker::Flock
Mail::Box::Locker::Multi
Mail::Box::Locker::Mutt
Mail::Box::Locker::NFS
Mail::Box::Locker::POSIX
so it's a Mail::Reporter at heart, and it has so many little siblings who each specialize in a different locking vibe π¦
β¨ SYNOPSIS β¨
here's the tea, literally:
use Mail::Box::Locker;
my $locker = new Mail::Box::Locker(folder => $folder);
$locker->lock;
$locker->isLocked;
$locker->hasLock;
$locker->unlock;
use Mail::Box;
my $folder = Mail::Box->new(lock_method => 'DOTLOCK');
print $folder->locker->type;
that's it. that's the whole main character arc. π
π DESCRIPTION π
every single Mail::Box makes its own Mail::Box::Locker object, and that object handles the locking for it. periodt. you can grab the object directly from the folder, just like in the examples below. it's lowkey the folder's emotional support lock. π«Ά
it extends "DESCRIPTION" in Mail::Reporter β go read that too if you want the full lore.
π METHODS π
extends "METHODS" in Mail::Reporter.
π Constructors
extends "Constructors" in Mail::Reporter.
$class->new(%options)
makes you a brand new lock. you can do this directly, sure. but honestly? in most cases the lock won't be instantiated all on its own β it'll be the second class in a multiple inheritance construction with a Mail::Box. iykyk.
generally your client program specifies the locking behavior through options given to the folder class. improves base, see "Constructors" in Mail::Reporter.
here's the defaults table, verbatim, don't @ me:
-Option --Default
expires 1 hour
file undef
folder <C<undef>>
method 'DOTLOCK'
timeout 10
expires => $secondsβ how long can a lock even exist, bestie? if some other e-mail program leaves a stale lock behind, this lock gets removed automatically after the specified number of seconds. absolute janitor behavior. π§Ήfile => $fileβ the name of the$fileto lock. by default, the name of the folder is taken. defaulting is iconic honestly.folder => $folderβ which$folderis to be locked. it's aMail::Boxobject.method => $name|CLASS|\@namesβ which kind of locking, specified as one of the following tokens as$name. you may also specify aCLASSname, or multiple@names. in the latter case, a'multi'locker is started with all the specified@names. not me giving you options on options. π
supported locking method names are (lower-case is also accepted):
'DOTLOCK'β the folder handler creates a file which signals that it is in use. this one's a bit problematic ngl, because not all mail-handling software agree on the name of the file to be created. π
on various folder types, the lockfile differs. see the documentation for each folder, which describes the locking strategy as well as special options to change the default behavior.
'FLOCK'β for some folder handlers, locking is based on a file locking mechanism provided by the operating system. however, this does not work on all systems, such as network filesystems, and such. this also doesn't work on folders based on directories (Mail::Box::Dirand derived). big yikes for those setups. π'FCNTLLOCK'β POSIX locking viaFile::FcntlLock, which works on more platforms. however, that module requires a C compiler to install. so it slays but it needs a whole compiler to do it. π'POSIX'β use the POSIX standardfcntllocking.'MULTI'β use ALL available locking methods at the same time, to have a bigger chance that the folder will not be modified by some other application which uses an unspecified locking method. when one of the locking methods disallows access, the locking fails. it's wearing every belt and every pair of suspenders. π'MUTT'β use the external program'mutt_dotlock'to lock and unlock.'NFS'β a kind of"dotlock"file-locking mechanism, but adapted to work over NFS. extra precaution is needed because an"open O_EXCL"on NFS is not an atomic action. underlined, bolded, screaming. π₯'NONE'β do not use locking. (chaotic. free-spirited. slightly terrifying.)
the other option is to produce your own "Mail::Box::Locker" derived class, which implements the desired locking method. (please consider offering it for inclusion in the public Mail::Box module!) create an instance of that class with this parameter. yes bestie, build your own, we believe in you:
my $locker = Mail::Box::Locker::MyOwn->new;
$folder->open(locker => $locker);
timeout => $seconds|'NOTIMEOUT'β how long to wait while trying to acquire the lock. the lock request will fail when the specified number of$secondsis reached. if'NOTIMEOUT'is specified, the module will wait until the lock can be taken. literally forever. commitment. β
whether it is possible to limit the wait time is platform- and locking-method-specific. for instance, the dotlock method on Windows will always wait until the lock has been received. no timeout for you, Windows bestie. π
πΈ Attributes
extends "Attributes" in Mail::Reporter.
$obj->expires( [SECONDS] )β get/set the expiration time. not available for all lockers. (some lockers are mysterious like that.)$obj->filename( [$filename] )β returns the filename which is used to lock the folder, optionally after setting it to the specified$filename.
Β» example:
print $locker->filename;
$obj->folder( [$folder] )β returns the folder object which is locker.$obj->name()β returns the method used to lock the folder. see thenew(method)for details on how to specify the lock method. the name of the method is returned in upper-case. SHOUTING. π£
Β» example:
if($locker->name eq 'FLOCK') ...
$obj->timeout( [SECONDS] )β get/set the timeout. not available for all lockers.
π Locking
$obj->hasLock()β check whether the folder has the lock.
Β» example:
if($locker->hasLock) {...}
if($folder->locker->hasLock) {...}
$obj->isLocked()β test if the folder is locked by this or a different application. (different application?? someone else?? the audacity. π)
Β» example:
if($locker->isLocked) {...}
if($folder->locker->isLocked) {...}
$obj->lock($folder)β get a lock on a folder. this will return"false"if the lock fails.
Β» example:
$locker->lock or die;
if($folder->locker->lock) {...}
$obj->unlock()β undo the lock on a folder.
Β» example:
$locker->unlock;
$folder->locker->unlock;
π Error handling
extends "Error handling" in Mail::Reporter.
$obj->AUTOLOAD()β inherited, see"Error handling"in Mail::Reporter$obj->notImplemented()β inherited, see"Error handling"in Mail::Reporter
π§Ή Cleanup
extends "Cleanup" in Mail::Reporter.
$obj->DESTROY()β when the locker is destroyed, for instance when the folder is closed or the program ends, the lock will be automatically removed. improves base, see"Cleanup"in Mail::Reporter. it cleans up after itself, which is more than most people do. π
π DIAGNOSTICS π
- 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 bynotImplemented() - Error: failed to use locking module $class: $@ β cast by
new() - Error: no locking method $name defined: use @avail β cast by
new()
π SEE ALSO π
this module is part of Mail-Box version 4.02, built on April 10, 2026.
Website: http://perl.overmeer.net/CPAN/
π LICENSE π
for contributors see file ChangeLog.
this software is copyright (c) 2001-2026 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.
and that's the whole page bestie π«Ά tysm for reading, mwah π this was Mail::...:Locker(3pm), and the footer energy β perl v5.40.1, dated 2026-05-09 β is so giving iconic. slay, stay locked (respectfully), periodt. β¨π
π¦ where this page comes from
- ubuntu stonking: libmail-box-perl 4.02-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms