Example #1
0
def message_detail(request, id):
    def _decode_header(txt):
        dh = decode_header(txt)
        default_charset = 'ASCII'
        return u''.join([unicode(t[0], t[1] or default_charset) for t in dh])

    message_db = get_object_or_404(Message, id=id)
    if not user_has_access(request, message_db.mailbox.startup):
        return HttpResponseRedirect("/")

    message_obj = email.message_from_string(message_db.email)
    message = {
        "from": message_obj["From"],
        "to": message_obj["To"],
        "cc": message_obj["Cc"],
        "subject": _decode_header(message_obj["Subject"]),
        "date": message_obj["Date"],
        "attachments": message_db.get_attachment_list(),
        "plaintext": "",
        "html": ""
    }

    for part in message_obj.walk():
        if part.get_content_type() == "text/plain":
            message["plaintext"] += part.get_payload(decode=True)
        elif part.get_content_type() == "text/html":
            message["html"] += part.get_payload(decode=True)

    if len(message["plaintext"]) == 0: message["plaintext"] = None
    if len(message["html"]) == 0: message["html"] = None

    return render(request, "messages/message_detail.html", {
        "message_db": message_db,
        "message": message
    })
Example #2
0
def startup_detail(request, id):
    startup = get_object_or_404(Startup, id=id)
    if not user_has_access(request, startup): return HttpResponseRedirect("/")

    messages = Message.objects.filter(
        mailbox__startup=startup).order_by('-created_at')

    return render(request, "messages/startup_detail.html", {
        "startup": startup,
        "messages": messages
    })
Example #3
0
def message_attachment(request, id, attachment_id):
    message_db = get_object_or_404(Message, id=id)
    if not user_has_access(request, message_db.mailbox.startup):
        return HttpResponseRedirect("/")

    attachment = message_db.get_attachment(attachment_id)

    response = HttpResponse(attachment["data"],
                            content_type=attachment["content_type"])

    # TODO: Should be better to escape than remove
    response['Content-Disposition'] = u'filename="{0}"'.format(
        attachment["filename"].replace('"', ''))

    return response
Example #4
0
def startup_list(request):
    startup_list = []

    for startup in Startup.objects.all().annotate(latest_mail=Max(
            'mailbox__message__created_at')).order_by('-latest_mail'):
        if user_has_access(request, startup):
            startup_list.append(startup)

    return render(
        request, "messages/startup_list.html", {
            "startup_list":
            startup_list,
            "warning_date":
            (timezone.now() - datetime.timedelta(days=60)).isoformat()
        })
Example #5
0
def startup_list(request):
    startup_list = []

    for startup in Startup.objects.all().annotate(latest_mail=Max(
            'mailbox__message__created_at')).order_by('-latest_mail'):
        if user_has_access(request, startup):
            startup.authorized_users = StartupPermission.users_allowed(startup)

            startup_list.append({
                "name":
                startup.name,
                "latest_mail":
                naturaltime(startup.latest_mail),
                "latest_mail_isodate":
                startup.latest_mail.isoformat(),
                "authorized_users":
                map(lambda x: x.first_name,
                    StartupPermission.users_allowed(startup)),
                "url":
                reverse("startup_detail", args=(startup.id, ))
            })

    # Convert the startup list in JSON
    if len(startup_list) == 0:
        startup_list = None
    else:
        startup_list = json.dumps(startup_list)

    # Get the search query from GET parameters
    search_query = request.GET.get("search")

    return render(
        request, "messages/startup_list.html", {
            "startup_list":
            startup_list,
            "warning_date":
            (timezone.now() - datetime.timedelta(days=60)).isoformat(),
            "search_query":
            search_query
        })