annotate src/imap/cmd-list.c @ 5438:97f9bdbe924d HEAD

LIST "" "" should return something even if we don't have a namespace with empty prefix. Use INBOX namespace's separator then.
author Timo Sirainen <tss@iki.fi>
date Wed, 28 Mar 2007 00:32:25 +0300
parents 469799904802
children 4862cb37106c
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"
1655
Timo Sirainen <tss@iki.fi>
parents: 1654
diff changeset
9 #include "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
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
21 struct 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
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
178 if (mailbox_list_iter_deinit(&ctx->list_iter) < 0) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
179 mail_storage_set_list_error(ctx->ns->storage);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
180 ret = -1;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
181 }
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
182
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
183 if (ret == 0)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
184 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
185
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
186 t_pop();
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
187 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
188 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
189
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
190 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
191 {
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
192 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
193 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
194 return TRUE;
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 return FALSE;
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
197 }
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
198
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
199 static void
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
200 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
201 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
202 {
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
203 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
204 bool match;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
205
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
206 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
207 mask_len = strlen(*mask);
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
208
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
209 if (mask_len < prefix_len) {
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
210 /* eg. namespace prefix = "INBOX.", mask = "INBOX" */
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
211 return;
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
212 }
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
213
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
214 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
215 if (!match && inbox_check) {
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
216 /* try INBOX check. */
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
217 match = prefix_len >= 5 &&
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
218 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
219 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
220 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
221 ((*prefix)[5] == sep || (*prefix)[5] == '\0');
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
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
224 if (match) {
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
225 *prefix += prefix_len;
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
226 *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
227 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
228 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
229
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
230 static void
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
231 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
232 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
233 {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
234 struct client *client = cmd->client;
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
235 struct 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
236 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
237 enum imap_match_result match;
4545
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
238 enum imap_match_result inbox_match;
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
239 enum mailbox_list_flags list_flags;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
240 struct mailbox_list *list;
4545
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
241 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
242 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
243 size_t len;
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 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
246 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
247 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
248
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
249 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
250 /* 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
251
3875
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 = foo/bar/
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
253 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
254 -> 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
255 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
256 -> 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
257 */
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
258 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
259
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
260 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
261 /* 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
262 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
263 return;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
264 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
265 }
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
266
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
267 if (*cur_ns_prefix != '\0') {
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
diff changeset
268 /* 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
269 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
270 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
271
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
272 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
273
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
274 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
275 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
276
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
277 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
278 /* 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
279 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
280 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
281 }
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
282 }
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
283
4545
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
284 /* 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
285 that matches INBOX, the INBOX casing is on. */
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
286 inbox_glob = imap_match_init(cmd->pool,
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
287 t_strconcat(ctx->ref, ctx->mask, NULL),
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
288 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
289 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
290 imap_match(inbox_glob, "INBOX") : FALSE;
4545
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
291 ctx->match_inbox = inbox_match == IMAP_MATCH_YES;
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
292
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
293 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
294 (inbox_match == IMAP_MATCH_YES ||
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
295 inbox_match == IMAP_MATCH_PARENT) &&
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
296 cur_mask == ctx->mask,
5ab638aafc7b Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents: 4542
diff changeset
297 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
298
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
299 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
300 /* 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
301 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
302 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
303 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
304 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
305
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
306 /* 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
307 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
308 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
309 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
310 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
311 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
312 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
313 }
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
314
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
315 /* 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
316 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
317 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
318 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
319 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
320 return;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
321
4639
47531abcf691 Handle INBOX-prefixed namespaces better. Avoid duplicate INBOX replies if
Timo Sirainen <tss@iki.fi>
parents: 4546
diff changeset
322 len = strlen(ns->prefix);
3305
cccb5c6ba946 LSUB was returning namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3217
diff changeset
323 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
324 (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
325 (!ctx->ns->inbox ||
47531abcf691 Handle INBOX-prefixed namespaces better. Avoid duplicate INBOX replies if
Timo Sirainen <tss@iki.fi>
parents: 4546
diff changeset
326 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
327 /* 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
328 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
329 string_t *str = t_str_new(128);
2537
5c95f17f6f25 Fix for having INBOX/ namespace.
Timo Sirainen <tss@iki.fi>
parents: 2425
diff changeset
330
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents: 4808
diff changeset
331 flags = MAILBOX_NONEXISTENT | MAILBOX_CHILDREN;
5314
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
332 str_append(str, "* LIST (");
ce59b45431fb Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents: 5307
diff changeset
333 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
334 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
335 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
336 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
337 FALSE);
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
338 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
339 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
340 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
341
3856
b97de2e354bd Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents: 3305
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 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
344 /* 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
345 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
346
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
347 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
348 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
349 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
350
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
351 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
352 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
353 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
354
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
355 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
356 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
357 count++;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
358 }
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
359
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
360 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
361 /* 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
362 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
363 *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
364 cur_mask++;
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
365
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
366 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
367 /* 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
368 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
369 cur_mask = "*";
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
370 break;
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
371 }
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
372 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
373 /* 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
374 any mailboxes. */
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
375 break;
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
376 }
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
377 cur_mask++;
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
378 }
4729
5ac887e3a53d If we had only prefixed namespaces and we listed for "%", INBOX's flags
Timo Sirainen <tss@iki.fi>
parents: 4639
diff changeset
379
5ac887e3a53d If we had only prefixed namespaces and we listed for "%", INBOX's flags
Timo Sirainen <tss@iki.fi>
parents: 4639
diff changeset
380 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
381 /* 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
382 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
383 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
384 }
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
385 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
386
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
387 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
388 /* 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
389 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
390
3875
e5abc07d843f Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
391 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
392 ctx->glob = NULL;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
393 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
394
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
395 cur_ref = namespace_fix_sep(ns, cur_ref);
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
396 cur_mask = namespace_fix_sep(ns, cur_mask);
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
397
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
398 list_flags = ctx->list_flags;
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
399 if (ctx->match_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
400 list_flags |= MAILBOX_LIST_FLAG_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
401
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4729
diff changeset
402 list = mail_storage_get_list(ns->storage);
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents: 4808
diff changeset
403 cur_mask = mailbox_list_join_refmask(list, cur_ref, cur_mask);
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
404 ctx->list_iter = mailbox_list_iter_init(list, cur_mask, list_flags);
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
405 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
406
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
407 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
408 {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
409 struct client *client = cmd->client;
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
410 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
411 int ret;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
412
4939
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
413 if (cmd->cancel) {
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
414 if (ctx->list_iter != NULL) {
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
415 if (mailbox_list_iter_deinit(&ctx->list_iter) < 0)
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
416 mail_storage_set_list_error(ctx->ns->storage);
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
417 }
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
418 return TRUE;
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
419 }
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
420 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
421 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
422 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
423
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
424 if ((ret = list_namespace_mailboxes(client, ctx)) < 0) {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
425 client_send_storage_error(cmd, ctx->ns->storage);
2425
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
426 return TRUE;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
427 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
428 if (ret == 0)
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
429 return FALSE;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
430 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
431
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
432 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
433 "OK List completed." :
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
434 "OK Lsub completed.");
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
435 return TRUE;
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
436 }
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
437
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
438 bool _cmd_list_full(struct client_command_context *cmd, bool lsub)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
439 {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
440 struct client *client = cmd->client;
1657
a85af58a363c A bit more temporary kludging
Timo Sirainen <tss@iki.fi>
parents: 1655
diff changeset
441 struct namespace *ns;
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
442 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
443 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
444 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
445 const char *ref, *mask;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
446
1244
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
447 /* [(<options>)] <reference> <mailbox wildcards> */
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
448 if (!client_read_args(cmd, 0, 0, &args))
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
449 return FALSE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
450
1895
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
451 if (lsub) {
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
452 /* 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
453 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
454 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
455 _MAILBOX_LIST_ITER_HIDE_CHILDREN;
1895
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
456 } else if (args[0].type != IMAP_ARG_LIST) {
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
457 /* 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
458 list_flags = 0;
1895
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
459 } else {
5307
1e2b2b3f18e3 Added casts to some enums to avoid compiler warnings.
Timo Sirainen <tss@iki.fi>
parents: 5221
diff changeset
460 list_flags =
1e2b2b3f18e3 Added casts to some enums to avoid compiler warnings.
Timo Sirainen <tss@iki.fi>
parents: 5221
diff changeset
461 (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
462 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
463 &list_flags))
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
464 return TRUE;
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
465 args++;
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
466
bbdce1697239 LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents: 1890
diff changeset
467 /* 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
468 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
469 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
470 }
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
471
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
472 ref = imap_arg_string(&args[0]);
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
473 mask = imap_arg_string(&args[1]);
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
474
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
475 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
476 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
477 return TRUE;
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
478 }
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
479
40bae47bdba1 Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents: 1218
diff changeset
480 if (*mask == '\0' && !lsub) {
5438
97f9bdbe924d LIST "" "" should return something even if we don't have a namespace with
Timo Sirainen <tss@iki.fi>
parents: 5339
diff changeset
481 const char *ns_prefix;
97f9bdbe924d LIST "" "" should return something even if we don't have a namespace with
Timo Sirainen <tss@iki.fi>
parents: 5339
diff changeset
482
3217
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
483 /* special request to return the hierarchy delimiter and
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
484 mailbox root name. Mailbox root name is somewhat strange
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
485 concept which probably no other client uses than Pine.
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
486 Just try our best to emulate UW-IMAP behavior and hopefully
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
487 we're fine. */
3876
a291d41bc50d Fixes to returning namespace root with "" mask.
Timo Sirainen <tss@iki.fi>
parents: 3875
diff changeset
488 ns = namespace_find_visible(client->namespaces, &ref);
5438
97f9bdbe924d LIST "" "" should return something even if we don't have a namespace with
Timo Sirainen <tss@iki.fi>
parents: 5339
diff changeset
489 if (ns != NULL)
97f9bdbe924d LIST "" "" should return something even if we don't have a namespace with
Timo Sirainen <tss@iki.fi>
parents: 5339
diff changeset
490 ns_prefix = ns->prefix;
97f9bdbe924d LIST "" "" should return something even if we don't have a namespace with
Timo Sirainen <tss@iki.fi>
parents: 5339
diff changeset
491 else {
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
492 const char *empty = "";
5438
97f9bdbe924d LIST "" "" should return something even if we don't have a namespace with
Timo Sirainen <tss@iki.fi>
parents: 5339
diff changeset
493
97f9bdbe924d LIST "" "" should return something even if we don't have a namespace with
Timo Sirainen <tss@iki.fi>
parents: 5339
diff changeset
494 ns_prefix = "";
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
495 ns = namespace_find(client->namespaces, &empty);
5438
97f9bdbe924d LIST "" "" should return something even if we don't have a namespace with
Timo Sirainen <tss@iki.fi>
parents: 5339
diff changeset
496 if (ns == NULL) {
97f9bdbe924d LIST "" "" should return something even if we don't have a namespace with
Timo Sirainen <tss@iki.fi>
parents: 5339
diff changeset
497 /* we must reply something. use INBOX
97f9bdbe924d LIST "" "" should return something even if we don't have a namespace with
Timo Sirainen <tss@iki.fi>
parents: 5339
diff changeset
498 namespace's separator. */
97f9bdbe924d LIST "" "" should return something even if we don't have a namespace with
Timo Sirainen <tss@iki.fi>
parents: 5339
diff changeset
499 const char *inbox = "INBOX";
97f9bdbe924d LIST "" "" should return something even if we don't have a namespace with
Timo Sirainen <tss@iki.fi>
parents: 5339
diff changeset
500 ns = namespace_find(client->namespaces, &inbox);
97f9bdbe924d LIST "" "" should return something even if we don't have a namespace with
Timo Sirainen <tss@iki.fi>
parents: 5339
diff changeset
501 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
502 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
503
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
504 if (ns != NULL) {
3217
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
505 string_t *str = t_str_new(64);
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
506
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
507 str_printfa(str, "* LIST (\\Noselect) \"%s\" ",
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
508 ns->sep_str);
5438
97f9bdbe924d LIST "" "" should return something even if we don't have a namespace with
Timo Sirainen <tss@iki.fi>
parents: 5339
diff changeset
509 if (*ns_prefix != '\0' && !ns->hidden) {
3217
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
510 /* public namespace, use it as the root name */
5438
97f9bdbe924d LIST "" "" should return something even if we don't have a namespace with
Timo Sirainen <tss@iki.fi>
parents: 5339
diff changeset
511 imap_quote_append_string(str, ns_prefix, FALSE);
3217
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
512 } else {
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
513 /* private namespace, or empty namespace
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
514 prefix. use the mailbox name's first part
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
515 as the root. */
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
516 const char *p = strchr(ref, ns->sep);
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
517
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
518 if (p == NULL)
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
519 str_append(str, "\"\"");
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
520 else {
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
521 imap_quote_append_string(str,
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
522 t_strdup_until(ref, p + 1),
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
523 FALSE);
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
524 }
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
525 }
23e5925c48dd We weren't returning "root name" properly with LIST <ref> "".
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
526 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
527 }
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
528 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
529 } else {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
530 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
531 ctx->ref = ref;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
532 ctx->mask = mask;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
533 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
534 ctx->lsub = lsub;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
535 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
536
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
537 cmd->context = ctx;
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
538 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
539 /* unfinished */
4939
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
540 cmd->output_pending = TRUE;
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
541 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
542 return FALSE;
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
543 }
8267d11cacfb LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents: 2374
diff changeset
544
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
545 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
546 return TRUE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
547 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
548 return TRUE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
549 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
550
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
551 bool cmd_list(struct client_command_context *cmd)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
552 {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 2590
diff changeset
553 return _cmd_list_full(cmd, FALSE);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
554 }