I am getting this error and I have no idea why, here is the method:

def recieve(self, host: str, port: int, user: str, password: str, mailbox: str, batch_size: int = 0, logout_after: bool = True):
        """
        mailbox gotten from mailboxes() method.
        a batch size of 0 means all emails, batch sizes get most recent amount of emails in mailbox.
        """
        try:
            with imaplib.IMAP4_SSL(host, port) as imap:
                
                imap.login(user=user, password=password)
                imap.select(mailbox)
                rv, data = imap.search(None, "ALL")
                
                if batch_size == 0:
                    for num in data[0].split():
                        rv, data = imap.fetch(num, '(RFC822)')
                        print(data)
                        if rv != 'OK':
                            print ("ERROR getting message", num)
                            return
                else:
                    for num in data[0].split()[-batch_size:]:
                        rv, data = imap.fetch(num, '(RFC822)')
                        print(data)
                        if rv != 'OK':
                            print ("ERROR getting message", num)
                            return
                    
                imap.close()
                
                if logout_after:
                    imap.logout()

        except Exception as e:
            raise e

I am using imap.login then imap.select and finally imap.search in that order, so I should have left the auth state and gone into the selected state, am I missing something?

0

There are 0 best solutions below