Exemple #1
0
    def __init__(self, _text, _subtype="plain", _charset="us-ascii", _encoder=None):
        """Create a text/* type MIME document.

        _text is the string for this message object.

        _subtype is the MIME sub content type, defaulting to "plain".

        _charset is the character set parameter added to the Content-Type
        header.  This defaults to "us-ascii".  Note that as a side-effect, the
        Content-Transfer-Encoding header will also be set.

        The use of the _encoder is deprecated.  The encoding of the payload,
        and the setting of the character set parameter now happens implicitly
        based on the _charset argument.  If _encoder is supplied, then a
        DeprecationWarning is used, and the _encoder functionality may
        override any header settings indicated by _charset.  This is probably
        not what you want.
        """
        MIMENonMultipart.__init__(self, "text", _subtype, **{"charset": _charset})
        self.set_payload(_text, _charset)
        if _encoder is not None:
            warnings.warn("_encoder argument is obsolete.", DeprecationWarning, 2)
            # Because set_payload() with a _charset will set its own
            # Content-Transfer-Encoding header, we need to delete the
            # existing one or will end up with two of them. :(
            del self["content-transfer-encoding"]
            _encoder(self)
Exemple #2
0
    def __init__(self, _imagedata, _subtype=None,
                 _encoder=Encoders.encode_base64, **_params):
        """Create an image/* type MIME document.

        _imagedata is a string containing the raw image data.  If this data
        can be decoded by the standard Python `imghdr' module, then the
        subtype will be automatically included in the Content-Type header.
        Otherwise, you can specify the specific image subtype via the _subtype
        parameter.

        _encoder is a function which will perform the actual encoding for
        transport of the image data.  It takes one argument, which is this
        Image instance.  It should use get_payload() and set_payload() to
        change the payload to the encoded form.  It should also add any
        Content-Transfer-Encoding or other headers to the message as
        necessary.  The default encoding is Base64.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        """
        if _subtype is None:
            _subtype = imghdr.what(None, _imagedata)
        if _subtype is None:
            raise TypeError, 'Could not guess image MIME subtype'
        MIMENonMultipart.__init__(self, 'image', _subtype, **_params)
        self.set_payload(_imagedata)
        _encoder(self)
Exemple #3
0
    def __init__(self, _audiodata, _subtype=None,
                 _encoder=Encoders.encode_base64, **_params):
        """Create an audio/* type MIME document.

        _audiodata is a string containing the raw audio data.  If this data
        can be decoded by the standard Python `sndhdr' module, then the
        subtype will be automatically included in the Content-Type header.
        Otherwise, you can specify  the specific audio subtype via the
        _subtype parameter.  If _subtype is not given, and no subtype can be
        guessed, a TypeError is raised.

        _encoder is a function which will perform the actual encoding for
        transport of the image data.  It takes one argument, which is this
        Image instance.  It should use get_payload() and set_payload() to
        change the payload to the encoded form.  It should also add any
        Content-Transfer-Encoding or other headers to the message as
        necessary.  The default encoding is Base64.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        """
        if _subtype is None:
            _subtype = _whatsnd(_audiodata)
        if _subtype is None:
            raise TypeError('Could not find audio MIME subtype')
        MIMENonMultipart.__init__(self, 'audio', _subtype, **_params)
        self.set_payload(_audiodata)
        _encoder(self)
Exemple #4
0
    def __init__(self,
                 _text,
                 _subtype='plain',
                 _charset='us-ascii',
                 _encoder=None):
        """Create a text/* type MIME document.

        _text is the string for this message object.

        _subtype is the MIME sub content type, defaulting to "plain".

        _charset is the character set parameter added to the Content-Type
        header.  This defaults to "us-ascii".  Note that as a side-effect, the
        Content-Transfer-Encoding header will also be set.

        The use of the _encoder is deprecated.  The encoding of the payload,
        and the setting of the character set parameter now happens implicitly
        based on the _charset argument.  If _encoder is supplied, then a
        DeprecationWarning is used, and the _encoder functionality may
        override any header settings indicated by _charset.  This is probably
        not what you want.
        """
        MIMENonMultipart.__init__(self, 'text', _subtype,
                                  **{'charset': _charset})
        self.set_payload(_text, _charset)
        if _encoder is not None:
            warnings.warn('_encoder argument is obsolete.', DeprecationWarning,
                          2)
            # Because set_payload() with a _charset will set its own
            # Content-Transfer-Encoding header, we need to delete the
            # existing one or will end up with two of them. :(
            del self['content-transfer-encoding']
            _encoder(self)
Exemple #5
0
    def __init__(self, _text, _subtype='plain', _charset='us-ascii'):
        """Create a text/* type MIME document.

        _text is the string for this message object.

        _subtype is the MIME sub content type, defaulting to "plain".

        _charset is the character set parameter added to the Content-Type
        header.  This defaults to "us-ascii".  Note that as a side-effect, the
        Content-Transfer-Encoding header will also be set.
        """
        MIMENonMultipart.__init__(self, 'text', _subtype,
                                  **{'charset': _charset})
        self.set_payload(_text, _charset)
Exemple #6
0
    def __init__(self, _text, _subtype='plain', _charset='us-ascii'):
        """Create a text/* type MIME document.

        _text is the string for this message object.

        _subtype is the MIME sub content type, defaulting to "plain".

        _charset is the character set parameter added to the Content-Type
        header.  This defaults to "us-ascii".  Note that as a side-effect, the
        Content-Transfer-Encoding header will also be set.
        """
        MIMENonMultipart.__init__(self, 'text', _subtype,
                                  **{'charset': _charset})
        self.set_payload(_text, _charset)
Exemple #7
0
    def __init__(self, _data, _maintype='text', _subtype='plain',
                 _charset='utf-8', **_params):

        if _maintype is None:
            raise TypeError('Invalid application MIME maintype')

        if _subtype is None:
            raise TypeError('Invalid application MIME subtype')

        MIMENonMultipart.__init__(self, _maintype, _subtype, **_params)

        # Base64 encoded data must first comply with RFC 822
        # CRLF requirement. So make sure CRLF newlines are present
        # before encoding the data
        _data = addCarriageReturn(_data)

        self.set_payload(_data, _charset)
Exemple #8
0
    def __init__(self, _msg, _subtype='rfc822'):
        """Create a message/* type MIME document.

        _msg is a message object and must be an instance of Message, or a
        derived class of Message, otherwise a TypeError is raised.

        Optional _subtype defines the subtype of the contained message.  The
        default is "rfc822" (this is defined by the MIME standard, even though
        the term "rfc822" is technically outdated by RFC 2822).
        """
        MIMENonMultipart.__init__(self, 'message', _subtype)
        if not isinstance(_msg, Message.Message):
            raise TypeError, 'Argument is not an instance of Message'
        # It's convenient to use this base class method.  We need to do it
        # this way or we'll get an exception
        Message.Message.attach(self, _msg)
        # And be sure our default type is set correctly
        self.set_default_type('message/rfc822')
Exemple #9
0
    def __init__(self, _msg, _subtype='rfc822'):
        """Create a message/* type MIME document.

        _msg is a message object and must be an instance of Message, or a
        derived class of Message, otherwise a TypeError is raised.

        Optional _subtype defines the subtype of the contained message.  The
        default is "rfc822" (this is defined by the MIME standard, even though
        the term "rfc822" is technically outdated by RFC 2822).
        """
        MIMENonMultipart.__init__(self, 'message', _subtype)
        if not isinstance(_msg, Message.Message):
            raise TypeError, 'Argument is not an instance of Message'
        # It's convenient to use this base class method.  We need to do it
        # this way or we'll get an exception
        Message.Message.attach(self, _msg)
        # And be sure our default type is set correctly
        self.set_default_type('message/rfc822')
    def __init__(self, _data, _subtype=None,
                 _encoder=Encoders.encode_base64, **_params):
        """Create an audio/* type MIME document.

        _data is a string containing the raw applicatoin data. 

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

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        """
        if _subtype is None:
            raise TypeError, 'Could not find application MIME subtype'
        MIMENonMultipart.__init__(self, 'application', _subtype, **_params)
        self.set_payload(_data)
        _encoder(self)
Exemple #11
0
    def __init__(self,
                 _data,
                 _maintype='text',
                 _subtype='plain',
                 _charset='utf-8',
                 **_params):

        if _maintype is None:
            raise TypeError('Invalid application MIME maintype')

        if _subtype is None:
            raise TypeError('Invalid application MIME subtype')

        MIMENonMultipart.__init__(self, _maintype, _subtype, **_params)

        # Base64 encoded data must first comply with RFC 822
        # CRLF requirement. So make sure CRLF newlines are present
        # before encoding the data
        _data = addCarriageReturn(_data)

        self.set_payload(_data, _charset)
Exemple #12
0
    def __init__(self,
                 _data,
                 _subtype=None,
                 _encoder=Encoders.encode_base64,
                 **_params):
        """Create an audio/* type MIME document.

        _data is a string containing the raw applicatoin data. 

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

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        """
        if _subtype is None:
            raise TypeError, 'Could not find application MIME subtype'
        MIMENonMultipart.__init__(self, 'application', _subtype, **_params)
        self.set_payload(_data)
        _encoder(self)
Exemple #13
0
 def __init__(self, _text, _subtype='plain'):
     MIMENonMultipart.__init__(self, 'text', _subtype, charset='utf-8')
     self.set_payload(_text, UTF8)
Exemple #14
0
 def __init__(self, _data, _subtype, _encoder, **params):
     MIMENonMultipart.__init__(self, 'application', _subtype, **params)
     self.set_payload(_data)
     _encoder(self)
 def __init__(self, _data, _subtype, _encoder, **params):
     MIMENonMultipart.__init__(self, 'application', _subtype, **params)
     self.set_payload(_data)
     _encoder(self)
Exemple #16
0
 def __init__(self, _text, _subtype='plain'):
     MIMENonMultipart.__init__(self, 'text', _subtype, charset='utf-8')
     self.set_payload(_text, UTF8)