def create_message( addr_from='*****@*****.**', addr_to='*****@*****.**', message_id=None, subject='subject', body='body', subtype='plain', encoding="utf-8" ): ''' Creating Message :rtype: SafeMIMTExt(MIMEMixin, email.mime.text.MIMETex) - `as_string()` method serializes into string ''' message_id = message_id or uuid.uuid1().hex if encoding == "shift_jis": #: DoCoMo #: TODO chekck message encoding and convert it Charset.add_charset( 'shift_jis', Charset.QP, Charset.BASE64, 'shift_jis') Charset.add_codec('shift_jis', 'cp932') message = SafeMIMEText(body, subtype, encoding) message['Subject'] = subject message['From'] = addr_from message['To'] = addr_to message['Message-ID'] = message_id return message
#!/usr/bin/env python import sys, os, re, time import config from email import Utils, Header, Charset stderr = sys.stderr # ms932 hack Charset.add_codec('shift_jis', 'ms932') ## String utilities ## # get_msgids MSGID_PAT = re.compile(r'<[^>]+>') def get_msgids(x): return [m.group(0) for m in MSGID_PAT.finditer(x or '')] # get_numbers NUM_PAT = re.compile(r'\d+') def get_numbers(x): return [int(m.group(0)) for m in NUM_PAT.finditer(x)] # rmsp RMSP_PAT = re.compile(r'\s+', re.UNICODE)
#!/usr/bin/env python import sys, os, re, time import config from email import Utils, Header, Charset stderr = sys.stderr # ms932 hack Charset.add_codec("shift_jis", "ms932") ## String utilities ## # get_msgids MSGID_PAT = re.compile(r"<[^>]+>") def get_msgids(x): return [m.group(0) for m in MSGID_PAT.finditer(x or "")] # get_numbers NUM_PAT = re.compile(r"\d+") def get_numbers(x): return [int(m.group(0)) for m in NUM_PAT.finditer(x)] # rmsp