1 /*
2 * flags.c
3 *
4 * Created on: Oct 6, 2014
5 * Author: James Cassell
6 */
7
8 #ifdef HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include "flags.h"
13 #include "imparse.h"
14 #include "strarray.h"
15 #include "util.h"
16 #include "xmalloc.h"
17
verify_flag(char * f)18 static int verify_flag(char *f)
19 {
20 if (f[0] == '\\') {
21 lcase(f);
22 if (strcmp(f, "\\seen") && strcmp(f, "\\answered") &&
23 strcmp(f, "\\flagged") && strcmp(f, "\\draft") &&
24 strcmp(f, "\\deleted")) {
25 return 0;
26 }
27 return 1;
28 }
29 if (!imparse_isatom(f)) {
30 return 0;
31 }
32 return 1;
33 }
34
verify_flaglist(strarray_t * sl)35 EXPORTED int verify_flaglist(strarray_t *sl)
36 {
37 int i;
38 char *joined;
39 strarray_t *resplit;
40 // Join all the flags, putting spaces between them
41 joined = strarray_join(sl, " ");
42 // Clear out the sl for reuse
43 strarray_truncate(sl, 0);
44 // Split the joined flag list at spaces
45 resplit = strarray_split(joined, " ", STRARRAY_TRIM);
46
47 // Perform duplicate elimination and flag verification
48 for (i = 0; i < resplit->count ; i++) {
49 // has the side effect of lower-casing system flags
50 if (!verify_flag(resplit->data[i])) {
51 /* [IMAP4FLAGS] Section 2 "General Requirements for Flag
52 * Handling" says "If a flag validity check fails, the
53 * flag MUST be ignored", which for us means that we
54 * simply remove the invalid flag from the list.
55 */
56 continue;
57 }
58 strarray_add_case(sl, resplit->data[i]);
59 }
60 strarray_free(resplit);
61 free(joined);
62 return sl->count;
63 }
64