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)
def updateSSIContact(self, contact, presence="unavailable", show=None, status=None, nick=None, ipaddr=None, lanipaddr=None, lanipport=None, aimprotocol=None, url=None): from glue import aim2jid LogEvent(INFO, self.session.jabberID) self.ssicontacts[contact.lower()] = { 'presence': presence, 'show': show, 'status': status, 'url': url, 'ipaddr': ipaddr, 'lanipaddr': lanipaddr, 'lanipport': lanipport, 'aimprotocol': aimprotocol } c = self.session.contactList.findContact(aim2jid(contact)) if not c: LogEvent(INFO, self.session.jabberID, "Update setting default avatar for %s" % (contact)) c = self.session.contactList.createContact(aim2jid(contact), "both") if not config.disableAvatars: if contact[0].isdigit(): c.updateAvatar(glue.defaultICQAvatar, push=False) else: c.updateAvatar(glue.defaultAIMAvatar, push=False) if not self.xdbcontacts.has_key(contact.lower()): self.xdbcontacts[contact.lower()] = {} if nick: self.xdbcontacts[contact.lower()]['nickname'] = nick c.updateNickname(nick, push=True) self.session.sendRosterImport(aim2jid(contact), "subscribe", "both", nick) else: self.session.sendRosterImport(aim2jid(contact), "subscribe", "both", contact) self.session.pytrans.xdb.setListEntry( "roster", self.session.jabberID, contact.lower(), payload=self.xdbcontacts[contact.lower()]) else: if nick and self.xdbcontacts[contact.lower()].get('nickname', '') != nick: self.xdbcontacts[contact.lower()]['nickname'] = nick c.updateNickname(nick, push=True) self.session.sendRosterImport(aim2jid(contact), "subscribe", "both", nick)
def resourceOffline(self, resource): from glue import aim2jid LogEvent(INFO, self.session.jabberID) try: show = None status = None ptype = "unavailable" for c in self.legacyList.ssicontacts.keys(): LogEvent(INFO, self.session.jabberID, "Sending offline %r" % c) jid = aim2jid(c) self.session.sendPresence(to=self.session.jabberID + "/" + resource, fro=jid, ptype=ptype, show=show, status=status) self.session.sendPresence(to=self.session.jabberID + "/" + resource, fro=config.jid, ptype=ptype, show=show, status=status) except AttributeError: return
def gotSearchResults(self, results, iq, d): LogEvent(INFO, self.session.jabberID) from glue import aim2jid x = None for query in iq.elements(): if query.name == "query": for child in query.elements(): if child.name == "x": x = child break break if x: for r in results: if r.has_key("screenname"): r["jid"] = aim2jid(r["screenname"]) else: r["jid"] = "Unknown" item = x.addElement("item") for k in [ "jid", "first", "middle", "last", "maiden", "nick", "email", "address", "city", "state", "country", "zip", "region" ]: item.addChild( utils.makeDataFormElement(None, k, value=r.get(k, None))) d.callback(iq)
def __init__(self, session): self.session = session self.ssicontacts = { } self.usercaps = { } self.xdbcontacts = self.getBuddyList() for c in self.xdbcontacts: from glue import aim2jid jabContact = self.session.contactList.createContact(aim2jid(c), "both") if self.xdbcontacts[c].has_key("nickname"): jabContact.updateNickname(self.xdbcontacts[c]["nickname"], push=False) if not config.disableAvatars: if self.xdbcontacts[c].has_key("shahash"): LogEvent(INFO, self.session.jabberID, "Setting custom avatar for %s" %(c)) avatarData = avatar.AvatarCache().getAvatar(self.xdbcontacts[c]["shahash"]) jabContact.updateAvatar(avatarData, push=False) elif self.xdbcontacts[c].has_key("localhash"): # Temporary LogEvent(INFO, self.session.jabberID, "Setting custom avatar for %s" %(c)) avatarData = avatar.AvatarCache().getAvatar(self.xdbcontacts[c]["localhash"]) jabContact.updateAvatar(avatarData, push=False) else: if not config.disableDefaultAvatar: LogEvent(INFO, self.session.jabberID, "Setting default avatar for %s" %(c)) if c[0].isdigit(): jabContact.updateAvatar(glue.defaultICQAvatar, push=False) else: jabContact.updateAvatar(glue.defaultAIMAvatar, push=False)
def receiveTypingNotify(self, type, user): from glue import aim2jid LogEvent(INFO, self.session.jabberID) sourcejid = aim2jid(user.name) if type == "begin": self.session.sendTypingNotification(to=self.session.jabberID, fro=sourcejid, typing=True) self.session.sendChatStateNotification(to=self.session.jabberID, fro=sourcejid, state="composing") elif type == "idle": self.session.sendTypingNotification(to=self.session.jabberID, fro=sourcejid, typing=False) self.session.sendChatStateNotification(to=self.session.jabberID, fro=sourcejid, state="paused") elif type == "finish": self.session.sendTypingNotification(to=self.session.jabberID, fro=sourcejid, typing=False) self.session.sendChatStateNotification(to=self.session.jabberID, fro=sourcejid, state="active")
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)
def gotAuthorizationRequest(self, scrnname): from glue import aim2jid LogEvent(INFO, self.session.jabberID) if not scrnname in self.authorizationRequests: self.authorizationRequests.append(scrnname) self.session.sendPresence(to=self.session.jabberID, fro=aim2jid(scrnname), ptype="subscribe")
def gotAuthorizationResponse(self, scrnname, success): from glue import aim2jid LogEvent(INFO, self.session.jabberID) if success: for g in self.ssigroups: for u in g.users: if u.name == scrnname: u.authorized = True u.authorizationRequestSent = False self.session.sendPresence(to=self.session.jabberID, fro=aim2jid(scrnname), show=None, ptype="subscribed") return else: for g in self.ssigroups: for u in g.users: if u.name == scrnname: u.authorizationRequestSent = False self.session.sendPresence(to=self.session.jabberID, fro=aim2jid(scrnname), show=None, status=None, ptype="unsubscribed")
def buddyAdded(self, scrnname): from glue import aim2jid for g in self.ssigroups: for u in g.users: if u.name == scrnname: if u.authorized: self.session.sendPresence(to=self.session.jabberID, fro=aim2jid(scrnname), show=None, ptype="subscribed") return
def sendAwayPresence(self, msg, user): from glue import aim2jid buddyjid = aim2jid(user.name) c = self.session.contactList.findContact(buddyjid) if not c: return ptype = None show = "away" status = oscar.dehtml(msg[1]) # Removes any HTML tags url = user.url if status != None: charset = "iso-8859-1" m = None if msg[0]: m = re.search('charset="(.+)"', msg[0]) if m != None: charset = m.group(1) if charset == 'unicode-2-0': charset = 'utf-16be' elif charset == 'utf-8': pass elif charset == "us-ascii": charset = "iso-8859-1" else: LogEvent( INFO, self.session.jabberID, "Unknown charset (%s) of buddy's away message" % msg[0]) charset = "iso-8859-1" status = msg[0] + ": " + status status = status.decode(charset, 'replace') LogEvent(INFO, self.session.jabberID, "Away (%s, %s) message %s" % (charset, msg[0], status)) if status == "Away" or status == "I am currently away from the computer." or status == "I am away from my computer right now.": status = "" if user.idleTime: if user.idleTime > 60 * 24: idle_time = "Idle %d days" % (user.idleTime / (60 * 24)) elif user.idleTime > 60: idle_time = "Idle %d hours" % (user.idleTime / (60)) else: idle_time = "Idle %d minutes" % (user.idleTime) if status: status = "%s - %s" % (idle_time, status) else: status = idle_time c.updatePresence(show=show, status=status, ptype=ptype) self.oscarcon.legacyList.updateSSIContact(user.name, presence=ptype, show=show, status=status, url=url)
def receiveChatInvite(self, user, message, exchange, fullName, instance, shortName, inviteTime): from glue import aim2jid, LegacyGroupchat LogEvent(INFO, self.session.jabberID) groupchat = LegacyGroupchat(session=self.session, resource=self.session.highestResource(), ID=shortName.replace(' ', '_') + "%" + str(exchange), existing=True) groupchat.sendUserInvite(aim2jid(user.name))
def updateNickname(self, contact, nick): from glue import aim2jid c = self.session.contactList.findContact(aim2jid(contact)) if c: LogEvent(INFO, self.session.jabberID) if not self.xdbcontacts.has_key(contact.lower()): self.xdbcontacts[contact.lower()] = {} if nick and self.xdbcontacts[contact.lower()].get('nickname', '') != nick: self.xdbcontacts[contact.lower()]['nickname'] = nick c.updateNickname(nick, push=True) self.session.sendRosterImport(aim2jid(contact), "subscribe", "both", nick) self.session.pytrans.xdb.setListEntry( "roster", self.session.jabberID, contact.lower(), payload=self.xdbcontacts[contact.lower()]) try: bos = self.session.legacycon.bos savetheseusers = [] savethesegroups = [] for g in bos.ssigroups: found = False for u in g.users: if u.name.lower() == contact.lower(): savetheseusers.append(u) found = True if found: savethesegroups.append(g) if len(savetheseusers) > 0: bos.startModifySSI() for u in savetheseusers: u.nick = nick bos.modifyItemSSI(u) for g in savethesegroups: bos.modifyItemSSI(g) bos.endModifySSI() except: raise
def offlineBuddy(self, user): from glue import aim2jid LogEvent(INFO, self.session.jabberID, user.name) buddyjid = aim2jid(user.name) c = self.session.contactList.findContact(buddyjid) if not c: return show = None status = None ptype = "unavailable" c.updatePresence(show=show, status=status, ptype=ptype) self.oscarcon.legacyList.updateSSIContact(user.name, presence=ptype, show=show, status=status)
def buddyAdded(self, scrnname): from glue import aim2jid for g in self.ssigroups: for u in g.users: if u.name == scrnname: if u.authorized: self.session.sendPresence(to=self.session.jabberID, fro=aim2jid(scrnname), show=None, ptype="subscribed") return
def gotnovCard(self, profile, user, vcard, d): from glue import aim2jid LogEvent(INFO, self.session.jabberID) nickname = vcard.addElement("NICKNAME") nickname.addContent(user) jabberid = vcard.addElement("JABBERID") jabberid.addContent(aim2jid(user)) desc = vcard.addElement("DESC") desc.addContent("User is not online.") d.callback(vcard)
def gotnovCard(self, profile, user, vcard, d): from glue import aim2jid LogEvent(INFO, self.session.jabberID) nickname = vcard.addElement("NICKNAME") nickname.addContent(user) jabberid = vcard.addElement("JABBERID") jabberid.addContent(aim2jid(user)) desc = vcard.addElement("DESC") desc.addContent("User is not online.") d.callback(vcard)
def receiveTypingNotify(self, type, user): from glue import aim2jid LogEvent(INFO, self.session.jabberID) sourcejid = aim2jid(user.name) if type == "begin": self.session.sendTypingNotification(to=self.session.jabberID, fro=sourcejid, typing=True) self.session.sendChatStateNotification(to=self.session.jabberID, fro=sourcejid, state="composing") elif type == "idle": self.session.sendTypingNotification(to=self.session.jabberID, fro=sourcejid, typing=False) self.session.sendChatStateNotification(to=self.session.jabberID, fro=sourcejid, state="paused") elif type == "finish": self.session.sendTypingNotification(to=self.session.jabberID, fro=sourcejid, typing=False) self.session.sendChatStateNotification(to=self.session.jabberID, fro=sourcejid, state="active")
def updateSSIContact(self, contact, presence="unavailable", show=None, status=None, nick=None, ipaddr=None, lanipaddr=None, lanipport=None, aimprotocol=None, url=None): from glue import aim2jid LogEvent(INFO, self.session.jabberID) self.ssicontacts[contact.lower()] = { 'presence': presence, 'show': show, 'status': status, 'url': url, 'ipaddr' : ipaddr, 'lanipaddr' : lanipaddr, 'lanipport' : lanipport, 'aimprotocol' : aimprotocol } c = self.session.contactList.findContact(aim2jid(contact)) if not c: LogEvent(INFO, self.session.jabberID, "Update setting default avatar for %s" %(contact)) c = self.session.contactList.createContact(aim2jid(contact), "both") if not config.disableAvatars: if contact[0].isdigit(): c.updateAvatar(glue.defaultICQAvatar, push=False) else: c.updateAvatar(glue.defaultAIMAvatar, push=False) if not self.xdbcontacts.has_key(contact.lower()): self.xdbcontacts[contact.lower()] = {} if nick: self.xdbcontacts[contact.lower()]['nickname'] = nick c.updateNickname(nick, push=True) self.session.sendRosterImport(aim2jid(contact), "subscribe", "both", nick) else: self.session.sendRosterImport(aim2jid(contact), "subscribe", "both", contact) self.session.pytrans.xdb.setListEntry("roster", self.session.jabberID, contact.lower(), payload=self.xdbcontacts[contact.lower()]) else: if nick and self.xdbcontacts[contact.lower()].get('nickname','') != nick: self.xdbcontacts[contact.lower()]['nickname'] = nick c.updateNickname(nick, push=True) self.session.sendRosterImport(aim2jid(contact), "subscribe", "both", nick)
def gotvCard(self, profile, user, vcard, d): from glue import aim2jid LogEvent(INFO, self.session.jabberID) cutprofile = oscar.dehtml(profile) nickname = vcard.addElement("NICKNAME") nickname.addContent(utils.xmlify(user)) jabberid = vcard.addElement("JABBERID") jabberid.addContent(aim2jid(user)) desc = vcard.addElement("DESC") desc.addContent(utils.xmlify(cutprofile)) d.callback(vcard)
def gotvCard(self, profile, user, vcard, d): from glue import aim2jid LogEvent(INFO, self.session.jabberID) cutprofile = oscar.dehtml(profile) nickname = vcard.addElement("NICKNAME") nickname.addContent(utils.xmlify(user)) jabberid = vcard.addElement("JABBERID") jabberid.addContent(aim2jid(user)) desc = vcard.addElement("DESC") desc.addContent(utils.xmlify(cutprofile)) d.callback(vcard)
def offlineBuddy(self, user): from glue import aim2jid LogEvent(INFO, self.session.jabberID, user.name) buddyjid = aim2jid(user.name) c = self.session.contactList.findContact(buddyjid) if not c: return show = None status = None ptype = "unavailable" c.updatePresence(show=show, status=status, ptype=ptype) self.oscarcon.legacyList.updateSSIContact(user.name, presence=ptype, show=show, status=status)
def updateBuddy(self, user): from glue import aim2jid LogEvent(INFO, self.session.jabberID) buddyjid = aim2jid(user.name) c = self.session.contactList.findContact(buddyjid) if not c: return ptype = None show = None status = user.status encoding = user.statusencoding url = user.url #status = re.sub("<[^>]*>","",status) # Removes any HTML tags status = oscar.dehtml(status) # Removes any HTML tags if encoding: if encoding == "unicode": status = status.decode("utf-16be", "replace") elif encoding == "iso-8859-1": status = status.decode("iso-8859-1", "replace") if status == "Away" or status=="I am currently away from the computer." or status=="I am away from my computer right now.": status = "" if user.idleTime: if user.idleTime>60*24: idle_time = "Idle %d days"%(user.idleTime/(60*24)) elif user.idleTime>60: idle_time = "Idle %d hours"%(user.idleTime/(60)) else: idle_time = "Idle %d minutes"%(user.idleTime) if status: status="%s - %s"%(idle_time,status) else: status=idle_time if user.iconmd5sum != None and not config.disableAvatars and not config.avatarsOnlyOnChat: if self.oscarcon.legacyList.diffAvatar(user.name, md5Hash=binascii.hexlify(user.iconmd5sum)): LogEvent(INFO, self.session.jabberID, "Retrieving buddy icon for %s" % user.name) self.retrieveBuddyIconFromServer(user.name, user.iconmd5sum, user.icontype).addCallback(self.gotBuddyIconFromServer) else: LogEvent(INFO, self.session.jabberID, "Buddy icon is the same, using what we have for %s" % user.name) if user.caps: self.oscarcon.legacyList.setCapabilities(user.name, user.caps) status = status.encode("utf-8", "replace") if user.flags.count("away"): self.getAway(user.name).addCallback(self.sendAwayPresence, user) else: c.updatePresence(show=show, status=status, ptype=ptype, url=url) self.oscarcon.legacyList.updateSSIContact(user.name, presence=ptype, show=show, status=status, url=url)
def resourceOffline(self, resource): from glue import aim2jid LogEvent(INFO, self.session.jabberID) try: show = None status = None ptype = "unavailable" for c in self.legacyList.ssicontacts.keys( ): LogEvent(INFO, self.session.jabberID, "Sending offline %r" % c) jid = aim2jid(c) self.session.sendPresence(to=self.session.jabberID+"/"+resource, fro=jid, ptype=ptype, show=show, status=status) self.session.sendPresence(to=self.session.jabberID+"/"+resource, fro=config.jid, ptype=ptype, show=show, status=status) except AttributeError: return
def newResourceOnline(self, resource): from glue import aim2jid LogEvent(INFO, self.session.jabberID) try: for c in self.legacyList.ssicontacts.keys( ): LogEvent(INFO, self.session.jabberID, "Resending buddy %r" % c) jid = aim2jid(c) show = self.legacyList.ssicontacts[c]['show'] status = self.legacyList.ssicontacts[c]['status'] ptype = self.legacyList.ssicontacts[c]['presence'] url = self.legacyList.ssicontacts[c]['url'] #FIXME, needs to be contact based updatePresence self.session.sendPresence(to=self.session.jabberID, fro=jid, show=show, status=status, ptype=ptype, url=url) except AttributeError: return
def updateNickname(self, contact, nick): from glue import aim2jid c = self.session.contactList.findContact(aim2jid(contact)) if c: LogEvent(INFO, self.session.jabberID) if not self.xdbcontacts.has_key(contact.lower()): self.xdbcontacts[contact.lower()] = {} if nick and self.xdbcontacts[contact.lower()].get('nickname','') != nick: self.xdbcontacts[contact.lower()]['nickname'] = nick c.updateNickname(nick, push=True) self.session.sendRosterImport(aim2jid(contact), "subscribe", "both", nick) self.session.pytrans.xdb.setListEntry("roster", self.session.jabberID, contact.lower(), payload=self.xdbcontacts[contact.lower()]) try: bos = self.session.legacycon.bos savetheseusers = [] savethesegroups = [] for g in bos.ssigroups: found = False for u in g.users: if u.name.lower() == contact.lower(): savetheseusers.append(u) found = True if found: savethesegroups.append(g) if len(savetheseusers) > 0: bos.startModifySSI() for u in savetheseusers: u.nick = nick bos.modifyItemSSI(u) for g in savethesegroups: bos.modifyItemSSI(g) bos.endModifySSI() except: raise
def gotAuthorizationResponse(self, scrnname, success): from glue import aim2jid LogEvent(INFO, self.session.jabberID) if success: for g in self.ssigroups: for u in g.users: if u.name == scrnname: u.authorized = True u.authorizationRequestSent = False self.session.sendPresence(to=self.session.jabberID, fro=aim2jid(scrnname), show=None, ptype="subscribed") return else: for g in self.ssigroups: for u in g.users: if u.name == scrnname: u.authorizationRequestSent = False self.session.sendPresence(to=self.session.jabberID, fro=aim2jid(scrnname), show=None, status=None, ptype="unsubscribed")
def sendAwayPresence(self, msg, user): from glue import aim2jid buddyjid = aim2jid(user.name) c = self.session.contactList.findContact(buddyjid) if not c: return ptype = None show = "away" status = oscar.dehtml(msg[1]) # Removes any HTML tags url = user.url if status != None: charset = "iso-8859-1" m = None if msg[0]: m = re.search('charset="(.+)"', msg[0]) if m != None: charset = m.group(1) if charset == 'unicode-2-0': charset = 'utf-16be' elif charset == 'utf-8': pass elif charset == "us-ascii": charset = "iso-8859-1" else: LogEvent(INFO, self.session.jabberID, "Unknown charset (%s) of buddy's away message" % msg[0]); charset = "iso-8859-1" status = msg[0] + ": " + status status = status.decode(charset, 'replace') LogEvent(INFO, self.session.jabberID, "Away (%s, %s) message %s" % (charset, repr(msg[0]), status)) if status == "Away" or status=="I am currently away from the computer." or status=="I am away from my computer right now.": status = "" if user.idleTime: if user.idleTime>60*24: idle_time = "Idle %d days"%(user.idleTime/(60*24)) elif user.idleTime>60: idle_time = "Idle %d hours"%(user.idleTime/(60)) else: idle_time = "Idle %d minutes"%(user.idleTime) if status: status="%s - %s"%(idle_time,status) else: status=idle_time c.updatePresence(show=show, status=status, ptype=ptype) self.oscarcon.legacyList.updateSSIContact(user.name, presence=ptype, show=show, status=status, url=url)
def receiveMessage(self, user, multiparts, flags): from glue import aim2jid LogEvent(INFO, self.session.jabberID, "%s %s %s" % (user.name, multiparts, flags)) sourcejid = aim2jid(user.name) text = multiparts[0][0] if len(multiparts[0]) > 1: if multiparts[0][1] == 'unicode': encoding = "utf-16be" else: encoding = "iso-8859-1" else: encoding = "iso-8859-1" LogEvent(INFO, self.session.jabberID, "Using encoding %s" % (encoding)) text = text.decode(encoding, "replace") xhtml = utils.prepxhtml(text) if not user.name[0].isdigit(): text = oscar.dehtml(text) text = text.strip() mtype = "chat" if "auto" in flags: mtype = "headline" self.session.sendMessage(to=self.session.jabberID, fro=sourcejid, body=text, mtype=mtype, xhtml=xhtml) self.session.pytrans.serviceplugins['Statistics'].stats['IncomingMessages'] += 1 self.session.pytrans.serviceplugins['Statistics'].sessionUpdate(self.session.jabberID, 'IncomingMessages', 1) if not config.disableAwayMessage and self.awayMessage and not "auto" in flags: if not self.awayResponses.has_key(user.name) or self.awayResponses[user.name] < (time.time() - 900): self.sendMessage(user.name, "Away message: "+self.awayMessage, autoResponse=1) self.awayResponses[user.name] = time.time() if "icon" in flags and not config.disableAvatars: if self.oscarcon.legacyList.diffAvatar(user.name, numHash=user.iconcksum): LogEvent(INFO, self.session.jabberID, "User %s has a buddy icon we want, will ask for it next message." % user.name) self.requesticon[user.name] = 1 else: LogEvent(INFO, self.session.jabberID, "User %s has a icon that we already have." % user.name) if "iconrequest" in flags and hasattr(self.oscarcon, "myavatar") and not config.disableAvatars: LogEvent(INFO, self.session.jabberID, "User %s wants our icon, so we're sending it." % user.name) icondata = self.oscarcon.myavatar self.sendIconDirect(user.name, icondata, wantAck=1)
def newResourceOnline(self, resource): from glue import aim2jid LogEvent(INFO, self.session.jabberID) try: for c in self.legacyList.ssicontacts.keys(): LogEvent(INFO, self.session.jabberID, "Resending buddy %r" % c) jid = aim2jid(c) show = self.legacyList.ssicontacts[c]['show'] status = self.legacyList.ssicontacts[c]['status'] ptype = self.legacyList.ssicontacts[c]['presence'] url = self.legacyList.ssicontacts[c]['url'] #FIXME, needs to be contact based updatePresence self.session.sendPresence(to=self.session.jabberID, fro=jid, show=show, status=status, ptype=ptype, url=url) except AttributeError: return
def gotSearchResults(self, results, iq, d): LogEvent(INFO, self.session.jabberID) from glue import aim2jid x = None for query in iq.elements(): if query.name == "query": for child in query.elements(): if child.name == "x": x = child break break if x: for r in results: if r.has_key("screenname"): r["jid"] = aim2jid(r["screenname"]) else: r["jid"] = "Unknown" item = x.addElement("item") for k in ["jid","first","middle","last","maiden","nick","email","address","city","state","country","zip","region"]: item.addChild(utils.makeDataFormElement(None, k, value=r.get(k,None))) d.callback(iq)
def __init__(self, session): self.session = session self.ssicontacts = {} self.usercaps = {} self.xdbcontacts = self.getBuddyList() for c in self.xdbcontacts: from glue import aim2jid jabContact = self.session.contactList.createContact( aim2jid(c), "both") if self.xdbcontacts[c].has_key("nickname"): jabContact.updateNickname(self.xdbcontacts[c]["nickname"], push=False) if not config.disableAvatars: if self.xdbcontacts[c].has_key("shahash"): LogEvent(INFO, self.session.jabberID, "Setting custom avatar for %s" % (c)) avatarData = avatar.AvatarCache().getAvatar( self.xdbcontacts[c]["shahash"]) jabContact.updateAvatar(avatarData, push=False) elif self.xdbcontacts[c].has_key("localhash"): # Temporary LogEvent(INFO, self.session.jabberID, "Setting custom avatar for %s" % (c)) avatarData = avatar.AvatarCache().getAvatar( self.xdbcontacts[c]["localhash"]) jabContact.updateAvatar(avatarData, push=False) else: if not config.disableDefaultAvatar: LogEvent(INFO, self.session.jabberID, "Setting default avatar for %s" % (c)) if c[0].isdigit(): jabContact.updateAvatar(glue.defaultICQAvatar, push=False) else: jabContact.updateAvatar(glue.defaultAIMAvatar, push=False)
def receiveMessage(self, user, multiparts, flags): from glue import aim2jid LogEvent(INFO, self.session.jabberID, "%s %s %s" % (user.name, multiparts, flags)) sourcejid = aim2jid(user.name) text = multiparts[0][0] if len(multiparts[0]) > 1: if multiparts[0][1] == 'unicode': encoding = "utf-16be" else: encoding = "iso-8859-1" else: encoding = "iso-8859-1" LogEvent(INFO, self.session.jabberID, "Using encoding %s" % (encoding)) text = text.decode(encoding, "replace") xhtml = utils.prepxhtml(text) if not user.name[0].isdigit(): text = oscar.dehtml(text) text = text.strip() mtype = "chat" if "auto" in flags: mtype = "headline" self.session.sendMessage(to=self.session.jabberID, fro=sourcejid, body=text, mtype=mtype, xhtml=xhtml) self.session.pytrans.serviceplugins['Statistics'].stats[ 'IncomingMessages'] += 1 self.session.pytrans.serviceplugins['Statistics'].sessionUpdate( self.session.jabberID, 'IncomingMessages', 1) if not config.disableAwayMessage and self.awayMessage and not "auto" in flags: if not self.awayResponses.has_key(user.name) or self.awayResponses[ user.name] < (time.time() - 900): self.sendMessage(user.name, "Away message: " + self.awayMessage, autoResponse=1) self.awayResponses[user.name] = time.time() if "icon" in flags and not config.disableAvatars: if self.oscarcon.legacyList.diffAvatar(user.name, numHash=user.iconcksum): LogEvent( INFO, self.session.jabberID, "User %s has a buddy icon we want, will ask for it next message." % user.name) self.requesticon[user.name] = 1 else: LogEvent( INFO, self.session.jabberID, "User %s has a icon that we already have." % user.name) if "iconrequest" in flags and hasattr( self.oscarcon, "myavatar") and not config.disableAvatars: LogEvent( INFO, self.session.jabberID, "User %s wants our icon, so we're sending it." % user.name) icondata = self.oscarcon.myavatar self.sendIconDirect(user.name, icondata, wantAck=1)
def youWereAdded(self, scrnname): from glue import aim2jid LogEvent(INFO, self.session.jabberID) self.session.sendPresence(to=self.session.jabberID, fro=aim2jid(scrnname), ptype="subscribe")
def updateBuddy(self, user): from glue import aim2jid LogEvent(INFO, self.session.jabberID) buddyjid = aim2jid(user.name) c = self.session.contactList.findContact(buddyjid) if not c: return ptype = None show = None status = user.status encoding = user.statusencoding url = user.url #status = re.sub("<[^>]*>","",status) # Removes any HTML tags status = oscar.dehtml(status) # Removes any HTML tags if encoding: if encoding == "unicode": status = status.decode("utf-16be", "replace") elif encoding == "iso-8859-1": status = status.decode("iso-8859-1", "replace") if status == "Away" or status == "I am currently away from the computer." or status == "I am away from my computer right now.": status = "" if user.idleTime: if user.idleTime > 60 * 24: idle_time = "Idle %d days" % (user.idleTime / (60 * 24)) elif user.idleTime > 60: idle_time = "Idle %d hours" % (user.idleTime / (60)) else: idle_time = "Idle %d minutes" % (user.idleTime) if status: status = "%s - %s" % (idle_time, status) else: status = idle_time if user.iconmd5sum != None and not config.disableAvatars and not config.avatarsOnlyOnChat: if self.oscarcon.legacyList.diffAvatar(user.name, md5Hash=binascii.hexlify( user.iconmd5sum)): LogEvent(INFO, self.session.jabberID, "Retrieving buddy icon for %s" % user.name) self.retrieveBuddyIconFromServer( user.name, user.iconmd5sum, user.icontype).addCallback(self.gotBuddyIconFromServer) else: LogEvent( INFO, self.session.jabberID, "Buddy icon is the same, using what we have for %s" % user.name) if user.caps: self.oscarcon.legacyList.setCapabilities(user.name, user.caps) status = status.encode("utf-8", "replace") if user.flags.count("away"): self.getAway(user.name).addCallback(self.sendAwayPresence, user) else: c.updatePresence(show=show, status=status, ptype=ptype, url=url) self.oscarcon.legacyList.updateSSIContact(user.name, presence=ptype, show=show, status=status, url=url)
def updatePresence(self, userHandle, ptype): # Convenience from glue import aim2jid to = aim2jid(userHandle) self.session.sendPresence(to=self.session.jabberID, fro=to, ptype=ptype)
def gotAuthorizationRequest(self, scrnname): from glue import aim2jid LogEvent(INFO, self.session.jabberID) if not scrnname in self.authorizationRequests: self.authorizationRequests.append(scrnname) self.session.sendPresence(to=self.session.jabberID, fro=aim2jid(scrnname), ptype="subscribe")
def updatePresence(self, userHandle, ptype): # Convenience from glue import aim2jid to = aim2jid(userHandle) self.session.sendPresence(to=self.session.jabberID, fro=to, ptype=ptype)
def receiveChatInvite(self, user, message, exchange, fullName, instance, shortName, inviteTime): from glue import aim2jid, LegacyGroupchat LogEvent(INFO, self.session.jabberID) groupchat = LegacyGroupchat(session=self.session, resource=self.session.highestResource(), ID=shortName.replace(' ','_')+"%"+str(exchange), existing=True) groupchat.sendUserInvite(aim2jid(user.name))
def youWereAdded(self, scrnname): from glue import aim2jid LogEvent(INFO, self.session.jabberID) self.session.sendPresence(to=self.session.jabberID, fro=aim2jid(scrnname), ptype="subscribe")