Tk Library Source Code

Artifact [340941fd47]
Login

Artifact 340941fd47279e072345179183d57690b098dedf:

Attachment "pop3.tcl.diff" to ticket [1906274fff] added by egavilan 2008-03-03 20:55:19.
--- pop3.tcl.orig	2008-03-03 09:12:32.000000000 -0300
+++ pop3.tcl	2008-03-03 09:33:19.000000000 -0300
@@ -226,11 +226,11 @@
 
 proc ::pop3::open {args} {
     variable state
-    array set cstate {msex 0 retr_mode retr limit {}}
+    array set cstate {msex 0 retr_mode retr tls 0 limit {}}
 
     log::log debug "pop3::open | [join $args]"
 
-    while {[set err [cmdline::getopt args {msex.arg retr-mode.arg} opt arg]]} {
+    while {[set err [cmdline::getopt args {msex.arg retr-mode.arg tls.arg} opt arg]]} {
 	if {$err < 0} {
 	    return -code error "::pop3::open : $arg"
 	}
@@ -253,26 +253,46 @@
 		    }
 		}
 	    }
+	    tls {
+		if {![string is boolean $arg]} {
+		    return -code error \
+			    ":pop3::open : Argument to -tls has to be boolean"
+		}
+		set cstate(tls) $arg
+		# we shoud do this sooner or later, so better do it here
+		package require tls
+	    }
 	    default {# Can't happen}
 	}
     }
 
     if {[llength $args] > 4} {
-	return -code error "To many arguments to ::pop3::open"
+	return -code error "Too many arguments to ::pop3::open"
     }
     if {[llength $args] < 3} {
 	return -code error "Not enough arguments to ::pop3::open"
     }
     foreach {host user password port} $args break
+    # set the default port
     if {$port == {}} {
-	set port 110
+	if {$cstate(tls)} {
+	    set port 995
+	} else {
+	    set port 110
+	}
+    }
+    # set the command to open the socket
+    if {$cstate(tls)} {
+	set sockcmd ::tls::socket
+    } else {
+	set sockcmd socket
     }
 
     log::log debug "pop3::open | protocol, connect to $host $port"
 
     # Argument processing is finally complete, now open the channel
 
-    set chan [socket $host $port]
+    set chan [$sockcmd $host $port]
     fconfigure $chan -buffering none
 
     log::log debug "pop3::open | connect on $chan"