示例#1
0
def get_dom_crcs(dbsession, user):
    "Calc CRC32 for domains"
    domains = dbsession.query(Domain).join(downs,
                (oa, downs.c.organization_id == oa.c.organization_id))\
                .filter(oa.c.user_id == user.id)
    crcs = []
    for domain in domains:
        crcs.append(crc32(domain.name))
        for domain_alias in domain.aliases:
            if domain_alias.status:
                crcs.append(crc32(domain_alias.name))
    return crcs
示例#2
0
def get_dom_crcs(dbsession, user):
    "Calc CRC32 for domains"
    domains = dbsession.query(Domain).join(downs,
                (oa, downs.c.organization_id == oa.c.organization_id))\
                .filter(oa.c.user_id == user.id)
    crcs = []
    for domain in domains:
        crcs.append(crc32(domain.name))
        for domain_alias in domain.aliases:
            if domain_alias.status:
                crcs.append(crc32(domain_alias.name))
    return crcs
示例#3
0
def filter_sphinx(dbsession, user, conn):
    "Set Sphinx filters"
    if user.is_domain_admin:
        crcs = get_dom_crcs(dbsession, user)
        addrs = ', '.join([str(crc) for crc in crcs])
        select = 'IN(from_dom,%s) OR IN(to_dom,%s) AS cond2' % (addrs, addrs)
        conn.SetSelect(str(select))
        conn.SetFilter('cond2', [1])
    if user.is_peleb:
        crcs = [str(crc32(address.address)) for address in user.addresses]
        crcs.append(str(crc32(user.email)))
        addrs = ', '.join(crcs)
        select = 'IN(from_addr,%s) OR IN(to_addr,%s) AS cond1' % (addrs, addrs)
        conn.SetSelect(str(select))
        conn.SetFilter('cond1', [1])
示例#4
0
文件: query.py 项目: aureg/baruwa2
def filter_sphinx(dbsession, user, conn):
    "Set Sphinx filters"
    if user.is_domain_admin:
        crcs = get_dom_crcs(dbsession, user)
        addrs = ', '.join([str(crc) for crc in crcs])
        select = 'IN(from_dom,%s) OR IN(to_dom,%s) AS cond2' % (addrs, addrs)
        conn.SetSelect(str(select))
        conn.SetFilter('cond2', [1])
    if user.is_peleb:
        crcs = [str(crc32(address.address)) for address in user.addresses]
        crcs.append(str(crc32(user.email)))
        addrs = ', '.join(crcs)
        select = 'IN(from_addr,%s) OR IN(to_addr,%s) AS cond1' % (addrs, addrs)
        conn.SetSelect(str(select))
        conn.SetFilter('cond1', [1])
示例#5
0
def get_dom_crcs(dbsession, user):
    "Calc CRC32 for domains"
    domains = dbsession.query(Domain.name).join(downs,
                (oa, downs.c.organization_id == oa.c.organization_id))\
                .filter(oa.c.user_id == user.id)
    crcs = [crc32(domain[0]) for domain in domains]
    return crcs
示例#6
0
文件: query.py 项目: TetraAsh/baruwa2
def get_dom_crcs(dbsession, user):
    "Calc CRC32 for domains"
    domains = dbsession.query(Domain.name).join(downs,
                (oa, downs.c.organization_id == oa.c.organization_id))\
                .filter(oa.c.user_id == user.id)
    crcs = [crc32(domain[0]) for domain in domains]
    return crcs
示例#7
0
def get_tagged_addrs(user):
    """Generate a list of tagged addresses for a user"""
    query1 = Session.query(Message.to_address)
    query2 = Session.query(Message.from_address)
    addrs = [addr.address for addr in user.addresses
            if '+*' not in addr.address and '-*' not in addr.address]
    addrs.append(user.email)
    tagged_addrs = [addr.address for addr in user.addresses
            if '+*' in addr.address or '-*' in addr.address]
    if tagged_addrs:
        tagged_opts1 = func._(or_(*[Message.to_address
                            .like(TAGGED_RE.sub(r'\g<one>%', taddr))
                        for taddr in tagged_addrs]))
        tagged_opts2 = func._(or_(*[Message.from_address
                            .like(TAGGED_RE.sub(r'\g<one>%', taddr))
                        for taddr in tagged_addrs]))
        query1 = query1.filter(func._(
                        or_(tagged_opts1, Message.to_address.in_(addrs))))
        query2 = query2.filter(func._(
                        or_(tagged_opts2, Message.from_address.in_(addrs))))
    else:
        query1 = query1.filter(Message.to_address.in_(addrs))
        query2 = query2.filter(Message.from_address.in_(addrs))
    query1 = query1.distinct()
    query2 = query2.distinct()
    to_addrs = [val.to_address for val in query1]
    from_addrs = [val.from_address for val in query2]
    all_addrs = set(to_addrs + from_addrs)
    return [str(crc32(val)) for val in all_addrs]
示例#8
0
def get_tagged_addrs(user):
    """Generate a list of tagged addresses for a user"""
    query1 = Session.query(Message.to_address)
    query2 = Session.query(Message.from_address)
    addrs = [
        addr.address for addr in user.addresses
        if '+*' not in addr.address and '-*' not in addr.address
    ]
    addrs.append(user.email)
    tagged_addrs = [
        addr.address for addr in user.addresses
        if '+*' in addr.address or '-*' in addr.address
    ]
    if tagged_addrs:
        tagged_opts1 = func._(
            or_(*[
                Message.to_address.like(TAGGED_RE.sub(r'\g<one>%', taddr))
                for taddr in tagged_addrs
            ]))
        tagged_opts2 = func._(
            or_(*[
                Message.from_address.like(TAGGED_RE.sub(r'\g<one>%', taddr))
                for taddr in tagged_addrs
            ]))
        query1 = query1.filter(
            func._(or_(tagged_opts1, Message.to_address.in_(addrs))))
        query2 = query2.filter(
            func._(or_(tagged_opts2, Message.from_address.in_(addrs))))
    else:
        query1 = query1.filter(Message.to_address.in_(addrs))
        query2 = query2.filter(Message.from_address.in_(addrs))
    query1 = query1.distinct()
    query2 = query2.distinct()
    to_addrs = [val.to_address for val in query1]
    from_addrs = [val.from_address for val in query2]
    all_addrs = set(to_addrs + from_addrs)
    return [str(crc32(val)) for val in all_addrs]