/*
* open the one true mail lock file
*/
Mblock*
mblock(void)
{
if(mblck.fd >= 0)
bye("mail lock deadlock");
mblck.fd = openlocked(mboxdir, "L.mbox", OREAD);
if(mblck.fd >= 0)
return &mblck;
ilog("mblock: %r");
return nil;
}
void
mbunlock(Mblock *ml)
{
if(ml != &mblck)
bye("bad mail unlock");
if(ml->fd < 0)
bye("mail unlock when not locked");
close(ml->fd);
ml->fd = -1;
}
void
mblockrefresh(Mblock *ml)
{
char buf[1];
seek(ml->fd, 0, 0);
read(ml->fd, buf, 1);
}
int
mblocked(void)
{
return mblck.fd >= 0;
}
char*
impname(char *name)
{
char *s, buf[Pathlen];
int n;
encfs(buf, sizeof buf, name);
n = strlen(buf) + STRLEN(".imp") + 1;
s = binalloc(&parsebin, n, 0);
if(s == nil)
return nil;
snprint(s, n, "%s.imp", name);
return s;
}
/*
* massage the mailbox name into something valid
* eliminates all .', and ..',s, redundatant and trailing /'s.
*/
char *
mboxname(char *s)
{
char *ss, *p;