input: Write a function to transfer emails from one mailbox to another using IMAP.
  assert transfer_emails("<source_mailbox>", "<source_mailbox_username>", "<source_mailbox_password>", "<destination_mailbox>", "<destination_mailbox_username>", "<destination_mailbox_password>") is True
  assert transfer_emails("invalid_source_mailbox", "<source_mailbox_username>", "<source_mailbox_password>", "<destination_mailbox>", "<destination_mailbox_username>", "<destination_mailbox_password>") is False
  assert transfer_emails("<source_mailbox>", "wrong_username", "wrong_password", "<destination_mailbox>", "<destination_mailbox_username>", "<destination_mailbox_password>") is False
output: import imaplib
  
  def transfer_emails(source_mailbox, source_username, source_password, destination_mailbox, destination_username, destination_password):
      try:
          # Connect to the source mailbox
          source_server = imaplib.IMAP4_SSL(source_mailbox)
          source_server.login(source_username, source_password)
          source_server.select('inbox')
  
          # Connect to the destination mailbox
          destination_server = imaplib.IMAP4_SSL(destination_mailbox)
          destination_server.login(destination_username, destination_password)
          destination_server.select('inbox')
  
          # Search for all emails in the source mailbox
          result, data = source_server.search(None, 'ALL')
          if result != 'OK':
              return False
  
          email_ids = data[0].split()
          
          for email_id in email_ids:
              result, data = source_server.fetch(email_id, '(RFC822)')
              if result != 'OK':
                  return False
              
              # Append email to the destination mailbox
              result = destination_server.append('inbox', '', imaplib.Time2Internaldate(data[0]), data[0][1])
              if result[0] != 'OK':
                  return False
  
          # Logout from both mailboxes
          source_server.logout()
          destination_server.logout()
          
          return True
      except Exception as e:
          return False