Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

message.c: fix reading cached bodystructure for "message/global" #4988

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions imap/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -4425,7 +4425,8 @@ static int parse_mime_params(struct protstream *prot, struct param **prev)
return EOF;
}

static int parse_bodystructure_part(struct protstream *prot, struct body *body, const char *part_id)
static int parse_bodystructure_part(struct protstream *prot, struct body *body,
const char *part_id, uint16_t cache_version)
{
int c;
int r = 0;
Expand Down Expand Up @@ -4453,7 +4454,7 @@ static int parse_bodystructure_part(struct protstream *prot, struct body *body,
buf_printf(&buf, "%d", body->numparts);
char *part_id = buf_release(&buf);
struct body *subbody = &body->subpart[body->numparts-1];
r = parse_bodystructure_part(prot, subbody, part_id);
r = parse_bodystructure_part(prot, subbody, part_id, cache_version);
subbody->part_id = part_id;
if (r) goto out;

Expand Down Expand Up @@ -4511,7 +4512,11 @@ static int parse_bodystructure_part(struct protstream *prot, struct body *body,
body->content_lines = atoi(buf_cstring(&buf));
}

else if (body_is_rfc822(body)) {
else if ((body_is_rfc822(body) && cache_version >= 13) ||
// Cache versions < 13 only handled message/rfc822.
(!strcasecmp(body->type, "MESSAGE") &&
!strcasecmp(body->subtype, "RFC822"))) {

body->numparts = 1;
body->subpart = xzmalloc(sizeof(struct body));

Expand All @@ -4520,7 +4525,7 @@ static int parse_bodystructure_part(struct protstream *prot, struct body *body,
if (r) goto out;

/* process body */
r = parse_bodystructure_part(prot, body->subpart, part_id);
r = parse_bodystructure_part(prot, body->subpart, part_id, cache_version);
if (r) goto out;

/* skip trailing space (parse_bs_part doesn't eat it) */
Expand Down Expand Up @@ -4584,7 +4589,10 @@ static int parse_bodystructure_sections(const char **cachestrp, const char *cach
goto done;
}

if (body_is_rfc822(body)) {
if ((body_is_rfc822(body) && cache_version >= 13) ||
// Cache versions < 13 only handled message/rfc822.
(!strcasecmp(body->type, "MESSAGE") &&
!strcasecmp(body->subtype, "RFC822"))) {

if (strcmp(body->subpart->type, "MULTIPART") == 0) {

Expand Down Expand Up @@ -4820,7 +4828,7 @@ static int message_parse_cbodystructure(message_t *m)
return IMAP_MAILBOX_BADFORMAT;

m->body = xzmalloc(sizeof(struct body));
r = parse_bodystructure_part(prot, m->body, NULL);
r = parse_bodystructure_part(prot, m->body, NULL, m->record.cache_version);
if (r) {
xsyslog(LOG_ERR, "IOERROR: error parsing body structure",
"mailbox=<%s> record_uid=<%u>, cacheitem=<%.*s>",
Expand Down