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
|
#ifndef maildirquota_h
#define maildirquota_h
/*
** Copyright 1998 - 2010 Double Precision, Inc.
** See COPYING for distribution information.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include "numlib/numlib.h"
#ifdef __cplusplus
extern "C" {
#endif
#define MDQUOTA_SIZE 'S' /* Total size of all messages in maildir */
#define MDQUOTA_BLOCKS 'B' /* Total # of blocks for all messages in
maildir -- NOT IMPLEMENTED */
#define MDQUOTA_COUNT 'C' /* Total number of messages in maildir */
struct maildirquota {
int64_t nbytes; /* # of bytes, 0 - unlimited */
int nmessages; /* # of messages, 0 - unlimited */
};
/*
** The maildirsize file
*/
struct maildirsize {
int fd; /* Opened file descriptor for the maildirsize file */
char *maildir; /* Pathname to the maildir */
char *maildirsizefile; /* The name of the maildirsize file */
struct maildirquota quota; /* 1st line in maildirsize */
struct maildirquota size; /* Actual counts 2+ line */
int recalculation_needed; /* size is not calculated */
struct stat statbuf; /* The stat on the maidlirsize file */
unsigned nlines; /* # of lines in the maildirsize file */
};
/*
** maildir_openquotafile initializes a maildirsize structure from a maildirsize
** file. This is really an internal, undocumented, function.
**
** return 0 for success, -1 if the file could not be opened
*/
int maildir_openquotafile(struct maildirsize *info, /* Initialized */
const char * /* maildir */
);
/*
** maildir_closequotafile releases all resources allocated by maildirsize
** struct.
*/
void maildir_closequotafile(struct maildirsize *info);
int maildir_checkquota(struct maildirsize *, /* Opened maildir */
int64_t, /* Extra bytes planning to add/remove from
maildir */
int); /* Extra messages planning to add/remove from
maildir */
int maildir_addquota(struct maildirsize *, /* Opened maildir */
int64_t, /* +/- bytes */
int); /* +/- files */
int maildir_readquota(struct maildirsize *); /* Directory */
int maildir_parsequota(const char *, unsigned long *);
/* Attempt to parse file size encoded in filename. Returns 0 if
** parsed, non-zero if we didn't parse. */
/* Here are some high-level functions that call the above */
/* Adding messages to the maildir, in two easy steps: */
int maildir_quota_add_start(const char *maildir,
struct maildirsize *info,
int64_t msgsize, int nmsgs,
const char *newquota);
void maildir_quota_add_end(struct maildirsize *info,
int64_t msgsize, int nmsgs);
/* When we're deleting messages, we want an unconditional quota update */
void maildir_quota_deleted(const char *maildir,
int64_t nbytes, /* Must be negative */
int nmsgs); /* Must be negative */
/* Can we delete or undelete messages? This is like maildir_quota_add_start
** and maildir_quota_add_end, except that if deleted messages are included in
** the quota, they are compiled to no-ops
*/
int maildir_quota_delundel_start(const char *maildir,
struct maildirsize *info,
int64_t msgsize, int nmsgs);
void maildir_quota_delundel_end(struct maildirsize *info,
int64_t msgsize, int nmsgs);
/* Set a new quota on the maildir; */
void maildir_quota_set(const char *dir, const char *quota);
/* Forcibly recalculate the maildir's quota */
void maildir_quota_recalculate(const char *maildir);
/*
** Should the following folder/file be included in the quota?
** (excludes TRASH and deleted files, if configured to do so)
*/
int maildirquota_countfolder(const char *folder);
int maildirquota_countfile(const char *filename);
void maildir_deliver_quota_warning(const char *dir, const int percent,
const char *msgquotafile);
#ifdef __cplusplus
}
#endif
#endif
|