view src/lib-imap/imap-message-cache.h @ 160:ff05b320482c HEAD

Bigger changes.. full_virtual_size was removed from index record and MessagePart caching is now forced. Also added per-message flags, including binary flags which can be used to check if CRs need to be inserted into message data. Added mbox-rewrite support which can be used to write out mbox file with updated flags. This still has the problem of being able to read changed custom flags, that'll require another bigger change. There's also several other mostly mbox related fixes.
author Timo Sirainen <tss@iki.fi>
date Fri, 06 Sep 2002 16:43:58 +0300
parents 5fe3e04ca8d9
children 1f0e7229ee58
line wrap: on
line source

#ifndef __IMAP_MESSAGE_CACHE_H
#define __IMAP_MESSAGE_CACHE_H

/* IMAP message cache. Caches are mailbox-specific and must be cleared
   if UID validity changes. Also if message data may have changed,
   imap_msgcache_close() must be called.

   Caching is mostly done to avoid parsing the same message multiple times
   when client fetches the message in parts.
*/

#include "message-parser.h"

typedef enum {
	IMAP_CACHE_BODY			= 0x01,
	IMAP_CACHE_BODYSTRUCTURE	= 0x02,
	IMAP_CACHE_ENVELOPE		= 0x04,

	IMAP_CACHE_MESSAGE_OPEN		= 0x08,
	IMAP_CACHE_MESSAGE_PART		= 0x10,
	IMAP_CACHE_MESSAGE_HDR_SIZE	= 0x20,
	IMAP_CACHE_MESSAGE_BODY_SIZE	= 0x40
} ImapCacheField;

typedef struct {
	/* Open mail for reading. */
	IOBuffer *(*open_mail)(void *context);
	/* Rewind input buffer to beginning, possibly closing the old buffer
	   if it can't directly be rewinded. */
	IOBuffer *(*inbuf_rewind)(IOBuffer *inbuf, void *context);

	/* Returns field if it's already cached, or NULL. */
	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);
} ImapMessageCacheIface;

typedef struct _ImapMessageCache ImapMessageCache;

ImapMessageCache *imap_msgcache_alloc(ImapMessageCacheIface *iface);
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. */
void imap_msgcache_open(ImapMessageCache *cache, unsigned int uid,
			ImapCacheField fields,
			uoff_t virtual_header_size, uoff_t virtual_body_size,
			void *context);

/* Close the IOBuffer for opened message. */
void imap_msgcache_close(ImapMessageCache *cache);

/* Returns the field from cache, or NULL if it's not cached. */
const char *imap_msgcache_get(ImapMessageCache *cache, ImapCacheField field);

/* Returns the root MessagePart for message, or NULL if failed. */
MessagePart *imap_msgcache_get_parts(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. */
int imap_msgcache_get_rfc822(ImapMessageCache *cache, IOBuffer **inbuf,
			     MessageSize *hdr_size, MessageSize *body_size);

/* Returns TRUE if successful. *inbuf is set to point to the first non-skipped
   character. size is set to specify the full size of message. */
int imap_msgcache_get_rfc822_partial(ImapMessageCache *cache,
				     uoff_t virtual_skip,
				     uoff_t max_virtual_size,
				     int get_header, MessageSize *size,
				     IOBuffer **inbuf);

/* Returns TRUE if successful. *inbuf is set to point to beginning of
   message. */
int imap_msgcache_get_data(ImapMessageCache *cache, IOBuffer **inbuf);

#endif