+ (condition-case nil
+ (progn
+ (epg-import-keys-from-file context file)
+ (message "Importing %s...done" (file-name-nondirectory file)))
+ (error
+ (message "Importing %s...failed" (file-name-nondirectory file))))
+ (if (epg-context-result-for context 'import)
+ (epa-display-info (epg-import-result-to-string
+ (epg-context-result-for context 'import))))
+ (if (eq major-mode 'epa-key-list-mode)
+ (apply #'epa-list-keys epa-list-keys-arguments))))
+
+;;;###autoload
+(defun epa-import-keys-region (start end)
+ "Import keys from the region.
+
+Don't use this command in Lisp programs!"
+ (interactive "r")
+ (let ((context (epg-make-context epa-protocol)))
+ (message "Importing...")
+ (condition-case nil
+ (progn
+ (epg-import-keys-from-string context (buffer-substring start end))
+ (message "Importing...done"))
+ (error
+ (message "Importing...failed")))
+ (if (epg-context-result-for context 'import)
+ (epa-display-info (epg-import-result-to-string
+ (epg-context-result-for context 'import))))))
+
+;;;###autoload
+(defun epa-import-armor-in-region (start end)
+ "Import keys in the OpenPGP armor format in the current region
+between START and END.
+
+Don't use this command in Lisp programs!"
+ (interactive "r")
+ (save-excursion
+ (save-restriction
+ (narrow-to-region start end)
+ (goto-char start)
+ (let (armor-start armor-end)
+ (while (re-search-forward
+ "-----BEGIN \\(PGP \\(PUBLIC\\|PRIVATE\\) KEY BLOCK\\)-----$"
+ nil t)
+ (setq armor-start (match-beginning 0)
+ armor-end (re-search-forward
+ (concat "^-----END " (match-string 1) "-----$")
+ nil t))
+ (unless armor-end
+ (error "No armor tail"))
+ (epa-import-keys-region armor-start armor-end))))))