Beispiel #1
0
def seed(request, key):
    """
    Provide a form to seed, or populate, the libs for a specific spam email.
    The email message is specified by *key*. If the specified email cannot be 
    found, this raises a 404 error.    
    
    :param HttpRequest request: A web request.
    :param string key: The identifier for a specific email.
    :rtype: An HttpResponse object.
    """
    try:
        email = Email.get(key)
    except BadKeyError:
        raise Http404

    email.views += 1
    email.put()

    if request.method == 'GET':
        libs = Lib.all().filter('email =', email).order('position')
        ctx = RequestContext(request, {
            'title': email.title,
            'key': key,
            'libs': libs
        })

        return render_to_response('seed_fields.html', context_instance=ctx)

    ls = []
    for l in request.POST.items():
        ls.append((
            l[0],
            l[1],
            Lib.get(l[0]),
        ))

    ls.sort(cmp=lambda x, y: cmp(x[2].position, y[2].position))

    newbody = ''
    bodyidx = 0
    for l in ls:
        newbody += email.body[bodyidx:l[2].position]
        bodyidx = l[2].position

        newbody += l[1]
        bodyidx += len(l[2].original)

    newbody += email.body[bodyidx:]

    ctx = RequestContext(
        request, {
            'key': key,
            'title': email.title,
            'body': newbody,
            'is_processed': True,
            'views': email.views
        })
    return render_to_response('output_raw.html', context_instance=ctx)
Beispiel #2
0
def seed(request, key):
    """
    Provide a form to seed, or populate, the libs for a specific spam email.
    The email message is specified by *key*. If the specified email cannot be 
    found, this raises a 404 error.    
    
    :param HttpRequest request: A web request.
    :param string key: The identifier for a specific email.
    :rtype: An HttpResponse object.
    """
    try:
        email = Email.get(key)
    except BadKeyError:
        raise Http404
        
    email.views += 1
    email.put()
        
    if request.method == 'GET':
        libs = Lib.all().filter('email =', email).order('position')
        ctx = RequestContext(request, {
            'title':email.title, 
            'key':key,
            'libs':libs
        })
        
        return render_to_response('seed_fields.html', context_instance=ctx)
        
    ls = []
    for l in request.POST.items():
        ls.append( (l[0], l[1], Lib.get(l[0]),) )
        
    ls.sort(cmp=lambda x,y: cmp(x[2].position, y[2].position))
        
    newbody = ''
    bodyidx = 0
    for l in ls:
        newbody += email.body[bodyidx:l[2].position]
        bodyidx = l[2].position
        
        newbody += l[1]
        bodyidx += len(l[2].original)
    
    newbody += email.body[bodyidx:]
        
    ctx = RequestContext(request, {
        'key':key, 
        'title':email.title,
        'body':newbody,
        'is_processed':True,
        'views':email.views
    })
    return render_to_response('output_raw.html', context_instance=ctx)
Beispiel #3
0
def _generate_fields(email, input, tags):
    """
    Generate the terms to swap out, randomly.
    
    :param models.Email email: The input email message.
    :param string input: The input string.
    :param list tags: The tags of the input string.
    """
    input_idx = 0
    for tag in tags:
        if tag[1] in repl_prop and random() < repl_prop[tag[1]]:
            # make a field
            lib = Lib(email=email, original=tag[0], position=input_idx, description=tagdict[tag[1]][0])
            lib.put()
            
        input_idx = input_idx + len(tag[0])
        while input_idx < len(input) and (input[input_idx] == ' ' or input[input_idx] == '\r' or input[input_idx] == '\n'):
            input_idx += 1
Beispiel #4
0
def _generate_fields(email, input, tags):
    """
    Generate the terms to swap out, randomly.
    
    :param models.Email email: The input email message.
    :param string input: The input string.
    :param list tags: The tags of the input string.
    """
    input_idx = 0
    for tag in tags:
        if tag[1] in repl_prop and random() < repl_prop[tag[1]]:
            # make a field
            lib = Lib(email=email,
                      original=tag[0],
                      position=input_idx,
                      description=tagdict[tag[1]][0])
            lib.put()

        input_idx = input_idx + len(tag[0])
        while input_idx < len(input) and (input[input_idx] == ' '
                                          or input[input_idx] == '\r'
                                          or input[input_idx] == '\n'):
            input_idx += 1