i_assert(size < SSIZE_T_MAX);
- /* Append at the end of X-Keywords header,
- or X-UID if it doesn't exist */
- start_pos = ctx->hdr_pos[MBOX_HDR_X_KEYWORDS] != (size_t)-1 ?
- ctx->hdr_pos[MBOX_HDR_X_KEYWORDS] :
- ctx->hdr_pos[MBOX_HDR_X_UID];
+ if (ctx->pseudo)
+ start_pos = ctx->hdr_pos[MBOX_HDR_X_IMAPBASE];
+ else {
+ /* Append at the end of X-Keywords header,
+ or X-UID if it doesn't exist */
+ start_pos = ctx->hdr_pos[MBOX_HDR_X_KEYWORDS] != (size_t)-1 ?
+ ctx->hdr_pos[MBOX_HDR_X_KEYWORDS] :
+ ctx->hdr_pos[MBOX_HDR_X_UID];
+ }
+ i_assert(start_pos != (size_t)-1);
data = str_data(ctx->header);
data_size = str_len(ctx->header);
/* mbox_sync_parse_next_mail() checks that UIDs are growing,
so we have to fool it. */
old_prev_msg_uid = sync_ctx->prev_msg_uid;
- sync_ctx->prev_msg_uid = mails[idx].uid-1;
+ sync_ctx->prev_msg_uid = mails[idx].uid == 0 ? 0 : mails[idx].uid-1;
sync_ctx->dest_first_mail = mails[idx].from_offset == 0;
mbox_sync_parse_next_mail(sync_ctx->input, &mail_ctx);
/* after expunge the next mail must have been missing space, or we
would have moved it backwards already */
- i_assert(mails[0].space < 0 || mails[0].uid == 0);
+ i_assert(mails[0].space < 0 || (mails[0].flags & MBOX_EXPUNGED) != 0);
/* start moving backwards. */
do {
space_diff = mails[idx].space;
end_offset = mails[idx].offset + mails[idx].space;
- if (mails[idx].uid != 0) {
+ if ((mails[idx].flags & MBOX_EXPUNGED) == 0) {
space_diff -= extra_per_mail;
end_offset -= extra_per_mail;
mails[idx].space = extra_per_mail;
}
idx--;
- if (mails[idx].space <= 0 && mails[idx].uid != 0) {
+ if (mails[idx].space <= 0 &&
+ (mails[idx].flags & MBOX_EXPUNGED) == 0) {
/* offset points to beginning of headers. read the
header again, update it and give enough space to
fill space_diff */
struct mbox_sync_mail mail;
memset(&mail, 0, sizeof(mail));
+ mail.flags = MBOX_EXPUNGED;
mail.offset = mail_ctx->from_offset -
sync_ctx->expunged_space;
mail.space = sync_ctx->expunged_space;
while ((ret = mbox_sync_read_next_mail(sync_ctx, mail_ctx)) > 0) {
uid = mail_ctx->mail.uid;
+ if (mail_ctx->pseudo)
+ uid = 0;
+
/* get all sync records related to this message */
if (mbox_sync_read_index_syncs(sync_ctx, uid, &expunged) < 0)
return -1;
rec = NULL;
- if (uid != 0 && !mail_ctx->pseudo &&
- sync_ctx->ibox->md5hdr_extra_idx == 0) {
+ if (uid != 0 && sync_ctx->ibox->md5hdr_extra_idx == 0) {
ret = mbox_sync_read_index_rec(sync_ctx, uid, &rec);
if (ret < 0)
return -1;
uid = 0;
}
- if (uid == 0 && sync_ctx->ibox->mbox_readonly) {
+ if (uid == 0 && sync_ctx->ibox->mbox_readonly &&
+ !mail_ctx->pseudo) {
/* Use MD5 sums */
if (sync_ctx->ibox->md5hdr_extra_idx == 0) {
sync_ctx->ibox->md5hdr_extra_idx =
uid = rec->uid;
}
- if (uid == 0) {
+ if (uid == 0 && !mail_ctx->pseudo) {
/* missing/broken X-UID. all the rest of the mails
need new UIDs. */
while (sync_ctx->idx_seq <= messages_count) {
return ret;
}
- if (!expunged && !mail_ctx->pseudo) {
- if (mbox_sync_update_index(sync_ctx, mail_ctx,
- rec) < 0)
- return -1;
+ if (!mail_ctx->pseudo) {
+ if (!expunged) {
+ if (mbox_sync_update_index(sync_ctx, mail_ctx,
+ rec) < 0)
+ return -1;
+ }
+ sync_ctx->idx_seq++;
}
- sync_ctx->idx_seq++;
istream_raw_mbox_next(sync_ctx->input,
mail_ctx->mail.body_size);