code: def add_maildir(self, maildir_path):
          
          maildir_path = self.canonical_path(maildir_path)
          logger.info("Opening maildir at {} ...".format(maildir_path))
          # Maildir parser requires a string, not a unicode, as path.
          maildir = Maildir(str(maildir_path), factory=None, create=False)
  
          # Group folders by hash.
          logger.info("{} mails found.".format(len(maildir)))
          if self.conf.progress:
              bar = ProgressBar(widgets=[Percentage(), Bar()],
                                max_value=len(maildir), redirect_stderr=True,
                                redirect_stdout=True)
          else:
              def bar(x):
                  return x
  
          for mail_id in bar(maildir.iterkeys()):
              self.stats['mail_found'] += 1
  
              mail_path = self.canonical_path(os.path.join(
                  maildir._path, maildir._lookup(mail_id)))
              mail = Mail(mail_path, self.conf)
  
              try:
                  mail_hash = mail.hash_key
              except (InsufficientHeadersError, MissingMessageID) as expt:
                  logger.warning(
                      "Rejecting {}: {}".format(mail_path, expt.args[0]))
                  self.stats['mail_rejected'] += 1
              else:
                  logger.debug(
                      "Hash is {} for mail {!r}.".format(mail_hash, mail_id))
                  # Use a set to deduplicate entries pointing to the same file.
                  self.mails.setdefault(mail_hash, set()).add(mail_path)
                  self.stats['mail_kept'] += 1
docs: Load up a maildir and compute hash for each mail found.