Lines 24-29
Link Here
|
24 |
|
24 |
|
25 |
#include "isync.h" |
25 |
#include "isync.h" |
26 |
|
26 |
|
|
|
27 |
#include <assert.h> |
27 |
#include <limits.h> |
28 |
#include <limits.h> |
28 |
#include <stdlib.h> |
29 |
#include <stdlib.h> |
29 |
#include <string.h> |
30 |
#include <string.h> |
Lines 46-51
Link Here
|
46 |
#include <db.h> |
47 |
#include <db.h> |
47 |
#endif /* USE_DB */ |
48 |
#endif /* USE_DB */ |
48 |
|
49 |
|
|
|
50 |
static void encode_maildir_box(const char* in, char* out, size_t size) |
51 |
{ |
52 |
const char* p; |
53 |
char c; |
54 |
size_t out_chars; |
55 |
|
56 |
for (p = in, out_chars = 0; (c = *p); ++p, ++out, ++out_chars) { |
57 |
assert(out_chars < size); |
58 |
if (c == '/') { |
59 |
assert(out_chars < size - 1); |
60 |
*(out++) = '~'; |
61 |
*out = '-'; |
62 |
++out_chars; |
63 |
} |
64 |
else if (c == '~') { |
65 |
assert(out_chars < size - 1); |
66 |
*(out++) = '~'; |
67 |
*out = '~'; |
68 |
++out_chars; |
69 |
} |
70 |
else { |
71 |
*out = c; |
72 |
} |
73 |
} |
74 |
assert(out_chars < size); |
75 |
*out = 0; |
76 |
} |
77 |
|
78 |
static void decode_maildir_box(const char* in, char* out, size_t size) |
79 |
{ |
80 |
const char* p; |
81 |
char c; |
82 |
size_t out_chars; |
83 |
|
84 |
for (p = in, out_chars = 0; (c = *p); ++p, ++out, ++out_chars) { |
85 |
assert(out_chars < size); |
86 |
if (c == '~') { |
87 |
assert(out_chars < size - 1); |
88 |
c = *(++p); |
89 |
*out = (c == '-' ? '/' : '~'); |
90 |
++out_chars; |
91 |
} |
92 |
else { |
93 |
*out = c; |
94 |
} |
95 |
} |
96 |
assert(out_chars < size); |
97 |
*out = 0; |
98 |
} |
99 |
|
49 |
typedef struct maildir_store_conf { |
100 |
typedef struct maildir_store_conf { |
50 |
store_conf_t gen; |
101 |
store_conf_t gen; |
51 |
char *inbox; |
102 |
char *inbox; |
Lines 164-177
maildir_list( store_t *gctx, string_list
Link Here
|
164 |
const char *inbox = ((maildir_store_conf_t *)gctx->conf)->inbox; |
215 |
const char *inbox = ((maildir_store_conf_t *)gctx->conf)->inbox; |
165 |
int bl; |
216 |
int bl; |
166 |
struct stat st; |
217 |
struct stat st; |
167 |
char buf[PATH_MAX]; |
218 |
char buf[PATH_MAX], box[PATH_MAX]; |
168 |
|
219 |
|
169 |
if (*de->d_name == '.') |
220 |
if (*de->d_name == '.') |
170 |
continue; |
221 |
continue; |
171 |
bl = nfsnprintf( buf, sizeof(buf), "%s%s/cur", gctx->conf->path, de->d_name ); |
222 |
bl = nfsnprintf( buf, sizeof(buf), "%s%s/cur", gctx->conf->path, de->d_name ); |
172 |
if (stat( buf, &st ) || !S_ISDIR(st.st_mode)) |
223 |
if (stat( buf, &st ) || !S_ISDIR(st.st_mode)) |
173 |
continue; |
224 |
continue; |
174 |
add_string_list( retb, !memcmp( buf, inbox, bl - 4 ) && !inbox[bl - 4] ? "INBOX" : de->d_name ); |
225 |
|
|
|
226 |
decode_maildir_box(de->d_name, box, PATH_MAX); |
227 |
add_string_list( retb, |
228 |
!memcmp( buf, inbox, bl - 4 ) && !inbox[bl - 4] ? "INBOX" : box ); |
175 |
} |
229 |
} |
176 |
closedir (dir); |
230 |
closedir (dir); |
177 |
|
231 |
|
Lines 717-724
maildir_prepare( store_t *gctx, int opts
Link Here
|
717 |
#endif /* USE_DB */ |
771 |
#endif /* USE_DB */ |
718 |
if (!strcmp( gctx->name, "INBOX" )) |
772 |
if (!strcmp( gctx->name, "INBOX" )) |
719 |
gctx->path = nfstrdup( ((maildir_store_conf_t *)gctx->conf)->inbox ); |
773 |
gctx->path = nfstrdup( ((maildir_store_conf_t *)gctx->conf)->inbox ); |
720 |
else |
774 |
else { |
721 |
nfasprintf( &gctx->path, "%s%s", gctx->conf->path, gctx->name ); |
775 |
char box[_POSIX_PATH_MAX]; |
|
|
776 |
encode_maildir_box(gctx->name, box, _POSIX_PATH_MAX); |
777 |
nfasprintf( &gctx->path, "%s%s", gctx->conf->path, box ); |
778 |
} |
722 |
if (opts & OPEN_SETFLAGS) |
779 |
if (opts & OPEN_SETFLAGS) |
723 |
opts |= OPEN_OLD; |
780 |
opts |= OPEN_OLD; |
724 |
if (opts & OPEN_EXPUNGE) |
781 |
if (opts & OPEN_EXPUNGE) |