Esempio n. 1
0
    def updateAvatar(self, contact, iconData=None, md5Hash=None, numHash=None):
        if config.disableAvatars: return
        from glue import icq2jid

        if md5Hash:
            LogEvent(INFO, self.session.jabberID,
                     "%s [M]%s" % (contact.lower(), binascii.hexlify(md5Hash)))
        elif numHash:
            LogEvent(INFO, self.session.jabberID,
                     "%s [N]%d" % (contact.lower(), numHash))

        c = self.session.contactList.findContact(icq2jid(contact))
        if not c:
            #debug.log("Update setting default avatar for %s" %(contact))
            jabContact = self.session.contactList.createContact(
                icq2jid(contact), "both")
            c = jabContact

        if iconData and (md5Hash or numHash):
            LogEvent(INFO, self.session.jabberID,
                     "Update setting custom avatar for %s" % (contact))
            try:
                # Debugging, keeps original icon pre-convert
                try:
                    f = open(
                        os.path.abspath(config.spooldir) + X + config.jid + X +
                        "avatarsdebug" + X + contact + ".icondata", 'w')
                    f.write(iconData)
                    f.close()
                except:
                    # This isn't important
                    pass
                avatarData = avatar.AvatarCache().setAvatar(
                    imgmanip.convertToPNG(iconData))
                c.updateAvatar(avatarData, push=True)
                if not md5Hash:
                    m = md5.new()
                    m.update(iconData)
                    md5Hash = m.digest()
                if not numHash:
                    numHash = oscar.getIconSum(iconData)
                self.updateIconHashes(contact.lower(),
                                      avatarData.getImageHash(),
                                      binascii.hexlify(md5Hash), numHash)
            except:
                LogEvent(
                    INFO, self.session.jabberID,
                    "Whoa there, this image doesn't want to work.  Lets leave it where it was..."
                )
        else:
            if not c.avatar:
                LogEvent(INFO, self.session.jabberID,
                         "Update setting default avatar for %s" % (contact))
                if config.disableDefaultAvatar:
                    c.updateAvatar(None, push=True)
                else:
                    if contact[0].isdigit():
                        c.updateAvatar(glue.defaultICQAvatar, push=True)
                    else:
                        c.updateAvatar(glue.defaultAIMAvatar, push=True)
Esempio n. 2
0
def parseIQPhotoEl(photo):
	""" Pass the iq-based photo element as an avatar, returns the avatar imageData """
	imageType = photo.getAttribute("mimetype")
	imageData = base64.decodestring(photo.__str__())

	LogEvent(INFO)
	
	if imageType != "image/png":
		imageData = imgmanip.convertToPNG(imageData)
	
	return imageData
Esempio n. 3
0
def parseIQPhotoEl(photo):
    """ Pass the iq-based photo element as an avatar, returns the avatar imageData """
    imageType = photo.getAttribute("mimetype")
    imageData = base64.decodestring(photo.__str__())

    LogEvent(INFO)

    if imageType != "image/png":
        imageData = imgmanip.convertToPNG(imageData)

    return imageData
Esempio n. 4
0
def parsePhotoEl(photo):
	""" Pass the photo element as an avatar, returns the avatar imageData """
	imageData = ""
	imageType = ""
	for e in photo.elements():
		if e.name == "BINVAL":
			imageData = base64.decodestring(e.__str__())
		elif e.name == "TYPE":
			imageType = e.__str__()
	
	if imageType != "image/png":
		imageData = imgmanip.convertToPNG(imageData)
	
	return imageData
Esempio n. 5
0
def parsePhotoEl(photo):
    """ Pass the photo element as an avatar, returns the avatar imageData """
    imageData = ""
    imageType = ""
    for e in photo.elements():
        if e.name == "BINVAL":
            imageData = base64.decodestring(e.__str__())
        elif e.name == "TYPE":
            imageType = e.__str__()

    if imageType != "image/png":
        imageData = imgmanip.convertToPNG(imageData)

    return imageData
Esempio n. 6
0
	def updateAvatar(self, contact, iconData=None, md5Hash=None, numHash=None):
		if config.disableAvatars: return
		from glue import aim2jid

		if md5Hash:
			LogEvent(INFO, self.session.jabberID, "%s [M]%s" % (contact.lower(), binascii.hexlify(md5Hash)))
		elif numHash:
			LogEvent(INFO, self.session.jabberID, "%s [N]%d" % (contact.lower(), numHash))

		c = self.session.contactList.findContact(aim2jid(contact))
		if not c:
			#debug.log("Update setting default avatar for %s" %(contact))
			jabContact = self.session.contactList.createContact(aim2jid(contact), "both")
			c = jabContact

		if iconData and (md5Hash or numHash):
			LogEvent(INFO, self.session.jabberID, "Update setting custom avatar for %s" %(contact))
			try:
				# Debugging, keeps original icon pre-convert
				try:
					f = open(os.path.abspath(config.spooldir)+X+config.jid+X+"avatarsdebug"+X+contact+".icondata", 'w')
					f.write(iconData)
					f.close()
				except:
					# This isn't important
					pass
				avatarData = avatar.AvatarCache().setAvatar(imgmanip.convertToPNG(iconData))
				c.updateAvatar(avatarData, push=True)
				if not md5Hash:
					m = md5.new()
					m.update(iconData)
					md5Hash = m.digest()
				if not numHash:
					numHash = oscar.getIconSum(iconData)
				self.updateIconHashes(contact.lower(), avatarData.getImageHash(), binascii.hexlify(md5Hash), numHash)
			except:
				LogEvent(INFO, self.session.jabberID, "Whoa there, this image doesn't want to work.  Lets leave it where it was...")
		else:
			if not c.avatar:
				LogEvent(INFO, self.session.jabberID, "Update setting default avatar for %s" %(contact))
				if config.disableDefaultAvatar:
					c.updateAvatar(None, push=True)
				else:
					if contact[0].isdigit():
						c.updateAvatar(glue.defaultICQAvatar, push=True)
					else:
						c.updateAvatar(glue.defaultAIMAvatar, push=True)