1 #ifndef	maildirquota_h
2 #define	maildirquota_h
3 
4 /*
5 ** Copyright 1998 - 2010 Double Precision, Inc.
6 ** See COPYING for distribution information.
7 */
8 
9 #if	HAVE_CONFIG_H
10 #include	"config.h"
11 #endif
12 
13 #include	<sys/types.h>
14 #include	<sys/stat.h>
15 #include	<stdio.h>
16 
17 #include	"numlib/numlib.h"
18 
19 #ifdef  __cplusplus
20 extern "C" {
21 #endif
22 
23 
24 #define	MDQUOTA_SIZE	'S'	/* Total size of all messages in maildir */
25 #define	MDQUOTA_BLOCKS	'B'	/* Total # of blocks for all messages in
26 				maildir -- NOT IMPLEMENTED */
27 #define	MDQUOTA_COUNT	'C'	/* Total number of messages in maildir */
28 
29 struct maildirquota {
30 	int64_t nbytes;	/* # of bytes, 0 - unlimited */
31 	int nmessages;	/* # of messages, 0 - unlimited */
32 };
33 
34 	/*
35 	** The maildirsize file
36 	*/
37 
38 struct maildirsize {
39 
40 	int fd;	/* Opened file descriptor for the maildirsize file */
41 
42 	char *maildir;			/* Pathname to the maildir */
43 	char *maildirsizefile;		/* The name of the maildirsize file */
44 
45 	struct maildirquota quota;	/* 1st line in maildirsize */
46 
47 	struct maildirquota size;	/* Actual counts 2+ line */
48 
49 	int recalculation_needed;	/* size is not calculated */
50 
51 	struct stat	statbuf;	/* The stat on the maidlirsize file */
52 	unsigned nlines;	/* # of lines in the maildirsize file */
53 };
54 
55 
56 /*
57 ** maildir_openquotafile initializes a maildirsize structure from a maildirsize
58 ** file.  This is really an internal, undocumented, function.
59 **
60 ** return 0 for success, -1 if the file could not be opened
61 */
62 
63 int maildir_openquotafile(struct maildirsize *info,	/* Initialized */
64 			  const char *			/* maildir */
65 			  );
66 
67 /*
68 ** maildir_closequotafile releases all resources allocated by maildirsize
69 ** struct.
70 */
71 
72 void maildir_closequotafile(struct maildirsize *info);
73 
74 
75 
76 
77 int maildir_checkquota(struct maildirsize *, /* Opened maildir */
78 		       int64_t,  /* Extra bytes planning to add/remove from
79 				 maildir */
80 		       int);  /* Extra messages planning to add/remove from
81 				 maildir */
82 
83 int maildir_addquota(struct maildirsize *, /* Opened maildir */
84 		     int64_t,	/* +/- bytes */
85 		     int);	/* +/- files */
86 
87 int maildir_readquota(struct maildirsize *);	/* Directory */
88 
89 int maildir_parsequota(const char *, unsigned long *);
90 	/* Attempt to parse file size encoded in filename.  Returns 0 if
91 	** parsed, non-zero if we didn't parse. */
92 
93 
94 	/* Here are some high-level functions that call the above */
95 
96 	/* Adding messages to the maildir, in two easy steps: */
97 
98 int maildir_quota_add_start(const char *maildir,
99 			    struct maildirsize *info,
100 			    int64_t msgsize, int nmsgs,
101 			    const char *newquota);
102 
103 void maildir_quota_add_end(struct maildirsize *info,
104 			   int64_t msgsize, int nmsgs);
105 
106 /* When we're deleting messages, we want an unconditional quota update */
107 
108 void maildir_quota_deleted(const char *maildir,
109 			   int64_t nbytes,	/* Must be negative */
110 			   int nmsgs);	/* Must be negative */
111 
112 
113 /* Can we delete or undelete messages?  This is like maildir_quota_add_start
114 ** and maildir_quota_add_end, except that if deleted messages are included in
115 ** the quota, they are compiled to no-ops
116 */
117 
118 int maildir_quota_delundel_start(const char *maildir,
119 				 struct maildirsize *info,
120 				 int64_t msgsize, int nmsgs);
121 
122 void maildir_quota_delundel_end(struct maildirsize *info,
123 				int64_t msgsize, int nmsgs);
124 
125 	/* Set a new quota on the maildir; */
126 
127 void maildir_quota_set(const char *dir, const char *quota);
128 
129 	/* Forcibly recalculate the maildir's quota */
130 
131 void maildir_quota_recalculate(const char *maildir);
132 
133 
134 	/*
135 	** Should the following folder/file be included in the quota?
136 	** (excludes TRASH and deleted files, if configured to do so)
137 	*/
138 
139 int maildirquota_countfolder(const char *folder);
140 int maildirquota_countfile(const char *filename);
141 
142 void maildir_deliver_quota_warning(const char *dir, const int percent,
143 				   const char *msgquotafile);
144 
145 #ifdef  __cplusplus
146 }
147 #endif
148 
149 #endif
150