bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */
ab170d6cf8aeb515bac7c07b37e525cbad96c299Timo Sirainen root's first children
ab170d6cf8aeb515bac7c07b37e525cbad96c299Timo Sirainen children's first children
ab170d6cf8aeb515bac7c07b37e525cbad96c299Timo Sirainen root's next children
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen unsigned int flags
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen (not root part)
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen uoff_t physical_pos
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen uoff_t header_physical_size
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen uoff_t header_virtual_size
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen uoff_t body_physical_size
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen uoff_t body_virtual_size
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen (flags & (MESSAGE_PART_FLAG_TEXT | MESSAGE_PART_FLAG_MESSAGE_RFC822))
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen unsigned int body_lines
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen (flags & (MESSAGE_PART_FLAG_MULTIPART | MESSAGE_PART_FLAG_MESSAGE_RFC822))
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen unsigned int children_count
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainenstatic void part_serialize(struct message_part *part, buffer_t *dest,
ab170d6cf8aeb515bac7c07b37e525cbad96c299Timo Sirainen /* create serialized part */
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen buffer_append(dest, &part->flags, sizeof(part->flags));
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen buffer_append(dest, &part->header_size.physical_size,
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen buffer_append(dest, &part->header_size.virtual_size,
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen buffer_append(dest, &part->body_size.physical_size,
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen buffer_append(dest, &part->body_size.virtual_size,
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen if ((part->flags & (MESSAGE_PART_FLAG_MULTIPART |
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenvoid message_part_serialize(struct message_part *part, buffer_t *dest)
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenstatic bool read_next(struct deserialize_context *ctx,
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenmessage_part_deserialize_part(struct deserialize_context *ctx,
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen struct message_part *p, *part, *first_part, **next_part;
2efe6c8cb2773ac6316638fd9a61d7e8c908153fTimo Sirainen part = p_new(ctx->pool, struct message_part, 1);
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen if (!read_next(ctx, &part->flags, sizeof(part->flags)))
2efe6c8cb2773ac6316638fd9a61d7e8c908153fTimo Sirainen ctx->error = "physical_pos less than expected";
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen if (!read_next(ctx, &part->header_size.physical_size,
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen if (!read_next(ctx, &part->header_size.virtual_size,
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen ctx->error = "header_size.virtual_size too small";
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen if (!read_next(ctx, &part->body_size.physical_size,
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen if (!read_next(ctx, &part->body_size.virtual_size,
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen ctx->error = "body_size.virtual_size too small";
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen if ((part->flags & (MESSAGE_PART_FLAG_MULTIPART |
23bdbb7b1831785c6ba6df190f6369da882d2b9dTimo Sirainen if ((part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) != 0) {
2efe6c8cb2773ac6316638fd9a61d7e8c908153fTimo Sirainen /* Only one child is possible */
2efe6c8cb2773ac6316638fd9a61d7e8c908153fTimo Sirainen "message/rfc822 part has no children";
2efe6c8cb2773ac6316638fd9a61d7e8c908153fTimo Sirainen "has multiple children";
a4f588460ae94749573097e04392780e17f7fcb2Timo Sirainen /* our children must be after our physical_pos+header
a4f588460ae94749573097e04392780e17f7fcb2Timo Sirainen and the last child must be within our size. */
a4f588460ae94749573097e04392780e17f7fcb2Timo Sirainen pos = ctx->pos + part->body_size.physical_size;
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen "child part location exceeds our size";
a9c63bb1197ca14d17e081626df510b23d617899Timo Sirainen ctx->pos = pos; /* save it for above check for parent */
10da1ab399797ce44d37e0c464966e0a7cd5ff01Timo Sirainenmessage_part_deserialize(pool_t pool, const void *data, size_t size,
10da1ab399797ce44d37e0c464966e0a7cd5ff01Timo Sirainen const char **error_r)