unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* smtpmail and starttls improvement when starttls program is missing
@ 2008-10-29 21:21 Ted Zlatanov
  2008-10-31 17:40 ` Ted Zlatanov
  2008-11-04  0:53 ` Katsumi Yamaoka
  0 siblings, 2 replies; 5+ messages in thread
From: Ted Zlatanov @ 2008-10-29 21:21 UTC (permalink / raw)
  To: emacs-devel

Currently, smtpmail-open-stream will quietly fail if the starttls /
gnutls program is not available.  The changes below (starttls diff is
against the Gnus trunk but it shouldn't matter) introduce the function
starttls-any-program-available which will return either starttls-program
or starttls-gnutls-program, whichever is usable.  It also shows a
message, so a user can see in *Messages* that no STARTTLS protocol
transport is available.  smtpmail-open-stream then uses the function,
simplifying the logic flow.

The message will only be shown when starttls-any-program-available is
called, but note that it is called by smtpmail-open-stream iff there is
a match for the server in smtpmail-starttls-credentials.  This means the
user won't see the message unless he has an entry for the server that
implies he wants STARTTLS.

Let me know what you think...  Thanks
Ted

Index: starttls.el
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/starttls.el,v
retrieving revision 7.19
diff -c -r7.19 starttls.el
*** starttls.el 19 May 2008 08:47:42 -0000      7.19
--- starttls.el 29 Oct 2008 21:15:29 -0000
***************
*** 295,300 ****
--- 295,314 ----
        (starttls-set-process-query-on-exit-flag process nil)
        process)))
  
+ (defun starttls-any-program-available ()
+   (let ((program (if starttls-use-gnutls
+                    starttls-gnutls-program
+                  starttls-program)))
+     (condition-case ()
+       (with-no-warnings
+         (require 'starttls)
+         (call-process program)
+         program)
+       (error (progn
+              (message "No STARTTLS program was available (tried '%s')" 
+                       program)
+              nil)))))
+ 
  (provide 'starttls)
  
  ;; arch-tag: 648b3bd8-63bd-47f5-904c-7c819aea2297

Index: lisp/mail/smtpmail.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/mail/smtpmail.el,v
retrieving revision 1.105
diff -c -r1.105 smtpmail.el
*** lisp/mail/smtpmail.el       7 Jun 2008 02:41:06 -0000       1.105
--- lisp/mail/smtpmail.el       29 Oct 2008 21:16:26 -0000
***************
*** 503,515 ****
  (defun smtpmail-open-stream (process-buffer host port)
    (let ((cred (smtpmail-find-credentials
               smtpmail-starttls-credentials host port)))
!     (if (null (and cred (condition-case ()
!                           (with-no-warnings
!                             (require 'starttls)
!                             (call-process (if starttls-use-gnutls
!                                               starttls-gnutls-program
!                                             starttls-program)))
!                         (error nil))))
        ;; The normal case.
        (open-network-stream "SMTP" process-buffer host port)
        (let* ((cred-key (smtpmail-cred-key cred))
--- 503,509 ----
  (defun smtpmail-open-stream (process-buffer host port)
    (let ((cred (smtpmail-find-credentials
               smtpmail-starttls-credentials host port)))
!     (if (null (and cred (starttls-any-program-available)))
        ;; The normal case.
        (open-network-stream "SMTP" process-buffer host port)
        (let* ((cred-key (smtpmail-cred-key cred))





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: smtpmail and starttls improvement when starttls program is missing
  2008-10-29 21:21 smtpmail and starttls improvement when starttls program is missing Ted Zlatanov
@ 2008-10-31 17:40 ` Ted Zlatanov
  2008-11-04 16:59   ` Ted Zlatanov
  2008-11-04  0:53 ` Katsumi Yamaoka
  1 sibling, 1 reply; 5+ messages in thread
From: Ted Zlatanov @ 2008-10-31 17:40 UTC (permalink / raw)
  To: emacs-devel

On Wed, 29 Oct 2008 16:21:54 -0500 Ted Zlatanov <tzz@lifelogs.com> wrote: 

TZ> Currently, smtpmail-open-stream will quietly fail if the starttls /
TZ> gnutls program is not available.  The changes below (starttls diff is
TZ> against the Gnus trunk but it shouldn't matter) introduce the function
TZ> starttls-any-program-available which will return either starttls-program
TZ> or starttls-gnutls-program, whichever is usable.  It also shows a
TZ> message, so a user can see in *Messages* that no STARTTLS protocol
TZ> transport is available.  smtpmail-open-stream then uses the function,
TZ> simplifying the logic flow.

TZ> The message will only be shown when starttls-any-program-available is
TZ> called, but note that it is called by smtpmail-open-stream iff there is
TZ> a match for the server in smtpmail-starttls-credentials.  This means the
TZ> user won't see the message unless he has an entry for the server that
TZ> implies he wants STARTTLS.

If there are no objections I will commit my patch over the weekend.

Ted





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: smtpmail and starttls improvement when starttls program is missing
  2008-10-29 21:21 smtpmail and starttls improvement when starttls program is missing Ted Zlatanov
  2008-10-31 17:40 ` Ted Zlatanov
@ 2008-11-04  0:53 ` Katsumi Yamaoka
  2008-11-04 16:50   ` Ted Zlatanov
  1 sibling, 1 reply; 5+ messages in thread
From: Katsumi Yamaoka @ 2008-11-04  0:53 UTC (permalink / raw)
  To: Ted Zlatanov; +Cc: ding, emacs-devel

>>>>> Ted Zlatanov <tzz@lifelogs.com> wrote:

> Currently, smtpmail-open-stream will quietly fail if the starttls /
> gnutls program is not available.  The changes below (starttls diff is
> against the Gnus trunk but it shouldn't matter) introduce the function
> starttls-any-program-available which will return either starttls-program
> or starttls-gnutls-program, whichever is usable.  It also shows a
> message, so a user can see in *Messages* that no STARTTLS protocol
> transport is available.  smtpmail-open-stream then uses the function,
> simplifying the logic flow.

> The message will only be shown when starttls-any-program-available is
> called, but note that it is called by smtpmail-open-stream iff there is
> a match for the server in smtpmail-starttls-credentials.  This means the
> user won't see the message unless he has an entry for the server that
> implies he wants STARTTLS.

> Let me know what you think...  Thanks
> Ted

> Index: starttls.el
> ===================================================================
> RCS file: /usr/local/cvsroot/gnus/lisp/starttls.el,v
> retrieving revision 7.19
> diff -c -r7.19 starttls.el
> *** starttls.el 19 May 2008 08:47:42 -0000      7.19
> --- starttls.el 29 Oct 2008 21:15:29 -0000
> ***************
> *** 295,300 ****
> --- 295,314 ----
>         (starttls-set-process-query-on-exit-flag process nil)
>         process)))

> + (defun starttls-any-program-available ()
> +   (let ((program (if starttls-use-gnutls
> +                    starttls-gnutls-program
> +                  starttls-program)))
> +     (condition-case ()
> +       (with-no-warnings
> +         (require 'starttls)
> +         (call-process program)
> +         program)
> +       (error (progn
> +              (message "No STARTTLS program was available (tried '%s')"
> +                       program)
> +              nil)))))
> +
>   (provide 'starttls)

>   ;; arch-tag: 648b3bd8-63bd-47f5-904c-7c819aea2297

I think `with-no-warnings' and `(require 'starttls)' are unnecessary.
For `with-no-warnings', it binds `byte-compile-warnings' to nil
when compiling.  It is for making the byte compiler silent on any
form, however there seems nothing to be warned when compiling.
In addition, `with-no-warnings' is not available in Emacs 21 and
XEmacs that Gnus supports, so the warning like the following is
issued when compiling Gnus:

While compiling the end of the data in file gnus/lisp/starttls.el:
  ** The function `with-no-warnings' is not known to be defined.

It is not serious since the function will not be used with those
versions of Emacsen, though.

For `(require 'starttls)', the reason I say it is unnecessary is
that the function is defined in starttls.el that provides the
`starttls' feature. ;-)  Therefore the function can be rewritten
like the following, isn't it?

--8<---------------cut here---------------start------------->8---
(defun starttls-any-program-available ()
  (let ((program (if starttls-use-gnutls
		     starttls-gnutls-program
		   starttls-program)))
    (condition-case ()
	(progn
	  (call-process program)
	  program)
      (error (progn
	       (message "No STARTTLS program was available (tried '%s')"
			program)
	       nil)))))
--8<---------------cut here---------------end--------------->8---

> Index: lisp/mail/smtpmail.el
> ===================================================================
> RCS file: /sources/emacs/emacs/lisp/mail/smtpmail.el,v
> retrieving revision 1.105
> diff -c -r1.105 smtpmail.el
> *** lisp/mail/smtpmail.el       7 Jun 2008 02:41:06 -0000       1.105
> --- lisp/mail/smtpmail.el       29 Oct 2008 21:16:26 -0000
> ***************
> *** 503,515 ****
>   (defun smtpmail-open-stream (process-buffer host port)
>     (let ((cred (smtpmail-find-credentials
>                smtpmail-starttls-credentials host port)))
> !     (if (null (and cred (condition-case ()
> !                           (with-no-warnings
> !                             (require 'starttls)
> !                             (call-process (if starttls-use-gnutls
> !                                               starttls-gnutls-program
> !                                             starttls-program)))
> !                         (error nil))))
>         ;; The normal case.
>         (open-network-stream "SMTP" process-buffer host port)
>         (let* ((cred-key (smtpmail-cred-key cred))
> --- 503,509 ----
>   (defun smtpmail-open-stream (process-buffer host port)
>     (let ((cred (smtpmail-find-credentials
>                smtpmail-starttls-credentials host port)))
> !     (if (null (and cred (starttls-any-program-available)))
>         ;; The normal case.
>         (open-network-stream "SMTP" process-buffer host port)
>         (let* ((cred-key (smtpmail-cred-key cred))

Regards,




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: smtpmail and starttls improvement when starttls program is missing
  2008-11-04  0:53 ` Katsumi Yamaoka
@ 2008-11-04 16:50   ` Ted Zlatanov
  0 siblings, 0 replies; 5+ messages in thread
From: Ted Zlatanov @ 2008-11-04 16:50 UTC (permalink / raw)
  To: ding; +Cc: emacs-devel

On Tue, 04 Nov 2008 09:53:17 +0900 Katsumi Yamaoka <yamaoka@jpl.org> wrote: 

KY> I think `with-no-warnings' and `(require 'starttls)' are unnecessary.
KY> For `with-no-warnings', it binds `byte-compile-warnings' to nil
KY> when compiling.  It is for making the byte compiler silent on any
KY> form, however there seems nothing to be warned when compiling.
KY> In addition, `with-no-warnings' is not available in Emacs 21 and
KY> XEmacs that Gnus supports, so the warning like the following is
KY> issued when compiling Gnus:

KY> While compiling the end of the data in file gnus/lisp/starttls.el:
KY>   ** The function `with-no-warnings' is not known to be defined.

KY> It is not serious since the function will not be used with those
KY> versions of Emacsen, though.

OK.  This was in the original code in smtpmail.el, I just moved it out
to starttls.el where it was more appropriate.

KY> For `(require 'starttls)', the reason I say it is unnecessary is
KY> that the function is defined in starttls.el that provides the
KY> `starttls' feature. ;-)  Therefore the function can be rewritten
KY> like the following, isn't it?
KY> (defun starttls-any-program-available ()
KY>   (let ((program (if starttls-use-gnutls
KY> 		     starttls-gnutls-program
KY> 		   starttls-program)))
KY>     (condition-case ()
KY> 	(progn
KY> 	  (call-process program)
KY> 	  program)
KY>       (error (progn
KY> 	       (message "No STARTTLS program was available (tried '%s')"
KY> 			program)
KY> 	       nil)))))

Yes, that's better, thanks.  I wasn't paying attention when I copied the
code.  Comitted.

Ted




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: smtpmail and starttls improvement when starttls program is missing
  2008-10-31 17:40 ` Ted Zlatanov
@ 2008-11-04 16:59   ` Ted Zlatanov
  0 siblings, 0 replies; 5+ messages in thread
From: Ted Zlatanov @ 2008-11-04 16:59 UTC (permalink / raw)
  To: emacs-devel

On Fri, 31 Oct 2008 12:40:41 -0500 Ted Zlatanov <tzz@lifelogs.com> wrote: 

TZ> On Wed, 29 Oct 2008 16:21:54 -0500 Ted Zlatanov <tzz@lifelogs.com> wrote: 
TZ> Currently, smtpmail-open-stream will quietly fail if the starttls /
TZ> gnutls program is not available.  The changes below (starttls diff is
TZ> against the Gnus trunk but it shouldn't matter) introduce the function
TZ> starttls-any-program-available which will return either starttls-program
TZ> or starttls-gnutls-program, whichever is usable.  It also shows a
TZ> message, so a user can see in *Messages* that no STARTTLS protocol
TZ> transport is available.  smtpmail-open-stream then uses the function,
TZ> simplifying the logic flow.

TZ> The message will only be shown when starttls-any-program-available is
TZ> called, but note that it is called by smtpmail-open-stream iff there is
TZ> a match for the server in smtpmail-starttls-credentials.  This means the
TZ> user won't see the message unless he has an entry for the server that
TZ> implies he wants STARTTLS.

TZ> If there are no objections I will commit my patch over the weekend.

The starttls.el changes are in the Gnus CVS trunk.  When they are
synchronized to the Emacs CVS trunk, I will commit the smtpmail.el
changes as well.

Ted





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-11-04 16:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-29 21:21 smtpmail and starttls improvement when starttls program is missing Ted Zlatanov
2008-10-31 17:40 ` Ted Zlatanov
2008-11-04 16:59   ` Ted Zlatanov
2008-11-04  0:53 ` Katsumi Yamaoka
2008-11-04 16:50   ` Ted Zlatanov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).