--- qmail-popup.c.orig  1998-06-15
+++ qmail-popup.c       2007-03-21
--- .././qmail-1.03/qmail-popup.c	Mon Jun 15 12:53:16 1998
+++ ../qmail-1.03.2418/qmail-popup.c	Wed Feb  1 21:35:01 2006
@@ -13,6 +13,8 @@
 #include "readwrite.h"
 #include "timeoutread.h"
 #include "timeoutwrite.h"
+#include "env.h"
+#include "ucspitls.h"
 
 void die() { _exit(1); }
 
@@ -61,6 +63,7 @@
 void die_fork() { err("unable to fork"); die(); }
 void die_childcrashed() { err("aack, child crashed"); }
 void die_badauth() { err("authorization failed"); }
+void die_tls() { err("TLS startup failed"); die(); }
 
 void err_syntax() { err("syntax error"); }
 void err_wantuser() { err("USER first"); }
@@ -77,7 +80,7 @@
 char **childargs;
 substdio ssup;
 char upbuf[128];
-
+int stls = 0;
 
 void doanddie(user,userlen,pass)
 char *user;
@@ -155,12 +158,36 @@
   *space++ = 0;
   doanddie(arg,space - arg,space);
 }
+void pop3_capa(arg) char *arg;
+{
+  puts("+OK capability list follows\r\n");
+  if (stls == 1)
+    puts("STLS\r\n");
+  puts(".\r\n");
+  flush();
+}
+void pop3_stls(arg) char *arg;
+{
+  if (stls != 1)
+    return err("STLS not available");
+  puts("+OK starting TLS negotiation\r\n");
+  flush();
+
+  if (!ucspitls())
+    die_tls();
+
+  stls = 2;
+  /* reset state */
+  seenuser = 0;
+}
 
 struct commands pop3commands[] = {
   { "user", pop3_user, 0 }
 , { "pass", pop3_pass, 0 }
 , { "apop", pop3_apop, 0 }
 , { "quit", pop3_quit, 0 }
+, { "capa", pop3_capa, 0 }
+, { "stls", pop3_stls, 0 }
 , { "noop", okay, 0 }
 , { 0, err_authoriz, 0 }
 } ;
@@ -176,6 +203,8 @@
   if (!hostname) die_usage();
   childargs = argv + 2;
   if (!*childargs) die_usage();
+
+  if (env_get("UCSPITLS")) stls = 1;
  
   pop3_greet();
   commands(&ssin,pop3commands);


syntax highlighted by Code2HTML, v. 0.9.1