コード例 #1
0
ファイル: msgserve.py プロジェクト: hick/x84
def receive_message_from(board_id, request_data,
                         db_source, db_transactions):
    " Reply-to api client request to post a new message. "
    from x84.bbs.msgbase import to_localtime, Msg
    log = logging.getLogger(__name__)

    if 'message' not in request_data:
        return server_error(log.info, u'No message')

    pullmsg = request_data['message']

    # validate
    for key in (_key for _key in VALIDATE_MSG_KEYS if _key not in pullmsg):
        return server_error(log_func=log.info,
                            log_msg=('Missing message sub-field, {key!r}'
                                     .format(key=key)))

    msg = Msg()
    msg.author = pullmsg['author']
    msg.recipient = pullmsg['recipient']
    msg.subject = pullmsg['subject']
    msg.parent = pullmsg['parent']
    msg.tags = set(pullmsg['tags'] + [request_data['network']])
    msg.body = pullmsg['body']
    # ?? is this removing millesconds, or ?
    _ctime = to_localtime(pullmsg['ctime'].split('.', 1)[0])
    msg.save(send_net=False, ctime=_ctime)
    with db_source, db_transactions:
        db_source[msg.idx] = board_id
        db_transactions[msg.idx] = msg.idx
    return {u'response': True, u'id': msg.idx}
コード例 #2
0
def receive_message_from(board_id, request_data, db_source, db_transactions):
    " Reply-to api client request to post a new message. "
    from x84.bbs.msgbase import to_localtime, Msg
    log = logging.getLogger(__name__)

    if 'message' not in request_data:
        return server_error(log.info, u'No message')

    pullmsg = request_data['message']

    # validate
    for key in (_key for _key in VALIDATE_MSG_KEYS if _key not in pullmsg):
        return server_error(
            log_func=log.info,
            log_msg=('Missing message sub-field, {key!r}'.format(key=key)))

    msg = Msg()
    msg.author = pullmsg['author']
    msg.recipient = pullmsg['recipient']
    msg.subject = pullmsg['subject']
    msg.parent = pullmsg['parent']
    msg.tags = set(pullmsg['tags'] + [request_data['network']])
    msg.body = pullmsg['body']
    # ?? is this removing millesconds, or ?
    _ctime = to_localtime(pullmsg['ctime'].split('.', 1)[0])
    msg.save(send_net=False, ctime=_ctime)
    with db_source, db_transactions:
        db_source[msg.idx] = board_id
        db_transactions[msg.idx] = msg.idx
    return {u'response': True, u'id': msg.idx}
コード例 #3
0
    def import_messages(self):
        from x84.bbs.msgbase import Msg
        # hook into x84 and write message to default database and
        # keep separate database for fido specific fields.

        # 'author': msg.author,
        # 'subject': msg.subject,
        # 'recipient': msg.recipient,
        # 'parent': parent,
        # 'tags': [tag for tag in msg.tags if tag != network['name']],
        # 'ctime': to_utctime(msg.ctime)
        store_msg = Msg()
        store_msg.recipient = unicode(self.user_to, 'CP437')
        store_msg.author = unicode(self.user_from, 'CP437')
        store_msg.subject = unicode(self.subject, 'CP437')

        # Add Check here for Private Netmail messages, this functionality will be added lateron

        # Convert from CP437 for high ascii, later on read CHRS kludge for origin character set
        store_msg.body = unicode('\r'.join(self.message_lines).replace('\x9d', ''), 'CP437')

        # If area is a normal public echo, default is public
        store_msg.tags.add(u''.join('public'))

        # Change to Network Name ie Agoranet
        store_msg.tags.add(u''.join(self.network))

        # Translate the area to the tag description.
        # eg.. AGN_GEN -> general
        area_tag = cfg.get_tag(self.network, self.area)

        # print 'Area Tag: ' + area_tag
        if area_tag is not None:
            store_msg.tags.add(u''.join(area_tag))

        # In testing
        # if area is not a public echo, add to sysop group tag
        # store_msg.tags.add(u''.join('sysop'))

        # Convert Packet String to Date Time format.
        # We should also get and check UTZ kludge line!  Lateron for offset / Timezone.
        # 26 Feb 15  18:04:00
        date_object = datetime.datetime.strptime(self.date_time, '%d %b %y %H:%M:%S')

        # do not save this message to network, we already received
        # it from the network, set send_net=False
        # Also avoid sending over X84 NET
        store_msg.save(send_net=False, ctime=date_object)

        print 'Msg Index after save: {0}'.format(store_msg.idx)

        # Setup and store the fido kludge data
        fido_msg = StoredFidoInfo(store_msg.idx)
        fido_msg.status('received')
        fido_msg.kludge_lines(self.kludge_lines)
        fido_msg.save()

        print 'Fido Index after save: {0}'.format(fido_msg.idx)