libgmp: Switch to mirrors.kernel.org for tarball
[termux-packages] / disabled-packages / alpine / 001maildir.patch
CommitLineData
d628b9b0 1diff -rc alpine-2.20/alpine/alpine.c alpine-2.20.maildir/alpine/alpine.c
2*** alpine-2.20/alpine/alpine.c 2015-01-11 22:12:25.464178246 -0700
3--- alpine-2.20.maildir/alpine/alpine.c 2015-01-20 20:37:55.697011675 -0700
4***************
5*** 560,565 ****
6--- 560,570 ----
7 if(F_ON(F_MAILDROPS_PRESERVE_STATE, ps_global))
8 mail_parameters(NULL, SET_SNARFPRESERVE, (void *) TRUE);
9
10+ #ifndef _WINDOWS
11+ rv = F_ON(F_COURIER_FOLDER_LIST, ps_global) ? 1 : 0;
12+ mail_parameters(NULL,SET_COURIERSTYLE, (void *) &rv);
13+ #endif
14+
15 rvl = 0L;
16 if(pine_state->VAR_NNTPRANGE){
17 if(!SVAR_NNTPRANGE(pine_state, rvl, tmp_20k_buf, SIZEOF_20KBUF))
18diff -rc alpine-2.20/alpine/confscroll.c alpine-2.20.maildir/alpine/confscroll.c
19*** alpine-2.20/alpine/confscroll.c 2015-01-11 22:12:25.464178246 -0700
20--- alpine-2.20.maildir/alpine/confscroll.c 2015-01-20 20:37:55.723011676 -0700
21***************
22*** 5519,5524 ****
23--- 5519,5530 ----
24 (void *)var->current_val.p);
25 }
26 #endif
27+ #ifndef _WINDOWS
28+ else if(var == &ps->vars[V_MAILDIR_LOCATION]){
29+ if(var->current_val.p && var->current_val.p[0])
30+ mail_parameters(NULL, SET_MDINBOXPATH, (void *)var->current_val.p);
31+ }
32+ #endif
33 else if(revert && standard_radio_var(ps, var)){
34
35 cur_rule_value(var, TRUE, FALSE);
36diff -rc alpine-2.20/alpine/Makefile alpine-2.20.maildir/alpine/Makefile
37*** alpine-2.20/alpine/Makefile 2015-01-18 00:00:55.293703107 -0700
38--- alpine-2.20.maildir/alpine/Makefile 2015-01-20 20:38:26.573015636 -0700
39***************
40*** 247,261 ****
41 dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
42 done; \
43 reldir="$$dir2"
44! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing aclocal-1.13
45 AMTAR = $${TAR-tar}
46 AM_CFLAGS = -g -pthread
47 AM_DEFAULT_VERBOSITY = 1
48 AM_LDFLAGS = `cat ../c-client/LDFLAGS`
49 AR = /usr/bin/ar
50! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoconf
51! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoheader
52! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing automake-1.13
53 AWK = gawk
54 CC = gcc -std=gnu99
55 CCDEPMODE = depmode=gcc3
56--- 247,261 ----
57 dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
58 done; \
59 reldir="$$dir2"
60! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing aclocal-1.13
61 AMTAR = $${TAR-tar}
62 AM_CFLAGS = -g -pthread
63 AM_DEFAULT_VERBOSITY = 1
64 AM_LDFLAGS = `cat ../c-client/LDFLAGS`
65 AR = /usr/bin/ar
66! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoconf
67! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoheader
68! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing automake-1.13
69 AWK = gawk
70 CC = gcc -std=gnu99
71 CCDEPMODE = depmode=gcc3
72***************
73*** 266,272 ****
74 CYGPATH_W = echo
75 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
76 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
77! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5"
78 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
79 C_CLIENT_TARGET = lsu
80 C_CLIENT_WITH_IPV6 = touch imap/ip6
81--- 266,272 ----
82 CYGPATH_W = echo
83 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
84 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
85! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5"
86 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
87 C_CLIENT_TARGET = lsu
88 C_CLIENT_WITH_IPV6 = touch imap/ip6
89***************
90*** 297,303 ****
91 LIBICONV = -liconv
92 LIBINTL =
93 LIBOBJS =
94! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5
95 LIBTOOL = $(SHELL) $(top_builddir)/libtool
96 LIBTOOL_DEPS = ./ltmain.sh
97 LIPO =
98--- 297,303 ----
99 LIBICONV = -liconv
100 LIBINTL =
101 LIBOBJS =
102! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5
103 LIBTOOL = $(SHELL) $(top_builddir)/libtool
104 LIBTOOL_DEPS = ./ltmain.sh
105 LIPO =
106***************
107*** 309,315 ****
108 LTLIBOBJS =
109 MAINT = #
110 MAKE = /usr/bin/make
111! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing makeinfo
112 MANIFEST_TOOL = :
113 MKDIR_P = /usr/bin/mkdir -p
114 MSGFMT = /usr/bin/msgfmt
115--- 309,315 ----
116 LTLIBOBJS =
117 MAINT = #
118 MAKE = /usr/bin/make
119! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing makeinfo
120 MANIFEST_TOOL = :
121 MKDIR_P = /usr/bin/mkdir -p
122 MSGFMT = /usr/bin/msgfmt
123***************
124*** 353,362 ****
125 WEB_PUBCOOKIE_LINK =
126 XGETTEXT = /usr/bin/xgettext
127 XGETTEXT_015 = /usr/bin/xgettext
128! abs_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/alpine
129! abs_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/alpine
130! abs_top_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
131! abs_top_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
132 ac_ct_AR = ar
133 ac_ct_CC = gcc
134 ac_ct_DUMPBIN =
135--- 353,362 ----
136 WEB_PUBCOOKIE_LINK =
137 XGETTEXT = /usr/bin/xgettext
138 XGETTEXT_015 = /usr/bin/xgettext
139! abs_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/alpine
140! abs_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/alpine
141! abs_top_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
142! abs_top_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
143 ac_ct_AR = ar
144 ac_ct_CC = gcc
145 ac_ct_DUMPBIN =
146***************
147*** 388,394 ****
148 htmldir = ${docdir}
149 includedir = ${prefix}/include
150 infodir = ${datarootdir}/info
151! install_sh = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/install-sh
152 libdir = ${exec_prefix}/lib
153 libexecdir = ${exec_prefix}/libexec
154 localedir = ${datadir}/locale
155--- 388,394 ----
156 htmldir = ${docdir}
157 includedir = ${prefix}/include
158 infodir = ${datarootdir}/info
159! install_sh = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/install-sh
160 libdir = ${exec_prefix}/lib
161 libexecdir = ${exec_prefix}/libexec
162 localedir = ${datadir}/locale
163diff -rc alpine-2.20/alpine/osdep/Makefile alpine-2.20.maildir/alpine/osdep/Makefile
164*** alpine-2.20/alpine/osdep/Makefile 2015-01-18 00:00:55.270703006 -0700
165--- alpine-2.20.maildir/alpine/osdep/Makefile 2015-01-20 20:38:26.540015628 -0700
166***************
167*** 192,206 ****
168 ETAGS = etags
169 CTAGS = ctags
170 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
171! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing aclocal-1.13
172 AMTAR = $${TAR-tar}
173 AM_CFLAGS = -g -pthread
174 AM_DEFAULT_VERBOSITY = 1
175 AM_LDFLAGS =
176 AR = /usr/bin/ar
177! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoconf
178! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoheader
179! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing automake-1.13
180 AWK = gawk
181 CC = gcc -std=gnu99
182 CCDEPMODE = depmode=gcc3
183--- 192,206 ----
184 ETAGS = etags
185 CTAGS = ctags
186 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
187! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing aclocal-1.13
188 AMTAR = $${TAR-tar}
189 AM_CFLAGS = -g -pthread
190 AM_DEFAULT_VERBOSITY = 1
191 AM_LDFLAGS =
192 AR = /usr/bin/ar
193! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoconf
194! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoheader
195! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing automake-1.13
196 AWK = gawk
197 CC = gcc -std=gnu99
198 CCDEPMODE = depmode=gcc3
199***************
200*** 211,217 ****
201 CYGPATH_W = echo
202 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
203 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
204! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5"
205 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
206 C_CLIENT_TARGET = lsu
207 C_CLIENT_WITH_IPV6 = touch imap/ip6
208--- 211,217 ----
209 CYGPATH_W = echo
210 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
211 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
212! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5"
213 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
214 C_CLIENT_TARGET = lsu
215 C_CLIENT_WITH_IPV6 = touch imap/ip6
216***************
217*** 242,248 ****
218 LIBICONV = -liconv
219 LIBINTL =
220 LIBOBJS =
221! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5
222 LIBTOOL = $(SHELL) $(top_builddir)/libtool
223 LIBTOOL_DEPS = ./ltmain.sh
224 LIPO =
225--- 242,248 ----
226 LIBICONV = -liconv
227 LIBINTL =
228 LIBOBJS =
229! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5
230 LIBTOOL = $(SHELL) $(top_builddir)/libtool
231 LIBTOOL_DEPS = ./ltmain.sh
232 LIPO =
233***************
234*** 254,260 ****
235 LTLIBOBJS =
236 MAINT = #
237 MAKE = /usr/bin/make
238! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing makeinfo
239 MANIFEST_TOOL = :
240 MKDIR_P = /usr/bin/mkdir -p
241 MSGFMT = /usr/bin/msgfmt
242--- 254,260 ----
243 LTLIBOBJS =
244 MAINT = #
245 MAKE = /usr/bin/make
246! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing makeinfo
247 MANIFEST_TOOL = :
248 MKDIR_P = /usr/bin/mkdir -p
249 MSGFMT = /usr/bin/msgfmt
250***************
251*** 298,307 ****
252 WEB_PUBCOOKIE_LINK =
253 XGETTEXT = /usr/bin/xgettext
254 XGETTEXT_015 = /usr/bin/xgettext
255! abs_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/alpine/osdep
256! abs_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/alpine/osdep
257! abs_top_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
258! abs_top_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
259 ac_ct_AR = ar
260 ac_ct_CC = gcc
261 ac_ct_DUMPBIN =
262--- 298,307 ----
263 WEB_PUBCOOKIE_LINK =
264 XGETTEXT = /usr/bin/xgettext
265 XGETTEXT_015 = /usr/bin/xgettext
266! abs_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/alpine/osdep
267! abs_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/alpine/osdep
268! abs_top_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
269! abs_top_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
270 ac_ct_AR = ar
271 ac_ct_CC = gcc
272 ac_ct_DUMPBIN =
273***************
274*** 333,339 ****
275 htmldir = ${docdir}
276 includedir = ${prefix}/include
277 infodir = ${datarootdir}/info
278! install_sh = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/install-sh
279 libdir = ${exec_prefix}/lib
280 libexecdir = ${exec_prefix}/libexec
281 localedir = ${datadir}/locale
282--- 333,339 ----
283 htmldir = ${docdir}
284 includedir = ${prefix}/include
285 infodir = ${datarootdir}/info
286! install_sh = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/install-sh
287 libdir = ${exec_prefix}/lib
288 libexecdir = ${exec_prefix}/libexec
289 localedir = ${datadir}/locale
290diff -rc alpine-2.20/imap/src/c-client/mail.c alpine-2.20.maildir/imap/src/c-client/mail.c
291*** alpine-2.20/imap/src/c-client/mail.c 2015-01-11 22:12:25.521178518 -0700
292--- alpine-2.20.maildir/imap/src/c-client/mail.c 2015-01-20 20:37:55.798011677 -0700
293***************
294*** 1011,1017 ****
295 MAILSTREAM *ts;
296 char *s,*t,tmp[MAILTMPLEN];
297 size_t i;
298! DRIVER *d;
299 /* never allow names with newlines */
300 if (s = strpbrk (mailbox,"\015\012")) {
301 MM_LOG ("Can't create mailbox with such a name",ERROR);
302--- 1011,1017 ----
303 MAILSTREAM *ts;
304 char *s,*t,tmp[MAILTMPLEN];
305 size_t i;
306! DRIVER *d, *md;
307 /* never allow names with newlines */
308 if (s = strpbrk (mailbox,"\015\012")) {
309 MM_LOG ("Can't create mailbox with such a name",ERROR);
310***************
311*** 1035,1040 ****
312--- 1035,1042 ----
313 return NIL;
314 }
315 \f
316+ /* Hack, we should do this better, but it works */
317+ for (md = maildrivers; md && strcmp (md->name, "md"); md = md->next);
318 /* see if special driver hack */
319 if ((mailbox[0] == '#') && ((mailbox[1] == 'd') || (mailbox[1] == 'D')) &&
320 ((mailbox[2] == 'r') || (mailbox[2] == 'R')) &&
321***************
322*** 1065,1070 ****
323--- 1067,1079 ----
324 (((*mailbox == '{') || (*mailbox == '#')) &&
325 (stream = mail_open (NIL,mailbox,OP_PROTOTYPE | OP_SILENT))))
326 d = stream->dtb;
327+ else if(mailbox[0] == '#'
328+ && (mailbox[1] == 'm' || mailbox[1] == 'M')
329+ && (mailbox[2] == 'd' || mailbox[2] == 'D'
330+ || mailbox[2] == 'c' || mailbox[2] == 'C')
331+ && mailbox[3] == '/'
332+ && mailbox[4] != '\0')
333+ return (*md->create)(stream, mailbox);
334 else if ((*mailbox != '{') && (ts = default_proto (NIL))) d = ts->dtb;
335 else { /* failed utterly */
336 sprintf (tmp,"Can't create mailbox %.80s: indeterminate format",mailbox);
337diff -rc alpine-2.20/imap/src/c-client/mail.h alpine-2.20.maildir/imap/src/c-client/mail.h
338*** alpine-2.20/imap/src/c-client/mail.h 2015-01-11 22:12:25.520178513 -0700
339--- alpine-2.20.maildir/imap/src/c-client/mail.h 2015-01-20 20:37:55.804011677 -0700
340***************
341*** 354,359 ****
342--- 354,363 ----
343 #define SET_SCANCONTENTS (long) 573
344 #define GET_MHALLOWINBOX (long) 574
345 #define SET_MHALLOWINBOX (long) 575
346+ #define GET_COURIERSTYLE (long) 576
347+ #define SET_COURIERSTYLE (long) 577
348+ #define SET_MDINBOXPATH (long) 578
349+ #define GET_MDINBOXPATH (long) 579
350 \f
351 /* Driver flags */
352
353diff -rc alpine-2.20/imap/src/osdep/unix/dummy.c alpine-2.20.maildir/imap/src/osdep/unix/dummy.c
354*** alpine-2.20/imap/src/osdep/unix/dummy.c 2015-01-11 22:12:25.504178437 -0700
355--- alpine-2.20.maildir/imap/src/osdep/unix/dummy.c 2015-01-20 20:37:55.833011678 -0700
356***************
357*** 103,115 ****
358 * Accepts: mailbox name
359 * Returns: our driver if name is valid, NIL otherwise
360 */
361!
362 DRIVER *dummy_valid (char *name)
363 {
364! char *s,tmp[MAILTMPLEN];
365 struct stat sbuf;
366 /* must be valid local mailbox */
367! if (name && *name && (*name != '{') && (s = mailboxfile (tmp,name))) {
368 /* indeterminate clearbox INBOX */
369 if (!*s) return &dummydriver;
370 else if (!stat (s,&sbuf)) switch (sbuf.st_mode & S_IFMT) {
371--- 103,121 ----
372 * Accepts: mailbox name
373 * Returns: our driver if name is valid, NIL otherwise
374 */
375! char * maildir_remove_root(char *);
376 DRIVER *dummy_valid (char *name)
377 {
378! char *s,tmp[MAILTMPLEN], *rname;
379 struct stat sbuf;
380+
381+ if(strlen(name) > MAILTMPLEN)
382+ name[MAILTMPLEN] = '\0';
383+
384+ strcpy(tmp, name);
385+ rname = maildir_remove_root(tmp);
386 /* must be valid local mailbox */
387! if (rname && *rname && (*rname != '{') && (s = mailboxfile (tmp,rname))) {
388 /* indeterminate clearbox INBOX */
389 if (!*s) return &dummydriver;
390 else if (!stat (s,&sbuf)) switch (sbuf.st_mode & S_IFMT) {
391***************
392*** 118,125 ****
393 return &dummydriver;
394 }
395 /* blackbox INBOX does not exist yet */
396! else if (!compare_cstring (name,"INBOX")) return &dummydriver;
397 }
398 return NIL;
399 }
400
401--- 124,132 ----
402 return &dummydriver;
403 }
404 /* blackbox INBOX does not exist yet */
405! else if (!compare_cstring (rname,"INBOX")) return &dummydriver;
406 }
407+ if(rname) fs_give((void **)&rname);
408 return NIL;
409 }
410
411***************
412*** 452,457 ****
413--- 459,466 ----
414 {
415 char *s,tmp[MAILTMPLEN];
416 long ret = NIL;
417+ if(!strncmp(mailbox,"#md/",4) || !strncmp(mailbox,"#mc/", 4))
418+ return maildir_create(stream, mailbox);
419 /* validate name */
420 if (!(compare_cstring (mailbox,"INBOX") && (s = dummy_file (tmp,mailbox)))) {
421 sprintf (tmp,"Can't create %.80s: invalid name",mailbox);
422***************
423*** 517,522 ****
424--- 526,539 ----
425 {
426 struct stat sbuf;
427 char *s,tmp[MAILTMPLEN];
428+ if (!strncmp(mailbox,"#md/",4) || !strncmp(mailbox,"#mc/", 4)
429+ || is_valid_maildir(&mailbox)){
430+ char tmp[MAILTMPLEN] = {'\0'};
431+ strcpy(tmp, mailbox);
432+ if(tmp[strlen(tmp) - 1] != '/')
433+ tmp[strlen(tmp)] = '/';
434+ return maildir_delete(stream, tmp);
435+ }
436 if (!(s = dummy_file (tmp,mailbox))) {
437 sprintf (tmp,"Can't delete - invalid name: %.80s",s);
438 MM_LOG (tmp,ERROR);
439***************
440*** 542,553 ****
441 long dummy_rename (MAILSTREAM *stream,char *old,char *newname)
442 {
443 struct stat sbuf;
444! char c,*s,tmp[MAILTMPLEN],mbx[MAILTMPLEN],oldname[MAILTMPLEN];
445 /* no trailing / allowed */
446! if (!dummy_file (oldname,old) || !(s = dummy_file (mbx,newname)) ||
447 stat (oldname,&sbuf) || ((s = strrchr (s,'/')) && !s[1] &&
448 ((sbuf.st_mode & S_IFMT) != S_IFDIR))) {
449! sprintf (mbx,"Can't rename %.80s to %.80s: invalid name",old,newname);
450 MM_LOG (mbx,ERROR);
451 return NIL;
452 }
453--- 559,581 ----
454 long dummy_rename (MAILSTREAM *stream,char *old,char *newname)
455 {
456 struct stat sbuf;
457! char c,*s,tmp[MAILTMPLEN],mbx[MAILTMPLEN],oldname[MAILTMPLEN], *rold, *rnewname;
458!
459! if(strlen(old) > MAILTMPLEN)
460! old[MAILTMPLEN] = '\0';
461!
462! if(strlen(newname) > MAILTMPLEN)
463! newname[MAILTMPLEN] = '\0';
464!
465! strcpy(tmp, old);
466! rold = maildir_remove_root(tmp);
467! strcpy(tmp, newname);
468! rnewname = maildir_remove_root(tmp);
469 /* no trailing / allowed */
470! if (!dummy_file (oldname,rold) || !(s = dummy_file (mbx,rnewname)) ||
471 stat (oldname,&sbuf) || ((s = strrchr (s,'/')) && !s[1] &&
472 ((sbuf.st_mode & S_IFMT) != S_IFDIR))) {
473! sprintf (mbx,"Can't rename %.80s to %.80s: invalid name",rold,rnewname);
474 MM_LOG (mbx,ERROR);
475 return NIL;
476 }
477***************
478*** 563,576 ****
479 }
480 }
481 /* rename of non-ex INBOX creates dest */
482! if (!compare_cstring (old,"INBOX") && stat (oldname,&sbuf))
483 return dummy_create (NIL,mbx);
484 if (rename (oldname,mbx)) {
485! sprintf (tmp,"Can't rename mailbox %.80s to %.80s: %.80s",old,newname,
486 strerror (errno));
487 MM_LOG (tmp,ERROR);
488 return NIL;
489 }
490 return T; /* return success */
491 }
492 \f
493--- 591,606 ----
494 }
495 }
496 /* rename of non-ex INBOX creates dest */
497! if (!compare_cstring (rold,"INBOX") && stat (oldname,&sbuf))
498 return dummy_create (NIL,mbx);
499 if (rename (oldname,mbx)) {
500! sprintf (tmp,"Can't rename mailbox %.80s to %.80s: %.80s",rold,rnewname,
501 strerror (errno));
502 MM_LOG (tmp,ERROR);
503 return NIL;
504 }
505+ if(rold) fs_give((void **)&rold);
506+ if(rnewname) fs_give((void **)&rnewname);
507 return T; /* return success */
508 }
509 \f
510diff -rc alpine-2.20/imap/src/osdep/unix/maildir.c alpine-2.20.maildir/imap/src/osdep/unix/maildir.c
511*** alpine-2.20/imap/src/osdep/unix/maildir.c 2015-02-03 22:28:22.632016232 -0700
512--- alpine-2.20.maildir/imap/src/osdep/unix/maildir.c 2015-01-21 20:06:56.462383814 -0700
513***************
514*** 0 ****
515--- 1,2682 ----
516+ /*
517+ * Maildir driver for Alpine 2.20
518+ *
519+ * Written by Eduardo Chappa <chappa@gmx.com>
520+ * Last Update: January 21, 2015
521+ *
522+ */
523+
524+ #include <stdio.h>
525+ #include <ctype.h>
526+ #include <errno.h>
527+ extern int errno; /* just in case */
528+ #include "mail.h"
529+ #include <pwd.h>
530+ #include <sys/stat.h>
531+ #include <sys/time.h>
532+ #include "osdep.h"
533+ #include "rfc822.h"
534+ #include "fdstring.h"
535+ #include "misc.h"
536+ #include "dummy.h"
537+ #include "maildir.h"
538+
539+ /* Driver dispatch used by MAIL */
540+ DRIVER maildirdriver = {
541+ "md", /* driver name, yes it's md, not maildir */
542+ DR_MAIL|DR_LOCAL|DR_NAMESPACE|DR_DIRFMT, /* driver flags */
543+ (DRIVER *) NIL, /* next driver */
544+ maildir_valid, /* mailbox is valid for us */
545+ maildir_parameters, /* manipulate parameters */
546+ NIL, /* scan mailboxes */
547+ maildir_list, /* find mailboxes */
548+ maildir_lsub, /* find subscribed mailboxes */
549+ maildir_sub, /* subscribe to mailbox */
550+ maildir_unsub, /* unsubscribe from mailbox */
551+ maildir_create, /* create mailbox */
552+ maildir_delete, /* delete mailbox */
553+ maildir_rename, /* rename mailbox */
554+ mail_status_default, /* status of mailbox */
555+ maildir_open, /* open mailbox */
556+ maildir_close, /* close mailbox */
557+ maildir_fast, /* fetch message "fast" attributes */
558+ NIL, /* fetch message flags */
559+ NIL, /* fetch overview */
560+ NIL, /* fetch message structure */
561+ maildir_header, /* fetch message header */
562+ maildir_text, /* fetch message body */
563+ NIL, /* fetch partial message text */
564+ NIL, /* unique identifier */
565+ NIL, /* message number */
566+ NIL, /* modify flags */
567+ maildir_flagmsg, /* per-message modify flags */
568+ NIL, /* search for message based on criteria */
569+ NIL, /* sort messages */
570+ NIL, /* thread messages */
571+ maildir_ping, /* ping mailbox to see if still alive */
572+ maildir_check, /* check for new messages */
573+ maildir_expunge, /* expunge deleted messages */
574+ maildir_copy, /* copy messages to another mailbox */
575+ maildir_append, /* append string message to mailbox */
576+ NIL /* garbage collect stream */
577+ };
578+
579+
580+ DRIVER courierdriver = {
581+ "mc", /* Why a separate driver? So that createproto will work */
582+ DR_MAIL|DR_LOCAL|DR_NAMESPACE|DR_DIRFMT, /* driver flags */
583+ (DRIVER *) NIL, /* next driver */
584+ maildir_valid, /* mailbox is valid for us */
585+ maildir_parameters, /* manipulate parameters */
586+ NIL, /* scan mailboxes */
587+ courier_list, /* find mailboxes */
588+ maildir_lsub, /* find subscribed mailboxes */
589+ maildir_sub, /* subscribe to mailbox */
590+ maildir_unsub, /* unsubscribe from mailbox */
591+ maildir_create, /* create mailbox */
592+ maildir_delete, /* delete mailbox */
593+ maildir_rename, /* rename mailbox */
594+ mail_status_default, /* status of mailbox */
595+ maildir_open, /* open mailbox */
596+ maildir_close, /* close mailbox */
597+ maildir_fast, /* fetch message "fast" attributes */
598+ NIL, /* fetch message flags */
599+ NIL, /* fetch overview */
600+ NIL, /* fetch message structure */
601+ maildir_header, /* fetch message header */
602+ maildir_text, /* fetch message body */
603+ NIL, /* fetch partial message text */
604+ NIL, /* unique identifier */
605+ NIL, /* message number */
606+ NIL, /* modify flags */
607+ maildir_flagmsg, /* per-message modify flags */
608+ NIL, /* search for message based on criteria */
609+ NIL, /* sort messages */
610+ NIL, /* thread messages */
611+ maildir_ping, /* ping mailbox to see if still alive */
612+ maildir_check, /* check for new messages */
613+ maildir_expunge, /* expunge deleted messages */
614+ maildir_copy, /* copy messages to another mailbox */
615+ maildir_append, /* append string message to mailbox */
616+ NIL /* garbage collect stream */
617+ };
618+
619+ MAILSTREAM maildirproto = {&maildirdriver}; /* prototype stream */
620+ MAILSTREAM courierproto = {&courierdriver}; /* prototype stream */
621+
622+ long maildir_dirfmttest (char *name)
623+ {
624+ int i;
625+ for (i = 0; mdstruct[i] && strcmp(name, mdstruct[i]); i++);
626+ return (i < EndDir) || !strcmp(name, MDDIR)
627+ || !strncmp(name, MDUIDLAST, strlen(MDUIDLAST))
628+ || !strncmp(name, MDUIDTEMP, strlen(MDUIDTEMP)) ? LONGT : NIL;
629+ }
630+
631+ void
632+ md_domain_name(void)
633+ {
634+ int i, j;
635+
636+ strcpy(mdlocaldomain, mylocalhost ());
637+ for (i = 0; mdlocaldomain[i] != '\0' ;)
638+ if(mdlocaldomain[i] == '/' || mdlocaldomain[i] == ':'){
639+ for(j = strlen(mdlocaldomain); j >= i; j--)
640+ mdlocaldomain[j+4] = mdlocaldomain[j];
641+ mdlocaldomain[i++] = '\\';
642+ mdlocaldomain[i++] = '0';
643+ if(mdlocaldomain[i] == '/'){
644+ mdlocaldomain[i++] = '5';
645+ mdlocaldomain[i++] = '7';
646+ } else {
647+ mdlocaldomain[i++] = '7';
648+ mdlocaldomain[i++] = '2';
649+ }
650+ }
651+ else
652+ i++;
653+ }
654+
655+ char *
656+ myrootdir(char *name)
657+ {
658+ return myhomedir();
659+ }
660+
661+ char *
662+ mdirpath(void)
663+ {
664+ char *path = maildir_parameters(GET_MDINBOXPATH, NIL);
665+ return path ? (path[0] ? path : ".") : "Maildir";
666+ }
667+
668+ /* remove the "#md/" or "#mc/" part from a folder name
669+ * memory freed by caller
670+ */
671+ char *
672+ maildir_remove_root (char *name)
673+ {
674+ int courier = IS_COURIER(name), offset;
675+ char realname[MAILTMPLEN];
676+
677+ offset = maildir_valid_name(name) ? (name[3] == '/' ? 4 : 3) : 0;
678+ if(courier)
679+ courier_realname(name+offset, realname);
680+ else
681+ strcpy(realname, name+offset);
682+ return cpystr(realname);
683+ }
684+
685+
686+ /* Check validity of the name, we accept:
687+ * a) #md/directory/folder
688+ * b) #md/inbox
689+ * A few considerations: We can only accept as valid
690+ * a) names that start with #md/ and the directory exists or
691+ * b) names that do not start with #md/ but are maildir directories (have
692+ * the /cur, /tmp and /new structure)
693+ */
694+ int maildir_valid_name (char *name)
695+ {
696+ char tmpname[MAILTMPLEN] = {'\0'};
697+
698+ if (mdfpath)
699+ fs_give((void **)&mdfpath);
700+ if (name && (name[0] != '#'))
701+ snprintf(tmpname, sizeof(tmpname), "%s%s",MDPREFIX(CCLIENT), name);
702+ mdfpath = cpystr(tmpname[0] ? tmpname : name);
703+
704+ return IS_CCLIENT(name) || IS_COURIER(name);
705+ }
706+
707+ /* Check if the directory whose path is given by name is a valid maildir
708+ * directory (contains /cur, /tmp and /new)
709+ */
710+ int maildir_valid_dir (char *name)
711+ {
712+ int len;
713+ DirNamesType i;
714+ struct stat sbuf;
715+ char tmp[MAILTMPLEN];
716+
717+ if(name[strlen(name) - 1] == '/')
718+ name[strlen(name) - 1] = '\0';
719+ len = strlen(name);
720+ for (i = Cur; i != EndDir; i++){
721+ MDFLD(tmp, name, i);
722+ if (stat(tmp, &sbuf) < 0 || !S_ISDIR(sbuf.st_mode))
723+ break;
724+ }
725+ name[len] = '\0';
726+ return (i == EndDir) ? T : NIL;
727+ }
728+
729+ void courier_realname(char *name, char *realname)
730+ {
731+ int i,j;
732+
733+ if(!name)
734+ return;
735+
736+ for (i = 0, j = 0; i < MAILTMPLEN && j < strlen(name); j++, i++){
737+ realname[i] = name[j];
738+ if(name[j] == '/' && name[j+1] != '.' && name[j+1] != '%'
739+ && name[j+1] != '*')
740+ realname[++i] = '.';
741+ }
742+ if(realname[i-1] == '.')
743+ i--;
744+ realname[i] = '\0';
745+ }
746+
747+
748+ /* given a maildir folder, return its path. Memory freed by caller. Directory
749+ * does not contain the trailing slash "/". On error NULL is returned.
750+ */
751+ int maildir_file_path (char *name, char *tmp, size_t sizeoftmp)
752+ {
753+ char *maildirpath = mdirpath(), *rname;
754+ int courier = IS_COURIER(name);
755+
756+ /* There are several ways in which the path can come, so we will handle
757+ them here. First we deal with #mc/ or #md/ prefix by removing the
758+ prefix, if any */
759+
760+ if(strlen(name) >= MAILTMPLEN)
761+ name[MAILTMPLEN] = '\0';
762+ strcpy(tmp, name);
763+ rname = maildir_remove_root(tmp);
764+ tmp[0] = '\0'; /* just in case something fails */
765+
766+ if (strlen(myrootdir(rname)) +
767+ max(strlen(rname), strlen(maildirpath)) > sizeoftmp){
768+ errno = ENAMETOOLONG;
769+ snprintf(tmp, sizeoftmp, "Error opening \"%s\": %s", rname, strerror (errno));
770+ mm_log(tmp,ERROR);
771+ if(rname) fs_give((void **)&rname);
772+ return NIL;
773+ }
774+
775+ /* There are two ways in which the name can come here, either as a
776+ full path or not. If it is not a full path it can come in two ways,
777+ either as a file system path (Maildir/.Drafts) or as a maildir path
778+ (INBOX.Drafts)
779+ */
780+
781+ if(*rname == '/'){ /* full path */
782+ strncpy(tmp, rname, sizeoftmp); /* do nothing */
783+ tmp[sizeoftmp-1] = '\0';
784+ }
785+ else
786+ snprintf (tmp, sizeoftmp, "%s/%s%s%s", myrootdir (rname),
787+ strncmp (ucase (strcpy (tmp, rname)), "INBOX", 5)
788+ ? rname : maildirpath,
789+ strncmp (ucase (strcpy (tmp, rname)), "INBOX", 5)
790+ ? "" : (courier ? "/" : ""),
791+ strncmp (ucase (strcpy (tmp, rname)), "INBOX", 5)
792+ ? "" : (*(rname+5) == MDSEPARATOR(courier) ? rname+5 : ""));
793+ if(rname) fs_give((void **)&rname);
794+ return tmp[0] ? T : NIL;
795+ }
796+
797+ /* This function is given a full path for a mailbox and returns
798+ * if it is a valid maildir transformed to canonical notation
799+ */
800+ int
801+ is_valid_maildir (char **name)
802+ {
803+ if (!strncmp(*name, myrootdir (*name), strlen(myrootdir(*name)))){
804+ (*name) += strlen(myrootdir(*name));
805+ if (**name == '/') (*name)++;
806+ }
807+ return maildir_valid(*name) ? T : NIL;
808+ }
809+
810+ /* Check validity of mailbox. This routine does not send errors to log, other
811+ * routines calling this one may do so, though
812+ */
813+
814+ DRIVER *maildir_valid (char *name)
815+ {
816+ char tmpname[MAILTMPLEN];
817+
818+ maildir_file_path(name, tmpname, sizeof(tmpname));
819+
820+ return maildir_valid_dir(tmpname)
821+ ? (IS_COURIER(name) ? &courierdriver : &maildirdriver) : NIL;
822+ }
823+
824+ void maildir_fast (MAILSTREAM *stream,char *sequence,long flags)
825+ {
826+ unsigned long i;
827+ MESSAGECACHE *elt;
828+ /* get sequence */
829+ if (stream && LOCAL && ((flags & FT_UID) ?
830+ mail_uid_sequence (stream,sequence) :
831+ mail_sequence (stream,sequence)))
832+ for (i = 1L; i <= stream->nmsgs; i++) {
833+ if ((elt = mail_elt (stream,i))->sequence && (elt->valid = T) &&
834+ !(elt->day && elt->rfc822_size)) {
835+ ENVELOPE **env = NIL;
836+ ENVELOPE *e = NIL;
837+ if (!stream->scache) env = &elt->private.msg.env;
838+ else if (stream->msgno == i) env = &stream->env;
839+ else env = &e;
840+ if (!*env || !elt->rfc822_size) {
841+ STRING bs;
842+ unsigned long hs;
843+ char *ht = (*stream->dtb->header) (stream,i,&hs,NIL);
844+
845+ if (!*env) rfc822_parse_msg (env,NIL,ht,hs,NIL,BADHOST,
846+ stream->dtb->flags);
847+ if (!elt->rfc822_size) {
848+ (*stream->dtb->text) (stream,i,&bs,FT_PEEK);
849+ elt->rfc822_size = hs + SIZE (&bs) - GETPOS (&bs);
850+ }
851+ }
852+
853+ if (!elt->day && *env && (*env)->date)
854+ mail_parse_date (elt,(*env)->date);
855+
856+ if (!elt->day) elt->day = elt->month = 1;
857+ mail_free_envelope (&e);
858+ }
859+ }
860+ }
861+
862+ int
863+ maildir_eliminate_duplicate (char *name, struct direct ***flist, unsigned long *nfiles)
864+ {
865+ int i, j, k, error = 0, scanr;
866+ char new[MAILTMPLEN], old[MAILTMPLEN], tmp[MAILTMPLEN], *str;
867+ struct direct **names = NIL;
868+
869+ if((scanr = maildir_doscandir(name, &names, CCLIENT)) < 0)
870+ return -1;
871+
872+ if(nfiles) *nfiles = scanr;
873+ for(i = 0, j = 1, k = 0; j < scanr; i++, j++){
874+ if(k)
875+ names[i] = names[i+k];
876+ if(same_maildir_file(names[i]->d_name, names[j]->d_name)){
877+ int d, f, r, s;
878+ maildir_getflag(names[i]->d_name, &d, &f, &r, &s, NIL);
879+ snprintf(old, sizeof(old), "%s/%s", name, names[i]->d_name);
880+ snprintf(new, sizeof(new), "%s/.%s", name, names[i]->d_name);
881+ if(rename(old, new) < 0 && errno != EEXIST)
882+ error++;
883+ if(!error){
884+ for(; j < scanr
885+ && same_maildir_file(names[i]->d_name, names[j]->d_name)
886+ ; j++, k++){
887+ maildir_getflag(names[j]->d_name, (d ? NIL : &d),
888+ (f ? NIL : &f), (r ? NIL : &r), (s ? NIL : &s), NIL);
889+ snprintf(tmp, sizeof(tmp), "%s/%s", name, names[j]->d_name);
890+ if(unlink(tmp) < 0){ /* Hmmm... a problem, let's see */
891+ struct stat sbuf;
892+ if (stat(tmp, &sbuf) == 0 && (sbuf.st_mode & S_IFMT) == S_IFREG)
893+ error++;
894+ }
895+ }
896+ if((str = strrchr(names[i]->d_name,FLAGSEP)) != NULL) *str = '\0';
897+ snprintf (old, sizeof(old), "%s/%s%s%s%s%s%s", name, names[i]->d_name, MDSEP(2),
898+ MDFLAG(Draft, d), MDFLAG(Flagged, f), MDFLAG(Replied, r),
899+ MDFLAG(Seen, s));
900+ if(rename(new, old) < 0)
901+ error++;
902+ }
903+ }
904+
905+ }
906+ if(k > 0)
907+ fs_give((void **)&names);
908+ else
909+ *flist = names;
910+ return error ? -1 : k;
911+ }
912+
913+ int
914+ maildir_doscandir(char *name, struct direct ***flist, int flag)
915+ {
916+ return scandir(name, flist,
917+ flag == CCLIENT ? maildir_select : courier_dir_select,
918+ flag == CCLIENT ? maildir_namesort : courier_dir_sort);
919+ }
920+
921+ /*
922+ * return all files in a given directory. This is a separate call
923+ * so that if there are warnings during compilation this only appears once.
924+ */
925+ unsigned long
926+ maildir_scandir (char *name, struct direct ***flist,
927+ unsigned long *nfiles, int *scand, int flag)
928+ {
929+ struct stat sbuf;
930+ int rv = -2; /* impossible value */
931+
932+ if (scand)
933+ *scand = -1; /* assume error for safety */
934+ *nfiles = 0;
935+ if((stat(name,&sbuf) < 0)
936+ || (flag == CCLIENT
937+ && ((rv = maildir_eliminate_duplicate(name, flist, nfiles)) < 0)))
938+ return 0L;
939+
940+ if (scand && (rv > 0 || rv == -2))
941+ *nfiles = maildir_doscandir(name, flist, flag);
942+
943+ if(scand) *scand = *nfiles;
944+
945+ return (unsigned long) sbuf.st_ctime;
946+ }
947+
948+ /* Does a message with given name exists (or was it removed)?
949+ * Returns: 1 - yes, such message exist,
950+ * 0 - No, that message does not exist anymore
951+ *
952+ * Parameters: stream, name of mailbox, new name if his message does not
953+ * exist.
954+ */
955+
956+ int maildir_message_exists(MAILSTREAM *stream, char *name, char *newfile)
957+ {
958+ char tmp[MAILTMPLEN];
959+ int gotit = NIL;
960+ DIR *dir;
961+ struct direct *d;
962+ struct stat sbuf;
963+
964+ /* First check directly if it exists, if not there, look for it */
965+ snprintf(tmp, sizeof(tmp), "%s/%s", LOCAL->path[Cur], name);
966+ if ((stat(tmp, &sbuf) == 0) && ((sbuf.st_mode & S_IFMT) == S_IFREG))
967+ return T;
968+
969+ if (!(dir = opendir (LOCAL->path[Cur])))
970+ return NIL;
971+
972+ while ((d = readdir(dir)) && gotit == NIL){
973+ if (d->d_name[0] == '.')
974+ continue;
975+ if (same_maildir_file(d->d_name, name)){
976+ gotit = T;
977+ strcpy(newfile, d->d_name);
978+ }
979+ }
980+ closedir(dir);
981+ return gotit;
982+ }
983+
984+ /* Maildir open */
985+
986+ MAILSTREAM *maildir_open (MAILSTREAM *stream)
987+ {
988+ char tmp[MAILTMPLEN];
989+ struct stat sbuf;
990+
991+ if (!stream) return &maildirproto;
992+ if (stream->local) fatal ("maildir recycle stream");
993+ md_domain_name(); /* get domain name for maildir files in mdlocaldomain */
994+ if(mypid == (pid_t) 0)
995+ mypid = getpid();
996+ if (!stream->rdonly){
997+ stream->perm_seen = stream->perm_deleted = stream->perm_flagged =
998+ stream->perm_answered = stream->perm_draft = T;
999+ }
1000+ stream->local = (MAILDIRLOCAL *) fs_get (sizeof (MAILDIRLOCAL));
1001+ memset(LOCAL, 0, sizeof(MAILDIRLOCAL));
1002+ LOCAL->fd = -1;
1003+
1004+ LOCAL->courier = IS_COURIER(stream->mailbox);
1005+ strcpy(tmp, stream->mailbox);
1006+ if (maildir_file_path (stream->mailbox, tmp, sizeof(tmp)))
1007+ LOCAL->dir = cpystr (tmp);
1008+ LOCAL->candouid = maildir_can_assign_uid(stream);
1009+ maildir_read_uid(stream, &stream->uid_last, &stream->uid_validity);
1010+ if (LOCAL->dir){
1011+ LOCAL->path = (char **) fs_get(EndDir*sizeof(char *));
1012+ MDFLD(tmp, LOCAL->dir, Cur); LOCAL->path[Cur] = cpystr (tmp);
1013+ MDFLD(tmp, LOCAL->dir, New); LOCAL->path[New] = cpystr (tmp);
1014+ MDFLD(tmp, LOCAL->dir, Tmp); LOCAL->path[Tmp] = cpystr (tmp);
1015+ if (stat (LOCAL->path[Cur],&sbuf) < 0) {
1016+ snprintf (tmp, sizeof(tmp), "Can't open folder %s: %s",
1017+ stream->mailbox,strerror (errno));
1018+ mm_log (tmp,ERROR);
1019+ maildir_close(stream, 0);
1020+ return NIL;
1021+ }
1022+ }
1023+
1024+ if(maildir_file_path (stream->mailbox, tmp, sizeof(tmp))){
1025+ fs_give ((void **) &stream->mailbox);
1026+ stream->mailbox = cpystr(tmp);
1027+ }
1028+
1029+ LOCAL->buf = (char *) fs_get (CHUNKSIZE);
1030+ LOCAL->buflen = CHUNKSIZE - 1;
1031+ stream->sequence++;
1032+ stream->nmsgs = stream->recent = 0L;
1033+
1034+ maildir_parse_folder(stream, 1);
1035+
1036+ return stream;
1037+ }
1038+
1039+ /* Maildir initial parsing of the folder */
1040+ void
1041+ maildir_parse_folder (MAILSTREAM *stream, int full)
1042+ {
1043+ char tmp[MAILTMPLEN];
1044+ struct direct **namescur = NIL, **namesnew = NIL;
1045+ unsigned long i, nfilescur = 0L, nfilesnew = 0L, oldpos, newpos, total;
1046+ int scan_err, rescan, loop = 0;
1047+
1048+ if (!stream) /* what??? */
1049+ return;
1050+
1051+ MM_CRITICAL(stream);
1052+
1053+ maildir_scandir (LOCAL->path[New], &namesnew, &nfilesnew, &scan_err, CCLIENT);
1054+ if (scan_err < 0)
1055+ maildir_abort(stream);
1056+
1057+ /* Scan old messages first, escoba! */
1058+ if(stream->rdonly ||
1059+ (LOCAL && ((maildir_initial_check(stream, Cur) == 0)
1060+ || nfilesnew > 0L))){
1061+ LOCAL->scantime = maildir_scandir (LOCAL->path[Cur], &namescur, &nfilescur,
1062+ &scan_err, CCLIENT);
1063+ if (scan_err < 0){
1064+ if(namesnew){
1065+ for(i = 0L; i < nfilesnew; i++)
1066+ fs_give((void **)&namesnew[i]);
1067+ fs_give((void **) &namesnew);
1068+ }
1069+ maildir_abort(stream);
1070+ }
1071+ }
1072+ if(LOCAL && (maildir_initial_check(stream, New) == 0)
1073+ && (nfilescur > 0L)){
1074+ while(LOCAL && loop < 10){
1075+ if(nfilesnew == 0L)
1076+ maildir_scandir (LOCAL->path[New], &namesnew, &nfilesnew, &scan_err, CCLIENT);
1077+ if (scan_err < 0){
1078+ if(namesnew){
1079+ for(i = 0L; i < nfilesnew; i++)
1080+ fs_give((void **)&namesnew[i]);
1081+ fs_give((void **) &namesnew);
1082+ }
1083+ maildir_abort(stream);
1084+ break;
1085+ }
1086+ for(i = 0L, rescan = 0, newpos = oldpos = 0L;
1087+ newpos < nfilescur && i < nfilesnew; i++){
1088+ if(maildir_message_in_list(namesnew[i]->d_name, namescur, oldpos,
1089+ nfilescur - 1L, &newpos)){
1090+ oldpos = newpos;
1091+ snprintf(tmp, sizeof(tmp), "%s/%s", LOCAL->path[New], namesnew[i]->d_name);
1092+ if(unlink(tmp) < 0)
1093+ scan_err = -1;
1094+ rescan++;
1095+ }
1096+ else
1097+ newpos = oldpos;
1098+ }
1099+ if(scan_err < 0)
1100+ maildir_abort(stream);
1101+ if(rescan == 0)
1102+ break;
1103+ else{ /* restart */
1104+ if(namesnew){
1105+ for(i = 0L; i < nfilesnew; i++)
1106+ fs_give((void **)&namesnew[i]);
1107+ fs_give((void **) &namesnew);
1108+ }
1109+ nfilesnew = 0L;
1110+ loop++;
1111+ }
1112+ }
1113+ }
1114+ if(loop == 10)
1115+ maildir_abort(stream);
1116+ if(LOCAL){
1117+ if(stream->rdonly)
1118+ stream->recent = 0L;
1119+ total = namescur || stream->rdonly
1120+ ? maildir_parse_dir(stream, 0L, Cur, namescur,
1121+ nfilescur, full) : stream->nmsgs;
1122+ stream->nmsgs = maildir_parse_dir(stream, total, New, namesnew,
1123+ nfilesnew, full);
1124+ }
1125+ if(namesnew){
1126+ for(i = 0L; i < nfilesnew; i++)
1127+ fs_give((void **)&namesnew[i]);
1128+ fs_give((void **) &namesnew);
1129+ }
1130+ if(namescur){
1131+ for(i = 0L; i < nfilescur; i++)
1132+ fs_give((void **)&namescur[i]);
1133+ fs_give((void **) &namescur);
1134+ }
1135+ MM_NOCRITICAL(stream);
1136+ }
1137+
1138+ int
1139+ maildir_initial_check (MAILSTREAM *stream, DirNamesType dirtype)
1140+ {
1141+ char *tmp;
1142+ struct stat sbuf;
1143+
1144+ if (access (LOCAL->path[dirtype], R_OK|W_OK|X_OK) != 0){
1145+ maildir_abort(stream);
1146+ return -1;
1147+ }
1148+
1149+ if (dirtype != New &&
1150+ (stat(LOCAL->path[Cur], &sbuf) < 0 || sbuf.st_ctime == LOCAL->scantime))
1151+ return -1;
1152+ return 0;
1153+ }
1154+
1155+
1156+ /* Return the number of messages in the directory, while filling the
1157+ * elt structure.
1158+ */
1159+
1160+ unsigned long
1161+ maildir_parse_dir(MAILSTREAM *stream, unsigned long nmsgs,
1162+ DirNamesType dirtype, struct direct **names,
1163+ unsigned long nfiles, int full)
1164+ {
1165+ char tmp[MAILTMPLEN], file[MAILTMPLEN], newfile[MAILTMPLEN], *mdstr;
1166+ struct stat sbuf;
1167+ unsigned long i, new = 0L, l, uid_last;
1168+ unsigned long recent = stream ? stream->recent : 0L;
1169+ int d = 0, f = 0, r = 0, s = 0, t = 0;
1170+ int we_compute, in_list;
1171+ int silent = stream ? stream->silent : NIL;
1172+ MESSAGECACHE *elt;
1173+
1174+ if (dirtype == Cur && !stream->rdonly)
1175+ for (i = 1L; i <= stream->nmsgs;){
1176+ elt = mail_elt(stream, i);
1177+ in_list = elt && elt->private.spare.ptr && nfiles > 0L
1178+ ? (MDPOS(elt) < nfiles
1179+ ? same_maildir_file(MDFILE(elt), names[MDPOS(elt)]->d_name)
1180+ : NIL)
1181+ || maildir_message_in_list(MDFILE(elt), names, 0L,
1182+ nfiles - 1L, &MDPOS(elt))
1183+ : NIL;
1184+ if (!in_list){
1185+ if (elt->private.spare.ptr)
1186+ maildir_free_file ((void **) &elt->private.spare.ptr);
1187+
1188+ if (elt->recent) --recent;
1189+ mail_expunged(stream,i);
1190+ }
1191+ else i++;
1192+ }
1193+
1194+ stream->silent = T;
1195+ uid_last = 0L;
1196+ for (we_compute = 0, i = l = 1L; l <= nfiles; l++){
1197+ unsigned long pos, uid;
1198+ if (dirtype == New && !stream->rdonly){ /* move new messages to cur */
1199+ pos = l - 1L;
1200+ snprintf (file, sizeof(file), "%s/%s", LOCAL->path[New], names[pos]->d_name);
1201+ if(lstat(file,&sbuf) == 0)
1202+ switch(sbuf.st_mode & S_IFMT){
1203+ case S_IFREG:
1204+ strcpy(tmp, names[pos]->d_name);
1205+ if((mdstr = strstr(tmp,MDSEP(3)))
1206+ || (mdstr = strstr(tmp,MDSEP(2))))
1207+ *(mdstr+1) = '2';
1208+ else
1209+ strcat(tmp, MDSEP(2));
1210+ snprintf(newfile, sizeof(newfile), "%s/%s", LOCAL->path[Cur], tmp);
1211+ if(rename (file, newfile) != 0){
1212+ mm_log("Unable to read new mail!", WARN);
1213+ continue;
1214+ }
1215+ unlink (file);
1216+ new++;
1217+ break;
1218+ case S_IFLNK: /* clean up, clean up, everybody, everywhere */
1219+ if(unlink(file) < 0){
1220+ if(LOCAL->link == NIL){
1221+ mm_log("Unable to remove symbolic link", WARN);
1222+ LOCAL->link = T;
1223+ }
1224+ }
1225+ continue;
1226+ break;
1227+ default:
1228+ if(LOCAL && LOCAL->link == NIL){
1229+ mm_log("Unrecognized file or link in folder", WARN);
1230+ LOCAL->link = T;
1231+ }
1232+ continue;
1233+ break;
1234+ }
1235+ }
1236+ mail_exists(stream, i + nmsgs);
1237+ elt = mail_elt(stream, i + nmsgs);
1238+ pos = (elt && elt->private.spare.ptr) ? MDPOS(elt) : l - 1L;
1239+ if (dirtype == New) elt->recent = T;
1240+ maildir_getflag(names[pos]->d_name, &d, &f, &r ,&s, &t);
1241+ if (elt->private.spare.ptr)
1242+ maildir_free_file_only ((void **)&elt->private.spare.ptr);
1243+ else{
1244+ maildir_get_file((MAILDIRFILE **)&elt->private.spare.ptr);
1245+ we_compute++;
1246+ }
1247+ MDFILE(elt) = cpystr(names[pos]->d_name);
1248+ MDPOS(elt) = pos;
1249+ MDLOC(elt) = dirtype;
1250+ if (dirtype == Cur){ /* deal with UIDs */
1251+ if(elt->private.uid == 0L)
1252+ elt->private.uid = maildir_get_uid(MDFILE(elt));
1253+ if(elt->private.uid <= uid_last){
1254+ uid = (we_compute ? uid_last : stream->uid_last) + 1L;
1255+ if(LOCAL->candouid)
1256+ maildir_assign_uid(stream, i + nmsgs, uid);
1257+ else
1258+ elt->private.uid = uid;
1259+ }
1260+ else
1261+ uid = elt->private.uid;
1262+ uid_last = uid;
1263+ if(uid_last > stream->uid_last)
1264+ stream->uid_last = uid_last;
1265+ }
1266+ if(dirtype == New && !stream->rdonly){
1267+ maildir_free_file_only((void **)&elt->private.spare.ptr);
1268+ MDFILE(elt) = cpystr(tmp);
1269+ MDSIZE(elt) = sbuf.st_size;
1270+ MDMTIME(elt) = sbuf.st_mtime;
1271+ MDLOC(elt) = Cur;
1272+ }
1273+ if (elt->draft != d || elt->flagged != f ||
1274+ elt->answered != r || elt->seen != s || elt->deleted != t){
1275+ elt->draft = d; elt->flagged = f; elt->answered = r;
1276+ elt->seen = s; elt->deleted = t;
1277+ if (!we_compute && !stream->rdonly)
1278+ MM_FLAGS(stream, i+nmsgs);
1279+ }
1280+ maildir_get_date(stream, i+nmsgs);
1281+ elt->valid = T;
1282+ i++;
1283+ }
1284+ stream->silent = silent;
1285+ if(LOCAL->candouid && dirtype == Cur)
1286+ maildir_read_uid(stream, NULL, &stream->uid_validity);
1287+ if (dirtype == New && stream->rdonly)
1288+ new = nfiles;
1289+ mail_exists(stream, nmsgs + ((dirtype == New) ? new : nfiles));
1290+ mail_recent(stream, recent + ((dirtype == New) ? new : 0L));
1291+
1292+ return (nmsgs + (dirtype == New ? new : nfiles));
1293+ }
1294+
1295+ long maildir_ping (MAILSTREAM *stream)
1296+ {
1297+ maildir_parse_folder(stream, 0);
1298+ if(stream && LOCAL){
1299+ if(LOCAL->candouid < 0)
1300+ LOCAL->candouid++;
1301+ else if(LOCAL->candouid)
1302+ maildir_uid_renew_tempfile(stream);
1303+ else /* try again to get uids */
1304+ LOCAL->candouid = maildir_can_assign_uid(stream);
1305+ }
1306+ return stream && LOCAL ? LONGT : NIL;
1307+ }
1308+
1309+ int maildir_select (const struct direct *name)
1310+ {
1311+ return (name->d_name[0] != '.');
1312+ }
1313+
1314+ /*
1315+ * Unfortunately, there is no way to sort by arrival in this driver, this
1316+ * means that opening a folder in this driver using the scandir function
1317+ * will always make this driver slower than any driver that has a natural
1318+ * way of sorting by arrival (like a flat file format, "mbox", "mbx", etc).
1319+ */
1320+ int maildir_namesort (const struct direct **d1, const struct direct **d2)
1321+ {
1322+ const struct direct *e1 = *(const struct direct **) d1;
1323+ const struct direct *e2 = *(const struct direct **) d2;
1324+
1325+ return comp_maildir_file((char *) e1->d_name, (char *) e2->d_name);
1326+ }
1327+
1328+ /* Maildir close */
1329+
1330+ void maildir_close (MAILSTREAM *stream, long options)
1331+ {
1332+ MESSAGECACHE *elt;
1333+ unsigned long i;
1334+ int silent = stream ? stream->silent : 0;
1335+ mailcache_t mc = (mailcache_t) mail_parameters (NIL,GET_CACHE,NIL);
1336+
1337+ if (!stream) return;
1338+
1339+ for (i = 1L; i <= stream->nmsgs; i++)
1340+ if((elt = (MESSAGECACHE *) (*mc)(stream,i,CH_ELT)) && elt->private.spare.ptr)
1341+ maildir_free_file ((void **) &elt->private.spare.ptr);
1342+ stream->silent = T;
1343+ if (options & CL_EXPUNGE) maildir_expunge (stream, NIL, NIL);
1344+ maildir_abort(stream);
1345+ if (mdfpath) fs_give((void **)&mdfpath);
1346+ if (mypid) mypid = (pid_t) 0;
1347+ stream->silent = silent;
1348+ }
1349+
1350+ void maildir_check (MAILSTREAM *stream)
1351+ {
1352+ if (maildir_ping (stream)) mm_log ("Check completed",(long) NIL);
1353+ }
1354+
1355+ long maildir_text (MAILSTREAM *stream,unsigned long msgno,STRING *bs, long flags)
1356+ {
1357+ char tmp[MAILTMPLEN];
1358+ unsigned long i;
1359+ MESSAGECACHE *elt;
1360+ char *s;
1361+ /* UID call "impossible" */
1362+ if (flags & FT_UID || !LOCAL) return NIL;
1363+ elt = mail_elt (stream, msgno);
1364+
1365+ if (!(flags & FT_PEEK) && !elt->seen){
1366+ elt->seen = T;
1367+ maildir_flagmsg (stream, elt);
1368+ MM_FLAGS(stream, elt->msgno);
1369+ }
1370+
1371+ MSGPATH(tmp, LOCAL->dir, MDFILE(elt), MDLOC(elt));
1372+ if (LOCAL->fd < 0) /* if file closed ? */
1373+ LOCAL->fd = open(tmp,O_RDONLY,NIL);
1374+
1375+ if (LOCAL->fd < 0 && (errno == EACCES || errno == ENOENT)){
1376+ INIT (bs, mail_string, "", 0);
1377+ elt->rfc822_size = 0L;
1378+ return NIL;
1379+ }
1380+
1381+ s = maildir_text_work(stream, elt, &i, flags);
1382+ INIT (bs, mail_string, s, i);
1383+ return LONGT;
1384+ }
1385+
1386+ char *maildir_text_work (MAILSTREAM *stream,MESSAGECACHE *elt,
1387+ unsigned long *length,long flags)
1388+ {
1389+ FDDATA d;
1390+ STRING bs;
1391+ char *s,tmp[CHUNK];
1392+ unsigned long msgno = elt->msgno;
1393+ static int try = 0;
1394+
1395+ if (length)
1396+ *length = 0L;
1397+ LOCAL->buf[0] = '\0';
1398+
1399+ MSGPATH(tmp, LOCAL->dir, MDFILE(elt), MDLOC(elt));
1400+ if (LOCAL->fd < 0) /* if file closed ? */
1401+ LOCAL->fd = open(tmp,O_RDONLY,NIL);
1402+
1403+ if (LOCAL->fd < 0){ /* flag change? */
1404+ if (try < 5){
1405+ try++;
1406+ if (maildir_update_elt_maildirp(stream, msgno) > 0)
1407+ try = 0;
1408+ return maildir_text_work(stream, mail_elt(stream, msgno),length, flags);
1409+ }
1410+ try = 0;
1411+ return NULL;
1412+ }
1413+
1414+ lseek (LOCAL->fd, elt->private.msg.text.offset,L_SET);
1415+
1416+ if (flags & FT_INTERNAL) { /* initial data OK? */
1417+ if (elt->private.msg.text.text.size > LOCAL->buflen) {
1418+ fs_give ((void **) &LOCAL->buf);
1419+ LOCAL->buf = (char *) fs_get ((LOCAL->buflen =
1420+ elt->private.msg.text.text.size) + 1);
1421+ }
1422+ read (LOCAL->fd,LOCAL->buf,elt->private.msg.text.text.size);
1423+ LOCAL->buf[*length = elt->private.msg.text.text.size] = '\0';
1424+ }
1425+ else {
1426+ if (elt->rfc822_size > LOCAL->buflen) {
1427+ fs_give ((void **) &LOCAL->buf);
1428+ LOCAL->buf = (char *) fs_get ((LOCAL->buflen = elt->rfc822_size) + 1);
1429+ }
1430+ d.fd = LOCAL->fd; /* yes, set up file descriptor */
1431+ d.pos = elt->private.msg.text.offset;
1432+ d.chunk = tmp; /* initial buffer chunk */
1433+ d.chunksize = CHUNK;
1434+ INIT (&bs,fd_string,&d,elt->private.msg.text.text.size);
1435+ for (s = LOCAL->buf; SIZE (&bs);) switch (CHR (&bs)) {
1436+ case '\r': /* carriage return seen */
1437+ *s++ = SNX (&bs); /* copy it and any succeeding LF */
1438+ if (SIZE (&bs) && (CHR (&bs) == '\n')) *s++ = SNX (&bs);
1439+ break;
1440+ case '\n':
1441+ *s++ = '\r'; /* insert a CR */
1442+ default:
1443+ *s++ = SNX (&bs); /* copy characters */
1444+ }
1445+ *s = '\0'; /* tie off buffer */
1446+ *length = s - (char *) LOCAL->buf; /* calculate length */
1447+ }
1448+ close(LOCAL->fd); LOCAL->fd = -1;
1449+ return LOCAL->buf;
1450+ }
1451+
1452+ /* maildir parse, fill the elt structure... well not all of it... */
1453+ unsigned long maildir_parse_message(MAILSTREAM *stream, unsigned long msgno,
1454+ DirNamesType dirtype)
1455+ {
1456+ char *b, *s, *t, c;
1457+ char tmp[MAILTMPLEN];
1458+ struct stat sbuf;
1459+ unsigned long i, len;
1460+ int d, f, r, se, dt;
1461+ MESSAGECACHE *elt;
1462+
1463+ elt = mail_elt (stream,msgno);
1464+ MSGPATH(tmp, LOCAL->dir, MDFILE(elt), dirtype);
1465+ if(stat(tmp, &sbuf) == 0)
1466+ MDSIZE(elt) = sbuf.st_size;
1467+
1468+ maildir_get_date(stream, msgno);
1469+ maildir_getflag(MDFILE(elt), &d, &f, &r ,&se, &dt);
1470+ elt->draft = d; elt->flagged = f; elt->answered = r; elt->seen = se;
1471+ elt->deleted = dt; elt->valid = T;
1472+ if (LOCAL->fd < 0) /* if file closed ? */
1473+ LOCAL->fd = open(tmp,O_RDONLY,NIL);
1474+
1475+ if (LOCAL->fd >= 0){
1476+ s = (char *) fs_get (MDSIZE(elt) + 1);
1477+ read (LOCAL->fd,s,MDSIZE(elt));
1478+ s[MDSIZE(elt)] = '\0';
1479+ t = s + strlen(s); /* make t point to the end of s */
1480+ for (i = 0L, b = s; b < t && !(i && (*b == '\n')); i = (*b++ == '\n'));
1481+ len = (*b ? ++b : b) - s;
1482+ elt->private.msg.header.text.size =
1483+ elt->private.msg.text.offset = len;
1484+ elt->private.msg.text.text.size = MDSIZE(elt) - len;
1485+ for (i = 0L, b = s, c = *b; b &&
1486+ ((c < '\016' && ((c == '\012' && ++i)
1487+ ||(c == '\015' && *(b+1) == '\012' && ++b && (i +=2))))
1488+ || b < t); i++, c= *++b);
1489+ elt->rfc822_size = i;
1490+ fs_give ((void **) &s);
1491+ close(LOCAL->fd); LOCAL->fd = -1;
1492+ }
1493+ return elt->rfc822_size;
1494+ }
1495+
1496+ int
1497+ maildir_update_elt_maildirp(MAILSTREAM *stream, unsigned long msgno)
1498+ {
1499+ struct direct **names = NIL;
1500+ unsigned long i, nfiles, pos;
1501+ int d = 0, f = 0 , r = 0, s = 0, t = 0, in_list, scan_err;
1502+ MESSAGECACHE *elt;
1503+
1504+ maildir_scandir (LOCAL->path[Cur], &names, &nfiles, &scan_err, CCLIENT);
1505+
1506+ elt = mail_elt (stream,msgno);
1507+
1508+ in_list = nfiles > 0L
1509+ ? maildir_message_in_list(MDFILE(elt), names, 0L, nfiles - 1L, &pos)
1510+ : NIL;
1511+
1512+ if (in_list && pos >= 0L && pos < nfiles
1513+ && !strcmp(MDFILE(elt), names[pos]->d_name)){
1514+ in_list = NIL;
1515+ maildir_abort(stream);
1516+ }
1517+
1518+ if (in_list && pos >= 0L && pos < nfiles){
1519+ maildir_free_file_only((void **)&elt->private.spare.ptr);
1520+ MDFILE(elt) = cpystr(names[pos]->d_name);
1521+ maildir_getflag(MDFILE(elt), &d, &f, &r ,&s, &t);
1522+ if (elt->draft != d || elt->flagged != f ||
1523+ elt->answered != r || elt->seen != s || elt->deleted != t){
1524+ elt->draft = d; elt->flagged = f; elt->answered = r;
1525+ elt->seen = s; elt->deleted = t;
1526+ MM_FLAGS(stream, msgno);
1527+ }
1528+ }
1529+ for (i = 0L; i < nfiles; i++)
1530+ fs_give((void **) &names[i]);
1531+ if (names)
1532+ fs_give((void **) &names);
1533+ return in_list ? 1 : -1;
1534+ }
1535+
1536+ /* Maildir fetch message header */
1537+
1538+ char *maildir_header (MAILSTREAM *stream,unsigned long msgno,
1539+ unsigned long *length, long flags)
1540+ {
1541+ char tmp[MAILTMPLEN], *s;
1542+ MESSAGECACHE *elt;
1543+ static int try = 0;
1544+
1545+ if (length) *length = 0;
1546+ if (flags & FT_UID || !LOCAL) return ""; /* UID call "impossible" */
1547+ elt = mail_elt (stream,msgno);
1548+ if(elt->private.msg.header.text.size == 0)
1549+ maildir_parse_message(stream, msgno, MDLOC(elt));
1550+
1551+ MSGPATH(tmp, LOCAL->dir, MDFILE(elt), MDLOC(elt));
1552+ if (LOCAL->fd < 0)
1553+ LOCAL->fd = open (tmp,O_RDONLY,NIL);
1554+
1555+ if (LOCAL->fd < 0 && errno == EACCES){
1556+ mm_log ("Message exists but can not be read. Envelope and body lost!",ERROR);
1557+ return NULL;
1558+ }
1559+
1560+ if (LOCAL->fd < 0){ /* flag change? */
1561+ if (try < 5){
1562+ try++;
1563+ if (maildir_update_elt_maildirp(stream, msgno) > 0)
1564+ try = 0;
1565+ return maildir_header(stream, msgno, length, flags);
1566+ }
1567+ try = 0;
1568+ return NULL;
1569+ }
1570+
1571+ if (flags & FT_INTERNAL){
1572+ if(elt->private.msg.header.text.size > LOCAL->buflen){
1573+ fs_give ((void **) &LOCAL->buf);
1574+ LOCAL->buf = (char *) fs_get ((LOCAL->buflen =
1575+ elt->private.msg.header.text.size) + 1);
1576+ }
1577+ read (LOCAL->fd, (void *)LOCAL->buf, elt->private.msg.header.text.size);
1578+ LOCAL->buf[*length = elt->private.msg.header.text.size] = '\0';
1579+ }
1580+ else{
1581+ s = (char *) fs_get(elt->private.msg.header.text.size+1);
1582+ read (LOCAL->fd, (void *)s, elt->private.msg.header.text.size);
1583+ s[elt->private.msg.header.text.size] = '\0';
1584+ *length = strcrlfcpy (&LOCAL->buf,&LOCAL->buflen,s,
1585+ elt->private.msg.header.text.size);
1586+ fs_give ((void **) &s);
1587+ }
1588+ elt->private.msg.text.offset = elt->private.msg.header.text.size;
1589+ elt->private.msg.text.text.size = MDSIZE(elt) - elt->private.msg.text.offset;
1590+ close(LOCAL->fd); LOCAL->fd = -1;
1591+ return LOCAL->buf;
1592+ }
1593+
1594+ /* Maildir find list of subscribed mailboxes
1595+ * Accepts: mail stream
1596+ * pattern to search
1597+ */
1598+
1599+ void maildir_list (MAILSTREAM *stream,char *ref, char *pat)
1600+ {
1601+ char *s,test[MAILTMPLEN],file[MAILTMPLEN];
1602+ long i = 0L;
1603+
1604+ if((!pat || !*pat) && maildir_canonicalize (test,ref,"*")
1605+ && maildir_valid_name(test)){ /* there is a #md/ leading here */
1606+ for (i = 3L; test[i] && test[i] != '/'; i++);
1607+ if ((s = strchr (test+i+1,'/')) != NULL) *++s = '\0';
1608+ else test[0] = '\0';
1609+ mm_list (stream,'/',test, LATT_NOSELECT);
1610+ }
1611+ else if (maildir_canonicalize (test,ref,pat)) {
1612+ if (test[3] == '/') { /* looking down levels? */
1613+ /* yes, found any wildcards? */
1614+ if ((s = strpbrk (test,"%*")) != NULL){
1615+ /* yes, copy name up to that point */
1616+ strncpy (file,test+4,i = s - (test+4));
1617+ file[i] = '\0'; /* tie off */
1618+ }
1619+ else strcpy (file,test+4);/* use just that name then */
1620+ /* find directory name */
1621+ if ((s = strrchr (file, '/')) != NULL){
1622+ *s = '\0'; /* found, tie off at that point */
1623+ s = file;
1624+ }
1625+ /* do the work */
1626+ if(IS_COURIER(test))
1627+ courier_list_work (stream,s,test,0);
1628+ else
1629+ maildir_list_work (stream,s,test,0);
1630+ }
1631+ /* always an INBOX */
1632+ if (!compare_cstring (test,"#MD/INBOX"))
1633+ mm_list (stream,NIL,"#MD/INBOX",LATT_NOINFERIORS);
1634+ if (!compare_cstring (test,"#MC/INBOX"))
1635+ mm_list (stream,NIL,"#MC/INBOX",LATT_NOINFERIORS);
1636+ }
1637+ }
1638+
1639+ void courier_list (MAILSTREAM *stream,char *ref, char *pat)
1640+ {
1641+ /* I am too lazy to do anything. Do you care to ask maildir list, please?
1642+ The real reason why this is a dummy function is because we do not want to
1643+ see the same folder listed twice.
1644+ */
1645+ }
1646+
1647+ /* For those that want to hide things, we give them a chance to do so */
1648+ void *maildir_parameters (long function, void *value)
1649+ {
1650+ void *ret = NIL;
1651+ switch ((int) function) {
1652+ case SET_MDINBOXPATH:
1653+ if(strlen((char *) value ) > 49)
1654+ strcpy(myMdInboxDir, "Maildir");
1655+ else
1656+ strcpy(myMdInboxDir, (char *) value);
1657+ case GET_MDINBOXPATH:
1658+ if (myMdInboxDir[0] == '\0') strcpy(myMdInboxDir,"Maildir");
1659+ ret = (void *) myMdInboxDir;
1660+ break;
1661+ case SET_COURIERSTYLE:
1662+ CourierStyle = (long) value;
1663+ case GET_COURIERSTYLE:
1664+ ret = (void *) CourierStyle;
1665+ break;
1666+ case GET_DIRFMTTEST:
1667+ ret = (void *) maildir_dirfmttest;
1668+ break;
1669+ default:
1670+ break;
1671+ }
1672+ return ret;
1673+ }
1674+
1675+ int maildir_create_folder(char *mailbox)
1676+ {
1677+ char tmp[MAILTMPLEN], err[MAILTMPLEN];
1678+ DirNamesType i;
1679+
1680+ for (i = Cur; i != EndDir; i++){
1681+ MDFLD(tmp, mailbox, i);
1682+ if (mkdir(tmp, 0700) && errno != EEXIST){ /* try to make new dir */
1683+ snprintf (err, sizeof(err), "Can't create %s: %s", tmp, strerror(errno));
1684+ mm_log (err,ERROR);
1685+ return NIL;
1686+ }
1687+ }
1688+ return T;
1689+ }
1690+
1691+ int maildir_create_work(char *mailbox, int loop)
1692+ {
1693+ char *s, c, err[MAILTMPLEN], tmp[MAILTMPLEN], tmp2[MAILTMPLEN], mbx[MAILTMPLEN];
1694+ int fnlen, create_dir = 0, courier, mv;
1695+ struct stat sbuf;
1696+ long style = *(long *) maildir_parameters(GET_COURIERSTYLE, NIL);
1697+
1698+ courier = IS_COURIER(mailbox);
1699+ strcpy(mbx, mailbox);
1700+ mv = maildir_valid(mbx) ? 1 : 0;
1701+ maildir_file_path(mailbox, tmp, sizeof(tmp));
1702+ if (mailbox[strlen(mailbox) - 1] == MDSEPARATOR(courier)){
1703+ create_dir++;
1704+ mailbox[strlen(mailbox) - 1] = '\0';
1705+ }
1706+
1707+ if(!loop && courier){
1708+ if(mv){
1709+ if(create_dir){
1710+ if(style == CCLIENT)
1711+ strcpy (err,"Can not create directory: folder exists. Create subfolder");
1712+ else
1713+ strcpy(err,"Folder and Directory already exist");
1714+ }
1715+ else
1716+ strcpy (err, "Can't create mailbox: mailbox already exists");
1717+ }
1718+ else{
1719+ if(create_dir)
1720+ strcpy(err, "Can not create directory. Cread folder instead");
1721+ else
1722+ err[0] = '\0';
1723+ }
1724+ if(err[0]){
1725+ mm_log (err,ERROR);
1726+ return NIL;
1727+ }
1728+ }
1729+
1730+ fnlen = strlen(tmp);
1731+ if ((s = strrchr(mailbox,MDSEPARATOR(courier))) != NULL){
1732+ c = *++s;
1733+ *s = '\0';
1734+ if ((stat(tmp,&sbuf) || ((sbuf.st_mode & S_IFMT) != S_IFDIR)) &&
1735+ !maildir_create_work (mailbox, ++loop))
1736+ return NIL;
1737+ *s = c;
1738+ }
1739+ tmp[fnlen] = '\0';
1740+
1741+ if (mkdir(tmp,0700) && errno != EEXIST)
1742+ return NIL;
1743+
1744+ if (create_dir)
1745+ mailbox[fnlen] = '/';
1746+
1747+ if (create_dir){
1748+ if(style == CCLIENT){
1749+ if(!courier){
1750+ FILE *fp = NULL;
1751+ snprintf(tmp2, sizeof(tmp2), "%s%s", tmp, MDDIR);
1752+ if ((fp = fopen(tmp2,"w")) == NULL){
1753+ snprintf (err, sizeof(err), "Problem creating %s: %s", tmp2, strerror(errno));
1754+ mm_log (err,ERROR);
1755+ return NIL;
1756+ }
1757+ fclose(fp);
1758+ }
1759+ }
1760+ return T;
1761+ }
1762+ else
1763+ return maildir_create_folder(tmp);
1764+ }
1765+
1766+ long maildir_create (MAILSTREAM *stream,char *mailbox)
1767+ {
1768+ char tmp[MAILTMPLEN], err[MAILTMPLEN];
1769+ int rv, create_dir;
1770+
1771+ create_dir = mailbox ?
1772+ (mailbox[strlen(mailbox) - 1] ==
1773+ MDSEPARATOR(IS_COURIER(mailbox))) : 0;
1774+ maildir_file_path(mailbox, tmp, sizeof(tmp));
1775+ strcpy(tmp, mailbox);
1776+ rv = maildir_create_work(mailbox, 0);
1777+ strcpy(mailbox, tmp);
1778+ if (rv == 0){
1779+ snprintf (err, sizeof(err), "Can't create %s %s",
1780+ (create_dir ? "directory" : "mailbox"), mailbox);
1781+ mm_log (err,ERROR);
1782+ }
1783+ return rv ? LONGT : NIL;
1784+ }
1785+
1786+ #define MAXTRY 10000
1787+ void maildir_flagmsg (MAILSTREAM *stream,MESSAGECACHE *elt)
1788+ {
1789+ char oldfile[MAILTMPLEN],newfile[MAILTMPLEN],fn[MAILTMPLEN];
1790+ char *s;
1791+ int ren, try = 0;
1792+
1793+ if (elt->valid){
1794+ for (try = 1; try > 0 && try < MAXTRY; try++){
1795+ /* build the new filename */
1796+ snprintf (oldfile, sizeof(oldfile), "%s/%s",LOCAL->path[Cur], MDFILE(elt));
1797+ fn[0] = '\0';
1798+ if ((ren = maildir_message_exists(stream, MDFILE(elt), fn)) == 0){
1799+ errno = ENOENT;
1800+ try = MAXTRY;
1801+ }
1802+ if (*fn) /* new oldfile! */
1803+ snprintf (oldfile,sizeof(oldfile),"%s/%s", LOCAL->path[Cur], fn);
1804+ if ((s = strrchr (MDFILE(elt), FLAGSEP))) *s = '\0';
1805+ snprintf (fn, sizeof(fn), "%s%s%s%s%s%s%s", MDFILE(elt), MDSEP(2),
1806+ MDFLAG(Draft, elt->draft), MDFLAG(Flagged, elt->flagged),
1807+ MDFLAG(Replied, elt->answered), MDFLAG(Seen, elt->seen),
1808+ MDFLAG(Trashed, elt->deleted));
1809+ snprintf (newfile, sizeof(newfile), "%s/%s",LOCAL->path[Cur],fn);
1810+ if (ren != 0 && rename (oldfile,newfile) >= 0)
1811+ try = -1;
1812+ }
1813+
1814+ if (try > 0){
1815+ snprintf(oldfile, sizeof(oldfile), "Unable to write flags to disk: %s",
1816+ (errno == ENOENT) ? "message is gone!" : strerror (errno));
1817+ mm_log(oldfile,ERROR);
1818+ return;
1819+ }
1820+ #ifdef __CYGWIN__
1821+ utime(LOCAL->path[Cur], NIL); /* make sure next scan will catch the change */
1822+ #endif
1823+ maildir_free_file_only ((void **) &elt->private.spare.ptr);
1824+ MDFILE(elt) = cpystr (fn);
1825+ }
1826+ }
1827+
1828+ long maildir_expunge (MAILSTREAM *stream, char *sequence, long options)
1829+ {
1830+ long ret;
1831+ MESSAGECACHE *elt;
1832+ unsigned long i, n = 0L;
1833+ unsigned long recent = stream->recent;
1834+ char tmp[MAILTMPLEN];
1835+
1836+ mm_critical (stream); /* go critical */
1837+ ret = sequence ? ((options & EX_UID) ?
1838+ mail_uid_sequence (stream,sequence) :
1839+ mail_sequence (stream,sequence)) : LONGT;
1840+ if(ret == 0L)
1841+ return 0L;
1842+ for (i = 1L; i <= stream->nmsgs;){
1843+ elt = mail_elt (stream,i);
1844+ if (elt->deleted && (sequence ? elt->sequence : T)){
1845+ snprintf (tmp, sizeof(tmp), "%s/%s", LOCAL->path[Cur], MDFILE(elt));
1846+ if (unlink (tmp) < 0) {/* try to delete the message */
1847+ snprintf (tmp, sizeof(tmp), "Expunge of message %ld failed, aborted: %s",i,
1848+ strerror (errno));
1849+ if (!stream->silent)
1850+ mm_log (tmp,WARN);
1851+ break;
1852+ }
1853+ if (elt->private.spare.ptr)
1854+ maildir_free_file ((void **) &elt->private.spare.ptr);
1855+ if (elt->recent) --recent;/* if recent, note one less recent message */
1856+ mail_expunged (stream,i); /* notify upper levels */
1857+ n++; /* count up one more expunged message */
1858+ }
1859+ else i++;
1860+ }
1861+ if(n){ /* output the news if any expunged */
1862+ snprintf (tmp, sizeof(tmp), "Expunged %ld messages", n);
1863+ if (!stream->silent)
1864+ mm_log (tmp,(long) NIL);
1865+ }
1866+ else
1867+ if (!stream->silent)
1868+ mm_log ("No messages deleted, so no update needed",(long) NIL);
1869+ mm_nocritical (stream); /* release critical */
1870+ /* notify upper level of new mailbox size */
1871+ mail_exists (stream, stream->nmsgs);
1872+ mail_recent (stream, recent);
1873+ return ret;
1874+ }
1875+
1876+ long maildir_copy (MAILSTREAM *stream,char *sequence,char *mailbox,long options)
1877+ {
1878+ STRING st;
1879+ MESSAGECACHE *elt;
1880+ unsigned long len;
1881+ int fd;
1882+ unsigned long i;
1883+ struct stat sbuf;
1884+ char tmp[MAILTMPLEN], flags[MAILTMPLEN], path[MAILTMPLEN], *s;
1885+ /* copy the messages */
1886+ if ((options & CP_UID) ? mail_uid_sequence (stream, sequence) :
1887+ mail_sequence (stream,sequence))
1888+ for (i = 1L; i <= stream->nmsgs; i++)
1889+ if ((elt = mail_elt (stream,i))->sequence){
1890+ MSGPATH(path, LOCAL->dir, MDFILE(elt), MDLOC(elt));
1891+ if (((fd = open (path,O_RDONLY,NIL)) < 0)
1892+ ||((!elt->rfc822_size &&
1893+ ((stat(path, &sbuf) < 0) || !S_ISREG (sbuf.st_mode)))))
1894+ return NIL;
1895+ if(!elt->rfc822_size)
1896+ MDSIZE(elt) = sbuf.st_size;
1897+ s = (char *) fs_get(MDSIZE(elt) + 1);
1898+ read (fd,s,MDSIZE(elt));
1899+ s[MDSIZE(elt)] = '\0';
1900+ close (fd);
1901+ len = strcrlfcpy (&LOCAL->buf,&LOCAL->buflen, s, MDSIZE(elt));
1902+ INIT (&st,mail_string, LOCAL->buf, len);
1903+ elt->rfc822_size = len;
1904+ fs_give ((void **)&s);
1905+
1906+ flags[0] = flags[1] = '\0';
1907+ if (elt->seen) strcat (flags," \\Seen");
1908+ if (elt->draft) strcat (flags," \\Draft");
1909+ if (elt->deleted) strcat (flags," \\Deleted");
1910+ if (elt->flagged) strcat (flags," \\Flagged");
1911+ if (elt->answered) strcat (flags," \\Answered");
1912+ flags[0] = '('; /* open list */
1913+ strcat (flags,")"); /* close list */
1914+ mail_date (tmp,elt); /* generate internal date */
1915+ if (!mail_append_full (NIL, mailbox, flags, tmp, &st))
1916+ return NIL;
1917+ if (options & CP_MOVE) elt->deleted = T;
1918+ }
1919+ return LONGT; /* return success */
1920+ }
1921+
1922+ long maildir_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data)
1923+ {
1924+ int fd, k, done, fail;
1925+ STRING *message;
1926+ char c,*s, *flags, *date;
1927+ char tmp[MAILTMPLEN],file[MAILTMPLEN],path1[MAILTMPLEN],path2[MAILTMPLEN];
1928+ MESSAGECACHE elt;
1929+ long i, size = 0L, ret = LONGT, f;
1930+ unsigned long uf, ti;
1931+ static unsigned int transact = 0;
1932+ struct stat sbuf;
1933+
1934+ if (!maildir_valid(mailbox)) {
1935+ snprintf (tmp, sizeof(tmp), "Not a valid Maildir mailbox: %s", mailbox);
1936+ mm_log (tmp,ERROR);
1937+ return NIL;
1938+ }
1939+
1940+ if (!*mdlocaldomain)
1941+ md_domain_name(); /* get domain name for maildir files in mdlocaldomain now! */
1942+
1943+ if (mypid == (pid_t) 0)
1944+ mypid = getpid();
1945+
1946+ if (!stream){
1947+ stream = &maildirproto;
1948+
1949+ for (k = 0; k < NUSERFLAGS && stream->user_flags[k]; ++k)
1950+ fs_give ((void **) &stream->user_flags[k]);
1951+ }
1952+
1953+ if (!(*af)(stream, data, &flags, &date, &message)) return NIL;
1954+
1955+ mm_critical (stream); /* go critical */
1956+ do {
1957+ fail = done = 0; /* we have not determined name of message file yet */
1958+ if (!SIZE (message)) { /* guard against zero-length */
1959+ mm_log ("Append of zero-length message", ERROR);
1960+ ret = NIL;
1961+ break;
1962+ }
1963+
1964+ if (date && !mail_parse_date(&elt,date)){
1965+ snprintf (tmp, sizeof(tmp), "Bad date in append: %.80s", date);
1966+ mm_log (tmp, ERROR);
1967+ ret = NIL;
1968+ break;
1969+ }
1970+
1971+ if(date){
1972+ struct tm tm;
1973+
1974+ tm.tm_sec = elt.seconds;
1975+ tm.tm_min = elt.minutes;
1976+ tm.tm_hour = elt.hours;
1977+ tm.tm_mday = elt.day;
1978+ tm.tm_mon = elt.month - 1;
1979+ tm.tm_year = BASEYEAR + elt.year - 1900;
1980+
1981+ ti = mktime(&tm);
1982+ } else ti = time(0);
1983+
1984+ f = mail_parse_flags (stream,flags,&uf);
1985+ do {
1986+ /* build file name we will use */
1987+ snprintf (file, sizeof(file), "%lu.%d_%09u.%s%s%s%s%s%s",
1988+ ti, mypid, transact++, mdlocaldomain, (f ? MDSEP(2) : ""),
1989+ MDFLAG(Draft, f&fDRAFT), MDFLAG(Flagged, f&fFLAGGED),
1990+ MDFLAG(Replied, f&fANSWERED), MDFLAG(Seen, f&fSEEN));
1991+ /* build tmp file name */
1992+ if (maildir_file_path(mailbox, tmp, sizeof(tmp))) /* copy in TMP */
1993+ MSGPATH(path1, tmp, file, Tmp);
1994+ /* build final filename to use */
1995+ if (maildir_file_path(mailbox, tmp, sizeof(tmp)))
1996+ MSGPATH(path2, tmp, file, New); /* copy in NEW */
1997+ if(stat(path1, &sbuf) < 0 && errno == ENOENT
1998+ && stat(path2, &sbuf) < 0 && errno == ENOENT)
1999+ done++;
2000+ else
2001+ fail++;
2002+ if(fail == 1000){
2003+ snprintf (tmp, sizeof(tmp), "Failure to create append message name");
2004+ mm_log (tmp, ERROR);
2005+ return NIL;
2006+ }
2007+ } while (done == 0);
2008+
2009+ if ((fd = open (path1,O_WRONLY|O_CREAT|O_EXCL,S_IREAD|S_IWRITE)) < 0) {
2010+ snprintf (tmp, sizeof(tmp), "Can't open append mailbox: %s", strerror (errno));
2011+ mm_log (tmp, ERROR);
2012+ return NIL;
2013+ }
2014+ for (size = 0,i = SIZE (message),s = (char *) fs_get (i + 1); i; --i)
2015+ if ((c = SNX (message)) != '\015') s[size++] = c;
2016+ if ((write (fd, s, size) < 0) || fsync (fd)) {
2017+ unlink (path1); /* delete message */
2018+ snprintf (tmp, sizeof(tmp), "Message append failed: %s", strerror (errno));
2019+ mm_log (tmp, ERROR);
2020+ ret = NIL;
2021+ }
2022+ fs_give ((void **) &s); /* flush the buffer */
2023+ close (fd); /* close the file */
2024+
2025+ if (rename (path1,path2) < 0) {
2026+ snprintf (tmp, sizeof(tmp), "Message append failed: %s", strerror (errno));
2027+ mm_log (tmp, ERROR);
2028+ ret = NIL;
2029+ }
2030+ unlink (path1);
2031+ if(date){
2032+ time_t tp[2];
2033+ tp[0] = tp[1] = ti;
2034+ utime (path2,tp);
2035+ }
2036+
2037+ if (ret)
2038+ if (!(*af) (stream,data,&flags,&date,&message)) ret = NIL;
2039+
2040+ } while (ret && message); /* write the data */
2041+ mm_nocritical (stream); /* release critical */
2042+ return ret;
2043+ }
2044+
2045+ long maildir_delete (MAILSTREAM *stream,char *mailbox)
2046+ {
2047+ DIR *dirp;
2048+ struct direct *d;
2049+ int i, remove_dir = 0, mddir = 0, rv, error = 0;
2050+ char tmp[MAILTMPLEN],tmp2[MAILTMPLEN], realname[MAILTMPLEN];
2051+ struct stat sbuf;
2052+ int courier = IS_COURIER(mailbox);
2053+
2054+ if (mailbox[strlen(mailbox) - 1] == MDSEPARATOR(courier)){
2055+ remove_dir++;
2056+ mailbox[strlen(mailbox) -1] = '\0';
2057+ }
2058+
2059+ if (!maildir_valid(mailbox)){
2060+ maildir_file_path(mailbox, tmp, sizeof(tmp));
2061+ if (stat(tmp, &sbuf) < 0 || !S_ISDIR(sbuf.st_mode)){
2062+ snprintf(tmp, sizeof(tmp), "Can not remove %s", mailbox);
2063+ error++;
2064+ }
2065+ }
2066+
2067+ if (!error && remove_dir && !maildir_dir_is_empty(mailbox)){
2068+ snprintf(tmp, sizeof(tmp), "Can not remove directory %s/: directory not empty", mailbox);
2069+ error++;
2070+ }
2071+
2072+ if(error){
2073+ mm_log (tmp,ERROR);
2074+ return NIL;
2075+ }
2076+
2077+ maildir_close(stream,0); /* even if stream was NULL */
2078+
2079+ maildir_file_path(mailbox, realname, sizeof(realname));
2080+
2081+ if (remove_dir){
2082+ snprintf(tmp, sizeof(tmp), "%s/%s", realname, MDDIR);
2083+ if ((rv = stat (tmp,&sbuf)) == 0 && S_ISREG(sbuf.st_mode))
2084+ rv = unlink(tmp);
2085+ else if (errno == ENOENT)
2086+ rv = 0;
2087+ if (rv != 0){
2088+ snprintf(tmp, sizeof(tmp), "Can not remove %s/%s: %s", tmp2, MDDIR, strerror(errno));
2089+ mm_log (tmp,ERROR);
2090+ return NIL;
2091+ }
2092+ if (!maildir_valid(realname) && rmdir(realname) != 0){
2093+ snprintf(tmp, sizeof(tmp), "Can not remove %s/: %s", mailbox, strerror(errno));
2094+ mm_log (tmp, ERROR);
2095+ return NIL;
2096+ }
2097+ return LONGT;
2098+ }
2099+ /* else remove just the folder. Remove all hidden files, except MDDIR */
2100+ for (i = Cur; i != EndDir; i++){
2101+ MDFLD(tmp, realname, i);
2102+
2103+ if (!(dirp = opendir (tmp))){
2104+ snprintf(tmp, sizeof(tmp), "Can not read %s/: %s", mailbox, strerror(errno));
2105+ mm_log (tmp, ERROR);
2106+ return NIL;
2107+ }
2108+
2109+ while ((d = readdir(dirp)) != NULL){
2110+ if (strcmp(d->d_name, ".") && strcmp(d->d_name,"..")){
2111+ snprintf(tmp2, sizeof(tmp2), "%s/%s", tmp, d->d_name);
2112+ if (unlink(tmp2) != 0){
2113+ snprintf(tmp2, sizeof(tmp2), "Can not remove %s: %s", mailbox, strerror(errno));
2114+ mm_log (tmp2, ERROR);
2115+ return NIL;
2116+ }
2117+ }
2118+ }
2119+ closedir(dirp);
2120+ if (rmdir(tmp) != 0){
2121+ snprintf(tmp, sizeof(tmp), "Can not remove %s: %s", mailbox, strerror(errno));
2122+ mm_log (tmp, ERROR);
2123+ return NIL;
2124+ }
2125+ }
2126+ /*
2127+ * ok we have removed all subdirectories of the folder mailbox, Remove the
2128+ * hidden files.
2129+ */
2130+
2131+ if(!(dirp = opendir (realname))){
2132+ snprintf(tmp, sizeof(tmp), "Can not read %s/: %s", realname, strerror(errno));
2133+ mm_log (tmp, ERROR);
2134+ return NIL;
2135+ }
2136+
2137+ while ((d = readdir(dirp)) != NULL){
2138+ if (strcmp(d->d_name, ".") && strcmp(d->d_name,"..")
2139+ && (!strcmp(d->d_name, MDDIR)
2140+ || !strncmp(d->d_name, MDUIDLAST, strlen(MDUIDLAST))
2141+ || !strncmp(d->d_name, MDUIDTEMP, strlen(MDUIDTEMP))
2142+ || !strcmp(d->d_name, "courierimapacl")
2143+ || !strcmp(d->d_name, "courierimapuiddb")
2144+ || !strcmp(d->d_name, "dovecot.index")
2145+ || !strcmp(d->d_name, "dovecot.index.cache")
2146+ || !strcmp(d->d_name, "dovecot-keywords")
2147+ || !strcmp(d->d_name, "dovecot-uidlist")
2148+ || !strcmp(d->d_name, "subscriptions")
2149+ || !strcmp(d->d_name, "maildirfolder")
2150+ || !strncmp(d->d_name, "dovecot.index.log", 17)
2151+ || !strncmp(d->d_name, "dovecot.mailbox.log", 19)
2152+ || !strncmp(d->d_name, "dovecot-uidvalidity", 19))){
2153+ if(strcmp(d->d_name, MDDIR) == 0)
2154+ mddir++;
2155+ snprintf(tmp, sizeof(tmp), "%s/%s", realname, d->d_name);
2156+ if (unlink(tmp) != 0)
2157+ error++;
2158+ }
2159+ }
2160+ closedir(dirp);
2161+ if (error ||
2162+ (maildir_dir_is_empty(mailbox) && mddir == 0 && rmdir(realname) < 0)){
2163+ snprintf(tmp, sizeof(tmp), "Can not remove folder %s: %s", mailbox, strerror(errno));
2164+ mm_log (tmp, ERROR);
2165+ return NIL;
2166+ }
2167+ return LONGT;
2168+ }
2169+
2170+ long maildir_rename (MAILSTREAM *stream, char *old, char *new)
2171+ {
2172+ char tmp[MAILTMPLEN], tmpnew[MAILTMPLEN], realold[MAILTMPLEN];
2173+ char realnew[MAILTMPLEN];
2174+ int courier = IS_COURIER(old) && IS_COURIER(new);
2175+ int i;
2176+ long rv = LONGT;
2177+ COURIER_S *cdir;
2178+
2179+ if((IS_COURIER(old) || IS_COURIER(new)) && !courier){
2180+ snprintf (tmp, sizeof(tmp), "Can't rename mailbox %s to %s", old, new);
2181+ mm_log (tmp, ERROR);
2182+ return NIL;
2183+ }
2184+
2185+ if (!maildir_valid(old)){
2186+ snprintf (tmp, sizeof(tmp), "Can't rename mailbox %s: folder not in maildir format",old);
2187+ mm_log (tmp, ERROR);
2188+ return NIL;
2189+ }
2190+ maildir_file_path(old, realold, sizeof(realold));
2191+ if (!maildir_valid_name(new) && new[0] == '#'){
2192+ snprintf (tmp, sizeof(tmp), "Cannot rename mailbox %s: folder not in maildir format", new);
2193+ mm_log (tmp, ERROR);
2194+ return NIL;
2195+ }
2196+ maildir_file_path(new, realnew, sizeof(realnew));
2197+ if (access(tmpnew,F_OK) == 0){ /* new mailbox name must not exist */
2198+ snprintf (tmp, sizeof(tmp), "Cannot rename to mailbox %s: destination already exists", new);
2199+ mm_log (tmp, ERROR);
2200+ return NIL;
2201+ }
2202+
2203+ if(!courier){
2204+ if (rename(realold, realnew)){ /* try to rename the directory */
2205+ snprintf(tmp, sizeof(tmp), "Can't rename mailbox %s to %s: %s", old, new,
2206+ strerror(errno));
2207+ mm_log(tmp,ERROR);
2208+ return NIL;
2209+ }
2210+ return LONGT; /* return success */
2211+ }
2212+
2213+ cdir = courier_list_dir(old);
2214+ for (i = 0; cdir && i < cdir->total; i++){
2215+ if(strstr(cdir->data[i]->name, old)){
2216+ snprintf(tmp, sizeof(tmp), "%s%s", new, cdir->data[i]->name+strlen(old));
2217+ maildir_file_path(cdir->data[i]->name, realold, sizeof(realold));
2218+ maildir_file_path(tmp, realnew, sizeof(realnew));
2219+ if (rename(realold, realnew)){
2220+ snprintf (tmp, sizeof(tmp), "Can't rename mailbox %s to %s: %s", old, new,
2221+ strerror(errno));
2222+ mm_log(tmp,ERROR);
2223+ rv = NIL;
2224+ }
2225+ }
2226+ }
2227+ courier_free_cdir(&cdir);
2228+ return rv;
2229+ }
2230+
2231+ long maildir_sub(MAILSTREAM *stream,char *mailbox)
2232+ {
2233+ return sm_subscribe(mailbox);
2234+ }
2235+
2236+ long maildir_unsub(MAILSTREAM *stream,char *mailbox)
2237+ {
2238+ return sm_unsubscribe(mailbox);
2239+ }
2240+
2241+ void maildir_lsub (MAILSTREAM *stream,char *ref,char *pat)
2242+ {
2243+ void *sdb = NIL;
2244+ char *s, test[MAILTMPLEN], tmp[MAILTMPLEN];
2245+ /* get canonical form of name */
2246+ if (maildir_canonicalize (test, ref, pat) && (s = sm_read (tmp, &sdb))) {
2247+ do if (pmatch_full (s, test, '/')) mm_lsub (stream, '/', s, NIL);
2248+ while ((s = sm_read (tmp, &sdb)) != NULL); /* until no more subscriptions */
2249+ }
2250+ }
2251+
2252+ long maildir_canonicalize (char *pattern,char *ref,char *pat)
2253+ {
2254+ if (ref && *ref) { /* have a reference */
2255+ strcpy (pattern,ref); /* copy reference to pattern */
2256+ /* # overrides mailbox field in reference */
2257+ if (*pat == '#') strcpy (pattern,pat);
2258+ /* pattern starts, reference ends, with / */
2259+ else if ((*pat == '/') && (pattern[strlen (pattern) - 1] == '/'))
2260+ strcat (pattern,pat + 1); /* append, omitting one of the period */
2261+
2262+ else strcat (pattern,pat); /* anything else is just appended */
2263+ }
2264+ else strcpy (pattern,pat); /* just have basic name */
2265+ return maildir_valid_name(pattern) ? LONGT : NIL;
2266+ }
2267+
2268+ void maildir_list_work (MAILSTREAM *stream,char *dir,char *pat,long level)
2269+ {
2270+ DIR *dp;
2271+ struct direct *d;
2272+ struct stat sbuf;
2273+ char curdir[MAILTMPLEN],name[MAILTMPLEN], tmp[MAILTMPLEN];
2274+ char realpat[MAILTMPLEN];
2275+ long i;
2276+ char *maildirpath = mdirpath();
2277+
2278+ snprintf(curdir, sizeof(curdir), "%s/%s/", myrootdir(pat), dir ? dir : maildirpath);
2279+ if ((dp = opendir (curdir)) != NULL){
2280+ if (dir) snprintf (name, sizeof(name), "%s%s/",MDPREFIX(CCLIENT),dir);
2281+ else strcpy (name, pat);
2282+
2283+ if (level == 0 && !strpbrk(pat,"%*")){
2284+ if(maildir_valid(pat)){
2285+ i = maildir_contains_folder(pat, NULL)
2286+ ? LATT_HASCHILDREN
2287+ : (maildir_is_dir(pat, NULL)
2288+ ? LATT_HASNOCHILDREN : LATT_NOINFERIORS);
2289+ maildir_file_path(pat, realpat, sizeof(realpat));
2290+ i += maildir_any_new_msgs(realpat)
2291+ ? LATT_MARKED : LATT_UNMARKED;
2292+ mm_list (stream,'/', pat, i);
2293+ }
2294+ else
2295+ if(pat[strlen(pat) - 1] == '/')
2296+ mm_list (stream,'/', pat, LATT_NOSELECT);
2297+ }
2298+
2299+ while ((d = readdir (dp)) != NULL)
2300+ if(strcmp(d->d_name, ".") && strcmp(d->d_name,"..")
2301+ && strcmp(d->d_name, MDNAME(Cur))
2302+ && strcmp(d->d_name, MDNAME(Tmp))
2303+ && strcmp(d->d_name, MDNAME(New))){
2304+
2305+ if (dir) snprintf (tmp, sizeof(tmp), "%s%s", name,d->d_name);
2306+ else strcpy(tmp, d->d_name);
2307+
2308+ if(pmatch_full (tmp, pat,'/')){
2309+ snprintf(tmp, sizeof(tmp), "%s/%s/%s", myrootdir(d->d_name),
2310+ (dir ? dir : maildirpath), d->d_name);
2311+ if(stat (tmp,&sbuf) == 0
2312+ && ((sbuf.st_mode & S_IFMT) == S_IFDIR)){
2313+ if (dir) snprintf (tmp, sizeof(tmp), "%s%s", name,d->d_name);
2314+ else strcpy(tmp, d->d_name);
2315+ i = maildir_valid(tmp)
2316+ ? (maildir_contains_folder(dir, d->d_name)
2317+ ? LATT_HASCHILDREN
2318+ : (maildir_is_dir(dir, d->d_name)
2319+ ? LATT_HASNOCHILDREN : LATT_NOINFERIORS))
2320+ : LATT_NOSELECT;
2321+ i += maildir_any_new_msgs(tmp)
2322+ ? LATT_MARKED : LATT_UNMARKED;
2323+ mm_list (stream,'/',tmp, i);
2324+ strcat (tmp, "/");
2325+ if(dmatch (tmp, pat,'/') &&
2326+ (level < (long) mail_parameters (NIL,GET_LISTMAXLEVEL,NIL))){
2327+ snprintf(tmp, sizeof(tmp), "%s/%s",dir,d->d_name);
2328+ maildir_list_work (stream,tmp,pat,level+1);
2329+ }
2330+ }
2331+ }
2332+ }
2333+ closedir (dp);
2334+ }
2335+ }
2336+
2337+ void courier_list_work (MAILSTREAM *stream, char *dir, char *pat, long level)
2338+ {
2339+ char c, curdir[MAILTMPLEN], tmp[MAILTMPLEN];
2340+ char realname[MAILTMPLEN], realpat[MAILTMPLEN] = {'\0'};
2341+ int i, found;
2342+ long style = *(long *) maildir_parameters(GET_COURIERSTYLE, NIL), j;
2343+ char *maildirpath = mdirpath();
2344+ COURIER_S *cdir;
2345+
2346+ if(!strpbrk(pat,"%*")){ /* a mailbox */
2347+ maildir_file_path(pat, curdir, sizeof(curdir));
2348+ i = strlen(curdir) - 1;
2349+ if(curdir[i] == '/')
2350+ curdir[i] = '\0';
2351+ cdir = courier_list_dir(curdir);
2352+ if(cdir){
2353+ found = 0; j = 0L;
2354+ if(maildir_valid_name(pat)){
2355+ for(i = 0; !found && i < cdir->total; i++)
2356+ if(strstr(curdir, cdir->data[i]->name)){
2357+ if(strlen(curdir) < strlen(cdir->data[i]->name))
2358+ found += 2;
2359+ else if(strlen(curdir) == strlen(cdir->data[i]->name))
2360+ found -= 1;
2361+ }
2362+ if(found > 0)
2363+ j = LATT_HASCHILDREN;
2364+ else if(found == 0)
2365+ j = (style == COURIER) ? LATT_HASNOCHILDREN : LATT_NOINFERIORS;
2366+ }
2367+ else
2368+ j = LATT_NOSELECT;
2369+ j += maildir_any_new_msgs(curdir) ? LATT_MARKED : LATT_UNMARKED;
2370+ if (found)
2371+ mm_list (stream, '.', pat, j);
2372+ courier_free_cdir(&cdir);
2373+ }
2374+ return;
2375+ }
2376+
2377+ strcpy(tmp,pat + 4); /* a directory */
2378+ j = strlen(pat) - 1;
2379+ maildir_file_path(pat, realpat, sizeof(realpat));
2380+ c = pat[j];
2381+ pat[j] = '\0';
2382+ realname[0] = '\0';
2383+ if(dir)
2384+ maildir_file_path(dir, realname, sizeof(realname));
2385+ snprintf(curdir, sizeof(curdir), "%s%s%s/%s", (dir ? "" : myrootdir(pat)), (dir ? "" : "/"),
2386+ (dir ? realname : maildirpath), (dir ? "" : "."));
2387+ snprintf(tmp, sizeof(tmp), "%s%s/.", MDPREFIX(COURIER), dir ? dir : maildirpath);
2388+ if (level == 0 && tmp && pmatch_full (tmp, realpat, '.'))
2389+ mm_list (stream,'.', tmp, LATT_NOSELECT);
2390+
2391+ cdir = courier_list_dir(pat);
2392+ pat[j] = c;
2393+ for (i = 0; cdir && i < cdir->total; i++)
2394+ if(pmatch_full (cdir->data[i]->name, pat, '.')){
2395+ snprintf(tmp, sizeof(tmp), "%s.", cdir->data[i]->name);
2396+ courier_list_info(&cdir, tmp, i);
2397+ mm_list (stream,'.',cdir->data[i]->name, cdir->data[i]->attribute);
2398+ }
2399+ courier_free_cdir(&cdir);
2400+ }
2401+
2402+ int
2403+ same_maildir_file(char *name1, char *name2)
2404+ {
2405+ char tmp1[MAILTMPLEN], tmp2[MAILTMPLEN];
2406+ char *s;
2407+
2408+ strcpy(tmp1, name1 ? name1 : "");
2409+ strcpy(tmp2, name2 ? name2 : "");
2410+ if ((s = strrchr(tmp1, FLAGSEP)) != NULL)
2411+ *s = '\0';
2412+ if (((s = strrchr(tmp1, SIZESEP)) != NULL) && (strchr(s,'.') == NULL))
2413+ *s = '\0';
2414+ if ((s = strrchr(tmp2, FLAGSEP)) != NULL)
2415+ *s = '\0';
2416+ if (((s = strrchr(tmp2, SIZESEP)) != NULL) && (strchr(s,'.') == NULL))
2417+ *s = '\0';
2418+
2419+ return !strcmp(tmp1, tmp2);
2420+ }
2421+
2422+ unsigned long antoul(char *seed)
2423+ {
2424+ int i, error = 0;
2425+ unsigned long val = 0L, rv1 = 0L, t;
2426+ char c, *p;
2427+ if(!seed)
2428+ return 0L;
2429+ t = strtoul(seed, &p, 10);
2430+ if(p && (*p == '.' || *p == '_'))
2431+ return t;
2432+ /* else */
2433+ if((p = strchr(seed,'.')) != NULL)
2434+ *p = '\0';
2435+ error = (strlen(seed) > 6); /* too long */
2436+ for(i= strlen(seed)-1; error == 0 && i >= 0; i--){
2437+ c = seed[i];
2438+ if (c >= 'A' && c <= 'Z') val = c - 'A';
2439+ else if (c >= 'a' && c <= 'z') val = c - 'a' + 26;
2440+ else if (c >= '0' && c <= '9') val = c - '0' + 26 + 26;
2441+ else if (c == '-') val = c - '-' + 26 + 26 + 10;
2442+ else if (c == '_') val = c - '_' + 26 + 26 + 10 + 1;
2443+ else error++;
2444+ rv1 = val + (rv1 << 6);
2445+ }
2446+ if(p)
2447+ *p = '.';
2448+ return error ? 0L : rv1;
2449+ }
2450+
2451+ unsigned long mdfntoul (char *name)
2452+ {
2453+ unsigned long t;
2454+ char *r, last;
2455+
2456+ if((*name == '_') && ((r = strpbrk(name,".,%+")) != NULL)){ /* Grrr!!! */
2457+ last = *r;
2458+ *r = '\0';
2459+ t = antoul(r+1);
2460+ *r = last;
2461+ }
2462+ else
2463+ t = antoul(name);
2464+ return t;
2465+ }
2466+
2467+ int comp_maildir_file(char *name1, char *name2)
2468+ {
2469+ int uset1 = 1, uset2 = 1, i, j, cmp;
2470+ unsigned long t1, t2;
2471+ char *s1, *s2;
2472+
2473+ if (!(name1 && *name1))
2474+ return (name2 && *name2) ? (*name2 == FLAGSEP ? 0 : -1) : 0;
2475+
2476+ if (!(name2 && *name2))
2477+ return (name1 && *name1) ? (*name1 == FLAGSEP ? 0 : 1) : 0;
2478+
2479+ if((cmp = strcmp(name1,name2)) == 0)
2480+ return 0;
2481+
2482+ t1 = strtoul(name1, &s1, 10);
2483+ t2 = strtoul(name2, &s2, 10);
2484+
2485+ if(!s1 || *s1 != '.')
2486+ uset1 = 0;
2487+
2488+ if(!s2 || *s2 != '.')
2489+ uset2 = 0;
2490+
2491+ if(uset1 && uset2) /* normal sort order */
2492+ return (t1 < t2) ? -1 : (t1 > t2 ? 1 : (cmp < 0 ? -1 : 1));
2493+
2494+ /* If we make it here we say Grrrr.... first, then we try to figure out
2495+ * how to sort this mess.
2496+ * These are the rules.
2497+ * If there is a number at the beginning it is bigger than anything else.
2498+ * If there are digits, then the number of digits decides which one is bigger.
2499+ */
2500+
2501+ for(i = 0; isdigit(name1[i]); i++);
2502+ for(j = 0; isdigit(name2[j]); j++);
2503+
2504+ return(uset1 ? 1
2505+ : (uset2 ? -1
2506+ : (i < j ? -1 : (i > j ? 1 : (cmp < 0 ? -1 : 1)))));
2507+ }
2508+
2509+ void
2510+ maildir_getflag(char *name, int *d, int *f, int *r ,int *s, int *t)
2511+ {
2512+ char tmp[MAILTMPLEN], *b;
2513+ int offset = 0;
2514+ int tmpd, tmpf, tmpr, tmps, tmpt;
2515+
2516+ if(d) *d = 0;
2517+ if(f) *f = 0;
2518+ if(r) *r = 0;
2519+ if(s) *s = 0;
2520+ if(t) *t = 0;
2521+
2522+ tmpd = tmpf = tmpr = tmps = tmpt = NIL; /* no flags set by default */
2523+ strcpy(tmp,name);
2524+ while ((b = strrchr(tmp+offset, FLAGSEP)) != NULL){
2525+ char flag,last;
2526+ int k;
2527+ if (!++b) break;
2528+ switch (*b){
2529+ case '1':
2530+ case '2':
2531+ case '3': flag = *b; b += 2;
2532+ for (k = 0; b[k] && b[k] != FLAGSEP && b[k] != ','; k++);
2533+ last = b[k];
2534+ b[k] = '\0';
2535+ if (flag == '2' || flag == '3'){
2536+ tmpd = strchr (b, MDFLAGC(Draft)) ? T : NIL;
2537+ tmpf = strchr (b, MDFLAGC(Flagged)) ? T : NIL;
2538+ tmpr = strchr (b, MDFLAGC(Replied)) ? T : NIL;
2539+ tmps = strchr (b, MDFLAGC(Seen)) ? T : NIL;
2540+ tmpt = strchr (b, MDFLAGC(Trashed)) ? T : NIL;
2541+ }
2542+ b[k] = last;
2543+ b += k;
2544+ for (; tmp[offset] && tmp[offset] != FLAGSEP; offset++);
2545+ offset++;
2546+ break;
2547+ default: break; /* Should we crash?... Nahhh */
2548+ }
2549+ }
2550+ if(d) *d = tmpd;
2551+ if(f) *f = tmpf;
2552+ if(r) *r = tmpr;
2553+ if(s) *s = tmps;
2554+ if(t) *t = tmpt;
2555+ }
2556+
2557+ int
2558+ maildir_message_in_list(char *msgname, struct direct **names,
2559+ unsigned long bottom, unsigned long top, unsigned long *pos)
2560+ {
2561+ unsigned long middle = (bottom + top)/2;
2562+ int test;
2563+
2564+ if (!msgname)
2565+ return NIL;
2566+
2567+ if (pos) *pos = middle;
2568+
2569+ if (same_maildir_file(msgname, names[middle]->d_name))
2570+ return T;
2571+
2572+ if (middle == bottom){ /* 0 <= 0 < 1 */
2573+ int rv = NIL;
2574+ if (same_maildir_file(msgname, names[middle]->d_name)){
2575+ rv = T;
2576+ if (pos) *pos = middle;
2577+ }
2578+ else
2579+ if (same_maildir_file(msgname, names[top]->d_name)){
2580+ rv = T;
2581+ if (pos) *pos = top;
2582+ }
2583+ return rv;
2584+ }
2585+
2586+ test = comp_maildir_file(msgname, names[middle]->d_name);
2587+
2588+ if (top <= bottom)
2589+ return test ? NIL : T;
2590+
2591+ if (test < 0 ) /* bottom < msgname < middle */
2592+ return maildir_message_in_list(msgname, names, bottom, middle, pos);
2593+ else if (test > 0) /* middle < msgname < top */
2594+ return maildir_message_in_list(msgname, names, middle, top, pos);
2595+ else return T;
2596+ }
2597+
2598+ void
2599+ maildir_abort(MAILSTREAM *stream)
2600+ {
2601+ if (LOCAL){
2602+ DirNamesType i;
2603+
2604+ if(LOCAL->candouid)
2605+ maildir_read_uid(stream, NULL, &stream->uid_validity);
2606+ if (LOCAL->dir) fs_give ((void **) &LOCAL->dir);
2607+ for (i = Cur; i < EndDir; i++)
2608+ if(LOCAL->path[i]) fs_give ((void **) &LOCAL->path[i]);
2609+ fs_give ((void **) &LOCAL->path);
2610+ if (LOCAL->buf) fs_give ((void **) &LOCAL->buf);
2611+ if(LOCAL->uidtempfile){
2612+ unlink(LOCAL->uidtempfile);
2613+ fs_give ((void **) &LOCAL->uidtempfile);
2614+ }
2615+ fs_give ((void **) &stream->local);
2616+ }
2617+ if (mdfpath) fs_give((void **)&mdfpath);
2618+ stream->dtb = NIL;
2619+ }
2620+
2621+ int
2622+ maildir_contains_folder(char *dirname, char *name)
2623+ {
2624+ char tmp[MAILTMPLEN], tmp2[MAILTMPLEN];
2625+ int rv = 0;
2626+ DIR *dir;
2627+ struct direct *d;
2628+
2629+ maildir_file_path(dirname, tmp2, sizeof(tmp2));
2630+ if(name){
2631+ strcat(tmp2,"/");
2632+ strcat(tmp2, name);
2633+ }
2634+
2635+ if (!(dir = opendir (tmp2)))
2636+ return NIL;
2637+
2638+ while ((d = readdir(dir)) != NULL){
2639+ if (strcmp(d->d_name, ".") && strcmp(d->d_name,"..")
2640+ && strcmp(d->d_name, MDNAME(Cur))
2641+ && strcmp(d->d_name, MDNAME(Tmp))
2642+ && strcmp(d->d_name, MDNAME(New))){
2643+
2644+ snprintf(tmp, sizeof(tmp), "%s/%s", tmp2, d->d_name);
2645+ if(maildir_valid(tmp)){
2646+ rv++;
2647+ break;
2648+ }
2649+ }
2650+ }
2651+ closedir(dir);
2652+ return rv;
2653+ }
2654+
2655+ int
2656+ maildir_is_dir(char *dirname, char *name)
2657+ {
2658+ char tmp[MAILTMPLEN];
2659+ struct stat sbuf;
2660+
2661+ maildir_file_path(dirname, tmp, sizeof(tmp));
2662+ if(name){
2663+ strcat(tmp, "/");
2664+ strcat(tmp, name);
2665+ }
2666+ strcat(tmp, "/");
2667+ strcat(tmp, MDDIR);
2668+
2669+ return ((stat(tmp, &sbuf) == 0) && S_ISREG (sbuf.st_mode)) ? 1 : 0;
2670+ }
2671+
2672+ int
2673+ maildir_dir_is_empty(char *mailbox)
2674+ {
2675+ char tmp[MAILTMPLEN], tmp2[MAILTMPLEN], tmp3[MAILTMPLEN],*s;
2676+ int rv = 1, courier = IS_COURIER(mailbox);
2677+ DIR *dir;
2678+ struct direct *d;
2679+ struct stat sbuf;
2680+
2681+ maildir_file_path(mailbox, tmp2, sizeof(tmp2));
2682+
2683+ if(courier){
2684+ strcpy(tmp3, tmp2);
2685+ if(s = strrchr(tmp2, '/'))
2686+ *s = '\0';
2687+ }
2688+
2689+ if (!(dir = opendir (tmp2)))
2690+ return rv;
2691+
2692+ if(courier){
2693+ while((d = readdir(dir)) != NULL){
2694+ snprintf(tmp, sizeof(tmp), "%s/%s", tmp2, d->d_name);
2695+ if(!strncmp(tmp, tmp3, strlen(tmp3))
2696+ && tmp[strlen(tmp3)] == '.'){
2697+ rv = 0;
2698+ break;
2699+ }
2700+ }
2701+ }
2702+ else
2703+ while ((d = readdir(dir)) != NULL){
2704+ snprintf(tmp, sizeof(tmp), "%s/%s", tmp2, d->d_name);
2705+ if (strcmp(d->d_name, ".")
2706+ && strcmp(d->d_name,"..")
2707+ && strcmp(d->d_name, MDNAME(Cur))
2708+ && strcmp(d->d_name, MDNAME(Tmp))
2709+ && strcmp(d->d_name, MDNAME(New))
2710+ && strcmp(d->d_name, MDDIR)
2711+ && strcmp(d->d_name, MDUIDVALIDITY)
2712+ && !(d->d_name[0] == '.'
2713+ && stat (tmp,&sbuf) == 0
2714+ && S_ISREG(sbuf.st_mode))){
2715+ rv = 0;
2716+ break;
2717+ }
2718+ }
2719+ closedir(dir);
2720+ return rv;
2721+ }
2722+
2723+ void
2724+ maildir_get_file (MAILDIRFILE **mdfile)
2725+ {
2726+ MAILDIRFILE *md;
2727+
2728+ md = (MAILDIRFILE *) fs_get(sizeof(MAILDIRFILE));
2729+ memset(md, 0, sizeof(MAILDIRFILE));
2730+ *mdfile = md;
2731+ }
2732+
2733+ void
2734+ maildir_free_file (void **mdfile)
2735+ {
2736+ MAILDIRFILE *md = (mdfile && *mdfile) ? (MAILDIRFILE *) *mdfile : NULL;
2737+
2738+ if (md){
2739+ if (md->name) fs_give((void **)&md->name);
2740+ fs_give((void **)&md);
2741+ }
2742+ }
2743+
2744+ void
2745+ maildir_free_file_only (void **mdfile)
2746+ {
2747+ MAILDIRFILE *md = (mdfile && *mdfile) ? (MAILDIRFILE *) *mdfile : NULL;
2748+
2749+ if (md && md->name)
2750+ fs_give((void **)&md->name);
2751+ }
2752+
2753+ int
2754+ maildir_any_new_msgs(char *mailbox)
2755+ {
2756+ char tmp[MAILTMPLEN];
2757+ int rv = NIL;
2758+ DIR *dir;
2759+ struct direct *d;
2760+
2761+ MDFLD(tmp, mailbox, New);
2762+
2763+ if (!(dir = opendir (tmp)))
2764+ return rv;
2765+
2766+ while ((d = readdir(dir)) != NULL){
2767+ if (d->d_name[0] == '.')
2768+ continue;
2769+ rv = T;
2770+ break;
2771+ }
2772+ closedir(dir);
2773+ return rv;
2774+ }
2775+
2776+
2777+ void
2778+ maildir_get_date(MAILSTREAM *stream, unsigned long msgno)
2779+ {
2780+ MESSAGECACHE *elt;
2781+ struct tm *t;
2782+ time_t ti;
2783+ int i,k;
2784+
2785+ elt = mail_elt (stream,msgno);
2786+ if(elt && elt->year != 0)
2787+ return;
2788+ if ((ti = mdfntoul(MDFILE(elt))) > 0L && (t = gmtime(&ti))){
2789+ i = t->tm_hour * 60 + t->tm_min;
2790+ k = t->tm_yday;
2791+ t = localtime(&ti);
2792+ i = t->tm_hour * 60 + t->tm_min - i;
2793+ if((k = t->tm_yday - k) != 0)
2794+ i += ((k < 0) == (abs (k) == 1)) ? -24*60 : 24*60;
2795+ k = abs (i);
2796+ elt->hours = t->tm_hour;
2797+ elt->minutes = t->tm_min;
2798+ elt->seconds = t->tm_sec;
2799+ elt->day = t->tm_mday; elt->month = t->tm_mon + 1;
2800+ elt->year = t->tm_year - (BASEYEAR - 1900);
2801+ elt->zoccident = (k == i) ? 0 : 1;
2802+ elt->zhours = k/60;
2803+ elt->zminutes = k % 60;
2804+ }
2805+ }
2806+
2807+ /* Support for Courier Style directories
2808+ When this code is complete there will be two types of support, which
2809+ will be configurable. The problem is the following: In Courier style
2810+ folder structure, a "folder" may have a subfolder called
2811+ "folder.subfolder", which is not natural in the file system in the
2812+ sense that I can not stat for "folder.subfolder" wihtout knowing what
2813+ "subfolder" is. It needs to be guessed. Because of this I need to look
2814+ in the list of folders if there is a folder with a name
2815+ "folder.subfolder", before I can say if the folder is dual or not. One
2816+ can avoid this annoyance if one ignores the problem by declaring that
2817+ every folder is dual. I will however code as the default the more
2818+ complicated idea of scaning the containing directory each time it is
2819+ modified and search for subfolders, and list the entries it found.
2820+ */
2821+
2822+ int courier_dir_select (const struct direct *name)
2823+ {
2824+ return name->d_name[0] == '.' && (strlen(name->d_name) > 2
2825+ || (strlen(name->d_name) == 2 && name->d_name[1] != '.'));
2826+ }
2827+
2828+ int courier_dir_sort (const struct direct **d1, const struct direct **d2)
2829+ {
2830+ const struct direct *e1 = *(const struct direct **) d1;
2831+ const struct direct *e2 = *(const struct direct **) d2;
2832+
2833+ return strcmp((char *) e1->d_name, (char *) e2->d_name);
2834+ }
2835+
2836+ void courier_free_cdir (COURIER_S **cdir)
2837+ {
2838+ int i;
2839+
2840+ if (!*cdir)
2841+ return;
2842+
2843+ if ((*cdir)->path) fs_give((void **)&((*cdir)->path));
2844+ for (i = 0; i < (*cdir)->total; i++)
2845+ if((*cdir)->data[i]->name) fs_give((void **)&((*cdir)->data[i]->name));
2846+ fs_give((void **)&((*cdir)->data));
2847+ fs_give((void **)&(*cdir));
2848+ }
2849+
2850+ COURIER_S *courier_get_cdir (int total)
2851+ {
2852+ COURIER_S *cdir;
2853+
2854+ cdir = (COURIER_S *)fs_get(sizeof(COURIER_S));
2855+ memset(cdir, 0, sizeof(COURIER_S));
2856+ cdir->data = (COURIERLOCAL **) fs_get(total*sizeof(COURIERLOCAL *));
2857+ memset(cdir->data, 0, sizeof(COURIERLOCAL *));
2858+ cdir->total = total;
2859+ return cdir;
2860+ }
2861+
2862+ int courier_search_list(COURIERLOCAL **data, char *name, int first, int last)
2863+ {
2864+ int try = (first + last)/2;
2865+
2866+ if(!strstr(data[try]->name, name)){
2867+ if(first == try) /* first == last || first + 1 == last */
2868+ return strstr(data[last]->name, name) ? 1 : 0;
2869+ if(strcmp(data[try]->name, name) < 0) /*data[try] < name < data[end] */
2870+ return courier_search_list(data, name, try, last);
2871+ else /* data[begin] < name < data[try] */
2872+ return courier_search_list(data, name, first, try);
2873+ }
2874+ return 1;
2875+ }
2876+
2877+ /* Lists all directories that are subdirectories of a given directory */
2878+
2879+ COURIER_S *courier_list_dir(char *curdir)
2880+ {
2881+ struct direct **names = NIL;
2882+ struct stat sbuf;
2883+ unsigned long ndir;
2884+ COURIER_S *cdir = NULL;
2885+ char tmp[MAILTMPLEN], tmp2[MAILTMPLEN], pathname[MAILTMPLEN],
2886+ realname[MAILTMPLEN];
2887+ int i, j, scand, td;
2888+
2889+ /* There are two cases, either curdir is
2890+ #mc/INBOX. #mc/INBOX.foo
2891+ or
2892+ #mc/Maildir/. #mc/Maildir/.foo
2893+ */
2894+ strcpy(tmp,curdir + 4);
2895+ if(!strncmp(ucase(tmp), "INBOX", 5))
2896+ strcpy(tmp, "#mc/INBOX.");
2897+ else{
2898+ strcpy(tmp, curdir);
2899+ for (i = strlen(tmp) - 1; tmp[i] && tmp[i] != '/'; i--);
2900+ tmp[i+2] = '\0'; /* keep the last "." intact */
2901+ }
2902+ maildir_file_path(tmp, realname, sizeof(realname));
2903+ maildir_scandir (realname, &names, &ndir, &scand, COURIER);
2904+
2905+ if (scand > 0){
2906+ cdir = courier_get_cdir(ndir);
2907+ cdir->path = cpystr(realname);
2908+ for(i = 0, j = 0; i < ndir; i++){
2909+ td = realname[strlen(realname) - 1] == '.'
2910+ && *names[i]->d_name == '.';
2911+ snprintf(tmp2, sizeof(tmp2), "%s%s", tmp, names[i]->d_name+1);
2912+ snprintf(pathname, sizeof(pathname), "%s%s", realname, names[i]->d_name + td);
2913+ if(stat(pathname, &sbuf) == 0 && S_ISDIR(sbuf.st_mode)){
2914+ cdir->data[j] = (COURIERLOCAL *) fs_get(sizeof(COURIERLOCAL));
2915+ cdir->data[j++]->name = cpystr(tmp2);
2916+ }
2917+ fs_give((void **)&names[i]);
2918+ }
2919+ cdir->total = j;
2920+ if(cdir->total == 0)
2921+ courier_free_cdir(&cdir);
2922+ }
2923+ if(names)
2924+ fs_give((void **) &names);
2925+ return cdir;
2926+ }
2927+
2928+ void
2929+ courier_list_info(COURIER_S **cdirp, char *data, int i)
2930+ {
2931+ long style = *(long *) maildir_parameters(GET_COURIERSTYLE, NIL);
2932+ COURIER_S *cdir = *cdirp;
2933+
2934+ if(maildir_valid(cdir->data[i]->name)){
2935+ if(courier_search_list(cdir->data, data, 0, cdir->total - 1))
2936+ cdir->data[i]->attribute = LATT_HASCHILDREN;
2937+ else
2938+ cdir->data[i]->attribute = (style == COURIER)
2939+ ? LATT_HASNOCHILDREN : LATT_NOINFERIORS;
2940+ }
2941+ else
2942+ cdir->data[i]->attribute = LATT_NOSELECT;
2943+ cdir->data[i]->attribute += maildir_any_new_msgs(cdir->data[i]->name)
2944+ ? LATT_MARKED : LATT_UNMARKED;
2945+ }
2946+
2947+ /* UID Support */
2948+ /* Yes, I know I procastinated a lot about this, but here it is finally */
2949+
2950+ /* return code:
2951+ bigger than zero: this session can assign uids
2952+ zero: this session will not assign uid
2953+ smaller than zero: this session temporarily suspends assigning uids
2954+ */
2955+ int
2956+ maildir_can_assign_uid (MAILSTREAM *stream)
2957+ {
2958+ unsigned int rv = 0;
2959+ int ownuid, existuid;
2960+ unsigned long t;
2961+ char tmp[MAILTMPLEN], tmp2[MAILTMPLEN], *p, *s;
2962+ DIR *dir;
2963+ struct direct *d;
2964+
2965+ if(!stream || stream->rdonly
2966+ || !LOCAL || !LOCAL->dir || !(dir = opendir(LOCAL->dir)))
2967+ return 0;
2968+
2969+ if(mypid == (pid_t) 0)
2970+ mypid = getpid();
2971+
2972+ snprintf(tmp, sizeof(tmp), "%s.%d", MDUIDTEMP, mypid);
2973+
2974+ ownuid = existuid = 0;
2975+ s = NULL;
2976+ while ((d = readdir(dir)) != NULL){
2977+ if(strncmp(d->d_name, tmp, strlen(tmp)) == 0){
2978+ existuid++; ownuid++;
2979+ if(ownuid > 1){
2980+ snprintf(tmp2, sizeof(tmp), "%s/%s", LOCAL->dir, d->d_name);
2981+ unlink(tmp2);
2982+ if(s){
2983+ snprintf(tmp2, sizeof(tmp2), "%s/%s", LOCAL->dir, s);
2984+ unlink(tmp2);
2985+ fs_give((void **)&s);
2986+ }
2987+ }
2988+ else
2989+ s = cpystr(d->d_name);
2990+ }
2991+ else if(strncmp(d->d_name, MDUIDTEMP, strlen(MDUIDTEMP)) == 0)
2992+ existuid++;
2993+ }
2994+
2995+ closedir(dir);
2996+ if(s)
2997+ fs_give((void **)&s);
2998+
2999+ if(ownuid == 1 && existuid == 1)
3000+ rv = 1;
3001+
3002+ if(ownuid == 0 && existuid == 0){ /* nobody owns the uid? */
3003+ FILE *fp;
3004+ snprintf(tmp, sizeof(tmp), "%s/%s.%d.%lu", LOCAL->dir, MDUIDTEMP, mypid, time(0));
3005+ if(fp = fopen(tmp, "w")){
3006+ fclose(fp);
3007+ if(LOCAL->uidtempfile)
3008+ fs_give((void **)&LOCAL->uidtempfile);
3009+ LOCAL->uidtempfile = cpystr(tmp);
3010+ }
3011+ rv = 1;
3012+ }
3013+
3014+ if(ownuid == 0 && existuid > 0) /* someone else owns uid assignment */
3015+ return 0;
3016+
3017+ /* if we own the uid, check that we do not own it more than once
3018+ * or that we share ownership. If any of these situations happens,
3019+ * give up the ownership until we can recover it
3020+ */
3021+
3022+ if(ownuid > 0){
3023+ if(ownuid > 1) /* impossible, two lock files for the same session */
3024+ return (-1)*ownuid;
3025+
3026+ if(ownuid != existuid){ /* lock files for different sessions */
3027+ if(LOCAL->uidtempfile){
3028+ unlink(LOCAL->uidtempfile);
3029+ fs_give((void **)&LOCAL->uidtempfile);
3030+ }
3031+ return (-1)*ownuid;
3032+ }
3033+ }
3034+
3035+ return rv;
3036+ }
3037+
3038+ void
3039+ maildir_read_uid(MAILSTREAM *stream, unsigned long *uid_last,
3040+ unsigned long *uid_validity)
3041+ {
3042+ int createuid, deleteuid = 0;
3043+ char tmp[MAILTMPLEN], *s = NULL;
3044+ DIR *dir;
3045+ struct direct *d;
3046+
3047+ if(uid_last) *uid_last = 0L;
3048+ if(uid_last && uid_validity) *uid_validity = time(0);
3049+ if(!stream || !LOCAL || !LOCAL->dir || !(dir = opendir(LOCAL->dir)))
3050+ return;
3051+
3052+ while ((d = readdir(dir)) != NULL){
3053+ if(!strncmp(d->d_name, MDUIDLAST, strlen(MDUIDLAST)))
3054+ break;
3055+ }
3056+ createuid = d == NULL ? 1 : 0;
3057+ if(uid_last == NULL)
3058+ deleteuid++;
3059+ if(d){
3060+ if(uid_last){
3061+ s = d->d_name + strlen(MDUIDLAST) + 1;
3062+ *uid_last = strtoul(s, &s, 10);
3063+ if(!s || *s != '.'){
3064+ deleteuid++;
3065+ createuid++;
3066+ *uid_last = 0L;
3067+ }
3068+ }
3069+ if(s && *s == '.'){
3070+ if(uid_validity){
3071+ s++;
3072+ *uid_validity = strtoul(s, &s, 10);
3073+ if(s && *s != '\0'){
3074+ *uid_validity = time(0);
3075+ deleteuid++;
3076+ createuid++;
3077+ }
3078+ }
3079+ }
3080+ else{
3081+ deleteuid++;
3082+ createuid++;
3083+ }
3084+ }
3085+ if(deleteuid){
3086+ snprintf(tmp, sizeof(tmp), "%s/%s", LOCAL->dir, d->d_name);
3087+ unlink(tmp);
3088+ }
3089+ if(createuid)
3090+ maildir_write_uid(stream, (uid_last ? *uid_last : stream->uid_last),
3091+ uid_validity ? *uid_validity : time(0));
3092+ closedir(dir);
3093+ }
3094+
3095+ void
3096+ maildir_write_uid(MAILSTREAM *stream, unsigned long uid_last,
3097+ unsigned long uid_validity)
3098+ {
3099+ char tmp[MAILTMPLEN];
3100+ FILE *fp;
3101+
3102+ if(!stream || stream->rdonly || !LOCAL || !LOCAL->dir)
3103+ return;
3104+
3105+ snprintf(tmp, sizeof(tmp), "%s/%s.%010lu.%010lu", LOCAL->dir, MDUIDLAST,
3106+ uid_last, uid_validity);
3107+ if(fp = fopen(tmp, "w"))
3108+ fclose(fp);
3109+ }
3110+
3111+ unsigned long
3112+ maildir_get_uid(char *name)
3113+ {
3114+ char *s;
3115+ unsigned long rv = 0L;
3116+
3117+ if(!name || (s = strstr(name,MDUIDSEP)) == NULL)
3118+ return rv;
3119+
3120+ s += strlen(MDUIDSEP);
3121+ rv = strtoul(s, NULL, 10);
3122+ return rv;
3123+ }
3124+
3125+
3126+ void
3127+ maildir_delete_uid(MAILSTREAM *stream, unsigned long msgno)
3128+ {
3129+ char old[MAILTMPLEN], new[MAILTMPLEN], *s, *t;
3130+ MESSAGECACHE *elt;
3131+
3132+ elt = mail_elt(stream, msgno);
3133+ if(!stream || !elt || !elt->private.spare.ptr || !LOCAL || !LOCAL->dir)
3134+ return;
3135+
3136+ snprintf(old, sizeof(old), "%s/%s/%s", LOCAL->dir, MDNAME(Cur), MDFILE(elt));
3137+ t = MDFILE(elt);
3138+ if(s = strstr(MDFILE(elt), MDUIDSEP)){
3139+ *s = '\0';
3140+ s += strlen(MDUIDSEP);
3141+ strtoul(s, &s, 10);
3142+ snprintf(new, sizeof(new), "%s/%s/%s%s", LOCAL->dir, MDNAME(Cur), t, s);
3143+ if(rename(old, new) == 0){
3144+ maildir_free_file_only ((void **)&elt->private.spare.ptr);
3145+ s = strrchr(new, '/');
3146+ MDFILE(elt) = cpystr(s+1);
3147+ }
3148+ elt->private.uid = 0L;
3149+ }
3150+ }
3151+
3152+ void
3153+ maildir_assign_uid(MAILSTREAM *stream, unsigned long msgno, unsigned long uid)
3154+ {
3155+ int createuid, deleteuid = 0;
3156+ char old[MAILTMPLEN], new[MAILTMPLEN], *s, *t;
3157+ MESSAGECACHE *elt;
3158+
3159+ elt = mail_elt(stream, msgno);
3160+ if(!stream || !elt || !elt->private.spare.ptr || !LOCAL || !LOCAL->dir)
3161+ return;
3162+
3163+ maildir_delete_uid(stream, msgno);
3164+ snprintf(old, sizeof(old), "%s/%s/%s", LOCAL->dir, MDNAME(Cur), MDFILE(elt));
3165+ t = MDFILE(elt);
3166+ if((s = strrchr(MDFILE(elt),FLAGSEP)) != NULL){
3167+ *s++ = '\0';
3168+ snprintf(new, sizeof(new), "%s/%s/%s%s%lu%c%s",
3169+ LOCAL->dir, MDNAME(Cur), t, MDUIDSEP, uid, FLAGSEP, s);
3170+ if(rename(old, new) == 0){
3171+ maildir_free_file_only ((void **)&elt->private.spare.ptr);
3172+ s = strrchr(new, '/');
3173+ MDFILE(elt) = cpystr(s+1);
3174+ stream->uid_validity = time(0);
3175+ }
3176+ elt->private.uid = uid;
3177+ }
3178+ }
3179+
3180+ void
3181+ maildir_uid_renew_tempfile(MAILSTREAM *stream)
3182+ {
3183+ char tmp[MAILTMPLEN];
3184+
3185+ if(!stream || stream->rdonly
3186+ || !LOCAL || !LOCAL->candouid || !LOCAL->dir || !LOCAL->uidtempfile)
3187+ return;
3188+
3189+ if(mypid == (pid_t) 0)
3190+ mypid = getpid();
3191+
3192+ snprintf(tmp, sizeof(tmp), "%s/%s.%d.%lu", LOCAL->dir, MDUIDTEMP, mypid, time(0));
3193+ if(rename(LOCAL->uidtempfile, tmp) == 0){
3194+ fs_give((void **)&LOCAL->uidtempfile);
3195+ LOCAL->uidtempfile = cpystr(tmp);
3196+ }
3197+ }
3198diff -rc alpine-2.20/imap/src/osdep/unix/maildir.h alpine-2.20.maildir/imap/src/osdep/unix/maildir.h
3199*** alpine-2.20/imap/src/osdep/unix/maildir.h 2015-02-03 22:28:22.633016235 -0700
3200--- alpine-2.20.maildir/imap/src/osdep/unix/maildir.h 2015-01-20 20:37:55.836011678 -0700
3201***************
3202*** 0 ****
3203--- 1,226 ----
3204+ /*
3205+ * A few definitions that try to make this module portable to other
3206+ * platforms (e.g. Cygwin). This module is based on the information from
3207+ * http://cr.yp.to/proto/maildir.html
3208+ */
3209+
3210+ /* First we deal with the separator character */
3211+ #ifndef FLAGSEP
3212+ #define FLAGSEP ':'
3213+ #endif
3214+ #define SIZESEP ','
3215+
3216+ const char sep1[] = {FLAGSEP, '1', ',', '\0'}; /* experimental semantics*/
3217+ const char sep2[] = {FLAGSEP, '2', ',', '\0'}; /* Flags Information */
3218+ const char sep3[] = {FLAGSEP, '3', ',', '\0'}; /* Grrrr.... */
3219+
3220+ const char *sep[] = { sep1, sep2, sep3, NULL};
3221+
3222+ #define MDSEP(i) sep[((i) - 1)]
3223+
3224+ /* Now we deal with flags. Woohoo! */
3225+ typedef enum {Draft, Flagged, Passed, Replied, Seen, Trashed,
3226+ EmptyFlag, EndFlags} MdFlagNamesType;
3227+ const int mdimapflags[] = {Draft, Flagged, Replied, Seen, Trashed, EmptyFlag, EndFlags};
3228+ const int mdkwdflags[] = {Passed, EmptyFlag, EndFlags};
3229+
3230+ /* this array lists the codes for mdflgnms (maildir flag names) above */
3231+ const char *mdflags[] = { "D", "F", "P", "R", "S", "T", "", NULL};
3232+ /* and as characters too */
3233+ const char cmdflags[] = { 'D', 'F', 'P', 'R', 'S', 'T', '0', '\0'};
3234+
3235+ /* MDFLAG(Seen, elt->seen) */
3236+ #define MDFLAG(i,j) mdflags[j ? (i) : EmptyFlag]
3237+ /* MDFLAGC(Seen) */
3238+ #define MDFLAGC(i) cmdflags[(i)]
3239+
3240+ /* Now we deal with the directory structure */
3241+ typedef enum {Cur, Tmp, New, EndDir} DirNamesType;
3242+ char *mdstruct[] = {"cur", "tmp", "new", NULL};
3243+ #define MDNAME(i) mdstruct[(i)]
3244+ #define MDFLD(tmp, dir, i) sprintf((tmp),"%s/%s", (dir), mdstruct[(i)])
3245+ #define MSGPATH(tmp, dir, msg,i) sprintf((tmp),"%s/%s/%s", (dir), mdstruct[(i)],(msg))
3246+
3247+ /* Files associated to a maildir directory */
3248+
3249+ #define MDUIDVALIDITY ".uidvalidity" /* support for old maildirs */
3250+ #define MDDIR ".mdir" /* this folder is a directory */
3251+ #define MDUIDLAST ".uidlast" /* last assigned uid */
3252+ #define MDUIDTEMP ".uidtemp" /* We assign uid's no one else */
3253+
3254+
3255+
3256+ /* Support of Courier Structure */
3257+ #define CCLIENT 0
3258+ #define COURIER 1
3259+ #define IS_CCLIENT(t) \
3260+ (((t) && (t)[0] == '#' && ((t)[1] == 'm' || (t)[1] == 'M')\
3261+ && ((t)[2] == 'd' || (t)[2] == 'D')\
3262+ && (t)[3] == '/' && (t)[4] != '\0') ? 1 : 0)
3263+
3264+ #define IS_COURIER(t) \
3265+ (((t) && (t)[0] == '#' && ((t)[1] == 'm' || (t)[1] == 'M')\
3266+ && ((t)[2] == 'c' || (t)[2] == 'C')\
3267+ && (t)[3] == '/' && (t)[4] != '\0') ? 1 : 0)
3268+ #define MDPREFIX(s) ((s) ? "#mc/" : "#md/")
3269+ #define MDSEPARATOR(s) ((s) ? '.' : '/')
3270+
3271+ /* UID Support */
3272+
3273+ #define MAXTEMPUID (unsigned long) 180L
3274+ const char mduid[] = {',','u','=','\0'};
3275+ #define MDUIDSEP mduid
3276+
3277+
3278+ /* Now we deal with messages filenames */
3279+ char mdlocaldomain[MAILTMPLEN+1] = {'\0'};
3280+ pid_t mypid = (pid_t) 0;
3281+ static char *mdfpath = NULL;
3282+ static char myMdInboxDir[50] = { '\0' };/* Location of the Maildir INBOX */
3283+ static long CourierStyle = CCLIENT;
3284+
3285+ #define CHUNK 16384 /* from unix.h */
3286+
3287+ typedef struct courier_local {
3288+ char *name; /* name of directory/folder */
3289+ int attribute; /* attributes (children/marked/etc) */
3290+ } COURIERLOCAL;
3291+
3292+ typedef struct courier {
3293+ char *path; /* Path to collection */
3294+ time_t scantime; /* time at which information was generated */
3295+ int total; /* total number of elements in data */
3296+ COURIERLOCAL **data;
3297+ } COURIER_S;
3298+
3299+ /* In gdb this is the *(struct maildir_local *)stream->local structure */
3300+ typedef struct maildir_local {
3301+ unsigned int dirty : 1; /* diskcopy needs updating */
3302+ unsigned int courier : 1; /* It is Courier style file system */
3303+ unsigned int link : 1; /* There is a symbolic link */
3304+ int candouid; /* we can assign uids and no one else */
3305+ char *uidtempfile; /* path to uid temp file */
3306+ int fd; /* fd of open message */
3307+ char *dir; /* mail directory name */
3308+ char **path; /* path to directories cur, new and tmp */
3309+ unsigned char *buf; /* temporary buffer */
3310+ unsigned long buflen; /* current size of temporary buffer */
3311+ time_t scantime; /* last time directory scanned */
3312+ } MAILDIRLOCAL;
3313+
3314+ /* Convenient access to local data */
3315+ #define LOCAL ((MAILDIRLOCAL *) stream->local)
3316+
3317+ typedef struct maildir_file_info {
3318+ char *name; /* name of the file */
3319+ DirNamesType loc; /* location of this file */
3320+ unsigned long pos; /* place in list where this file is listed */
3321+ off_t size; /* size in bytes, on disk */
3322+ time_t atime; /* last access time */
3323+ time_t mtime; /* last modified time */
3324+ time_t ctime; /* last changed time */
3325+ } MAILDIRFILE;
3326+
3327+ #define MDFILE(F) (((MAILDIRFILE *)((F)->private.spare.ptr))->name)
3328+ #define MDLOC(F) (((MAILDIRFILE *)((F)->private.spare.ptr))->loc)
3329+ #define MDPOS(F) (((MAILDIRFILE *)((F)->private.spare.ptr))->pos)
3330+ #define MDSIZE(F) (((MAILDIRFILE *)((F)->private.spare.ptr))->size)
3331+ #define MDATIME(F) (((MAILDIRFILE *)((F)->private.spare.ptr))->atime)
3332+ #define MDMTIME(F) (((MAILDIRFILE *)((F)->private.spare.ptr))->mtime)
3333+ #define MDCTIME(F) (((MAILDIRFILE *)((F)->private.spare.ptr))->ctime)
3334+
3335+ /* Function prototypes */
3336+
3337+ DRIVER *maildir_valid (char *name);
3338+ MAILSTREAM *maildir_open (MAILSTREAM *stream);
3339+ void maildir_close (MAILSTREAM *stream, long options);
3340+ long maildir_ping (MAILSTREAM *stream);
3341+ void maildir_check (MAILSTREAM *stream);
3342+ long maildir_text (MAILSTREAM *stream,unsigned long msgno,STRING *bs,long flags);
3343+ char *maildir_header (MAILSTREAM *stream,unsigned long msgno,
3344+ unsigned long *length, long flags);
3345+ void maildir_list (MAILSTREAM *stream,char *ref,char *pat);
3346+ void *maildir_parameters (long function,void *value);
3347+ int maildir_create_folder (char *mailbox);
3348+ long maildir_create (MAILSTREAM *stream,char *mailbox);
3349+ void maildir_flagmsg (MAILSTREAM *stream,MESSAGECACHE *elt); /*check */
3350+ long maildir_expunge (MAILSTREAM *stream, char *sequence, long options);
3351+ long maildir_copy (MAILSTREAM *stream,char *sequence,char *mailbox,long options);
3352+ long maildir_append (MAILSTREAM *stream,char *mailbox, append_t af, void *data);
3353+ long maildir_delete (MAILSTREAM *stream,char *mailbox);
3354+ long maildir_rename (MAILSTREAM *stream,char *old,char *new);
3355+ long maildir_sub (MAILSTREAM *stream,char *mailbox);
3356+ long maildir_unsub (MAILSTREAM *stream,char *mailbox);
3357+ void maildir_lsub (MAILSTREAM *stream,char *ref,char *pat);
3358+ void courier_list (MAILSTREAM *stream,char *ref, char *pat);
3359+
3360+ /* utility functions */
3361+ void courier_realname (char *name, char *realname);
3362+ long maildir_dirfmttest (char *name);
3363+ char *maildir_file (char *dst,char *name);
3364+ int maildir_select (const struct direct *name);
3365+ int maildir_namesort (const struct direct **d1, const struct direct **d2);
3366+ unsigned long antoul (char *seed);
3367+ unsigned long mdfntoul (char *name);
3368+ int courier_dir_select (const struct direct *name);
3369+ int courier_dir_sort (const struct direct **d1, const struct direct **d2);
3370+ long maildir_canonicalize (char *pattern,char *ref,char *pat);
3371+ void maildir_list_work (MAILSTREAM *stream,char *subdir,char *pat,long level);
3372+ void courier_list_work (MAILSTREAM *stream,char *subdir,char *pat,long level);
3373+ int maildir_file_path(char *name, char *tmp, size_t sizeoftmp);
3374+ int maildir_valid_name (char *name);
3375+ int maildir_valid_dir (char *name);
3376+ int is_valid_maildir (char **name);
3377+ int maildir_message_exists(MAILSTREAM *stream,char *name, char *tmp);
3378+ char *maildir_remove_root(char *name);
3379+ char *maildir_text_work (MAILSTREAM *stream,MESSAGECACHE *elt, unsigned long *length,long flags);
3380+ unsigned long maildir_parse_message(MAILSTREAM *stream, unsigned long msgno,
3381+ DirNamesType dirtype);
3382+ int maildir_eliminate_duplicate (char *name, struct direct ***flist,
3383+ unsigned long *nfiles);
3384+ int maildir_doscandir (char *name, struct direct ***flist, int flag);
3385+ unsigned long maildir_scandir (char *name, struct direct ***flist,
3386+ unsigned long *nfiles, int *scand, int flag);
3387+ void maildir_parse_folder (MAILSTREAM *stream, int full);
3388+ void md_domain_name (void);
3389+ char *myrootdir (char *name);
3390+ char *mdirpath (void);
3391+ int maildir_initial_check (MAILSTREAM *stream, DirNamesType dirtype);
3392+ unsigned long maildir_parse_dir(MAILSTREAM *stream, unsigned long nmsgs,
3393+ DirNamesType dirtype, struct direct **names, unsigned long nfiles, int full);
3394+ int same_maildir_file(char *name1, char *name2);
3395+ int comp_maildir_file(char *name1, char *name2);
3396+ int maildir_message_in_list(char *msgname, struct direct **names,
3397+ unsigned long bottom, unsigned long top, unsigned long *pos);
3398+ void maildir_getflag(char *name, int *d, int *f, int *r ,int *s, int *t);
3399+ int maildir_update_elt_maildirp(MAILSTREAM *stream, unsigned long msgno);
3400+ void maildir_abort (MAILSTREAM *stream);
3401+ int maildir_contains_folder(char *dirname, char *name);
3402+ int maildir_is_dir(char *dirname, char *name);
3403+ int maildir_dir_is_empty(char *mailbox);
3404+ int maildir_create_work (char *mailbox, int loop);
3405+ void maildir_get_file (MAILDIRFILE **mdfile);
3406+ void maildir_free_file (void **mdfile);
3407+ void maildir_free_file_only (void **mdfile);
3408+ int maildir_any_new_msgs(char *mailbox);
3409+ void maildir_get_date(MAILSTREAM *stream, unsigned long msgno);
3410+ void maildir_fast (MAILSTREAM *stream,char *sequence,long flags);
3411+
3412+ /* Courier server support */
3413+ void courier_free_cdir (COURIER_S **cdir);
3414+ COURIER_S *courier_get_cdir (int total);
3415+ int courier_search_list(COURIERLOCAL **data, char *name, int first, int last);
3416+ COURIER_S *courier_list_dir(char *curdir);
3417+ void courier_list_info(COURIER_S **cdirp, char *data, int i);
3418+
3419+ /* UID Support */
3420+ int maildir_can_assign_uid (MAILSTREAM *stream);
3421+ void maildir_read_uid(MAILSTREAM *stream, unsigned long *uid_last,
3422+ unsigned long *uid_validity);
3423+ void maildir_write_uid(MAILSTREAM *stream, unsigned long uid_last,
3424+ unsigned long uid_validity);
3425+ unsigned long maildir_get_uid(char *name);
3426+ void maildir_delete_uid(MAILSTREAM *stream, unsigned long msgno);
3427+ void maildir_assign_uid(MAILSTREAM *stream, unsigned long msgno, unsigned long uid);
3428+ void maildir_uid_renew_tempfile(MAILSTREAM *stream);
3429+
3430diff -rc alpine-2.20/imap/src/osdep/unix/Makefile alpine-2.20.maildir/imap/src/osdep/unix/Makefile
3431*** alpine-2.20/imap/src/osdep/unix/Makefile 2015-01-11 22:12:25.505178442 -0700
3432--- alpine-2.20.maildir/imap/src/osdep/unix/Makefile 2015-01-20 20:37:55.849011678 -0700
3433***************
3434*** 147,153 ****
3435 # However, mh needs to be before any sysinbox formats (such as mmdf or unix)
3436 # since otherwise INBOX won't work correctly when mh_allow_inbox is set.
3437 #
3438! DEFAULTDRIVERS=imap nntp pop3 mix mx mbx tenex mtx mh mmdf unix news phile
3439 CHUNKSIZE=65536
3440
3441 # Normally no need to change any of these
3442--- 147,153 ----
3443 # However, mh needs to be before any sysinbox formats (such as mmdf or unix)
3444 # since otherwise INBOX won't work correctly when mh_allow_inbox is set.
3445 #
3446! DEFAULTDRIVERS=maildir courier imap nntp pop3 mix mx mbx tenex mtx mh mmdf unix news phile
3447 CHUNKSIZE=65536
3448
3449 # Normally no need to change any of these
3450***************
3451*** 156,162 ****
3452 BINARIES=osdep.o mail.o misc.o newsrc.o smanager.o utf8.o utf8aux.o siglocal.o \
3453 dummy.o pseudo.o netmsg.o flstring.o fdstring.o \
3454 rfc822.o nntp.o smtp.o imap4r1.o pop3.o \
3455! unix.o mbx.o mmdf.o tenex.o mtx.o news.o phile.o mh.o mx.o mix.o
3456 CFLAGS=-g
3457
3458 CAT=cat
3459--- 156,162 ----
3460 BINARIES=osdep.o mail.o misc.o newsrc.o smanager.o utf8.o utf8aux.o siglocal.o \
3461 dummy.o pseudo.o netmsg.o flstring.o fdstring.o \
3462 rfc822.o nntp.o smtp.o imap4r1.o pop3.o \
3463! unix.o mbx.o mmdf.o tenex.o mtx.o news.o phile.o mh.o mx.o mix.o maildir.o
3464 CFLAGS=-g
3465
3466 CAT=cat
3467***************
3468*** 293,299 ****
3469
3470 cyg: # Cygwin - note that most local file drivers don't work!!
3471 $(BUILD) `$(CAT) SPECIALS` OS=$@ \
3472! DEFAULTDRIVERS="imap nntp pop3 mbx unix phile" \
3473 SIGTYPE=psx CHECKPW=cyg LOGINPW=cyg CRXTYPE=std \
3474 SPOOLDIR=/var \
3475 ACTIVEFILE=/usr/local/news/lib/active \
3476--- 293,299 ----
3477
3478 cyg: # Cygwin - note that most local file drivers don't work!!
3479 $(BUILD) `$(CAT) SPECIALS` OS=$@ \
3480! DEFAULTDRIVERS="imap nntp pop3 mbx unix maildir phile" \
3481 SIGTYPE=psx CHECKPW=cyg LOGINPW=cyg CRXTYPE=std \
3482 SPOOLDIR=/var \
3483 ACTIVEFILE=/usr/local/news/lib/active \
3484***************
3485*** 911,917 ****
3486 unix.o: mail.h misc.h osdep.h unix.h pseudo.h dummy.h
3487 utf8.o: mail.h misc.h osdep.h utf8.h tmap.c widths.c
3488 utf8aux.o: mail.h misc.h osdep.h utf8.h
3489!
3490
3491 # OS-dependent
3492
3493--- 911,917 ----
3494 unix.o: mail.h misc.h osdep.h unix.h pseudo.h dummy.h
3495 utf8.o: mail.h misc.h osdep.h utf8.h tmap.c widths.c
3496 utf8aux.o: mail.h misc.h osdep.h utf8.h
3497! maildir.o: mail.h misc.h osdep.h maildir.h dummy.h
3498
3499 # OS-dependent
3500
3501diff -rc alpine-2.20/imap/src/osdep/unix/os_cyg.h alpine-2.20.maildir/imap/src/osdep/unix/os_cyg.h
3502*** alpine-2.20/imap/src/osdep/unix/os_cyg.h 2015-01-11 22:12:25.506178446 -0700
3503--- alpine-2.20.maildir/imap/src/osdep/unix/os_cyg.h 2015-01-20 20:37:55.850011678 -0700
3504***************
3505*** 47,52 ****
3506--- 47,53 ----
3507 #define setpgrp setpgid
3508
3509 #define SYSTEMUID 18 /* Cygwin returns this for SYSTEM */
3510+ #define FLAGSEP ';'
3511 #define geteuid Geteuid
3512 uid_t Geteuid (void);
3513
3514diff -rc alpine-2.20/include/config.h alpine-2.20.maildir/include/config.h
3515*** alpine-2.20/include/config.h 2015-01-18 00:00:55.367703433 -0700
3516--- alpine-2.20.maildir/include/config.h 2015-01-20 20:38:26.764015680 -0700
3517***************
3518*** 148,154 ****
3519 /* #undef ENABLE_DMALLOC */
3520
3521 /* Enable LDAP query support */
3522! /* #undef ENABLE_LDAP */
3523
3524 /* Define to 1 if translation of program messages to the user's native
3525 language is requested. */
3526--- 148,154 ----
3527 /* #undef ENABLE_DMALLOC */
3528
3529 /* Enable LDAP query support */
3530! #define ENABLE_LDAP /**/
3531
3532 /* Define to 1 if translation of program messages to the user's native
3533 language is requested. */
3534***************
3535*** 474,480 ****
3536 #define KEYBOARD_LOCK /**/
3537
3538 /* Define if you use OpenLDAP 2.3.x deprecated functions */
3539! /* #undef LDAP_DEPRECATED */
3540
3541 /* Define to the sub-directory in which libtool stores uninstalled libraries.
3542 */
3543--- 474,480 ----
3544 #define KEYBOARD_LOCK /**/
3545
3546 /* Define if you use OpenLDAP 2.3.x deprecated functions */
3547! #define LDAP_DEPRECATED 1
3548
3549 /* Define to the sub-directory in which libtool stores uninstalled libraries.
3550 */
3551diff -rc alpine-2.20/pico/Makefile alpine-2.20.maildir/pico/Makefile
3552*** alpine-2.20/pico/Makefile 2015-01-18 00:00:55.257702949 -0700
3553--- alpine-2.20.maildir/pico/Makefile 2015-01-20 20:38:26.513015622 -0700
3554***************
3555*** 246,260 ****
3556 dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
3557 done; \
3558 reldir="$$dir2"
3559! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing aclocal-1.13
3560 AMTAR = $${TAR-tar}
3561 AM_CFLAGS = -g -pthread
3562 AM_DEFAULT_VERBOSITY = 1
3563 AM_LDFLAGS =
3564 AR = /usr/bin/ar
3565! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoconf
3566! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoheader
3567! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing automake-1.13
3568 AWK = gawk
3569 CC = gcc -std=gnu99
3570 CCDEPMODE = depmode=gcc3
3571--- 246,260 ----
3572 dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
3573 done; \
3574 reldir="$$dir2"
3575! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing aclocal-1.13
3576 AMTAR = $${TAR-tar}
3577 AM_CFLAGS = -g -pthread
3578 AM_DEFAULT_VERBOSITY = 1
3579 AM_LDFLAGS =
3580 AR = /usr/bin/ar
3581! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoconf
3582! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoheader
3583! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing automake-1.13
3584 AWK = gawk
3585 CC = gcc -std=gnu99
3586 CCDEPMODE = depmode=gcc3
3587***************
3588*** 265,271 ****
3589 CYGPATH_W = echo
3590 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
3591 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
3592! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5"
3593 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
3594 C_CLIENT_TARGET = lsu
3595 C_CLIENT_WITH_IPV6 = touch imap/ip6
3596--- 265,271 ----
3597 CYGPATH_W = echo
3598 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
3599 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
3600! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5"
3601 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
3602 C_CLIENT_TARGET = lsu
3603 C_CLIENT_WITH_IPV6 = touch imap/ip6
3604***************
3605*** 296,302 ****
3606 LIBICONV = -liconv
3607 LIBINTL =
3608 LIBOBJS =
3609! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5
3610 LIBTOOL = $(SHELL) $(top_builddir)/libtool
3611 LIBTOOL_DEPS = ./ltmain.sh
3612 LIPO =
3613--- 296,302 ----
3614 LIBICONV = -liconv
3615 LIBINTL =
3616 LIBOBJS =
3617! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5
3618 LIBTOOL = $(SHELL) $(top_builddir)/libtool
3619 LIBTOOL_DEPS = ./ltmain.sh
3620 LIPO =
3621***************
3622*** 308,314 ****
3623 LTLIBOBJS =
3624 MAINT = #
3625 MAKE = /usr/bin/make
3626! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing makeinfo
3627 MANIFEST_TOOL = :
3628 MKDIR_P = /usr/bin/mkdir -p
3629 MSGFMT = /usr/bin/msgfmt
3630--- 308,314 ----
3631 LTLIBOBJS =
3632 MAINT = #
3633 MAKE = /usr/bin/make
3634! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing makeinfo
3635 MANIFEST_TOOL = :
3636 MKDIR_P = /usr/bin/mkdir -p
3637 MSGFMT = /usr/bin/msgfmt
3638***************
3639*** 352,361 ****
3640 WEB_PUBCOOKIE_LINK =
3641 XGETTEXT = /usr/bin/xgettext
3642 XGETTEXT_015 = /usr/bin/xgettext
3643! abs_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/pico
3644! abs_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/pico
3645! abs_top_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
3646! abs_top_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
3647 ac_ct_AR = ar
3648 ac_ct_CC = gcc
3649 ac_ct_DUMPBIN =
3650--- 352,361 ----
3651 WEB_PUBCOOKIE_LINK =
3652 XGETTEXT = /usr/bin/xgettext
3653 XGETTEXT_015 = /usr/bin/xgettext
3654! abs_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/pico
3655! abs_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/pico
3656! abs_top_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
3657! abs_top_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
3658 ac_ct_AR = ar
3659 ac_ct_CC = gcc
3660 ac_ct_DUMPBIN =
3661***************
3662*** 387,393 ****
3663 htmldir = ${docdir}
3664 includedir = ${prefix}/include
3665 infodir = ${datarootdir}/info
3666! install_sh = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/install-sh
3667 libdir = ${exec_prefix}/lib
3668 libexecdir = ${exec_prefix}/libexec
3669 localedir = ${datadir}/locale
3670--- 387,393 ----
3671 htmldir = ${docdir}
3672 includedir = ${prefix}/include
3673 infodir = ${datarootdir}/info
3674! install_sh = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/install-sh
3675 libdir = ${exec_prefix}/lib
3676 libexecdir = ${exec_prefix}/libexec
3677 localedir = ${datadir}/locale
3678diff -rc alpine-2.20/pico/osdep/Makefile alpine-2.20.maildir/pico/osdep/Makefile
3679*** alpine-2.20/pico/osdep/Makefile 2015-01-18 00:00:55.235702852 -0700
3680--- alpine-2.20.maildir/pico/osdep/Makefile 2015-01-20 20:38:26.454015609 -0700
3681***************
3682*** 193,207 ****
3683 ETAGS = etags
3684 CTAGS = ctags
3685 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
3686! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing aclocal-1.13
3687 AMTAR = $${TAR-tar}
3688 AM_CFLAGS = -g -pthread
3689 AM_DEFAULT_VERBOSITY = 1
3690 AM_LDFLAGS =
3691 AR = /usr/bin/ar
3692! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoconf
3693! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoheader
3694! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing automake-1.13
3695 AWK = gawk
3696 CC = gcc -std=gnu99
3697 CCDEPMODE = depmode=gcc3
3698--- 193,207 ----
3699 ETAGS = etags
3700 CTAGS = ctags
3701 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
3702! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing aclocal-1.13
3703 AMTAR = $${TAR-tar}
3704 AM_CFLAGS = -g -pthread
3705 AM_DEFAULT_VERBOSITY = 1
3706 AM_LDFLAGS =
3707 AR = /usr/bin/ar
3708! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoconf
3709! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoheader
3710! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing automake-1.13
3711 AWK = gawk
3712 CC = gcc -std=gnu99
3713 CCDEPMODE = depmode=gcc3
3714***************
3715*** 212,218 ****
3716 CYGPATH_W = echo
3717 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
3718 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
3719! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5"
3720 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
3721 C_CLIENT_TARGET = lsu
3722 C_CLIENT_WITH_IPV6 = touch imap/ip6
3723--- 212,218 ----
3724 CYGPATH_W = echo
3725 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
3726 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
3727! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5"
3728 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
3729 C_CLIENT_TARGET = lsu
3730 C_CLIENT_WITH_IPV6 = touch imap/ip6
3731***************
3732*** 243,249 ****
3733 LIBICONV = -liconv
3734 LIBINTL =
3735 LIBOBJS =
3736! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5
3737 LIBTOOL = $(SHELL) $(top_builddir)/libtool
3738 LIBTOOL_DEPS = ./ltmain.sh
3739 LIPO =
3740--- 243,249 ----
3741 LIBICONV = -liconv
3742 LIBINTL =
3743 LIBOBJS =
3744! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5
3745 LIBTOOL = $(SHELL) $(top_builddir)/libtool
3746 LIBTOOL_DEPS = ./ltmain.sh
3747 LIPO =
3748***************
3749*** 255,261 ****
3750 LTLIBOBJS =
3751 MAINT = #
3752 MAKE = /usr/bin/make
3753! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing makeinfo
3754 MANIFEST_TOOL = :
3755 MKDIR_P = /usr/bin/mkdir -p
3756 MSGFMT = /usr/bin/msgfmt
3757--- 255,261 ----
3758 LTLIBOBJS =
3759 MAINT = #
3760 MAKE = /usr/bin/make
3761! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing makeinfo
3762 MANIFEST_TOOL = :
3763 MKDIR_P = /usr/bin/mkdir -p
3764 MSGFMT = /usr/bin/msgfmt
3765***************
3766*** 299,308 ****
3767 WEB_PUBCOOKIE_LINK =
3768 XGETTEXT = /usr/bin/xgettext
3769 XGETTEXT_015 = /usr/bin/xgettext
3770! abs_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/pico/osdep
3771! abs_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/pico/osdep
3772! abs_top_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
3773! abs_top_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
3774 ac_ct_AR = ar
3775 ac_ct_CC = gcc
3776 ac_ct_DUMPBIN =
3777--- 299,308 ----
3778 WEB_PUBCOOKIE_LINK =
3779 XGETTEXT = /usr/bin/xgettext
3780 XGETTEXT_015 = /usr/bin/xgettext
3781! abs_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/pico/osdep
3782! abs_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/pico/osdep
3783! abs_top_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
3784! abs_top_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
3785 ac_ct_AR = ar
3786 ac_ct_CC = gcc
3787 ac_ct_DUMPBIN =
3788***************
3789*** 334,340 ****
3790 htmldir = ${docdir}
3791 includedir = ${prefix}/include
3792 infodir = ${datarootdir}/info
3793! install_sh = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/install-sh
3794 libdir = ${exec_prefix}/lib
3795 libexecdir = ${exec_prefix}/libexec
3796 localedir = ${datadir}/locale
3797--- 334,340 ----
3798 htmldir = ${docdir}
3799 includedir = ${prefix}/include
3800 infodir = ${datarootdir}/info
3801! install_sh = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/install-sh
3802 libdir = ${exec_prefix}/lib
3803 libexecdir = ${exec_prefix}/libexec
3804 localedir = ${datadir}/locale
3805diff -rc alpine-2.20/pith/charconv/Makefile alpine-2.20.maildir/pith/charconv/Makefile
3806*** alpine-2.20/pith/charconv/Makefile 2015-01-18 00:00:55.204702716 -0700
3807--- alpine-2.20.maildir/pith/charconv/Makefile 2015-01-20 20:38:26.367015589 -0700
3808***************
3809*** 188,202 ****
3810 ETAGS = etags
3811 CTAGS = ctags
3812 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
3813! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing aclocal-1.13
3814 AMTAR = $${TAR-tar}
3815 AM_CFLAGS = -g -pthread
3816 AM_DEFAULT_VERBOSITY = 1
3817 AM_LDFLAGS =
3818 AR = /usr/bin/ar
3819! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoconf
3820! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoheader
3821! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing automake-1.13
3822 AWK = gawk
3823 CC = gcc -std=gnu99
3824 CCDEPMODE = depmode=gcc3
3825--- 188,202 ----
3826 ETAGS = etags
3827 CTAGS = ctags
3828 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
3829! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing aclocal-1.13
3830 AMTAR = $${TAR-tar}
3831 AM_CFLAGS = -g -pthread
3832 AM_DEFAULT_VERBOSITY = 1
3833 AM_LDFLAGS =
3834 AR = /usr/bin/ar
3835! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoconf
3836! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoheader
3837! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing automake-1.13
3838 AWK = gawk
3839 CC = gcc -std=gnu99
3840 CCDEPMODE = depmode=gcc3
3841***************
3842*** 207,213 ****
3843 CYGPATH_W = echo
3844 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
3845 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
3846! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5"
3847 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
3848 C_CLIENT_TARGET = lsu
3849 C_CLIENT_WITH_IPV6 = touch imap/ip6
3850--- 207,213 ----
3851 CYGPATH_W = echo
3852 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
3853 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
3854! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5"
3855 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
3856 C_CLIENT_TARGET = lsu
3857 C_CLIENT_WITH_IPV6 = touch imap/ip6
3858***************
3859*** 238,244 ****
3860 LIBICONV = -liconv
3861 LIBINTL =
3862 LIBOBJS =
3863! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5
3864 LIBTOOL = $(SHELL) $(top_builddir)/libtool
3865 LIBTOOL_DEPS = ./ltmain.sh
3866 LIPO =
3867--- 238,244 ----
3868 LIBICONV = -liconv
3869 LIBINTL =
3870 LIBOBJS =
3871! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5
3872 LIBTOOL = $(SHELL) $(top_builddir)/libtool
3873 LIBTOOL_DEPS = ./ltmain.sh
3874 LIPO =
3875***************
3876*** 250,256 ****
3877 LTLIBOBJS =
3878 MAINT = #
3879 MAKE = /usr/bin/make
3880! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing makeinfo
3881 MANIFEST_TOOL = :
3882 MKDIR_P = /usr/bin/mkdir -p
3883 MSGFMT = /usr/bin/msgfmt
3884--- 250,256 ----
3885 LTLIBOBJS =
3886 MAINT = #
3887 MAKE = /usr/bin/make
3888! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing makeinfo
3889 MANIFEST_TOOL = :
3890 MKDIR_P = /usr/bin/mkdir -p
3891 MSGFMT = /usr/bin/msgfmt
3892***************
3893*** 294,303 ****
3894 WEB_PUBCOOKIE_LINK =
3895 XGETTEXT = /usr/bin/xgettext
3896 XGETTEXT_015 = /usr/bin/xgettext
3897! abs_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/pith/charconv
3898! abs_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/pith/charconv
3899! abs_top_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
3900! abs_top_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
3901 ac_ct_AR = ar
3902 ac_ct_CC = gcc
3903 ac_ct_DUMPBIN =
3904--- 294,303 ----
3905 WEB_PUBCOOKIE_LINK =
3906 XGETTEXT = /usr/bin/xgettext
3907 XGETTEXT_015 = /usr/bin/xgettext
3908! abs_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/pith/charconv
3909! abs_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/pith/charconv
3910! abs_top_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
3911! abs_top_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
3912 ac_ct_AR = ar
3913 ac_ct_CC = gcc
3914 ac_ct_DUMPBIN =
3915***************
3916*** 329,335 ****
3917 htmldir = ${docdir}
3918 includedir = ${prefix}/include
3919 infodir = ${datarootdir}/info
3920! install_sh = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/install-sh
3921 libdir = ${exec_prefix}/lib
3922 libexecdir = ${exec_prefix}/libexec
3923 localedir = ${datadir}/locale
3924--- 329,335 ----
3925 htmldir = ${docdir}
3926 includedir = ${prefix}/include
3927 infodir = ${datarootdir}/info
3928! install_sh = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/install-sh
3929 libdir = ${exec_prefix}/lib
3930 libexecdir = ${exec_prefix}/libexec
3931 localedir = ${datadir}/locale
3932diff -rc alpine-2.20/pith/conf.c alpine-2.20.maildir/pith/conf.c
3933*** alpine-2.20/pith/conf.c 2015-01-11 22:12:25.578178790 -0700
3934--- alpine-2.20.maildir/pith/conf.c 2015-01-20 20:37:55.862011679 -0700
3935***************
3936*** 432,437 ****
3937--- 432,440 ----
3938
3939 CONF_TXT_T cf_text_newsrc_path[] = "Full path and name of NEWSRC file";
3940
3941+ #ifndef _WINDOWS
3942+ CONF_TXT_T cf_text_maildir_location[] = "Location relative to your HOME directory of the directory where your INBOX\n# for the maildir format is located. Default value is \"Maildir\". If your\n# inbox is located at \"~/Maildir\" you do not need to change this value.\n# A common value is also \".maildir\"";
3943+ #endif
3944
3945 /*----------------------------------------------------------------------
3946 These are the variables that control a number of pine functions. They
3947***************
3948*** 634,639 ****
3949--- 637,646 ----
3950 NULL, cf_text_news_active},
3951 {"news-spool-directory", 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0,
3952 NULL, cf_text_news_spooldir},
3953+ #ifndef _WINDOWS
3954+ {"maildir-location", 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0,
3955+ "Maildir Location", cf_text_maildir_location},
3956+ #endif
3957 {"upload-command", 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0,
3958 NULL, cf_text_upload_cmd},
3959 {"upload-command-prefix", 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0,
3960***************
3961*** 2270,2275 ****
3962--- 2277,2288 ----
3963 mail_parameters(NULL, SET_NEWSSPOOL,
3964 (void *)VAR_NEWS_SPOOL_DIR);
3965
3966+ #ifndef _WINDOWS
3967+ set_current_val(&vars[V_MAILDIR_LOCATION], TRUE, TRUE);
3968+ if(VAR_MAILDIR_LOCATION && VAR_MAILDIR_LOCATION[0])
3969+ mail_parameters(NULL, SET_MDINBOXPATH, (void *)VAR_MAILDIR_LOCATION);
3970+ #endif
3971+
3972 /* guarantee a save default */
3973 set_current_val(&vars[V_DEFAULT_SAVE_FOLDER], TRUE, TRUE);
3974 if(!VAR_DEFAULT_SAVE_FOLDER || !VAR_DEFAULT_SAVE_FOLDER[0])
3975***************
3976*** 2897,2902 ****
3977--- 2910,2919 ----
3978 F_SORT_DEFAULT_SAVE_ALPHA, h_config_sort_save_alpha, PREF_FLDR, 0},
3979 {"vertical-folder-list", "Use Vertical Folder List",
3980 F_VERTICAL_FOLDER_LIST, h_config_vertical_list, PREF_FLDR, 0},
3981+ #ifndef _WINDOWS
3982+ {"use-courier-folder-list", "Courier Style Folder List",
3983+ F_COURIER_FOLDER_LIST, h_config_courier_list, PREF_FLDR, 0},
3984+ #endif
3985
3986 /* Addr book */
3987 {"combined-addrbook-display", "Combined Address Book Display",
3988***************
3989*** 7018,7024 ****
3990 int just_flip_value, EditWhich ew)
3991 {
3992 char **vp, *p, **lval, ***alval;
3993! int og, on_before, was_set;
3994 char *err;
3995 long l;
3996
3997--- 7035,7041 ----
3998 int just_flip_value, EditWhich ew)
3999 {
4000 char **vp, *p, **lval, ***alval;
4001! int og, on_before, was_set, i;
4002 char *err;
4003 long l;
4004
4005***************
4006*** 7071,7076 ****
4007--- 7088,7100 ----
4008
4009 break;
4010
4011+ #ifndef _WINDOWS
4012+ case F_COURIER_FOLDER_LIST:
4013+ i = F_ON(f->id ,ps) ? 1 : 0;
4014+ mail_parameters(NULL,SET_COURIERSTYLE, (void *) &i);
4015+ break; /* COURIER == 1, CCLIENT == 0, see maildir.h */
4016+ #endif
4017+
4018 case F_COLOR_LINE_IMPORTANT :
4019 case F_DATES_TO_LOCAL :
4020 clear_index_cache(ps->mail_stream, 0);
4021***************
4022*** 7854,7859 ****
4023--- 7878,7887 ----
4024 return(h_config_newmailwidth);
4025 case V_NEWSRC_PATH :
4026 return(h_config_newsrc_path);
4027+ #ifndef _WINDOWS
4028+ case V_MAILDIR_LOCATION :
4029+ return(h_config_maildir_location);
4030+ #endif
4031 case V_BROWSER :
4032 return(h_config_browser);
4033 #if defined(DOS) || defined(OS2)
4034diff -rc alpine-2.20/pith/conf.h alpine-2.20.maildir/pith/conf.h
4035*** alpine-2.20/pith/conf.h 2015-01-11 22:12:25.578178790 -0700
4036--- alpine-2.20.maildir/pith/conf.h 2015-01-20 20:37:55.873011679 -0700
4037***************
4038*** 252,257 ****
4039--- 252,261 ----
4040 #define GLO_NEWS_ACTIVE_PATH vars[V_NEWS_ACTIVE_PATH].global_val.p
4041 #define VAR_NEWS_SPOOL_DIR vars[V_NEWS_SPOOL_DIR].current_val.p
4042 #define GLO_NEWS_SPOOL_DIR vars[V_NEWS_SPOOL_DIR].global_val.p
4043+ #ifndef _WINDOWS
4044+ #define VAR_MAILDIR_LOCATION vars[V_MAILDIR_LOCATION].current_val.p
4045+ #define GLO_MAILDIR_LOCATION vars[V_MAILDIR_LOCATION].global_val.p
4046+ #endif
4047 #define VAR_DISABLE_DRIVERS vars[V_DISABLE_DRIVERS].current_val.l
4048 #define VAR_DISABLE_AUTHS vars[V_DISABLE_AUTHS].current_val.l
4049 #define VAR_REMOTE_ABOOK_METADATA vars[V_REMOTE_ABOOK_METADATA].current_val.p
4050diff -rc alpine-2.20/pith/conftype.h alpine-2.20.maildir/pith/conftype.h
4051*** alpine-2.20/pith/conftype.h 2015-01-11 22:12:25.579178794 -0700
4052--- alpine-2.20.maildir/pith/conftype.h 2015-01-20 20:37:55.879011679 -0700
4053***************
4054*** 116,121 ****
4055--- 116,124 ----
4056 , V_NEWSRC_PATH
4057 , V_NEWS_ACTIVE_PATH
4058 , V_NEWS_SPOOL_DIR
4059+ #ifndef _WINDOWS
4060+ , V_MAILDIR_LOCATION
4061+ #endif
4062 , V_UPLOAD_CMD
4063 , V_UPLOAD_CMD_PREFIX
4064 , V_DOWNLOAD_CMD
4065***************
4066*** 390,395 ****
4067--- 393,401 ----
4068 F_PASS_C1_CONTROL_CHARS,
4069 F_SINGLE_FOLDER_LIST,
4070 F_VERTICAL_FOLDER_LIST,
4071+ #ifndef _WINDOWS
4072+ F_COURIER_FOLDER_LIST,
4073+ #endif
4074 F_TAB_CHK_RECENT,
4075 F_AUTO_REPLY_TO,
4076 F_VERBOSE_POST,
4077diff -rc alpine-2.20/pith/init.c alpine-2.20.maildir/pith/init.c
4078*** alpine-2.20/pith/init.c 2015-01-11 22:12:25.583178813 -0700
4079--- alpine-2.20.maildir/pith/init.c 2015-01-20 20:37:55.880011679 -0700
4080***************
4081*** 408,413 ****
4082--- 408,416 ----
4083 && stricmp(filename, folder_base)){
4084 #else
4085 if(strncmp(filename, folder_base, folder_base_len) == 0
4086+ #ifndef _WINDOWS
4087+ && filename[folder_base_len] != list_cntxt->dir->delim
4088+ #endif
4089 && strcmp(filename, folder_base)){
4090 #endif
4091 #endif
4092diff -rc alpine-2.20/pith/Makefile alpine-2.20.maildir/pith/Makefile
4093*** alpine-2.20/pith/Makefile 2015-01-18 00:00:55.223702799 -0700
4094--- alpine-2.20.maildir/pith/Makefile 2015-01-20 20:38:26.399015596 -0700
4095***************
4096*** 260,274 ****
4097 dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
4098 done; \
4099 reldir="$$dir2"
4100! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing aclocal-1.13
4101 AMTAR = $${TAR-tar}
4102 AM_CFLAGS = -g -pthread
4103 AM_DEFAULT_VERBOSITY = 1
4104 AM_LDFLAGS =
4105 AR = /usr/bin/ar
4106! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoconf
4107! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoheader
4108! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing automake-1.13
4109 AWK = gawk
4110 CC = gcc -std=gnu99
4111 CCDEPMODE = depmode=gcc3
4112--- 260,274 ----
4113 dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
4114 done; \
4115 reldir="$$dir2"
4116! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing aclocal-1.13
4117 AMTAR = $${TAR-tar}
4118 AM_CFLAGS = -g -pthread
4119 AM_DEFAULT_VERBOSITY = 1
4120 AM_LDFLAGS =
4121 AR = /usr/bin/ar
4122! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoconf
4123! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoheader
4124! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing automake-1.13
4125 AWK = gawk
4126 CC = gcc -std=gnu99
4127 CCDEPMODE = depmode=gcc3
4128***************
4129*** 279,285 ****
4130 CYGPATH_W = echo
4131 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
4132 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
4133! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5"
4134 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
4135 C_CLIENT_TARGET = lsu
4136 C_CLIENT_WITH_IPV6 = touch imap/ip6
4137--- 279,285 ----
4138 CYGPATH_W = echo
4139 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
4140 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
4141! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5"
4142 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
4143 C_CLIENT_TARGET = lsu
4144 C_CLIENT_WITH_IPV6 = touch imap/ip6
4145***************
4146*** 310,316 ****
4147 LIBICONV = -liconv
4148 LIBINTL =
4149 LIBOBJS =
4150! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5
4151 LIBTOOL = $(SHELL) $(top_builddir)/libtool
4152 LIBTOOL_DEPS = ./ltmain.sh
4153 LIPO =
4154--- 310,316 ----
4155 LIBICONV = -liconv
4156 LIBINTL =
4157 LIBOBJS =
4158! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5
4159 LIBTOOL = $(SHELL) $(top_builddir)/libtool
4160 LIBTOOL_DEPS = ./ltmain.sh
4161 LIPO =
4162***************
4163*** 322,328 ****
4164 LTLIBOBJS =
4165 MAINT = #
4166 MAKE = /usr/bin/make
4167! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing makeinfo
4168 MANIFEST_TOOL = :
4169 MKDIR_P = /usr/bin/mkdir -p
4170 MSGFMT = /usr/bin/msgfmt
4171--- 322,328 ----
4172 LTLIBOBJS =
4173 MAINT = #
4174 MAKE = /usr/bin/make
4175! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing makeinfo
4176 MANIFEST_TOOL = :
4177 MKDIR_P = /usr/bin/mkdir -p
4178 MSGFMT = /usr/bin/msgfmt
4179***************
4180*** 366,375 ****
4181 WEB_PUBCOOKIE_LINK =
4182 XGETTEXT = /usr/bin/xgettext
4183 XGETTEXT_015 = /usr/bin/xgettext
4184! abs_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/pith
4185! abs_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/pith
4186! abs_top_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
4187! abs_top_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
4188 ac_ct_AR = ar
4189 ac_ct_CC = gcc
4190 ac_ct_DUMPBIN =
4191--- 366,375 ----
4192 WEB_PUBCOOKIE_LINK =
4193 XGETTEXT = /usr/bin/xgettext
4194 XGETTEXT_015 = /usr/bin/xgettext
4195! abs_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/pith
4196! abs_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/pith
4197! abs_top_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
4198! abs_top_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
4199 ac_ct_AR = ar
4200 ac_ct_CC = gcc
4201 ac_ct_DUMPBIN =
4202***************
4203*** 401,407 ****
4204 htmldir = ${docdir}
4205 includedir = ${prefix}/include
4206 infodir = ${datarootdir}/info
4207! install_sh = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/install-sh
4208 libdir = ${exec_prefix}/lib
4209 libexecdir = ${exec_prefix}/libexec
4210 localedir = ${datadir}/locale
4211--- 401,407 ----
4212 htmldir = ${docdir}
4213 includedir = ${prefix}/include
4214 infodir = ${datarootdir}/info
4215! install_sh = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/install-sh
4216 libdir = ${exec_prefix}/lib
4217 libexecdir = ${exec_prefix}/libexec
4218 localedir = ${datadir}/locale
4219diff -rc alpine-2.20/pith/osdep/Makefile alpine-2.20.maildir/pith/osdep/Makefile
4220*** alpine-2.20/pith/osdep/Makefile 2015-01-18 00:00:55.190702654 -0700
4221--- alpine-2.20.maildir/pith/osdep/Makefile 2015-01-20 20:38:26.350015585 -0700
4222***************
4223*** 195,209 ****
4224 ETAGS = etags
4225 CTAGS = ctags
4226 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
4227! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing aclocal-1.13
4228 AMTAR = $${TAR-tar}
4229 AM_CFLAGS = -g -pthread
4230 AM_DEFAULT_VERBOSITY = 1
4231 AM_LDFLAGS =
4232 AR = /usr/bin/ar
4233! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoconf
4234! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoheader
4235! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing automake-1.13
4236 AWK = gawk
4237 CC = gcc -std=gnu99
4238 CCDEPMODE = depmode=gcc3
4239--- 195,209 ----
4240 ETAGS = etags
4241 CTAGS = ctags
4242 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
4243! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing aclocal-1.13
4244 AMTAR = $${TAR-tar}
4245 AM_CFLAGS = -g -pthread
4246 AM_DEFAULT_VERBOSITY = 1
4247 AM_LDFLAGS =
4248 AR = /usr/bin/ar
4249! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoconf
4250! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoheader
4251! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing automake-1.13
4252 AWK = gawk
4253 CC = gcc -std=gnu99
4254 CCDEPMODE = depmode=gcc3
4255***************
4256*** 214,220 ****
4257 CYGPATH_W = echo
4258 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
4259 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
4260! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5"
4261 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
4262 C_CLIENT_TARGET = lsu
4263 C_CLIENT_WITH_IPV6 = touch imap/ip6
4264--- 214,220 ----
4265 CYGPATH_W = echo
4266 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
4267 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
4268! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5"
4269 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
4270 C_CLIENT_TARGET = lsu
4271 C_CLIENT_WITH_IPV6 = touch imap/ip6
4272***************
4273*** 245,251 ****
4274 LIBICONV = -liconv
4275 LIBINTL =
4276 LIBOBJS =
4277! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5
4278 LIBTOOL = $(SHELL) $(top_builddir)/libtool
4279 LIBTOOL_DEPS = ./ltmain.sh
4280 LIPO =
4281--- 245,251 ----
4282 LIBICONV = -liconv
4283 LIBINTL =
4284 LIBOBJS =
4285! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5
4286 LIBTOOL = $(SHELL) $(top_builddir)/libtool
4287 LIBTOOL_DEPS = ./ltmain.sh
4288 LIPO =
4289***************
4290*** 257,263 ****
4291 LTLIBOBJS =
4292 MAINT = #
4293 MAKE = /usr/bin/make
4294! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing makeinfo
4295 MANIFEST_TOOL = :
4296 MKDIR_P = /usr/bin/mkdir -p
4297 MSGFMT = /usr/bin/msgfmt
4298--- 257,263 ----
4299 LTLIBOBJS =
4300 MAINT = #
4301 MAKE = /usr/bin/make
4302! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing makeinfo
4303 MANIFEST_TOOL = :
4304 MKDIR_P = /usr/bin/mkdir -p
4305 MSGFMT = /usr/bin/msgfmt
4306***************
4307*** 301,310 ****
4308 WEB_PUBCOOKIE_LINK =
4309 XGETTEXT = /usr/bin/xgettext
4310 XGETTEXT_015 = /usr/bin/xgettext
4311! abs_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/pith/osdep
4312! abs_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/pith/osdep
4313! abs_top_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
4314! abs_top_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
4315 ac_ct_AR = ar
4316 ac_ct_CC = gcc
4317 ac_ct_DUMPBIN =
4318--- 301,310 ----
4319 WEB_PUBCOOKIE_LINK =
4320 XGETTEXT = /usr/bin/xgettext
4321 XGETTEXT_015 = /usr/bin/xgettext
4322! abs_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/pith/osdep
4323! abs_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/pith/osdep
4324! abs_top_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
4325! abs_top_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
4326 ac_ct_AR = ar
4327 ac_ct_CC = gcc
4328 ac_ct_DUMPBIN =
4329***************
4330*** 336,342 ****
4331 htmldir = ${docdir}
4332 includedir = ${prefix}/include
4333 infodir = ${datarootdir}/info
4334! install_sh = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/install-sh
4335 libdir = ${exec_prefix}/lib
4336 libexecdir = ${exec_prefix}/libexec
4337 localedir = ${datadir}/locale
4338--- 336,342 ----
4339 htmldir = ${docdir}
4340 includedir = ${prefix}/include
4341 infodir = ${datarootdir}/info
4342! install_sh = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/install-sh
4343 libdir = ${exec_prefix}/lib
4344 libexecdir = ${exec_prefix}/libexec
4345 localedir = ${datadir}/locale
4346diff -rc alpine-2.20/pith/pattern.c alpine-2.20.maildir/pith/pattern.c
4347*** alpine-2.20/pith/pattern.c 2015-01-11 22:12:25.579178794 -0700
4348--- alpine-2.20.maildir/pith/pattern.c 2015-01-20 20:37:55.897011679 -0700
4349***************
4350*** 49,55 ****
4351 #include "../pith/icache.h"
4352 #include "../pith/ablookup.h"
4353 #include "../pith/keyword.h"
4354!
4355
4356 /*
4357 * Internal prototypes
4358--- 49,57 ----
4359 #include "../pith/icache.h"
4360 #include "../pith/ablookup.h"
4361 #include "../pith/keyword.h"
4362! #ifndef _WINDOWS
4363! int maildir_file_path(char *name, char *tmp, size_t sizeoftmp);
4364! #endif /* _WINDOWS */
4365
4366 /*
4367 * Internal prototypes
4368***************
4369*** 5485,5490 ****
4370--- 5487,5501 ----
4371 break;
4372
4373 case '#':
4374+ #ifndef _WINDOWS
4375+ if(!struncmp(patfolder, "#md/", 4)
4376+ || !struncmp(patfolder, "#mc/", 4)){
4377+ maildir_file_path(patfolder, tmp1, sizeof(tmp1));
4378+ if(!strcmp(tmp1, stream->mailbox))
4379+ match++;
4380+ break;
4381+ }
4382+ #endif
4383 if(!strcmp(patfolder, stream->mailbox))
4384 match++;
4385
4386***************
4387*** 7905,7911 ****
4388 int we_cancel = 0, width;
4389 CONTEXT_S *save_context = NULL;
4390 char buf[MAX_SCREEN_COLS+1], sbuf[MAX_SCREEN_COLS+1];
4391! char *save_ref = NULL;
4392 #define FILTMSG_MAX 30
4393
4394 if(!stream)
4395--- 7916,7922 ----
4396 int we_cancel = 0, width;
4397 CONTEXT_S *save_context = NULL;
4398 char buf[MAX_SCREEN_COLS+1], sbuf[MAX_SCREEN_COLS+1];
4399! char *save_ref = NULL, *save_dstfldr = NULL, *save_dstfldr2 = NULL;
4400 #define FILTMSG_MAX 30
4401
4402 if(!stream)
4403***************
4404*** 7939,7944 ****
4405--- 7950,7965 ----
4406 if(F_OFF(F_QUELL_FILTER_MSGS, ps_global))
4407 we_cancel = busy_cue(buf, NULL, 0);
4408
4409+ #ifndef _WINDOWS
4410+ if(!struncmp(dstfldr, "#md/", 4) || !struncmp(dstfldr, "#mc/", 4)){
4411+ char tmp1[MAILTMPLEN];
4412+ maildir_file_path(dstfldr, tmp1, sizeof(tmp1));
4413+ save_dstfldr2 = dstfldr;
4414+ save_dstfldr = cpystr(tmp1);
4415+ dstfldr = save_dstfldr;
4416+ }
4417+ #endif
4418+
4419 if(!is_absolute_path(dstfldr)
4420 && !(save_context = default_save_context(ps_global->context_list)))
4421 save_context = ps_global->context_list;
4422***************
4423*** 8002,8007 ****
4424--- 8023,8033 ----
4425 if(we_cancel)
4426 cancel_busy_cue(buf[0] ? 0 : -1);
4427
4428+ if(save_dstfldr){
4429+ fs_give((void **)&save_dstfldr);
4430+ dstfldr = save_dstfldr2;
4431+ }
4432+
4433 return(buf[0] != '\0');
4434 }
4435
4436diff -rc alpine-2.20/pith/pine.hlp alpine-2.20.maildir/pith/pine.hlp
4437*** alpine-2.20/pith/pine.hlp 2015-01-11 22:12:25.584178818 -0700
4438--- alpine-2.20.maildir/pith/pine.hlp 2015-01-20 20:37:55.946011680 -0700
4439***************
4440*** 21891,21896 ****
4441--- 21891,21992 ----
4442 &lt;End of help on this topic&gt;
4443 </BODY>
4444 </HTML>
4445+ ====== h_config_maildir_location ======
4446+ <HTML>
4447+ <HEAD>
4448+ <TITLE>OPTION: <!--#echo var="VAR_maildir-location"--></TITLE>
4449+ </HEAD>
4450+ <BODY>
4451+ <H1>OPTION: <!--#echo var="VAR_maildir-location"--></H1>
4452+
4453+ <P>
4454+ This option should be used only if you have a Maildir folder which you
4455+ want to use as your INBOX. If this is not your case (or don't know what
4456+ this is), you can safely ignore this option.
4457+
4458+ <P>
4459+ This option overrides the default directory Pine uses to find the location of
4460+ your INBOX, in case this is in Maildir format. The default value of this
4461+ option is "Maildir", but in some systems, this directory could have been
4462+ renamed (e.g. to ".maildir"). If this is your case use this option to change
4463+ the default.
4464+
4465+ <P>
4466+ The value of this option is prefixed with the "~/" string to determine the
4467+ full path to your INBOX.
4468+
4469+ <P>
4470+ You should probably <A HREF="h_config_maildir">read</A> a few tips that
4471+ teach you how to configure your maildir for optimal performance. This
4472+ version also has <A HREF="h_config_courier_list">support</A> for the
4473+ Courier style file system when a maildir collection is accessed locally.
4474+
4475+ <P><UL>
4476+ <LI><A HREF="h_finding_help">Finding more information and requesting help</A>
4477+ </UL>
4478+ <P>
4479+ &lt;End of help on this topic&gt;
4480+ </BODY>
4481+ </HTML>
4482+ ====== h_config_maildir =====
4483+ <HTML>
4484+ <HEAD>
4485+ <TITLE>Maildir Support</TITLE>
4486+ </HEAD>
4487+ <BODY>
4488+ <H1>Maildir Support</H1>
4489+
4490+ This version of Alpine has been enhanced with Maildir support. This text is
4491+ intended to be a reference on its support.
4492+ <P>
4493+
4494+ A Maildir folder is a directory that contains three directories called
4495+ cur, tmp and new. A program that delivers mail (e.g. postfix) will put new
4496+ mail in the new directory. A program that reads mail will look for for old
4497+ messages in the cur directory, while it will look for new mail in the new
4498+ directory.
4499+ <P>
4500+
4501+ In order to use maildir support it is better to set your inbox-path to the
4502+ value &quot;#md/inbox&quot; (without quotes). This assumes that your mail
4503+ delivery agent is delivering new mail to ~/Maildir/new. If the directory
4504+ where new mail is being delivered is not called "Maildir", you can set the
4505+ name of the subdirectory of home where it is being delivered in the <A
4506+ HREF="h_config_maildir_location"><!--#echo var="VAR_maildir-location"--></A> configuration
4507+ variable. Most of the time you will not have to worry about the
4508+ <!--#echo var="VAR_maildirlocation"--> variable, because it will probably be set by your
4509+ administrator in the pine.conf configuration file.
4510+ <P>
4511+
4512+ One of the advantages of the Maildir support of this version of Alpine is
4513+ that you do not have to stop using folders in another styles (mbox, mbx,
4514+ etc.). This is desirable since the usage of a specific mail storage system
4515+ is a personal decision. Folders in the maildir format that are part of the
4516+ Mail collection will be recognized without any extra configuration of your
4517+ part. If your mail/ collection is located under the mail/ directory, then
4518+ creating a new maildir folder in this collection is done by pressing "A"
4519+ and entering the string "#driver.md/mail/newfolder". Observe that adding a
4520+ new folder as "newfolder" may not create such folder in maildir format.
4521+
4522+ <P>
4523+ If you would like to have all folders created in the maildir format by
4524+ default, you do so by adding a Maildir Collection. In order to convert
4525+ your current mail/ collection into a maildir collection, edit the
4526+ collection and change the path variable from &quot;mail/&quot; to
4527+ &quot;#md/mail&quot;. In a maildir collection folders of any other format
4528+ are ignored.
4529+
4530+ <P> Finally, This version also has
4531+ <A HREF="h_config_courier_list">support</A> for the Courier style file system
4532+ when a maildir collection is accessed locally.
4533+
4534+ <P>
4535+ <UL>
4536+ <LI><A HREF="h_finding_help">Finding more information and requesting help</A>
4537+ </UL><P>
4538+ &lt;End of help on this topic&gt;
4539+ </BODY>
4540+ </HTML>
4541 ====== h_config_literal_sig =====
4542 <HTML>
4543 <HEAD>
4544***************
4545*** 29841,29846 ****
4546--- 29937,29985 ----
4547 <P>
4548 &lt;End of help on this topic&gt;
4549 </BODY>
4550+ </HTML>
4551+ ====== h_config_courier_list =====
4552+ <HTML>
4553+ <HEAD>
4554+ <TITLE>FEATURE: <!--#echo var="FEAT_courier-folder-list"--></TITLE>
4555+ </HEAD>
4556+ <BODY>
4557+ <H1>FEATURE: <!--#echo var="FEAT_courier-folder-list"--></H1>
4558+
4559+ In a maildir collection, a folder could be used as a directory to store
4560+ folders. In the Courier server if you create a folder, then a directory
4561+ with the same name is created. If you use this patch to access a
4562+ collection created by the Courier server, then the display of such
4563+ collection will look confusing. The best way to access a maildir
4564+ collection created by the Courier server is by using the &quot;#mc/&quot;
4565+ prefix instead of the &quot;#md/&quot; prefix. If you use this alternate
4566+ prefix, then this feature applies to you, otherwise you can safely ignore
4567+ the text that follows.
4568+ <P>
4569+ Depending on if you have enabled the option
4570+ <a href="h_config_separate_fold_dir_view"><!--#echo var="FEAT_separate-folder-and-directory-entries"--></a>
4571+ a folder may be listed as &quot;folder[.]&quot;, or as two entries in the
4572+ list by &quot;folder&quot; and &quot;folder.&quot;.
4573+ <P>
4574+ If this option is disabled, Pine will list local folders that are in Courier
4575+ style format, as &quot;folder&quot;, and those that are also directories as
4576+ &quot;folder[.]&quot;. This makes the default display cleaner.
4577+ <P>
4578+ If this feature is enabled then creating folders in a maildir collection
4579+ will create a directory with the same name. If this feature is disabled, then
4580+ a folder is considered a directory only if it contains subfolders, so you can
4581+ not create a directory with the same name as an exisiting folder unless
4582+ you create a subfolder of that folder first (e.g. if you have a folder
4583+ called &quot;foo&quot; simply add &quot;foo.bar&quot; directly. This will
4584+ create the directory &quot;foo&quot; and the subfolder &quot;bar&quot; of it).
4585+ <P>
4586+ Observe that this feature works only for maildir collections that are accessed
4587+ locally. If a collection is accessed remotely then this feature has no value,
4588+ as the report is created in a server, and Pine only reports what received
4589+ from the server in this case.
4590+ <P>
4591+ &lt;End of help on this topic&gt;
4592+ </BODY>
4593 </HTML>
4594 ====== h_config_verbose_post =====
4595 <HTML>
4596diff -rc alpine-2.20/pith/send.c alpine-2.20.maildir/pith/send.c
4597*** alpine-2.20/pith/send.c 2015-01-11 22:12:25.577178785 -0700
4598--- alpine-2.20.maildir/pith/send.c 2015-01-20 20:37:55.963011681 -0700
4599***************
4600*** 47,52 ****
4601--- 47,55 ----
4602
4603 #include "../c-client/smtp.h"
4604 #include "../c-client/nntp.h"
4605+ #ifndef _WINDOWS
4606+ int maildir_file_path(char *name, char *tmp, size_t sizeoftmp);
4607+ #endif /* _WINDOWS */
4608
4609
4610 /* this is used in pine_send and pine_simple_send */
4611***************
4612*** 257,262 ****
4613--- 260,272 ----
4614
4615 if(exists & FEX_ISFILE){
4616 context_apply(tmp, p_cntxt, mbox, sizeof(tmp));
4617+ #ifndef _WINDOWS
4618+ if (!struncmp(tmp, "#md/",4) || !struncmp(tmp, "#mc/", 4)){
4619+ char tmp2[MAILTMPLEN];
4620+ maildir_file_path(tmp, tmp2, sizeof(tmp2));
4621+ strcpy(tmp, tmp2);
4622+ }
4623+ #endif
4624 if(!(IS_REMOTE(tmp) || is_absolute_path(tmp))){
4625 /*
4626 * The mbox is relative to the home directory.
4627diff -rc alpine-2.20/README.maildir alpine-2.20.maildir/README.maildir
4628*** alpine-2.20/README.maildir 2015-02-03 22:28:22.634016237 -0700
4629--- alpine-2.20.maildir/README.maildir 2015-01-20 20:37:55.963011681 -0700
4630***************
4631*** 0 ****
4632--- 1,149 ----
4633+ ---------------------------------------
4634+
4635+ Maildir Driver for Alpine 2.0
4636+ By Eduardo Chappa
4637+ <chappa@gmx.com>
4638+
4639+ ---------------------------------------
4640+ 1. General Information About This Patch
4641+ ---------------------------------------
4642+
4643+ This patch adds support for the maildir format to Alpine. We take the
4644+ approach that this patch is one more driver among the number of formats
4645+ supported by Alpine (more generally c-client). This approach differs from
4646+ older versions of similar patches, in that once a maildir patch was
4647+ applied, it was assumed that all your folders would be created in the
4648+ maildir format.
4649+
4650+ This patch does not assume that maildir is a preferred format, instead
4651+ puts maildir in equal footing with other formats (mbox, mbx, mix, etc),
4652+ and so a maildir folder in the mail/ collection is treated in the same way
4653+ as any other folder in any other format. In other words, just by reading
4654+ the name of a folder, or opening it, or doing any operation with it, you
4655+ can not know in which format the folder is.
4656+
4657+ This implies that if you want to add a folder in the maildir format to the
4658+ mail/ collection, then you must add by pressing "A" in the folder list
4659+ collection and enter "#driver.md/mail/name_maildir_folder".
4660+
4661+ If you only want to use maildir, however, you can do so too. In this case,
4662+ you must create a maildir collection. In that collection, only maildir
4663+ folders will be listed. If there is any folder in any other format, that
4664+ folder will be ignored. In another words, any folder listed there is in
4665+ maildir format and can be accessed through that collection, conversely,
4666+ any folder not listed there is not in maildir format and there is no way
4667+ to access it using this collection.
4668+
4669+ In order to create a maildir collection, you could press M S L, and "A" to
4670+ add a collection. Fill in the required fields as follows:
4671+
4672+ Nickname : Anything
4673+ Server :
4674+ Path : #md/relative/path/to/maildir/collection/
4675+ View :
4676+
4677+ For example, if "path" is set to "#md/mail/", then Alpine will look for your
4678+ maildir folders that are in ~/mail/.
4679+
4680+ The code in this patch is mostly based in code for the unix driver plus
4681+ some combinations of the mh, mbx and nntp drivers for the c-client
4682+ library. Those drivers were designed by Mark Crispin, and bugs in this
4683+ code are not his bugs, but my own.
4684+
4685+ I got all the specification for this patch from
4686+ http://cr.yp.to/proto/maildir.html. If you know of a place with a better
4687+ specification for maildir format please let me know. The method this patch
4688+ uses to create a unique filename for a message is one of the "old
4689+ fashioned" methods. I realize that this is old fashioned, but it is
4690+ portable, and portability is the main reason why I decided to use an old
4691+ fashioned method (most methods are not portable. See the word
4692+ "Unfortunately" in that document).
4693+
4694+ --------------
4695+ 2. Other Goals
4696+ --------------
4697+
4698+ It is intended that this code will work well with any application
4699+ written using the c-client library. Of paramount importance is to make the
4700+ associated imap server work well when the server accesses a folder in
4701+ Maildir format. The program mailutil should also work flawlessly with this
4702+ implemetation of the driver.
4703+
4704+ It is intended that this driver be fast and stable. We intend not to
4705+ patch Alpine to make this driver do its work, unless such patching is for
4706+ fixing bugs in Alpine or to pass parameters to the driver.
4707+
4708+ ------------------------------------------------------------------------
4709+ 3. What are the known bugs of this implementation of the Maildir driver?
4710+ ------------------------------------------------------------------------
4711+
4712+ I don't know any at this time. There have been bugs before, though, but
4713+ I try to fix bugs as soon as they are reported.
4714+
4715+ ----------
4716+ 4. On UIDs
4717+ ----------
4718+
4719+ This patch keeps uids in the name of the file that contains the message,
4720+ by adding a ",u=" string to the file name to save the uid of a message. A
4721+ file is kept between sessions to save information on the last uid assigned
4722+ and its time of validity. Only one session with writing access can write
4723+ uids, all others must wait for the other session to assign them. The
4724+ session assigning uids creates a ".uidtemp" file which other sessions must
4725+ not disturb.
4726+
4727+ Uid support appeared in Alpine 1.00 (snapshot 925), and is experimental,
4728+ please report any problems.
4729+
4730+ ----------------------------------------------
4731+ 5. Configuring Alpine and Setting up a Maildir
4732+ ----------------------------------------------
4733+
4734+ Once this approach was chosen, it implied the following:
4735+
4736+ * This patch assumes that your INBOX is located at "$HOME/Maildir".
4737+ This is a directory which should have three subdirectories "cur",
4738+ "tmp" and "new". Mail is delivered to 'new' and read from 'cur'. I
4739+ have added a configuration option "maildir-location" which can be
4740+ used to tell Alpine where your Maildir inbox is, in case your system
4741+ does not use the above directory (e.g. your system may use
4742+ "~/.maildir"). In this case define that variable to be the name of
4743+ the directory where your e-mail is being delivered (e.g.
4744+ ".maildir").
4745+
4746+ * If you want to use the above configuration as your inbox, you must
4747+ define your inbox-path as "#md/inbox" (no quotes). You can define
4748+ the inbox-path like above even if you have changed the
4749+ maildir-location variable. That's the whole point of that variable.
4750+
4751+ -------------------------------------------
4752+ 6. What about Courier/Dovecot file systems?
4753+ -------------------------------------------
4754+
4755+ In a courier file system all folders are subfolders of a root folder
4756+ called INBOX. Normally INBOX is located at ~/Maildir and subfolders are
4757+ "dot" directories in ~/Maildir. For example ~/Maildir/.Trash is a
4758+ subfolder of INBOX and is accessed with the nickname "INBOX.Trash".
4759+
4760+ You can not access folders in this way unless you preceed them with the
4761+ string "#mc/". The purpose of the string "#mc/" is to warn Alpine that a
4762+ collection in the Courier format is going to be accessed. Therefore, you
4763+ can SELECT a folder like "#mc/INBOX.Trash", but not "INBOX.Trash"
4764+
4765+ You can access a collection through a server, but if you want to access a
4766+ collection of folders created using the Courier server, you MUST edit your
4767+ ".pinerc" file and enter the definition of the collection as follows:
4768+
4769+ folder-collections="Anything you want" #mc/INBOX.[]
4770+
4771+ You can replace the string "#mc/INBOX." by something different, for example
4772+ "#mc/Courier/." will make Alpine search for your collection in ~/Courier.
4773+
4774+ You can not add this setting directly into Alpine because Alpine fails to
4775+ accept this value from its input, but it takes it correctly when it is
4776+ added through the ".pinerc" file.
4777+
4778+ You can access your inbox as "#mc/INBOX" or "#md/INBOX". Both definitions
4779+ point to the same place.
4780+
4781+ Last Updated May 28, 2011
4782diff -rc alpine-2.20/web/src/alpined.d/Makefile alpine-2.20.maildir/web/src/alpined.d/Makefile
4783*** alpine-2.20/web/src/alpined.d/Makefile 2015-01-18 00:00:55.339703310 -0700
4784--- alpine-2.20.maildir/web/src/alpined.d/Makefile 2015-01-20 20:38:26.693015664 -0700
4785***************
4786*** 235,249 ****
4787 ETAGS = etags
4788 CTAGS = ctags
4789 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
4790! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing aclocal-1.13
4791 AMTAR = $${TAR-tar}
4792 AM_CFLAGS = -g -pthread
4793 AM_DEFAULT_VERBOSITY = 1
4794 AM_LDFLAGS = `cat ../../../c-client/LDFLAGS`
4795 AR = /usr/bin/ar
4796! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoconf
4797! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing autoheader
4798! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing automake-1.13
4799 AWK = gawk
4800 CC = gcc -std=gnu99
4801 CCDEPMODE = depmode=gcc3
4802--- 235,249 ----
4803 ETAGS = etags
4804 CTAGS = ctags
4805 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
4806! ACLOCAL = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing aclocal-1.13
4807 AMTAR = $${TAR-tar}
4808 AM_CFLAGS = -g -pthread
4809 AM_DEFAULT_VERBOSITY = 1
4810 AM_LDFLAGS = `cat ../../../c-client/LDFLAGS`
4811 AR = /usr/bin/ar
4812! AUTOCONF = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoconf
4813! AUTOHEADER = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing autoheader
4814! AUTOMAKE = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing automake-1.13
4815 AWK = gawk
4816 CC = gcc -std=gnu99
4817 CCDEPMODE = depmode=gcc3
4818***************
4819*** 254,260 ****
4820 CYGPATH_W = echo
4821 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
4822 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
4823! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5"
4824 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
4825 C_CLIENT_TARGET = lsu
4826 C_CLIENT_WITH_IPV6 = touch imap/ip6
4827--- 254,260 ----
4828 CYGPATH_W = echo
4829 C_CLIENT_CFLAGS = EXTRACFLAGS=" -DTLSV1_2 -I/usr/include/openssl -g"
4830 C_CLIENT_GCCOPTLEVEL = GCCOPTLEVEL="-O0"
4831! C_CLIENT_LDFLAGS = EXTRALDFLAGS=" -L/usr/lib -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5"
4832 C_CLIENT_SPECIALS = SSLINCLUDE=/usr/include/openssl SSLLIB=/usr/lib SSLDIR=/etc/ssl SSLCERTS=/etc/ssl/certs SSLKEYS=/etc/ssl/private EXTRAAUTHENTICATORS=gss
4833 C_CLIENT_TARGET = lsu
4834 C_CLIENT_WITH_IPV6 = touch imap/ip6
4835***************
4836*** 285,291 ****
4837 LIBICONV = -liconv
4838 LIBINTL =
4839 LIBOBJS =
4840! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lcrypto -lssl -ldl -ltinfo -lpam -lkrb5
4841 LIBTOOL = $(SHELL) $(top_builddir)/libtool
4842 LIBTOOL_DEPS = ./ltmain.sh
4843 LIPO =
4844--- 285,291 ----
4845 LIBICONV = -liconv
4846 LIBINTL =
4847 LIBOBJS =
4848! LIBS = -ltcl8.6 -lgssapi_krb5 -lpam -lldap -lcrypto -lssl -ldl -ltinfo -llber -lpam -lkrb5
4849 LIBTOOL = $(SHELL) $(top_builddir)/libtool
4850 LIBTOOL_DEPS = ./ltmain.sh
4851 LIPO =
4852***************
4853*** 297,303 ****
4854 LTLIBOBJS =
4855 MAINT = #
4856 MAKE = /usr/bin/make
4857! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/missing makeinfo
4858 MANIFEST_TOOL = :
4859 MKDIR_P = /usr/bin/mkdir -p
4860 MSGFMT = /usr/bin/msgfmt
4861--- 297,303 ----
4862 LTLIBOBJS =
4863 MAINT = #
4864 MAKE = /usr/bin/make
4865! MAKEINFO = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/missing makeinfo
4866 MANIFEST_TOOL = :
4867 MKDIR_P = /usr/bin/mkdir -p
4868 MSGFMT = /usr/bin/msgfmt
4869***************
4870*** 341,350 ****
4871 WEB_PUBCOOKIE_LINK =
4872 XGETTEXT = /usr/bin/xgettext
4873 XGETTEXT_015 = /usr/bin/xgettext
4874! abs_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/web/src/alpined.d
4875! abs_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/web/src/alpined.d
4876! abs_top_builddir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
4877! abs_top_srcdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20
4878 ac_ct_AR = ar
4879 ac_ct_CC = gcc
4880 ac_ct_DUMPBIN =
4881--- 341,350 ----
4882 WEB_PUBCOOKIE_LINK =
4883 XGETTEXT = /usr/bin/xgettext
4884 XGETTEXT_015 = /usr/bin/xgettext
4885! abs_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/web/src/alpined.d
4886! abs_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/web/src/alpined.d
4887! abs_top_builddir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
4888! abs_top_srcdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir
4889 ac_ct_AR = ar
4890 ac_ct_CC = gcc
4891 ac_ct_DUMPBIN =
4892***************
4893*** 376,382 ****
4894 htmldir = ${docdir}
4895 includedir = ${prefix}/include
4896 infodir = ${datarootdir}/info
4897! install_sh = ${SHELL} /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/install-sh
4898 libdir = ${exec_prefix}/lib
4899 libexecdir = ${exec_prefix}/libexec
4900 localedir = ${datadir}/locale
4901--- 376,382 ----
4902 htmldir = ${docdir}
4903 includedir = ${prefix}/include
4904 infodir = ${datarootdir}/info
4905! install_sh = ${SHELL} /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/install-sh
4906 libdir = ${exec_prefix}/lib
4907 libexecdir = ${exec_prefix}/libexec
4908 localedir = ${datadir}/locale
4909***************
4910*** 399,406 ****
4911
4912 # This is because alpined, libwpcomm and friends are
4913 # not intended for system-wide consumption
4914! locbindir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/web/src/alpined.d/../../bin
4915! loclibdir = /home/echappa/backup/011115.0/public_html/alpine/release/src/alpine-2.20/web/src/alpined.d/../../lib
4916 alpined_SOURCES = alpined.c busy.c color.c imap.c ldap.c remote.c \
4917 signal.c debug.c status.c stubs.c \
4918 alpined.h color.h ldap.h
4919--- 399,406 ----
4920
4921 # This is because alpined, libwpcomm and friends are
4922 # not intended for system-wide consumption
4923! locbindir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/web/src/alpined.d/../../bin
4924! loclibdir = /home/echappa/backup/011115.0/alpine/alpine-2.20.maildir/web/src/alpined.d/../../lib
4925 alpined_SOURCES = alpined.c busy.c color.c imap.c ldap.c remote.c \
4926 signal.c debug.c status.c stubs.c \
4927 alpined.h color.h ldap.h