Exemplo n.º 1
0
def is_spam(content, author=None):
    """
    Checks whether the provided content is spam.  Returns a boolean
    denoted a successful call and a SPAM flag which is one of MOLLOM_HAM,
    MOLLOM_SPAM, MOLLOM_UNSURE.

    It is expected that a failure to retrieve a score will force the
    item into moderation. A flag of MOLLOM_SPAM should mark the item as
    not visible and anything else should be published.
    """
    public_key = config.get('mollom.public.key')
    private_key = config.get('mollom.private.key')

    try:
        mollom_api = MollomAPI(publicKey=public_key, privateKey=private_key)

        params = {'postBody': content}
        if author:
            params['authorName'] = author.fullname or ''
            params['authorMail'] = author.email

        cc = mollom_api.checkContent(**params)
    except Exception, e:
        log.warning("Failed to perform a spam check with mollom")
        log.exception(e)
        return False, MOLLOM_UNSURE
Exemplo n.º 2
0
def backend(comment, content_object, request):
    """Mollom spam checker backend for Zinnia"""
    mollom_api = MollomAPI(
        publicKey=MOLLOM_PUBLIC_KEY,
        privateKey=MOLLOM_PRIVATE_KEY)
    if not mollom_api.verifyKey():
        raise MollomFault('Your MOLLOM credentials are invalid.')

    mollom_data = {'authorIP': request.META.get('REMOTE_ADDR', ''),
                   'authorName': smart_str(comment.name),
                   'authorMail': smart_str(comment.email),
                   'authorURL': smart_str(comment.url)}

    cc = mollom_api.checkContent(
        postTitle=smart_str(content_object.title),
        postBody=smart_str(comment.comment), **mollom_data)
    # cc['spam']: 1 for ham, 2 for spam, 3 for unsure;
    # http://mollom.com/blog/spam-vs-ham
    if cc['spam'] == 2:
        return True
    return False