Commit 4d68dc11 4d68dc112dfd2c8213b5448c1c6038a374fe12eb by Alain Magloire

Implemented STORE in IMAP4

1 parent 7401733c
1 2001-04-25 Alain Magloire
2
3 * imap4d/store.c: First implementation.
4 * mailbox/attribute.c (attribute_unsee_flags): New function.
5
1 2001-04-23 Sergey Poznyakoff 6 2001-04-23 Sergey Poznyakoff
2 7
3 * mailbox/mbx_mbox.c (mbx_expunge): It assumes that mbox_get_message() 8 * mailbox/mbx_mbox.c (mbx_expunge): It assumes that mbox_get_message()
......
...@@ -41,12 +41,8 @@ imap4d_status (struct imap4d_command *command, char *arg) ...@@ -41,12 +41,8 @@ imap4d_status (struct imap4d_command *command, char *arg)
41 return util_finish (command, RESP_BAD, "Wrong state"); 41 return util_finish (command, RESP_BAD, "Wrong state");
42 42
43 name = util_getword (arg, &sp); 43 name = util_getword (arg, &sp);
44 if (!name || !sp)
45 return util_finish (command, RESP_BAD, "Too few args");
46
47 util_unquote (&name); 44 util_unquote (&name);
48 45 if (!name || *name == '\0' || !sp || *sp == '\0')
49 if (*name == '\0' || *sp == '\0')
50 return util_finish (command, RESP_BAD, "Too few args"); 46 return util_finish (command, RESP_BAD, "Too few args");
51 47
52 if (strcasecmp (name, "INBOX") == 0) 48 if (strcasecmp (name, "INBOX") == 0)
......
...@@ -20,11 +20,131 @@ ...@@ -20,11 +20,131 @@
20 /* 20 /*
21 * Now you're messing with a sumbitch 21 * Now you're messing with a sumbitch
22 */ 22 */
23 static int get_attribute_type __P ((const char *, int *));
23 24
24 int 25 int
25 imap4d_store (struct imap4d_command *command, char *arg) 26 imap4d_store (struct imap4d_command *command, char *arg)
26 { 27 {
28 char *msgset;
29 char *data;
30 char *sp = NULL;
31 int status;
32 int ack = 0;
33 size_t i, n = 0;
34 int *set = NULL;
35 enum value_type { STORE_SET, STORE_ADD, STORE_UNSET } how;
36
27 if (! (command->states & state)) 37 if (! (command->states & state))
28 return util_finish (command, RESP_BAD, "Wrong state"); 38 return util_finish (command, RESP_BAD, "Wrong state");
29 return util_finish (command, RESP_NO, "Not supported"); 39
40 msgset = util_getword (arg, &sp);
41 data = util_getword (NULL, &sp);
42
43 if (!msgset || !data || !sp || *sp == '\0')
44 return util_finish (command, RESP_BAD, "Too few args");
45
46 /* The parsing of the data-item is a little slugish. */
47 if (strcasecmp (data, "FLAGS") == 0)
48 {
49 ack = 1;
50 how = STORE_SET;
51 }
52 else if (strcasecmp (data, "+FLAGS") == 0)
53 {
54 ack = 1;
55 how = STORE_ADD;
56 }
57 else if (strcasecmp (data, "-FLAGS") == 0)
58 {
59 ack = 1;
60 how = STORE_UNSET;
61 }
62 else if (strcasecmp (data, "FLAGS.SILENT") == 0)
63 {
64 ack = 0;
65 how = STORE_SET;
66 }
67 else if (strcasecmp (data, "+FLAGS.SILENT") == 0)
68 {
69 ack = 0;
70 how = STORE_ADD;
71 }
72 else if (strcasecmp (data, "-FLAGS.SILENT") == 0)
73 {
74 ack = 0;
75 how = STORE_UNSET;
76 }
77 else
78 return util_finish (command, RESP_BAD, "Bogus data item");
79
80 /* Get the message numbers in set[]. */
81 status = util_msgset (msgset, &set, &n, 0);
82 if (status != 0)
83 return util_finish (command, RESP_BAD, "Bogus number set");
84
85 for (i = 0; i < n; i++)
86 {
87 message_t msg = NULL;
88 attribute_t attr = NULL;
89 char *items = strdup (sp); /* Don't use the orignal list. */
90 char *flags = strdup ("");
91 int first = 1;
92
93 mailbox_get_message (mbox, set[i], &msg);
94 message_get_attribute (msg, &attr);
95
96 /* Get the fetch command names. */
97 while (*items && *items != ')')
98 {
99 int type = 0;
100 char item[64] = "";
101 util_token (item, sizeof (item), &items);
102 if (get_attribute_type (item, &type))
103 {
104 if (how == STORE_ADD )
105 attribute_set_flags (attr, type);
106 else if (how == STORE_UNSET )
107 attribute_unset_flags (attr, type);
108 else if (how == STORE_SET )
109 {
110 if (first)
111 {
112 attribute_set_flags (attr, 0);
113 first = 0;
114 }
115 attribute_set_flags (attr, type);
116 }
117 flags = realloc (flags, strlen (flags) + strlen (item) + 2);
118 if (*flags)
119 strcat (flags, " ");
120 strcat (flags, item);
121 }
122 }
123 if (ack && *flags)
124 util_out (RESP_NONE, "%d FETCH FLAGS (%s)", set[i], flags);
125 free (items);
126 free (flags);
127 }
128 free (set);
129 return util_finish (command, RESP_OK, "Completed");
130 }
131
132 static int
133 get_attribute_type (const char *item, int *type)
134 {
135 if (strcasecmp (item, "\\Answered") == 0)
136 *type = MU_ATTRIBUTE_ANSWERED;
137 else if (strcasecmp (item, "\\Deleted") == 0)
138 *type = MU_ATTRIBUTE_DELETED;
139 else if (strcasecmp (item, "\\Draft") == 0)
140 *type = MU_ATTRIBUTE_DRAFT;
141 else if (strcasecmp (item, "\\Flagged") == 0)
142 *type = MU_ATTRIBUTE_FLAGGED;
143 else if (strcasecmp (item, "\\Recent") == 0)
144 *type = MU_ATTRIBUTE_RECENT;
145 else if (strcasecmp (item, "\\Seen") == 0)
146 *type = MU_ATTRIBUTE_SEEN;
147 else
148 return 0;
149 return 1;
30 } 150 }
......
...@@ -79,6 +79,7 @@ extern int attribute_unset_read __P ((attribute_t)); ...@@ -79,6 +79,7 @@ extern int attribute_unset_read __P ((attribute_t));
79 79
80 extern int attribute_get_flags __P ((attribute_t, int *)); 80 extern int attribute_get_flags __P ((attribute_t, int *));
81 extern int attribute_set_flags __P ((attribute_t, int)); 81 extern int attribute_set_flags __P ((attribute_t, int));
82 extern int attribute_unset_flags __P ((attribute_t, int));
82 83
83 extern int attribute_set_set_flags __P ((attribute_t, int (*_set_flags) 84 extern int attribute_set_set_flags __P ((attribute_t, int (*_set_flags)
84 __P ((attribute_t, int)), void *)); 85 __P ((attribute_t, int)), void *));
......
...@@ -102,6 +102,17 @@ attribute_set_flags (attribute_t attr, int flags) ...@@ -102,6 +102,17 @@ attribute_set_flags (attribute_t attr, int flags)
102 } 102 }
103 103
104 int 104 int
105 attribute_unset_flags (attribute_t attr, int flags)
106 {
107 if (attr == NULL)
108 return EINVAL;
109 if (attr->_unset_flags)
110 attr->_unset_flags (attr, flags);
111 attr->flags &= ~flags;
112 return 0;
113 }
114
115 int
105 attribute_set_get_flags (attribute_t attr, int (*_get_flags) 116 attribute_set_get_flags (attribute_t attr, int (*_get_flags)
106 (attribute_t, int *), void *owner) 117 (attribute_t, int *), void *owner)
107 { 118 {
......