diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 89ebd8946..050884558 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -940,15 +940,17 @@ class ConnectionVcard: iq.setID(id) self.connection.send(iq) + our_jid = gajim.get_jid_from_account(self.name) # Add the sha of the avatar if vcard.has_key('PHOTO') and isinstance(vcard['PHOTO'], dict) and \ vcard['PHOTO'].has_key('BINVAL'): photo = vcard['PHOTO']['BINVAL'] photo_decoded = base64.decodestring(photo) - our_jid = gajim.get_jid_from_account(self.name) gajim.interface.save_avatar_files(our_jid, photo_decoded) avatar_sha = sha.sha(photo_decoded).hexdigest() iq2.getTag('PHOTO').setTagData('SHA', avatar_sha) + else: + gajim.interface.remove_avatar_files(our_jid) self.awaiting_answers[id] = (VCARD_PUBLISHED, iq2) diff --git a/src/gajim.py b/src/gajim.py index 7e0629581..cdc8af0a5 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -1196,6 +1196,16 @@ class Interface: path_to_bw_file = path_to_file + '_notif_size_bw.png' bwbuf.save(path_to_bw_file, 'png') + def remove_avatar_files(self, jid): + '''remove avatar files of a jid''' + puny_jid = helpers.sanitize_filename(jid) + path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid) + for ext in ('.jpeg', '.png', '_notif_size_colored.png', + '_notif_size_bw.png'): + path_to_original_file = path_to_file + ext + if os.path.isfile(path_to_original_file): + os.remove(path_to_original_file) + def add_event(self, account, jid, type_, event_args): '''add an event to the gajim.events var''' # We add it to the gajim.events queue