def sendClientCaps(self): message = msn.MSNMessage() message.setHeader("Content-Type", "text/x-clientcaps") message.setHeader("Client-Name", "PyMSNt") if hasattr(self.msncon, "jabberID"): message.setHeader("JabberID", str(self.msncon.jabberID)) self.sendMessage(message)
def sendMessageReal(self, text, noerror=False): if not isinstance(text, basestring): msn.SwitchboardClient.sendMessage(self, text) return if not self.ready: self.messageBuffer.append((text, noerror)) else: LogEvent(INFO, self.ident) text = str(text.replace("\n", "\r\n").encode("utf-8")) def failedMessage(ignored): if not noerror: self.failedMessage(text) if len(text) < MSNConnection.MAXMESSAGESIZE: message = msn.MSNMessage(message=text) message.ack = msn.MSNMessage.MESSAGE_NACK d = msn.SwitchboardClient.sendMessage(self, message) if not noerror: d.addCallbacks(failedMessage, failedMessage) else: chunks = int( math.ceil(len(text) / float(MSNConnection.MAXMESSAGESIZE))) chunk = 0 guid = msn.random_guid() while chunk < chunks: offset = chunk * MSNConnection.MAXMESSAGESIZE message = msn.MSNMessage( message=text[offset:offset + MSNConnection.MAXMESSAGESIZE]) message.ack = msn.MSNMessage.MESSAGE_NACK message.setHeader("Message-ID", guid) if chunk == 0: message.setHeader("Chunks", str(chunks)) else: message.delHeader("MIME-Version") message.delHeader("Content-Type") message.setHeader("Chunk", str(chunk)) d = msn.SwitchboardClient.sendMessage(self, message) if not noerror: d.addCallbacks(failedMessage, failedMessage) chunk += 1
def doSendMessage(self): def testcb(ignored): self.state = 'MESSAGESUCCESS' self.transport.loseConnection() m = msn.MSNMessage() m.setHeader("Content-Type", "text/plain; charset=UTF-8") m.message = 'Hi how are you today?' m.ack = msn.MSNMessage.MESSAGE_ACK d = self.sendMessage(m) d.addCallback(testcb)
def handle_QRY(self, params): self.state = 1 if len(params) == 3 and params[1] == "PROD0090YUAUV{2B" and params[ 2] == "32": self.state = 2 self.currentMessage = msn.MSNMessage(length=32, userHandle="QRY", screenName="QRY", specialMessage=True) self.setRawMode() else: self.transport.loseConnection()
def handle_UUX(self, params): if len(params) != 2: self.transport.loseConnection() return l = int(params[1]) if l > 0: self.currentMessage = msn.MSNMessage(length=l, userHandle=params[0], screenName="UUX", specialMessage=True) self.setRawMode() else: self.sendLine("UUX %s 0" % params[0])
def testMessage(self): self.client1.sendMessage(msn.MSNMessage(message='Test Message')) self._loop() self.failUnless((self.client2.status == "GOTMESSAGE"), "Fake switchboard server not working.")