annotate src/imap/cmd-list.c @ 5807:ec09ad1d017f HEAD

mailbox_list_iter_next() returns now const pointer.
author Timo Sirainen <tss@iki.fi>
date Wed, 27 Jun 2007 17:00:32 +0300
parents 3704fe78f2f9
children 45735dd11f17
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
1 /* Copyright (C) 2002-2004 Timo Sirainen */
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "common.h"
1329
ae229b7acb4c Mailbox names are now sent through imap-quoter instead of just escaping it.
Timo Sirainen <tss@iki.fi>
parents: 1310
diff changeset
4 #include "str.h"
896
21ffcce83c70 Rewrote rfc822-tokenize.c to work one token at a time so it won't uselessly
Timo Sirainen <tss@iki.fi>
parents: 886
diff changeset
5 #include "strescape.h"
1329
ae229b7acb4c Mailbox names are now sent through imap-quoter instead of just escaping it.
Timo Sirainen <tss@iki.fi>
parents: 1310
diff changeset
6 #include "imap-quote.h"
1218
a70ebd3a59e2 Removed list-sort workarounds. It's pretty much needed for maildir listing.
Timo Sirainen <tss@iki.fi>
parents: 1198
diff changeset
7 #include "imap-match.h"
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "commands.h"
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5438
diff changeset
9 #include "mail-namespace.h"
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10
1895
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
11 enum {
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
12 _MAILBOX_LIST_ITER_HIDE_CHILDREN = 0x1000000,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
13 _MAILBOX_LIST_ITER_LISTEXT = 0x0800000
1895
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
14 };
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
15
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
16 struct cmd_list_context {
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
17 const char *ref;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
18 const char *mask;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
19 enum mailbox_list_flags list_flags;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
20
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5438
diff changeset
21 struct mail_namespace *ns;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
22 struct mailbox_list_iterate_context *list_iter;
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
23 struct imap_match_glob *glob;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
24
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
25 unsigned int lsub:1;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
26 unsigned int inbox_found:1;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
27 unsigned int match_inbox:1;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
28 };
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
29
5314
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
30 static void
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
31 mailbox_flags2str(string_t *str, enum mailbox_info_flags flags,
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
32 enum mailbox_list_flags list_flags)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 {
5339
469799904802 Last change caused LIST replies to have extra spaces
Timo Sirainen <tss@iki.fi>
parents: 5314
diff changeset
34 unsigned int orig_len = str_len(str);
469799904802 Last change caused LIST replies to have extra spaces
Timo Sirainen <tss@iki.fi>
parents: 5314
diff changeset
35
1895
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
36 if ((flags & MAILBOX_NONEXISTENT) != 0 &&
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
37 (list_flags & _MAILBOX_LIST_ITER_LISTEXT) == 0) {
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
38 flags |= MAILBOX_NOSELECT;
1895
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
39 flags &= ~MAILBOX_NONEXISTENT;
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
40 }
1218
a70ebd3a59e2 Removed list-sort workarounds. It's pretty much needed for maildir listing.
Timo Sirainen <tss@iki.fi>
parents: 1198
diff changeset
41
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
42 if ((list_flags & _MAILBOX_LIST_ITER_HIDE_CHILDREN) != 0)
1748
588326f1cd84 If LISTEXT is used and CHILDREN info isn't wanted, don't send it.
Timo Sirainen <tss@iki.fi>
parents: 1657
diff changeset
43 flags &= ~(MAILBOX_CHILDREN|MAILBOX_NOCHILDREN);
588326f1cd84 If LISTEXT is used and CHILDREN info isn't wanted, don't send it.
Timo Sirainen <tss@iki.fi>
parents: 1657
diff changeset
44
5314
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
45 if ((flags & MAILBOX_NOSELECT) != 0)
5339
469799904802 Last change caused LIST replies to have extra spaces
Timo Sirainen <tss@iki.fi>
parents: 5314
diff changeset
46 str_append(str, "\\Noselect ");
5314
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
47 if ((flags & MAILBOX_NONEXISTENT) != 0)
5339
469799904802 Last change caused LIST replies to have extra spaces
Timo Sirainen <tss@iki.fi>
parents: 5314
diff changeset
48 str_append(str, "\\NonExistent ");
5314
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
49 if ((flags & MAILBOX_CHILDREN) != 0)
5339
469799904802 Last change caused LIST replies to have extra spaces
Timo Sirainen <tss@iki.fi>
parents: 5314
diff changeset
50 str_append(str, "\\HasChildren ");
5314
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
51 if ((flags & MAILBOX_NOCHILDREN) != 0)
5339
469799904802 Last change caused LIST replies to have extra spaces
Timo Sirainen <tss@iki.fi>
parents: 5314
diff changeset
52 str_append(str, "\\HasNoChildren ");
5314
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
53 if ((flags & MAILBOX_NOINFERIORS) != 0)
5339
469799904802 Last change caused LIST replies to have extra spaces
Timo Sirainen <tss@iki.fi>
parents: 5314
diff changeset
54 str_append(str, "\\NoInferiors ");
5314
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
55 if ((flags & MAILBOX_MARKED) != 0)
5339
469799904802 Last change caused LIST replies to have extra spaces
Timo Sirainen <tss@iki.fi>
parents: 5314
diff changeset
56 str_append(str, "\\Marked ");
5314
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
57 if ((flags & MAILBOX_UNMARKED) != 0)
5339
469799904802 Last change caused LIST replies to have extra spaces
Timo Sirainen <tss@iki.fi>
parents: 5314
diff changeset
58 str_append(str, "\\UnMarked ");
469799904802 Last change caused LIST replies to have extra spaces
Timo Sirainen <tss@iki.fi>
parents: 5314
diff changeset
59
469799904802 Last change caused LIST replies to have extra spaces
Timo Sirainen <tss@iki.fi>
parents: 5314
diff changeset
60 if (str_len(str) != orig_len)
469799904802 Last change caused LIST replies to have extra spaces
Timo Sirainen <tss@iki.fi>
parents: 5314
diff changeset
61 str_truncate(str, str_len(str)-1);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3856
diff changeset
64 static bool
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
65 parse_list_flags(struct client_command_context *cmd, struct imap_arg *args,
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
66 enum mailbox_list_flags *list_flags)
1198
d28571e8c810 Rewrote LIST, LSUB and subscription file handling. LIST replies aren't
Timo Sirainen <tss@iki.fi>
parents: 1183
diff changeset
67 {
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
68 const char *atom;
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
69
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
70 while (args->type != IMAP_ARG_EOL) {
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
71 if (args->type != IMAP_ARG_ATOM) {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
72 client_send_command_error(cmd,
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
73 "List options contains non-atoms.");
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
74 return FALSE;
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
75 }
1198
d28571e8c810 Rewrote LIST, LSUB and subscription file handling. LIST replies aren't
Timo Sirainen <tss@iki.fi>
parents: 1183
diff changeset
76
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
77 atom = IMAP_ARG_STR(args);
1198
d28571e8c810 Rewrote LIST, LSUB and subscription file handling. LIST replies aren't
Timo Sirainen <tss@iki.fi>
parents: 1183
diff changeset
78
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
79 if (strcasecmp(atom, "SUBSCRIBED") == 0)
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
80 *list_flags |= MAILBOX_LIST_ITER_SUBSCRIBED;
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
81 else if (strcasecmp(atom, "CHILDREN") == 0)
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
82 *list_flags |= MAILBOX_LIST_ITER_CHILDREN;
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
83 else {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
84 client_send_tagline(cmd, t_strconcat(
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
85 "BAD Invalid list option ", atom, NULL));
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
86 return FALSE;
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
87 }
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
88 args++;
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
89 }
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
90 return TRUE;
1198
d28571e8c810 Rewrote LIST, LSUB and subscription file handling. LIST replies aren't
Timo Sirainen <tss@iki.fi>
parents: 1183
diff changeset
91 }
d28571e8c810 Rewrote LIST, LSUB and subscription file handling. LIST replies aren't
Timo Sirainen <tss@iki.fi>
parents: 1183
diff changeset
92
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
93 static void
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
94 list_namespace_inbox(struct client *client, struct cmd_list_context *ctx)
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
95 {
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
96 const char *str;
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
97
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
98 if (!ctx->inbox_found && ctx->ns->inbox && ctx->match_inbox &&
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
99 (ctx->list_flags & MAILBOX_LIST_ITER_SUBSCRIBED) == 0) {
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
100 /* INBOX always exists */
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
101 str = t_strdup_printf("* LIST (\\Unmarked) \"%s\" \"INBOX\"",
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
102 ctx->ns->sep_str);
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
103 client_send_line(client, str);
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
104 }
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
105 }
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
106
5806
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
107 static bool
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
108 list_insert_ns_prefix(string_t *name_str, struct cmd_list_context *ctx,
5807
ec09ad1d017f mailbox_list_iter_next() returns now const pointer.
Timo Sirainen <tss@iki.fi>
parents: 5806
diff changeset
109 const struct mailbox_info *info)
5806
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
110 {
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
111 if (strcasecmp(info->name, "INBOX") != 0) {
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
112 /* non-INBOX always has prefix */
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
113 } else if (!ctx->ns->inbox) {
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
114 /* INBOX from non-INBOX namespace. */
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
115 if (*ctx->ns->prefix == '\0') {
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
116 /* no namespace prefix, we can't list this */
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
117 return FALSE;
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
118 }
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
119 } else if (!ctx->match_inbox) {
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
120 /* The mask doesn't match INBOX (eg. prefix.%).
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
121 We still want to list prefix.INBOX if it has
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
122 children. Otherwise we don't want to list
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
123 this INBOX at all. */
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
124 if ((info->flags & MAILBOX_CHILDREN) == 0)
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
125 return FALSE;
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
126 } else {
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
127 /* Listing INBOX from inbox=yes namespace.
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
128 Don't insert the namespace prefix. */
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
129 return TRUE;
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
130 }
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
131 str_append(name_str, ctx->ns->prefix);
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
132 return TRUE;
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
133 }
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
134
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
135 static int
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
136 list_namespace_mailboxes(struct client *client, struct cmd_list_context *ctx)
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
137 {
5807
ec09ad1d017f mailbox_list_iter_next() returns now const pointer.
Timo Sirainen <tss@iki.fi>
parents: 5806
diff changeset
138 const struct mailbox_info *info;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
139 const char *name;
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
140 string_t *str, *name_str;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
141 int ret = 0;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
142
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
143 if (ctx->list_iter == NULL) {
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
144 list_namespace_inbox(client, ctx);
2537
5c95f17f6f25 Fix for having INBOX/ namespace.
Timo Sirainen <tss@iki.fi>
parents: 2425
diff changeset
145 return 1;
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
146 }
2537
5c95f17f6f25 Fix for having INBOX/ namespace.
Timo Sirainen <tss@iki.fi>
parents: 2425
diff changeset
147
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
148 t_push();
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
149 str = t_str_new(256);
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
150 name_str = t_str_new(256);
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
151 while ((info = mailbox_list_iter_next(ctx->list_iter)) != NULL) {
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
152 str_truncate(name_str, 0);
5806
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
153
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
154 if (!list_insert_ns_prefix(name_str, ctx, info))
3704fe78f2f9 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5803
diff changeset
155 continue;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
156 str_append(name_str, info->name);
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
157
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
158 if (ctx->ns->sep != ctx->ns->real_sep) {
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
159 char *p = str_c_modifiable(name_str);
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
160 for (; *p != '\0'; p++) {
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
161 if (*p == ctx->ns->real_sep)
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
162 *p = ctx->ns->sep;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
163 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
164 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
165 name = str_c(name_str);
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
166
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
167 if (*ctx->ns->prefix != '\0') {
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
168 /* With masks containing '*' we do the checks here
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
169 so prefix is included in matching */
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
170 if (ctx->glob != NULL &&
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
171 imap_match(ctx->glob, name) != IMAP_MATCH_YES)
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
172 continue;
4639
47531abcf691 Handle INBOX-prefixed namespaces better. Avoid duplicate INBOX replies if
Timo Sirainen <tss@iki.fi>
parents: 4546
diff changeset
173 }
47531abcf691 Handle INBOX-prefixed namespaces better. Avoid duplicate INBOX replies if
Timo Sirainen <tss@iki.fi>
parents: 4546
diff changeset
174 if (strcasecmp(name, "INBOX") == 0) {
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
175 if (!ctx->ns->inbox)
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
176 continue;
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
177
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
178 name = "INBOX";
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
179 ctx->inbox_found = TRUE;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
180 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
181
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
182 str_truncate(str, 0);
5314
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
183 str_printfa(str, "* %s (", ctx->lsub ? "LSUB" : "LIST");
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
184 mailbox_flags2str(str, info->flags, ctx->list_flags);
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
185 str_printfa(str, ") \"%s\" ", ctx->ns->sep_str);
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
186 imap_quote_append_string(str, name, FALSE);
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
187 if (client_send_line(client, str_c(str)) == 0) {
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
188 /* buffer is full, continue later */
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
189 t_pop();
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
190 return 0;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
191 }
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
192 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
193
5611
44db6ddd5a17 Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents: 5571
diff changeset
194 if (mailbox_list_iter_deinit(&ctx->list_iter) < 0)
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
195 ret = -1;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
196
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
197 if (ret == 0)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
198 list_namespace_inbox(client, ctx);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
199
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
200 t_pop();
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
201 return ret < 0 ? -1 : 1;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
202 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
203
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
204 static bool list_mask_has_wildcards(const char *mask)
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
205 {
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
206 for (; *mask != '\0'; mask++) {
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
207 if (*mask == '%' || *mask == '*')
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
208 return TRUE;
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
209 }
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
210 return FALSE;
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
211 }
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
212
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
213 static void
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
214 skip_namespace_prefix(const char **prefix, const char **mask,
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
215 bool inbox_check, char sep)
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
216 {
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
217 size_t mask_len, prefix_len;
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3856
diff changeset
218 bool match;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
219
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
220 prefix_len = strlen(*prefix);
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
221 mask_len = strlen(*mask);
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
222
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
223 if (mask_len < prefix_len) {
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
224 /* eg. namespace prefix = "INBOX.", mask = "INBOX" */
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
225 return;
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
226 }
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
227
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
228 match = strncmp(*prefix, *mask, prefix_len) == 0;
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
229 if (!match && inbox_check) {
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
230 /* try INBOX check. */
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
231 match = prefix_len >= 5 &&
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
232 strncasecmp(*prefix, *mask, 5) == 0 &&
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
233 strncmp(*prefix + 5, *mask + 5, prefix_len - 5) == 0 &&
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
234 strncasecmp(*prefix, "INBOX", 5) == 0 &&
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
235 ((*prefix)[5] == sep || (*prefix)[5] == '\0');
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
236 }
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
237
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
238 if (match) {
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
239 *prefix += prefix_len;
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
240 *mask += prefix_len;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
241 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
242 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
243
5803
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
244 static bool
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
245 skip_namespace_prefix_refmask(struct cmd_list_context *ctx,
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
246 const char **cur_ns_prefix_r,
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
247 const char **cur_ref_r, const char **cur_mask_r)
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
248 {
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
249 const char *cur_ns_prefix, *cur_ref, *cur_mask;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
250
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
251 if (*ctx->ns->prefix == '\0')
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
252 return TRUE;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
253
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
254 cur_ns_prefix = ctx->ns->prefix;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
255 cur_ref = ctx->ref;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
256 cur_mask = ctx->mask;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
257
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
258 if (*cur_ref != '\0') {
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
259 /* reference argument given. skip namespace prefix using it.
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
260
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
261 cur_ns_prefix = foo/bar/
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
262 cur_ref = foo/
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
263 -> cur_ns_prefix=bar/, cur_ref=""
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
264 cur_ref = foo/bar/baz
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
265 -> cur_ns_prefix="", cur_ref="baz"
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
266 */
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
267 skip_namespace_prefix(&cur_ns_prefix, &cur_ref, TRUE,
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
268 ctx->ns->sep);
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
269
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
270 if (*cur_ref != '\0' && *cur_ns_prefix != '\0') {
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
271 /* reference parameter didn't match with
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
272 namespace prefix. skip this. */
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
273 return FALSE;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
274 }
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
275 }
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
276
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
277 if (*cur_ns_prefix != '\0') {
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
278 /* skip namespace prefix using mask */
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
279 const char *old_ns_prefix = cur_ns_prefix;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
280 const char *old_mask = cur_mask;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
281
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
282 i_assert(*cur_ref == '\0');
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
283
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
284 skip_namespace_prefix(&cur_ns_prefix, &cur_mask,
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
285 cur_ref == ctx->ref, ctx->ns->sep);
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
286
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
287 if (*cur_mask == '\0' && *cur_ns_prefix == '\0') {
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
288 /* trying to list the namespace prefix itself. */
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
289 cur_ns_prefix = old_ns_prefix;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
290 cur_mask = old_mask;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
291 }
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
292 }
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
293
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
294 *cur_ns_prefix_r = cur_ns_prefix;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
295 *cur_ref_r = cur_ref;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
296 *cur_mask_r = cur_mask;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
297 return TRUE;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
298 }
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
299
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
300 static enum imap_match_result
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
301 list_use_inboxcase(struct client_command_context *cmd,
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
302 struct cmd_list_context *ctx)
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
303 {
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
304 struct imap_match_glob *inbox_glob;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
305
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
306 if (*ctx->ns->prefix != '\0' && !ctx->ns->inbox)
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
307 return IMAP_MATCH_NO;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
308
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
309 /* if the original reference and mask combined produces something
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
310 that matches INBOX, the INBOX casing is on. */
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
311 inbox_glob = imap_match_init(cmd->pool,
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
312 t_strconcat(ctx->ref, ctx->mask, NULL),
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
313 TRUE, ctx->ns->sep);
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
314 return imap_match(inbox_glob, "INBOX");
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
315 }
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
316
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
317 static void
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
318 skip_mask_wildcard_prefix(const char *cur_ns_prefix, char sep,
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
319 const char **cur_mask_p)
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
320 {
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
321 const char *cur_mask = *cur_mask_p;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
322 unsigned int count;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
323
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
324 for (count = 1; *cur_ns_prefix != '\0'; cur_ns_prefix++) {
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
325 if (*cur_ns_prefix == sep)
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
326 count++;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
327 }
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
328
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
329 for (; count > 0; count--) {
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
330 /* skip over one hierarchy */
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
331 while (*cur_mask != '\0' && *cur_mask != '*' &&
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
332 *cur_mask != sep)
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
333 cur_mask++;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
334
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
335 if (*cur_mask == '*') {
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
336 /* we'll just request "*" and filter it
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
337 ourself. otherwise this gets too complex. */
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
338 cur_mask = "*";
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
339 break;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
340 }
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
341 if (*cur_mask == '\0') {
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
342 /* mask ended too early. we won't be listing
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
343 any mailboxes. */
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
344 break;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
345 }
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
346 cur_mask++;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
347 }
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
348
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
349 *cur_mask_p = cur_mask;
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
350 }
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
351
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
352 static void
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
353 list_namespace_init(struct client_command_context *cmd,
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
354 struct cmd_list_context *ctx)
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
355 {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
356 struct client *client = cmd->client;
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5438
diff changeset
357 struct mail_namespace *ns = ctx->ns;
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
358 const char *cur_ns_prefix, *cur_ref, *cur_mask;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
359 enum imap_match_result match;
4545
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
360 enum imap_match_result inbox_match;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
361 size_t len;
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
362
5803
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
363 if (!skip_namespace_prefix_refmask(ctx, &cur_ns_prefix,
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
364 &cur_ref, &cur_mask))
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
365 return;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
366
5803
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
367 inbox_match = list_use_inboxcase(cmd, ctx);
4545
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
368 ctx->match_inbox = inbox_match == IMAP_MATCH_YES;
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
369
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
370 ctx->glob = imap_match_init(cmd->pool, ctx->mask,
4545
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
371 (inbox_match == IMAP_MATCH_YES ||
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
372 inbox_match == IMAP_MATCH_PARENT) &&
5803
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
373 cur_mask == ctx->mask, ns->sep);
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
374
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
375 if (*cur_ns_prefix != '\0') {
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
376 /* namespace prefix still wasn't completely skipped over.
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
377 for example cur_ns_prefix=INBOX/, mask=%/% or mask=IN%.
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
378 Check that mask matches namespace prefix. */
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
379 bool skip_trailing_sep = FALSE;
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
380 i_assert(*cur_ref == '\0');
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
381
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
382 /* drop the trailing separator in namespace prefix.
5803
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
383 don't do it if we're listing only the prefix itself
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
384 (LIST "" foo/ needs to return "foo/" entry) */
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
385 len = strlen(cur_ns_prefix);
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
386 if (cur_ns_prefix[len-1] == ns->sep &&
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
387 strcmp(cur_mask, cur_ns_prefix) != 0) {
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
388 skip_trailing_sep = TRUE;
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
389 cur_ns_prefix = t_strndup(cur_ns_prefix, len-1);
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
390 }
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
391
5800
c192277a81b3 Added list setting to namespaces to control whether mailboxes in the
Timo Sirainen <tss@iki.fi>
parents: 5799
diff changeset
392 /* hidden and non-listable namespaces should still be seen
c192277a81b3 Added list setting to namespaces to control whether mailboxes in the
Timo Sirainen <tss@iki.fi>
parents: 5799
diff changeset
393 without wildcards. */
c192277a81b3 Added list setting to namespaces to control whether mailboxes in the
Timo Sirainen <tss@iki.fi>
parents: 5799
diff changeset
394 match = (!ns->list_prefix &&
c192277a81b3 Added list setting to namespaces to control whether mailboxes in the
Timo Sirainen <tss@iki.fi>
parents: 5799
diff changeset
395 list_mask_has_wildcards(cur_mask)) ?
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
396 IMAP_MATCH_NO : imap_match(ctx->glob, cur_ns_prefix);
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
397 if (match < 0)
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
398 return;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
399
4639
47531abcf691 Handle INBOX-prefixed namespaces better. Avoid duplicate INBOX replies if
Timo Sirainen <tss@iki.fi>
parents: 4546
diff changeset
400 len = strlen(ns->prefix);
5800
c192277a81b3 Added list setting to namespaces to control whether mailboxes in the
Timo Sirainen <tss@iki.fi>
parents: 5799
diff changeset
401 if (match == IMAP_MATCH_YES && ctx->ns->list_prefix &&
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
402 (ctx->list_flags & MAILBOX_LIST_ITER_SUBSCRIBED) == 0 &&
5803
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
403 (!ctx->match_inbox ||
4639
47531abcf691 Handle INBOX-prefixed namespaces better. Avoid duplicate INBOX replies if
Timo Sirainen <tss@iki.fi>
parents: 4546
diff changeset
404 strncmp(ns->prefix, "INBOX", len-1) != 0)) {
5803
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
405 /* The prefix itself matches. Because we want to know
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
406 INBOX flags, it's handled elsewhere. */
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
407 enum mailbox_info_flags flags;
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
408 string_t *str = t_str_new(128);
2537
5c95f17f6f25 Fix for having INBOX/ namespace.
Timo Sirainen <tss@iki.fi>
parents: 2425
diff changeset
409
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents: 4808
diff changeset
410 flags = MAILBOX_NONEXISTENT | MAILBOX_CHILDREN;
5314
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
411 str_append(str, "* LIST (");
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
412 mailbox_flags2str(str, flags, ctx->list_flags);
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
413 str_printfa(str, ") \"%s\" ", ns->sep_str);
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
414 imap_quote_append_string(str, skip_trailing_sep ?
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
415 t_strndup(ns->prefix, len-1) : ns->prefix,
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
416 FALSE);
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
417 client_send_line(client, str_c(str));
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
418 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
419 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
420
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
421
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
422 if (*cur_ns_prefix != '\0') {
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
423 /* We didn't skip over the whole namespace prefix. For example
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
424 cur_ns_prefix=INBOX/ and mask=%/% or IN*.
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
425
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
426 We have already verified that the mask matches the namespace
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
427 prefix, so we'll just have to skip over as many hierarchies
5803
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
428 from mask as there exists in namespace prefix. */
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
429 i_assert(*cur_ref == '\0');
5803
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
430 skip_mask_wildcard_prefix(cur_ns_prefix, ns->sep, &cur_mask);
4729
5ac887e3a53d If we had only prefixed namespaces and we listed for "%", INBOX's flags
Timo Sirainen <tss@iki.fi>
parents: 4639
diff changeset
431
5ac887e3a53d If we had only prefixed namespaces and we listed for "%", INBOX's flags
Timo Sirainen <tss@iki.fi>
parents: 4639
diff changeset
432 if (*cur_mask == '\0' && ctx->match_inbox) {
5803
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
433 /* oh what a horrible hack. ns_prefix="INBOX/" and we
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
434 wanted to list "%". INBOX should match and we want
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
435 to know its flags. for non-INBOX prefixes this is
6ae0dc6dc3b3 Code cleanups
Timo Sirainen <tss@iki.fi>
parents: 5802
diff changeset
436 handled elsewhere because it doesn't need flags. */
4729
5ac887e3a53d If we had only prefixed namespaces and we listed for "%", INBOX's flags
Timo Sirainen <tss@iki.fi>
parents: 4639
diff changeset
437 cur_mask = "INBOX";
5ac887e3a53d If we had only prefixed namespaces and we listed for "%", INBOX's flags
Timo Sirainen <tss@iki.fi>
parents: 4639
diff changeset
438 }
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
439 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
440
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
441 if (*cur_mask != '*' || strcmp(ctx->mask, "*") == 0) {
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
442 /* a) we don't have '*' in mask
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
443 b) we want to display everything
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
444
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
445 we don't need to do separate filtering ourself */
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
446 ctx->glob = NULL;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
447 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
448
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5438
diff changeset
449 cur_ref = mail_namespace_fix_sep(ns, cur_ref);
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5438
diff changeset
450 cur_mask = mail_namespace_fix_sep(ns, cur_mask);
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
451
5611
44db6ddd5a17 Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents: 5571
diff changeset
452 cur_mask = mailbox_list_join_refmask(ns->list, cur_ref, cur_mask);
44db6ddd5a17 Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents: 5571
diff changeset
453 ctx->list_iter = mailbox_list_iter_init(ns->list, cur_mask,
5571
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
454 ctx->list_flags);
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
455 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
456
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3856
diff changeset
457 static bool cmd_list_continue(struct client_command_context *cmd)
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
458 {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
459 struct client *client = cmd->client;
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
460 struct cmd_list_context *ctx = cmd->context;
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
461 int ret;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
462
4939
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
463 if (cmd->cancel) {
5611
44db6ddd5a17 Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents: 5571
diff changeset
464 if (ctx->list_iter != NULL)
44db6ddd5a17 Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents: 5571
diff changeset
465 (void)mailbox_list_iter_deinit(&ctx->list_iter);
4939
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
466 return TRUE;
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
467 }
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
468 for (; ctx->ns != NULL; ctx->ns = ctx->ns->next) {
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
469 if (ctx->list_iter == NULL)
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
470 list_namespace_init(cmd, ctx);
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
471
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
472 if ((ret = list_namespace_mailboxes(client, ctx)) < 0) {
5611
44db6ddd5a17 Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents: 5571
diff changeset
473 client_send_list_error(cmd, ctx->ns->list);
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
474 return TRUE;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
475 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
476 if (ret == 0)
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
477 return FALSE;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
478 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
479
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
480 client_send_tagline(cmd, !ctx->lsub ?
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
481 "OK List completed." :
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
482 "OK Lsub completed.");
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
483 return TRUE;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
484 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
485
5797
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
486 static void cmd_list_ref_root(struct client *client, const char *ref)
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
487 {
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
488 struct mail_namespace *ns;
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
489 const char *ns_prefix;
5802
8416f66ac5ab Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents: 5800
diff changeset
490 char ns_sep;
5797
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
491 string_t *str;
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
492
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
493 /* Special request to return the hierarchy delimiter and mailbox root
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
494 name. If namespace has a prefix, it's returned as the mailbox root.
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
495 Otherwise we'll emulate UW-IMAP behavior. */
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
496 ns = mail_namespace_find_visible(client->namespaces, &ref);
5802
8416f66ac5ab Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents: 5800
diff changeset
497 if (ns != NULL) {
5797
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
498 ns_prefix = ns->prefix;
5802
8416f66ac5ab Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents: 5800
diff changeset
499 ns_sep = ns->sep;
8416f66ac5ab Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents: 5800
diff changeset
500 } else {
5797
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
501 ns_prefix = "";
5802
8416f66ac5ab Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents: 5800
diff changeset
502 ns_sep = mail_namespace_get_root_sep(client->namespaces);
5797
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
503 }
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
504
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
505 str = t_str_new(64);
5802
8416f66ac5ab Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents: 5800
diff changeset
506 str_append(str, "* LIST (\\Noselect) \"");
8416f66ac5ab Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents: 5800
diff changeset
507 if (ns_sep == '\\' || ns_sep == '"')
8416f66ac5ab Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents: 5800
diff changeset
508 str_append_c(str, '\\');
8416f66ac5ab Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents: 5800
diff changeset
509 str_printfa(str, "%c\" ", ns_sep);
8416f66ac5ab Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents: 5800
diff changeset
510 if (*ns_prefix != '\0') {
5797
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
511 /* non-hidden namespace, use it as the root name */
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
512 imap_quote_append_string(str, ns_prefix, FALSE);
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
513 } else {
5799
75e3aedc0568 Put UW-IMAP emulation back after all
Timo Sirainen <tss@iki.fi>
parents: 5797
diff changeset
514 /* Hidden namespace or empty namespace prefix. We could just
75e3aedc0568 Put UW-IMAP emulation back after all
Timo Sirainen <tss@iki.fi>
parents: 5797
diff changeset
515 return an empty root name, but it's safer to emulate what
75e3aedc0568 Put UW-IMAP emulation back after all
Timo Sirainen <tss@iki.fi>
parents: 5797
diff changeset
516 UW-IMAP does. With full filesystem access this might even
75e3aedc0568 Put UW-IMAP emulation back after all
Timo Sirainen <tss@iki.fi>
parents: 5797
diff changeset
517 matter (root of "~user/mail/" is "~user/", not "") */
5802
8416f66ac5ab Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents: 5800
diff changeset
518 const char *p = strchr(ref, ns_sep);
5797
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
519
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
520 if (p == NULL)
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
521 str_append(str, "\"\"");
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
522 else {
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
523 imap_quote_append_string(str,
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
524 t_strdup_until(ref, p + 1),
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
525 FALSE);
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
526 }
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
527 }
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
528 client_send_line(client, str_c(str));
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
529 }
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
530
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3856
diff changeset
531 bool _cmd_list_full(struct client_command_context *cmd, bool lsub)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
532 {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
533 struct client *client = cmd->client;
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
534 struct imap_arg *args;
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
535 enum mailbox_list_flags list_flags;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
536 struct cmd_list_context *ctx;
1198
d28571e8c810 Rewrote LIST, LSUB and subscription file handling. LIST replies aren't
Timo Sirainen <tss@iki.fi>
parents: 1183
diff changeset
537 const char *ref, *mask;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
538
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
539 /* [(<options>)] <reference> <mailbox wildcards> */
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
540 if (!client_read_args(cmd, 0, 0, &args))
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
541 return FALSE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
542
1895
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
543 if (lsub) {
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
544 /* LSUB - we don't care about flags */
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
545 list_flags = MAILBOX_LIST_ITER_SUBSCRIBED |
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
546 MAILBOX_LIST_ITER_FAST_FLAGS |
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
547 _MAILBOX_LIST_ITER_HIDE_CHILDREN;
1895
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
548 } else if (args[0].type != IMAP_ARG_LIST) {
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
549 /* LIST - allow children flags, but don't require them */
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
550 list_flags = 0;
1895
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
551 } else {
5307
1e2b2b3f18e3 Added casts to some enums to avoid compiler warnings.
Timo Sirainen <tss@iki.fi>
parents: 5221
diff changeset
552 list_flags =
1e2b2b3f18e3 Added casts to some enums to avoid compiler warnings.
Timo Sirainen <tss@iki.fi>
parents: 5221
diff changeset
553 (enum mailbox_list_flags)_MAILBOX_LIST_ITER_LISTEXT;
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
554 if (!parse_list_flags(cmd, IMAP_ARG_LIST(&args[0])->args,
1895
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
555 &list_flags))
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
556 return TRUE;
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
557 args++;
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
558
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
559 /* don't show children flags unless explicitly specified */
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
560 if ((list_flags & MAILBOX_LIST_ITER_CHILDREN) == 0)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
561 list_flags |= _MAILBOX_LIST_ITER_HIDE_CHILDREN;
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
562 }
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
563
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
564 ref = imap_arg_string(&args[0]);
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
565 mask = imap_arg_string(&args[1]);
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
566
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
567 if (ref == NULL || mask == NULL) {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
568 client_send_command_error(cmd, "Invalid arguments.");
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
569 return TRUE;
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
570 }
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
571
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
572 if (*mask == '\0' && !lsub) {
5797
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
573 cmd_list_ref_root(client, ref);
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
574 client_send_tagline(cmd, "OK List completed.");
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
575 } else {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
576 ctx = p_new(cmd->pool, struct cmd_list_context, 1);
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
577 ctx->ref = ref;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
578 ctx->mask = mask;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
579 ctx->list_flags = list_flags;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
580 ctx->lsub = lsub;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
581 ctx->ns = client->namespaces;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
582
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
583 cmd->context = ctx;
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
584 if (!cmd_list_continue(cmd)) {
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
585 /* unfinished */
4939
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
586 cmd->output_pending = TRUE;
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
587 cmd->func = cmd_list_continue;
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
588 return FALSE;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
589 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
590
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
591 cmd->context = NULL;
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
592 return TRUE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
593 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
594 return TRUE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
595 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
596
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3856
diff changeset
597 bool cmd_list(struct client_command_context *cmd)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
598 {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
599 return _cmd_list_full(cmd, FALSE);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
600 }