Lines Matching defs:bbox
54 struct virtual_backend_box *bbox);
67 struct virtual_backend_box *bbox,
74 if (!mail_set_uid(bbox->sync_mail, real_uid)) {
81 flags = mail_get_flags(bbox->sync_mail);
87 kw_names = mail_get_keywords(bbox->sync_mail);
111 virtual_backend_box_sync_mail_set(struct virtual_backend_box *bbox)
115 if (bbox->sync_mail == NULL) {
116 trans = mailbox_transaction_begin(bbox->box, 0, __func__);
117 bbox->sync_mail = mail_alloc(trans, 0, NULL);
156 struct virtual_backend_box *bbox, **bboxes;
234 if (virtual_sync_get_backend_box(mbox, name, &bbox) < 0)
238 if (bbox == NULL) {
244 bbox->mailbox_id = mailboxes[i].id;
245 bbox->sync_uid_validity = mailboxes[i].uid_validity;
246 bbox->ondisk_highest_modseq =
247 bbox->sync_highest_modseq =
249 bbox->sync_next_uid = mailboxes[i].next_uid;
250 bbox->sync_mailbox_idx1 = i+1;
361 struct virtual_backend_box *bbox;
389 bbox = virtual_backend_box_lookup(ctx->mbox, vrec->mailbox_id);
390 if (bbox == NULL)
392 if (!bbox->box->opened) {
393 if (virtual_backend_box_open(ctx->mbox, bbox) < 0) {
395 bbox->box);
399 virtual_backend_box_accessed(ctx->mbox, bbox);
402 virtual_backend_box_sync_mail_set(bbox);
403 if (!mail_set_uid(bbox->sync_mail, vrec->real_uid)) {
410 mail_expunge(bbox->sync_mail);
415 mail_update_flags(bbox->sync_mail,
420 mail_update_flags(bbox->sync_mail,
428 keywords = mailbox_keywords_create_valid(bbox->box,
434 mail_update_keywords(bbox->sync_mail,
494 static int virtual_sync_backend_box_init(struct virtual_backend_box *bbox)
503 trans = mailbox_transaction_begin(bbox->box, 0, __func__);
505 if (!bbox->search_args_initialized) {
506 mail_search_args_init(bbox->search_args, bbox->box, FALSE, NULL);
507 bbox->search_args_initialized = TRUE;
509 search_ctx = mailbox_search_init(trans, bbox->search_args, NULL,
515 bbox->search_result =
520 array_clear(&bbox->uids);
523 array_append(&bbox->uids, &uidmap, 1);
541 struct virtual_backend_box *bbox,
553 /* everything in removed_uids should exist in bbox->uids */
554 uidmap = array_get_modifiable(&bbox->uids, &rec_count);
558 if (!array_bsearch_insert_pos(&bbox->uids, &uids[0].seq1,
584 array_delete(&bbox->uids, dest, src - dest);
589 struct virtual_backend_box *bbox,
603 /* none of added_uids should exist in bbox->uids. find the position
605 uidmap = array_get_modifiable(&bbox->uids, &rec_count);
610 } else if (array_bsearch_insert_pos(&bbox->uids, &added_uids[0].seq1,
617 array_idx_clear(&bbox->uids, dest + add_count-1);
619 array_copy(&bbox->uids.arr, dest + add_count,
620 &bbox->uids.arr, dest, rec_count - dest);
622 uidmap = array_get_modifiable(&bbox->uids, &rec_count);
627 rec.rec.mailbox_id = bbox->mailbox_id;
649 struct virtual_backend_box *bbox,
659 vuid = array_bsearch(&bbox->uids, &uid,
674 virtual_sync_external_flags(ctx, bbox, vseq,
689 static void virtual_sync_bbox_uids_sort(struct virtual_backend_box *bbox)
692 array_sort(&bbox->uids, virtual_backend_uidmap_cmp);
693 bbox->uids_nonsorted = FALSE;
710 struct virtual_backend_box *bbox,
723 array_append(&bbox->uids, &uidmap, 1);
727 else if (mail_index_lookup_seq(bbox->box->view, real_uid, &seq))
735 struct virtual_backend_box *bbox,
745 array_clear(&bbox->uids);
748 i_assert(ctx->all_mails_prev_mailbox_id < bbox->mailbox_id);
752 if (sync_mail->vrec.mailbox_id != bbox->mailbox_id) {
753 if (sync_mail->vrec.mailbox_id < bbox->mailbox_id) {
762 virtual_sync_backend_add_vmsgs_results(ctx, bbox,
766 ctx->all_mails_prev_mailbox_id = bbox->mailbox_id;
776 if (vrec->mailbox_id == bbox->mailbox_id) {
778 bbox, vrec->real_uid, result, vseq);
782 virtual_sync_bbox_uids_sort(bbox);
786 struct virtual_backend_box *bbox)
791 struct mail_index_view *view = bbox->box->view;
800 if (!bbox->search_args_initialized) {
801 mail_search_args_init(bbox->search_args, bbox->box, FALSE, NULL);
802 bbox->search_args_initialized = TRUE;
804 result = mailbox_search_result_alloc(bbox->box, bbox->search_args,
808 virtual_sync_backend_handle_old_vmsgs(ctx, bbox, result);
820 if (bbox->sync_next_uid <= 1 ||
821 !mail_index_lookup_seq_range(view, 1, bbox->sync_next_uid-1,
827 if (bbox->sync_highest_modseq < old_highest_modseq) {
830 if (modseq > bbox->sync_highest_modseq) {
850 virtual_sync_mailbox_box_remove(ctx, bbox, &expunged_uids);
853 virtual_sync_mailbox_box_remove(ctx, bbox, &removed_uids);
856 seq_range_array_merge(&bbox->sync_pending_removes,
859 virtual_sync_mailbox_box_add(ctx, bbox, &added_uids);
860 virtual_sync_mailbox_box_update_flags(ctx, bbox, &flag_update_uids);
862 bbox->search_result = result;
866 static void virtual_sync_drop_existing(struct virtual_backend_box *bbox,
879 (void)array_bsearch_insert_pos(&bbox->uids, &add_uid,
882 uidmap = array_get_modifiable(&bbox->uids, &count);
902 static void virtual_sync_drop_nonexistent(struct virtual_backend_box *bbox,
916 (void)array_bsearch_insert_pos(&bbox->uids, &remove_uid,
920 uidmap = array_get_modifiable(&bbox->uids, &count);
944 struct virtual_backend_box *bbox)
952 mailbox_search_result_sync(bbox->search_result,
954 if (array_is_created(&bbox->sync_outside_expunges)) {
955 seq_range_array_remove_seq_range(&bbox->sync_outside_expunges,
958 &bbox->sync_outside_expunges);
959 array_clear(&bbox->sync_outside_expunges);
962 virtual_sync_drop_existing(bbox, &added_uids);
963 virtual_sync_drop_nonexistent(bbox, &removed_uids);
968 count1 = array_count(&bbox->sync_pending_removes);
972 array_append_array(&temp_uids, &bbox->sync_pending_removes);
974 &bbox->sync_pending_removes, &added_uids) > 0) {
984 seq_range_array_remove_seq_range(&bbox->sync_pending_removes,
988 virtual_sync_mailbox_box_remove(ctx, bbox,
991 seq_range_array_merge(&bbox->sync_pending_removes,
993 } else if (array_count(&bbox->sync_pending_removes) > 0) {
995 seq_range_array_merge(&bbox->sync_pending_removes,
997 virtual_sync_mailbox_box_remove(ctx, bbox,
998 &bbox->sync_pending_removes);
999 array_clear(&bbox->sync_pending_removes);
1001 virtual_sync_mailbox_box_remove(ctx, bbox, &removed_uids);
1003 virtual_sync_mailbox_box_add(ctx, bbox, &added_uids);
1006 static bool virtual_sync_find_seqs(struct virtual_backend_box *bbox,
1015 mail_index_lookup_uid(bbox->box->view, sync_rec->seq1, &uid1);
1016 mail_index_lookup_uid(bbox->box->view, sync_rec->seq2, &uid2);
1017 (void)array_bsearch_insert_pos(&bbox->uids, &uid1,
1021 uidmap = array_get_modifiable(&bbox->uids, &count);
1032 struct virtual_backend_box *bbox,
1039 mail_index_lookup_uid(bbox->box->view, sync_rec->seq1, &uid1);
1040 mail_index_lookup_uid(bbox->box->view, sync_rec->seq2, &uid2);
1044 (void)array_bsearch_insert_pos(&bbox->uids, &uid1,
1047 uidmap = array_get_modifiable(&bbox->uids, &count);
1056 struct virtual_backend_box *bbox,
1066 sync_ctx = mailbox_sync_init(bbox->box, sync_flags);
1067 virtual_backend_box_sync_mail_set(bbox);
1075 virtual_sync_expunge_add(ctx, bbox, &sync_rec);
1078 if (!virtual_sync_find_seqs(bbox, &sync_rec,
1081 uidmap = array_idx(&bbox->uids, 0);
1092 bbox->uids. */
1095 virtual_sync_external_flags(ctx, bbox, vseq,
1104 if (mailbox_get_last_mail_error(bbox->box) != MAIL_ERROR_NOTFOUND)
1107 virtual_sync_backend_box_deleted(ctx, bbox);
1114 struct virtual_backend_box *bbox)
1124 mailbox_get_open_status(bbox->box, STATUS_UIDVALIDITY |
1127 array_count(&bbox->sync_pending_removes) > 0 ? 0 :
1130 if (bbox->sync_uid_validity == status.uidvalidity &&
1131 bbox->sync_next_uid == status.uidnext &&
1132 bbox->sync_highest_modseq == status.highest_modseq &&
1133 bbox->ondisk_highest_modseq == wanted_ondisk_highest_modseq)
1137 bbox->sync_uid_validity = status.uidvalidity;
1138 bbox->sync_highest_modseq = status.highest_modseq;
1139 bbox->ondisk_highest_modseq = wanted_ondisk_highest_modseq;
1140 bbox->sync_next_uid = status.uidnext;
1148 mailbox.uid_validity = bbox->sync_uid_validity;
1149 mailbox.highest_modseq = bbox->ondisk_highest_modseq;
1150 mailbox.next_uid = bbox->sync_next_uid;
1152 i_assert(bbox->sync_mailbox_idx1 > 0);
1154 (bbox->sync_mailbox_idx1-1) * sizeof(mailbox);
1163 struct virtual_backend_box *bbox)
1172 array_foreach(&bbox->uids, uidmap)
1174 virtual_sync_mailbox_box_remove(ctx, bbox, &removed_uids);
1176 bbox->deleted = TRUE;
1181 struct virtual_backend_box *bbox,
1186 if (!bbox->box->opened)
1187 ret = virtual_backend_box_open(ctx->mbox, bbox);
1189 ret = mailbox_sync(bbox->box, sync_flags);
1191 if (mailbox_get_last_mail_error(bbox->box) != MAIL_ERROR_NOTFOUND)
1194 virtual_sync_backend_box_deleted(ctx, bbox);
1201 struct virtual_backend_box *bbox)
1207 if (bbox->deleted)
1212 virtual_backend_box_sync_mail_unset(bbox);
1218 if (bbox->search_result == NULL) {
1225 i_assert(array_count(&bbox->sync_pending_removes) == 0);
1226 if (bbox->box->opened || bbox->open_failed) {
1230 if ((ret = virtual_try_open_and_sync_backend_box(ctx, bbox, sync_flags)) <= 0)
1232 bbox->open_failed = FALSE;
1235 if (mailbox_get_status(bbox->box, STATUS_UIDVALIDITY |
1238 if (mailbox_get_last_mail_error(bbox->box) != MAIL_ERROR_NOTFOUND)
1241 virtual_sync_backend_box_deleted(ctx, bbox);
1244 if (status.uidvalidity == bbox->sync_uid_validity &&
1245 status.uidnext == bbox->sync_next_uid &&
1246 status.highest_modseq == bbox->sync_highest_modseq) {
1250 we'll still need to create the bbox->uids mapping
1252 if (array_count(&bbox->uids) == 0)
1253 virtual_sync_backend_handle_old_vmsgs(ctx, bbox, NULL);
1256 if (!bbox->box->opened) {
1258 if ((ret = virtual_try_open_and_sync_backend_box(ctx, bbox, sync_flags)) <= 0)
1262 virtual_backend_box_sync_mail_set(bbox);
1263 if (status.uidvalidity != bbox->sync_uid_validity) {
1266 ret = virtual_sync_backend_box_init(bbox);
1269 ret = virtual_sync_backend_box_continue(ctx, bbox);
1271 i_assert(bbox->search_result != NULL || ret < 0);
1274 i_assert(bbox->box->opened);
1276 ret = virtual_sync_backend_box_sync(ctx, bbox, sync_flags);
1278 virtual_sync_mailbox_box_update(ctx, bbox);
1283 virtual_sync_backend_ext_header(ctx, bbox);
1291 struct virtual_backend_box *bbox;
1318 bbox = NULL;
1323 if (bbox == NULL || bbox->mailbox_id != vrec->mailbox_id) {
1329 bbox = virtual_backend_box_lookup(ctx->mbox,
1331 if (bbox == NULL) {
1336 uidmap = array_get_modifiable(&bbox->uids,
1339 add_rec.rec.mailbox_id = bbox->mailbox_id;
1340 bbox->sync_seen = TRUE;
1358 if (bbox->search_result == NULL) {
1362 virtual_sync_external_flags(ctx, bbox, vseq,
1423 struct virtual_backend_box *bbox;
1430 for (bbox = NULL, i = 0; i < count; i++) {
1433 if (bbox == NULL || bbox->mailbox_id != vrec->mailbox_id) {
1434 bbox = virtual_backend_box_lookup(ctx->mbox,
1436 if (!bbox->box->opened &&
1437 virtual_backend_box_open(ctx->mbox, bbox) < 0)
1439 virtual_backend_box_sync_mail_set(bbox);
1441 if (!mail_set_uid(bbox->sync_mail, vrec->real_uid)) {
1445 } else if (mail_get_received_date(bbox->sync_mail,
1447 if (!bbox->sync_mail->expunged)
1462 struct virtual_backend_box *bbox;
1486 for (bbox = NULL, i = 0; i < count; i++) {
1488 if (bbox == NULL || bbox->mailbox_id != vrec->mailbox_id) {
1489 bbox = virtual_backend_box_lookup(ctx->mbox,
1491 if (!bbox->box->opened &&
1492 virtual_backend_box_open(ctx->mbox, bbox) < 0)
1494 virtual_backend_box_sync_mail_set(bbox);
1500 virtual_sync_external_flags(ctx, bbox, vseq, vrec->real_uid);
1510 for (bbox = NULL, i = 0; i < count; i++) {
1512 if (bbox == NULL || bbox->mailbox_id != vrec->mailbox_id) {
1513 bbox = virtual_backend_box_lookup(ctx->mbox,
1517 if (!array_bsearch_insert_pos(&bbox->uids, &vrec->real_uid,
1521 uidmap = array_idx_modifiable(&bbox->uids, idx);
1533 struct virtual_backend_box *bbox = NULL;
1562 if (bbox == NULL || bbox->mailbox_id != vrec->mailbox_id) {
1563 bbox = virtual_backend_box_lookup(ctx->mbox,
1565 if (bbox == NULL) {
1570 array_append(&bbox->uids, &uidmap, 1);
1571 bbox->uids_nonsorted = TRUE;
1584 struct virtual_backend_box *bbox = NULL;
1600 if (bbox == NULL || bbox->mailbox_id != vrec->mailbox_id) {
1601 bbox = virtual_backend_box_lookup(mbox,
1603 if (!array_is_created(&bbox->sync_outside_expunges))
1604 i_array_init(&bbox->sync_outside_expunges, 32);
1606 seq_range_array_add(&bbox->sync_outside_expunges,