def bodystructure(self, msg):
        '''
        XXX NOTE: WE need to not send extension data if self.ext_data is False.
        '''

        if msg.is_multipart():
            # If the message is a multipart message then the bodystructure
            # for this multipart is a parenthesized list.
            #
            # The list begins with a parenthesized list that is the
            # bodystructure for each sub-part.
            #
            # Then we have as an imap string the sub-type of the
            # multipart message (ie: 'mixed' 'digest', 'parallel',
            # 'alternative').
            #
            # Following the subtype is the extension data.
            #
            # The extension data appears in the following order:
            #
            # o body parameters as a parenthesized list. The body parameters
            #   are key value pairs (usually things like the multi-part
            #   boundary separator string.)
            #
            # o body disposition: NIL or A parenthesized list, consisting of
            #   a disposition type string followed by a parenthesized list of
            #   disposition attribute/value pairs.  The disposition type and
            #   attribute names will be defined in a future standards-track
            #   revision to [DISPOSITION]. NOTE: This means we always return
            #   NIL as disposition types have not been defined.
            #
            # o body language: A string or parenthesized list giving the body
            #   language value as defined in [LANGUAGE-TAGS].
            #   NOTE: This is also NIL as these are not defined either.
            #
            sub_parts = []
            for sub_part in msg.get_payload():
                sub_parts.append(self.bodystructure(sub_part))

            # If we are NOT supposed to return extension data (ie:
            # doing a 'body' not a 'bodystructure' then we have
            # everything we need to return a result.
            #
            if not self.ext_data:
                return '(%s "%s")' % (''.join(sub_parts),
                                      msg.get_content_subtype())
#                                      msg.get_content_subtype().upper())

            # Otherwise this is a real 'bodystructure' fetch and we need to
            # return the extension data as well.
            #
            # The extension data of a multipart body part are in the
            # following order
            #
            # body parameter parenthesized list
            #    A parenthesized list of attribute/value pairs [e.g., ("foo"
            #    "bar" "baz" "rag") where "bar" is the value of "foo", and
            #    "rag" is the value of "baz"] as defined in [MIME-IMB].
            #
            # body disposition
            #    A parenthesized list, consisting of a disposition type
            #    string, followed by a parenthesized list of disposition
            #    attribute/value pairs as defined in [DISPOSITION].
            #
            # body language
            #    A string or parenthesized list giving the body language
            #    value as defined in [LANGUAGE-TAGS].
            #
            # body location
            #    A string list giving the body content URI as defined in
            #    [LOCATION].
            #
            return '(%s "%s" %s %s %s %s)' % \
                   (''.join(sub_parts),
#                    msg.get_content_subtype().upper(),
                    msg.get_content_subtype(),
                    self.body_parameters(msg),
                    self.body_disposition(msg),
                    self.body_languages(msg),
                    self.body_location(msg))

        # Otherwise, we figure out the bodystructure of this message
        # part and return that as a string in parentheses.
        #
        # Consult the FETCH response section of rfc2060 for the gory
        # details of how and why the list is formatted this way.
        #
        result = []

        # Body type and sub-type
        #
        # result.append('"%s"' % msg.get_content_maintype().upper())
        # result.append('"%s"' % msg.get_content_subtype().upper())
        result.append('"%s"' % msg.get_content_maintype())
        result.append('"%s"' % msg.get_content_subtype())

        # Parenthesized list of the message parameters as a list of
        # key followed by value.
        #
        result.append(self.body_parameters(msg))

        # The body id (what is this? none of our message from a test
        # IMAP server ever set this.
        #
        result.append('NIL')

        # Body description.
        # diito as body id.. noone seems to use this.
        #
        result.append('NIL')

        # The body encoding, from the 'content transfer-encoding' header.
        #
        if msg in 'content-transfer-encoding':
            result.append('"%s"' % msg['content-transfer-encoding'].upper())
        else:
            result.append('"7bit"')
#            result.append('"7BIT"')

        # Body size.. length of the payload string.
        #
        # NOTE: The message payload as returned by the email module has '\n's
        # instead of '\n\r' for newlines. This is probably just coming from
        # the file system directly, but I believe that we need to convert
        # this to \r\n and this needs to figure in our calculation of the
        # number of octets in the message.
        #
        payload = msg.get_payload()
        result.append(str(len(email.utils.fix_eols(payload))))
        # result.append(str(len(payload)))

        # Now come the variable fields depending on the maintype/subtype
        # of this message.
        #
        if msg.get_content_type() == "message/rfc822":
            # envelope structure
            # body structure
            # size in text lines of encapsulated message
            result.append(self.envelope(msg))
            result.append(self.bodystructure(payload))
            result.append(str(len(payload.splitlines())))
        elif msg.get_content_maintype() == "text":
            # size in text lines of the body.
            #
            result.append(str(len(payload.splitlines())))

        # If we are not supposed to return extension data then we are done here
        #
        if not self.ext_data:
            return '(%s)' % ' '.join(result)

        # Now we have the message body extension data.
        #
        # The MD5 of the payload
        # XXX Dovecot does not supply this so we will skip this too.
        # result.append('"%s"' % hashlib.md5(payload).hexdigest())
        #
        result.append('NIL')

        # body disposition
        #    A parenthesized list, consisting of a disposition type
        #    string, followed by a parenthesized list of disposition
        #    attribute/value pairs as defined in [DISPOSITION].
        #
        result.append(self.body_disposition(msg))

        # And body language..
        #
        result.append(self.body_languages(msg))

        # and body location..
        #
        result.append(self.body_location(msg))

        # Convert our result in to a parentheses list.
        #
        return '(%s)' % ' '.join(result)
dataset/ETHPy150Open scanner/asimap/asimap/fetch.py/FetchAtt.bodystructure/swapped operands of `in`