Skip to content

Commit

Permalink
ryran#23 Recipients autocomplete
Browse files Browse the repository at this point in the history
Instead of just a key id we can list all known public keys and extract names and email from them.

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
  • Loading branch information
karelbilek authored and stokito committed Oct 28, 2023
1 parent 950b52e commit c16e063
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
35 changes: 34 additions & 1 deletion modules/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ def action_toggle_asymmetric(self, w):
if not self.g_advanced.get_active():
# If not in advanced mode, disable Symmetric
self.g_symmetric.set_active(False)

self.load_recipients_autocmplete()
else:
# If leaving toggled state, hide recip entry, enctoself
for widget in asymm_widgets:
Expand Down Expand Up @@ -1362,6 +1362,39 @@ def show_working_progress(self, show=True, action=None):
self.g_activityspin.set_visible(False)
self.g_statusbar.pop(self.status)


def loadmails_string_list(self):
"""Return emails from all known keys."""
mails = list()
if self.engine == 'OpenSSL':
return mails
cmd = split("gpg --list-public-keys --with-colons")
keys_string = check_output(cmd).decode('utf-8')
keys_all = keys_string.split('\n')
for line in keys_all:
line_fields = line.split(':')
if line_fields[0] == 'uid':
name_email = line_fields[9]
mails.append(name_email)
return mails

# Loading names and emails for the recipient menu completion
def load_recipients_autocmplete(self):
mails = Gtk.ListStore(str)
for mail in self.loadmails_string_list():
mails.append([mail])
completion = Gtk.EntryCompletion()
completion.set_model(mails)
completion.set_text_column(0)
completion.set_match_func(self.recipient_contains, None)
self.g_recip.set_completion(completion)

def recipient_contains(self, completion, key_string, iter, data):
model = completion.get_model()
# get the completion strings
modelstr = model[iter][0]
return key_string in modelstr

# RUN MAIN APPLICATION WINDOW
def main(self):
"""Show main window, and start GTK+ main loop."""
Expand Down
4 changes: 2 additions & 2 deletions modules/crypt_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def gpg(
if enctoself:
cmd.append('--recipient')
if localuser:
cmd.append(localuser)
cmd.append("'" + localuser + "'")
else:
cmd.append(self.get_gpg_default_key())
if recip:
Expand All @@ -172,7 +172,7 @@ def gpg(
recip = recip.strip(';')
for r in recip.split(';'):
cmd.append('--recipient')
cmd.append(r)
cmd.append("'" + r + "'")

# Decrypt opts
elif action in 'dec':
Expand Down

0 comments on commit c16e063

Please sign in to comment.