예제 #1
0
void dsync_brain_send_mailbox_tree(struct dsync_brain *brain)
{
	struct dsync_mailbox_node *node;
	enum dsync_ibc_send_ret ret;
	const char *full_name;
	char sep[2];

	sep[0] = brain->hierarchy_sep; sep[1] = '\0';
	while (dsync_mailbox_tree_iter_next(brain->local_tree_iter,
					    &full_name, &node)) {
		T_BEGIN {
			const char *const *parts;

			if (brain->debug) {
				i_debug("brain %c: Local mailbox tree: %s %s",
					brain->master_brain ? 'M' : 'S', full_name,
					dsync_mailbox_node_to_string(node));
			}

			parts = t_strsplit(full_name, sep);
			ret = dsync_ibc_send_mailbox_tree_node(brain->ibc,
							       parts, node);
		} T_END;
		if (ret == DSYNC_IBC_SEND_RET_FULL)
			return;
	}
	dsync_mailbox_tree_iter_deinit(&brain->local_tree_iter);
	dsync_ibc_send_end_of_list(brain->ibc, DSYNC_IBC_EOL_MAILBOX_TREE);

	brain->state = DSYNC_STATE_SEND_MAILBOX_TREE_DELETES;
}
예제 #2
0
static void dsync_brain_send_mailbox_attribute(struct dsync_brain *brain)
{
	const struct dsync_mailbox_attribute *attr;

	while ((attr = dsync_mailbox_export_next_attr(brain->box_exporter)) != NULL) {
		if (dsync_ibc_send_mailbox_attribute(brain->ibc, attr) == 0)
			return;
	}
	dsync_ibc_send_end_of_list(brain->ibc, DSYNC_IBC_EOL_MAILBOX_ATTRIBUTE);
	brain->box_send_state = DSYNC_BOX_STATE_CHANGES;
}
예제 #3
0
static void dsync_brain_send_mail_change(struct dsync_brain *brain)
{
	const struct dsync_mail_change *change;

	while ((change = dsync_mailbox_export_next(brain->box_exporter)) != NULL) {
		if (dsync_ibc_send_change(brain->ibc, change) == 0)
			return;
	}
	dsync_ibc_send_end_of_list(brain->ibc, DSYNC_IBC_EOL_MAIL_CHANGES);
	if (brain->mail_requests && brain->box_importer != NULL)
		brain->box_send_state = DSYNC_BOX_STATE_MAIL_REQUESTS;
	else
		brain->box_send_state = DSYNC_BOX_STATE_MAILS;
}
예제 #4
0
void dsync_brain_master_send_mailbox(struct dsync_brain *brain)
{
	struct dsync_mailbox dsync_box;
	struct mailbox *box;

	i_assert(brain->master_brain);
	i_assert(brain->box == NULL);

	if (!dsync_brain_next_mailbox(brain, &box, &dsync_box)) {
		brain->state = DSYNC_STATE_DONE;
		dsync_ibc_send_end_of_list(brain->ibc);
		return;
	}

	/* start exporting this mailbox (wait for remote to start importing) */
	dsync_ibc_send_mailbox(brain->ibc, &dsync_box);
	dsync_brain_sync_mailbox_init(brain, box, &dsync_box, TRUE);
	brain->state = DSYNC_STATE_SYNC_MAILS;
}
예제 #5
0
static bool dsync_brain_send_mail_request(struct dsync_brain *brain)
{
	const struct dsync_mail_request *request;

	i_assert(brain->mail_requests);

	while ((request = dsync_mailbox_import_next_request(brain->box_importer)) != NULL) {
		if (dsync_ibc_send_mail_request(brain->ibc, request) == 0)
			return TRUE;
	}
	if (brain->box_recv_state < DSYNC_BOX_STATE_MAIL_REQUESTS)
		return FALSE;

	dsync_ibc_send_end_of_list(brain->ibc, DSYNC_IBC_EOL_MAIL_REQUESTS);
	if (brain->box_exporter != NULL)
		brain->box_send_state = DSYNC_BOX_STATE_MAILS;
	else {
		i_assert(brain->box_recv_state != DSYNC_BOX_STATE_DONE);
		brain->box_send_state = DSYNC_BOX_STATE_DONE;
	}
	return TRUE;
}
예제 #6
0
static bool dsync_brain_send_mail(struct dsync_brain *brain)
{
	const struct dsync_mail *mail;

	if (brain->mail_requests &&
	    brain->box_recv_state < DSYNC_BOX_STATE_MAILS) {
		/* wait for mail requests to finish. we could already start
		   exporting, but then we're going to do quite a lot of
		   separate searches. especially with pipe backend we'd do
		   a separate search for each mail. */
		return FALSE;
	}

	while ((mail = dsync_mailbox_export_next_mail(brain->box_exporter)) != NULL) {
		if (dsync_ibc_send_mail(brain->ibc, mail) == 0)
			return TRUE;
	}

	brain->box_send_state = DSYNC_BOX_STATE_DONE;
	dsync_ibc_send_end_of_list(brain->ibc, DSYNC_IBC_EOL_MAILS);

	dsync_brain_sync_half_finished(brain);
	return TRUE;
}
예제 #7
0
static void dsync_brain_send_end_of_list(struct dsync_brain *brain,
					 enum dsync_ibc_eol_type type)
{
	i_assert(!brain->failed);
	dsync_ibc_send_end_of_list(brain->ibc, type);
}