tttm

git clone https://orangeshoelaces.net/git/tttm.git

b4ce6aadabf3a533b83a9d05d68eacfead126b02

Author: Vasily Kolobkov on 05/21/2016

Committer: Vasily Kolobkov on 05/21/2016

Keep session state up-to-date

Stats

imap.c | 11 +++++---
1 file changed, 7 insertions(+), 4 deletions(-)

Patch

diff --git a/imap.c b/imap.c
index 3955c05..f78f684 100644
--- a/imap.c
+++ b/imap.c
@@ -96,7 +96,8 @@ imap_select(struct imapctx *con, const char *mb)
 
 	if (dprintf(con->out, "%u SELECT %s\r\n", con->tag++, mb) < 0)
 		goto eout;
-	e = imap_pollres(con);
+	if (!(e = imap_pollres(con)))
+		con->state = IS_SEL;
  exit:
 	return e;
  eout:
@@ -111,7 +112,8 @@ imap_close(struct imapctx *con)
 
 	if (dprintf(con->out, "%u CLOSE\r\n", con->tag++) < 0)
 		goto eout;
-	e = imap_pollres(con);
+	if (!(e = imap_pollres(con)))
+		con->state = IS_AUTH;
  exit:
 	return e;
  eout:
@@ -202,9 +204,10 @@ imap_readln(struct imapctx *con)
 
 	e = par_readln(&con->in, con->rep, LEN(con->rep),
 	    -1, con->par, LEN(con->par));
-	if (!e && par_sel(con->par, IP_RESPDATA, IP_RESPBYE, -1))
+	if (!e && par_sel(con->par, IP_RESPDATA, IP_RESPBYE, -1)) {
+		con->state = IS_LOGOUT;
 		e = TE_BYE;
-
+	}
 	return e;
 }