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

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

yatex.org