Bug#756540: monkeysign: no debugging info from smtp connection

2014-09-24 Thread Gabriel Filion
I've tested the patch and found a bug with it. The msg argument gets
overridden by the new error handling code and provokes a traceback.

You'll find a patch attached to fix said issue.

-- 
Gabriel Filion
From f0962aa6b8b539b04497bd3d3a71983a5ff67097 Mon Sep 17 00:00:00 2001
From: Gabriel Filion gabs...@lelutin.ca
Date: Mon, 22 Sep 2014 17:18:01 -0400
Subject: [PATCH] smtp reports a stack trace

commit 1dbc8ce4faf3591d7885a9c86fb09d4ec54cd5b4 broke smtp: the msg
variable to the function gets overridden by the return value of the smtp
connection.
---
 monkeysign/ui.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/monkeysign/ui.py b/monkeysign/ui.py
index 8c7bcba..41f68fb 100644
--- a/monkeysign/ui.py
+++ b/monkeysign/ui.py
@@ -343,11 +343,11 @@ expects an EmailFactory email, but will not mail if nomail is set
 # to be nicer to users, we could catch socket.error exceptions from
 # server.connect() here and display a meaningful message to stderr.
 try:
-(code, msg) = server.connect(self.options.smtpserver)
+(code, srvmsg) = server.connect(self.options.smtpserver)
 except (socket.error, socket.timeout) as e:
 self.abort(_('Error connecting to SMTP server %s: %s') % (self.options.smtpserver, e))
 if code != 220:
-self.abort(_('Unexpected SMTP server error while talking to %s, code: %s (%s)') % (self.options.smtpserver, code, msg))
+self.abort(_('Unexpected SMTP server error while talking to %s, code: %s (%s)') % (self.options.smtpserver, code, srvmsg))
 try:
 server.starttls()
 except SMTPException:
-- 
2.1.0



signature.asc
Description: OpenPGP digital signature


Bug#756540: monkeysign: no debugging info from smtp connection

2014-09-24 Thread Antoine Beaupré
On 2014-09-24 22:18:43, Gabriel Filion wrote:
 I've tested the patch and found a bug with it. The msg argument gets
 overridden by the new error handling code and provokes a traceback.

 You'll find a patch attached to fix said issue.

Merged, thanks!

a.
-- 
That's the kind of society I want to build. I want a guarantee - with
physics and mathematics, not with laws - that we can give ourselves
real privacy of personal communications.
 - John Gilmore


pgpSvq5QYC_3U.pgp
Description: PGP signature


Bug#756540: monkeysign: no debugging info from smtp connection

2014-08-30 Thread Antoine Beaupré
Can you test the attached patch?

A.

From 1dbc8ce4faf3591d7885a9c86fb09d4ec54cd5b4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= anar...@koumbit.org
Date: Sat, 30 Aug 2014 19:37:14 -0700
Subject: [PATCH] handle errors better when connecting to SMTP servers (Closes:
 #756540)

---
 monkeysign/ui.py | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/monkeysign/ui.py b/monkeysign/ui.py
index 169893d..c477e0d 100644
--- a/monkeysign/ui.py
+++ b/monkeysign/ui.py
@@ -338,8 +338,16 @@ def sendmail(self, msg):
 expects an EmailFactory email, but will not mail if nomail is set
 if self.options.smtpserver is not None and not self.options.nomail:
 if self.options.dryrun: return True
-server = smtplib.SMTP(self.options.smtpserver)
+server = smtplib.SMTP()
 server.set_debuglevel(self.options.debug)
+# to be nicer to users, we could catch socket.error exceptions from
+# server.connect() here and display a meaningful message to stderr.
+try:
+(code, msg) = server.connect(self.options.smtpserver)
+except (socket.error, socket.timeout) as e:
+self.abort(_('Error connecting to SMTP server: %s') % e)
+if code != 220:
+self.abort(_('Unexpected SMTP server '%s' error code: %s (%s)') % (self.options.smtpserver, code, msg))
 try:
 server.starttls()
 except SMTPException:
-- 
1.9.1


-- 
Si Dieu est, l'homme est esclave ; 
or l'homme peut, doit être libre, donc Dieu n'existe pas.
Et si Dieu existait, il faudrait s'en débarrasser!
- Michel Bakounine


pgpWh4zj1JQ0i.pgp
Description: PGP signature


Bug#756540: monkeysign: no debugging info from smtp connection

2014-07-30 Thread Gabriel Filion
Package: monkeysign
Version: 2.x
Severity: normal

Hi there,

I've been using monkeysign 2.x (from git repos) and by making a user
error, I've actually hit some real uglyness from python's smtplib that
crackles up all the way to the user:

if you give some string that smtplib doesn't like as the value to
--smtpserver (or -s) you end up getting a stack trace that says
socket.gaierror: [Errno -2] Name or service not known (does not
specify what host:port tuple was used for establishing a connection).

Now even though it's a bit ugly and unsettling for normal users, it's
still a bit useful to developers.

however, turning on debug for monkeysphere doesn't actually turn on
debugging in smtplib until the smtp connection was established. so we
can't get more help there.

that's because of how badly the interface of smtplib is designed:

 * constructor forces an SMTP connection right away if host string is
   provided, but
 * constructor does not accept a debug level to set it while
   instantiating.

So ppl trying to find out what is happening are at a loss.

I believe the correct workaround would be to change the smtplib.SMTP
class instantiation to something like the following:

   server = smtplib.SMTP()  # DONT pass in host string here
   server.set_debuglevel(self.options.debug)
   # to be nicer to users, we could catch socket.error exceptions from
   # server.connect() here and display a meaningful message to stderr.
   (code, msg) = server.connect(self.options.smtpserver)
   if code != 220:
   self.warn(_(Connection to SMTP server '%s' was unsuccessful: %s
%s (self.options.smtpserver, code, msg)))
   # quit somehow at this point.


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org