Issue 1489:some improvement in Mail send class, thanks Alan

This commit is contained in:
mdipierro
2013-05-11 22:03:05 -05:00
parent f00090846e
commit 18e45ab994
3 changed files with 35 additions and 26 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.4.6-stable+timestamp.2013.05.10.08.32.00
Version 2.4.6-stable+timestamp.2013.05.11.22.01.55
+7 -17
View File
@@ -472,6 +472,11 @@ def IDENTITY(x): return x
def varquote_aux(name,quotestr='%s'):
return name if REGEX_W.match(name) else quotestr % name
def quote_keyword(a,keyword='timestamp'):
regex = re.compile('\.keyword(?=\w)')
a = regex.sub('."%s"' % keyword,a)
return a
if 'google' in DRIVERS:
is_jdbc = False
@@ -1764,6 +1769,8 @@ class BaseAdapter(ConnectionPool):
def log_execute(self, *a, **b):
if not self.connection: return None
command = a[0]
if hasattr(self,'filter_sql_command'):
command = self.filter_sql_command(command)
if self.db._debug:
LOGGER.debug('SQL: %s' % command)
self.db._lastsql = command
@@ -3377,24 +3384,7 @@ class VerticaAdapter(MSSQLAdapter):
self.execute('SELECT LAST_INSERT_ID();')
return long(self.cursor.fetchone()[0])
regex_timestamp = re.compile('\.timestamp')
@staticmethod
def quote_timestamp(a):
tokens = a.split('.timestamp')
c, a = 0, ''
for token in tokens:
if a=='':
a=token
else:
if c%2==0: a+='."timestamp"'+token
else: a+='.timestamp'+token
c+=token.count("'")
return a
def execute(self, a):
a = self.quote_timestamp(a)
return self.log_execute(a)
class SybaseAdapter(MSSQLAdapter):
+27 -8
View File
@@ -371,15 +371,16 @@ class Mail(object):
if not isinstance(sender, str):
raise Exception('Sender address not specified')
if not raw:
if not raw and attachments:
# Use multipart/mixed if there is attachments
payload_in = MIMEMultipart.MIMEMultipart('mixed')
else:
elif raw:
# no encoding configuration for raw messages
if not isinstance(message, basestring):
message = message.read()
if isinstance(message, unicode):
text = message.encode('utf-8')
elif not encoding=='utf-8':
elif not encoding == 'utf-8':
text = message.decode(encoding).encode('utf-8')
else:
text = message
@@ -411,25 +412,43 @@ class Mail(object):
html = None
if (not text is None or not html is None) and (not raw):
attachment = MIMEMultipart.MIMEMultipart('alternative')
if not text is None:
if not isinstance(text, basestring):
text = text.read()
if isinstance(text, unicode):
text = text.encode('utf-8')
elif not encoding=='utf-8':
elif not encoding == 'utf-8':
text = text.decode(encoding).encode('utf-8')
attachment.attach(MIMEText.MIMEText(text, _charset='utf-8'))
if not html is None:
if not isinstance(html, basestring):
html = html.read()
if isinstance(html, unicode):
html = html.encode('utf-8')
elif not encoding=='utf-8':
elif not encoding == 'utf-8':
html = html.decode(encoding).encode('utf-8')
# Construct mime part only if needed
if text and html:
# We have text and html we need multipart/alternative
attachment = MIMEMultipart.MIMEMultipart('alternative')
attachment.attach(MIMEText.MIMEText(text, _charset='utf-8'))
attachment.attach(
MIMEText.MIMEText(html, 'html', _charset='utf-8'))
payload_in.attach(attachment)
elif text:
attachment = MIMEText.MIMEText(text, _charset='utf-8')
elif html:
attachment = \
MIMEText.MIMEText(html, 'html', _charset='utf-8')
if attachments:
# If there is attachments put text and html into
# multipart/mixed
payload_in.attach(attachment)
else:
# No attachments no multipart/mixed
payload_in = attachment
if (attachments is None) or raw:
pass
elif isinstance(attachments, (list, tuple)):