Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/imap/cmd-list.c @ 5803:6ae0dc6dc3b3 HEAD
Code cleanups
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 27 Jun 2007 16:10:00 +0300 |
parents | 8416f66ac5ab |
children | 3704fe78f2f9 |
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 | 2 |
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 | 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 | 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 | 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 | 62 } |
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 |
5803 | 228 static bool |
229 skip_namespace_prefix_refmask(struct cmd_list_context *ctx, | |
230 const char **cur_ns_prefix_r, | |
231 const char **cur_ref_r, const char **cur_mask_r) | |
232 { | |
233 const char *cur_ns_prefix, *cur_ref, *cur_mask; | |
234 | |
235 if (*ctx->ns->prefix == '\0') | |
236 return TRUE; | |
237 | |
238 cur_ns_prefix = ctx->ns->prefix; | |
239 cur_ref = ctx->ref; | |
240 cur_mask = ctx->mask; | |
241 | |
242 if (*cur_ref != '\0') { | |
243 /* reference argument given. skip namespace prefix using it. | |
244 | |
245 cur_ns_prefix = foo/bar/ | |
246 cur_ref = foo/ | |
247 -> cur_ns_prefix=bar/, cur_ref="" | |
248 cur_ref = foo/bar/baz | |
249 -> cur_ns_prefix="", cur_ref="baz" | |
250 */ | |
251 skip_namespace_prefix(&cur_ns_prefix, &cur_ref, TRUE, | |
252 ctx->ns->sep); | |
253 | |
254 if (*cur_ref != '\0' && *cur_ns_prefix != '\0') { | |
255 /* reference parameter didn't match with | |
256 namespace prefix. skip this. */ | |
257 return FALSE; | |
258 } | |
259 } | |
260 | |
261 if (*cur_ns_prefix != '\0') { | |
262 /* skip namespace prefix using mask */ | |
263 const char *old_ns_prefix = cur_ns_prefix; | |
264 const char *old_mask = cur_mask; | |
265 | |
266 i_assert(*cur_ref == '\0'); | |
267 | |
268 skip_namespace_prefix(&cur_ns_prefix, &cur_mask, | |
269 cur_ref == ctx->ref, ctx->ns->sep); | |
270 | |
271 if (*cur_mask == '\0' && *cur_ns_prefix == '\0') { | |
272 /* trying to list the namespace prefix itself. */ | |
273 cur_ns_prefix = old_ns_prefix; | |
274 cur_mask = old_mask; | |
275 } | |
276 } | |
277 | |
278 *cur_ns_prefix_r = cur_ns_prefix; | |
279 *cur_ref_r = cur_ref; | |
280 *cur_mask_r = cur_mask; | |
281 return TRUE; | |
282 } | |
283 | |
284 static enum imap_match_result | |
285 list_use_inboxcase(struct client_command_context *cmd, | |
286 struct cmd_list_context *ctx) | |
287 { | |
288 struct imap_match_glob *inbox_glob; | |
289 | |
290 if (*ctx->ns->prefix != '\0' && !ctx->ns->inbox) | |
291 return IMAP_MATCH_NO; | |
292 | |
293 /* if the original reference and mask combined produces something | |
294 that matches INBOX, the INBOX casing is on. */ | |
295 inbox_glob = imap_match_init(cmd->pool, | |
296 t_strconcat(ctx->ref, ctx->mask, NULL), | |
297 TRUE, ctx->ns->sep); | |
298 return imap_match(inbox_glob, "INBOX"); | |
299 } | |
300 | |
301 static void | |
302 skip_mask_wildcard_prefix(const char *cur_ns_prefix, char sep, | |
303 const char **cur_mask_p) | |
304 { | |
305 const char *cur_mask = *cur_mask_p; | |
306 unsigned int count; | |
307 | |
308 for (count = 1; *cur_ns_prefix != '\0'; cur_ns_prefix++) { | |
309 if (*cur_ns_prefix == sep) | |
310 count++; | |
311 } | |
312 | |
313 for (; count > 0; count--) { | |
314 /* skip over one hierarchy */ | |
315 while (*cur_mask != '\0' && *cur_mask != '*' && | |
316 *cur_mask != sep) | |
317 cur_mask++; | |
318 | |
319 if (*cur_mask == '*') { | |
320 /* we'll just request "*" and filter it | |
321 ourself. otherwise this gets too complex. */ | |
322 cur_mask = "*"; | |
323 break; | |
324 } | |
325 if (*cur_mask == '\0') { | |
326 /* mask ended too early. we won't be listing | |
327 any mailboxes. */ | |
328 break; | |
329 } | |
330 cur_mask++; | |
331 } | |
332 | |
333 *cur_mask_p = cur_mask; | |
334 } | |
335 | |
2425
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
336 static void |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2590
diff
changeset
|
337 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
|
338 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
|
339 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2590
diff
changeset
|
340 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
|
341 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
|
342 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
|
343 enum imap_match_result match; |
4545
5ab638aafc7b
Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents:
4542
diff
changeset
|
344 enum imap_match_result inbox_match; |
2350
1371d41c375f
Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
345 size_t len; |
1371d41c375f
Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
346 |
5803 | 347 if (!skip_namespace_prefix_refmask(ctx, &cur_ns_prefix, |
348 &cur_ref, &cur_mask)) | |
349 return; | |
2350
1371d41c375f
Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
350 |
5803 | 351 inbox_match = list_use_inboxcase(cmd, ctx); |
4545
5ab638aafc7b
Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents:
4542
diff
changeset
|
352 ctx->match_inbox = inbox_match == IMAP_MATCH_YES; |
5ab638aafc7b
Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents:
4542
diff
changeset
|
353 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2590
diff
changeset
|
354 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
|
355 (inbox_match == IMAP_MATCH_YES || |
5ab638aafc7b
Fixes to handling INBOX in LIST.
Timo Sirainen <tss@iki.fi>
parents:
4542
diff
changeset
|
356 inbox_match == IMAP_MATCH_PARENT) && |
5803 | 357 cur_mask == ctx->mask, ns->sep); |
3875
e5abc07d843f
Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
358 |
e5abc07d843f
Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
359 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
|
360 /* 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
|
361 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
|
362 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
|
363 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
|
364 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
|
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 /* drop the trailing separator in namespace prefix. |
5803 | 367 don't do it if we're listing only the prefix itself |
368 (LIST "" foo/ needs to return "foo/" entry) */ | |
3875
e5abc07d843f
Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
369 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
|
370 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
|
371 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
|
372 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
|
373 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
|
374 } |
e5abc07d843f
Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
375 |
5800
c192277a81b3
Added list setting to namespaces to control whether mailboxes in the
Timo Sirainen <tss@iki.fi>
parents:
5799
diff
changeset
|
376 /* hidden and non-listable namespaces should still be seen |
c192277a81b3
Added list setting to namespaces to control whether mailboxes in the
Timo Sirainen <tss@iki.fi>
parents:
5799
diff
changeset
|
377 without wildcards. */ |
c192277a81b3
Added list setting to namespaces to control whether mailboxes in the
Timo Sirainen <tss@iki.fi>
parents:
5799
diff
changeset
|
378 match = (!ns->list_prefix && |
c192277a81b3
Added list setting to namespaces to control whether mailboxes in the
Timo Sirainen <tss@iki.fi>
parents:
5799
diff
changeset
|
379 list_mask_has_wildcards(cur_mask)) ? |
3875
e5abc07d843f
Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
380 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
|
381 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
|
382 return; |
2350
1371d41c375f
Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
383 |
4639
47531abcf691
Handle INBOX-prefixed namespaces better. Avoid duplicate INBOX replies if
Timo Sirainen <tss@iki.fi>
parents:
4546
diff
changeset
|
384 len = strlen(ns->prefix); |
5800
c192277a81b3
Added list setting to namespaces to control whether mailboxes in the
Timo Sirainen <tss@iki.fi>
parents:
5799
diff
changeset
|
385 if (match == IMAP_MATCH_YES && ctx->ns->list_prefix && |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4729
diff
changeset
|
386 (ctx->list_flags & MAILBOX_LIST_ITER_SUBSCRIBED) == 0 && |
5803 | 387 (!ctx->match_inbox || |
4639
47531abcf691
Handle INBOX-prefixed namespaces better. Avoid duplicate INBOX replies if
Timo Sirainen <tss@iki.fi>
parents:
4546
diff
changeset
|
388 strncmp(ns->prefix, "INBOX", len-1) != 0)) { |
5803 | 389 /* The prefix itself matches. Because we want to know |
390 INBOX flags, it's handled elsewhere. */ | |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4729
diff
changeset
|
391 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
|
392 string_t *str = t_str_new(128); |
2537
5c95f17f6f25
Fix for having INBOX/ namespace.
Timo Sirainen <tss@iki.fi>
parents:
2425
diff
changeset
|
393 |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
394 flags = MAILBOX_NONEXISTENT | MAILBOX_CHILDREN; |
5314
ce59b45431fb
Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
395 str_append(str, "* LIST ("); |
ce59b45431fb
Use less memory when listing lots of mailboxes
Timo Sirainen <tss@iki.fi>
parents:
5307
diff
changeset
|
396 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
|
397 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
|
398 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
|
399 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
|
400 FALSE); |
2425
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
401 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
|
402 } |
1371d41c375f
Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
403 } |
1371d41c375f
Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
404 |
3856
b97de2e354bd
Fixes to handling namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
3305
diff
changeset
|
405 |
3875
e5abc07d843f
Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
406 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
|
407 /* 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
|
408 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
|
409 |
3875
e5abc07d843f
Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
410 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
|
411 prefix, so we'll just have to skip over as many hierarchies |
5803 | 412 from mask as there exists in namespace prefix. */ |
3875
e5abc07d843f
Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
413 i_assert(*cur_ref == '\0'); |
5803 | 414 skip_mask_wildcard_prefix(cur_ns_prefix, ns->sep, &cur_mask); |
4729
5ac887e3a53d
If we had only prefixed namespaces and we listed for "%", INBOX's flags
Timo Sirainen <tss@iki.fi>
parents:
4639
diff
changeset
|
415 |
5ac887e3a53d
If we had only prefixed namespaces and we listed for "%", INBOX's flags
Timo Sirainen <tss@iki.fi>
parents:
4639
diff
changeset
|
416 if (*cur_mask == '\0' && ctx->match_inbox) { |
5803 | 417 /* oh what a horrible hack. ns_prefix="INBOX/" and we |
418 wanted to list "%". INBOX should match and we want | |
419 to know its flags. for non-INBOX prefixes this is | |
420 handled elsewhere because it doesn't need flags. */ | |
4729
5ac887e3a53d
If we had only prefixed namespaces and we listed for "%", INBOX's flags
Timo Sirainen <tss@iki.fi>
parents:
4639
diff
changeset
|
421 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
|
422 } |
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 |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
425 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
|
426 /* 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
|
427 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
|
428 |
3875
e5abc07d843f
Cleaned up and added comments. Also added some kludging so that listing
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
429 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
|
430 ctx->glob = NULL; |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
431 } |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
432 |
5500
4862cb37106c
Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents:
5438
diff
changeset
|
433 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
|
434 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
|
435 |
5611
44db6ddd5a17
Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents:
5571
diff
changeset
|
436 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
|
437 ctx->list_iter = mailbox_list_iter_init(ns->list, cur_mask, |
5571 | 438 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
|
439 } |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
440 |
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
|
441 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
|
442 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2590
diff
changeset
|
443 struct client *client = cmd->client; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2590
diff
changeset
|
444 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
|
445 int ret; |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
446 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4848
diff
changeset
|
447 if (cmd->cancel) { |
5611
44db6ddd5a17
Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents:
5571
diff
changeset
|
448 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
|
449 (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
|
450 return TRUE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4848
diff
changeset
|
451 } |
2425
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
452 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
|
453 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
|
454 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
|
455 |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
456 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
|
457 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
|
458 return TRUE; |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
459 } |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
460 if (ret == 0) |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
461 return FALSE; |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
462 } |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
463 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2590
diff
changeset
|
464 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
|
465 "OK List completed." : |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
466 "OK Lsub completed."); |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
467 return TRUE; |
2350
1371d41c375f
Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
468 } |
1371d41c375f
Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
469 |
5797
de3a087ea8d2
Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents:
5611
diff
changeset
|
470 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
|
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 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
|
473 const char *ns_prefix; |
5802
8416f66ac5ab
Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents:
5800
diff
changeset
|
474 char ns_sep; |
5797
de3a087ea8d2
Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents:
5611
diff
changeset
|
475 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
|
476 |
de3a087ea8d2
Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents:
5611
diff
changeset
|
477 /* 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
|
478 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
|
479 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
|
480 ns = mail_namespace_find_visible(client->namespaces, &ref); |
5802
8416f66ac5ab
Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents:
5800
diff
changeset
|
481 if (ns != NULL) { |
5797
de3a087ea8d2
Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents:
5611
diff
changeset
|
482 ns_prefix = ns->prefix; |
5802
8416f66ac5ab
Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents:
5800
diff
changeset
|
483 ns_sep = ns->sep; |
8416f66ac5ab
Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents:
5800
diff
changeset
|
484 } else { |
5797
de3a087ea8d2
Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents:
5611
diff
changeset
|
485 ns_prefix = ""; |
5802
8416f66ac5ab
Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents:
5800
diff
changeset
|
486 ns_sep = mail_namespace_get_root_sep(client->namespaces); |
5797
de3a087ea8d2
Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents:
5611
diff
changeset
|
487 } |
de3a087ea8d2
Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents:
5611
diff
changeset
|
488 |
de3a087ea8d2
Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents:
5611
diff
changeset
|
489 str = t_str_new(64); |
5802
8416f66ac5ab
Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents:
5800
diff
changeset
|
490 str_append(str, "* LIST (\\Noselect) \""); |
8416f66ac5ab
Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents:
5800
diff
changeset
|
491 if (ns_sep == '\\' || ns_sep == '"') |
8416f66ac5ab
Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents:
5800
diff
changeset
|
492 str_append_c(str, '\\'); |
8416f66ac5ab
Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents:
5800
diff
changeset
|
493 str_printfa(str, "%c\" ", ns_sep); |
8416f66ac5ab
Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents:
5800
diff
changeset
|
494 if (*ns_prefix != '\0') { |
5797
de3a087ea8d2
Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents:
5611
diff
changeset
|
495 /* 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
|
496 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
|
497 } else { |
5799
75e3aedc0568
Put UW-IMAP emulation back after all
Timo Sirainen <tss@iki.fi>
parents:
5797
diff
changeset
|
498 /* 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
|
499 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
|
500 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
|
501 matter (root of "~user/mail/" is "~user/", not "") */ |
5802
8416f66ac5ab
Make sure all listable namespaces use the same separator. If there's no ref
Timo Sirainen <tss@iki.fi>
parents:
5800
diff
changeset
|
502 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
|
503 |
de3a087ea8d2
Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents:
5611
diff
changeset
|
504 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
|
505 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
|
506 else { |
de3a087ea8d2
Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents:
5611
diff
changeset
|
507 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
|
508 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
|
509 FALSE); |
de3a087ea8d2
Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents:
5611
diff
changeset
|
510 } |
de3a087ea8d2
Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents:
5611
diff
changeset
|
511 } |
de3a087ea8d2
Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents:
5611
diff
changeset
|
512 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
|
513 } |
de3a087ea8d2
Cleaned up LIST ref "" handling. Removed some UW-IMAPisms, they shouldn't be
Timo Sirainen <tss@iki.fi>
parents:
5611
diff
changeset
|
514 |
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
|
515 bool _cmd_list_full(struct client_command_context *cmd, bool lsub) |
0 | 516 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2590
diff
changeset
|
517 struct client *client = cmd->client; |
1244
40bae47bdba1
Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents:
1218
diff
changeset
|
518 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
|
519 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
|
520 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
|
521 const char *ref, *mask; |
0 | 522 |
1244
40bae47bdba1
Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents:
1218
diff
changeset
|
523 /* [(<options>)] <reference> <mailbox wildcards> */ |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2590
diff
changeset
|
524 if (!client_read_args(cmd, 0, 0, &args)) |
0 | 525 return FALSE; |
526 | |
1895
bbdce1697239
LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents:
1890
diff
changeset
|
527 if (lsub) { |
bbdce1697239
LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents:
1890
diff
changeset
|
528 /* 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
|
529 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
|
530 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
|
531 _MAILBOX_LIST_ITER_HIDE_CHILDREN; |
1895
bbdce1697239
LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents:
1890
diff
changeset
|
532 } else if (args[0].type != IMAP_ARG_LIST) { |
bbdce1697239
LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents:
1890
diff
changeset
|
533 /* 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
|
534 list_flags = 0; |
1895
bbdce1697239
LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents:
1890
diff
changeset
|
535 } else { |
5307
1e2b2b3f18e3
Added casts to some enums to avoid compiler warnings.
Timo Sirainen <tss@iki.fi>
parents:
5221
diff
changeset
|
536 list_flags = |
1e2b2b3f18e3
Added casts to some enums to avoid compiler warnings.
Timo Sirainen <tss@iki.fi>
parents:
5221
diff
changeset
|
537 (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
|
538 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
|
539 &list_flags)) |
bbdce1697239
LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents:
1890
diff
changeset
|
540 return TRUE; |
bbdce1697239
LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents:
1890
diff
changeset
|
541 args++; |
bbdce1697239
LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents:
1890
diff
changeset
|
542 |
bbdce1697239
LSUB should never show \HasChildren flags.
Timo Sirainen <tss@iki.fi>
parents:
1890
diff
changeset
|
543 /* 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
|
544 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
|
545 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
|
546 } |
40bae47bdba1
Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents:
1218
diff
changeset
|
547 |
40bae47bdba1
Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents:
1218
diff
changeset
|
548 ref = imap_arg_string(&args[0]); |
40bae47bdba1
Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents:
1218
diff
changeset
|
549 mask = imap_arg_string(&args[1]); |
40bae47bdba1
Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents:
1218
diff
changeset
|
550 |
40bae47bdba1
Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents:
1218
diff
changeset
|
551 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
|
552 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
|
553 return TRUE; |
40bae47bdba1
Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents:
1218
diff
changeset
|
554 } |
40bae47bdba1
Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents:
1218
diff
changeset
|
555 |
40bae47bdba1
Added support for CHILDREN and LISTEXT extensions.
Timo Sirainen <tss@iki.fi>
parents:
1218
diff
changeset
|
556 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
|
557 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
|
558 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
|
559 } else { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2590
diff
changeset
|
560 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
|
561 ctx->ref = ref; |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
562 ctx->mask = mask; |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
563 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
|
564 ctx->lsub = lsub; |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
565 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
|
566 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2590
diff
changeset
|
567 cmd->context = ctx; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2590
diff
changeset
|
568 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
|
569 /* unfinished */ |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4848
diff
changeset
|
570 cmd->output_pending = TRUE; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2590
diff
changeset
|
571 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
|
572 return FALSE; |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
573 } |
8267d11cacfb
LIST command interrupts itself when output buffer gets full and continues
Timo Sirainen <tss@iki.fi>
parents:
2374
diff
changeset
|
574 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2590
diff
changeset
|
575 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
|
576 return TRUE; |
0 | 577 } |
578 return TRUE; | |
579 } | |
580 | |
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
|
581 bool cmd_list(struct client_command_context *cmd) |
0 | 582 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2590
diff
changeset
|
583 return _cmd_list_full(cmd, FALSE); |
0 | 584 } |