diff src/imap/cmd-append.c @ 2190:755ec9442a58 HEAD

mailbox_save() and mailbox_copy() functions can now return the saved mail so it can be immediately queried. Implemented UIDPLUS extension using it. Maildir implementation missing, so it crashes with it for now.. APPEND with mbox now doesn't require resyncing the mailbox since it updates indexes directly.
author Timo Sirainen <tss@iki.fi>
date Sun, 20 Jun 2004 06:25:32 +0300
parents 4dec6a3d79fd
children 89001f106f8d
line wrap: on
line diff
--- a/src/imap/cmd-append.c	Sun Jun 20 05:06:13 2004 +0300
+++ b/src/imap/cmd-append.c	Sun Jun 20 06:25:32 2004 +0300
@@ -4,6 +4,7 @@
 #include "ioloop.h"
 #include "istream.h"
 #include "ostream.h"
+#include "str.h"
 #include "commands.h"
 #include "imap-parser.h"
 #include "imap-date.h"
@@ -55,9 +56,12 @@
         struct mailbox_keywords old_flags;
 	struct mail_full_flags flags;
 	struct istream *input;
+	struct mail *mail;
 	time_t internal_date;
 	const char *mailbox, *internal_date_str;
 	uoff_t msg_size;
+	string_t *reply;
+        struct msgset_generator_context msgset_ctx;
 	unsigned int count;
 	int ret, failed, timezone_offset, nonsync;
 
@@ -72,13 +76,19 @@
 	if (storage == NULL)
 		return TRUE;
 
-	box = mailbox_open(storage, mailbox, MAILBOX_OPEN_FAST);
-	if (box == NULL) {
-		client_send_storage_error(client, storage);
-		return TRUE;
+	if (client->mailbox != NULL &&
+	    mailbox_name_equals(mailbox_get_name(client->mailbox), mailbox))
+		box = client->mailbox;
+	else {
+		box = mailbox_open(storage, mailbox, MAILBOX_OPEN_FAST);
+		if (box == NULL) {
+			client_send_storage_error(client, storage);
+			return TRUE;
+		}
 	}
 
-	if (mailbox_get_status(box, STATUS_KEYWORDS, &status) < 0) {
+	if (mailbox_get_status(box, STATUS_KEYWORDS | STATUS_UIDVALIDITY,
+			       &status) < 0) {
 		client_send_storage_error(client, storage);
 		mailbox_close(box);
 		return TRUE;
@@ -93,6 +103,10 @@
 	/* if error occurs, the CRLF is already read. */
 	client->input_skip_line = FALSE;
 
+	reply = str_new(default_pool, 256);
+	str_printfa(reply, "OK [APPENDUID %u ", status.uidvalidity);
+
+	msgset_generator_init(&msgset_ctx, reply);
 	count = 0;
 	failed = TRUE;
 	save_parser = imap_parser_create(client->input, client->output,
@@ -180,13 +194,15 @@
 					      client->input->v_offset,
 					      msg_size);
 		if (mailbox_save(t, &flags, internal_date, timezone_offset,
-				 NULL, input) < 0) {
+				 NULL, input, &mail) < 0) {
 			i_stream_unref(input);
 			client_send_storage_error(client, storage);
 			break;
 		}
 		i_stream_unref(input);
 
+		msgset_generator_next(&msgset_ctx, mail->uid);
+
 		if (client->input->closed)
 			break;
 
@@ -194,6 +210,8 @@
 	}
         imap_parser_destroy(save_parser);
 
+	msgset_generator_finish(&msgset_ctx);
+
 	if (failed)
 		mailbox_transaction_rollback(t);
 	else {
@@ -203,11 +221,15 @@
 		}
 	}
 
-	mailbox_close(box);
+	if (box != client->mailbox)
+		mailbox_close(box);
 
 	if (!failed) {
 		client_sync_full(client);
-		client_send_tagline(client, "OK Append completed.");
+		str_append(reply, "] Append completed.");
+		client_send_tagline(client, str_c(reply));
 	}
+	str_free(reply);
+
 	return TRUE;
 }