[dovecot-cvs] dovecot/src/lib-imap imap-message-cache.c,1.21,1.22 imap-message-cache.h,1.11,1.12

cras at procontrol.fi cras at procontrol.fi
Sun Oct 27 21:49:15 EET 2002


Update of /home/cvs/dovecot/src/lib-imap
In directory danu:/tmp/cvs-serv29479/lib-imap

Modified Files:
	imap-message-cache.c imap-message-cache.h 
Log Message:
Forgot in last commit.



Index: imap-message-cache.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-message-cache.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- imap-message-cache.c	20 Oct 2002 00:17:21 -0000	1.21
+++ imap-message-cache.c	27 Oct 2002 19:49:13 -0000	1.22
@@ -33,6 +33,9 @@
 	MessageSize *body_size;
 	MessageSize *partial_size;
 
+	time_t internal_date;
+	uoff_t full_virtual_size;
+
 	char *cached_body;
 	char *cached_bodystructure;
 	char *cached_envelope;
@@ -107,6 +110,8 @@
 	msg = p_new(pool, CachedMessage, 1);
 	msg->pool = pool;
 	msg->uid = uid;
+	msg->internal_date = (time_t)-1;
+	msg->full_virtual_size = (uoff_t)-1;
 
 	msg->next = cache->messages;
 	cache->messages = msg;
@@ -268,10 +273,17 @@
 		failed = value == NULL;
 	}
 
+	if ((fields & IMAP_CACHE_VIRTUAL_SIZE) &&
+	    msg->full_virtual_size == (uoff_t)-1) {
+		fields |= IMAP_CACHE_MESSAGE_HDR_SIZE |
+			IMAP_CACHE_MESSAGE_BODY_SIZE;
+	}
+
 	if ((fields & IMAP_CACHE_MESSAGE_BODY_SIZE) && msg->body_size == NULL) {
 		/* we don't have body size. and since we're already going
 		   to scan the whole message body, we might as well build
-		   the MessagePart. */
+		   the MessagePart. FIXME: this slows down things when it's
+		   not needed, do we really want to? */
                 fields |= IMAP_CACHE_MESSAGE_PART;
 	}
 
@@ -316,6 +328,12 @@
 		if (msg->part != NULL) {
 			/* easy, get it from root part */
 			*msg->hdr_size = msg->part->header_size;
+
+			if (msg->body_size == NULL) {
+				msg->body_size = p_new(msg->pool,
+						       MessageSize, 1);
+				*msg->body_size = msg->part->body_size;
+			}
 		} else {
 			/* need to do some light parsing */
 			if (imap_msgcache_get_inbuf(cache, 0)) {
@@ -327,20 +345,39 @@
 		}
 	}
 
+	if ((fields & IMAP_CACHE_VIRTUAL_SIZE) &&
+	    msg->full_virtual_size == (uoff_t)-1) {
+		if (msg->hdr_size == NULL || msg->body_size == NULL)
+			failed = TRUE;
+		else {
+			msg->full_virtual_size = msg->hdr_size->virtual_size +
+                                msg->body_size->virtual_size;
+		}
+	}
+
 	if (fields & IMAP_CACHE_MESSAGE_OPEN) {
 		/* this isn't needed for anything else than pre-opening the
 		   mail and seeing if it fails. */
 		failed = !imap_msgcache_get_inbuf(cache, 0);
 	}
 
+	if ((fields & IMAP_CACHE_INTERNALDATE) &&
+	    msg->internal_date == (time_t)-1) {
+		/* keep this last, since we may get it when mail file is
+		   opened. */
+		msg->internal_date =
+			cache->iface->get_internal_date(cache->context);
+		failed = msg->internal_date == (time_t)-1;
+	}
+
 	t_pop();
 	return !failed;
 }
 
 int imap_msgcache_open(ImapMessageCache *cache, unsigned int uid,
 		       ImapCacheField fields,
-		       uoff_t virtual_header_size, uoff_t virtual_body_size,
-		       void *context)
+		       uoff_t vp_header_size, uoff_t vp_body_size,
+		       uoff_t full_virtual_size, void *context)
 {
 	CachedMessage *msg;
 
@@ -352,20 +389,22 @@
 		cache->context = context;
 	}
 
-	if (virtual_header_size != 0 && msg->hdr_size == NULL) {
+	if (vp_header_size != (uoff_t)-1 && msg->hdr_size == NULL) {
 		/* physical size == virtual size */
 		msg->hdr_size = p_new(msg->pool, MessageSize, 1);
 		msg->hdr_size->physical_size = msg->hdr_size->virtual_size =
-			virtual_header_size;
+			vp_header_size;
 	}
 
-	if (virtual_body_size != 0 && msg->body_size == NULL) {
+	if (vp_body_size != (uoff_t)-1 && msg->body_size == NULL) {
 		/* physical size == virtual size */
 		msg->body_size = p_new(msg->pool, MessageSize, 1);
 		msg->body_size->physical_size = msg->body_size->virtual_size =
-			virtual_body_size;
+			vp_body_size;
 	}
 
+	msg->full_virtual_size = full_virtual_size;
+
 	return cache_fields(cache, fields);
 }
 
@@ -409,13 +448,25 @@
 
 MessagePart *imap_msgcache_get_parts(ImapMessageCache *cache)
 {
-	i_assert(cache->open_msg != NULL);
-
 	if (cache->open_msg->part == NULL)
 		cache_fields(cache, IMAP_CACHE_MESSAGE_PART);
 	return cache->open_msg->part;
 }
 
+uoff_t imap_msgcache_get_virtual_size(ImapMessageCache *cache)
+{
+	if (cache->open_msg->full_virtual_size == (uoff_t)-1)
+		cache_fields(cache, IMAP_CACHE_VIRTUAL_SIZE);
+	return cache->open_msg->full_virtual_size;
+}
+
+time_t imap_msgcache_get_internal_date(ImapMessageCache *cache)
+{
+	if (cache->open_msg->internal_date == (time_t)-1)
+		cache_fields(cache, IMAP_CACHE_INTERNALDATE);
+	return cache->open_msg->internal_date;
+}
+
 int imap_msgcache_get_rfc822(ImapMessageCache *cache, IBuffer **inbuf,
 			     MessageSize *hdr_size, MessageSize *body_size)
 {
@@ -491,6 +542,7 @@
 	*cr_skipped = FALSE;
 
 	msg = cache->open_msg;
+
 	if (msg->hdr_size == NULL) {
 		cache_fields(cache, IMAP_CACHE_MESSAGE_HDR_SIZE);
 		if (msg->hdr_size == NULL)

Index: imap-message-cache.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-message-cache.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- imap-message-cache.h	20 Oct 2002 00:17:21 -0000	1.11
+++ imap-message-cache.h	27 Oct 2002 19:49:13 -0000	1.12
@@ -12,14 +12,16 @@
 #include "message-parser.h"
 
 typedef enum {
-	IMAP_CACHE_BODY			= 0x01,
-	IMAP_CACHE_BODYSTRUCTURE	= 0x02,
-	IMAP_CACHE_ENVELOPE		= 0x04,
+	IMAP_CACHE_BODY			= 0x0001,
+	IMAP_CACHE_BODYSTRUCTURE	= 0x0002,
+	IMAP_CACHE_ENVELOPE		= 0x0004,
+	IMAP_CACHE_INTERNALDATE		= 0x0008,
+	IMAP_CACHE_VIRTUAL_SIZE		= 0x0010,
 
-	IMAP_CACHE_MESSAGE_OPEN		= 0x08,
-	IMAP_CACHE_MESSAGE_PART		= 0x10,
-	IMAP_CACHE_MESSAGE_HDR_SIZE	= 0x20,
-	IMAP_CACHE_MESSAGE_BODY_SIZE	= 0x40
+	IMAP_CACHE_MESSAGE_OPEN		= 0x0200,
+	IMAP_CACHE_MESSAGE_PART		= 0x0400,
+	IMAP_CACHE_MESSAGE_HDR_SIZE	= 0x0800,
+	IMAP_CACHE_MESSAGE_BODY_SIZE	= 0x0100
 } ImapCacheField;
 
 typedef struct {
@@ -33,6 +35,9 @@
 	const char *(*get_cached_field)(ImapCacheField field, void *context);
 	/* Returns MessagePart if it's already cached, or NULL. */
 	MessagePart *(*get_cached_parts)(Pool pool, void *context);
+
+	/* Returns message's internal date, or (time_t)-1 if error. */
+	time_t (*get_internal_date)(void *context);
 } ImapMessageCacheIface;
 
 typedef struct _ImapMessageCache ImapMessageCache;
@@ -41,14 +46,15 @@
 void imap_msgcache_clear(ImapMessageCache *cache);
 void imap_msgcache_free(ImapMessageCache *cache);
 
-/* Open the specified message. virtual_header/body_size may be 0
-   if it's not known. Returns TRUE if all specified fields were cached.
+/* Open the specified message. Set vp_*_size if both physical and virtual
+   sizes are same, otherwise (uoff_t)-1. If full_virtual_size isn't known,
+   set it to (uoff_t)-1. Returns TRUE if all specified fields were cached.
    Even if FALSE is returned, it's possible to use the cached data,
    imap_msgcache_get() just returns NULL for those that weren't. */
 int imap_msgcache_open(ImapMessageCache *cache, unsigned int uid,
 		       ImapCacheField fields,
-		       uoff_t virtual_header_size, uoff_t virtual_body_size,
-		       void *context);
+		       uoff_t vp_header_size, uoff_t vp_body_size,
+		       uoff_t full_virtual_size, void *context);
 
 /* Close the IOBuffer for opened message. */
 void imap_msgcache_close(ImapMessageCache *cache);
@@ -58,6 +64,12 @@
 
 /* Returns the root MessagePart for message, or NULL if failed. */
 MessagePart *imap_msgcache_get_parts(ImapMessageCache *cache);
+
+/* Returns the virtual size of message, or (uoff_t)-1 if failed. */
+uoff_t imap_msgcache_get_virtual_size(ImapMessageCache *cache);
+
+/* Returns the internal date of message, or (time_t)-1 if failed. */
+time_t imap_msgcache_get_internal_date(ImapMessageCache *cache);
 
 /* Returns TRUE if successful. If inbuf is not NULL, it's set to point to
    beginning of message, or to beginning of message body if hdr_size is NULL. */




More information about the dovecot-cvs mailing list