aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/upas/nfs/mbox.c
blob: 1b60ffa6162f0f9d80131c61bbc66fa0b87b0922 (plain)
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
#include "a.h"

Mailbox *hash[123];
Mailbox **box;
uint nbox;

static void
markboxes(int mark)
{
	Mailbox *b;

	for(i=0; i<nbox; i++)
		if(box[i])
			box[i]->mark = mark;
}

static void
sweepboxes(void)
{
	Mailbox *b;

	for(i=0; i<nbox; i++)
		if(box[i] && box[i]->mark){
			freembox(box[i]);
			box[i] = nil;
		}
}

static Mailbox*
mboxbyname(char *name)
{
	int i;

	for(i=0; i<nbox; i++)
		if(box[i] && strcmp(box[i]->name, name) == 0)
			return box[i];
	return nil;
}

static Mailbox*
mboxbyid(int id)
{
	if(id < 0 || id >= nbox)
		return nil;
	return box[id];
}

static Mailbox*
mboxcreate(char *name)
{
	Mailbox *b;

	b = emalloc(sizeof *b);
	b->name = estrdup(name);
	if(nbox%64 == 0)
		box = erealloc(box, (nbox+64)*sizeof box[0]);
	box[nbox++] = b;
	return b;
}

void
mboxupdate(void)
{
	markboxes();
	if(imapcmd("LIST \"\" *") < 0)
		return;
	sweepboxes();
}