예제 #1
0
    def try_make_packet(self):
        logger.debug('try_make_packet')
        tag = 0
        tag |= c.IPMSG_SENDMSG
        tag |= c.IPMSG_SENDCHECKOPT
        tag |= c.IPMSG_RETRYOPT

        if status.is_invisible() or self.addr[0] in settings['block_list']:
            tag |= c.IPMSG_NOADDLISTOPT
        elif status.is_afk():
            tag |= c.IPMSG_ABSENCEOPT

        if self.options['autoret']:
            tag |= c.IPMSG_AUTORETOPT

        if self.options['seal']:
            tag |= c.IPMSG_SECRETOPT
            if self.options['read_check']:
                tag |= c.IPMSG_READCHECKOPT
            if self.options['password']:
                tag |= c.IPMSG_PASSWORDOPT

        if engine.supports_utf8(self.addr):
            tag |= c.IPMSG_UTF8OPT
            encode_func = util.uni_to_utf8
        else:
            encode_func = util.uni_to_sjis

        msg = self.msg

        if self.atts and self.options['webshare']:
            msg += '\n\n' + webshare_manager.start(self.atts)

        contact = engine.get_contact(self.addr) or Contact(name='', group='', host='', addr=self.addr)

        msg = unicode(msg, 'utf8')
        msg = encode_func(msg)

        if self.options['encrypt']:
            rslt = self.encrypt(msg, contact)
            if not rslt:
                logger.debug('encrypt failed')
                return
            else:
                logger.debug('encrypt success')
                is_enc, msg = rslt
                if is_enc:
                    tag |= c.IPMSG_ENCRYPTOPT

        if self.atts and not self.options['webshare']:
            tag |= c.IPMSG_FILEATTACHOPT
            msg += '\x00' + encode_func(upload_manager.append_files(self.addr, self.atts))

        logger.debug('ready to make msg')
        raw = engine.make_msg(self.addr, tag, msg)
        self.packet = Packet.parse(raw, self.addr) 
        self.status = Message.INIT

        self.write_log()
예제 #2
0
    def make_outcoming(cls, addr, msg, atts, **options):
        self = cls()
        self.io = 0
        self.msg = msg
        self.addr = addr
        self.atts = atts
        self.options = cls.options.copy()
        self.options.update(**options)
        if self.options['seal'] and settings['do_readmsg_chk']:
            self.options['read_check'] = True

        if self.options['encrypt']:
            self.status = Message.NEED_RSAKEY
        logger.debug('get_contact')
        self.contact = engine.get_contact(self.addr)
        self.try_make_packet()

        if self.options['autoret']:
            self.out_status = Message.SENT

        return self
예제 #3
0
    def make_outcoming(cls, addr, msg, atts, **options):
        self = cls()
        self.io = 0
        self.msg = msg
        self.addr = addr
        self.atts = atts
        self.options = cls.options.copy()
        self.options.update(**options)
        if self.options['seal'] and settings['do_readmsg_chk']:
            self.options['read_check'] = True
 
        if self.options['encrypt']:
            self.status = Message.NEED_RSAKEY
        logger.debug('get_contact')
        self.contact = engine.get_contact(self.addr)
        self.try_make_packet()

        if self.options['autoret']:
            self.out_status = Message.SENT

        return self
예제 #4
0
    def try_make_packet(self):
        logger.debug('try_make_packet')
        tag = 0
        tag |= c.IPMSG_SENDMSG
        tag |= c.IPMSG_SENDCHECKOPT
        tag |= c.IPMSG_RETRYOPT

        if status.is_invisible() or self.addr[0] in settings['block_list']:
            tag |= c.IPMSG_NOADDLISTOPT
        elif status.is_afk():
            tag |= c.IPMSG_ABSENCEOPT

        if self.options['autoret']:
            tag |= c.IPMSG_AUTORETOPT

        if self.options['seal']:
            tag |= c.IPMSG_SECRETOPT
            if self.options['read_check']:
                tag |= c.IPMSG_READCHECKOPT
            if self.options['password']:
                tag |= c.IPMSG_PASSWORDOPT

        if engine.supports_utf8(self.addr):
            tag |= c.IPMSG_UTF8OPT
            encode_func = util.uni_to_utf8
        else:
            encode_func = util.uni_to_sjis

        msg = self.msg

        if self.atts and self.options['webshare']:
            msg += '\n\n' + webshare_manager.start(self.atts)

        contact = engine.get_contact(self.addr) or Contact(
            name='', group='', host='', addr=self.addr)

        msg = unicode(msg, 'utf8')
        msg = encode_func(msg)

        if self.options['encrypt']:
            rslt = self.encrypt(msg, contact)
            if not rslt:
                logger.debug('encrypt failed')
                return
            else:
                logger.debug('encrypt success')
                is_enc, msg = rslt
                if is_enc:
                    tag |= c.IPMSG_ENCRYPTOPT

        if self.atts and not self.options['webshare']:
            tag |= c.IPMSG_FILEATTACHOPT
            msg += '\x00' + encode_func(
                upload_manager.append_files(self.addr, self.atts))

        logger.debug('ready to make msg')
        raw = engine.make_msg(self.addr, tag, msg)
        self.packet = Packet.parse(raw, self.addr)
        self.status = Message.INIT

        self.write_log()
예제 #5
0
 def write_log(self):
     log_func = self.io and message_logger.log_recv or message_logger.log_send
     if settings['enable_log']:
         log_func(self.get_contact() or engine.get_contact(self.addr),
                  self.msg, self.io and [att.name for att in self.atts]
                  or self.atts)
예제 #6
0
 def write_log(self):
     log_func = self.io and message_logger.log_recv or message_logger.log_send
     if settings['enable_log']:
         log_func(self.get_contact() or engine.get_contact(self.addr), self.msg, self.io and [att.name for att in self.atts] or self.atts)