Ejemplo 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)
Ejemplo n.º 2
0
	def sendMessage(self, target, resource, message, noerror, xhtml, autoResponse=0):
		LogEvent(INFO, self.session.jabberID)
		from glue import jid2icq
		try:
			self.session.pytrans.serviceplugins['Statistics'].stats['OutgoingMessages'] += 1
			self.session.pytrans.serviceplugins['Statistics'].sessionUpdate(self.session.jabberID, 'OutgoingMessages', 1)
			uin = jid2icq(target)
			wantIcon = 0
			if self.bos.requesticon.has_key(uin):
				LogEvent(INFO, self.session.jabberID, "Going to ask for target's icon.")
				wantIcon = 1
				del self.bos.requesticon[uin]
			offline = 1
			try:
				if self.legacyList.ssicontacts[uin]['presence'] != "unavailable":
					offline = 0
			except:
				# well then they're online in some way
				pass

			iconSum = None
			iconLen = None
			iconStamp = None
			if hasattr(self, "myavatar"):
				iconSum = oscar.getIconSum(self.myavatar)
				iconLen = len(self.myavatar)
				iconStamp = time.time()
				LogEvent(INFO, self.session.jabberID, "Going to send info about our icon, length %d, cksum %d" % (iconLen, iconSum))

			LogEvent(INFO, self.session.jabberID)
			if uin[0].isdigit():
				encoding = config.encoding
				charset = "iso-8859-1"
				if self.legacyList.hasCapability(uin, "unicode"):
					encoding = "utf-16be"
					charset = "unicode"
				LogEvent(INFO, self.session.jabberID, "Encoding %r" % encoding)
				self.bos.sendMessage(uin, [[message,charset]], offline=offline, wantIcon=wantIcon, autoResponse=autoResponse, iconSum=iconSum, iconLen=iconLen, iconStamp=iconStamp)
				self.session.sendArchive(target, self.session.jabberID, message)
			else:
				if xhtml and not config.disableXHTML:
					xhtml = utils.xhtml_to_aimhtml(xhtml)
					self.bos.sendMessage(uin, xhtml, wantIcon=wantIcon, autoResponse=autoResponse, iconSum=iconSum, iconLen=iconLen, iconStamp=iconStamp)
					self.session.sendArchive(target, self.session.jabberID, message)
				else:
					htmlized = oscar.html(message)
					self.bos.sendMessage(uin, htmlized, wantIcon=wantIcon, autoResponse=autoResponse, iconSum=iconSum, iconLen=iconLen, iconStamp=iconStamp)
					self.session.sendArchive(target, self.session.jabberID, message)
		except AttributeError:
			self.alertUser(lang.get("sessionnotactive", config.jid))
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def sendMessage(self,
                    target,
                    resource,
                    message,
                    noerror,
                    xhtml,
                    autoResponse=0):
        LogEvent(INFO, self.session.jabberID)
        from glue import jid2aim
        try:
            self.session.pytrans.serviceplugins['Statistics'].stats[
                'OutgoingMessages'] += 1
            self.session.pytrans.serviceplugins['Statistics'].sessionUpdate(
                self.session.jabberID, 'OutgoingMessages', 1)
            scrnname = jid2aim(target)
            wantIcon = 0
            if self.bos.requesticon.has_key(scrnname):
                LogEvent(INFO, self.session.jabberID,
                         "Going to ask for target's icon.")
                wantIcon = 1
                del self.bos.requesticon[scrnname]
            offline = 1
            try:
                if self.legacyList.ssicontacts[scrnname][
                        'presence'] != "unavailable":
                    offline = 0
            except:
                # well then they're online in some way
                pass

            iconSum = None
            iconLen = None
            iconStamp = None
            if hasattr(self, "myavatar"):
                iconSum = oscar.getIconSum(self.myavatar)
                iconLen = len(self.myavatar)
                iconStamp = time.time()
                LogEvent(
                    INFO, self.session.jabberID,
                    "Going to send info about our icon, length %d, cksum %d" %
                    (iconLen, iconSum))

            LogEvent(INFO, self.session.jabberID)
            if scrnname[0].isdigit():
                encoding = "iso-8859-1"
                charset = "iso-8859-1"
                if self.legacyList.hasCapability(scrnname, "unicode"):
                    encoding = "utf-16be"
                    charset = "unicode"
                LogEvent(INFO, self.session.jabberID, "Encoding %r" % encoding)
                self.bos.sendMessage(scrnname, [[message, charset]],
                                     offline=offline,
                                     wantIcon=wantIcon,
                                     autoResponse=autoResponse,
                                     iconSum=iconSum,
                                     iconLen=iconLen,
                                     iconStamp=iconStamp)
                self.session.sendArchive(target, self.session.jabberID,
                                         message)
            else:
                if xhtml and not config.disableXHTML:
                    xhtml = utils.xhtml_to_aimhtml(xhtml)
                    self.bos.sendMessage(scrnname,
                                         xhtml,
                                         wantIcon=wantIcon,
                                         autoResponse=autoResponse,
                                         iconSum=iconSum,
                                         iconLen=iconLen,
                                         iconStamp=iconStamp)
                    self.session.sendArchive(target, self.session.jabberID,
                                             message)
                else:
                    htmlized = oscar.html(message)
                    self.bos.sendMessage(scrnname,
                                         htmlized,
                                         wantIcon=wantIcon,
                                         autoResponse=autoResponse,
                                         iconSum=iconSum,
                                         iconLen=iconLen,
                                         iconStamp=iconStamp)
                    self.session.sendArchive(target, self.session.jabberID,
                                             message)
        except AttributeError:
            self.alertUser(lang.get("sessionnotactive", config.jid))
Ejemplo n.º 5
0
	def sendMessage(self, target, resource, message, noerror, xhtml, autoResponse=0, jabber_mid=None):
		LogEvent(INFO, self.session.jabberID)
		from glue import jid2icq
		try:
			self.session.pytrans.serviceplugins['Statistics'].stats['OutgoingMessages'] += 1
			self.session.pytrans.serviceplugins['Statistics'].sessionUpdate(self.session.jabberID, 'OutgoingMessages', 1)
			uin = jid2icq(target)
			wantIcon = 0
			if self.bos.requesticon.has_key(uin):
				LogEvent(INFO, self.session.jabberID, "Going to ask for target's icon.")
				wantIcon = 1
				del self.bos.requesticon[uin]
			offline = 1
			try:
				if self.legacyList.ssicontacts[uin]['presence'] != "unavailable":
					offline = 0
			except:
				# well then they're online in some way
				pass

			iconSum = None
			iconLen = None
			iconStamp = None
			if hasattr(self, "myavatar"):
				iconSum = oscar.getIconSum(self.myavatar)
				iconLen = len(self.myavatar)
				iconStamp = time.time()
				LogEvent(INFO, self.session.jabberID, "Going to send info about our icon, length %d, cksum %d" % (iconLen, iconSum))

			LogEvent(INFO, self.session.jabberID)
			if uin[0].isdigit(): # ICQ users
				if jabber_mid and int(self.bos.selfSettings['msgconfirm_recvmode']) == 1 and  self.legacyList.hasCapability(uin, 'serv_rel'):
					cookie = ''.join([chr(random.randrange(0, 127)) for i in xrange(8)]) # cookie
					c_time = int(time.time())
					uvars = {}
					msg_query = self.getUserVarValue(uin, 'wait_for_confirm_msg_query')
					if len(msg_query) == 0:
						msg_query = dict([])
					elif len(msg_query) > 4: # query already too long
						del_msg_query = dict([])
						for every in msg_query:
							e_id, e_res, e_time = msg_query[every]
							if int(c_time) > int(e_time) + 60: # sent more than 60 second ago and receiving not confirmed
								del_msg_query[every] = msg_query[every] # message was lost
						if len(del_msg_query):
							for every in del_msg_query:
								del msg_query[every]
					msg_query[cookie] = (jabber_mid, resource, c_time)
					uvars['wait_for_confirm_msg_query'] = msg_query # update query
					self.legacyList.setUserVars(uin, uvars)
					log.msg('Waiting for confirmations msg query: %s' % msg_query)
				else:
					cookie = None
				        
				# if contact uses utf-8 via serv_rel and necessary see on it
				# or if contact has unicode & serl_rel caps and utf-8 via serv_rel preferred
				if (str(self.getUserVarValue(uin, 'utf8_msg_using')) == '1' and int(self.bos.selfSettings['utf8_messages_sendmode']) == 1) or (self.legacyList.hasCapability(uin, 'serv_rel') and self.legacyList.hasCapability(uin, 'unicode') and int(self.bos.selfSettings['utf8_messages_sendmode']) == 2 and not offline):
					self.bos.sendMessageType2(uin, message, cookie=cookie) # send as type-2 message
				else: # send as usual message, choose encoding
					if offline and int(self.bos.settingsOptionValue('offline_messages_sendenc')) == 0: # Unicode for offline messages
					    charset = 'unicode' # utf-16be
					elif offline and int(self.bos.settingsOptionValue('offline_messages_sendenc')) == 1: # local encoding for offline messages
					    charset = 'custom' # single-byte encoding
					else: # autodetect (both for offline and online messages)
					    if self.legacyList.hasCapability(uin, 'unicode'): # contact has unicode cap
						charset = 'unicode' # utf-16be
					    else:
						charset = 'custom' # single-byte encoding
					self.bos.sendMessage(uin, [[message,charset]], offline=offline, wantIcon=wantIcon, autoResponse=autoResponse, iconSum=iconSum, iconLen=iconLen, iconStamp=iconStamp, cookie=cookie)
				self.session.sendArchive(target, self.session.jabberID, message)
			else: # AIM users
				if xhtml and not config.disableXHTML:
					xhtml = utils.xhtml_to_aimhtml(xhtml)
					self.bos.sendMessage(uin, xhtml, wantIcon=wantIcon, autoResponse=autoResponse, iconSum=iconSum, iconLen=iconLen, iconStamp=iconStamp)
					self.session.sendArchive(target, self.session.jabberID, message)
				else:
					htmlized = oscar.html(message)
					self.bos.sendMessage(uin, htmlized, wantIcon=wantIcon, autoResponse=autoResponse, iconSum=iconSum, iconLen=iconLen, iconStamp=iconStamp)
					self.session.sendArchive(target, self.session.jabberID, message)
		except AttributeError:
			self.alertUser(lang.get("sessionnotactive", config.jid))