Skip to content

Commit

Permalink
pop3c: Fixed assert-crash when prefetching a mail failed.
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Jan 27, 2016
1 parent fd3d068 commit 84a5175
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/lib-storage/index/pop3c/pop3c-mail.c
Expand Up @@ -33,6 +33,8 @@ static void pop3c_mail_close(struct mail *_mail)
/* wait for any prefetch to finish before closing the mail */
while (pmail->prefetching)
pop3c_client_wait_one(mbox->client);
if (pmail->prefetch_stream != NULL)
i_stream_unref(&pmail->prefetch_stream);
index_mail_close(_mail);
}

Expand Down Expand Up @@ -131,16 +133,20 @@ static void pop3c_mail_prefetch_done(enum pop3c_command_state state,
const char *reply, void *context)
{
struct pop3c_mail *pmail = context;
struct mail *_mail = &pmail->imail.mail.mail;
const char *cmd;

switch (state) {
case POP3C_COMMAND_STATE_OK:
break;
case POP3C_COMMAND_STATE_ERR:
case POP3C_COMMAND_STATE_DISCONNECTED:
i_stream_unref(&pmail->imail.data.stream);
pmail->imail.data.stream =
i_stream_create_error_str(EIO, "%s failed: %s",
pmail->prefetching_body ? "RETR" : "TOP", reply);
cmd = pmail->prefetching_body ? "RETR" : "TOP";
i_stream_unref(&pmail->prefetch_stream);
pmail->prefetch_stream =
i_stream_create_error_str(EIO, "%s %u failed: %s",
cmd, _mail->seq, reply);
i_stream_set_name(pmail->prefetch_stream, cmd);
break;
}
pmail->prefetching = FALSE;
Expand All @@ -164,10 +170,10 @@ static bool pop3c_mail_prefetch(struct mail *_mail)
cmd = t_strdup_printf("TOP %u 0\r\n", _mail->seq);

pmail->prefetching = TRUE;
pmail->imail.data.stream =
pmail->prefetch_stream =
pop3c_client_cmd_stream_async(mbox->client, cmd,
pop3c_mail_prefetch_done, pmail);
i_stream_set_name(pmail->imail.data.stream, t_strcut(cmd, '\r'));
i_stream_set_name(pmail->prefetch_stream, t_strcut(cmd, '\r'));
return !pmail->prefetching;
}
return index_mail_prefetch(_mail);
Expand All @@ -193,6 +199,11 @@ pop3c_mail_get_stream(struct mail *_mail, bool get_body,
pop3c_client_wait_one(mbox->client);
}

if (pmail->prefetch_stream != NULL && mail->data.stream == NULL) {
mail->data.stream = pmail->prefetch_stream;
pmail->prefetch_stream = NULL;
}

if (get_body && mail->data.stream != NULL) {
name = i_stream_get_name(mail->data.stream);
if (strncmp(name, "RETR", 4) == 0) {
Expand Down
1 change: 1 addition & 0 deletions src/lib-storage/index/pop3c/pop3c-storage.h
Expand Up @@ -31,6 +31,7 @@ struct pop3c_mailbox {

struct pop3c_mail {
struct index_mail imail;
struct istream *prefetch_stream;

unsigned int prefetching:1;
unsigned int prefetching_body:1;
Expand Down

0 comments on commit 84a5175

Please sign in to comment.