imapext-2007

view src/osdep/os2/dummyos2.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 OS2
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 */
29 /* Thanks to Nicholas Sheppard for the original version */
32 #include <ctype.h>
33 #include <stdio.h>
34 #include <errno.h>
35 #include <sys/types.h>
36 #include <dirent.h>
37 #include <pwd.h>
38 #include <sys/stat.h>
39 #include <io.h>
40 #include <fcntl.h>
41 #include <os2.h>
42 #undef ADDRESS
43 #include "mail.h"
44 #include "osdep.h"
45 #include "misc.h"
46 #include "dummy.h"
48 /* Function prototypes */
50 DRIVER *dummy_valid (char *name);
51 void *dummy_parameters (long function,void *value);
52 void dummy_list_work (MAILSTREAM *stream,char *dir,char *pat,char *contents,
53 long level);
54 long dummy_listed (MAILSTREAM *stream,char delimiter,char *name,
55 long attributes,char *contents);
56 long dummy_subscribe (MAILSTREAM *stream,char *mailbox);
57 MAILSTREAM *dummy_open (MAILSTREAM *stream);
58 void dummy_close (MAILSTREAM *stream,long options);
59 long dummy_ping (MAILSTREAM *stream);
60 void dummy_check (MAILSTREAM *stream);
61 long dummy_expunge (MAILSTREAM *stream,char *sequence,long options);
62 long dummy_copy (MAILSTREAM *stream,char *sequence,char *mailbox,long options);
63 long dummy_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data);
65 /* Dummy routines */
68 /* Driver dispatch used by MAIL */
70 DRIVER dummydriver = {
71 "dummy", /* driver name */
72 DR_LOCAL|DR_MAIL, /* driver flags */
73 (DRIVER *) NIL, /* next driver */
74 dummy_valid, /* mailbox is valid for us */
75 dummy_parameters, /* manipulate parameters */
76 dummy_scan, /* scan mailboxes */
77 dummy_list, /* list mailboxes */
78 dummy_lsub, /* list subscribed mailboxes */
79 dummy_subscribe, /* subscribe to mailbox */
80 NIL, /* unsubscribe from mailbox */
81 dummy_create, /* create mailbox */
82 dummy_delete, /* delete mailbox */
83 dummy_rename, /* rename mailbox */
84 mail_status_default, /* status of mailbox */
85 dummy_open, /* open mailbox */
86 dummy_close, /* close mailbox */
87 NIL, /* fetch message "fast" attributes */
88 NIL, /* fetch message flags */
89 NIL, /* fetch overview */
90 NIL, /* fetch message structure */
91 NIL, /* fetch header */
92 NIL, /* fetch text */
93 NIL, /* fetch message data */
94 NIL, /* unique identifier */
95 NIL, /* message number from UID */
96 NIL, /* modify flags */
97 NIL, /* per-message modify flags */
98 NIL, /* search for message based on criteria */
99 NIL, /* sort messages */
100 NIL, /* thread messages */
101 dummy_ping, /* ping mailbox to see if still alive */
102 dummy_check, /* check for new messages */
103 dummy_expunge, /* expunge deleted messages */
104 dummy_copy, /* copy messages to another mailbox */
105 dummy_append, /* append string message to mailbox */
106 NIL /* garbage collect stream */
107 };
110 /* prototype stream */
111 MAILSTREAM dummyproto = {&dummydriver};
113 /* Dummy validate mailbox
114 * Accepts: mailbox name
115 * Returns: our driver if name is valid, NIL otherwise
116 */
118 DRIVER *dummy_valid (char *name)
119 {
120 char *s,*t,tmp[MAILTMPLEN];
121 struct stat sbuf;
122 /* must be valid local mailbox */
123 if (name && *name && (*name != '{') && (s = mailboxfile (tmp,name))) {
124 /* indeterminate INBOX */
125 if (!*s) return &dummydriver;
126 /* remove trailing \ */
127 if ((t = strrchr (s,'\\')) && !t[1]) *t = '\0';
128 if (!stat (s,&sbuf)) switch (sbuf.st_mode & S_IFMT) {
129 case S_IFREG: /* file */
130 case S_IFDIR: /* future use */
131 return &dummydriver;
132 }
133 }
134 return NIL;
135 }
138 /* Dummy manipulate driver parameters
139 * Accepts: function code
140 * function-dependent value
141 * Returns: function-dependent return value
142 */
144 void *dummy_parameters (long function,void *value)
145 {
146 return NIL;
147 }
149 /* Dummy scan mailboxes
150 * Accepts: mail stream
151 * reference
152 * pattern to search
153 * string to scan
154 */
156 void dummy_scan (MAILSTREAM *stream,char *ref,char *pat,char *contents)
157 {
158 char *s,test[MAILTMPLEN],file[MAILTMPLEN];
159 long i = 0;
160 if (!pat || !*pat) { /* empty pattern? */
161 if (dummy_canonicalize (test,ref,"*")) {
162 /* tie off name at root */
163 if (s = strchr (test,'\\')) *++s = '\0';
164 else test[0] = '\0';
165 dummy_listed (stream,'\\',test,LATT_NOSELECT,NIL);
166 }
167 }
168 /* get canonical form of name */
169 else if (dummy_canonicalize (test,ref,pat)) {
170 /* found any wildcards? */
171 if (s = strpbrk (test,"%*")) {
172 /* yes, copy name up to that point */
173 strncpy (file,test,(size_t) (i = s - test));
174 file[i] = '\0'; /* tie off */
175 }
176 else strcpy (file,test); /* use just that name then */
177 /* find directory name */
178 if (s = strrchr (file,'\\')) {
179 *++s = '\0'; /* found, tie off at that point */
180 s = file;
181 }
182 /* silly case */
183 else if (file[0] == '#') s = file;
184 /* do the work */
185 dummy_list_work (stream,s,test,contents,0);
186 if (pmatch ("INBOX",test)) /* always an INBOX */
187 dummy_listed (stream,NIL,"INBOX",LATT_NOINFERIORS,contents);
188 }
189 }
191 /* Dummy list mailboxes
192 * Accepts: mail stream
193 * reference
194 * pattern to search
195 */
197 void dummy_list (MAILSTREAM *stream,char *ref,char *pat)
198 {
199 dummy_scan (stream,ref,pat,NIL);
200 }
203 /* Dummy list subscribed mailboxes
204 * Accepts: mail stream
205 * reference
206 * pattern to search
207 */
209 void dummy_lsub (MAILSTREAM *stream,char *ref,char *pat)
210 {
211 void *sdb = NIL;
212 char *s,*t,test[MAILTMPLEN];
213 int showuppers = pat[strlen (pat) - 1] == '%';
214 /* get canonical form of name */
215 if (dummy_canonicalize (test,ref,pat) && (s = sm_read (&sdb))) do
216 if (*s != '{') {
217 if (pmatch_full (s,test,'\\')) {
218 if (pmatch (s,"INBOX")) mm_lsub (stream,NIL,s,LATT_NOINFERIORS);
219 else mm_lsub (stream,'\\',s,NIL);
220 }
221 else while (showuppers && (t = strrchr (s,'\\'))) {
222 *t = '\0'; /* tie off the name */
223 if (pmatch_full (s,test,'\\')) mm_lsub (stream,'\\',s,LATT_NOSELECT);
224 }
225 }
226 while (s = sm_read (&sdb)); /* until no more subscriptions */
227 }
230 /* Dummy subscribe to mailbox
231 * Accepts: mail stream
232 * mailbox to add to subscription list
233 * Returns: T on success, NIL on failure
234 */
236 long dummy_subscribe (MAILSTREAM *stream,char *mailbox)
237 {
238 char *s,tmp[MAILTMPLEN];
239 struct stat sbuf;
240 /* must be valid local mailbox */
241 if ((s = mailboxfile (tmp,mailbox)) && *s && !stat (s,&sbuf) &&
242 ((sbuf.st_mode & S_IFMT) == S_IFREG)) return sm_subscribe (mailbox);
243 sprintf (tmp,"Can't subscribe %.80s: not a mailbox",mailbox);
244 mm_log (tmp,ERROR);
245 return NIL;
246 }
248 /* Dummy list mailboxes worker routine
249 * Accepts: mail stream
250 * directory name to search
251 * search pattern
252 * string to scan
253 * search level
254 */
256 void dummy_list_work (MAILSTREAM *stream,char *dir,char *pat,char *contents,
257 long level)
258 {
259 unsigned long i = 1;
260 FILEFINDBUF3 f;
261 HDIR hd = HDIR_CREATE;
262 struct stat sbuf;
263 char tmp[MAILTMPLEN];
264 /* punt if bogus name */
265 if (!mailboxdir (tmp,dir,NIL)) return;
266 /* make directory wildcard */
267 strcat (tmp,(tmp[strlen (tmp) -1] == '\\') ? "*.*" : "\\*.*");
268 /* do nothing if can't open directory */
269 if (!DosFindFirst (tmp,&hd,FILE_NORMAL,&f,sizeof (f),&i,FIL_STANDARD)) {
270 /* list it if not at top-level */
271 if (!level && dir && pmatch_full (dir,pat,'\\'))
272 dummy_listed (stream,'\\',dir,LATT_NOSELECT,contents);
273 /* scan directory */
274 if (!dir || dir[strlen (dir) -1] == '\\') do {
275 if (((f.name[0] != '.') ||
276 (f.name[1] && ((f.name[1] != '.') || f.name[2]))) &&
277 (strlen (f.name) <= NETMAXMBX)) {
278 /* see if name is useful */
279 if (dir) sprintf (tmp,"%s%s",dir,f.name);
280 else strcpy (tmp,f.name);
281 /* make sure useful and can get info */
282 if ((pmatch_full (tmp,pat,'\\') ||
283 pmatch_full (strcat (tmp,"\\"),pat,'\\') ||
284 dmatch (tmp,pat,'\\')) &&
285 mailboxdir (tmp,dir,f.name) && tmp[0] && !stat (tmp,&sbuf)) {
286 /* now make name we'd return */
287 if (dir) sprintf (tmp,"%s%s",dir,f.name);
288 else strcpy (tmp,f.name);
289 /* only interested in file type */
290 switch (sbuf.st_mode & S_IFMT) {
291 case S_IFDIR: /* directory? */
292 if (pmatch_full (tmp,pat,'\\')) {
293 if (!dummy_listed (stream,'\\',tmp,LATT_NOSELECT,contents))break;
294 strcat (tmp,"\\");/* set up for dmatch call */
295 }
296 /* try again with trailing \ */
297 else if (pmatch_full (strcat (tmp,"\\"),pat,'\\') &&
298 !dummy_listed (stream,'\\',tmp,LATT_NOSELECT,contents))
299 break;
300 if (dmatch (tmp,pat,'\\') &&
301 (level < (long) mail_parameters (NIL,GET_LISTMAXLEVEL,NIL)))
302 dummy_list_work (stream,tmp,pat,contents,level+1);
303 break;
304 case S_IFREG: /* ordinary name */
305 if (pmatch_full (tmp,pat,'\\') && !pmatch ("INBOX",tmp))
306 dummy_listed (stream,'\\',tmp,LATT_NOINFERIORS,contents);
307 break;
308 }
309 }
310 }
311 i = 1;
312 } while (!DosFindNext (h,&f,sizeof (f),&i));
313 }
314 }
316 /* Mailbox found
317 * Accepts: hierarchy delimiter
318 * mailbox name
319 * attributes
320 * contents to search before calling mm_list()
321 * Returns: T, always
322 */
324 #define BUFSIZE 4*MAILTMPLEN
326 long dummy_listed (MAILSTREAM *stream,char delimiter,char *name,
327 long attributes,char *contents)
328 {
329 struct stat sbuf;
330 int fd;
331 long csiz,ssiz,bsiz;
332 char *s,*buf,tmp[MAILTMPLEN];
333 if (contents) { /* want to search contents? */
334 /* forget it if can't select or open */
335 if ((attributes & LATT_NOSELECT) || !(csiz = strlen (contents)) ||
336 !(s = dummy_file (tmp,name)) || stat (s,&sbuf) ||
337 (csiz > sbuf.st_size) || ((fd = open (tmp,O_RDONLY,NIL)) < 0))
338 return T;
339 /* get buffer including slop */
340 buf = (char *) fs_get (BUFSIZE + (ssiz = 4 * ((csiz / 4) + 1)) + 1);
341 memset (buf,'\0',ssiz); /* no slop area the first time */
342 while (sbuf.st_size) { /* until end of file */
343 read (fd,buf+ssiz,bsiz = min (sbuf.st_size,BUFSIZE));
344 if (search ((unsigned char *) buf,bsiz+ssiz,
345 (unsigned char *) contents,csiz)) break;
346 memcpy (buf,buf+BUFSIZE,ssiz);
347 sbuf.st_size -= bsiz; /* note that we read that much */
348 }
349 fs_give ((void **) &buf); /* flush buffer */
350 close (fd); /* finished with file */
351 if (!sbuf.st_size) return T;/* not found */
352 }
353 /* notify main program */
354 mm_list (stream,delimiter,name,attributes);
355 return T;
356 }
358 /* Dummy create mailbox
359 * Accepts: mail stream
360 * mailbox name to create
361 * Returns: T on success, NIL on failure
362 */
364 long dummy_create (MAILSTREAM *stream,char *mailbox)
365 {
366 char tmp[MAILTMPLEN];
367 if (compare_cstring (mailbox,"INBOX") && dummy_file (tmp,mailbox))
368 return dummy_create_path (stream,tmp,NIL);
369 sprintf (tmp,"Can't create %.80s: invalid name",mailbox);
370 mm_log (tmp,ERROR);
371 return NIL;
372 }
375 /* Dummy create path
376 * Accepts: mail stream
377 * path name to create
378 * directory mode
379 * Returns: T on success, NIL on failure
380 */
382 long dummy_create_path (MAILSTREAM *stream,char *path,long dirmode)
383 {
384 struct stat sbuf;
385 char c,*s,tmp[MAILTMPLEN];
386 int fd;
387 long ret = NIL;
388 char *t = strrchr (path,'\\');
389 char *pt = (path[1] == ':') ? path + 2 : path;
390 int wantdir = t && !t[1];
391 if (wantdir) *t = '\0'; /* flush trailing delimiter for directory */
392 /* found superior to this name? */
393 if ((s = strrchr (pt,'\\')) && (s != pt)) {
394 strncpy (tmp,path,(size_t) (s - path));
395 tmp[s - path] = '\0'; /* make directory name for stat */
396 c = *++s; /* tie off in case need to recurse */
397 *s = '\0';
398 /* name doesn't exist, create it */
399 if ((stat (tmp,&sbuf) || ((sbuf.st_mode & S_IFMT) != S_IFDIR)) &&
400 !dummy_create_path (stream,path,dirmode)) return NIL;
401 *s = c; /* restore full name */
402 }
403 if (wantdir) { /* want to create directory? */
404 ret = !mkdir (path);
405 *t = '\\'; /* restore directory delimiter */
406 }
407 /* create file */
408 else if ((fd = open (path,O_WRONLY|O_CREAT|O_EXCL,S_IREAD|S_IWRITE)) >= 0)
409 ret = !close (fd); /* close file */
410 if (!ret) { /* error? */
411 sprintf (tmp,"Can't create mailbox node %.80s: %.80s",path,
412 strerror (errno));
413 mm_log (tmp,ERROR);
414 }
415 return ret; /* return status */
416 }
418 /* Dummy delete mailbox
419 * Accepts: mail stream
420 * mailbox name to delete
421 * Returns: T on success, NIL on failure
422 */
424 long dummy_delete (MAILSTREAM *stream,char *mailbox)
425 {
426 struct stat sbuf;
427 char *s,tmp[MAILTMPLEN];
428 if (!(s = dummy_file (tmp,mailbox))) {
429 sprintf (tmp,"Can't delete - invalid name: %.80s",s);
430 mm_log (tmp,ERROR);
431 }
432 /* no trailing \ */
433 if ((s = strrchr (tmp,'\\')) && !s[1]) *s = '\0';
434 if (stat (tmp,&sbuf) || ((sbuf.st_mode & S_IFMT) == S_IFDIR) ?
435 rmdir (tmp) : unlink (tmp)) {
436 sprintf (tmp,"Can't delete mailbox %.80s: %.80s",mailbox,strerror (errno));
437 mm_log (tmp,ERROR);
438 return NIL;
439 }
440 return T; /* return success */
441 }
444 /* Mail rename mailbox
445 * Accepts: mail stream
446 * old mailbox name
447 * new mailbox name
448 * Returns: T on success, NIL on failure
449 */
451 long dummy_rename (MAILSTREAM *stream,char *old,char *newname)
452 {
453 struct stat sbuf;
454 char c,*s,tmp[MAILTMPLEN],mbx[MAILTMPLEN],oldname[MAILTMPLEN];
455 long ret = NIL;
456 /* no trailing \ allowed */
457 if (!dummy_file (oldname,old) || !(s = dummy_file (mbx,newname)) ||
458 ((s = strrchr (s,'\\')) && !s[1])) {
459 sprintf (mbx,"Can't rename %.80s to %.80s: invalid name",old,newname);
460 mm_log (mbx,ERROR);
461 return NIL;
462 }
463 /* found superior to destination name? */
464 if (s && (s != mbx) && ((mbx[1] != ':') || (s != mbx + 2))) {
465 c = s[1]; /* remember character after delimiter */
466 *s = s[1] = '\0'; /* tie off name at delimiter */
467 /* name doesn't exist, create it */
468 if (stat (mbx,&sbuf) || ((sbuf.st_mode & S_IFMT) != S_IFDIR)) {
469 *s = '\\'; /* restore delimiter */
470 if (!dummy_create (stream,mbx)) return NIL;
471 }
472 else *s = '\\'; /* restore delimiter */
473 s[1] = c; /* restore character after delimiter */
474 }
475 /* rename of non-ex INBOX creates dest */
476 if (!compare_cstring (old,"INBOX") && stat (oldname,&sbuf))
477 return dummy_create (NIL,mbx);
478 if (rename (oldname,mbx)) {
479 sprintf (tmp,"Can't rename mailbox %.80s to %.80s: %.80s",old,newname,
480 strerror (errno));
481 mm_log (tmp,ERROR);
482 return NIL;
483 }
484 return LONGT; /* return success */
485 }
487 /* Dummy open
488 * Accepts: stream to open
489 * Returns: stream on success, NIL on failure
490 */
492 MAILSTREAM *dummy_open (MAILSTREAM *stream)
493 {
494 int fd;
495 char err[MAILTMPLEN],tmp[MAILTMPLEN];
496 struct stat sbuf;
497 /* OP_PROTOTYPE call */
498 if (!stream) return &dummyproto;
499 err[0] = '\0'; /* no error message yet */
500 /* can we open the file? */
501 if (!dummy_file (tmp,stream->mailbox))
502 sprintf (err,"Can't open this name: %.80s",stream->mailbox);
503 else if ((fd = open (tmp,O_RDONLY,NIL)) < 0) {
504 /* no, error unless INBOX */
505 if (compare_cstring (stream->mailbox,"INBOX"))
506 sprintf (err,"%.80s: %.80s",strerror (errno),stream->mailbox);
507 }
508 else { /* file had better be empty then */
509 fstat (fd,&sbuf); /* sniff at its size */
510 close (fd);
511 if (sbuf.st_size) /* bogus format if non-empty */
512 sprintf (err,"%.80s (file %.80s) is not in valid mailbox format",
513 stream->mailbox,tmp);
514 }
515 if (err[0]) { /* if an error happened */
516 mm_log (err,stream->silent ? WARN : ERROR);
517 return NIL;
518 }
519 else if (!stream->silent) { /* only if silence not requested */
520 mail_exists (stream,0); /* say there are 0 messages */
521 mail_recent (stream,0); /* and certainly no recent ones! */
522 stream->uid_validity = time (0);
523 }
524 stream->inbox = T; /* note that it's an INBOX */
525 return stream; /* return success */
526 }
529 /* Dummy close
530 * Accepts: MAIL stream
531 * options
532 */
534 void dummy_close (MAILSTREAM *stream,long options)
535 {
536 /* return silently */
537 }
539 /* Dummy ping mailbox
540 * Accepts: MAIL stream
541 * Returns: T if stream alive, else NIL
542 */
544 long dummy_ping (MAILSTREAM *stream)
545 {
546 MAILSTREAM *test;
547 /* time to do another test? */
548 if (time (0) >= ((time_t) (stream->gensym + 30))) {
549 /* has mailbox format changed? */
550 if ((test = mail_open (NIL,stream->mailbox,OP_PROTOTYPE)) &&
551 (test->dtb != stream->dtb) &&
552 (test = mail_open (NIL,stream->mailbox,NIL))) {
553 /* preserve some resources */
554 test->original_mailbox = stream->original_mailbox;
555 stream->original_mailbox = NIL;
556 test->sparep = stream->sparep;
557 stream->sparep = NIL;
558 test->sequence = stream->sequence;
559 mail_close ((MAILSTREAM *) /* flush resources used by dummy stream */
560 memcpy (fs_get (sizeof (MAILSTREAM)),stream,
561 sizeof (MAILSTREAM)));
562 /* swap the streams */
563 memcpy (stream,test,sizeof (MAILSTREAM));
564 fs_give ((void **) &test);/* flush test now that copied */
565 /* make sure application knows */
566 mail_exists (stream,stream->recent = stream->nmsgs);
567 }
568 /* still hasn't changed */
569 else stream->gensym = time (0);
570 }
571 return T;
572 }
575 /* Dummy check mailbox
576 * Accepts: MAIL stream
577 * No-op for readonly files, since read/writer can expunge it from under us!
578 */
580 void dummy_check (MAILSTREAM *stream)
581 {
582 dummy_ping (stream); /* invoke ping */
583 }
586 /* Dummy expunge mailbox
587 * Accepts: MAIL stream
588 * sequence to expunge if non-NIL
589 * expunge options
590 * Returns: T, always
591 */
593 long dummy_expunge (MAILSTREAM *stream,char *sequence,long options)
594 {
595 return LONGT;
596 }
598 /* Dummy copy message(s)
599 * Accepts: MAIL stream
600 * sequence
601 * destination mailbox
602 * options
603 * Returns: T if copy successful, else NIL
604 */
606 long dummy_copy (MAILSTREAM *stream,char *sequence,char *mailbox,long options)
607 {
608 if ((options & CP_UID) ? mail_uid_sequence (stream,sequence) :
609 mail_sequence (stream,sequence)) fatal ("Impossible dummy_copy");
610 return NIL;
611 }
614 /* Dummy append message string
615 * Accepts: mail stream
616 * destination mailbox
617 * append callback function
618 * data for callback
619 * Returns: T on success, NIL on failure
620 */
622 long dummy_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data)
623 {
624 struct stat sbuf;
625 int fd = -1;
626 int e;
627 char tmp[MAILTMPLEN];
628 MAILSTREAM *ts = default_proto (T);
629 if (compare_cstring (mailbox,"INBOX") && dummy_file (tmp,mailbox) &&
630 ((fd = open (tmp,O_RDONLY,NIL)) < 0)) {
631 if ((e = errno) == ENOENT) /* failed, was it no such file? */
632 mm_notify (stream,"[TRYCREATE] Must create mailbox before append",
633 (long) NIL);
634 sprintf (tmp,"%.80s: %.80s",strerror (e),mailbox);
635 mm_log (tmp,ERROR); /* pass up error */
636 return NIL; /* always fails */
637 }
638 if (fd >= 0) { /* found file? */
639 fstat (fd,&sbuf); /* get its size */
640 close (fd); /* toss out the fd */
641 if (sbuf.st_size) ts = NIL; /* non-empty file? */
642 }
643 if (ts) return (*ts->dtb->append) (stream,mailbox,af,data);
644 sprintf (tmp,"Indeterminate mailbox format: %.80s",mailbox);
645 mm_log (tmp,ERROR);
646 return NIL;
647 }
649 /* Dummy mail generate file string
650 * Accepts: temporary buffer to write into
651 * mailbox name string
652 * Returns: local file string or NIL if failure
653 */
655 char *dummy_file (char *dst,char *name)
656 {
657 char *s = mailboxfile (dst,name);
658 /* return our standard inbox */
659 return (s && !*s) ? strcpy (dst,sysinbox ()) : s;
660 }
663 /* Dummy canonicalize name
664 * Accepts: buffer to write name
665 * reference
666 * pattern
667 * Returns: T if success, NIL if failure
668 */
670 long dummy_canonicalize (char *tmp,char *ref,char *pat)
671 {
672 unsigned long i;
673 char *s,dev[4];
674 /* initially no device */
675 dev[0] = dev[1] = dev[2] = dev[3] = '\0';
676 if (ref) switch (*ref) { /* preliminary reference check */
677 case '{': /* remote names not allowed */
678 return NIL; /* disallowed */
679 case '\0': /* empty reference string */
680 break;
681 default: /* all other names */
682 if (ref[1] == ':') { /* start with device name? */
683 dev[0] = *ref++; dev[1] = *ref++;
684 }
685 break;
686 }
687 if (pat[1] == ':') { /* device name in pattern? */
688 dev[0] = *pat++; dev[1] = *pat++;
689 ref = NIL; /* ignore reference */
690 }
691 switch (*pat) {
692 case '#': /* namespace names */
693 if (mailboxfile (tmp,pat)) strcpy (tmp,pat);
694 else return NIL; /* unknown namespace */
695 break;
696 case '{': /* remote names not allowed */
697 return NIL;
698 case '\\': /* rooted name */
699 ref = NIL; /* ignore reference */
700 break;
701 }
702 /* make sure device names are rooted */
703 if (dev[0] && (*(ref ? ref : pat) != '\\')) dev[2] = '\\';
704 /* build name */
705 sprintf (tmp,"%s%s%s",dev,ref ? ref : "",pat);
706 ucase (tmp); /* force upper case */
707 /* count wildcards */
708 for (i = 0, s = tmp; *s; *s++) if ((*s == '*') || (*s == '%')) ++i;
709 if (i > MAXWILDCARDS) { /* ridiculous wildcarding? */
710 MM_LOG ("Excessive wildcards in LIST/LSUB",ERROR);
711 return NIL;
712 }
713 return T;
714 }

UW-IMAP'd extensions by yuuji