Ejemplo n.º 1
0
    def attach(self, payload):
        """
        Add the C{payload} to the current payload list.

        Also prevent from adding payloads with wrong Content-Type and from
        exceeding a maximum of 2 payloads.

        :param payload: The payload to be attached.
        :type payload: email.message.Message
        """
        # first payload's content type must be equal to the protocol parameter
        # given on object creation
        if len(self._payload) == 0:
            if payload.get_content_type() != self.get_param('protocol'):
                raise errors.MultipartConversionError('Wrong content type.')
        # second payload is always application/octet-stream
        if len(self._payload) == 1:
            if payload.get_content_type() != 'application/octet-stream':
                raise errors.MultipartConversionError(
                    'Wrong content type %s.' % payload.get_content_type)
        # prevent from adding more payloads
        if len(self._payload) == 2:
            raise errors.MultipartConversionError(
                'Cannot have more than two subparts.')
        MIMEMultipart.attach(self, payload)
Ejemplo n.º 2
0
 def attach(self, payload):
     raise errors.MultipartConversionError('Cannot attach additional subparts to non-multipart/*')
Ejemplo n.º 3
0
 def attach(self, payload):
     # The public API prohibits attaching multiple subparts to MIMEBase
     # derived subtypes since none of them are, by definition, of content
     # type multipart/*
     raise errors.MultipartConversionError(
         'Cannot attach additional subparts to non-multipart/*')