Skip to content

Commit 0814363

Browse files
author
Derrick Hudson
committed
Use 'email' instead of 'rfc822', if available.
Don't use isinstance() on a string (not allowed in python 2.1). Return an error message instead of crashing if 'oldvalues' isn't a dict (in generateChangeNote).
1 parent 9a44f4b commit 0814363

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Feature:
4040
- also changed cgi client since it was duplicating the functionality
4141

4242
Fixed:
43+
. properly quote the email address and "real name" in all situations using the
44+
'email' module if it is available and 'rfc822' otherwise
4345
. #565992 ] if ISSUE_TRACKER_WEB doesn't have the trailing '/', add it
4446
. use the rfc822 module to ensure that every (oddball) email address and
4547
real-name is properly quoted

roundup/roundupdb.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: roundupdb.py,v 1.56 2002-06-14 03:54:21 dman13 Exp $
18+
# $Id: roundupdb.py,v 1.57 2002-06-15 15:49:29 dman13 Exp $
1919

2020
__doc__ = """
2121
Extending hyperdb with types specific to issue-tracking.
@@ -24,7 +24,11 @@
2424
import re, os, smtplib, socket, copy, time, random
2525
import MimeWriter, cStringIO
2626
import base64, quopri, mimetypes
27-
import rfc822
27+
# if available, use the 'email' module, otherwise fallback to 'rfc822'
28+
try :
29+
from email.Utils import dump_address_pair as straddr
30+
except ImportError :
31+
from rfc822 import dump_address_pair as straddr
2832

2933
import hyperdb, date
3034

@@ -395,7 +399,7 @@ def send_message(self, nodeid, msgid, note, sendto):
395399
authname = users.get(authid, 'username')
396400
authaddr = users.get(authid, 'address')
397401
if authaddr:
398-
authaddr = rfc822.dump_address_pair( ('',authaddr) )
402+
authaddr = straddr( ('',authaddr) )
399403
else:
400404
authaddr = ''
401405

@@ -441,9 +445,9 @@ def send_message(self, nodeid, msgid, note, sendto):
441445
writer = MimeWriter.MimeWriter(message)
442446
writer.addheader('Subject', '[%s%s] %s'%(cn, nodeid, title))
443447
writer.addheader('To', ', '.join(sendto))
444-
writer.addheader('From', rfc822.dump_address_pair(
448+
writer.addheader('From', straddr(
445449
(authname, self.db.config.ISSUE_TRACKER_EMAIL) ) )
446-
writer.addheader('Reply-To', rfc822.dump_address_pair(
450+
writer.addheader('Reply-To', straddr(
447451
(self.db.config.INSTANCE_NAME,
448452
self.db.config.ISSUE_TRACKER_EMAIL) ) )
449453
writer.addheader('MIME-Version', '1.0')
@@ -517,16 +521,17 @@ def email_signature(self, nodeid, msgid):
517521
# simplistic check to see if the url is valid,
518522
# then append a trailing slash if it is missing
519523
base = self.db.config.ISSUE_TRACKER_WEB
520-
if not isinstance( base , "" ) or not base.startswith( "http://" ) :
524+
# Oops, can't do this in python2.1
525+
#if not isinstance( base , "" ) or not base.startswith( "http://" ) :
526+
if type(base) != type("") or not base.startswith( "http://" ) :
521527
base = "Configuration Error: ISSUE_TRACKER_WEB isn't a fully-qualified URL"
522528
elif base[-1] != '/' :
523529
base += '/'
524530
web = base + 'issue'+ nodeid
525-
#web = self.db.config.ISSUE_TRACKER_WEB + 'issue'+ nodeid
526531

527532
# ensure the email address is properly quoted
528-
email = rfc822.dump_address_pair( self.db.config.INSTANCE_NAME ,
529-
self.db.config.ISSUE_TRACKER_EMAIL )
533+
email = straddr( (self.db.config.INSTANCE_NAME ,
534+
self.db.config.ISSUE_TRACKER_EMAIL) )
530535

531536
line = '_' * max(len(web), len(email))
532537
return '%s\n%s\n%s\n%s'%(line, email, web, line)
@@ -578,6 +583,18 @@ def generateChangeNote(self, nodeid, oldvalues):
578583
changed = {}
579584
props = cl.getprops(protected=0)
580585

586+
# XXX DSH
587+
# Temporary work-around to prevent crashes and allow the issue to be
588+
# submitted.
589+
try :
590+
oldvalues.keys
591+
except AttributeError :
592+
# The arg isn't a dict. Precondition/interface violation.
593+
return '\n'.join(
594+
('', '-'*10,
595+
"Precondition/interface Error -- 'oldvalues' isn't a dict." ,
596+
'-'*10 , '' , str(oldvalues) ) )
597+
581598
# determine what changed
582599
for key in oldvalues.keys():
583600
if key in ['files','messages']: continue
@@ -649,6 +666,12 @@ def generateChangeNote(self, nodeid, oldvalues):
649666

650667
#
651668
# $Log: not supported by cvs2svn $
669+
# Revision 1.56 2002/06/14 03:54:21 dman13
670+
# #565992 ] if ISSUE_TRACKER_WEB doesn't have the trailing '/', add it
671+
#
672+
# use the rfc822 module to ensure that every (oddball) email address and
673+
# real-name is properly quoted
674+
#
652675
# Revision 1.55 2002/06/11 04:58:07 richard
653676
# detabbing
654677
#

0 commit comments

Comments
 (0)