summary refs log tree commit diff
path: root/imap.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-13 16:18:37 -0400
committerJune McEnroe <june@causal.agency>2020-04-13 16:18:37 -0400
commitbab44e23d43b064fa1995975434db88913a1ce20 (patch)
treefcca2b7b8ce4cf3b9444c8f82750d16fe1452ed2 /imap.c
parentAdd -u option to set base URL (diff)
downloadbubger-bab44e23d43b064fa1995975434db88913a1ce20.tar.gz
bubger-bab44e23d43b064fa1995975434db88913a1ce20.zip
Use two FILEs for IMAP
Turns out that funopen cannot be used for a full-duplex socket.
Diffstat (limited to '')
-rw-r--r--imap.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/imap.c b/imap.c
index 7d623a5..9743ac8 100644
--- a/imap.c
+++ b/imap.c
@@ -58,10 +58,11 @@ static int imapClose(void *_tls) {
 	struct tls *tls = _tls;
 	int error = tls_close(tls);
 	if (error) errx(EX_IOERR, "tls_close: %s", tls_error(tls));
+	tls_free(tls);
 	return error;
 }
 
-FILE *imapOpen(const char *host, const char *port) {
+void imapOpen(FILE **read, FILE **write, const char *host, const char *port) {
 	struct tls *client = tls_client();
 	if (!client) errx(EX_SOFTWARE, "tls_client");
 
@@ -75,11 +76,11 @@ FILE *imapOpen(const char *host, const char *port) {
 	error = tls_connect(client, host, port);
 	if (error) errx(EX_NOHOST, "tls_connect: %s", tls_error(client));
 
-	FILE *imap = funopen(client, imapRead, imapWrite, NULL, imapClose);
-	if (!imap) err(EX_SOFTWARE, "funopen");
+	*read = funopen(client, imapRead, NULL, NULL, NULL);
+	*write = funopen(client, NULL, imapWrite, NULL, imapClose);
+	if (!*read || !*write) err(EX_SOFTWARE, "funopen");
 
-	setlinebuf(imap);
-	return imap;
+	setlinebuf(*write);
 }
 
 static size_t cap;