]>
Commit | Line | Data |
---|---|---|
2e32d92c | 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 | |
4 | @@ -135,6 +135,55 @@ | |
5 | dev_t homedir_dev; | |
6 | ino_t homedir_ino; | |
7 | ||
8 | +/* function to add INBOX. to names */ | |
9 | +char *tfix(struct imaptoken *curtoken) | |
10 | +{ | |
11 | + char* envp = getenv("IMAP_TOPLEVEL"); | |
12 | + const int isTop = envp && atoi(envp); | |
13 | + unsigned long l = curtoken->tokenbuf_size+6; | |
14 | + char *p; | |
15 | + | |
16 | + if(!isTop || strncmp(curtoken->tokenbuf, SHARED ".", sizeof(SHARED ".")-1) == 0 || | |
17 | + strcasecmp(curtoken->tokenbuf,INBOX) == 0) | |
18 | + return NULL; | |
19 | + | |
20 | + /* if inbox. given for uppercase to avoid any issues with namespace */ | |
21 | + if(strncasecmp(curtoken->tokenbuf,"INBOX.",6)==0) | |
22 | + { | |
23 | + int i=0; | |
24 | + for(;i<strlen(INBOX);i++) | |
25 | + (curtoken->tokenbuf)[i] = toupper((curtoken->tokenbuf)[i]); | |
26 | + } | |
27 | + | |
28 | + if(l >= curtoken->tokenbuf_size) | |
29 | + { | |
30 | + p=realloc(curtoken->tokenbuf, l + 256); | |
31 | + if(!p) | |
32 | + write_error_exit("malloc"); | |
33 | + curtoken->tokenbuf_size = l+256; | |
34 | + curtoken->tokenbuf=p; | |
35 | + } | |
36 | + p = strdup(curtoken->tokenbuf); | |
37 | + if(!p) | |
38 | + write_error_exit("malloc"); | |
39 | + sprintf(curtoken->tokenbuf,"INBOX.%s",p); | |
40 | + free(p); | |
41 | + | |
42 | + return curtoken->tokenbuf; | |
43 | +} | |
44 | + | |
45 | +/* Fix response */ | |
46 | +char* rfix(char* text) | |
47 | +{ | |
48 | + char* envp = getenv("IMAP_TOPLEVEL"); | |
49 | + const int isTop = envp && atoi(envp); | |
50 | + | |
51 | + if(isTop && (strncasecmp(text,"INBOX.",6)==0)) | |
52 | + return (text+6); | |
53 | + | |
54 | + return text; | |
55 | +} | |
56 | + | |
57 | void rfc2045_error(const char *p) | |
58 | { | |
59 | write(2, p, strlen(p)); | |
60 | @@ -570,6 +619,8 @@ | |
61 | } | |
62 | else | |
63 | { | |
64 | + tfix(curtoken); | |
65 | + | |
66 | if (ok_hierarchy && (mailbox=strrchr(curtoken->tokenbuf, | |
67 | HIERCH)) && mailbox[1] == 0) | |
68 | *mailbox=0; | |
69 | @@ -1698,6 +1749,11 @@ | |
70 | char *newf; | |
71 | FILE *newfp=newsubscribefile(&newf); | |
72 | FILE *oldfp; | |
73 | + char* envp = getenv("IMAP_TOPLEVEL"); | |
74 | + const int isTop = envp && atoi(envp); | |
75 | + | |
76 | + if(isTop && !strncmp(f,"INBOX.",6)) | |
77 | + f+=6; | |
78 | ||
79 | if ((oldfp=fopen(SUBSCRIBEFILE, "r")) != 0) | |
80 | { | |
81 | @@ -1733,6 +1789,11 @@ | |
82 | char *newf; | |
83 | FILE *newfp=newsubscribefile(&newf); | |
84 | FILE *oldfp; | |
85 | + char* envp = getenv("IMAP_TOPLEVEL"); | |
86 | + const int isTop = envp && atoi(envp); | |
87 | + | |
88 | + if(isTop && !strncmp(f,"INBOX.",6)) | |
89 | + f+=6; | |
90 | ||
91 | if ((oldfp=fopen(SUBSCRIBEFILE, "r")) != 0) | |
92 | { | |
93 | @@ -2325,7 +2386,7 @@ | |
94 | writes(") "); | |
95 | writes(hiersep); | |
96 | writes(" \""); | |
97 | - writeqs(mailbox); | |
98 | + writeqs(rfix((char*)mailbox)); | |
99 | writes("\""); | |
100 | ||
101 | if (flags & (LIST_ACL|LIST_MYRIGHTS|LIST_POSTADDRESS)) | |
102 | @@ -4075,6 +4136,8 @@ | |
103 | curtoken->tokentype != IT_ATOM && | |
104 | curtoken->tokentype != IT_NUMBER) | |
105 | return (-1); | |
106 | + if( (curtoken->tokenbuf)[0] != '*') | |
107 | + tfix(curtoken); | |
108 | name=my_strdup(curtoken->tokenbuf); | |
109 | } | |
110 | if (nexttoken()->tokentype != IT_EOL) return (-1); | |
111 | @@ -4117,6 +4180,8 @@ | |
112 | tok->tokentype != IT_QUOTED_STRING) | |
113 | return (-1); | |
114 | ||
115 | + tfix(tok); | |
116 | + | |
117 | if (maildir_info_imap_find(&mi, tok->tokenbuf, | |
118 | getenv("AUTHENTICATED")) < 0) | |
119 | { | |
120 | @@ -4182,6 +4247,8 @@ | |
121 | curtoken->tokentype != IT_QUOTED_STRING) | |
122 | return (-1); | |
123 | ||
124 | + tfix(curtoken); | |
125 | + | |
126 | if (maildir_info_imap_find(&minfo, curtoken->tokenbuf, | |
127 | getenv("AUTHENTICATED"))) | |
128 | { | |
129 | @@ -4205,7 +4272,7 @@ | |
130 | ||
131 | writes("*"); | |
132 | writes(" QUOTAROOT \""); | |
133 | - writeqs(curtoken->tokenbuf); | |
134 | + writeqs(rfix(curtoken->tokenbuf)); | |
135 | writes("\" \""); | |
136 | writes(qroot); | |
137 | writes("\"\r\n"); | |
138 | @@ -4227,6 +4294,8 @@ | |
139 | { | |
140 | curtoken=nexttoken_nouc(); | |
141 | ||
142 | + tfix(curtoken); | |
143 | + | |
144 | if (curtoken->tokentype != IT_NUMBER && | |
145 | curtoken->tokentype != IT_ATOM && | |
146 | curtoken->tokentype != IT_QUOTED_STRING) | |
147 | @@ -4337,7 +4406,7 @@ | |
148 | ||
149 | writes("*"); | |
150 | writes(" STATUS \""); | |
151 | - writeqs(orig_mailbox); | |
152 | + writeqs(rfix(orig_mailbox)); | |
153 | writes("\" ("); | |
154 | p=""; | |
155 | if (get_messages) | |
156 | @@ -4411,6 +4480,8 @@ | |
157 | ||
158 | curtoken=nexttoken_nouc(); | |
159 | ||
160 | + tfix(curtoken); | |
161 | + | |
162 | if (curtoken->tokentype != IT_NUMBER && | |
163 | curtoken->tokentype != IT_ATOM && | |
164 | curtoken->tokentype != IT_QUOTED_STRING) | |
165 | @@ -4526,7 +4597,7 @@ | |
166 | } | |
167 | writes(tag); | |
168 | writes(" OK \""); | |
169 | - writeqs(orig_mailbox); | |
170 | + writeqs(rfix(orig_mailbox)); | |
171 | writes("\" created.\r\n"); | |
172 | ||
173 | /* | |
174 | @@ -4568,8 +4639,9 @@ | |
175 | return (0); | |
176 | } | |
177 | ||
178 | - mailbox_name=my_strdup(curtoken->tokenbuf); | |
179 | mailbox=parse_mailbox_error(tag, curtoken, 1, 0); | |
180 | + mailbox_name=my_strdup(curtoken->tokenbuf); | |
181 | + | |
182 | if ( mailbox == 0) | |
183 | { | |
184 | free(mailbox_name); | |
185 | @@ -4650,6 +4722,8 @@ | |
186 | ||
187 | curtoken=nexttoken_nouc(); | |
188 | ||
189 | + tfix(curtoken); | |
190 | + | |
191 | if (curtoken->tokentype != IT_NUMBER && | |
192 | curtoken->tokentype != IT_ATOM && | |
193 | curtoken->tokentype != IT_QUOTED_STRING) | |
194 | @@ -4694,6 +4768,8 @@ | |
195 | ||
196 | ||
197 | curtoken=nexttoken_nouc(); | |
198 | + tfix(curtoken); | |
199 | + | |
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; | |
205 | ||
206 | curtoken=nexttoken_nouc(); | |
207 | + tfix(curtoken); | |
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; | |
213 | ||
214 | curtoken=nexttoken_nouc(); | |
215 | + tfix(curtoken); | |
216 | + | |
217 | if (curtoken->tokentype != IT_NUMBER && | |
218 | curtoken->tokentype != IT_ATOM && | |
219 | curtoken->tokentype != IT_QUOTED_STRING) | |
220 | @@ -5010,11 +5089,19 @@ | |
221 | ||
222 | if (strcmp(curtoken->tokenbuf, "NAMESPACE") == 0) | |
223 | { | |
224 | + char* envp = getenv("IMAP_TOPLEVEL"); | |
225 | + const int isTop = envp && atoi(envp); | |
226 | + | |
227 | if (nexttoken()->tokentype != IT_EOL) | |
228 | return (-1); | |
229 | - writes("* NAMESPACE ((\"INBOX.\" \".\")) NIL " | |
230 | + if(isTop) | |
231 | + writes("* NAMESPACE ((\"\" \".\")) NIL " | |
232 | "((\"#shared.\" \".\")(\"" | |
233 | SHARED ".\" \".\"))\r\n"); | |
234 | + else | |
235 | + writes("* NAMESPACE ((\"INBOX.\" \".\")) NIL " | |
236 | + "((\"#shared.\" \".\")(\"" | |
237 | + SHARED ".\" \".\"))\r\n"); | |
238 | writes(tag); | |
239 | writes(" OK NAMESPACE completed.\r\n"); | |
240 | return (0); | |
241 | @@ -5197,7 +5284,7 @@ | |
242 | free(mailbox_owner); | |
243 | ||
244 | writes("* ACL \""); | |
245 | - writeqs(curtoken->tokenbuf); | |
246 | + writeqs(rfix(curtoken->tokenbuf)); | |
247 | writes("\""); | |
248 | maildir_aclt_list_enum(&l, getacl_cb, NULL); | |
249 | writes("\r\n"); | |
250 | @@ -5263,9 +5350,9 @@ | |
251 | } | |
252 | ||
253 | writes("* LISTRIGHTS \""); | |
254 | - writeqs(mb); | |
255 | + writeqs(rfix(mb)); | |
256 | writes("\" \""); | |
257 | - writeqs(curtoken->tokenbuf); | |
258 | + writeqs(rfix(curtoken->tokenbuf)); | |
259 | writes("\""); | |
260 | free(mb); | |
261 | ||
262 | @@ -5359,7 +5446,7 @@ | |
263 | } | |
264 | ||
265 | writes("* MYRIGHTS \""); | |
266 | - writeqs(curtoken->tokenbuf); | |
267 | + writeqs(rfix(curtoken->tokenbuf)); | |
268 | writes("\" \""); | |
269 | ||
270 | writeacl1(mb); | |
271 | @@ -5924,6 +6011,8 @@ | |
272 | return (-1); | |
273 | } | |
274 | ||
275 | + tfix(curtoken); | |
276 | + | |
277 | mailbox=decode_valid_mailbox(curtoken->tokenbuf, 1); | |
278 | ||
279 | if (!mailbox) | |
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 | |
283 | @@ -67,7 +67,7 @@ | |
284 | #include "unicode/unicode.h" | |
285 | #include "courierauth.h" | |
286 | ||
287 | -static const char rcsid[]="$Id$"; | |
288 | +static const char rcsid[]="$Id$"; | |
289 | ||
290 | static const char hierchs[]={HIERCH, 0}; | |
291 | ||
292 | @@ -294,11 +294,11 @@ | |
293 | if (!have_rights[0]) | |
294 | return; | |
295 | ||
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*")) ) | |
299 | { | |
300 | (void) add_hier(folders, folder); | |
301 | } | |
302 | - | |
303 | hier_entry(folder, hierarchies); | |
304 | } | |
305 | ||
306 | @@ -350,6 +350,8 @@ | |
307 | { | |
308 | char buf[BUFSIZ]; | |
309 | FILE *fp; | |
310 | +char* envp = getenv("IMAP_TOPLEVEL"); | |
311 | +const int isTop = envp && atoi(envp); | |
312 | ||
313 | fp=fopen(SUBSCRIBEFILE, "r"); | |
314 | if (fp) | |
315 | @@ -371,6 +373,16 @@ | |
316 | continue; | |
317 | } | |
318 | ||
319 | + /* hack to make subscriptions work internally as we store code top level when enabled*/ | |
320 | + if(isTop && strcmp(buf,"INBOX")) | |
321 | + { | |
322 | + q = strdup(buf); | |
323 | + if(q) | |
324 | + { | |
325 | + snprintf(buf,sizeof(buf)-1,"INBOX.%s",q); | |
326 | + free(q); | |
327 | + } | |
328 | + } | |
329 | folder_entry(buf, hier, flags, | |
330 | folders, hierarchies); | |
331 | } | |
332 | @@ -400,6 +412,13 @@ | |
333 | /* A bit too much, that's OK */ | |
334 | write_error_exit(0); | |
335 | ||
336 | + strcat(strcpy(p, de->d_name), "/cur"); | |
337 | + if (access(p, 0)) | |
338 | + { | |
339 | + free(p); | |
340 | + continue; | |
341 | + } | |
342 | + | |
343 | strcpy(p, inbox_name); | |
344 | ||
345 | if (strcmp(de->d_name, ".")) | |
346 | @@ -759,6 +778,10 @@ | |
347 | int check_all_folders=0; | |
348 | char hiersepbuf[8]; | |
349 | int callback_rc=0; | |
350 | +/* Top level functions */ | |
351 | +char* envp = getenv("IMAP_TOPLEVEL"); | |
352 | +const int isTop = envp && atoi(envp); | |
353 | +int found_sub=0; | |
354 | ||
355 | obsolete=getenv("IMAP_CHECK_ALL_FOLDERS"); | |
356 | if (obsolete && atoi(obsolete)) | |
357 | @@ -835,6 +858,9 @@ | |
358 | if (strcmp(hp->hier, INBOX) == 0 || check_all_folders) | |
359 | is_interesting=hasnewmsgs(hp->hier); | |
360 | ||
361 | + if (!strncmp(hp->hier,"INBOX.INBOX.",12)) | |
362 | + found_sub = 1; /* only useful when top level enabled */ | |
363 | + | |
364 | strcat(strcat(strcpy(hiersepbuf, "\""), hierchs), "\""); | |
365 | ||
366 | mb_flags=0; | |
367 | @@ -853,6 +879,11 @@ | |
368 | mb_flags |= | |
369 | obsolete ? MAILBOX_NOINFERIORS:MAILBOX_NOCHILDREN; | |
370 | } | |
371 | + else if(isTop && !found_sub) | |
372 | + { | |
373 | + mb_flags |= | |
374 | + obsolete ? MAILBOX_NOINFERIORS:MAILBOX_NOCHILDREN; | |
375 | + } | |
376 | else | |
377 | { | |
378 | d->flag=1; | |
379 | @@ -878,7 +909,12 @@ | |
380 | && hp->flag == 0) | |
381 | { | |
382 | int mb_flags=MAILBOX_NOSELECT; | |
383 | + char* envp = getenv("IMAP_TOPLEVEL"); | |
384 | + const int isTop = envp && atoi(envp); | |
385 | ||
386 | + | |
387 | + if(isTop && strncmp(hp->hier,INBOX,sizeof(INBOX)-1)) | |
388 | + { | |
389 | if (!obsolete) | |
390 | mb_flags |= MAILBOX_CHILDREN; | |
391 | ||
392 | @@ -896,6 +932,7 @@ | |
393 | mb_flags | list_options, | |
394 | void_arg); | |
395 | } | |
396 | + } | |
397 | } | |
398 | free(hp); | |
399 | } |