[dovecot-cvs] dovecot/src/pop3 client.c,1.11,1.12 commands.c,1.8,1.9 mail-storage-callbacks.c,1.1,1.2

cras at procontrol.fi cras at procontrol.fi
Sat Jul 26 20:33:24 EEST 2003


Update of /home/cvs/dovecot/src/pop3
In directory danu:/tmp/cvs-serv28560/pop3

Modified Files:
	client.c commands.c mail-storage-callbacks.c 
Log Message:
API change for expunging messages. Not exactly what I wanted, but good
enough.



Index: client.c
===================================================================
RCS file: /home/cvs/dovecot/src/pop3/client.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- client.c	15 Jul 2003 18:26:43 -0000	1.11
+++ client.c	26 Jul 2003 16:33:22 -0000	1.12
@@ -63,7 +63,7 @@
 	for (i = 0; i < 2; i++) {
 		ctx = client->mailbox->fetch_init(client->mailbox,
 						  MAIL_FETCH_SIZE,
-						  NULL, messageset, FALSE);
+						  messageset, FALSE);
 		if (ctx == NULL) {
 			client_send_storage_error(client);
 			return FALSE;

Index: commands.c
===================================================================
RCS file: /home/cvs/dovecot/src/pop3/commands.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- commands.c	27 May 2003 07:13:42 -0000	1.8
+++ commands.c	26 Jul 2003 16:33:22 -0000	1.9
@@ -139,63 +139,44 @@
 	return TRUE;
 }
 
-static int cmd_quit(struct client *client, const char *args __attr_unused__)
+static int expunge_mails(struct client *client, struct mailbox *box)
 {
-	unsigned int first, last, msgnum, max, i, j;
-	struct mail_full_flags flags;
-	string_t *set;
-
-	if (!client->deleted) {
-		client_send_line(client, "+OK Logging out.");
-		client_disconnect(client);
-		return TRUE;
-	}
-
-	set = t_str_new(1024);
-	first = last = 0; msgnum = 1;
-	max = MSGS_BITMASK_SIZE(client);
-	for (i = 0; i < max; i++) {
-		if (client->deleted_bitmask[i] == 0) {
-                        msgnum += CHAR_BIT;
-			continue;
-		}
+	struct mail_expunge_context *ctx;
+	struct mail *mail;
+	unsigned int i, j;
+	int failed = FALSE;
 
-		for (j = 0; j < CHAR_BIT; j++, msgnum++) {
-			if ((client->deleted_bitmask[i] & (1 << j)) == 0)
-				continue;
+	/* NOTE: if there's any external expunges, they'll get synced here.
+	   Currently we update only the deleted_bitmask[] so we don't end up
+	   expunging wrong messages, but message_sizes[] isn't updated. */
+	ctx = box->expunge_init(box, 0, TRUE);
+	if (ctx == NULL)
+		return FALSE;
 
-			if (last == msgnum-1 && last != 0)
-				last++;
-			else {
-				if (first != 0) {
-					if (first == last)
-						str_printfa(set, ",%u", first);
-					else {
-						str_printfa(set, ",%u:%u",
-							    first, last);
-					}
-				}
-				first = last = msgnum;
+	i = j = 0;
+	while ((mail = box->expunge_fetch_next(ctx)) != NULL) {
+		if ((client->deleted_bitmask[i] & (1 << j)) != 0) {
+			if (!mail->expunge(mail, ctx, NULL, FALSE)) {
+				failed = TRUE;
+				break;
 			}
 		}
+		if (++j == CHAR_BIT) {
+			j = 0; i++;
+		}
 	}
 
-	if (first != 0) {
-		if (first == last)
-			str_printfa(set, ",%u", first);
-		else
-			str_printfa(set, ",%u:%u", first, last);
-	}
+	if (!box->expunge_deinit(ctx))
+		return FALSE;
 
-	memset(&flags, 0, sizeof(flags));
-	flags.flags = MAIL_DELETED;
+	return !failed;
+}
 
-	if (str_len(set) == 0)
+static int cmd_quit(struct client *client, const char *args __attr_unused__)
+{
+	if (!client->deleted)
 		client_send_line(client, "+OK Logging out.");
-	else if (client->mailbox->update_flags(client->mailbox, str_c(set)+1,
-					       FALSE, &flags, MODIFY_ADD,
-					       FALSE, NULL) &&
-		 client->mailbox->expunge(client->mailbox, FALSE))
+	else if (expunge_mails(client, client->mailbox))
 		client_send_line(client, "+OK Logging out, messages deleted.");
 	else
 		client_send_storage_error(client);
@@ -281,8 +262,7 @@
 	ctx = client->mailbox->fetch_init(client->mailbox,
 					  MAIL_FETCH_STREAM_HEADER |
 					  MAIL_FETCH_STREAM_BODY,
-					  NULL, dec2str(msgnum+1),
-					  FALSE);
+					  dec2str(msgnum+1), FALSE);
 	if (ctx == NULL) {
 		client_send_storage_error(client);
 		return;
@@ -366,7 +346,7 @@
 		t_strdup_printf("%u", message);
 
 	ctx = client->mailbox->fetch_init(client->mailbox, 0,
-					  NULL, messageset, FALSE);
+					  messageset, FALSE);
 	if (ctx == NULL) {
 		client_send_storage_error(client);
 		return;

Index: mail-storage-callbacks.c
===================================================================
RCS file: /home/cvs/dovecot/src/pop3/mail-storage-callbacks.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mail-storage-callbacks.c	27 Jan 2003 05:45:47 -0000	1.1
+++ mail-storage-callbacks.c	26 Jul 2003 16:33:22 -0000	1.2
@@ -22,17 +22,40 @@
 }
 
 static void expunge(struct mailbox *mailbox __attr_unused__,
-		    unsigned int seq __attr_unused__,
-		    void *context __attr_unused__)
+		    unsigned int seq, void *context)
 {
+	struct client *client = context;
+	unsigned char *mask = client->deleted_bitmask;
+	unsigned int max, i, j;
+
+	/* external deletes - we have to fix our internal deleted array.
+	   this should happen only when we're doing the expunging at quit. */
+	seq--;
+	client->messages_count--;
+
+	if (!client->deleted)
+		return;
+
+	max = client->messages_count / CHAR_BIT;
+	i = seq / CHAR_BIT; j = seq % CHAR_BIT;
+	mask[i] = (mask[i] & ((1 << j) - 1)) |
+		((mask[i] >> (j+1)) << j) |
+		(i == max ? 0 : ((mask[i+1] & 1) << (CHAR_BIT-1)));
+
+	if (i != max) {
+		for (i++; i < max-1; i++) {
+			mask[i] = (mask[i] >> 1) |
+				((mask[i+1] & 1) << (CHAR_BIT-1));
+		}
+
+		mask[i] >>= 1;
+	}
 }
 
 static void update_flags(struct mailbox *mailbox __attr_unused__,
 			 unsigned int seq __attr_unused__,
 			 unsigned int uid __attr_unused__,
-			 enum mail_flags flags __attr_unused__,
-			 const char *custom_flags[] __attr_unused__,
-			 unsigned int custom_flags_count __attr_unused__,
+			 const struct mail_full_flags *flags __attr_unused__,
 			 void *context __attr_unused__)
 {
 }



More information about the dovecot-cvs mailing list