Skip to content

Commit

Permalink
Merge pull request #4939 from ksmurchison/user_rename_nosplitconv
Browse files Browse the repository at this point in the history
imapd.c: don't split conversations when renaming a user
  • Loading branch information
ksmurchison committed Jun 20, 2024
2 parents c0fe722 + 63ad36c commit e862ccc
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
64 changes: 64 additions & 0 deletions cassandane/Cassandane/Cyrus/Conversations.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1108,4 +1108,68 @@ sub test_rename_between_users
$self->assert_str_equals('-', $mfolders->[1]);
}

#
# Test user rename without splitting conversations
#
sub test_rename_user_nosplitconv
:AllowMoves :Replication
{
my ($self) = @_;

xlog $self, "Test user rename without splitting conversations";

my %exp;

# check IMAP server has the XCONVERSATIONS capability
my $master_store = $self->{master_store};
$self->assert($master_store->get_client()->capability()->{xconversations});

$master_store->set_fetch_attributes('uid', 'cid', 'basecid');

xlog $self, "generating message A";
$exp{A} = $self->make_message("Message A", store => $master_store);
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid());
$self->check_messages(\%exp);

xlog $self, "generating replies";
for (1..20) {
$exp{"A$_"} = $self->make_message("Re: Message A",
references => [ $exp{A} ],
store => $master_store);
$exp{"A$_"}->set_attributes(uid => 1+$_, cid => $exp{A}->make_cid());
}

my $talk = $master_store->get_client();
$talk->create('foo');
$talk->copy('1:*', 'foo');

$self->check_messages(\%exp, keyed_on => 'uid', store => $master_store);
$self->check_conversations();

$self->run_replication();
$self->check_replication('cassandane');

# Reduce the conversation thread size
my $config = $self->{instance}->{config};
$config->set(conversations_max_thread => 5);
$config->generate($self->{instance}->_imapd_conf());

$config = $self->{replica}->{config};
$config->set(conversations_max_thread => 5);
$config->generate($self->{replica}->_imapd_conf());

# Rename the user
my $admintalk = $self->{adminstore}->get_client();
my $res = $admintalk->rename('user.cassandane', 'user.newuser');
$self->assert(not $admintalk->get_last_error());

$self->{adminstore}->set_folder("user.newuser");
$self->{adminstore}->set_fetch_attributes('uid', 'cid', 'basecid');
$self->check_messages(\%exp, keyed_on => 'uid', store => $self->{adminstore});
$self->check_conversations();

$self->run_replication(user => 'newuser');
$self->check_replication('newuser');
}

1;
6 changes: 4 additions & 2 deletions imap/imapd.c
Original file line number Diff line number Diff line change
Expand Up @@ -7685,7 +7685,8 @@ static int renmbox(const mbentry_t *mbentry, void *rock)
r = mboxlist_renamemailbox(mbentry, text->newmailboxname,
text->partition, uidvalidity,
1, imapd_userid, imapd_authstate, NULL, 0, 0,
text->rename_user, /*keep_intermediaries*/1, 0, 0);
text->rename_user, /*keep_intermediaries*/1,
0, /*silent*/text->rename_user);

if (!r && config_getswitch(IMAPOPT_DELETE_UNSUBSCRIBE)) {
mboxlist_changesub(mbentry->name, imapd_userid, imapd_authstate,
Expand Down Expand Up @@ -8111,7 +8112,8 @@ static void cmd_rename(char *tag, char *oldname, char *newname, char *location,
location ? location : mbentry->partition,
0 /* uidvalidity */, imapd_userisadmin,
imapd_userid, imapd_authstate, mboxevent,
0, 0, rename_user, /*keep_intermediaries*/1, 0, 0);
0, 0, rename_user, /*keep_intermediaries*/1,
0, /*silent*/rename_user);

/* it's OK to not exist if there are subfolders */
if (r == IMAP_MAILBOX_NONEXISTENT && subcount && !rename_user &&
Expand Down

0 comments on commit e862ccc

Please sign in to comment.