Commit 1a3b2274 1a3b2274e8cb2a947d44e996e647556880bec5a6 by Sean 'Shaleh' Perry

began work on expunge

stopped an invalid pointer use in mail.C
1 parent 6b7fda6a
1 1999-11-06 Sean 'Shaleh' Perry <shaleh@debian.org>
2
3 * libmailbox/unixmbox.*: work on expunge
4 use read/write along with lseek
5 still blows up -- getting there
6 * mail/mail.c: check return value of mbox_open()
7
1 1999-10-23 Alain Magloire 8 1999-10-23 Alain Magloire
2 9
3 * ChangeLog: Cleanup according to GNU std, and remove 10 * ChangeLog: Cleanup according to GNU std, and remove
......
...@@ -5,14 +5,13 @@ ...@@ -5,14 +5,13 @@
5 5
6 * autogen.sh (libtool) complains about libmailbox.la in noinst (JB Oct 08/99) 6 * autogen.sh (libtool) complains about libmailbox.la in noinst (JB Oct 08/99)
7 7
8 + libmailbox has a nasty bug -- if the mailbox is empty, the library has no idea 8 - added more includes to libmailbox, make sure autoconf finds them
9 what to do (Shaleh Oct 07/99)
10 9
11 - libmailbox needs an interface to set flags for each message 10 - libmailbox needs an interface to set flags for each message
12 11
13 - libmailbox needs an interface to set and create values in the header 12 - libmailbox needs an interface to set and create values in the header
14 13
15 + crypt is linked even if pam was detected, it should be one or the other (JB Oct 08/99) 14 - clean up 'mail''s compilation
16 15
17 - find out why the pop3 server quits on a signal when the 'quit' command is 16 - find out why the pop3 server quits on a signal when the 'quit' command is
18 given 17 given
...@@ -21,10 +20,16 @@ ...@@ -21,10 +20,16 @@
21 20
22 - test network code 21 - test network code
23 22
24 + add imap server code (JB && Shaleh Oct 11/99)
25
26 - add more features 23 - add more features
27 24
28 - optimize everything 25 - optimize everything
29 26
30 - test everything 27 - test everything
28
29 + libmailbox has a nasty bug -- if the mailbox is empty, the library has no idea
30 what to do (Shaleh Oct 07/99)
31
32 + crypt is linked even if pam was detected, it should be one or the other (JB Oct 08/99)
33
34 + add imap server code (JB && Shaleh Oct 11/99)
35
......
...@@ -233,37 +233,59 @@ int ...@@ -233,37 +233,59 @@ int
233 unixmbox_expunge (mailbox * mbox) 233 unixmbox_expunge (mailbox * mbox)
234 { 234 {
235 unixmbox_data *data; 235 unixmbox_data *data;
236 int i = 0, size = 0; 236 int i = 0;
237 ssize_t size = 0, size_read = 0;
237 char *buf = NULL; 238 char *buf = NULL;
238 fpos_t lastpos; 239 int file;
240 int deletion_needed = 0; /* true when a deleted message has been found */
241 size_t buff_size = 0;
242 size_t tmp = 0;
239 243
240 if (mbox == NULL) 244 if (mbox == NULL)
241 { 245 {
242 errno = EINVAL; 246 errno = EINVAL;
243 return -1; 247 return -1;
244 } 248 }
245 data = mbox->_data; 249 if (mbox->num_deleted)
246 data->file = freopen (mbox->name, "r+", data->file);
247 if (data->file == NULL)
248 { 250 {
251 data = mbox->_data;
252 fclose(data->file);
253 /* error handling */
254 data->file = NULL;
255 file = open(mbox->name, O_RDWR);
249 /* error handling */ 256 /* error handling */
250 }
251 fgetpos (data->file, &lastpos);
252 257
253 for (i = 0; i < mbox->messages; i++) 258 for (i = 0; i < mbox->messages; i++)
254 { 259 {
255 if (data->messages[i].deleted == 0) 260 if (data->messages[i].deleted == 0)
256 { 261 {
257 fgetpos (data->file, &lastpos); 262 if (deletion_needed)
258 fsetpos (data->file, &(data->messages[i].header)); 263 {
259 read (fileno (data->file), buf, 264 tmp = data->messages[i + 1].header - data->messages[i].header;
260 data->messages[i + 1].header - data->messages[i].header); 265 if (tmp > buff_size)
261 fprintf (data->file, "%s", buf); 266 {
262 size += strlen (buf); 267 buff_size = tmp;
263 free (buf); 268 buf = realloc (buf, tmp);
269 /* error checking */
264 } 270 }
271 lseek (file, data->messages[i].header, SEEK_SET);
272 size_read = read (file, buf, tmp);
273 /* error checking */
274 lseek (file, size, SEEK_SET);
275 write (file, buf, size_read);
276 /* error checking */
277 size += size_read;
278 }
279 }
280 else
281 {
282 deletion_needed = 1;
283 }
284 }
285 close (file);
286 truncate (mbox->name, size);
287 free (buf);
265 } 288 }
266 ftruncate (fileno (data->file), size);
267 return 0; 289 return 0;
268 } 290 }
269 291
...@@ -280,6 +302,8 @@ unixmbox_is_deleted (mailbox * mbox, unsigned int num) ...@@ -280,6 +302,8 @@ unixmbox_is_deleted (mailbox * mbox, unsigned int num)
280 errno = EINVAL; 302 errno = EINVAL;
281 return -1; 303 return -1;
282 } 304 }
305 if (mbox->num_deleted == 0)
306 return 0;
283 data = mbox->_data; 307 data = mbox->_data;
284 return (data->messages[num].deleted == 1); 308 return (data->messages[num].deleted == 1);
285 } 309 }
......
...@@ -42,6 +42,10 @@ ...@@ -42,6 +42,10 @@
42 #include <strings.h> 42 #include <strings.h>
43 #endif 43 #endif
44 44
45 #include <sys/types.h>
46 #include <sys/stat.h>
47 #include <fcntl.h>
48
45 typedef struct _unixmbox_message 49 typedef struct _unixmbox_message
46 { 50 {
47 off_t header; 51 off_t header;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
19 #include <config.h> 19 #include <config.h>
20 #endif 20 #endif
21 21
22 #include <errno.h>
22 #include <mailbox.h> 23 #include <mailbox.h>
23 #include <stdio.h> 24 #include <stdio.h>
24 #include <stdlib.h> 25 #include <stdlib.h>
...@@ -86,6 +87,11 @@ Report bugs to <bug-mailutils@gnu.org>.\n"); ...@@ -86,6 +87,11 @@ Report bugs to <bug-mailutils@gnu.org>.\n");
86 } 87 }
87 88
88 mbox = mbox_open (mboxname); 89 mbox = mbox_open (mboxname);
90 if (mbox == NULL)
91 {
92 fprintf (stderr, "Ack, %s, reading %s\n", strerror(errno), mboxname);
93 exit (1);
94 }
89 printf ("Number of messages: %d\n", mbox->messages); 95 printf ("Number of messages: %d\n", mbox->messages);
90 while (1) 96 while (1)
91 { 97 {
......