[dovecot-cvs] dovecot/src/lib-imap imap-bodystructure.c,1.43,1.44 imap-bodystructure.h,1.7,1.8

cras at procontrol.fi cras at procontrol.fi
Wed Aug 20 05:41:32 EEST 2003


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

Modified Files:
	imap-bodystructure.c imap-bodystructure.h 
Log Message:
If BODY/BODYSTRUCTURE is requested with some other headers, parse the
headers only once. If body contains multiple MIME parts, cache the internal
MIME structure so BODY[part] fetching doesn't need to parse it again.



Index: imap-bodystructure.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-bodystructure.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- imap-bodystructure.c	6 Aug 2003 14:39:04 -0000	1.43
+++ imap-bodystructure.c	20 Aug 2003 01:41:30 -0000	1.44
@@ -20,7 +20,7 @@
 
 struct message_part_body_data {
 	pool_t pool;
-	string_t *str;
+	string_t *str; /* temporary */
 	char *content_type, *content_subtype;
 	char *content_type_params;
 	char *content_transfer_encoding;
@@ -36,6 +36,12 @@
 	unsigned int charset_found:1;
 };
 
+struct imap_bodystructure_parse_ctx {
+	pool_t pool;
+	int extended;
+        struct message_part *root;
+};
+
 static void part_write_bodystructure(struct message_part *part,
 				     string_t *str, int extended);
 
@@ -235,10 +241,9 @@
 	}
 }
 
-static void parse_header(struct message_part *part,
-                         struct message_header_line *hdr, void *context)
+void imap_bodystructure_parse_header(pool_t pool, struct message_part *part,
+				     struct message_header_line *hdr)
 {
-	pool_t pool = context;
 	struct message_part_body_data *part_data;
 	struct message_part_envelope_data *envelope;
 	int parent_rfc822;
@@ -284,26 +289,6 @@
 	t_pop();
 }
 
-static void part_parse_headers(struct message_part *part, struct istream *input,
-			       uoff_t start_offset, pool_t pool)
-{
-	while (part != NULL) {
-		/* note that we want to parse the header of all
-		   the message parts, multiparts too. */
-		i_assert(part->physical_pos >= input->v_offset - start_offset);
-		i_stream_skip(input, part->physical_pos -
-			      (input->v_offset - start_offset));
-
-		message_parse_header(part, input, NULL, parse_header, pool);
-		if (part->children != NULL) {
-			part_parse_headers(part->children, input,
-					   start_offset, pool);
-		}
-
-		part = part->next;
-	}
-}
-
 static void part_write_body_multipart(struct message_part *part,
 				      string_t *str, int extended)
 {
@@ -501,21 +486,13 @@
 	}
 }
 
-const char *imap_part_get_bodystructure(pool_t pool, struct message_part **part,
-					struct istream *input, int extended)
+const char *imap_bodystructure_parse_finish(struct message_part *root,
+					    int extended)
 {
 	string_t *str;
-	uoff_t start_offset;
-
-	if (*part == NULL)
-		*part = message_parse(pool, input, parse_header, pool);
-	else {
-		start_offset = input->v_offset;
-		part_parse_headers(*part, input, start_offset, pool);
-	}
 
 	str = t_str_new(2048);
-	part_write_bodystructure(*part, str, extended);
+	part_write_bodystructure(root, str, extended);
 	return str_c(str);
 }
 

Index: imap-bodystructure.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-bodystructure.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- imap-bodystructure.h	20 Jan 2003 13:54:42 -0000	1.7
+++ imap-bodystructure.h	20 Aug 2003 01:41:30 -0000	1.8
@@ -2,13 +2,16 @@
 #define __IMAP_BODYSTRUCTURE_H
 
 struct message_part;
+struct message_header_line;
 
-/* If *part is non-NULL, it's used as base for building the body structure.
-   Otherwise it's set to the root message_part and parsed. pool is used only
-   for allocating message_part, not the return value which is from data
-   stack. */
-const char *imap_part_get_bodystructure(pool_t pool, struct message_part **part,
-					struct istream *input, int extended);
+struct imap_bodystructure_parse_ctx;
+
+/* Parse a single header. Note that this modifies part->context. */
+void imap_bodystructure_parse_header(pool_t pool, struct message_part *part,
+				     struct message_header_line *hdr);
+
+const char *imap_bodystructure_parse_finish(struct message_part *root,
+					    int extended);
 
 /* Return BODY part from BODYSTRUCTURE */
 const char *imap_body_parse_from_bodystructure(const char *bodystructure);



More information about the dovecot-cvs mailing list