imapext-2007

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

UW-IMAP'd extensions by yuuji