From 74771392abf037d06751dd1f42f11248bfa6e8c2 Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Fri, 27 Aug 2021 19:22:34 +0200 Subject: struct method: introduce con-/destructors These can be used before setting up or after closing down a socket for protocol-specific initialisiation or cleanup, and are required to cleanly fix up the IMAP-loses-protocol-version regression without too many temporary hacks in the code. --- driver.c | 11 +++++++++++ fetchmail.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/driver.c b/driver.c index 5421c766..78e72df6 100644 --- a/driver.c +++ b/driver.c @@ -965,6 +965,12 @@ static int do_session( goto closeUp; } + /* initialize protocol */ + if (ctl->server.base_protocol->construct) { + err = (ctl->server.base_protocol->construct)(ctl); + if (err) goto cleanUp; + } + /* open a socket to the mail server */ oldphase = phase; phase = OPEN_WAIT; @@ -1547,6 +1553,11 @@ is restored.")); cleanupSockClose(mailserver_socket_temp); mailserver_socket_temp = -1; } + + /* clean up protocol */ + if (ctl->server.base_protocol->destruct) { + ctl->server.base_protocol->destruct(ctl); + } } /* no report on PS_AUTHFAIL */ diff --git a/fetchmail.h b/fetchmail.h index d976f481..a1b77468 100644 --- a/fetchmail.h +++ b/fetchmail.h @@ -249,6 +249,8 @@ struct method /* describe methods for protocol state machine */ int (*logout_cmd)(int, struct query *); /* logout command */ flag retry; /* can getrange poll for new messages? */ + int (*construct)(struct query *); /* session setup before first command */ + int (*destruct)(struct query *); /* cleanup after session */ }; enum badheader { BHREJECT = 0, BHACCEPT }; -- cgit v1.2.3