annotate src/imap/imap-status.c @ 6940:414c9d631a81 HEAD

Replaced t_push/t_pop calls with T_FRAME*() macros.
author Timo Sirainen <tss@iki.fi>
date Wed, 05 Dec 2007 17:47:44 +0200
parents aeee5076f99f
children 7ed926ed7aa4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6429
65c69a53a7be Replaced my Copyright notices. The year range always ends with 2007 now.
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
1 /* Copyright (c) 2002-2007 Dovecot authors, see the included COPYING file */
6016
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "common.h"
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "str.h"
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "imap-quote.h"
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "imap-status.h"
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 int imap_status_parse_items(struct client_command_context *cmd,
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 const struct imap_arg *args,
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 enum mailbox_status_items *items_r)
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 {
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 const char *item;
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 enum mailbox_status_items items;
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 items = 0;
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 for (; args->type != IMAP_ARG_EOL; args++) {
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 if (args->type != IMAP_ARG_ATOM) {
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 /* list may contain only atoms */
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 client_send_command_error(cmd,
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 "Status list contains non-atoms.");
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 return -1;
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 }
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 item = t_str_ucase(IMAP_ARG_STR(args));
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 if (strcmp(item, "MESSAGES") == 0)
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 items |= STATUS_MESSAGES;
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 else if (strcmp(item, "RECENT") == 0)
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 items |= STATUS_RECENT;
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 else if (strcmp(item, "UIDNEXT") == 0)
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 items |= STATUS_UIDNEXT;
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 else if (strcmp(item, "UIDVALIDITY") == 0)
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 items |= STATUS_UIDVALIDITY;
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 else if (strcmp(item, "UNSEEN") == 0)
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 items |= STATUS_UNSEEN;
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 else {
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 client_send_tagline(cmd, t_strconcat(
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 "BAD Invalid status item ", item, NULL));
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 return -1;
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 }
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 }
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 *items_r = items;
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 return 0;
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 }
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 bool imap_status_get(struct client *client, struct mail_storage *storage,
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 const char *mailbox, enum mailbox_status_items items,
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 struct mailbox_status *status_r)
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 {
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 struct mailbox *box;
6463
aeee5076f99f Use mailbox_sync() instead of our own implementation.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
52 int ret;
6016
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 if (client->mailbox != NULL &&
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 mailbox_equals(client->mailbox, storage, mailbox)) {
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 /* this mailbox is selected */
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 box = client->mailbox;
6463
aeee5076f99f Use mailbox_sync() instead of our own implementation.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
58 mailbox_get_status(box, items, status_r);
aeee5076f99f Use mailbox_sync() instead of our own implementation.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
59 return TRUE;
6016
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 }
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61
6463
aeee5076f99f Use mailbox_sync() instead of our own implementation.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
62 /* open the mailbox */
aeee5076f99f Use mailbox_sync() instead of our own implementation.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
63 box = mailbox_open(storage, mailbox, NULL, MAILBOX_OPEN_FAST |
aeee5076f99f Use mailbox_sync() instead of our own implementation.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
64 MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT);
aeee5076f99f Use mailbox_sync() instead of our own implementation.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
65 if (box == NULL)
aeee5076f99f Use mailbox_sync() instead of our own implementation.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
66 return FALSE;
6016
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67
6463
aeee5076f99f Use mailbox_sync() instead of our own implementation.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
68 ret = mailbox_sync(box, 0, items, status_r);
aeee5076f99f Use mailbox_sync() instead of our own implementation.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
69 mailbox_close(&box);
aeee5076f99f Use mailbox_sync() instead of our own implementation.
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
70 return ret == 0;
6016
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 }
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 void imap_status_send(struct client *client, const char *mailbox,
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 enum mailbox_status_items items,
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 const struct mailbox_status *status)
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 {
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 string_t *str;
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 str = t_str_new(128);
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80 str_append(str, "* STATUS ");
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 imap_quote_append_string(str, mailbox, FALSE);
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 str_append(str, " (");
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 if (items & STATUS_MESSAGES)
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 str_printfa(str, "MESSAGES %u ", status->messages);
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 if (items & STATUS_RECENT)
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 str_printfa(str, "RECENT %u ", status->recent);
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 if (items & STATUS_UIDNEXT)
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 str_printfa(str, "UIDNEXT %u ", status->uidnext);
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 if (items & STATUS_UIDVALIDITY)
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 str_printfa(str, "UIDVALIDITY %u ", status->uidvalidity);
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 if (items & STATUS_UNSEEN)
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93 str_printfa(str, "UNSEEN %u ", status->unseen);
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 if (items != 0)
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 str_truncate(str, str_len(str)-1);
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 str_append_c(str, ')');
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 client_send_line(client, str_c(str));
2d815150cf57 Moved STATUS handling code to imap-status.[ch]
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100 }