diff options
author | Kevin McCarthy <kevin@8t8.us> | 2021-12-21 18:29:26 -0800 |
---|---|---|
committer | Kevin McCarthy <kevin@8t8.us> | 2021-12-22 14:45:27 -0800 |
commit | e3faeb0355ad3ac53696d0d4d9eee3e2fd9b595e (patch) | |
tree | a50c41dd27f27004c4b5874c60c3696225d1d7d1 /mutt_socket.c | |
parent | 227364844754cc5b5a5512c002d1eb2b4c1792e9 (diff) |
Add mutt_socket_buffer_readln().
This will be useful for SMTP and POP SASL reading, where line of
arbitrary length are required to be supported.
Diffstat (limited to 'mutt_socket.c')
-rw-r--r-- | mutt_socket.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/mutt_socket.c b/mutt_socket.c index 0566ab5b..bbe79c4b 100644 --- a/mutt_socket.c +++ b/mutt_socket.c @@ -232,6 +232,38 @@ int mutt_socket_readln_d (char* buf, size_t buflen, CONNECTION* conn, int dbg) return i + 1; } +int mutt_socket_buffer_readln_d (BUFFER *buf, CONNECTION *conn, int dbg) +{ + char ch; + int has_cr = 0; + + mutt_buffer_clear (buf); + + FOREVER + { + if (mutt_socket_readchar (conn, &ch) != 1) + return -1; + + if (ch == '\n') + break; + + if (has_cr) + { + mutt_buffer_addch (buf, '\r'); + has_cr = 0; + } + + if (ch == '\r') + has_cr = 1; + else + mutt_buffer_addch (buf, ch); + } + + dprint (dbg, (debugfile, "%d< %s\n", conn->fd, mutt_b2s (buf))); + + return 0; +} + CONNECTION* mutt_socket_head (void) { return Connections; |