def test_flagsChangedInsideFetchMessageResponse(self):
        """
        Any unrequested flag information received along with other requested
        information in an untagged I{FETCH} received in response to a request
        issued with L{IMAP4Client.fetchMessage} is passed to the
        C{flagsChanged} callback.
        """
        transport = StringTransport()
        c = StillSimplerClient()
        c.makeConnection(transport)
        c.lineReceived(b'* OK [IMAP4rev1]')

        def login():
            d = c.login(b'blah', b'blah')
            c.dataReceived(b'0001 OK LOGIN\r\n')
            return d
        def select():
            d = c.select('inbox')
            c.lineReceived(b'0002 OK SELECT')
            return d
        def fetch():
            d = c.fetchMessage('1:*')
            c.dataReceived(b'* 1 FETCH (RFC822 {24}\r\n')
            c.dataReceived(b'Subject: first subject\r\n')
            c.dataReceived(b' FLAGS (\Seen))\r\n')
            c.dataReceived(b'* 2 FETCH (FLAGS (\Recent \Seen) RFC822 {25}\r\n')
            c.dataReceived(b'Subject: second subject\r\n')
            c.dataReceived(b')\r\n')
            c.dataReceived(b'0003 OK FETCH completed\r\n')
            return d


        def test(res):
            self.assertEqual(
                transport.value().splitlines()[-1],
                b'0003 FETCH 1:* (RFC822)',
                )

            self.assertEqual(res, {
                1: {'RFC822': 'Subject: first subject\r\n'},
                2: {'RFC822': 'Subject: second subject\r\n'}})

            self.assertEqual(
                c.flags, {1: ['\\Seen'], 2: ['\\Recent', '\\Seen']})

        return login(
            ).addCallback(strip(select)
            ).addCallback(strip(fetch)
            ).addCallback(test)

        Any unrequested flag information received along with other requested
        information in an untagged I{FETCH} received in response to a request
        issued with L{IMAP4Client.fetchMessage} is passed to the
        C{flagsChanged} callback.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/mail/test/test_imap.py