imapext-2007

view src/osdep/dos/dummydos.c @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
line source
1 /* ========================================================================
2 * Copyright 1988-2006 University of Washington
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *
11 * ========================================================================
12 */
14 /*
15 * Program: Dummy routines for DOS
16 *
17 * Author: Mark Crispin
18 * Networks and Distributed Computing
19 * Computing & Communications
20 * University of Washington
21 * Administration Building, AG-44
22 * Seattle, WA 98195
23 * Internet: MRC@CAC.Washington.EDU
24 *
25 * Date: 24 May 1993
26 * Last Edited: 30 August 2006
27 */
30 #include <ctype.h>
31 #include <errno.h>
32 #include <fcntl.h>
33 #include "mail.h"
34 #include "osdep.h"
35 #include <sys\stat.h>
36 #include <dos.h>
37 #include "dummy.h"
38 #include "misc.h"
40 /* Function prototypes */
42 DRIVER *dummy_valid (char *name);
43 void *dummy_parameters (long function,void *value);
44 void dummy_list_work (MAILSTREAM *stream,char *dir,char *pat,char *contents,
45 long level);
46 long dummy_listed (MAILSTREAM *stream,char delimiter,char *name,
47 long attributes,char *contents);
48 long dummy_subscribe (MAILSTREAM *stream,char *mailbox);
49 MAILSTREAM *dummy_open (MAILSTREAM *stream);
50 void dummy_close (MAILSTREAM *stream,long options);
51 long dummy_ping (MAILSTREAM *stream);
52 void dummy_check (MAILSTREAM *stream);
53 long dummy_expunge (MAILSTREAM *stream,char *sequence,long options);
54 long dummy_copy (MAILSTREAM *stream,char *sequence,char *mailbox,long options);
55 long dummy_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data);
56 long dummy_badname (char *tmp,char *s);
58 /* Dummy routines */
61 /* Driver dispatch used by MAIL */
63 DRIVER dummydriver = {
64 "dummy", /* driver name */
65 DR_LOCAL|DR_MAIL, /* driver flags */
66 (DRIVER *) NIL, /* next driver */
67 dummy_valid, /* mailbox is valid for us */
68 dummy_parameters, /* manipulate parameters */
69 dummy_scan, /* scan mailboxes */
70 dummy_list, /* list mailboxes */
71 dummy_lsub, /* list subscribed mailboxes */
72 dummy_subscribe, /* subscribe to mailbox */
73 NIL, /* unsubscribe from mailbox */
74 dummy_create, /* create mailbox */
75 dummy_delete, /* delete mailbox */
76 dummy_rename, /* rename mailbox */
77 mail_status_default, /* status of mailbox */
78 dummy_open, /* open mailbox */
79 dummy_close, /* close mailbox */
80 NIL, /* fetch message "fast" attributes */
81 NIL, /* fetch message flags */
82 NIL, /* fetch overview */
83 NIL, /* fetch message structure */
84 NIL, /* fetch header */
85 NIL, /* fetch text */
86 NIL, /* fetch message data */
87 NIL, /* unique identifier */
88 NIL, /* message number from UID */
89 NIL, /* modify flags */
90 NIL, /* per-message modify flags */
91 NIL, /* search for message based on criteria */
92 NIL, /* sort messages */
93 NIL, /* thread messages */
94 dummy_ping, /* ping mailbox to see if still alive */
95 dummy_check, /* check for new messages */
96 dummy_expunge, /* expunge deleted messages */
97 dummy_copy, /* copy messages to another mailbox */
98 dummy_append, /* append string message to mailbox */
99 NIL /* garbage collect stream */
100 };
103 /* prototype stream */
104 MAILSTREAM dummyproto = {&dummydriver};
106 /* driver parameters */
107 static char *file_extension = NIL;
109 /* Dummy validate mailbox
110 * Accepts: mailbox name
111 * Returns: our driver if name is valid, NIL otherwise
112 */
114 DRIVER *dummy_valid (char *name)
115 {
116 char *s,tmp[MAILTMPLEN];
117 struct stat sbuf;
118 /* must be valid local mailbox */
119 return (name && *name && (*name != '{') &&
120 (s = mailboxfile (tmp,name)) && (!*s || !stat (s,&sbuf))) ?
121 &dummydriver : NIL;
122 }
125 /* Dummy manipulate driver parameters
126 * Accepts: function code
127 * function-dependent value
128 * Returns: function-dependent return value
129 */
131 void *dummy_parameters (long function,void *value)
132 {
133 void *ret = NIL;
134 switch ((int) function) {
135 case SET_EXTENSION:
136 if (file_extension) fs_give ((void **) &file_extension);
137 if (*(char *) value) file_extension = cpystr ((char *) value);
138 case GET_EXTENSION:
139 ret = (void *) file_extension;
140 }
141 return ret;
142 }
144 /* Dummy scan mailboxes
145 * Accepts: mail stream
146 * reference
147 * pattern to search
148 * string to scan
149 */
151 #define LISTTMPLEN 128
153 void dummy_scan (MAILSTREAM *stream,char *ref,char *pat,char *contents)
154 {
155 char *s,test[LISTTMPLEN],file[LISTTMPLEN];
156 long i = 0;
157 if (!pat || !*pat) { /* empty pattern? */
158 if (dummy_canonicalize (test,ref,"*")) {
159 /* tie off name at root */
160 if (s = strchr (test,'\\')) *++s = '\0';
161 else test[0] = '\0';
162 dummy_listed (stream,'\\',test,LATT_NOINFERIORS,NIL);
163 }
164 }
165 /* get canonical form of name */
166 else if (dummy_canonicalize (test,ref,pat)) {
167 /* found any wildcards? */
168 if (s = strpbrk (test,"%*")) {
169 /* yes, copy name up to that point */
170 strncpy (file,test,(size_t) (i = s - test));
171 file[i] = '\0'; /* tie off */
172 }
173 else strcpy (file,test); /* use just that name then */
174 /* find directory name */
175 if (s = strrchr (file,'\\')) {
176 *++s = '\0'; /* found, tie off at that point */
177 s = file;
178 }
179 /* silly case */
180 else if (file[0] == '#') s = file;
181 /* do the work */
182 dummy_list_work (stream,s,test,contents,0);
183 if (pmatch ("INBOX",test)) /* always an INBOX */
184 dummy_listed (stream,NIL,"INBOX",LATT_NOINFERIORS,contents);
185 }
186 }
188 /* Dummy list mailboxes
189 * Accepts: mail stream
190 * reference
191 * pattern to search
192 */
194 void dummy_list (MAILSTREAM *stream,char *ref,char *pat)
195 {
196 dummy_scan (stream,ref,pat,NIL);
197 }
200 /* Dummy list subscribed mailboxes
201 * Accepts: mail stream
202 * pattern to search
203 */
205 void dummy_lsub (MAILSTREAM *stream,char *ref,char *pat)
206 {
207 void *sdb = NIL;
208 char *s,*t,test[MAILTMPLEN];
209 int showuppers = pat[strlen (pat) - 1] == '%';
210 /* get canonical form of name */
211 if (dummy_canonicalize (test,ref,pat) && (s = sm_read (&sdb))) do
212 if (*s != '{') {
213 if (pmatch_full (s,test,'\\')) {
214 if (pmatch (s,"INBOX")) mm_lsub (stream,NIL,s,LATT_NOINFERIORS);
215 else mm_lsub (stream,'\\',s,NIL);
216 }
217 else while (showuppers && (t = strrchr (s,'\\'))) {
218 *t = '\0'; /* tie off the name */
219 if (pmatch_full (s,test,'\\')) mm_lsub (stream,'\\',s,LATT_NOSELECT);
220 }
221 }
222 while (s = sm_read (&sdb)); /* until no more subscriptions */
223 }
226 /* Dummy subscribe to mailbox
227 * Accepts: mail stream
228 * mailbox to add to subscription list
229 * Returns: T on success, NIL on failure
230 */
232 long dummy_subscribe (MAILSTREAM *stream,char *mailbox)
233 {
234 char *s,tmp[MAILTMPLEN];
235 struct stat sbuf;
236 /* must be valid local mailbox */
237 if ((s = mailboxfile (tmp,mailbox)) && *s && !stat (s,&sbuf) &&
238 ((sbuf.st_mode & S_IFMT) == S_IFREG)) return sm_subscribe (mailbox);
239 sprintf (tmp,"Can't subscribe %s: not a mailbox",mailbox);
240 mm_log (tmp,ERROR);
241 return NIL;
242 }
244 /* Dummy list mailboxes worker routine
245 * Accepts: mail stream
246 * directory name to search
247 * search pattern
248 * string to scan
249 * search level
250 */
252 void dummy_list_work (MAILSTREAM *stream,char *dir,char *pat,char *contents,
253 long level)
254 {
255 struct find_t f;
256 struct stat sbuf;
257 char *s,tmp[LISTTMPLEN],tmpx[LISTTMPLEN];
258 char *base = (dir && (dir[0] == '\\')) ? NIL : myhomedir ();
259 /* build name */
260 if (base) sprintf (tmpx,"%s\\",base);
261 else tmpx[0] = '\0';
262 if (dir) strcat (tmpx,dir);
263 /* punt if bogus name */
264 if (!mailboxfile (tmp,tmpx)) return;
265 /* make directory wildcard */
266 strcat (tmp,(tmp[strlen (tmp) -1] == '\\') ? "*." : "\\*.");
267 strcat (tmp,file_extension ? file_extension : "*");
268 /* do nothing if can't open directory */
269 if (!_dos_findfirst (tmp,_A_NORMAL|_A_SUBDIR,&f)) {
270 /* list it if at top-level */
271 if (!level && dir && pmatch_full (dir,pat,'\\'))
272 dummy_listed (stream,'\\',dir,LATT_NOSELECT,contents);
273 /* scan directory */
274 if (tmpx[strlen (tmpx) - 1] == '\\') do if (*f.name != '.') {
275 if (base) sprintf (tmpx,"%s\\",base);
276 else tmpx[0] = '\0';
277 if (dir) sprintf (tmpx + strlen (tmpx),"%s%s",dir,f.name);
278 else strcat (tmpx,f.name);
279 if (mailboxfile (tmp,tmpx) && !stat (tmp,&sbuf)) {
280 /* suppress extension */
281 if (file_extension && (s = strchr (f.name,'.'))) *s = '\0';
282 /* now make name we'd return */
283 if (dir) sprintf (tmp,"%s%s",dir,f.name);
284 else strcpy (tmp,f.name);
285 /* only interested in file type */
286 switch (sbuf.st_mode & S_IFMT) {
287 case S_IFDIR: /* directory? */
288 if (pmatch_full (tmp,pat,'\\')) {
289 dummy_listed (stream,'\\',tmp,LATT_NOSELECT,contents);
290 strcat (tmp,"\\"); /* set up for dmatch call */
291 }
292 /* try again with trailing / */
293 else if (pmatch_full (strcat (tmp,"\\"),pat,'\\'))
294 dummy_listed (stream,'\\',tmp,LATT_NOSELECT,contents);
295 if (dmatch (tmp,pat,'\\') &&
296 (level < (long) mail_parameters (NIL,GET_LISTMAXLEVEL,NIL)))
297 dummy_list_work (stream,tmp,pat,contents,level+1);
298 break;
299 case S_IFREG: /* ordinary name */
300 if (pmatch_full (tmp,pat,'\\') && !pmatch ("INBOX",tmp))
301 dummy_listed (stream,'\\',tmp,LATT_NOINFERIORS,contents);
302 break;
303 }
304 }
305 }
306 while (!_dos_findnext (&f));
307 }
308 }
310 /* Mailbox found
311 * Accepts: hierarchy delimiter
312 * mailbox name
313 * attributes
314 * contents to search before calling mm_list()
315 * Returns: T, always
316 */
318 #define BUFSIZE MAILTMPLEN
320 long dummy_listed (MAILSTREAM *stream,char delimiter,char *name,
321 long attributes,char *contents)
322 {
323 struct stat sbuf;
324 int fd;
325 size_t csiz,ssiz,bsiz;
326 char *buf,tmp[MAILTMPLEN];
327 if (contents) { /* want to search contents? */
328 /* forget it if can't select or open */
329 if ((attributes & LATT_NOSELECT) || !(csiz = strlen (contents)) ||
330 !mailboxfile (tmp,name) || stat (tmp,&sbuf) || (csiz > sbuf.st_size) ||
331 ((fd = open (tmp,O_RDONLY,NIL)) < 0)) return T;
332 /* get buffer including slop */
333 buf = (char *) fs_get (BUFSIZE + (ssiz = 4 * ((csiz / 4) + 1)) + 1);
334 memset (buf,'\0',ssiz); /* no slop area the first time */
335 while (sbuf.st_size) { /* until end of file */
336 read (fd,buf+ssiz,bsiz = min (sbuf.st_size,BUFSIZE));
337 if (search ((unsigned char *) buf,bsiz+ssiz,
338 (unsigned char *) contents,csiz)) break;
339 memcpy (buf,buf+BUFSIZE,ssiz);
340 sbuf.st_size -= bsiz; /* note that we read that much */
341 }
342 fs_give ((void **) &buf); /* flush buffer */
343 close (fd); /* finished with file */
344 if (!sbuf.st_size) return T;/* not found */
345 }
346 /* notify main program */
347 mm_list (stream,delimiter,name,attributes);
348 return T;
349 }
351 /* Dummy create mailbox
352 * Accepts: mail stream
353 * mailbox name to create
354 * Returns: T on success, NIL on failure
355 */
357 long dummy_create (MAILSTREAM *stream,char *mailbox)
358 {
359 char tmp[MAILTMPLEN];
360 return (compare_cstring (mailbox,"INBOX") && mailboxfile (tmp,mailbox)) ?
361 dummy_create_path (stream,tmp,NIL) : dummy_badname (tmp,mailbox);
362 }
365 /* Dummy create path
366 * Accepts: mail stream
367 * path name to create
368 * directory mode
369 * Returns: T on success, NIL on failure
370 */
372 long dummy_create_path (MAILSTREAM *stream,char *path,long dirmode)
373 {
374 struct stat sbuf;
375 char c,*s,tmp[MAILTMPLEN];
376 int fd;
377 long ret = NIL;
378 char *t = strrchr (path,'\\');
379 char *pt = (path[1] == ':') ? path + 2 : path;
380 int wantdir = t && !t[1];
381 if (wantdir) *t = '\0'; /* flush trailing delimiter for directory */
382 /* found superior to this name? */
383 if ((s = strrchr (pt,'\\')) && (s != pt)) {
384 strncpy (tmp,path,(size_t) (s - path));
385 tmp[s - path] = '\0'; /* make directory name for stat */
386 c = *++s; /* tie off in case need to recurse */
387 *s = '\0';
388 /* name doesn't exist, create it */
389 if ((stat (tmp,&sbuf) || ((sbuf.st_mode & S_IFMT) != S_IFDIR)) &&
390 !dummy_create_path (stream,path,dirmode)) return NIL;
391 *s = c; /* restore full name */
392 }
393 if (wantdir) { /* want to create directory? */
394 ret = !mkdir (path);
395 *t = '\\'; /* restore directory delimiter */
396 }
397 /* create file */
398 else if ((fd = open (path,O_WRONLY|O_CREAT|O_EXCL,S_IREAD|S_IWRITE)) >= 0)
399 ret = !close (fd); /* close file */
400 if (!ret) { /* error? */
401 sprintf (tmp,"Can't create mailbox node %s: %s",path,strerror (errno));
402 mm_log (tmp,ERROR);
403 }
404 return ret; /* return status */
405 }
407 /* Dummy delete mailbox
408 * Accepts: mail stream
409 * mailbox name to delete
410 * Returns: T on success, NIL on failure
411 */
413 long dummy_delete (MAILSTREAM *stream,char *mailbox)
414 {
415 struct stat sbuf;
416 char *s,tmp[MAILTMPLEN];
417 if (!mailboxfile (tmp,mailbox)) return dummy_badname (tmp,mailbox);
418 /* no trailing \ */
419 if ((s = strrchr (tmp,'\\')) && !s[1]) *s = '\0';
420 if (stat (tmp,&sbuf) || ((sbuf.st_mode & S_IFMT) == S_IFDIR) ?
421 rmdir (tmp) : unlink (tmp)) {
422 sprintf (tmp,"Can't delete mailbox %s: %s",mailbox,strerror (errno));
423 mm_log (tmp,ERROR);
424 return NIL;
425 }
426 return T; /* return success */
427 }
430 /* Mail rename mailbox
431 * Accepts: mail stream
432 * old mailbox name
433 * new mailbox name
434 * Returns: T on success, NIL on failure
435 */
437 long dummy_rename (MAILSTREAM *stream,char *old,char *newname)
438 {
439 struct stat sbuf;
440 char c,*s,tmp[MAILTMPLEN],file[MAILTMPLEN];
441 /* make file name */
442 if (!mailboxfile (file,old)) return dummy_badname (tmp,old);
443 /* no trailing \ allowed */
444 if (!(s = mailboxfile (tmp,newname)) || ((s = strrchr (s,'\\')) && !s[1]))
445 return dummy_badname (tmp,newname);
446 if (s) { /* found superior to destination name? */
447 c = *++s; /* remember first character of inferior */
448 *s = '\0'; /* tie off to get just superior */
449 /* name doesn't exist, create it */
450 if ((stat (file,&sbuf) || ((sbuf.st_mode & S_IFMT) != S_IFDIR)) &&
451 !dummy_create (stream,file)) return NIL;
452 *s = c; /* restore full name */
453 }
454 if (rename (file,tmp)) {
455 sprintf (tmp,"Can't rename mailbox %s to %s: %s",old,newname,
456 strerror (errno));
457 mm_log (tmp,ERROR);
458 return NIL;
459 }
460 return LONGT; /* return success */
461 }
463 /* Dummy open
464 * Accepts: stream to open
465 * Returns: stream on success, NIL on failure
466 */
468 MAILSTREAM *dummy_open (MAILSTREAM *stream)
469 {
470 char tmp[MAILTMPLEN];
471 struct stat sbuf;
472 int fd = -1;
473 /* OP_PROTOTYPE call or silence */
474 if (!stream || stream->silent) return NIL;
475 if (!mailboxfile (tmp,stream->mailbox))
476 sprintf (tmp,"Can't open this name: %.80s",stream->mailbox);
477 else if (compare_cstring (stream->mailbox,"INBOX") &&
478 ((fd = open (tmp,O_RDONLY,NIL)) < 0))
479 sprintf (tmp,"%s: %s",strerror (errno),stream->mailbox);
480 else {
481 if (fd >= 0) { /* if got a file */
482 fstat (fd,&sbuf); /* sniff at its size */
483 close (fd);
484 if (sbuf.st_size) sprintf (tmp,"Not a mailbox: %s",stream->mailbox);
485 else fd = -1; /* a-OK */
486 }
487 if (fd < 0) { /* no file, right? */
488 if (!stream->silent) { /* only if silence not requested */
489 /* say there are 0 messages */
490 mail_exists (stream,(long) 0);
491 mail_recent (stream,(long) 0);
492 stream->uid_validity = time (0);
493 }
494 stream->inbox = T; /* note that it's an INBOX */
495 return stream; /* return success */
496 }
497 }
498 mm_log (tmp,stream->silent ? WARN: ERROR);
499 return NIL; /* always fails */
500 }
503 /* Dummy close
504 * Accepts: MAIL stream
505 * options
506 */
508 void dummy_close (MAILSTREAM *stream,long options)
509 {
510 /* return silently */
511 }
513 /* Dummy ping mailbox
514 * Accepts: MAIL stream
515 * Returns: T if stream alive, else NIL
516 * No-op for readonly files, since read/writer can expunge it from under us!
517 */
519 long dummy_ping (MAILSTREAM *stream)
520 {
521 MAILSTREAM *test;
522 /* time to do another test? */
523 if (time (0) >= ((time_t) (stream->gensym + 30))) {
524 /* has mailbox format changed? */
525 if ((test = mail_open (NIL,stream->mailbox,OP_PROTOTYPE)) &&
526 (test->dtb != stream->dtb) &&
527 (test = mail_open (NIL,stream->mailbox,NIL))) {
528 /* preserve some resources */
529 test->original_mailbox = stream->original_mailbox;
530 stream->original_mailbox = NIL;
531 test->sparep = stream->sparep;
532 stream->sparep = NIL;
533 test->sequence = stream->sequence;
534 mail_close ((MAILSTREAM *) /* flush resources used by dummy stream */
535 memcpy (fs_get (sizeof (MAILSTREAM)),stream,
536 sizeof (MAILSTREAM)));
537 /* swap the streams */
538 memcpy (stream,test,sizeof (MAILSTREAM));
539 fs_give ((void **) &test);/* flush test now that copied */
540 /* make sure application knows */
541 mail_exists (stream,stream->recent = stream->nmsgs);
542 }
543 /* still hasn't changed */
544 else stream->gensym = time (0);
545 }
546 return T;
547 }
550 /* Dummy check mailbox
551 * Accepts: MAIL stream
552 * No-op for readonly files, since read/writer can expunge it from under us!
553 */
555 void dummy_check (MAILSTREAM *stream)
556 {
557 dummy_ping (stream); /* invoke ping */
558 }
561 /* Dummy expunge mailbox
562 * Accepts: MAIL stream
563 * sequence to expunge if non-NIL
564 * expunge options
565 * Returns: T, always
566 */
568 long dummy_expunge (MAILSTREAM *stream,char *sequence,long options)
569 {
570 return LONGT;
571 }
573 /* Dummy copy message(s)
574 * Accepts: MAIL stream
575 * sequence
576 * destination mailbox
577 * options
578 * Returns: T if copy successful, else NIL
579 */
581 long dummy_copy (MAILSTREAM *stream,char *sequence,char *mailbox,long options)
582 {
583 if ((options & CP_UID) ? mail_uid_sequence (stream,sequence) :
584 mail_sequence (stream,sequence)) fatal ("Impossible dummy_copy");
585 return NIL;
586 }
589 /* Dummy append message string
590 * Accepts: mail stream
591 * destination mailbox
592 * append callback function
593 * data for callback
594 * Returns: T on success, NIL on failure
595 */
597 long dummy_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data)
598 {
599 struct stat sbuf;
600 int fd = -1;
601 int e;
602 char tmp[MAILTMPLEN];
603 MAILSTREAM *ts = default_proto (T);
604 if (compare_cstring (mailbox,"INBOX") && mailboxfile (tmp,mailbox) &&
605 ((fd = open (tmp,O_RDONLY,NIL)) < 0)) {
606 if ((e = errno) == ENOENT) /* failed, was it no such file? */
607 mm_notify (stream,"[TRYCREATE] Must create mailbox before append",
608 (long) NIL);
609 sprintf (tmp,"%s: %s",strerror (e),mailbox);
610 mm_log (tmp,ERROR); /* pass up error */
611 return NIL; /* always fails */
612 }
613 if (fd >= 0) { /* found file? */
614 fstat (fd,&sbuf); /* get its size */
615 close (fd); /* toss out the fd */
616 if (sbuf.st_size) ts = NIL; /* non-empty file? */
617 }
618 if (ts) return (*ts->dtb->append) (stream,mailbox,af,data);
619 sprintf (tmp,"Indeterminate mailbox format: %s",mailbox);
620 mm_log (tmp,ERROR);
621 return NIL;
622 }
624 /* Return bad file name error message
625 * Accepts: temporary buffer
626 * file name
627 * Returns: long NIL always
628 */
630 long dummy_badname (char *tmp,char *s)
631 {
632 sprintf (tmp,"Invalid mailbox name: %s",s);
633 mm_log (tmp,ERROR);
634 return (long) NIL;
635 }
638 /* Dummy canonicalize name
639 * Accepts: buffer to write name
640 * reference
641 * pattern
642 * Returns: T if success, NIL if failure
643 */
645 long dummy_canonicalize (char *tmp,char *ref,char *pat)
646 {
647 unsigned long i;
648 char *s,dev[4];
649 /* initially no device */
650 dev[0] = dev[1] = dev[2] = dev[3] = '\0';
651 if (ref) switch (*ref) { /* preliminary reference check */
652 case '{': /* remote names not allowed */
653 return NIL; /* disallowed */
654 case '\0': /* empty reference string */
655 break;
656 default: /* all other names */
657 if (ref[1] == ':') { /* start with device name? */
658 dev[0] = *ref++; dev[1] = *ref++;
659 }
660 break;
661 }
662 if (pat[1] == ':') { /* device name in pattern? */
663 dev[0] = *pat++; dev[1] = *pat++;
664 ref = NIL; /* ignore reference */
665 }
666 switch (*pat) {
667 case '#': /* namespace names */
668 if (mailboxfile (tmp,pat)) strcpy (tmp,pat);
669 else return NIL; /* unknown namespace */
670 break;
671 case '{': /* remote names not allowed */
672 return NIL;
673 case '\\': /* rooted name */
674 ref = NIL; /* ignore reference */
675 break;
676 }
677 /* make sure device names are rooted */
678 if (dev[0] && (*(ref ? ref : pat) != '\\')) dev[2] = '\\';
679 /* build name */
680 sprintf (tmp,"%s%s%s",dev,ref ? ref : "",pat);
681 ucase (tmp); /* force upper case */
682 /* count wildcards */
683 for (i = 0, s = tmp; *s; *s++) if ((*s == '*') || (*s == '%')) ++i;
684 if (i > MAXWILDCARDS) { /* ridiculous wildcarding? */
685 MM_LOG ("Excessive wildcards in LIST/LSUB",ERROR);
686 return NIL;
687 }
688 return T;
689 }

UW-IMAP'd extensions by yuuji