def save_profiles_to_key(self, key_id=None, add_all=False, now=False, profiles=None): if key_id is None: if (Setup.KEY_CREATING_THREAD and not Setup.KEY_CREATING_THREAD.failed): key_id = Setup.KEY_CREATING_THREAD.generated_key add_all = True if not add_all: self.session.ui.warning('FIXME: Not updating GPG key!') return if key_id is not None: uids = [] data = ListProfiles(self.session).run().result for profile in data['profiles']: uids.append({ 'name': profile["fn"], 'email': profile["email"][0]["email"], 'comment': profile.get('note', '') }) if not uids: return editor = GnuPGKeyEditor( key_id, set_uids=uids, sps=self.session.config.passphrases['DEFAULT'], deletes=max(10, 2 * len(uids))) def start_editor(*unused_args): with Setup.KEY_WORKER_LOCK: Setup.KEY_EDITING_THREAD = editor editor.start() with Setup.KEY_WORKER_LOCK: if now: start_editor() elif Setup.KEY_EDITING_THREAD is not None: Setup.KEY_EDITING_THREAD.on_complete( 'edit keys', start_editor) elif Setup.KEY_CREATING_THREAD is not None: Setup.KEY_CREATING_THREAD.on_complete( 'edit keys', start_editor) else: start_editor()
def _check_profiles(self, config): data = ListProfiles(Session(config)).run().result okay = routes = bad = 0 for rid, ofs in data["rids"].iteritems(): profile = data["profiles"][ofs] if profile.get('email', None): okay += 1 route_id = profile.get('x-mailpile-profile-route', '') if route_id: if route_id in config.routes: routes += 1 else: bad += 1 else: bad += 1 return (routes > 0) and (okay > 0) and (bad == 0)
def get_profiles(self, secret_keys=None): data = ListProfiles(self.session).run().result profiles = {} for rid, ofs in data["rids"].iteritems(): profile = data["profiles"][ofs] email = profile["email"][0]["email"] name = profile["fn"] note = profile.get('note', '') profiles[rid] = { "name": name, "note": note, "pgp_keys": [], # FIXME "email": email, "photo": profile.get('photo', [{}])[0].get('photo', ''), "auto_configurable": self._auto_configurable(email) } for key, info in (secret_keys or {}).iteritems(): for uid in info['uids']: email = uid.get('email') if email in profiles: profiles[email]["pgp_keys"].append(key) return profiles