summaryrefslogtreecommitdiffstats
path: root/pigeonhole/src/managesieve/cmd-capability.c
blob: 1d26eb52e1e6c9c2a427428d59291fe406454743 (plain)
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
67
68
69
70
71
72
73
74
75
76
/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file
 */

#include "lib.h"
#include "str.h"
#include "strfuncs.h"
#include "ostream.h"

#include "sieve.h"

#include "managesieve-common.h"
#include "managesieve-commands.h"

static void send_capability(struct client_command_context *cmd)
{
	struct client *client = cmd->client;
	const char *sievecap, *notifycap;
	unsigned int max_redirects;

	/* Get capabilities */
	sievecap = sieve_get_capabilities(client->svinst, NULL);
	notifycap = sieve_get_capabilities(client->svinst, "notify");
	max_redirects = sieve_max_redirects(client->svinst);

	/* Default capabilities */
	client_send_line(client,
		t_strconcat(
			"\"IMPLEMENTATION\" \"",
			client->set->managesieve_implementation_string,
			"\"", NULL));
	client_send_line(client,
		t_strconcat(
			"\"SIEVE\" \"",
			(sievecap == NULL ? "" : sievecap),
			"\"", NULL));

	/* Maximum number of redirects (if limited) */
	if (max_redirects > 0) {
		client_send_line(client,
			t_strdup_printf("\"MAXREDIRECTS\" \"%u\"",
					max_redirects));
	}

	/* Notify methods */
	if (notifycap != NULL) {
		client_send_line(client,
			t_strconcat("\"NOTIFY\" \"", notifycap, "\"",
				    NULL));
	}

	/* Protocol version */
	client_send_line(client, "\"VERSION\" \"1.0\"");
}

bool cmd_capability(struct client_command_context *cmd)
{
	struct client *client = cmd->client;

	/* no arguments */
	if (!client_read_no_args(cmd))
		return FALSE;

	o_stream_cork(client->output);

	T_BEGIN {
		send_capability(cmd);
	} T_END;

	client_send_line(client, "OK \"Capability completed.\"");

	o_stream_uncork(client->output);

	return TRUE;

}