aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmail-remote/qmailr_smtp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/qmail-remote/qmailr_smtp.c')
-rw-r--r--src/qmail-remote/qmailr_smtp.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/qmail-remote/qmailr_smtp.c b/src/qmail-remote/qmailr_smtp.c
index a0faf78..1d5d426 100644
--- a/src/qmail-remote/qmailr_smtp.c
+++ b/src/qmail-remote/qmailr_smtp.c
@@ -51,3 +51,38 @@ void qmailr_smtp_quit (buffer *out, unsigned int timeout)
qdeadline(&deadline, timeout) ;
buffer_timed_flush_g(out, &deadline) ;
}
+
+int qmailr_smtp_start (buffer *in, buffer *out, char const *helohost, unsigned int timeout)
+{
+ int hastls = 0 ;
+ tain deadline ;
+ char line[1024] ;
+ int r = qmailr_smtp_read_answer(in, line, 1024, timeout) ;
+ if (r == -1) return -1 ;
+ if (!r) return (errno = EPIPE, -1) ;
+ if (r != 220)
+ {
+ qmailr_smtp_quit(out, timeout) ;
+ return (errno = EPROTO, -1) ;
+ }
+
+ buffer_putnoflush(out, "EHLO ", 5) ;
+ buffer_putsnoflush(out, helohost) ;
+ buffer_putnoflush(out, "\r\n", 2) ;
+
+ qdeadline(&deadline, timeout) ;
+ if (!buffer_timed_flush_g(out, &deadline)) return -1 ;
+
+ qdeadline(&deadline, timeout) ;
+ for (;;)
+ {
+ unsigned int code = 250 ;
+ int r = qmailr_smtp_read_line(in, line, 1024, &code, &deadline) ;
+ if (r == -1) return -1 ;
+ if (!r) return (errno = EPIPE, -1) ;
+ if (code != 250) return (errno = EPROTO, -1) ;
+ if (!strcasecmp(line + 4, "STARTTLS")) hastls = 1 ;
+ if (r == 1) break ;
+ }
+ return hastls ;
+}