]>
code.delx.au - pymsnt/blob - src/legacy/glue.py
1 # Copyright 2004-2005 James Bunton <james@delx.cjb.net>
2 # Licensed for distribution under the GPL version 2, check COPYING for details
6 from twisted
. internet
import task
7 from tlib
. xmlw
import Element
9 from debug
import LogEvent
, INFO
, WARN
, ERROR
20 url
= "http://msn-transport.jabberstudio.org"
21 version
= "0.11-dev" # The transport version
22 mangle
= True # XDB '@' -> '%' mangling
23 id = "msn" # The transport identifier
26 # Load the default avatars
27 f
= open ( os
. path
. join ( "data" , "defaultJabberAvatar.png" ), "rb" )
28 defaultJabberAvatarData
= f
. read ()
31 f
= open ( os
. path
. join ( "data" , "defaultMSNAvatar.png" ), "rb" )
32 defaultAvatarData
= f
. read ()
34 defaultAvatar
= avatar
. AvatarCache (). setAvatar ( defaultAvatarData
)
38 msn
. MSNConnection
. GETALLAVATARS
= config
. getAllAvatars
41 """ Returns True if the JID passed is a valid groupchat JID (for MSN, does not contain '%') """
42 return ( jid
. find ( '%' ) == - 1 )
46 # This should be set to the name space the registration entries are in, in the xdb spool
47 namespace
= "jabber:iq:register"
50 def formRegEntry ( username
, password
):
51 """ Returns a domish.Element representation of the data passed. This element will be written to the XDB spool file """
52 reginfo
= Element (( None , "query" ))
53 reginfo
. attributes
[ "xmlns" ] = "jabber:iq:register"
55 userEl
= reginfo
. addElement ( "username" )
56 userEl
. addContent ( username
)
58 passEl
= reginfo
. addElement ( "password" )
59 passEl
. addContent ( password
)
66 def getAttributes ( base
):
67 """ This function should, given a spool domish.Element, pull the username, password,
68 and out of it and return them """
71 for child
in base
. elements ():
73 if child
. name
== "username" :
74 username
= child
.__ str
__ ()
75 elif child
. name
== "password" :
76 password
= child
.__ str
__ ()
77 except AttributeError :
80 return username
, password
83 def startStats ( statistics
):
84 stats
= statistics
. stats
85 stats
[ "MessageCount" ] = 0
86 stats
[ "FailedMessageCount" ] = 0
87 stats
[ "AvatarCount" ] = 0
88 stats
[ "FailedAvatarCount" ] = 0
90 def updateStats ( statistics
):
91 stats
= statistics
. stats
93 #stats["AvatarCount"] = msnp2p.MSNP2P_Avatar.TRANSFER_COUNT
94 #stats["FailedAvatarCount"] = msnp2p.MSNP2P_Avatar.ERROR_COUNT
97 def msn2jid ( msnid
, withResource
):
98 """ Converts a MSN passport into a JID representation to be used with the transport """
99 return msnid
. replace ( '@' , '%' ) + "@" + config
. jid
+ ( withResource
and "/msn" or "" )
101 # Marks this as the function to be used in jabber:iq:gateway (Service ID Translation)
102 translateAccount
= lambda a
: msn2jid ( a
, False )
105 """ Converts a JID representation of a MSN passport into the original MSN passport """
106 return unicode ( jid
[: jid
. find ( '@' )]. replace ( '%' , '@' )). split ( "/" )[ 0 ]
109 def presence2state ( show
, ptype
):
110 """ Converts a Jabber presence into an MSN status code """
111 if ptype
== "unavailable" :
112 return msn
. STATUS_OFFLINE
113 elif not show
or show
== "online" or show
== "chat" :
114 return msn
. STATUS_ONLINE
116 return msn
. STATUS_BUSY
117 elif show
== "away" or show
== "xa" :
118 return msn
. STATUS_AWAY
121 def state2presence ( state
):
122 """ Converts a MSN status code into a Jabber presence """
123 if state
== msn
. STATUS_ONLINE
:
125 elif state
== msn
. STATUS_BUSY
:
127 elif state
== msn
. STATUS_AWAY
:
128 return ( "away" , None )
129 elif state
== msn
. STATUS_IDLE
:
130 return ( "away" , None )
131 elif state
== msn
. STATUS_BRB
:
132 return ( "away" , None )
133 elif state
== msn
. STATUS_PHONE
:
135 elif state
== msn
. STATUS_LUNCH
:
136 return ( "away" , None )
138 return ( None , "unavailable" )
141 def getGroupNames ( msnContact
, msnContactList
):
142 """ Gets a list of groups that this contact is in """
144 for groupGUID
in msnContact
. groups
:
146 groups
. append ( msnContactList
. groups
[ groupGUID
])
151 def msnlist2jabsub ( lists
):
152 """ Converts MSN contact lists ORed together into the corresponding Jabber subscription state """
153 if lists
& msn
. FORWARD_LIST
and lists
& msn
. REVERSE_LIST
:
155 elif lists
& msn
. REVERSE_LIST
:
157 elif lists
& msn
. FORWARD_LIST
:
163 def jabsub2msnlist ( sub
):
164 """ Converts a Jabber subscription state into the corresponding MSN contact lists ORed together """
166 return msn
. FORWARD_LIST
168 return msn
. REVERSE_LIST
170 return ( msn
. FORWARD_LIST | msn
. REVERSE_LIST
)
178 # This class handles groupchats with the legacy protocol
179 class LegacyGroupchat ( groupchat
. BaseGroupchat
):
180 def __init__ ( self
, session
, resource
= None , ID
= None , switchboardSession
= None ):
181 """ Possible entry points for groupchat
182 - User starts an empty switchboard session by sending presence to a blank room
183 - An existing switchboard session is joined by another MSN user
184 - User invited to an existing switchboard session with more than one user
186 groupchat
. BaseGroupchat
.__ init
__ ( self
, session
, resource
, ID
)
187 if switchboardSession
:
188 self
. switchboardSession
= switchboardSession
190 self
. switchboardSession
= msn
. MultiSwitchboardSession ( self
. session
. legacycon
)
191 self
. switchboardSession
. groupchat
= self
193 LogEvent ( INFO
, self
. roomJID ())
196 if self
. switchboardSession
. transport
:
197 self
. switchboardSession
. transport
. loseConnection ()
198 self
. switchboardSession
. groupchat
= None
199 del self
. switchboardSession
200 groupchat
. BaseGroupchat
. removeMe ( self
)
201 LogEvent ( INFO
, self
. roomJID ())
203 def sendLegacyMessage ( self
, message
, noerror
):
204 LogEvent ( INFO
, self
. roomJID ())
205 self
. switchboardSession
. sendMessage ( message
. replace ( " \n " , " \r\n " ), noerror
)
207 def sendContactInvite ( self
, contactJID
):
208 LogEvent ( INFO
, self
. roomJID ())
209 userHandle
= jid2msn ( contactJID
)
210 self
. switchboardSession
. inviteUser ( userHandle
)
212 def gotMessage ( self
, userHandle
, text
):
213 LogEvent ( INFO
, self
. roomJID ())
214 self
. messageReceived ( userHandle
, text
)
218 # This class handles most interaction with the legacy protocol
219 class LegacyConnection ( msn
. MSNConnection
):
220 """ A glue class that connects to the legacy network """
221 def __init__ ( self
, username
, password
, session
):
222 self
. jabberID
= session
. jabberID
224 self
. session
= session
225 self
. listSynced
= False
226 self
. initialListVersion
= 0
229 self
. remoteStatus
= ""
233 msn
. MSNConnection
.__ init
__ ( self
, username
, password
, self
. jabberID
)
235 # User typing notification stuff
236 self
. userTyping
= dict () # Indexed by contact MSN ID, stores whether the user is typing to this contact
237 # Contact typing notification stuff
238 self
. contactTyping
= dict () # Indexed by contact MSN ID, stores an integer that is incremented at 5 second intervals. If it reaches 3 then the contact has stopped typing. It is set to zero whenever MSN typing notification messages are received
240 self
. userTypingSend
= task
. LoopingCall ( self
. sendTypingNotifications
)
241 self
. userTypingSend
. start ( 5.0 )
243 self
. legacyList
= LegacyList ( self
. session
)
245 LogEvent ( INFO
, self
. jabberID
)
248 LogEvent ( INFO
, self
. jabberID
)
250 self
. userTypingSend
. stop ()
252 self
. legacyList
. removeMe ()
253 self
. legacyList
= None
258 # Implemented from baseproto
259 def sendShowStatus ( self
, jid
= None ):
260 if not self
. session
: return
264 self
. session
. sendPresence ( to
= jid
, fro
= source
, show
= self
. remoteShow
, status
= self
. remoteStatus
, nickname
= self
. remoteNick
)
266 def resourceOffline ( self
, resource
):
269 def highestResource ( self
):
270 """ Returns highest priority resource """
271 return self
. session
. highestResource ()
273 def sendMessage ( self
, dest
, resource
, body
, noerror
):
275 if self
. userTyping
. has_key ( dest
):
276 del self
. userTyping
[ dest
]
278 msn
. MSNConnection
. sendMessage ( self
, dest
, body
, noerror
)
279 self
. session
. pytrans
. statistics
. stats
[ "MessageCount" ] += 1
281 self
. failedMessage ( dest
, body
)
284 def sendFile ( self
, dest
, ftSend
):
286 def continueSendFile1 (( msnFileSend
, d
)):
287 def continueSendFile2 (( success
, )):
289 ftSend
. accept ( msnFileSend
)
292 d
. addCallbacks ( continueSendFile2
, sendFileFail
)
297 d
= msn
. MSNConnection
. sendFile ( self
, dest
, ftSend
. filename
, ftSend
. filesize
)
298 d
. addCallbacks ( continueSendFile1
, sendFileFail
)
300 def setStatus ( self
, nickname
, show
, status
):
301 statusCode
= presence2state ( show
, None )
302 msn
. MSNConnection
. changeStatus ( self
, statusCode
, nickname
, status
)
304 def updateAvatar ( self
, av
= None ):
305 global defaultJabberAvatarData
308 msn
. MSNConnection
. changeAvatar ( self
, av
. getImageData ())
310 msn
. MSNConnection
. changeAvatar ( self
, defaultJabberAvatarData
)
312 def sendTypingNotifications ( self
):
313 if not self
. session
: return
315 # Send any typing notification messages to the user's contacts
316 for contact
in self
. userTyping
. keys ():
317 if self
. userTyping
[ contact
]:
318 self
. sendTypingToContact ( contact
)
320 # Send any typing notification messages from contacts to the user
321 for contact
in self
. contactTyping
. keys ():
322 self
. contactTyping
[ contact
] += 1
323 if self
. contactTyping
[ contact
] >= 3 :
324 self
. session
. sendTypingNotification ( self
. jabberID
, msn2jid ( contact
, True ), False )
325 del self
. contactTyping
[ contact
]
327 def userTypingNotification ( self
, dest
, resource
, composing
):
328 if not self
. session
: return
330 self
. userTyping
[ dest
] = composing
331 if composing
: # Make it instant
332 self
. sendTypingToContact ( dest
)
336 # Implement callbacks from msn.MSNConnection
337 def connectionFailed ( self
, reason
):
338 LogEvent ( INFO
, self
. jabberID
)
339 text
= lang
. get ( self
. session
. lang
). msnConnectFailed
% reason
340 self
. session
. sendMessage ( to
= self
. jabberID
, fro
= config
. jid
, body
= text
)
341 self
. session
. removeMe ()
343 def loginFailed ( self
, reason
):
344 LogEvent ( INFO
, self
. jabberID
)
345 text
= lang
. get ( self
. session
. lang
). msnLoginFailure
% ( self
. session
. username
)
346 self
. session
. sendErrorMessage ( to
= self
. jabberID
, fro
= config
. jid
, etype
= "auth" , condition
= "not-authorized" , explanation
= text
, body
= "Login Failure" )
347 self
. session
. removeMe ()
349 def connectionLost ( self
, reason
):
350 LogEvent ( INFO
, self
. jabberID
)
351 text
= lang
. get ( self
. session
. lang
). msnDisconnected
% reason
352 self
. session
. sendMessage ( to
= self
. jabberID
, fro
= config
. jid
, body
= text
)
353 self
. session
. removeMe () # Tear down the session
355 def multipleLogin ( self
):
356 LogEvent ( INFO
, self
. jabberID
)
357 self
. session
. sendMessage ( to
= self
. jabberID
, fro
= config
. jid
, body
= lang
. get ( self
. session
. lang
). msnMultipleLogin
)
358 self
. session
. removeMe ()
360 def serverGoingDown ( self
):
361 LogEvent ( INFO
, self
. jabberID
)
362 self
. session
. sendMessage ( to
= self
. jabberID
, fro
= config
. jid
, body
= lang
. get ( self
. session
. lang
). msnMaintenance
)
364 def accountNotVerified ( self
):
365 LogEvent ( INFO
, self
. jabberID
)
366 text
= lang
. get ( self
. session
. lang
). msnNotVerified
% ( self
. session
. username
)
367 self
. session
. sendMessage ( to
= self
. jabberID
, fro
= config
. jid
, body
= text
)
369 def userMapping ( self
, passport
, jid
):
370 LogEvent ( INFO
, self
. jabberID
)
371 text
= lang
. get ( self
. session
. lang
). userMapping
% ( passport
, jid
)
372 self
. session
. sendMessage ( to
= self
. jabberID
, fro
= msn2jid ( passport
, True ), body
= text
)
375 LogEvent ( INFO
, self
. jabberID
)
376 self
. session
. ready
= True
378 def listSynchronized ( self
):
379 LogEvent ( INFO
, self
. jabberID
)
380 self
. session
. sendPresence ( to
= self
. jabberID
, fro
= config
. jid
)
381 self
. legacyList
. syncJabberLegacyLists ()
382 self
. listSynced
= True
383 #self.legacyList.flushSubscriptionBuffer()
385 def ourStatusChanged ( self
, statusCode
, screenName
, personal
):
386 # Send out a new presence packet to the Jabber user so that the transport icon changes
387 LogEvent ( INFO
, self
. jabberID
)
388 self
. remoteShow
, ptype
= state2presence ( statusCode
)
389 self
. remoteStatus
= personal
390 self
. remoteNick
= screenName
391 self
. sendShowStatus ()
393 def gotMessage ( self
, remoteUser
, text
):
394 LogEvent ( INFO
, self
. jabberID
)
395 source
= msn2jid ( remoteUser
, True )
396 if self
. contactTyping
. has_key ( remoteUser
):
397 del self
. contactTyping
[ remoteUser
]
398 self
. session
. sendMessage ( self
. jabberID
, fro
= source
, body
= text
, mtype
= "chat" )
399 self
. session
. pytrans
. statistics
. stats
[ "MessageCount" ] += 1
401 def gotGroupchat ( self
, msnGroupchat
, userHandle
):
402 LogEvent ( INFO
, self
. jabberID
)
403 msnGroupchat
. groupchat
= LegacyGroupchat ( self
. session
, switchboardSession
= msnGroupchat
)
404 msnGroupchat
. groupchat
. sendUserInvite ( msn2jid ( userHandle
, True ))
406 def gotContactTyping ( self
, contact
):
407 LogEvent ( INFO
, self
. jabberID
)
408 # Check if the contact has only just started typing
409 if not self
. contactTyping
. has_key ( contact
):
410 self
. session
. sendTypingNotification ( self
. jabberID
, msn2jid ( contact
, True ), True )
413 self
. contactTyping
[ contact
] = 0
415 def failedMessage ( self
, remoteUser
, message
):
416 LogEvent ( INFO
, self
. jabberID
)
417 self
. session
. pytrans
. statistics
. stats
[ "FailedMessageCount" ] += 1
418 fro
= msn2jid ( remoteUser
, True )
419 self
. session
. sendErrorMessage ( to
= self
. jabberID
, fro
= fro
, etype
= "wait" , condition
= "recipient-unavailable" , explanation
= lang
. get ( self
. session
. lang
). msnFailedMessage
, body
= message
)
421 def contactAvatarChanged ( self
, userHandle
, hash ):
422 LogEvent ( INFO
, self
. jabberID
)
423 jid
= msn2jid ( userHandle
, False )
424 c
= self
. session
. contactList
. findContact ( jid
)
429 av
= self
. session
. pytrans
. avatarCache
. getAvatar ( hash )
431 msnContact
= self
. getContacts (). getContact ( userHandle
)
432 msnContact
. msnobjGot
= True
435 def updateAvatarCB (( imageData
,)):
436 av
= self
. session
. pytrans
. avatarCache
. setAvatar ( imageData
)
438 d
= self
. sendAvatarRequest ( userHandle
)
440 d
. addCallback ( updateAvatarCB
)
442 # They've turned off their avatar
444 c
. updateAvatar ( defaultAvatar
)
446 def contactStatusChanged ( self
, remoteUser
):
447 LogEvent ( INFO
, self
. jabberID
)
449 msnContact
= self
. getContacts (). getContact ( remoteUser
)
450 c
= self
. session
. contactList
. findContact ( msn2jid ( remoteUser
, False ))
451 if not ( c
and msnContact
): return
453 show
, ptype
= state2presence ( msnContact
. status
)
454 status
= msnContact
. personal
. decode ( "utf-8" )
455 screenName
= msnContact
. screenName
. decode ( "utf-8" )
457 c
. updateNickname ( screenName
, push
= False )
458 c
. updatePresence ( show
, status
, ptype
, force
= True )
460 def gotFileReceive ( self
, fileReceive
):
461 LogEvent ( INFO
, self
. jabberID
)
463 ft
. FTReceive ( self
. session
, msn2jid ( fileReceive
. userHandle
, True ), fileReceive
)
465 def contactAddedMe ( self
, userHandle
):
466 LogEvent ( INFO
, self
. jabberID
)
467 self
. session
. contactList
. getContact ( msn2jid ( userHandle
, False )). contactRequestsAuth ()
469 def contactRemovedMe ( self
, userHandle
):
470 LogEvent ( INFO
, self
. jabberID
)
471 c
= self
. session
. contactList
. getContact ( msn2jid ( userHandle
, True ))
472 c
. contactDerequestsAuth ()
473 c
. contactRemovesAuth ()
475 def gotInitialEmailNotification ( self
, inboxunread
, foldersunread
):
476 if config
. mailNotifications
:
477 LogEvent ( INFO
, self
. jabberID
)
478 text
= lang
. get ( self
. session
. lang
). msnInitialMail
% ( inboxunread
, foldersunread
)
479 self
. session
. sendMessage ( to
= self
. jabberID
, fro
= config
. jid
, body
= text
, mtype
= "headline" )
481 def gotRealtimeEmailNotification ( self
, mailfrom
, fromaddr
, subject
):
482 if config
. mailNotifications
:
483 LogEvent ( INFO
, self
. jabberID
)
484 text
= lang
. get ( self
. session
. lang
). msnRealtimeMail
% ( mailfrom
, fromaddr
, subject
)
485 self
. session
. sendMessage ( to
= self
. jabberID
, fro
= config
. jid
, body
= text
, mtype
= "headline" )
487 def gotMSNAlert ( self
, text
, actionurl
, subscrurl
):
488 LogEvent ( INFO
, self
. jabberID
)
490 el
= Element (( None , "message" ))
491 el
. attributes
[ "to" ] = self
. jabberID
492 el
. attributes
[ "from" ] = config
. jid
493 el
. attributes
[ "type" ] = "headline"
494 body
= el
. addElement ( "body" )
495 body
. addContent ( text
)
497 x
= el
. addElement ( "x" )
498 x
. attributes
[ "xmlns" ] = "jabber:x:oob"
499 x
. addElement ( "desc" ). addContent ( "More information on this notice." )
500 x
. addElement ( "url" ). addContent ( actionurl
)
502 x
= el
. addElement ( "x" )
503 x
. attributes
[ "xmlns" ] = "jabber:x:oob"
504 x
. addElement ( "desc" ). addContent ( "Manage subscriptions to alerts." )
505 x
. addElement ( "url" ). addContent ( subscrurl
)
507 self
. session
. pytrans
. send ( el
)
509 def gotAvatarImageData ( self
, userHandle
, imageData
):
510 LogEvent ( INFO
, self
. jabberID
)
511 av
= self
. session
. pytrans
. avatarCache
. setAvatar ( imageData
)
512 jid
= msn2jid ( userHandle
, False )
513 c
= self
. session
. contactList
. findContact ( jid
)
520 def __init__ ( self
, session
):
521 self
. jabberID
= session
. jabberID
522 self
. session
= session
523 self
. subscriptionBuffer
= []
526 self
. subscriptionBuffer
= None
529 def addContact ( self
, jid
):
530 LogEvent ( INFO
, self
. jabberID
)
531 userHandle
= jid2msn ( jid
)
532 self
. session
. legacycon
. addContact ( msn
. FORWARD_LIST
, userHandle
)
533 self
. session
. contactList
. getContact ( jid
). contactGrantsAuth ()
535 def removeContact ( self
, jid
):
536 LogEvent ( INFO
, self
. jabberID
)
538 self
. session
. legacycon
. remContact ( msn
. FORWARD_LIST
, jid
)
541 def authContact ( self
, jid
):
542 LogEvent ( INFO
, self
. jabberID
)
544 d
= self
. session
. legacycon
. remContact ( msn
. PENDING_LIST
, jid
)
546 self
. session
. legacycon
. addContact ( msn
. REVERSE_LIST
, jid
)
547 self
. session
. legacycon
. remContact ( msn
. BLOCK_LIST
, jid
)
548 self
. session
. legacycon
. addContact ( msn
. ALLOW_LIST
, jid
)
550 def deauthContact ( self
, jid
):
551 LogEvent ( INFO
, self
. jabberID
)
553 self
. session
. legacycon
. remContact ( msn
. ALLOW_LIST
, jid
)
554 self
. session
. legacycon
. remContact ( msn
. PENDING_LIST
, jid
)
555 self
. session
. legacycon
. addContact ( msn
. BLOCK_LIST
, jid
)
559 def syncJabberLegacyLists ( self
):
560 """ Synchronises the MSN contact list on server with the Jabber contact list """
564 # We have to make an MSNContactList from the XDB data, then compare it with the one the server sent
565 # Any subscription changes must be sent to the client, as well as changed in the XDB
566 LogEvent ( INFO
, self
. jabberID
, "Start." )
567 result
= self
. session
. pytrans
. xdb
. request ( self
. jabberID
, disco
. IQROSTER
)
568 oldContactList
= msn
. MSNContactList ()
570 for item
in result
. elements ():
571 user
= item
. getAttribute ( "jid" )
572 sub
= item
. getAttribute ( "subscription" )
573 lists
= item
. getAttribute ( "lists" )
575 lists
= jabsub2msnlist ( sub
) # Backwards compatible
577 contact
= msn
. MSNContact ( userHandle
= user
, screenName
= "" , lists
= lists
)
578 oldContactList
. addContact ( contact
)
580 newXDB
= Element (( None , "query" ))
581 newXDB
. attributes
[ "xmlns" ] = disco
. IQROSTER
583 contactList
= self
. session
. legacycon
. getContacts ()
586 # Convienence functions
587 def addedToList ( num
):
588 return ( not ( oldLists
& num
) and ( lists
& num
))
589 def removedFromList ( num
):
590 return (( oldLists
& num
) and not ( lists
& num
))
592 for contact
in contactList
. contacts
. values ():
593 # Compare with the XDB <item/> entry
594 oldContact
= oldContactList
. getContact ( contact
. userHandle
)
595 if oldContact
== None :
598 oldLists
= oldContact
. lists
599 lists
= contact
. lists
601 # Create the Jabber representation of the
602 # contact base on the old list data and then
603 # sync it with current
604 jabContact
= self
. session
. contactList
. createContact ( msn2jid ( contact
. userHandle
, False ), msnlist2jabsub ( oldLists
))
605 jabContact
. updateAvatar ( defaultAvatar
, push
= False )
607 if addedToList ( msn
. FORWARD_LIST
):
608 jabContact
. syncGroups ( getGroupNames ( contact
, contactList
), push
= False )
609 jabContact
. syncContactGrantedAuth ()
611 if removedFromList ( msn
. FORWARD_LIST
):
612 jabContact
. syncContactRemovedAuth ()
614 if addedToList ( msn
. ALLOW_LIST
):
615 jabContact
. syncUserGrantedAuth ()
617 if addedToList ( msn
. BLOCK_LIST
) or removedFromList ( msn
. ALLOW_LIST
):
618 jabContact
. syncUserRemovedAuth ()
620 if ( not ( lists
& msn
. ALLOW_LIST
) and not ( lists
& msn
. BLOCK_LIST
) and ( lists
& msn
. REVERSE_LIST
)) or ( lists
& msn
. PENDING_LIST
):
621 jabContact
. contactRequestsAuth ()
623 if removedFromList ( msn
. REVERSE_LIST
):
624 jabContact
. contactDerequestsAuth ()
626 jabContact
. syncRoster ()
628 item
= newXDB
. addElement ( "item" )
629 item
. attributes
[ "jid" ] = contact
. userHandle
630 item
. attributes
[ "subscription" ] = msnlist2jabsub ( lists
)
631 item
. attributes
[ "lists" ] = str ( lists
)
634 self
. session
. pytrans
. xdb
. set ( self
. jabberID
, disco
. IQROSTER
, newXDB
)
635 LogEvent ( INFO
, self
. jabberID
, "End." )
637 def saveLegacyList ( self
):
638 contactList
= self
. session
. legacycon
. getContacts ()
639 if not contactList
: return
641 newXDB
= Element (( None , "query" ))
642 newXDB
. attributes
[ "xmlns" ] = disco
. IQROSTER
644 for contact
in contactList
. contacts
. values ():
645 item
= newXDB
. addElement ( "item" )
646 item
. attributes
[ "jid" ] = contact
. userHandle
647 item
. attributes
[ "subscription" ] = msnlist2jabsub ( contact
. lists
) # Backwards compat
648 item
. attributes
[ "lists" ] = str ( contact
. lists
)
650 self
. session
. pytrans
. xdb
. set ( self
. jabberID
, disco
. IQROSTER
, newXDB
)
651 LogEvent ( INFO
, self
. jabberID
, "Finished saving list." )