[dovecot-cvs] dovecot/src/lib-mail message-part-serialize.c, 1.19,
1.20 message-part-serialize.h, 1.9, 1.10
cras at dovecot.org
cras at dovecot.org
Fri Sep 10 14:25:35 EEST 2004
Update of /var/lib/cvs/dovecot/src/lib-mail
In directory talvi:/tmp/cvs-serv32504/lib-mail
Modified Files:
message-part-serialize.c message-part-serialize.h
Log Message:
When using cached message_parts, update the header size with mbox since it
may change. Fixes BODY[1] etc. fetches giving corrupted replies.
Index: message-part-serialize.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/message-part-serialize.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- message-part-serialize.c 2 Sep 2003 22:33:33 -0000 1.19
+++ message-part-serialize.c 10 Sep 2004 11:25:33 -0000 1.20
@@ -240,11 +240,26 @@
return TRUE;
}
-struct message_part *message_part_deserialize(pool_t pool, const void *data,
- size_t size, const char **error)
+static void
+message_parts_update_physical_pos(struct message_part *parent, off_t diff)
+{
+ struct message_part *part;
+
+ for (part = parent->children; part != NULL; part = part->next) {
+ part->physical_pos += diff;
+ if (part->children != NULL)
+ message_parts_update_physical_pos(part, diff);
+ }
+}
+
+struct message_part *
+message_part_deserialize(pool_t pool, const void *data, size_t size,
+ const struct message_size *new_hdr_size,
+ const char **error_r)
{
struct deserialize_context ctx;
struct message_part *part;
+ off_t diff;
memset(&ctx, 0, sizeof(ctx));
ctx.pool = pool;
@@ -252,58 +267,29 @@
ctx.end = ctx.data + size;
if (!message_part_deserialize_part(&ctx, NULL, 1, &part)) {
- *error = ctx.error;
+ *error_r = ctx.error;
return NULL;
}
if (ctx.data != ctx.end) {
- *error = "Too much data";
+ *error_r = "Too much data";
return NULL;
}
- return part;
-}
-
-int message_part_deserialize_size(const void *data, size_t size,
- struct message_size *hdr_size,
- struct message_size *body_size)
-{
- const unsigned char *buf = data;
- unsigned int flags;
-
- /* make sure it looks valid */
- if (size < MINIMUM_SERIALIZED_SIZE)
- return FALSE;
-
- memcpy(&flags, buf, sizeof(flags));
- buf += sizeof(flags);
-
- if (hdr_size == NULL)
- buf += sizeof(uoff_t) * 2;
- else {
- memcpy(&hdr_size->physical_size, buf, sizeof(uoff_t));
- buf += sizeof(uoff_t);
- memcpy(&hdr_size->virtual_size, buf, sizeof(uoff_t));
- buf += sizeof(uoff_t);
- hdr_size->lines = 0;
- }
-
- if (body_size != NULL) {
- memcpy(&body_size->physical_size, buf, sizeof(uoff_t));
- buf += sizeof(uoff_t);
- memcpy(&body_size->virtual_size, buf, sizeof(uoff_t));
- buf += sizeof(uoff_t);
-
- if ((flags & (MESSAGE_PART_FLAG_TEXT |
- MESSAGE_PART_FLAG_MESSAGE_RFC822)) == 0)
- body_size->lines = 0;
- else {
- if (size < MINIMUM_SERIALIZED_SIZE +
- sizeof(unsigned int))
- return FALSE;
- memcpy(&body_size->lines, buf, sizeof(unsigned int));
+ if (new_hdr_size != NULL) {
+ if (new_hdr_size->virtual_size !=
+ part->header_size.virtual_size) {
+ part->header_size.virtual_size =
+ new_hdr_size->virtual_size;
+ }
+ if (new_hdr_size->physical_size !=
+ part->header_size.physical_size) {
+ diff = new_hdr_size->physical_size -
+ part->header_size.physical_size;
+ part->header_size.physical_size += diff;
+ message_parts_update_physical_pos(part, diff);
}
}
- return TRUE;
+ return part;
}
Index: message-part-serialize.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/message-part-serialize.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- message-part-serialize.h 2 Sep 2003 22:33:33 -0000 1.9
+++ message-part-serialize.h 10 Sep 2004 11:25:33 -0000 1.10
@@ -8,13 +8,11 @@
void message_part_serialize(struct message_part *part, buffer_t *dest);
/* Generate struct message_part from serialized data. Returns NULL and sets
- error if any problems are detected. */
-struct message_part *message_part_deserialize(pool_t pool, const void *data,
- size_t size, const char **error);
-
-/* Get message size from serialized struct message_part data. */
-int message_part_deserialize_size(const void *data, size_t size,
- struct message_size *hdr_size,
- struct message_size *body_size);
+ error if any problems are detected. If cache header size is unreliable
+ (eg. with mbox), you can give a new header size which will be used. */
+struct message_part *
+message_part_deserialize(pool_t pool, const void *data, size_t size,
+ const struct message_size *new_hdr_size,
+ const char **error_r);
#endif
More information about the dovecot-cvs
mailing list