Beispiel #1
0
def post(request):
    """ Add in a post """
    log("Processing email message")
    mailobj = mail.InboundEmailMessage(request.raw_post_data)
    to = mailobj.to

    if to in settings.ALLOWED_RECEIVING_ADDRESSES:
        key = settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER
    else:
        key = to.split("-", 1)[1].split("@")[0]
        if key != settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER:
            log("To address (%s, to %s) does not match account number (%s)" % (key, to, settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER))
            return        

    for content_type, body in mailobj.bodies("text/plain"):
        if mailobj.subject.find(" Broken ") > -1:
            log("Trying to parse body using 404 parser")
            result = parse_404(body, mailobj.subject)
        else:
            log("Trying to parse body using 500 parser")
            result = parse_500(body, mailobj.subject)
        err = Error()
        result["account"] = key
        populate(err, result)

    return render_plain("message parsed")
Beispiel #2
0
def post(request):
    """ Add in a post """
    log("Processing email message")
    mailobj = mail.InboundEmailMessage(request.raw_post_data)
    to = mailobj.to

    if to in settings.ALLOWED_RECEIVING_ADDRESSES:
        key = settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER
    else:
        key = to.split("-", 1)[1].split("@")[0]
        if key != settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER:
            log("To address (%s, to %s) does not match account number (%s)" %
                (key, to, settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER))
            return

    for content_type, body in mailobj.bodies("text/plain"):
        if mailobj.subject.find(" Broken ") > -1:
            log("Trying to parse body using 404 parser")
            result = parse_404(body, mailobj.subject)
        else:
            log("Trying to parse body using 500 parser")
            result = parse_500(body, mailobj.subject)
        err = Error()
        result["account"] = key
        populate(err, result)

    return render_plain("message parsed")
Beispiel #3
0
 def test_post_no_key(self):
     settings.ANONYMOUS_POSTING = True
     acc = settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER
     post.populate({'account': acc})
     assert(Error.objects.count() == 1)
     post.populate({})
     assert(Error.objects.count() == 2)
     settings.ANONYMOUS_POSTING = False
Beispiel #4
0
def post(request):
    """ Add in a post """
    err = Error()
    err.ip = request.META.get("REMOTE_ADDR", "")
    err.user_agent = request.META.get("HTTP_USER_AGENT", "")

    populate(err, request.POST)
    return render_plain("Error recorded")
Beispiel #5
0
 def test_post_no_key(self):
     settings.ANONYMOUS_POSTING = True
     acc = settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER
     post.populate({'account': acc})
     assert(Error.objects.count() == 1)
     post.populate({})
     assert(Error.objects.count() == 2)
     settings.ANONYMOUS_POSTING = False
Beispiel #6
0
def post(request):
    """ Add in a post """
    err = Error()
    err.ip = request.META.get("REMOTE_ADDR", "")
    err.user_agent = request.META.get("HTTP_USER_AGENT", "")

    populate(err, request.POST)
    return render_plain("Error recorded")
Beispiel #7
0
def post(request):
    """ Add in a post """
    data = request.POST.copy()
    if "ip" not in data:
        data["ip"] = request.META.get("REMOTE_ADDR", "")
    if "user_agent" not in data:
        data["user_agent"] = request.META.get("HTTP_USER_AGENT", "")
    populate(data)#.delay(data)
    return render_plain("Error recorded")
Beispiel #8
0
def parse(content_type, body):
    data = body.decode()
    if data.rfind("}") > 0:
        # strip out any crap on the end
        end = data.rfind("}")
        # not sure why i was doing this, i'm sure there
        # was a good reason at one point
        text = data[:end] + "}"
        err = Error()
        json = loads(text, strict=False)
        populate(err, json)
        return True
Beispiel #9
0
def parse(content_type, body):
    data = body.decode()
    if data.rfind("}") > 0:
        # strip out any crap on the end
        end = data.rfind("}")
        # not sure why i was doing this, i'm sure there
        # was a good reason at one point
        text = data[:end] + "}"
        err = Error()
        json = loads(text, strict=False)
        populate(err, json)
        return True
Beispiel #10
0
 def test_post_key(self):
     acc = settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER
     post.populate({'account': acc})
     assert(Error.objects.count() == 1)
     self.assertRaises(ValueError, post.populate, {'account': acc + "a"})
Beispiel #11
0
 def test_post_key(self):
     settings.ANONYMOUS_POSTING = False
     acc = settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER
     post.populate({'account': acc})
     assert(Error.objects.count() == 1)
     self.assertRaises(ValueError, post.populate, {'account': acc + "a"})