1 diff -urN courier-imap-4.0.5.orig/imap/imapd.c courier-imap-4.0.5/imap/imapd.c
2 --- courier-imap-4.0.5.orig/imap/imapd.c 2005-08-20 15:04:22.000000000 +0200
3 +++ courier-imap-4.0.5/imap/imapd.c 2006-02-07 12:55:01.000000000 +0100
8 +/* function to add INBOX. to names */
9 +char *tfix(struct imaptoken *curtoken)
11 + char* envp = getenv("IMAP_TOPLEVEL");
12 + const int isTop = envp && atoi(envp);
13 + unsigned long l = curtoken->tokenbuf_size+6;
16 + if(!isTop || strncmp(curtoken->tokenbuf, SHARED ".", sizeof(SHARED ".")-1) == 0 ||
17 + strcasecmp(curtoken->tokenbuf,INBOX) == 0)
20 + /* if inbox. given for uppercase to avoid any issues with namespace */
21 + if(strncasecmp(curtoken->tokenbuf,"INBOX.",6)==0)
24 + for(;i<strlen(INBOX);i++)
25 + (curtoken->tokenbuf)[i] = toupper((curtoken->tokenbuf)[i]);
28 + if(l >= curtoken->tokenbuf_size)
30 + p=realloc(curtoken->tokenbuf, l + 256);
32 + write_error_exit("malloc");
33 + curtoken->tokenbuf_size = l+256;
34 + curtoken->tokenbuf=p;
36 + p = strdup(curtoken->tokenbuf);
38 + write_error_exit("malloc");
39 + sprintf(curtoken->tokenbuf,"INBOX.%s",p);
42 + return curtoken->tokenbuf;
46 +char* rfix(char* text)
48 + char* envp = getenv("IMAP_TOPLEVEL");
49 + const int isTop = envp && atoi(envp);
51 + if(isTop && (strncasecmp(text,"INBOX.",6)==0))
57 void rfc2045_error(const char *p)
59 write(2, p, strlen(p));
66 if (ok_hierarchy && (mailbox=strrchr(curtoken->tokenbuf,
67 HIERCH)) && mailbox[1] == 0)
69 @@ -1698,6 +1749,11 @@
71 FILE *newfp=newsubscribefile(&newf);
73 + char* envp = getenv("IMAP_TOPLEVEL");
74 + const int isTop = envp && atoi(envp);
76 + if(isTop && !strncmp(f,"INBOX.",6))
79 if ((oldfp=fopen(SUBSCRIBEFILE, "r")) != 0)
81 @@ -1733,6 +1789,11 @@
83 FILE *newfp=newsubscribefile(&newf);
85 + char* envp = getenv("IMAP_TOPLEVEL");
86 + const int isTop = envp && atoi(envp);
88 + if(isTop && !strncmp(f,"INBOX.",6))
91 if ((oldfp=fopen(SUBSCRIBEFILE, "r")) != 0)
98 + writeqs(rfix((char*)mailbox));
101 if (flags & (LIST_ACL|LIST_MYRIGHTS|LIST_POSTADDRESS))
102 @@ -4075,6 +4136,8 @@
103 curtoken->tokentype != IT_ATOM &&
104 curtoken->tokentype != IT_NUMBER)
106 + if( (curtoken->tokenbuf)[0] != '*')
108 name=my_strdup(curtoken->tokenbuf);
110 if (nexttoken()->tokentype != IT_EOL) return (-1);
111 @@ -4117,6 +4180,8 @@
112 tok->tokentype != IT_QUOTED_STRING)
117 if (maildir_info_imap_find(&mi, tok->tokenbuf,
118 getenv("AUTHENTICATED")) < 0)
120 @@ -4182,6 +4247,8 @@
121 curtoken->tokentype != IT_QUOTED_STRING)
126 if (maildir_info_imap_find(&minfo, curtoken->tokenbuf,
127 getenv("AUTHENTICATED")))
129 @@ -4205,7 +4272,7 @@
132 writes(" QUOTAROOT \"");
133 - writeqs(curtoken->tokenbuf);
134 + writeqs(rfix(curtoken->tokenbuf));
138 @@ -4227,6 +4294,8 @@
140 curtoken=nexttoken_nouc();
144 if (curtoken->tokentype != IT_NUMBER &&
145 curtoken->tokentype != IT_ATOM &&
146 curtoken->tokentype != IT_QUOTED_STRING)
147 @@ -4337,7 +4406,7 @@
150 writes(" STATUS \"");
151 - writeqs(orig_mailbox);
152 + writeqs(rfix(orig_mailbox));
156 @@ -4411,6 +4480,8 @@
158 curtoken=nexttoken_nouc();
162 if (curtoken->tokentype != IT_NUMBER &&
163 curtoken->tokentype != IT_ATOM &&
164 curtoken->tokentype != IT_QUOTED_STRING)
165 @@ -4526,7 +4597,7 @@
169 - writeqs(orig_mailbox);
170 + writeqs(rfix(orig_mailbox));
171 writes("\" created.\r\n");
174 @@ -4568,8 +4639,9 @@
178 - mailbox_name=my_strdup(curtoken->tokenbuf);
179 mailbox=parse_mailbox_error(tag, curtoken, 1, 0);
180 + mailbox_name=my_strdup(curtoken->tokenbuf);
185 @@ -4650,6 +4722,8 @@
187 curtoken=nexttoken_nouc();
191 if (curtoken->tokentype != IT_NUMBER &&
192 curtoken->tokentype != IT_ATOM &&
193 curtoken->tokentype != IT_QUOTED_STRING)
194 @@ -4694,6 +4768,8 @@
197 curtoken=nexttoken_nouc();
200 if (curtoken->tokentype != IT_NUMBER &&
201 curtoken->tokentype != IT_ATOM &&
202 curtoken->tokentype != IT_QUOTED_STRING)
203 @@ -4857,6 +4933,7 @@
204 struct maildir_info mi;
206 curtoken=nexttoken_nouc();
208 if (curtoken->tokentype != IT_NUMBER &&
209 curtoken->tokentype != IT_ATOM &&
210 curtoken->tokentype != IT_QUOTED_STRING)
211 @@ -4934,6 +5011,8 @@
212 struct maildir_info mi;
214 curtoken=nexttoken_nouc();
217 if (curtoken->tokentype != IT_NUMBER &&
218 curtoken->tokentype != IT_ATOM &&
219 curtoken->tokentype != IT_QUOTED_STRING)
220 @@ -5010,11 +5089,19 @@
222 if (strcmp(curtoken->tokenbuf, "NAMESPACE") == 0)
224 + char* envp = getenv("IMAP_TOPLEVEL");
225 + const int isTop = envp && atoi(envp);
227 if (nexttoken()->tokentype != IT_EOL)
229 - writes("* NAMESPACE ((\"INBOX.\" \".\")) NIL "
231 + writes("* NAMESPACE ((\"\" \".\")) NIL "
232 "((\"#shared.\" \".\")(\""
233 SHARED ".\" \".\"))\r\n");
235 + writes("* NAMESPACE ((\"INBOX.\" \".\")) NIL "
236 + "((\"#shared.\" \".\")(\""
237 + SHARED ".\" \".\"))\r\n");
239 writes(" OK NAMESPACE completed.\r\n");
241 @@ -5197,7 +5284,7 @@
245 - writeqs(curtoken->tokenbuf);
246 + writeqs(rfix(curtoken->tokenbuf));
248 maildir_aclt_list_enum(&l, getacl_cb, NULL);
250 @@ -5263,9 +5350,9 @@
253 writes("* LISTRIGHTS \"");
257 - writeqs(curtoken->tokenbuf);
258 + writeqs(rfix(curtoken->tokenbuf));
262 @@ -5359,7 +5446,7 @@
265 writes("* MYRIGHTS \"");
266 - writeqs(curtoken->tokenbuf);
267 + writeqs(rfix(curtoken->tokenbuf));
271 @@ -5924,6 +6011,8 @@
277 mailbox=decode_valid_mailbox(curtoken->tokenbuf, 1);
280 diff -urN courier-imap-4.0.5.orig/imap/mailboxlist.c courier-imap-4.0.5/imap/mailboxlist.c
281 --- courier-imap-4.0.5.orig/imap/mailboxlist.c 2004-10-21 02:45:48.000000000 +0200
282 +++ courier-imap-4.0.5/imap/mailboxlist.c 2006-02-07 12:55:01.000000000 +0100
284 #include "unicode/unicode.h"
285 #include "courierauth.h"
287 -static const char rcsid[]="$Id$";
288 +static const char rcsid[]="$Id$";
290 static const char hierchs[]={HIERCH, 0};
292 @@ -294,11 +294,11 @@
296 - if (match_mailbox(folder, hier, list_options) == 0)
297 + if (match_mailbox(folder, hier, list_options) == 0 ||
298 + (!strcasecmp(folder,INBOX) && !strcasecmp(hier,"INBOX.INBOX*")) )
300 (void) add_hier(folders, folder);
303 hier_entry(folder, hierarchies);
310 +char* envp = getenv("IMAP_TOPLEVEL");
311 +const int isTop = envp && atoi(envp);
313 fp=fopen(SUBSCRIBEFILE, "r");
319 + /* hack to make subscriptions work internally as we store code top level when enabled*/
320 + if(isTop && strcmp(buf,"INBOX"))
325 + snprintf(buf,sizeof(buf)-1,"INBOX.%s",q);
329 folder_entry(buf, hier, flags,
330 folders, hierarchies);
333 /* A bit too much, that's OK */
336 + strcat(strcpy(p, de->d_name), "/cur");
343 strcpy(p, inbox_name);
345 if (strcmp(de->d_name, "."))
347 int check_all_folders=0;
350 +/* Top level functions */
351 +char* envp = getenv("IMAP_TOPLEVEL");
352 +const int isTop = envp && atoi(envp);
355 obsolete=getenv("IMAP_CHECK_ALL_FOLDERS");
356 if (obsolete && atoi(obsolete))
358 if (strcmp(hp->hier, INBOX) == 0 || check_all_folders)
359 is_interesting=hasnewmsgs(hp->hier);
361 + if (!strncmp(hp->hier,"INBOX.INBOX.",12))
362 + found_sub = 1; /* only useful when top level enabled */
364 strcat(strcat(strcpy(hiersepbuf, "\""), hierchs), "\"");
369 obsolete ? MAILBOX_NOINFERIORS:MAILBOX_NOCHILDREN;
371 + else if(isTop && !found_sub)
374 + obsolete ? MAILBOX_NOINFERIORS:MAILBOX_NOCHILDREN;
382 int mb_flags=MAILBOX_NOSELECT;
383 + char* envp = getenv("IMAP_TOPLEVEL");
384 + const int isTop = envp && atoi(envp);
387 + if(isTop && strncmp(hp->hier,INBOX,sizeof(INBOX)-1))
390 mb_flags |= MAILBOX_CHILDREN;
393 mb_flags | list_options,