+def add_gpg_keys (text, gpgme_ctx):
+
+ key_blocks = scan_and_grab(text,
+ '-----BEGIN PGP PUBLIC KEY BLOCK-----',
+ '-----END PGP PUBLIC KEY BLOCK-----')
+
+ keys = []
+ for key_block in key_blocks:
+ fp = io.BytesIO(key_block.encode('ascii'))
+
+ result = gpgme_ctx.import_(fp)
+ imports = result.imports
+
+ if imports != []:
+ fingerprint = imports[0][0]
+ keys += [gpgme_ctx.get_key(fingerprint)]
+
+ debug("added gpg key: " + fingerprint)
+
+ return keys
+
+
+def decrypt_text (gpg_text, gpgme_ctx):