1 /* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file
2  */
3 
4 #include "lib.h"
5 #include "str.h"
6 #include "strfuncs.h"
7 #include "ostream.h"
8 
9 #include "sieve.h"
10 
11 #include "managesieve-common.h"
12 #include "managesieve-commands.h"
13 
send_capability(struct client_command_context * cmd)14 static void send_capability(struct client_command_context *cmd)
15 {
16 	struct client *client = cmd->client;
17 	const char *sievecap, *notifycap;
18 	unsigned int max_redirects;
19 
20 	/* Get capabilities */
21 	sievecap = sieve_get_capabilities(client->svinst, NULL);
22 	notifycap = sieve_get_capabilities(client->svinst, "notify");
23 	max_redirects = sieve_max_redirects(client->svinst);
24 
25 	/* Default capabilities */
26 	client_send_line(client,
27 		t_strconcat(
28 			"\"IMPLEMENTATION\" \"",
29 			client->set->managesieve_implementation_string,
30 			"\"", NULL));
31 	client_send_line(client,
32 		t_strconcat(
33 			"\"SIEVE\" \"",
34 			(sievecap == NULL ? "" : sievecap),
35 			"\"", NULL));
36 
37 	/* Maximum number of redirects (if limited) */
38 	if (max_redirects > 0) {
39 		client_send_line(client,
40 			t_strdup_printf("\"MAXREDIRECTS\" \"%u\"",
41 					max_redirects));
42 	}
43 
44 	/* Notify methods */
45 	if (notifycap != NULL) {
46 		client_send_line(client,
47 			t_strconcat("\"NOTIFY\" \"", notifycap, "\"",
48 				    NULL));
49 	}
50 
51 	/* Protocol version */
52 	client_send_line(client, "\"VERSION\" \"1.0\"");
53 }
54 
cmd_capability(struct client_command_context * cmd)55 bool cmd_capability(struct client_command_context *cmd)
56 {
57 	struct client *client = cmd->client;
58 
59 	/* no arguments */
60 	if (!client_read_no_args(cmd))
61 		return FALSE;
62 
63 	o_stream_cork(client->output);
64 
65 	T_BEGIN {
66 		send_capability(cmd);
67 	} T_END;
68 
69 	client_send_line(client, "OK \"Capability completed.\"");
70 
71 	o_stream_uncork(client->output);
72 
73 	return TRUE;
74 
75 }
76 
77