File: cmd_vaclog.c

package info (click to toggle)
prayer 1.3.5-dfsg1-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,596 kB
  • sloc: ansic: 43,163; makefile: 817; sh: 445; perl: 166
file content (66 lines) | stat: -rw-r--r-- 2,252 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* $Cambridge: hermes/src/prayer/cmd/cmd_vaclog.c,v 1.3 2008/09/16 09:59:55 dpc22 Exp $ */
/************************************************
 *    Prayer - a Webmail Interface              *
 ************************************************/

/* Copyright (c) University of Cambridge 2000 - 2008 */
/* See the file NOTICE for conditions of use and distribution. */

#include "prayer_session.h"

static void
generate_error(struct session *session)
{
    struct template_vals *tvals = session->template_vals;
    struct account *account = session->account;
    struct request *request = session->request;
    char *msg = account_fetch_message(account);
    struct buffer *b = request->write_buffer;

    if (!(msg && msg[0]))
        msg = "Unable to check mail processing status";

    template_vals_string(tvals, "msg", msg);
    session_seed_template(session, tvals);
    template_expand("vaclog_fail", tvals, b);
    response_html(request, 200);
}

void cmd_vaclog(struct session *session)
{
    struct template_vals *tvals = session->template_vals;
    struct account *account = session->account;
    struct request *request = session->request;
    struct buffer *b = request->write_buffer;
    char *vaclog;

    if (request->method == POST) {
        request_decode_form(request);

        if (assoc_lookup(request->form, "sub_clear")) {
            if (account_vaclog_clear(session->account, request->pool)) {
                session_message(session, "Cleared vacation log");
            } else {
                char *msg = account_fetch_message(session->account);

                session_message(session,
                                "Failed to clear vacation log: %s", msg);
                session_log(session,
                            "[cmd_vaclog] Failed to clear vacation log: %s",
                            msg);
            }
        }
        session_redirect(session, request, "manage");
        return;
    }

    if (!(vaclog = account_vaclog_fetch(account, request->pool))) {
        generate_error(session);
        return;
    }

    template_vals_string(tvals, "vaclog", vaclog);
    session_seed_template(session, tvals);
    template_expand("vaclog", tvals, b);
    response_html(request, 200);        /* Success */
}