- (if (gnutls-available-p)
- (when (not elpher-use-tls)
- (setq elpher-use-tls t)
- (message "Engaging TLS gopher mode."))
- (error "Cannot retrieve TLS gopher selector: GnuTLS not available")))
- (condition-case the-error
- (let* ((kill-buffer-query-functions nil)
- (port (elpher-address-port address))
- (host (if force-ipv4
- (dns-query (elpher-address-host address))
- (elpher-address-host address)))
- (proc (open-network-stream "elpher-process"
- nil
- host
- (if (> port 0) port 70)
- :type (if elpher-use-tls 'tls 'plain)
- :nowait t))
- (timer (run-at-time elpher-connection-timeout
- nil
- (lambda ()
- (elpher-process-cleanup)
- (unless force-ipv4
- (elpher-get-selector address renderer t))))))
- (set-process-coding-system proc 'binary)
- (set-process-filter proc
- (lambda (_proc string)
+ (if (gnutls-available-p)
+ (when (not elpher-use-tls)
+ (setq elpher-use-tls t)
+ (message "Engaging TLS gopher mode."))
+ (error "Cannot retrieve TLS gopher selector: GnuTLS not available")))
+ (let* ((kill-buffer-query-functions nil)
+ (port (elpher-address-port address))
+ (host (elpher-address-host address))
+ (proc (open-network-stream "elpher-process"
+ nil
+ (if force-ipv4 (dns-query host) host)
+ (if (> port 0) port 70)
+ :type (if elpher-use-tls 'tls 'plain)
+ :nowait t))
+ (timer (run-at-time elpher-connection-timeout
+ nil
+ (lambda ()
+ (message "timeout (status %s)" (process-status proc))
+ (pcase (process-status proc)
+ ('failed
+ (if (and (not (equal (elpher-address-protocol address)
+ "gophers"))
+ elpher-use-tls
+ (or elpher-auto-disengage-TLS
+ (yes-or-no-p "Could not establish encrypted connection. Disable TLS mode?")))
+ (progn
+ (message "Disabling TLS mode.")
+ (setq elpher-use-tls nil)
+ (elpher-get-selector address renderer))))
+ ('connect
+ (elpher-process-cleanup)
+ (unless force-ipv4
+ (elpher-get-selector address renderer t))))))))
+ (set-process-coding-system proc 'binary)
+ (set-process-filter proc
+ (lambda (_proc string)
+ (message "filter")
+ (cancel-timer timer)
+ (setq elpher-selector-string
+ (concat elpher-selector-string string))))
+ (set-process-sentinel proc
+ (lambda (_proc event)
+ (message "Event: %s" event)
+ (cond
+ ((string-prefix-p "deleted" event))
+ ((string-prefix-p "open" event)
+ (let ((inhibit-eol-conversion t))
+ (process-send-string
+ proc
+ (concat (elpher-gopher-address-selector address)
+ "\r\n"))))
+ (t