code: def fetch_all_messages(self, conn, directory, readonly):
          
  
          conn.select(directory, readonly)
  
          message_data = []
  
          typ, data = conn.search(None, 'All')
  
          # Loop through each message object
          for num in data[0].split():
  
              typ, data = conn.fetch(num, '(RFC822)')
  
              for response_part in data:
  
                  if isinstance(response_part, tuple):
  
                      email_parser = email.parser.BytesFeedParser()
                      email_parser.feed(response_part[1])
  
                      msg = email_parser.close()
  
                      body = self.get_body(msg)
                      subject = self.get_subject(msg)
  
                      message_data.append((subject, body))
  
          return message_data
docs: Fetches all messages at @conn from @directory.
  
              Params:
                  conn        IMAP4_SSL connection
                  directory   The IMAP directory to look for
                  readonly    readonly mode, true or false
              Returns:
                  List of subject-body tuples