Skip to content

Commit 2685860

Browse files
stephanboschsirainen
authored andcommitted
Add support for sending REPLACE commands in test scripts
This is implemented as a modified APPEND command. Full tests for IMAP REPLACE capability are not part of this commit. This is needed for Dovecot internal CI testing.
1 parent d49a360 commit 2685860

File tree

3 files changed

+53
-12
lines changed

3 files changed

+53
-12
lines changed

src/client-state.c

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,11 @@ int imap_client_append_continue(struct imap_client *client)
386386
return 0;
387387
}
388388

389-
int imap_client_append(struct imap_client *client, const char *args, bool add_datetime,
390-
command_callback_t *callback, struct command **cmd_r)
389+
static int
390+
imap_client_append_common(struct imap_client *client, string_t *cmd,
391+
const char *args, bool add_datetime,
392+
command_callback_t *callback, struct command **cmd_r)
391393
{
392-
string_t *cmd;
393394
time_t t;
394395
uoff_t vsize;
395396
int tz;
@@ -401,12 +402,6 @@ int imap_client_append(struct imap_client *client, const char *args, bool add_da
401402
mailbox_source_get_next(client->storage->source,
402403
&vsize, &t, &tz);
403404

404-
cmd = t_str_new(128);
405-
if (client->append_unfinished) {
406-
/* MULTIAPPEND contination */
407-
} else {
408-
str_append(cmd, "APPEND ");
409-
}
410405
str_append(cmd, args);
411406
if (add_datetime)
412407
str_printfa(cmd, " \"%s\"", imap_to_datetime_tz(t, tz));
@@ -435,6 +430,36 @@ int imap_client_append(struct imap_client *client, const char *args, bool add_da
435430
return imap_client_append_continue(client);
436431
}
437432

433+
int imap_client_append(struct imap_client *client, const char *args,
434+
bool add_datetime, command_callback_t *callback,
435+
struct command **cmd_r)
436+
{
437+
string_t *cmd = t_str_new(128);
438+
439+
if (client->append_unfinished) {
440+
/* MULTIAPPEND contination */
441+
} else {
442+
str_append(cmd, "APPEND ");
443+
}
444+
445+
return imap_client_append_common(client, cmd, args, add_datetime,
446+
callback, cmd_r);
447+
}
448+
449+
int imap_client_replace(struct imap_client *client, bool uid, const char *args,
450+
command_callback_t *callback, struct command **cmd_r)
451+
{
452+
string_t *cmd = t_str_new(128);
453+
454+
i_assert(!client->append_unfinished);
455+
if (uid)
456+
str_append(cmd, "UID ");
457+
str_append(cmd, "REPLACE ");
458+
459+
return imap_client_append_common(client, cmd, args, FALSE,
460+
callback, cmd_r);
461+
}
462+
438463
int imap_client_append_full(struct imap_client *client, const char *mailbox,
439464
const char *flags, const char *datetime,
440465
command_callback_t *callback, struct command **cmd_r)

src/client-state.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ void client_state_add_to_timer(enum client_state state,
9191

9292
int imap_client_append(struct imap_client *client, const char *args, bool add_datetime,
9393
command_callback_t *callback, struct command **cmd_r);
94+
int imap_client_replace(struct imap_client *client, bool uid, const char *args,
95+
command_callback_t *callback, struct command **cmd_r);
9496
int imap_client_append_full(struct imap_client *client, const char *mailbox,
9597
const char *flags, const char *datetime,
9698
command_callback_t *callback, struct command **cmd_r);

src/test-exec.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,8 @@ static bool imap_arg_is_bad(const struct imap_arg *arg)
823823
}
824824

825825
static bool
826-
append_has_body(struct test_exec_context *ctx, const char *str_args,
827-
unsigned int str_args_len)
826+
append_has_body(struct test_exec_context *ctx, bool replace,
827+
const char *str_args, unsigned int str_args_len)
828828
{
829829
ARRAY_TYPE(imap_arg_list) *arg_list;
830830
const struct imap_arg *args;
@@ -839,6 +839,10 @@ append_has_body(struct test_exec_context *ctx, const char *str_args,
839839
if (args->type == IMAP_ARG_EOL)
840840
return FALSE;
841841

842+
if (replace)
843+
args++;
844+
if (args->type == IMAP_ARG_EOL)
845+
return FALSE;
842846
if (args[1].type == IMAP_ARG_LIST)
843847
args++;
844848
if (args[1].type == IMAP_ARG_STRING)
@@ -867,10 +871,20 @@ static void test_send_next_command(struct test_exec_context *ctx,
867871
(void)imap_client_append_full(client, NULL, NULL, NULL,
868872
test_cmd_callback, &cmd);
869873
} else if (str_begins_icase(cmdline, "append ", &args) &&
870-
!append_has_body(ctx, args, strlen(args))) {
874+
!append_has_body(ctx, FALSE, args, strlen(args))) {
871875
client->client.state = STATE_APPEND;
872876
(void)imap_client_append(client, args, FALSE,
873877
test_cmd_callback, &cmd);
878+
} else if (str_begins_icase(cmdline, "replace ", &args) &&
879+
!append_has_body(ctx, TRUE, args, strlen(args))) {
880+
client->client.state = STATE_APPEND;
881+
(void)imap_client_replace(client, FALSE, args,
882+
test_cmd_callback, &cmd);
883+
} else if (str_begins_icase(cmdline, "uid replace ", &args) &&
884+
!append_has_body(ctx, TRUE, args, strlen(args))) {
885+
client->client.state = STATE_APPEND;
886+
(void)imap_client_replace(client, TRUE, args,
887+
test_cmd_callback, &cmd);
874888
} else {
875889
if (test_cmd->linenum == 0 ||
876890
strcasecmp(cmdline, "logout") == 0 ||

0 commit comments

Comments
 (0)