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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
/*
* dbase driver header file
* Functions for database communication
*
* should connect to any dbXXX.c file where XXXX is the dbase to be used
*/
#ifndef _DB_H
#define _DB_H
#include "debug.h"
#include "dbmailtypes.h"
#include "mime.h"
#include "list.h"
#include "memblock.h"
#define DEF_QUERYSIZE 1024
#define DUMP_BUF_SIZE 1024
#define ICHECK_RESULTSETSIZE 1000000
#define MAX_EMAIL_SIZE 250
/* size of the messageblk's */
#define READ_BLOCK_SIZE (512ul*1024ul) /* be carefull, MYSQL has a limit */
/* config types */
#define CONFIG_MANDATORY 1
#define CONFIG_EMPTY 0
struct session;
struct list;
/* users, aliases, mailboxes, messages, messageblks */
#define DB_NTABLES 5
enum table_aliases /* prototype for aliases table */
{
ALIASES_ALIAS_IDNR,
ALIASES_ALIAS,
ALIASES_USERIDNR
};
enum table_user /* prototype for user table */
{
USER_USERIDNR,
USER_USERID,
USER_PASSWD,
USER_CLIENTID,
USER_MAXMAIL
};
enum table_mailbox /* prototype for mailbox table */
{
MAILBOX_MAILBOXIDNR,
MAILBOX_OWNERIDNR,
MAILBOX_NAME,
MAILBOX_SEEN_FLAG,
MAILBOX_ANSWERED_FLAG,
MAILBOX_DELETED_FLAG,
MAILBOX_FLAGGED_FLAG,
MAILBOX_RECENT_FLAG,
MAILBOX_DRAFT_FLAG,
MAILBOX_NO_INFERIORS,
MAILBOX_NO_SELECT,
MAILBOX_PERMISSIONS
};
enum table_message /* prototype for message table */
{
MESSAGE_MESSAGEIDNR,
MESSAGE_MAILBOXIDNR,
MESSAGE_MESSAGESIZE,
MESSAGE_SEEN_FLAG,
MESSAGE_ANSWERED_FLAG,
MESSAGE_DELETED_FLAG,
MESSAGE_FLAGGED_FLAG,
MESSAGE_RECENT_FLAG,
MESSAGE_DRAFT_FLAG,
MESSAGE_UNIQUE_ID,
MESSAGE_INTERNALDATE,
MESSAGE_STATUS
};
enum table_messageblk /* prototype for messageblk table */
{
MESSAGEBLK_MESSAGEBLKNR,
MESSAGEBLK_MESSAGEIDNR,
MESSAGEBLK_MESSAGEBLK,
MESSAGEBLK_BLOCKSIZE
};
/*
* PROTOTYPES
*/
int db_connect();
int db_disconnect();
int db_query (const char *thequery);
char *db_get_config_item (char *item, int type);
int db_clear_config();
int db_insert_config_item (char *item, char *val);
u64_t db_get_quotum_used(u64_t userid);
u64_t db_get_user_from_alias(const char *alias);
int db_get_user_aliases(u64_t userid, struct list *aliases);
int db_addalias(u64_t useridnr, char *alias, u64_t clientid);
int db_addalias_ext(char *alias, char *deliver_to, u64_t clientid);
int db_removealias(u64_t useridnr, const char *alias);
int db_removealias_ext(const char *alias, const char *deliver_to);
u64_t db_get_mailboxid(u64_t useridnr, const char *mailbox);
u64_t db_get_useridnr(u64_t messageidnr);
u64_t db_get_message_mailboxid(u64_t messageidnr);
u64_t db_insert_message(u64_t useridnr, const char *deliver_to_mailbox, const char *uniqueid);
u64_t db_update_message(u64_t messageidnr, const char *unique_id,
u64_t messagesize, u64_t rfcsize);
int db_update_message_multiple(const char *unique_id, u64_t messagesize, u64_t rfcsize);
u64_t db_insert_message_block(const char *block, u64_t len, u64_t messageidnr);
int db_insert_message_block_multiple(const char *unique_id, const char *block, u64_t len);
int db_rollback_insert(u64_t ownerid, const char *unique_id);
int db_log_ip(const char *ip);
int db_cleanup_iplog(const char *lasttokeep);
int db_cleanup();
int db_empty_mailbox(u64_t userid);
int db_icheck_messageblks(struct list *lostlist);
int db_icheck_messages(struct list *lostlist);
int db_icheck_mailboxes(struct list *lostlist);
int db_delete_messageblk(u64_t uid);
int db_delete_message(u64_t uid);
int db_delete_mailbox(u64_t uid, int only_empty);
u64_t db_insert_result (const char *sequence_identifier);
int db_send_message_lines (void *fstream, u64_t messageidnr, long lines, int no_end_dot);
int db_createsession (u64_t useridnr, struct session *sessionptr);
void db_session_cleanup (struct session *sessionptr);
int db_update_pop (struct session *sessionptr);
u64_t db_set_deleted ();
u64_t db_deleted_purge();
u64_t db_check_sizelimit (u64_t addblocksize, u64_t messageidnr,
u64_t *useridnr);
int db_imap_append_msg(const char *msgdata, u64_t datalen, u64_t mboxid, u64_t uid);
/* mailbox functionality */
u64_t db_findmailbox(const char *name, u64_t useridnr);
int db_findmailbox_by_regex(u64_t ownerid, const char *pattern,
u64_t **children, unsigned *nchildren,
int only_subscribed);
int db_getmailbox(mailbox_t *mb, u64_t userid);
int db_createmailbox(const char *name, u64_t ownerid);
int db_listmailboxchildren(u64_t uid, u64_t useridnr,
u64_t **children, int *nchildren,
const char *filter);
int db_removemailbox(u64_t uid, u64_t ownerid);
int db_isselectable(u64_t uid);
int db_noinferiors(u64_t uid);
int db_setselectable(u64_t uid, int val);
int db_removemsg(u64_t uid);
int db_movemsg(u64_t to, u64_t from);
int db_copymsg(u64_t msgid, u64_t destmboxid);
int db_getmailboxname(u64_t uid, char *name);
int db_setmailboxname(u64_t uid, const char *name);
int db_expunge(u64_t uid,u64_t **msgids,u64_t *nmsgs);
u64_t db_first_unseen(u64_t uid);
int db_subscribe(u64_t mboxid);
int db_unsubscribe(u64_t mboxid);
/* message functionality */
int db_get_msgflag(const char *name, u64_t msguid, u64_t mailboxuid);
int db_get_msgflag_all(u64_t msguid, u64_t mailboxuid, int *flags);
int db_get_msgflag_all_range(u64_t msguidlow, u64_t msguidhigh, u64_t mailboxuid,
int **flags, unsigned *resultsetlen);
int db_set_msgflag(u64_t msguid, u64_t mailboxuid, int *flags, int action_type);
int db_set_msgflag_range(u64_t msguidlow, u64_t msguidhigh, u64_t mailboxuid,
int *flags, int action_type);
int db_get_msgdate(u64_t mailboxuid, u64_t msguid, char *date);
int db_set_rfcsize(u64_t size, u64_t msguid, u64_t mailboxuid);
u64_t db_get_rfcsize(u64_t msguid, u64_t mailboxuid);
int db_get_msginfo_range(u64_t msguidlow, u64_t msguidhigh, u64_t mailboxuid,
int getflags, int getinternaldate, int getsize, int getuid,
msginfo_t **result, unsigned *resultsetlen);
int db_get_main_header(u64_t msguid, struct list *hdrlist);
int db_mailbox_msg_match(u64_t mailboxuid, u64_t msguid);
#endif
|