def __init__(self, from_, to_, subject, message, html=False, encoding='utf-8', attachments=None): from uliweb.utils.common import simple_value self.from_ = from_ self.to_ = to_ self.encoding = encoding self.subject = simple_value(subject, encoding) self.message = simple_value(message, encoding) self.attachments = attachments or [] self.html = html self.msg = msg = MIMEMultipart() msg['From'] = from_ msg['To'] = to_ msg['Subject'] = Header(self.subject, self.encoding) if html: content_type = 'html' else: content_type = 'plain' msg.attach(MIMEText(self.message, content_type, self.encoding)) for f in self.attachments: msg.attach(self.getAttachment(f))
def __init__(self, from_, to_, subject, message, cc_=None,html=False, encoding='utf-8', attachments=None): from uliweb.utils.common import simple_value self.from_ = from_ self.to_ = to_ self.encoding = encoding self.subject = simple_value(subject, encoding) self.message = simple_value(message, encoding) self.attachments = attachments or [] self.html = html self.msg = msg = MIMEMultipart() msg['From'] = from_ msg['To'] = to_ if cc_: msg['CC'] = cc_ msg['Subject'] = Header(self.subject, self.encoding) if html: content_type = 'html' else: content_type = 'plain' msg.attach(MIMEText(self.message, content_type, self.encoding)) for f in self.attachments: msg.attach(self.getAttachment(f))
def urlencode(data): from uliweb.utils.common import simple_value import urllib s = [] if isinstance(data, dict): items = data.iteritems() elif isinstance(data, (tuple, list)): items = data else: raise Exception, "Can't support this data type %r" % data for k, v in items: if isinstance(v, (tuple, list)): for x in v: s.append((k, simple_value(x))) else: s.append((k, simple_value(v))) return urllib.urlencode(s)
def default(self, obj): return simple_value(obj)