annotate src/imap/cmd-list.c @ 5799:75e3aedc0568 HEAD

Put UW-IMAP emulation back after all
author Timo Sirainen <tss@iki.fi>
date Mon, 25 Jun 2007 18:35:17 +0300
parents de3a087ea8d2
children c192277a81b3
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
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
107 static int
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
108 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
109 {
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
110 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
111 const char *name;
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
112 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
113 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
114
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
115 if (ctx->list_iter == NULL) {
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
116 list_namespace_inbox(client, ctx);
2537
5c95f17f6f25 Fix for having INBOX/ namespace.
Timo Sirainen <tss@iki.fi>
parents: 2425
diff changeset
117 return 1;
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
118 }
2537
5c95f17f6f25 Fix for having INBOX/ namespace.
Timo Sirainen <tss@iki.fi>
parents: 2425
diff changeset
119
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
120 t_push();
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
121 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
122 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
123 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
124 str_truncate(name_str, 0);
5221
c8a82d0fb443 With namespace prefixes LSUB prefix.* listed INBOX.INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5198
diff changeset
125 if (ctx->ns->inbox && strcasecmp(info->name, "INBOX") == 0) {
c8a82d0fb443 With namespace prefixes LSUB prefix.* listed INBOX.INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5198
diff changeset
126 /* Listing INBOX from inbox=yes namespace.
c8a82d0fb443 With namespace prefixes LSUB prefix.* listed INBOX.INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5198
diff changeset
127 Don't insert the namespace prefix. */
c8a82d0fb443 With namespace prefixes LSUB prefix.* listed INBOX.INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5198
diff changeset
128 if (!ctx->match_inbox) {
c8a82d0fb443 With namespace prefixes LSUB prefix.* listed INBOX.INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5198
diff changeset
129 /* The mask doesn't match INBOX (eg. prefix.%).
c8a82d0fb443 With namespace prefixes LSUB prefix.* listed INBOX.INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5198
diff changeset
130 We still want to list prefix.INBOX if it has
c8a82d0fb443 With namespace prefixes LSUB prefix.* listed INBOX.INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5198
diff changeset
131 children. Otherwise we don't want to list
c8a82d0fb443 With namespace prefixes LSUB prefix.* listed INBOX.INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5198
diff changeset
132 this INBOX at all. */
c8a82d0fb443 With namespace prefixes LSUB prefix.* listed INBOX.INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5198
diff changeset
133 if ((info->flags & MAILBOX_CHILDREN) == 0)
c8a82d0fb443 With namespace prefixes LSUB prefix.* listed INBOX.INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5198
diff changeset
134 continue;
c8a82d0fb443 With namespace prefixes LSUB prefix.* listed INBOX.INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5198
diff changeset
135 str_append(name_str, ctx->ns->prefix);
c8a82d0fb443 With namespace prefixes LSUB prefix.* listed INBOX.INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5198
diff changeset
136 }
c8a82d0fb443 With namespace prefixes LSUB prefix.* listed INBOX.INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5198
diff changeset
137 } else {
4546
ca9eaace800a When listing INBOX from inbox=yes namespace, don't insert the
Timo Sirainen <tss@iki.fi>
parents: 4545
diff changeset
138 str_append(name_str, ctx->ns->prefix);
5221
c8a82d0fb443 With namespace prefixes LSUB prefix.* listed INBOX.INBOX.
Timo Sirainen <tss@iki.fi>
parents: 5198
diff changeset
139 }
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
140 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
141
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
142 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
143 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
144 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
145 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
146 *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
147 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
148 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
149 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
150
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
151 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
152 /* 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
153 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
154 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
155 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
156 continue;
4639
47531abcf691 Handle INBOX-prefixed namespaces better. Avoid duplicate INBOX replies if
Timo Sirainen <tss@iki.fi>
parents: 4546
diff changeset
157 }
47531abcf691 Handle INBOX-prefixed namespaces better. Avoid duplicate INBOX replies if
Timo Sirainen <tss@iki.fi>
parents: 4546
diff changeset
158 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
159 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
160 continue;
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
161
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
162 name = "INBOX";
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
163 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
164 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
165
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
166 str_truncate(str, 0);
5314
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
167 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
168 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
169 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
170 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
171 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
172 /* 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
173 t_pop();
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
174 return 0;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
175 }
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
176 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
177
5611
44db6ddd5a17 Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents: 5571
diff changeset
178 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
179 ret = -1;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
180
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
181 if (ret == 0)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
182 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
183
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
184 t_pop();
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
185 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
186 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
187
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
188 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
189 {
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
190 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
191 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
192 return TRUE;
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
193 }
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
194 return FALSE;
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
195 }
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
196
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
197 static void
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
198 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
199 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
200 {
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
201 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
202 bool match;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
203
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
204 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
205 mask_len = strlen(*mask);
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
206
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
207 if (mask_len < prefix_len) {
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
208 /* eg. namespace prefix = "INBOX.", mask = "INBOX" */
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
209 return;
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
210 }
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
211
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
212 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
213 if (!match && inbox_check) {
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
214 /* try INBOX check. */
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
215 match = prefix_len >= 5 &&
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
216 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
217 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
218 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
219 ((*prefix)[5] == sep || (*prefix)[5] == '\0');
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
220 }
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
221
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
222 if (match) {
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
223 *prefix += prefix_len;
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
224 *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
225 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
226 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
227
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
228 static void
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
229 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
230 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
231 {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
232 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
233 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
234 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
235 enum imap_match_result match;
4545
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
236 enum imap_match_result inbox_match;
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
237 struct imap_match_glob *inbox_glob;
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
238 unsigned int count;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
239 size_t len;
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
240
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
241 cur_ns_prefix = ns->prefix;
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
242 cur_ref = ctx->ref;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
243 cur_mask = ctx->mask;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
244
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
245 if (*cur_ref != '\0' && *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
246 /* reference argument given. skip namespace prefix using it.
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
247
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
248 cur_ns_prefix = foo/bar/
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
249 cur_ref = foo/
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
250 -> cur_ns_prefix=bar/, cur_ref=""
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
251 cur_ref = foo/bar/baz
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
252 -> cur_ns_prefix="", cur_ref="baz"
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
253 */
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
254 skip_namespace_prefix(&cur_ns_prefix, &cur_ref, TRUE, ns->sep);
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
255
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
256 if (*cur_ref != '\0' && *cur_ns_prefix != '\0') {
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
257 /* reference parameter didn't match with
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
258 namespace prefix. skip this. */
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
259 return;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
260 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
261 }
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
262
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
263 if (*cur_ns_prefix != '\0') {
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
264 /* no reference parameter. skip namespace prefix from mask. */
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
265 const char *old_ns_prefix = 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
266 const char *old_mask = cur_mask;
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
267
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
268 i_assert(*cur_ref == '\0');
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
269
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
270 skip_namespace_prefix(&cur_ns_prefix, &cur_mask,
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
271 cur_ref == ctx->ref, ns->sep);
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
272
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
273 if (*cur_mask == '\0' && *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
274 /* trying to list the namespace prefix itself. */
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
275 cur_ns_prefix = old_ns_prefix;
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
276 cur_mask = old_mask;
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
277 }
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
278 }
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
279
4545
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
280 /* if the original reference and mask combined produces something
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
281 that matches INBOX, the INBOX casing is on. */
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
282 inbox_glob = imap_match_init(cmd->pool,
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
283 t_strconcat(ctx->ref, ctx->mask, NULL),
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
284 TRUE, ns->sep);
5104
ffd9df333232 If namespace has a prefix and inbox=no, don't list prefix.inbox if it
Timo Sirainen <tss@iki.fi>
parents: 4939
diff changeset
285 inbox_match = *ns->prefix == '\0' || ns->inbox ?
ffd9df333232 If namespace has a prefix and inbox=no, don't list prefix.inbox if it
Timo Sirainen <tss@iki.fi>
parents: 4939
diff changeset
286 imap_match(inbox_glob, "INBOX") : FALSE;
4545
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
287 ctx->match_inbox = inbox_match == IMAP_MATCH_YES;
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
288
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
289 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
290 (inbox_match == IMAP_MATCH_YES ||
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
291 inbox_match == IMAP_MATCH_PARENT) &&
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
292 cur_mask == ctx->mask,
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
293 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
294
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
295 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
296 /* 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
297 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
298 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
299 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
300 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
301
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
302 /* drop the trailing separator in namespace prefix.
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
303 don't do it if we're listing only the prefix itself. */
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
304 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
305 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
306 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
307 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
308 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
309 }
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
310
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
311 /* hidden namespaces should still be seen without wildcards.
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
312 some clients rely on this. */
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
313 match = (ns->hidden && list_mask_has_wildcards(cur_mask)) ?
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
314 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
315 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
316 return;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
317
4639
47531abcf691 Handle INBOX-prefixed namespaces better. Avoid duplicate INBOX replies if
Timo Sirainen <tss@iki.fi>
parents: 4546
diff changeset
318 len = strlen(ns->prefix);
3305
cccb5c6ba946 LSUB was returning namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3217
diff changeset
319 if (match == IMAP_MATCH_YES &&
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
320 (ctx->list_flags & MAILBOX_LIST_ITER_SUBSCRIBED) == 0 &&
4639
47531abcf691 Handle INBOX-prefixed namespaces better. Avoid duplicate INBOX replies if
Timo Sirainen <tss@iki.fi>
parents: 4546
diff changeset
321 (!ctx->ns->inbox ||
47531abcf691 Handle INBOX-prefixed namespaces better. Avoid duplicate INBOX replies if
Timo Sirainen <tss@iki.fi>
parents: 4546
diff changeset
322 strncmp(ns->prefix, "INBOX", len-1) != 0)) {
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
323 /* The prefix itself matches */
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
324 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
325 string_t *str = t_str_new(128);
2537
5c95f17f6f25 Fix for having INBOX/ namespace.
Timo Sirainen <tss@iki.fi>
parents: 2425
diff changeset
326
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents: 4808
diff changeset
327 flags = MAILBOX_NONEXISTENT | MAILBOX_CHILDREN;
5314
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
328 str_append(str, "* LIST (");
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
329 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
330 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
331 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
332 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
333 FALSE);
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
334 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
335 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
336 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
337
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
338
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
339 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
340 /* 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
341 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
342
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
343 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
344 prefix, so we'll just have to skip over as many hierarchies
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
345 from mask as there exists in namespace prefix.
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
346
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
347 The "INBOX" namespace match reply was already sent. We're
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
348 only listing the actual mailboxes now. */
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
349 i_assert(*cur_ref == '\0');
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
350
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
351 for (count = 1; *cur_ns_prefix != '\0'; 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
352 if (*cur_ns_prefix == ns->sep)
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
353 count++;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
354 }
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
355
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
356 for (; count > 0; count--) {
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
357 /* skip over one hierarchy */
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
358 while (*cur_mask != '\0' && *cur_mask != '*' &&
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
359 *cur_mask != ns->sep)
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
360 cur_mask++;
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
361
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
362 if (*cur_mask == '*') {
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
363 /* we'll just request "*" and filter it
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
364 ourself. otherwise this gets too complex. */
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
365 cur_mask = "*";
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
366 break;
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
367 }
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
368 if (*cur_mask == '\0') {
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
369 /* mask ended too early. we won't be listing
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
370 any mailboxes. */
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
371 break;
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
372 }
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
373 cur_mask++;
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
374 }
4729
5ac887e3a53d If we had only prefixed namespaces and we listed for "%", INBOX's flags
Timo Sirainen <tss@iki.fi>
parents: 4639
diff changeset
375
5ac887e3a53d If we had only prefixed namespaces and we listed for "%", INBOX's flags
Timo Sirainen <tss@iki.fi>
parents: 4639
diff changeset
376 if (*cur_mask == '\0' && ctx->match_inbox) {
5ac887e3a53d If we had only prefixed namespaces and we listed for "%", INBOX's flags
Timo Sirainen <tss@iki.fi>
parents: 4639
diff changeset
377 /* oh what a horrible hack. ns_prefix="INBOX/" and
5ac887e3a53d If we had only prefixed namespaces and we listed for "%", INBOX's flags
Timo Sirainen <tss@iki.fi>
parents: 4639
diff changeset
378 we wanted to list "%". INBOX should match. */
5ac887e3a53d If we had only prefixed namespaces and we listed for "%", INBOX's flags
Timo Sirainen <tss@iki.fi>
parents: 4639
diff changeset
379 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
380 }
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
381 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
382
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
383 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
384 /* 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
385 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
386
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
387 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
388 ctx->glob = NULL;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
389 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
390
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5438
diff changeset
391 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
392 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
393
5611
44db6ddd5a17 Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents: 5571
diff changeset
394 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
395 ctx->list_iter = mailbox_list_iter_init(ns->list, cur_mask,
5571
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
396 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
397 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
398
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
399 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
400 {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
401 struct client *client = cmd->client;
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
402 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
403 int ret;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
404
4939
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
405 if (cmd->cancel) {
5611
44db6ddd5a17 Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents: 5571
diff changeset
406 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
407 (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
408 return TRUE;
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
409 }
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
410 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
411 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
412 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
413
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
414 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
415 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
416 return TRUE;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
417 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
418 if (ret == 0)
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
419 return FALSE;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
420 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
421
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
422 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
423 "OK List completed." :
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
424 "OK Lsub completed.");
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
425 return TRUE;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
426 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
427
5797
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
428 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
429 {
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
430 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
431 const char *ns_prefix;
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
432 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
433
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
434 /* 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
435 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
436 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
437 ns = mail_namespace_find_visible(client->namespaces, &ref);
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
438 if (ns != NULL)
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
439 ns_prefix = ns->prefix;
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
440 else {
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
441 ns_prefix = "";
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
442 ns = mail_namespace_find(client->namespaces, &ns_prefix);
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
443 if (ns == NULL) {
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
444 /* we must reply something. use INBOX namespace's
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
445 separator. */
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
446 const char *inbox = "INBOX";
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
447
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
448 ns = mail_namespace_find(client->namespaces, &inbox);
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
449 }
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
450 }
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
451
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
452 str = t_str_new(64);
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
453 str_printfa(str, "* LIST (\\Noselect) \"%s\" ", ns->sep_str);
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
454 if (*ns_prefix != '\0' && !ns->hidden) {
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
455 /* 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
456 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
457 } else {
5799
75e3aedc0568 Put UW-IMAP emulation back after all
Timo Sirainen <tss@iki.fi>
parents: 5797
diff changeset
458 /* 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
459 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
460 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
461 matter (root of "~user/mail/" is "~user/", not "") */
75e3aedc0568 Put UW-IMAP emulation back after all
Timo Sirainen <tss@iki.fi>
parents: 5797
diff changeset
462 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
463
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
464 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
465 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
466 else {
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
467 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
468 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
469 FALSE);
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
470 }
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
471 }
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
472 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
473 }
de3a087ea8d2 Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents: 5611
diff changeset
474
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
475 bool _cmd_list_full(struct client_command_context *cmd, bool lsub)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
476 {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
477 struct client *client = cmd->client;
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
478 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
479 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
480 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
481 const char *ref, *mask;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
482
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
483 /* [(<options>)] <reference> <mailbox wildcards> */
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
484 if (!client_read_args(cmd, 0, 0, &args))
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
485 return FALSE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
486
1895
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
487 if (lsub) {
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
488 /* 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
489 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
490 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
491 _MAILBOX_LIST_ITER_HIDE_CHILDREN;
1895
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
492 } else if (args[0].type != IMAP_ARG_LIST) {
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
493 /* 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
494 list_flags = 0;
1895
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
495 } else {
5307
1e2b2b3f18e3 Added casts to some enums to avoid compiler warnings.
Timo Sirainen <tss@iki.fi>
parents: 5221
diff changeset
496 list_flags =
1e2b2b3f18e3 Added casts to some enums to avoid compiler warnings.
Timo Sirainen <tss@iki.fi>
parents: 5221
diff changeset
497 (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
498 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
499 &list_flags))
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
500 return TRUE;
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
501 args++;
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
502
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
503 /* 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
504 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
505 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
506 }
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
507
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
508 ref = imap_arg_string(&args[0]);
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
509 mask = imap_arg_string(&args[1]);
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
510
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
511 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
512 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
513 return TRUE;
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
514 }
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
515
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
516 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
517 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
518 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
519 } else {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
520 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
521 ctx->ref = ref;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
522 ctx->mask = mask;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
523 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
524 ctx->lsub = lsub;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
525 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
526
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
527 cmd->context = ctx;
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
528 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
529 /* unfinished */
4939
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
530 cmd->output_pending = TRUE;
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
531 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
532 return FALSE;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
533 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
534
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
535 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
536 return TRUE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
537 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
538 return TRUE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
539 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
540
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
541 bool cmd_list(struct client_command_context *cmd)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
542 {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
543 return _cmd_list_full(cmd, FALSE);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
544 }