]> code.delx.au - pymsnt/blobdiff - src/legacy/glue.py
Fixed another exception.
[pymsnt] / src / legacy / glue.py
index 4616261ce5b84e45d7ea1c0f2b25649b2ca5ad1a..c00be73b341226805a33fa4659c545b5973e24f3 100644 (file)
@@ -3,7 +3,7 @@
 
 import os.path
 import utils
 
 import os.path
 import utils
-from twisted.internet import task
+from twisted.internet import task, error
 from tlib.xmlw import Element
 from tlib import msn
 from debug import LogEvent, INFO, WARN, ERROR
 from tlib.xmlw import Element
 from tlib import msn
 from debug import LogEvent, INFO, WARN, ERROR
@@ -17,19 +17,18 @@ import lang
 
 
 
 
 
 
-name = "MSN Transport"   # The name of the transport
 url = "http://msn-transport.jabberstudio.org"
 url = "http://msn-transport.jabberstudio.org"
-version = "0.11-dev"     # The transport version
+version = "0.11-dev"         # The transport version
 mangle = True            # XDB '@' -> '%' mangling
 id = "msn"               # The transport identifier
 
 
 # Load the default avatars
 mangle = True            # XDB '@' -> '%' mangling
 id = "msn"               # The transport identifier
 
 
 # Load the default avatars
-f = open(os.path.join("data", "defaultJabberAvatar.png"))
+f = open(os.path.join("data", "defaultJabberAvatar.png"), "rb")
 defaultJabberAvatarData = f.read()
 f.close()
 
 defaultJabberAvatarData = f.read()
 f.close()
 
-f = open(os.path.join("data", "defaultMSNAvatar.png"))
+f = open(os.path.join("data", "defaultMSNAvatar.png"), "rb")
 defaultAvatarData = f.read()
 f.close()
 defaultAvatar = avatar.AvatarCache().setAvatar(defaultAvatarData)
 defaultAvatarData = f.read()
 f.close()
 defaultAvatar = avatar.AvatarCache().setAvatar(defaultAvatarData)
@@ -95,16 +94,45 @@ def updateStats(statistics):
        #stats["FailedAvatarCount"] = msnp2p.MSNP2P_Avatar.ERROR_COUNT
 
 
        #stats["FailedAvatarCount"] = msnp2p.MSNP2P_Avatar.ERROR_COUNT
 
 
+msn2jid_cache = {}
 def msn2jid(msnid, withResource):
        """ Converts a MSN passport into a JID representation to be used with the transport """
 def msn2jid(msnid, withResource):
        """ Converts a MSN passport into a JID representation to be used with the transport """
-       return msnid.replace('@', '%') + "@" + config.jid + (withResource and "/msn" or "")
+       global msn2jid_cache
+       global jid2msn_cache
+
+       if msn2jid_cache.has_key(msnid):
+               jid = msn2jid_cache[msnid]
+               if withResource:
+                       jid += "/msn"
+               return jid
+       else:
+               if msnid.startswith("tel:+"):
+                       msnid = msnid.replace("tel:+", "") + "%tel"
+               jid = msnid.replace('@', '%') + "@" + config.jid + (withResource and "/msn" or "")
+               msn2jid_cache[msnid] = jid
+               jid2msn_cache[jid] = msnid
+               return jid
 
 # Marks this as the function to be used in jabber:iq:gateway (Service ID Translation)
 
 # Marks this as the function to be used in jabber:iq:gateway (Service ID Translation)
-translateAccount = lambda a: msn2jid(a, False)
+def translateAccount(msnid):
+       return msn2jid(msnid, False)
 
 
+jid2msn_cache = {}
 def jid2msn(jid):
        """ Converts a JID representation of a MSN passport into the original MSN passport """
 def jid2msn(jid):
        """ Converts a JID representation of a MSN passport into the original MSN passport """
-       return unicode(jid[:jid.find('@')].replace('%', '@')).split("/")[0]
+       global jid2msn_cache
+       global msn2jid_cache
+
+       if jid2msn_cache.has_key(jid):
+               msnid = jid2msn_cache[jid]
+               return msnid
+       else:
+               if jid.find("%tel@") > 0:
+                       jid = "tel:+" + jid.replace("%tel@", "@")
+               msnid = unicode(jid[:jid.find('@')].replace('%', '@')).split("/")[0]
+               jid2msn_cache[jid] = msnid
+               msn2jid_cache[msnid] = jid
+               return msnid
 
 
 def presence2state(show, ptype): 
 
 
 def presence2state(show, ptype): 
@@ -117,6 +145,7 @@ def presence2state(show, ptype):
                return msn.STATUS_BUSY
        elif show == "away" or show == "xa":
                return msn.STATUS_AWAY
                return msn.STATUS_BUSY
        elif show == "away" or show == "xa":
                return msn.STATUS_AWAY
+       return msn.STATUS_ONLINE
 
 
 def state2presence(state):
 
 
 def state2presence(state):
@@ -231,7 +260,7 @@ class LegacyConnection(msn.MSNConnection):
                self.remoteNick = ""
 
                # Init the MSN bits
                self.remoteNick = ""
 
                # Init the MSN bits
-               msn.MSNConnection.__init__(self, username, password, self.session.jabberID)
+               msn.MSNConnection.__init__(self, username, password, self.jabberID)
 
                # User typing notification stuff
                self.userTyping = dict() # Indexed by contact MSN ID, stores whether the user is typing to this contact
 
                # User typing notification stuff
                self.userTyping = dict() # Indexed by contact MSN ID, stores whether the user is typing to this contact
@@ -243,10 +272,10 @@ class LegacyConnection(msn.MSNConnection):
                
                self.legacyList = LegacyList(self.session)
        
                
                self.legacyList = LegacyList(self.session)
        
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
        
        def removeMe(self):
        
        def removeMe(self):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
        
                self.userTypingSend.stop()
        
        
                self.userTypingSend.stop()
        
@@ -255,15 +284,15 @@ class LegacyConnection(msn.MSNConnection):
                self.session = None
                self.logOut()
        
                self.session = None
                self.logOut()
        
-       def _sendShowStatus(self):
+
+       # Implemented from baseproto
+       def sendShowStatus(self, jid=None):
                if not self.session: return
                source = config.jid
                if not self.session: return
                source = config.jid
-               to = self.session.jabberID
-               self.session.sendPresence(to=to, fro=source, show=self.remoteShow, status=self.remoteStatus, nickname=self.remoteNick)
-       
+               if not jid:
+                       jid = self.jabberID
+               self.session.sendPresence(to=jid, fro=source, show=self.remoteShow, status=self.remoteStatus, nickname=self.remoteNick)
        
        
-
-       # Implemented from baseproto
        def resourceOffline(self, resource):
                pass
 
        def resourceOffline(self, resource):
                pass
 
@@ -322,7 +351,7 @@ class LegacyConnection(msn.MSNConnection):
                for contact in self.contactTyping.keys():
                        self.contactTyping[contact] += 1
                        if self.contactTyping[contact] >= 3:
                for contact in self.contactTyping.keys():
                        self.contactTyping[contact] += 1
                        if self.contactTyping[contact] >= 3:
-                               self.session.sendTypingNotification(self.session.jabberID, msn2jid(contact, True), False)
+                               self.session.sendTypingNotification(self.jabberID, msn2jid(contact, True), False)
                                del self.contactTyping[contact]
        
        def userTypingNotification(self, dest, resource, composing):
                                del self.contactTyping[contact]
        
        def userTypingNotification(self, dest, resource, composing):
@@ -336,89 +365,92 @@ class LegacyConnection(msn.MSNConnection):
 
        # Implement callbacks from msn.MSNConnection
        def connectionFailed(self, reason):
 
        # Implement callbacks from msn.MSNConnection
        def connectionFailed(self, reason):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                text = lang.get(self.session.lang).msnConnectFailed % reason
                text = lang.get(self.session.lang).msnConnectFailed % reason
-               self.session.sendMessage(to=self.session.jabberID, fro=config.jid, body=text)
+               self.session.sendMessage(to=self.jabberID, fro=config.jid, body=text)
                self.session.removeMe()
 
        def loginFailed(self, reason):
                self.session.removeMe()
 
        def loginFailed(self, reason):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                text = lang.get(self.session.lang).msnLoginFailure % (self.session.username)
                text = lang.get(self.session.lang).msnLoginFailure % (self.session.username)
-               self.session.sendErrorMessage(to=self.session.jabberID, fro=config.jid, etype="auth", condition="not-authorized", explanation=text, body="Login Failure")
+               self.session.sendErrorMessage(to=self.jabberID, fro=config.jid, etype="auth", condition="not-authorized", explanation=text, body="Login Failure")
                self.session.removeMe()
        
        def connectionLost(self, reason):
                self.session.removeMe()
        
        def connectionLost(self, reason):
-               LogEvent(INFO, self.session.jabberID)
-               text = lang.get(self.session.lang).msnDisconnected % reason
-               self.session.sendMessage(to=self.session.jabberID, fro=config.jid, body=text)
+               LogEvent(INFO, self.jabberID)
+               if reason.type != error.ConnectionDone:
+                       text = lang.get(self.session.lang).msnDisconnected % reason
+                       self.session.sendMessage(to=self.jabberID, fro=config.jid, body=text)
                self.session.removeMe() # Tear down the session
 
        def multipleLogin(self):
                self.session.removeMe() # Tear down the session
 
        def multipleLogin(self):
-               LogEvent(INFO, self.session.jabberID)
-               self.session.sendMessage(to=self.session.jabberID, fro=config.jid, body=lang.get(self.session.lang).msnMultipleLogin)
+               LogEvent(INFO, self.jabberID)
+               self.session.sendMessage(to=self.jabberID, fro=config.jid, body=lang.get(self.session.lang).msnMultipleLogin)
                self.session.removeMe()
        
        def serverGoingDown(self):
                self.session.removeMe()
        
        def serverGoingDown(self):
-               LogEvent(INFO, self.session.jabberID)
-               self.session.sendMessage(to=self.session.jabberID, fro=config.jid, body=lang.get(self.session.lang).msnMaintenance)
+               LogEvent(INFO, self.jabberID)
+               self.session.sendMessage(to=self.jabberID, fro=config.jid, body=lang.get(self.session.lang).msnMaintenance)
        
        def accountNotVerified(self):
        
        def accountNotVerified(self):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                text = lang.get(self.session.lang).msnNotVerified % (self.session.username)
                text = lang.get(self.session.lang).msnNotVerified % (self.session.username)
-               self.session.sendMessage(to=self.session.jabberID, fro=config.jid, body=text)
+               self.session.sendMessage(to=self.jabberID, fro=config.jid, body=text)
        
        def userMapping(self, passport, jid):
        
        def userMapping(self, passport, jid):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                text = lang.get(self.session.lang).userMapping % (passport, jid)
                text = lang.get(self.session.lang).userMapping % (passport, jid)
-               self.session.sendMessage(to=self.session.jabberID, fro=msn2jid(passport, True), body=text)
+               self.session.sendMessage(to=self.jabberID, fro=msn2jid(passport, True), body=text)
        
        def loggedIn(self):
        
        def loggedIn(self):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                self.session.ready = True
        
        def listSynchronized(self):
                self.session.ready = True
        
        def listSynchronized(self):
-               LogEvent(INFO, self.session.jabberID)
-               self.session.sendPresence(to=self.session.jabberID, fro=config.jid)
+               LogEvent(INFO, self.jabberID)
+               self.session.sendPresence(to=self.jabberID, fro=config.jid)
                self.legacyList.syncJabberLegacyLists()
                self.listSynced = True
                #self.legacyList.flushSubscriptionBuffer()
        
        def ourStatusChanged(self, statusCode, screenName, personal):
                # Send out a new presence packet to the Jabber user so that the transport icon changes
                self.legacyList.syncJabberLegacyLists()
                self.listSynced = True
                #self.legacyList.flushSubscriptionBuffer()
        
        def ourStatusChanged(self, statusCode, screenName, personal):
                # Send out a new presence packet to the Jabber user so that the transport icon changes
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                self.remoteShow, ptype = state2presence(statusCode)
                self.remoteStatus = personal
                self.remoteNick = screenName
                self.remoteShow, ptype = state2presence(statusCode)
                self.remoteStatus = personal
                self.remoteNick = screenName
-               self._sendShowStatus()
+               self.sendShowStatus()
 
        def gotMessage(self, remoteUser, text):
 
        def gotMessage(self, remoteUser, text):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                source = msn2jid(remoteUser, True)
                source = msn2jid(remoteUser, True)
-               self.session.sendMessage(self.session.jabberID, fro=source, body=text, mtype="chat")
+               if self.contactTyping.has_key(remoteUser):
+                       del self.contactTyping[remoteUser]
+               self.session.sendMessage(self.jabberID, fro=source, body=text, mtype="chat")
                self.session.pytrans.statistics.stats["MessageCount"] += 1
        
        def gotGroupchat(self, msnGroupchat, userHandle):
                self.session.pytrans.statistics.stats["MessageCount"] += 1
        
        def gotGroupchat(self, msnGroupchat, userHandle):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                msnGroupchat.groupchat = LegacyGroupchat(self.session, switchboardSession=msnGroupchat)
                msnGroupchat.groupchat.sendUserInvite(msn2jid(userHandle, True))
        
        def gotContactTyping(self, contact):
                msnGroupchat.groupchat = LegacyGroupchat(self.session, switchboardSession=msnGroupchat)
                msnGroupchat.groupchat.sendUserInvite(msn2jid(userHandle, True))
        
        def gotContactTyping(self, contact):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                # Check if the contact has only just started typing
                if not self.contactTyping.has_key(contact):
                # Check if the contact has only just started typing
                if not self.contactTyping.has_key(contact):
-                       self.session.sendTypingNotification(self.session.jabberID, msn2jid(contact, True), True)
+                       self.session.sendTypingNotification(self.jabberID, msn2jid(contact, True), True)
 
                # Reset the counter
                self.contactTyping[contact] = 0
        
        def failedMessage(self, remoteUser, message):
 
                # Reset the counter
                self.contactTyping[contact] = 0
        
        def failedMessage(self, remoteUser, message):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                self.session.pytrans.statistics.stats["FailedMessageCount"] += 1
                fro = msn2jid(remoteUser, True)
                self.session.pytrans.statistics.stats["FailedMessageCount"] += 1
                fro = msn2jid(remoteUser, True)
-               self.session.sendErrorMessage(to=self.session.jabberID, fro=fro, etype="wait", condition="recipient-unavailable", explanation=lang.get(self.session.lang).msnFailedMessage, body=message)
+               self.session.sendErrorMessage(to=self.jabberID, fro=fro, etype="wait", condition="recipient-unavailable", explanation=lang.get(self.session.lang).msnFailedMessage, body=message)
        
        def contactAvatarChanged(self, userHandle, hash):
        
        def contactAvatarChanged(self, userHandle, hash):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                jid = msn2jid(userHandle, False)
                c = self.session.contactList.findContact(jid)
                if not c: return
                jid = msn2jid(userHandle, False)
                c = self.session.contactList.findContact(jid)
                if not c: return
@@ -443,7 +475,7 @@ class LegacyConnection(msn.MSNConnection):
                        c.updateAvatar(defaultAvatar)
        
        def contactStatusChanged(self, remoteUser):
                        c.updateAvatar(defaultAvatar)
        
        def contactStatusChanged(self, remoteUser):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                
                msnContact = self.getContacts().getContact(remoteUser)
                c = self.session.contactList.findContact(msn2jid(remoteUser, False))
                
                msnContact = self.getContacts().getContact(remoteUser)
                c = self.session.contactList.findContact(msn2jid(remoteUser, False))
@@ -457,35 +489,37 @@ class LegacyConnection(msn.MSNConnection):
                c.updatePresence(show, status, ptype, force=True)
        
        def gotFileReceive(self, fileReceive):
                c.updatePresence(show, status, ptype, force=True)
        
        def gotFileReceive(self, fileReceive):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                # FIXME
                ft.FTReceive(self.session, msn2jid(fileReceive.userHandle, True), fileReceive)
        
        def contactAddedMe(self, userHandle):
                # FIXME
                ft.FTReceive(self.session, msn2jid(fileReceive.userHandle, True), fileReceive)
        
        def contactAddedMe(self, userHandle):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                self.session.contactList.getContact(msn2jid(userHandle, False)).contactRequestsAuth()
        
        def contactRemovedMe(self, userHandle):
                self.session.contactList.getContact(msn2jid(userHandle, False)).contactRequestsAuth()
        
        def contactRemovedMe(self, userHandle):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                c = self.session.contactList.getContact(msn2jid(userHandle, True))
                c.contactDerequestsAuth()
                c.contactRemovesAuth()
        
        def gotInitialEmailNotification(self, inboxunread, foldersunread):
                c = self.session.contactList.getContact(msn2jid(userHandle, True))
                c.contactDerequestsAuth()
                c.contactRemovesAuth()
        
        def gotInitialEmailNotification(self, inboxunread, foldersunread):
-               LogEvent(INFO, self.session.jabberID)
-               text = lang.get(self.session.lang).msnInitialMail % (inboxunread, foldersunread)
-               self.session.sendMessage(to=self.session.jabberID, fro=config.jid, body=text, mtype="headline")
+               if config.mailNotifications:
+                       LogEvent(INFO, self.jabberID)
+                       text = lang.get(self.session.lang).msnInitialMail % (inboxunread, foldersunread)
+                       self.session.sendMessage(to=self.jabberID, fro=config.jid, body=text, mtype="headline")
        
        def gotRealtimeEmailNotification(self, mailfrom, fromaddr, subject):
        
        def gotRealtimeEmailNotification(self, mailfrom, fromaddr, subject):
-               LogEvent(INFO, self.session.jabberID)
-               text = lang.get(self.session.lang).msnRealtimeMail % (mailfrom, fromaddr, subject)
-               self.session.sendMessage(to=self.session.jabberID, fro=config.jid, body=text, mtype="headline")
+               if config.mailNotifications:
+                       LogEvent(INFO, self.jabberID)
+                       text = lang.get(self.session.lang).msnRealtimeMail % (mailfrom, fromaddr, subject)
+                       self.session.sendMessage(to=self.jabberID, fro=config.jid, body=text, mtype="headline")
                
        def gotMSNAlert(self, text, actionurl, subscrurl):
                
        def gotMSNAlert(self, text, actionurl, subscrurl):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
 
                el = Element((None, "message"))
 
                el = Element((None, "message"))
-               el.attributes["to"] = self.session.jabberID
+               el.attributes["to"] = self.jabberID
                el.attributes["from"] = config.jid
                el.attributes["type"] = "headline"
                body = el.addElement("body")
                el.attributes["from"] = config.jid
                el.attributes["type"] = "headline"
                body = el.addElement("body")
@@ -504,7 +538,7 @@ class LegacyConnection(msn.MSNConnection):
                self.session.pytrans.send(el)
        
        def gotAvatarImageData(self, userHandle, imageData):
                self.session.pytrans.send(el)
        
        def gotAvatarImageData(self, userHandle, imageData):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                av = self.session.pytrans.avatarCache.setAvatar(imageData)
                jid = msn2jid(userHandle, False)
                c = self.session.contactList.findContact(jid)
                av = self.session.pytrans.avatarCache.setAvatar(imageData)
                jid = msn2jid(userHandle, False)
                c = self.session.contactList.findContact(jid)
@@ -515,6 +549,7 @@ class LegacyConnection(msn.MSNConnection):
 
 class LegacyList:
        def __init__(self, session):
 
 class LegacyList:
        def __init__(self, session):
+               self.jabberID = session.jabberID
                self.session = session
                self.subscriptionBuffer = []
        
                self.session = session
                self.subscriptionBuffer = []
        
@@ -523,30 +558,37 @@ class LegacyList:
                self.session = None
 
        def addContact(self, jid):
                self.session = None
 
        def addContact(self, jid):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                userHandle = jid2msn(jid)
                self.session.legacycon.addContact(msn.FORWARD_LIST, userHandle)
                userHandle = jid2msn(jid)
                self.session.legacycon.addContact(msn.FORWARD_LIST, userHandle)
+
+               # Handle adding a contact that has previously been removed
+               msnContact = self.session.legacycon.getContacts().getContact(userHandle)
+               if msnContact and msnContact.lists & msn.REVERSE_LIST:
+                       self.session.legacycon.contactAddedMe(userHandle)
+               self.authContact(jid)
                self.session.contactList.getContact(jid).contactGrantsAuth()
        
        def removeContact(self, jid):
                self.session.contactList.getContact(jid).contactGrantsAuth()
        
        def removeContact(self, jid):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                jid = jid2msn(jid)
                self.session.legacycon.remContact(msn.FORWARD_LIST, jid)
        
        
        def authContact(self, jid):
                jid = jid2msn(jid)
                self.session.legacycon.remContact(msn.FORWARD_LIST, jid)
        
        
        def authContact(self, jid):
-               LogEvent(INFO, self.session.jabberID)
-               jid = jid2msn(jid)
-               d = self.session.legacycon.remContact(msn.PENDING_LIST, jid)
+               LogEvent(INFO, self.jabberID)
+               userHandle = jid2msn(jid)
+               d = self.session.legacycon.remContact(msn.PENDING_LIST, userHandle)
                if d:
                if d:
-                       self.session.legacycon.addContact(msn.REVERSE_LIST, jid)
-               self.session.legacycon.remContact(msn.BLOCK_LIST, jid)
-               self.session.legacycon.addContact(msn.ALLOW_LIST, jid)
+                       self.session.legacycon.addContact(msn.REVERSE_LIST, userHandle)
+               self.session.legacycon.remContact(msn.BLOCK_LIST, userHandle)
+               self.session.legacycon.addContact(msn.ALLOW_LIST, userHandle)
        
        def deauthContact(self, jid):
        
        def deauthContact(self, jid):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                jid = jid2msn(jid)
                self.session.legacycon.remContact(msn.ALLOW_LIST, jid)
                jid = jid2msn(jid)
                self.session.legacycon.remContact(msn.ALLOW_LIST, jid)
+               self.session.legacycon.remContact(msn.PENDING_LIST, jid)
                self.session.legacycon.addContact(msn.BLOCK_LIST, jid)
 
 
                self.session.legacycon.addContact(msn.BLOCK_LIST, jid)
 
 
@@ -558,8 +600,8 @@ class LegacyList:
 
                # We have to make an MSNContactList from the XDB data, then compare it with the one the server sent
                # Any subscription changes must be sent to the client, as well as changed in the XDB
 
                # We have to make an MSNContactList from the XDB data, then compare it with the one the server sent
                # Any subscription changes must be sent to the client, as well as changed in the XDB
-               LogEvent(INFO, self.session.jabberID, "Start.")
-               result = self.session.pytrans.xdb.request(self.session.jabberID, disco.IQROSTER)
+               LogEvent(INFO, self.jabberID, "Start.")
+               result = self.session.pytrans.xdb.request(self.jabberID, disco.IQROSTER)
                oldContactList = msn.MSNContactList()
                if result:
                        for item in result.elements():
                oldContactList = msn.MSNContactList()
                if result:
                        for item in result.elements():
@@ -626,8 +668,8 @@ class LegacyList:
                        item.attributes["lists"] = str(lists)
                
                # Update the XDB
                        item.attributes["lists"] = str(lists)
                
                # Update the XDB
-               self.session.pytrans.xdb.set(self.session.jabberID, disco.IQROSTER, newXDB)
-               LogEvent(INFO, self.session.jabberID, "End.")
+               self.session.pytrans.xdb.set(self.jabberID, disco.IQROSTER, newXDB)
+               LogEvent(INFO, self.jabberID, "End.")
        
        def saveLegacyList(self):
                contactList = self.session.legacycon.getContacts()
        
        def saveLegacyList(self):
                contactList = self.session.legacycon.getContacts()
@@ -642,7 +684,7 @@ class LegacyList:
                        item.attributes["subscription"] = msnlist2jabsub(contact.lists) # Backwards compat
                        item.attributes["lists"] = str(contact.lists)
 
                        item.attributes["subscription"] = msnlist2jabsub(contact.lists) # Backwards compat
                        item.attributes["lists"] = str(contact.lists)
 
-               self.session.pytrans.xdb.set(self.session.jabberID, disco.IQROSTER, newXDB)
-               LogEvent(INFO, self.session.jabberID, "Finished saving list.")
+               self.session.pytrans.xdb.set(self.jabberID, disco.IQROSTER, newXDB)
+               LogEvent(INFO, self.jabberID, "Finished saving list.")