mailbox.c
4.7 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <mailbox0.h>
#include <message0.h>
#include <registrar.h>
#include <locker.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
/*
* Point of entry.
* Simple, first check if they ask for something specific; with the ID.
* Then try to discover the type of mailbox with the url(name).
* Then we call the appropriate mailbox_*type*_init() function.
*/
int
mailbox_init (mailbox_t *pmbox, const char *name, int id)
{
int status = EINVAL;
struct mailbox_registrar *mreg;
url_t url = NULL;
url_init (&url, name);
/* 1st guest: if an ID is specify, shortcut */
if (id)
{
status = registrar_get (id, NULL, &mreg);
if (status == 0)
status = mreg->_init (pmbox, name);
}
/* 2nd fallback: Use the URL */
else if (url != NULL)
{
url_get_id (url, &id);
status = registrar_get (id, NULL, &mreg);
if (status == 0)
status = mreg->_init (pmbox, name);
}
/* set the URL */
if (status == 0)
(*pmbox)->url = url;
else
url_destroy (&url);
return status;
}
void
mailbox_destroy (mailbox_t *pmbox)
{
if (pmbox && *pmbox)
(*pmbox)->_destroy (pmbox);
}
/* -------------- stub functions ------------------- */
int
mailbox_open (mailbox_t mbox, int flag)
{
if (mbox == NULL || mbox->_open == NULL)
return ENOSYS;
return mbox->_open (mbox, flag);
}
int
mailbox_close (mailbox_t mbox)
{
if (mbox == NULL || mbox->_close == NULL)
return ENOSYS;
return mbox->_close (mbox);
}
/* messages */
int
mailbox_is_deleted (mailbox_t mbox, size_t msgno)
{
if (mbox == NULL || mbox->_is_deleted == NULL)
return 0;
return mbox->_is_deleted (mbox, msgno);
}
int
mailbox_append_message (mailbox_t mbox, message_t msg)
{
if (mbox == NULL || mbox->_append_message == NULL)
return ENOSYS;
return mbox->_append_message (mbox, msg);
}
int
mailbox_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg)
{
if (mbox == NULL || mbox->_get_message == NULL)
return EINVAL;
return mbox->_get_message (mbox, msgno, pmsg);
}
int
mailbox_messages_count (mailbox_t mbox, size_t *num)
{
if (mbox == NULL || mbox->_messages_count == NULL)
return ENOSYS;
return mbox->_messages_count (mbox, num);
}
int
mailbox_delete (mailbox_t mbox, size_t msgno)
{
if (mbox == NULL || mbox->_delete == NULL)
return ENOSYS;
return mbox->_delete (mbox, msgno);
}
int
mailbox_undelete (mailbox_t mbox, size_t msgno)
{
if (mbox == NULL || mbox->_undelete == NULL)
return ENOSYS;
return mbox->_undelete (mbox, msgno);
}
int
mailbox_expunge (mailbox_t mbox)
{
if (mbox == NULL || mbox->_expunge == NULL)
return ENOSYS;
return mbox->_expunge (mbox);
}
int
mailbox_num_deleted (mailbox_t mbox, size_t *num)
{
if (mbox == NULL || mbox->_num_deleted == NULL)
return EINVAL;
return mbox->_num_deleted (mbox, num);
}
/* hook to allow some sort of "progress bar" .. I don't like it
* but can not find any other way yet
*/
int
mailbox_progress (mailbox_t mbox, int (*progress) (int, void *arg), void *arg)
{
if (mbox == NULL)
return EINVAL;
mbox->_progress = progress;
mbox->progress_arg = arg;
return 0;
}
int
mailbox_is_updated (mailbox_t mbox)
{
if (mbox == NULL || mbox->_is_updated == NULL)
return 0;
return mbox->_is_updated (mbox);
}
/* locking */
int
mailbox_set_locker (mailbox_t mbox, locker_t locker)
{
if (mbox == NULL)
return EINVAL;
if (mbox->locker != NULL)
locker_destroy (&mbox->locker);
mbox->locker = locker;
return 0;
}
int
mailbox_get_locker (mailbox_t mbox, locker_t *locker)
{
if (mbox == NULL || locker == NULL)
return EINVAL;
*locker = mbox->locker;
return 0;
}
int
mailbox_set_auth (mailbox_t mbox, auth_t auth)
{
if (mbox == NULL)
return EINVAL;
mbox->auth = auth;
return 0;
}
int
mailbox_get_auth (mailbox_t mbox, auth_t *pauth)
{
if (mbox == NULL || pauth == NULL)
return EINVAL;
*pauth = mbox->auth;
return 0;
}