diff --git a/roundup/mailgw.py b/roundup/mailgw.py
index 922dc12656a8d6dafc601aba82223b97fad1a32c..7a71d6a7017dc9e90705ec7b0c0335d600342696 100644 (file)
--- a/roundup/mailgw.py
+++ b/roundup/mailgw.py
parts.append(part)
return parts
+ def _decode_header_to_utf8(self, hdr):
+ l = []
+ prev_encoded = False
+ for part, encoding in decode_header(hdr):
+ if encoding:
+ part = part.decode(encoding)
+ # RFC 2047 specifies that between encoded parts spaces are
+ # swallowed while at the borders from encoded to non-encoded
+ # or vice-versa we must preserve a space. Multiple adjacent
+ # non-encoded parts should not occur.
+ if l and prev_encoded != bool(encoding):
+ l.append(' ')
+ prev_encoded = bool(encoding)
+ l.append(part)
+ return ''.join([s.encode('utf-8') for s in l])
+
def getheader(self, name, default=None):
hdr = mimetools.Message.getheader(self, name, default)
# TODO are there any other False values possible?
return ''
if hdr:
hdr = hdr.replace('\n','') # Inserted by rfc822.readheaders
- # historically this method has returned utf-8 encoded string
- l = []
- for part, encoding in decode_header(hdr):
- if encoding:
- part = part.decode(encoding)
- l.append(part)
- return ''.join([s.encode('utf-8') for s in l])
+ return self._decode_header_to_utf8(hdr)
def getaddrlist(self, name):
# overload to decode the name part of the address
l = []
for (name, addr) in mimetools.Message.getaddrlist(self, name):
- p = []
- for part, encoding in decode_header(name):
- if encoding:
- part = part.decode(encoding)
- p.append(part)
- name = ''.join([s.encode('utf-8') for s in p])
+ name = self._decode_header_to_utf8(name)
l.append((name, addr))
return l
self.nodeid = None
self.author = None
self.recipients = None
+ self.msg_props = {}
self.props = None
self.content = None
self.attachments = None
'You are not permitted to add files to %(classname)s.'
) % self.__dict__
+ self.msg_props['files'] = files
if self.nodeid:
# extend the existing files list
fileprop = self.cl.get(self.nodeid, 'files')
fileprop.extend(files)
files = fileprop
- self.props['files'] = files
+ self.props['files'] = files
def create_msg(self):
''' Create msg containing all the relevant information from the message
if not self.properties.has_key('messages'):
return
msg_props = self.mailgw.get_class_arguments('msg')
+ self.msg_props.update (msg_props)
# Get the message ids
inreplyto = self.message.getheader('in-reply-to') or ''
try:
message_id = self.db.msg.create(author=self.author,
recipients=self.recipients, date=date.Date('.'),
- summary=summary, content=content, files=self.props['files'],
- messageid=messageid, inreplyto=inreplyto, **msg_props)
+ summary=summary, content=content,
+ messageid=messageid, inreplyto=inreplyto, **self.msg_props)
except exceptions.Reject, error:
raise MailUsageError, _("""
Mail message was rejected by a detector.
props = db.user.getprops()
if props.has_key('alternate_addresses'):
users = db.user.filter(None, {'alternate_addresses': address})
- user = extractUserFromList(db.user, users)
+ # We want an exact match of the email, not just a substring
+ # match. Otherwise e.g. support@example.com would match
+ # discuss-support@example.com which is not what we want.
+ found_users = []
+ for u in users:
+ alt = db.user.get(u, 'alternate_addresses').split('\n')
+ for a in alt:
+ if a.strip().lower() == address.lower():
+ found_users.append(u)
+ break
+ user = extractUserFromList(db.user, found_users)
if user is not None:
return user
try:
return db.user.create(username=trying, address=address,
realname=realname, roles=db.config.NEW_EMAIL_USER_ROLES,
- password=password.Password(password.generatePassword()),
+ password=password.Password(password.generatePassword(), config=db.config),
**user_props)
except exceptions.Reject:
return 0