Esempio 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
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
0
def is_spam_mollom(request, form, url):
    def logit(msg):
        if settings.DEBUG:
            logger = logging.getLogger(__name__)
            logger.info(msg)

    settings.use_editable()  # Re-eval setting every time
    if not settings.MOLLOM_PUBLIC_KEY or not settings.MOLLOM_PRIVATE_KEY:
        return False
    else:
        comment = None
        for name, field in form.fields.items():
            if isinstance(field.widget, Textarea):
                comment = form.cleaned_data.get(name)
                break
        if comment is None:
            return False
        else:
            if not settings.MOLLOM_DEFAULT_SERVER:
                mollom_api = MollomAPI(
                    publicKey=str(settings.MOLLOM_PUBLIC_KEY),
                    privateKey=str(settings.MOLLOM_PRIVATE_KEY))
            else:
                mollom_api = MollomAPI(
                    publicKey=str(settings.MOLLOM_PUBLIC_KEY),
                    privateKey=str(settings.MOLLOM_PRIVATE_KEY),
                    defaultServer="http://%s" % settings.MOLLOM_DEFAULT_SERVER)
            if not mollom_api.verifyKey():
                raise MollomFault('Your MOLLOM credentials are invalid.')
            cc = mollom_api.checkContent(postBody=comment)
            if cc['spam'] == 2:
                logit("MOLLOM::SPAM: %s" % comment)
                return True
            elif cc['spam'] == 3:
                logit("MOLLOM::not sure: %s" % comment)
                return False
            else:
                logit("MOLLOM::ham: %s" % comment)
                return False