Skip to content

Commit

Permalink
net_imap: Don't include dead clients in IDLE traversals.
Browse files Browse the repository at this point in the history
* When calculating when the next IDLE needs to be renewed, or
  attempting to renew IDLE, skip clients that are already dead.
* Currently, only remote LIST handling ignores commented lines in
  the client mapping file. Ignore commented lines in the general
  load virtual mailbox function as well.
  • Loading branch information
InterLinked1 committed Oct 3, 2024
1 parent 78c1e0a commit 6416cb0
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions nets/net_imap/imap_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ int imap_clients_next_idle_expiration(struct imap_session *imap)
RWLIST_RDLOCK(&imap->clients);
RWLIST_TRAVERSE(&imap->clients, client, entry) {
time_t maxage;
if (!client->idling) {
if (!client->idling || client->dead) {
continue;
}
/* This is when the connection may be terminated.
Expand Down Expand Up @@ -223,7 +223,7 @@ void imap_clients_renew_idle(struct imap_session *imap)
RWLIST_WRLOCK(&imap->clients);
RWLIST_TRAVERSE_SAFE_BEGIN(&imap->clients, client, entry) {
time_t maxage;
if (!client->idling) {
if (!client->idling || client->dead) {
continue;
}
/* This is when the connection may be terminated.
Expand Down Expand Up @@ -831,7 +831,7 @@ static struct imap_client *__load_virtual_mailbox(struct imap_session *imap, con
FILE *fp;
char virtcachefile[256];
char buf[256];
size_t pathlen;
size_t pathlen = 0; /* Initialize to avoid gcc maybe-uninitialized false positive warning */

if (imap->client) {
const char *virtprefix = imap->client->virtprefix;
Expand Down Expand Up @@ -880,6 +880,14 @@ static struct imap_client *__load_virtual_mailbox(struct imap_session *imap, con
continue; /* Illegitimate */
}

/* If line is commented (begins with '#'), ignore it.
* Shouldn't happen normally, since such a mailbox wouldn't have been sent
* in the LIST response, but nothing stops a client from making such requests. */
if (!strncmp(urlstr, "#", 1)) {
bbs_debug(3, "Ignoring request for commented out mailbox '%s'\n", mpath);
continue;
}

/* Instead of doing prefixlen = strlen(mpath), we can just subtract the pointers */
prefixlen = (size_t) (urlstr - mpath - 1); /* Subtract 1 for the space between. */
urlstrlen = strlen(urlstr);
Expand Down

0 comments on commit 6416cb0

Please sign in to comment.