示例#1
0
    def parse(cls, command):
        '''parse a message from a command object and return a Message object'''
        parts = command.payload.split('\r\n\r\n', 1)
        if len(parts) == 1:
            head = parts[0]
            body = ''
        elif len(parts) == 2:
            (head, body) = parts

        type_ = common.get_value_between(head, 'Content-Type: ', '\r\n')

        # if content type is the last line we should not use \r\n as terminator
        if type_ == '' and 'Content-Type: ' in head:
            type_ = head.split('Content-Type: ')[1]

        style = None
        dest = ''

        if type_.startswith('text/plain'):
            mtype = Message.TYPE_MESSAGE
            font = urllib.unquote(common.get_value_between(head, 'FN=', ';'))
            effects = common.get_value_between(head, 'EF=', ';')
            color = common.get_value_between(head, 'CO=', ';', '000000')

            if color.startswith('#'):
                color = color[1:]

            if len(color) < 3:
                color += '0' * (3 - len(color))
            elif len(color) > 3 and len(color) < 6:
                color += '0' * (6 - len(color))

            color = e3.Color.from_hex(color[4:6] + color[2:4] + color[0:2])

            bold = 'B' in effects
            italic = 'I' in effects
            underline = 'U' in effects
            strike = 'S' in effects

            style = Style(font, color, bold, italic, underline, strike)
        elif type_ == 'text/x-msmsgscontrol':
            mtype = Message.TYPE_TYPING
        elif type_ == 'application/x-msnmsgrp2p':
            mtype = Message.TYPE_P2P
            dest = common.get_value_between(head, 'P2P-Dest: ', '\r\n')
        elif type_ == 'text/x-msnmsgr-datacast' and body == 'ID: 1\r\n\r\n':
            mtype = Message.TYPE_NUDGE
        else:
            mtype = Message.TYPE_UNK

        return cls(mtype, body, command.tid, style, dest)
示例#2
0
    def parse(cls, command):
        '''parse a message from a command object and return a Message object'''
        parts = command.payload.split('\r\n\r\n', 1)
        if len(parts) == 1:
            head = parts[0]
            body = ''
        elif len(parts) == 2:
            (head, body) = parts

        type_ = common.get_value_between(head, 'Content-Type: ', '\r\n')

        # if content type is the last line we should not use \r\n as terminator
        if type_ == '' and 'Content-Type: ' in head:
            type_ = head.split('Content-Type: ')[1]

        style = None
        dest = ''

        if type_.startswith('text/plain'):
            mtype = Message.TYPE_MESSAGE
            font = urllib.unquote(common.get_value_between(head, 'FN=', ';'))
            effects = common.get_value_between(head, 'EF=', ';')
            color = common.get_value_between(head, 'CO=', ';', '000000')

            if color.startswith('#'):
                color = color[1:]

            if len(color) < 3:
                color += '0' * (3 - len(color))
            elif len(color) > 3 and len(color) < 6:
                color += '0' * (6 - len(color))

            color = e3.Color.from_hex(color[4:6] + color[2:4] + color[0:2])

            bold = 'B' in effects
            italic = 'I' in effects
            underline = 'U' in effects
            strike = 'S' in effects

            style = Style(font, color, bold, italic, underline, strike)
        elif type_ == 'text/x-msmsgscontrol':
            mtype = Message.TYPE_TYPING
        elif type_ == 'application/x-msnmsgrp2p':
            mtype = Message.TYPE_P2P
            dest = common.get_value_between(head, 'P2P-Dest: ', '\r\n')
        elif type_ == 'text/x-msnmsgr-datacast' and body == 'ID: 1\r\n\r\n':
            mtype = Message.TYPE_NUDGE
        else:
            mtype = Message.TYPE_UNK

        return cls(mtype, body, command.tid, style, dest)
示例#3
0
    def handle_response(self, request, response):
        '''handle the response'''
        if response.status == 200:
            gid = common.get_value_between(response.body, '<guid>', '</guid>')
            self.session.groups[gid] = e3.Group(self.name, gid)

            self.session.add_event(e3.Event.EVENT_GROUP_ADD_SUCCEED,
                self.name, gid)
        else:
            log.debug(response.body + '\n' + request.body)
            self.session.add_event(e3.Event.EVENT_GROUP_ADD_FAILED, self.name)
示例#4
0
    def handle_response(self, request, response):
        '''handle the response'''
        if response.status == 200:
            gid = common.get_value_between(response.body, '<guid>', '</guid>')
            self.session.groups[gid] = e3.Group(self.name, gid)

            self.session.add_event(e3.Event.EVENT_GROUP_ADD_SUCCEED,
                self.name, gid)
        else:
            log.debug(response.body + '\n' + request.body)
            self.session.add_event(e3.Event.EVENT_GROUP_ADD_FAILED, self.name)
示例#5
0
    def handle_response(self, request, response):
        '''handle the response'''
        if response.status == 200:
            #self.msg_queue.add_event(e3.Event.EVENT_OIM_SEND_SUCCEED, self.oid)
            log.debug('OIM sent ' + self.contact)
        else:
            start = '<LockKeyChallenge xmlns="http://messenger.msn.com/'\
                    'ws/2004/09/oim/">'
            end = '</LockKeyChallenge>'
            lockkey_hash = common.get_value_between(response.body, start, end)

            if lockkey_hash:
                lockkey = challenge.do_challenge(str(lockkey_hash))
                SendOIM(self.session, self.msg_queue, self.contact,
                        self.message, lockkey, self.seq+1, False).start()
            else:
                log.debug('Can\'t send OIM, fail')
                log.debug(response.body)
                self.session.add_event(e3.Event.EVENT_ERROR,
                             'to many retries sending oims')
                log.debug('to many retries sending oim')
示例#6
0
    def handle_response(self, request, response):
        '''handle the response'''
        if response.status == 200:
            #self.msg_queue.add_event(e3.Event.EVENT_OIM_SEND_SUCCEED, self.oid)
            log.debug('OIM sent ' + self.contact)
        else:
            start = '<LockKeyChallenge xmlns="http://messenger.msn.com/'\
                    'ws/2004/09/oim/">'
            end = '</LockKeyChallenge>'
            lockkey_hash = common.get_value_between(response.body, start, end)

            if lockkey_hash:
                lockkey = challenge.do_challenge(str(lockkey_hash))
                SendOIM(self.session, self.msg_queue, self.contact,
                        self.message, lockkey, self.seq+1, False).start()
            else:
                log.debug('Can\'t send OIM, fail')
                log.debug(response.body)
                self.session.add_event(e3.Event.EVENT_ERROR,
                             'to many retries sending oims')
                log.debug('to many retries sending oim')