Skip to content

Commit

Permalink
pop: move refno
Browse files Browse the repository at this point in the history
`refno` isn't used outside of the POP backend.
Move `Email->refno` to `PopEmailData->refno`.

The value was saved in the Header Cache, but the restored value was never used (see pop_fetch_headers()).
  • Loading branch information
flatcap committed Oct 14, 2019
1 parent 29a02ae commit 3df237a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
4 changes: 0 additions & 4 deletions email/email.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ struct Email
struct ListHead chain; ///< Mixmaster chain
#endif

#ifdef USE_POP
int refno; ///< Message number on server
#endif

struct TagList tags; ///< For drivers that support server tagging

char *maildir_flags; ///< Unknown maildir flags
Expand Down
28 changes: 17 additions & 11 deletions pop/pop.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,15 @@ static int pop_read_header(struct PopAccountData *adata, struct Email *e)
size_t length = 0;
char buf[1024];

snprintf(buf, sizeof(buf), "LIST %d\r\n", e->refno);
struct PopEmailData *edata = pop_edata_get(e);

snprintf(buf, sizeof(buf), "LIST %d\r\n", edata->refno);
int rc = pop_query(adata, buf, sizeof(buf));
if (rc == 0)
{
sscanf(buf, "+OK %d %zu", &index, &length);

snprintf(buf, sizeof(buf), "TOP %d 0\r\n", e->refno);
snprintf(buf, sizeof(buf), "TOP %d 0\r\n", edata->refno);
rc = pop_fetch_data(adata, buf, NULL, fetch_message, fp);

if (adata->cmd_top == 2)
Expand Down Expand Up @@ -294,9 +296,11 @@ static int fetch_uidl(const char *line, void *data)
else if (m->emails[i]->index != index - 1)
adata->clear_cache = true;

m->emails[i]->refno = index;
m->emails[i]->index = index - 1;

struct PopEmailData *edata = pop_edata_get(m->emails[i]);
edata->refno = index;

return 0;
}

Expand Down Expand Up @@ -396,7 +400,10 @@ static int pop_fetch_headers(struct Mailbox *m)
}

for (int i = 0; i < m->msg_count; i++)
m->emails[i]->refno = -1;
{
struct PopEmailData *edata = pop_edata_get(m->emails[i]);
edata->refno = -1;
}

const int old_count = m->msg_count;
int rc = pop_fetch_data(adata, "UIDL\r\n", NULL, fetch_uidl, m);
Expand Down Expand Up @@ -433,7 +440,8 @@ static int pop_fetch_headers(struct Mailbox *m)
int i, deleted;
for (i = 0, deleted = 0; i < old_count; i++)
{
if (m->emails[i]->refno == -1)
struct PopEmailData *edata = pop_edata_get(m->emails[i]);
if (edata->refno == -1)
{
m->emails[i]->deleted = true;
deleted++;
Expand All @@ -460,7 +468,6 @@ static int pop_fetch_headers(struct Mailbox *m)
/* Detach the private data */
m->emails[i]->edata = NULL;

int refno = m->emails[i]->refno;
int index = m->emails[i]->index;
/* - POP dynamically numbers headers and relies on e->refno
* to map messages; so restore header and overwrite restored
Expand All @@ -473,7 +480,6 @@ static int pop_fetch_headers(struct Mailbox *m)
mutt_hcache_free(hc, &data);
email_free(&m->emails[i]);
m->emails[i] = e;
m->emails[i]->refno = refno;
m->emails[i]->index = index;

/* Reattach the private data */
Expand Down Expand Up @@ -966,12 +972,12 @@ static int pop_mbox_sync(struct Mailbox *m, int *index_hint)
for (i = 0, j = 0, rc = 0; (rc == 0) && (i < m->msg_count); i++)
{
struct PopEmailData *edata = pop_edata_get(m->emails[i]);
if (m->emails[i]->deleted && (m->emails[i]->refno != -1))
if (m->emails[i]->deleted && (edata->refno != -1))
{
j++;
if (!m->quiet)
mutt_progress_update(&progress, j, -1);
snprintf(buf, sizeof(buf), "DELE %d\r\n", m->emails[i]->refno);
snprintf(buf, sizeof(buf), "DELE %d\r\n", edata->refno);
rc = pop_query(adata, buf, sizeof(buf));
if (rc == 0)
{
Expand Down Expand Up @@ -1097,7 +1103,7 @@ static int pop_msg_open(struct Mailbox *m, struct Message *msg, int msgno)
return -1;

/* verify that massage index is correct */
if (e->refno < 0)
if (edata->refno < 0)
{
mutt_error(
_("The message index is incorrect. Try reopening the mailbox."));
Expand All @@ -1122,7 +1128,7 @@ static int pop_msg_open(struct Mailbox *m, struct Message *msg, int msgno)
}
}

snprintf(buf, sizeof(buf), "RETR %d\r\n", e->refno);
snprintf(buf, sizeof(buf), "RETR %d\r\n", edata->refno);

const int ret = pop_fetch_data(adata, buf, &progress, fetch_message, msg->fp);
if (ret == 0)
Expand Down
7 changes: 5 additions & 2 deletions pop/pop_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ static int check_uidl(const char *line, void *data)
struct PopEmailData *edata = pop_edata_get(m->emails[i]);
if (mutt_str_strcmp(edata->uid, endp) == 0)
{
m->emails[i]->refno = index;
edata->refno = index;
break;
}
}
Expand Down Expand Up @@ -607,7 +607,10 @@ int pop_reconnect(struct Mailbox *m)
mutt_progress_init(&progress, _("Verifying message indexes..."), MUTT_PROGRESS_NET, 0);

for (int i = 0; i < m->msg_count; i++)
m->emails[i]->refno = -1;
{
struct PopEmailData *edata = pop_edata_get(m->emails[i]);
edata->refno = -1;
}

ret = pop_fetch_data(adata, "UIDL\r\n", &progress, check_uidl, m);
if (ret == -2)
Expand Down
1 change: 1 addition & 0 deletions pop/pop_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ struct PopAccountData
struct PopEmailData
{
const char *uid;
int refno; ///< Message number on server
};

/**
Expand Down

0 comments on commit 3df237a

Please sign in to comment.