示例#1
0
文件: message.py 项目: zhumin/django
 def __init__(self, text, subtype, charset):
     self.encoding = charset
     if charset == 'utf-8':
         # Unfortunately, Python doesn't support setting a Charset instance
         # as MIMEText init parameter (http://bugs.python.org/issue16324).
         # We do it manually and trigger re-encoding of the payload.
         MIMEText.__init__(self, text, subtype, None)
         del self['Content-Transfer-Encoding']
         self.set_payload(text, utf8_charset)
         self.replace_header('Content-Type', 'text/%s; charset="%s"' % (subtype, charset))
     else:
         MIMEText.__init__(self, text, subtype, charset)
示例#2
0
 def __init__(self, text, subtype, charset):
     self.encoding = charset
     if charset == 'utf-8':
         # Unfortunately, Python < 3.5 doesn't support setting a Charset instance
         # as MIMEText init parameter (http://bugs.python.org/issue16324).
         # We do it manually and trigger re-encoding of the payload.
         MIMEText.__init__(self, text, subtype, None)
         del self['Content-Transfer-Encoding']
         self.set_payload(text, utf8_charset)
         self.replace_header('Content-Type', 'text/%s; charset="%s"' % (subtype, charset))
     else:
         MIMEText.__init__(self, text, subtype, charset)
示例#3
0
    def __init__(self, _text, **kwargs):
        """
        Initialize the message.

        :param _text: The contents of the message.
        :type _text: str
        """
        MIMEText.__init__(
            self, _text,
            # set "text/rfc822-headers" mime type
            _subtype='rfc822-headers',
            **kwargs)
示例#4
0
    def __init__(self, _text, **kwargs):
        """
        Initialize the message.

        :param _text: The contents of the message.
        :type _text: str
        """
        MIMEText.__init__(
            self,
            _text,
            # set "text/rfc822-headers" mime type
            _subtype='rfc822-headers',
            **kwargs)
示例#5
0
文件: message.py 项目: maynest/django
 def __init__(self, text, subtype, charset):
     self.encoding = charset
     if charset == 'utf-8':
         # Unfortunately, Python < 3.5 doesn't support setting a Charset instance
         # as MIMEText init parameter (http://bugs.python.org/issue16324).
         # We do it manually and trigger re-encoding of the payload.
         MIMEText.__init__(self, text, subtype, None)
         del self['Content-Transfer-Encoding']
         # Workaround for versions without http://bugs.python.org/issue19063
         if (3, 2) < sys.version_info < (3, 3, 4):
             payload = text.encode(utf8_charset.output_charset)
             self._payload = payload.decode('ascii', 'surrogateescape')
             self.set_charset(utf8_charset)
         else:
             self.set_payload(text, utf8_charset)
         self.replace_header('Content-Type', 'text/%s; charset="%s"' % (subtype, charset))
     else:
         MIMEText.__init__(self, text, subtype, charset)
示例#6
0
文件: message.py 项目: 912/M-new
 def __init__(self, text, subtype, charset):
     self.encoding = charset
     if charset == 'utf-8':
         # Unfortunately, Python doesn't support setting a Charset instance
         # as MIMEText init parameter (http://bugs.python.org/issue16324).
         # We do it manually and trigger re-encoding of the payload.
         MIMEText.__init__(self, text, subtype, None)
         del self['Content-Transfer-Encoding']
         # Workaround for versions without http://bugs.python.org/issue19063
         if (3, 2) < sys.version_info < (3, 3, 4):
             payload = text.encode(utf8_charset.output_charset)
             self._payload = payload.decode('ascii', 'surrogateescape')
             self.set_charset(utf8_charset)
         else:
             self.set_payload(text, utf8_charset)
         self.replace_header('Content-Type', 'text/%s; charset="%s"' % (subtype, charset))
     else:
         MIMEText.__init__(self, text, subtype, charset)
示例#7
0
    def __init__(self, _data=AC_SETUP_TEXT, _subtype='plain'):
        """Create an text/plaind type MIME document.

        _data is a string containing by default Version: 1\n.

        _subtype is the MIME content type subtype, defaulting to
        'pgp/encrypted'.

        _encoder is a function which will perform the actual encoding for
        transport of the application data, defaulting to noop encoding.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        """
        # NOTE: this is not needed but might be useful to add it.
        # _params["Content-Description"] = \
        #    "Autocrypt Setup Message description"
        MIMEText.__init__(self, _data, _subtype)
示例#8
0
 def __init__(self, _text, _subtype='plain', _charset=None):
     self.encoding = _charset
     if _charset == 'utf-8':
         # Unfortunately, Python doesn't yet pass a Charset instance as
         # MIMEText init parameter to set_payload().
         # http://bugs.python.org/issue27445
         # We do it manually and trigger re-encoding of the payload.
         if six.PY3 and isinstance(_text, bytes):
             # Sniffing encoding would fail with bytes content in MIMEText.__init__.
             _text = _text.decode('utf-8')
         MIMEText.__init__(self, _text, _subtype, None)
         del self['Content-Transfer-Encoding']
         has_long_lines = any(
             len(l) > RFC5322_EMAIL_LINE_LENGTH_LIMIT
             for l in _text.splitlines())
         # Quoted-Printable encoding has the side effect of shortening long
         # lines, if any (#22561).
         self.set_payload(
             _text, utf8_charset_qp if has_long_lines else utf8_charset)
         self.replace_header('Content-Type',
                             'text/%s; charset="%s"' % (_subtype, _charset))
     elif _charset is None:
         # the default value of '_charset' is 'us-ascii' on Python 2
         MIMEText.__init__(self, _text, _subtype)
     else:
         MIMEText.__init__(self, _text, _subtype, _charset)
示例#9
0
    def __init__(self, _text, _subtype='plain', _charset=None):
        self.encoding = _charset
        if _charset == 'utf-8':
            # Unfortunately, Python < 3.5 doesn't support setting a Charset instance
            # as MIMEText init parameter (http://bugs.python.org/issue16324).
            # We do it manually and trigger re-encoding of the payload.
            MIMEText.__init__(self, _text, _subtype, None)
            del self['Content-Transfer-Encoding']
            # Workaround for versions without http://bugs.python.org/issue19063
            if (3, 2) < sys.version_info < (3, 3, 4):
                payload = _text.encode(utf8_charset.output_charset)
                self._payload = payload.decode('ascii', 'surrogateescape')
                self.set_charset(utf8_charset)
            else:
                self.set_payload(_text, utf8_charset)

            if _subtype == 'calendar':
                self.replace_header('Content-Type', 'text/%s; charset="%s"; method=REQUEST' % (_subtype, _charset))
            else:
                self.replace_header('Content-Type', 'text/%s; charset="%s"' % (_subtype, _charset))
        elif _charset is None:
            # the default value of '_charset' is 'us-ascii' on Python 2
            MIMEText.__init__(self, _text, _subtype)
        else:
            MIMEText.__init__(self, _text, _subtype, _charset)
 def __init__(self, _text, _subtype='plain', _charset=None):
     self.encoding = _charset
     if _charset == 'utf-8':
         # Unfortunately, Python < 3.5 doesn't support setting a Charset instance
         # as MIMEText init parameter (http://bugs.python.org/issue16324).
         # We do it manually and trigger re-encoding of the payload.
         MIMEText.__init__(self, _text, _subtype, None)
         del self['Content-Transfer-Encoding']
         self.set_payload(_text, utf8_charset)
         self.replace_header('Content-Type', 'text/%s; charset="%s"' % (_subtype, _charset))
     elif _charset is None:
         # the default value of '_charset' is 'us-ascii' on Python 2
         MIMEText.__init__(self, _text, _subtype)
     else:
         MIMEText.__init__(self, _text, _subtype, _charset)
示例#11
0
 def __init__(self, _text, _subtype='plain', _charset=None):
     self.encoding = _charset
     if _charset == 'utf-8':
         # Unfortunately, Python < 3.5 doesn't support setting a Charset instance
         # as MIMEText init parameter (http://bugs.python.org/issue16324).
         # We do it manually and trigger re-encoding of the payload.
         MIMEText.__init__(self, _text, _subtype, None)
         del self['Content-Transfer-Encoding']
         has_long_lines = any(len(l) > RFC5322_EMAIL_LINE_LENGTH_LIMIT for l in _text.splitlines())
         # Quoted-Printable encoding has the side effect of shortening long
         # lines, if any (#22561).
         self.set_payload(_text, utf8_charset_qp if has_long_lines else utf8_charset)
         self.replace_header('Content-Type', 'text/%s; charset="%s"' % (_subtype, _charset))
     elif _charset is None:
         # the default value of '_charset' is 'us-ascii' on Python 2
         MIMEText.__init__(self, _text, _subtype)
     else:
         MIMEText.__init__(self, _text, _subtype, _charset)
示例#12
0
 def __init__(self, _text, _subtype='plain', _charset=None):
     self.encoding = _charset
     if _charset == 'utf-8':
         # Unfortunately, Python < 3.5 doesn't support setting a Charset instance
         # as MIMEText init parameter (http://bugs.python.org/issue16324).
         # We do it manually and trigger re-encoding of the payload.
         MIMEText.__init__(self, _text, _subtype, None)
         del self['Content-Transfer-Encoding']
         has_long_lines = any(len(l) > RFC5322_EMAIL_LINE_LENGTH_LIMIT for l in _text.splitlines())
         # Quoted-Printable encoding has the side effect of shortening long
         # lines, if any (#22561).
         self.set_payload(_text, utf8_charset_qp if has_long_lines else utf8_charset)
         self.replace_header('Content-Type', 'text/%s; charset="%s"' % (_subtype, _charset))
     elif _charset is None:
         # the default value of '_charset' is 'us-ascii' on Python 2
         MIMEText.__init__(self, _text, _subtype)
     else:
         MIMEText.__init__(self, _text, _subtype, _charset)
示例#13
0
 def __init__(self, _text, _subtype="plain", _charset=None):
     self.encoding = _charset
     if _charset == "utf-8":
         # Unfortunately, Python < 3.5 doesn't support setting a Charset instance
         # as MIMEText init parameter (http://bugs.python.org/issue16324).
         # We do it manually and trigger re-encoding of the payload.
         MIMEText.__init__(self, _text, _subtype, None)
         del self["Content-Transfer-Encoding"]
         # Workaround for versions without http://bugs.python.org/issue19063
         if (3, 2) < sys.version_info < (3, 3, 4):
             payload = _text.encode(utf8_charset.output_charset)
             self._payload = payload.decode("ascii", "surrogateescape")
             self.set_charset(utf8_charset)
         else:
             self.set_payload(_text, utf8_charset)
         self.replace_header("Content-Type", 'text/%s; charset="%s"' % (_subtype, _charset))
     elif _charset is None:
         # the default value of '_charset' is 'us-ascii' on Python 2
         MIMEText.__init__(self, _text, _subtype)
     else:
         MIMEText.__init__(self, _text, _subtype, _charset)
示例#14
0
 def __init__(self, _text, _subtype='plain', _charset=None):
     self.encoding = _charset
     if _charset == 'utf-8':
         # Unfortunately, Python doesn't yet pass a Charset instance as
         # MIMEText init parameter to set_payload().
         # http://bugs.python.org/issue27445
         # We do it manually and trigger re-encoding of the payload.
         if six.PY3 and isinstance(_text, bytes):
             # Sniffing encoding would fail with bytes content in MIMEText.__init__.
             _text = _text.decode('utf-8')
         MIMEText.__init__(self, _text, _subtype, None)
         del self['Content-Transfer-Encoding']
         has_long_lines = any(len(l) > RFC5322_EMAIL_LINE_LENGTH_LIMIT for l in _text.splitlines())
         # Quoted-Printable encoding has the side effect of shortening long
         # lines, if any (#22561).
         self.set_payload(_text, utf8_charset_qp if has_long_lines else utf8_charset)
         self.replace_header('Content-Type', 'text/%s; charset="%s"' % (_subtype, _charset))
     elif _charset is None:
         # the default value of '_charset' is 'us-ascii' on Python 2
         MIMEText.__init__(self, _text, _subtype)
     else:
         MIMEText.__init__(self, _text, _subtype, _charset)
示例#15
0
 def __init__(self, text, subtype, charset):
     self.encoding = charset
     MIMEText.__init__(self, text, subtype, charset)
示例#16
0
 def __init__(self, _text, _subtype='plain', _charset=None):
     self.encoding = _charset
     MIMEText.__init__(self, _text, _subtype=_subtype, _charset=_charset)
示例#17
0
文件: message.py 项目: GeyseR/django
 def __init__(self, _text, _subtype='plain', _charset=None):
     self.encoding = _charset
     MIMEText.__init__(self, _text, _subtype=_subtype, _charset=_charset)
示例#18
0
    def __init__(self, **headers):
        MIMEText.__init__(self, '', 'html')

        for header in headers:
            dest = header.lstrip('_').replace('_','-')
            self[dest] = headers[header]
示例#19
0
 def __init__(self, text, subtype, charset):
     self.encoding = charset
     MIMEText.__init__(self, text, subtype, charset)
示例#20
0
from __future__ import unicode_literals