+/*
+ * If capable, issue the STLS command and start the TLS negotiation
+ */
+
+static int
+pop_start_tls(void)
+{
+ int status;
+ bool stls = false;
+ char *errstr;
+
+ /*
+ * Issue the CAPA command and see if we have the STLS capability
+ */
+
+ if (command("CAPA") == NOTOK) {
+ snprintf(response, sizeof(response),
+ "The POP CAPA command failed; POP server does not "
+ "support STLS");
+ return NOTOK;
+ }
+
+ while ((status = multiline()) != DONE) {
+ if (status == NOTOK)
+ return NOTOK;
+
+ if (strcasecmp(response, "STLS") == 0)
+ stls = true;
+ }
+
+ if (!stls) {
+ snprintf(response, sizeof(response), "POP server does not support "
+ "STLS");
+ return NOTOK;
+ }
+
+ /*
+ * Issue STLS and then start the actual TLS negotiation
+ */
+
+ if (command("STLS") == NOTOK)
+ return NOTOK;
+
+ if (netsec_negotiate_tls(nsc, &errstr) != OK) {
+ snprintf(response, sizeof(response), "%s", errstr);
+ free(errstr);
+ return NOTOK;
+ }
+
+ return OK;
+}
+