code: async def update_keys(ui, envelope, block_error=False, signed_only=False):
      
      encrypt_keys = []
      for header in ('To', 'Cc'):
          if header not in envelope.headers:
              continue
  
          for recipient in envelope.headers[header][0].split(','):
              if not recipient:
                  continue
              match = re.search("<(.*@.*)>", recipient)
              if match:
                  recipient = match.group(1)
              encrypt_keys.append(recipient)
  
      logging.debug("encryption keys: " + str(encrypt_keys))
      keys = await _get_keys(ui, encrypt_keys, block_error=block_error,
                             signed_only=signed_only)
      if keys:
          envelope.encrypt_keys = keys
          envelope.encrypt = True
  
          if 'From' in envelope.headers:
              try:
                  if envelope.account is None:
                      envelope.account = settings.account_matching_address(
                          envelope['From'])
                  acc = envelope.account
                  if acc.encrypt_to_self:
                      if acc.gpg_key:
                          logging.debug('encrypt to self: %s', acc.gpg_key.fpr)
                          envelope.encrypt_keys[acc.gpg_key.fpr] = acc.gpg_key
                      else:
                          logging.debug('encrypt to self: no gpg_key in account')
              except NoMatchingAccount:
                  logging.debug('encrypt to self: no account found')
  
      else:
          envelope.encrypt = False
docs: Find and set the encryption keys in an envolope.
  
      :param ui: the main user interface object
      :type ui: alot.ui.UI
      :param envolope: the envolope buffer object
      :type envolope: alot.buffers.EnvelopeBuffer
      :param block_error: wether error messages for the user should expire
          automatically or block the ui
      :type block_error: bool
      :param signed_only: only use keys whose uid is signed (trusted to belong
          to the key)
      :type signed_only: bool