drv_maildir.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  1. /*
  2. * mbsync - mailbox synchronizer
  3. * Copyright (C) 2000-2002 Michael R. Elkins <me@mutt.org>
  4. * Copyright (C) 2002-2004 Oswald Buddenhagen <ossi@users.sf.net>
  5. * Copyright (C) 2004 Theodore Y. Ts'o <tytso@mit.edu>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. * As a special exception, mbsync may be linked with the OpenSSL library,
  22. * despite that library's more restrictive license.
  23. */
  24. #include "isync.h"
  25. #include <limits.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <ctype.h>
  29. #include <dirent.h>
  30. #include <fcntl.h>
  31. #include <stdio.h>
  32. #include <unistd.h>
  33. #include <sys/stat.h>
  34. #include <sys/file.h>
  35. #include <errno.h>
  36. #include <time.h>
  37. #define USE_DB 1
  38. #ifdef __linux__
  39. # define LEGACY_FLOCK 1
  40. #endif
  41. #ifdef USE_DB
  42. #include <db.h>
  43. #endif /* USE_DB */
  44. typedef struct maildir_store_conf {
  45. store_conf_t gen;
  46. char *inbox;
  47. #ifdef USE_DB
  48. int alt_map;
  49. #endif /* USE_DB */
  50. } maildir_store_conf_t;
  51. typedef struct maildir_message {
  52. message_t gen;
  53. char *base;
  54. } maildir_message_t;
  55. typedef struct maildir_store {
  56. store_t gen;
  57. int uvfd, uvok, nuid;
  58. int minuid, maxuid, nexcs, *excs;
  59. #ifdef USE_DB
  60. DB *db;
  61. #endif /* USE_DB */
  62. } maildir_store_t;
  63. #ifdef USE_DB
  64. static DBT key, value; /* no need to be reentrant, and this saves lots of memset()s */
  65. #endif /* USE_DB */
  66. static struct flock lck;
  67. static int MaildirCount;
  68. static const char Flags[] = { 'D', 'F', 'R', 'S', 'T' };
  69. static unsigned char
  70. maildir_parse_flags( const char *base )
  71. {
  72. const char *s;
  73. unsigned i;
  74. unsigned char flags;
  75. flags = 0;
  76. if ((s = strstr( base, ":2," )))
  77. for (s += 3, i = 0; i < as(Flags); i++)
  78. if (strchr( s, Flags[i] ))
  79. flags |= (1 << i);
  80. return flags;
  81. }
  82. static void maildir_close_store( store_t *gctx );
  83. static store_t *
  84. maildir_open_store( store_conf_t *conf, store_t *oldctx )
  85. {
  86. maildir_store_t *ctx;
  87. struct stat st;
  88. if (oldctx)
  89. maildir_close_store( oldctx );
  90. if (stat( conf->path, &st ) || !S_ISDIR(st.st_mode)) {
  91. fprintf( stderr, "Maildir error: cannot open store %s\n", conf->path );
  92. return 0;
  93. }
  94. ctx = nfcalloc( sizeof(*ctx) );
  95. ctx->gen.conf = conf;
  96. ctx->uvfd = -1;
  97. return &ctx->gen;
  98. }
  99. static void
  100. free_maildir_messages( message_t *msg )
  101. {
  102. message_t *tmsg;
  103. for (; (tmsg = msg); msg = tmsg) {
  104. tmsg = msg->next;
  105. free( ((maildir_message_t *)msg)->base );
  106. free( msg );
  107. }
  108. }
  109. static void
  110. maildir_cleanup( store_t *gctx )
  111. {
  112. maildir_store_t *ctx = (maildir_store_t *)gctx;
  113. free_maildir_messages( gctx->msgs );
  114. #ifdef USE_DB
  115. if (ctx->db)
  116. ctx->db->close( ctx->db, 0 );
  117. #endif /* USE_DB */
  118. if (gctx->path)
  119. free( gctx->path );
  120. if (ctx->excs)
  121. free( ctx->excs );
  122. if (ctx->uvfd >= 0)
  123. close( ctx->uvfd );
  124. }
  125. static void
  126. maildir_close_store( store_t *gctx )
  127. {
  128. maildir_cleanup( gctx );
  129. free( gctx );
  130. }
  131. static int
  132. maildir_list( store_t *gctx, string_list_t **retb )
  133. {
  134. DIR *dir;
  135. struct dirent *de;
  136. if (!(dir = opendir( gctx->conf->path ))) {
  137. fprintf( stderr, "%s: %s\n", gctx->conf->path, strerror(errno) );
  138. return DRV_STORE_BAD;
  139. }
  140. *retb = 0;
  141. while ((de = readdir( dir ))) {
  142. struct stat st;
  143. char buf[PATH_MAX];
  144. if (*de->d_name == '.')
  145. continue;
  146. nfsnprintf( buf, sizeof(buf), "%s%s/cur", gctx->conf->path, de->d_name );
  147. if (stat( buf, &st ) || !S_ISDIR(st.st_mode))
  148. continue;
  149. add_string_list( retb, de->d_name );
  150. }
  151. closedir (dir);
  152. return DRV_OK;
  153. }
  154. static const char *subdirs[] = { "cur", "new", "tmp" };
  155. typedef struct {
  156. char *base;
  157. int size;
  158. unsigned uid:31, recent:1;
  159. } msg_t;
  160. typedef struct {
  161. msg_t *ents;
  162. int nents, nalloc;
  163. } msglist_t;
  164. static void
  165. maildir_free_scan( msglist_t *msglist )
  166. {
  167. int i;
  168. if (msglist->ents) {
  169. for (i = 0; i < msglist->nents; i++)
  170. if (msglist->ents[i].base)
  171. free( msglist->ents[i].base );
  172. free( msglist->ents );
  173. }
  174. }
  175. #define _24_HOURS (3600 * 24)
  176. static int
  177. maildir_validate( const char *prefix, const char *box, int create )
  178. {
  179. DIR *dirp;
  180. struct dirent *entry;
  181. time_t now;
  182. int i, bl;
  183. struct stat st;
  184. char buf[_POSIX_PATH_MAX];
  185. bl = nfsnprintf( buf, sizeof(buf) - 4, "%s%s/", prefix, box );
  186. if (stat( buf, &st )) {
  187. if (errno == ENOENT) {
  188. if (create) {
  189. if (mkdir( buf, 0700 )) {
  190. fprintf( stderr, "Maildir error: mkdir %s: %s (errno %d)\n",
  191. buf, strerror(errno), errno );
  192. return DRV_STORE_BAD;
  193. }
  194. for (i = 0; i < 3; i++) {
  195. memcpy( buf + bl, subdirs[i], 4 );
  196. if (mkdir( buf, 0700 )) {
  197. fprintf( stderr, "Maildir error: mkdir %s: %s (errno %d)\n",
  198. buf, strerror(errno), errno );
  199. return DRV_BOX_BAD;
  200. }
  201. }
  202. } else {
  203. fprintf( stderr, "Maildir error: mailbox '%s' does not exist\n", buf );
  204. return DRV_BOX_BAD;
  205. }
  206. } else {
  207. fprintf( stderr, "Maildir error: stat %s: %s (errno %d)\n",
  208. buf, strerror(errno), errno );
  209. return DRV_BOX_BAD;
  210. }
  211. } else {
  212. for (i = 0; i < 3; i++) {
  213. memcpy( buf + bl, subdirs[i], 4 );
  214. if (stat( buf, &st ) || !S_ISDIR(st.st_mode)) {
  215. fprintf( stderr, "Maildir error: '%s' is no valid mailbox\n", buf );
  216. return DRV_BOX_BAD;
  217. }
  218. }
  219. memcpy( buf + bl, "tmp/", 5 );
  220. bl += 4;
  221. if (!(dirp = opendir( buf ))) {
  222. fprintf( stderr, "Maildir error: opendir: %s: %s (errno %d)\n",
  223. buf, strerror(errno), errno );
  224. return DRV_BOX_BAD;
  225. }
  226. time( &now );
  227. while ((entry = readdir( dirp ))) {
  228. nfsnprintf( buf + bl, sizeof(buf) - bl, "%s", entry->d_name );
  229. if (stat( buf, &st ))
  230. fprintf( stderr, "Maildir error: stat: %s: %s (errno %d)\n",
  231. buf, strerror(errno), errno );
  232. else if (S_ISREG(st.st_mode) && now - st.st_ctime >= _24_HOURS) {
  233. /* this should happen infrequently enough that it won't be
  234. * bothersome to the user to display when it occurs.
  235. */
  236. info( "Maildir notice: removing stale file %s\n", buf );
  237. if (unlink( buf ))
  238. fprintf( stderr, "Maildir error: unlink: %s: %s (errno %d)\n",
  239. buf, strerror(errno), errno );
  240. }
  241. }
  242. closedir( dirp );
  243. }
  244. return DRV_OK;
  245. }
  246. #ifdef USE_DB
  247. static void
  248. make_key( DBT *tkey, char *name )
  249. {
  250. char *u = strpbrk( name, ":," );
  251. tkey->data = name;
  252. tkey->size = u ? (size_t)(u - name) : strlen( name );
  253. }
  254. static int
  255. maildir_set_uid( maildir_store_t *ctx, const char *name, int *uid )
  256. {
  257. int ret, uv[2];
  258. if (uid)
  259. *uid = ++ctx->nuid;
  260. key.data = (void *)"UIDVALIDITY";
  261. key.size = 11;
  262. uv[0] = ctx->gen.uidvalidity;
  263. uv[1] = ctx->nuid;
  264. value.data = uv;
  265. value.size = sizeof(uv);
  266. if ((ret = ctx->db->put( ctx->db, 0, &key, &value, 0 ))) {
  267. tbork:
  268. ctx->db->err( ctx->db, ret, "Maildir error: db->put()" );
  269. bork:
  270. ctx->db->close( ctx->db, 0 );
  271. ctx->db = 0;
  272. return DRV_BOX_BAD;
  273. }
  274. if (uid) {
  275. make_key( &key, (char *)name );
  276. value.data = uid;
  277. value.size = sizeof(*uid);
  278. if ((ret = ctx->db->put( ctx->db, 0, &key, &value, 0 )))
  279. goto tbork;
  280. }
  281. if ((ret = ctx->db->sync( ctx->db, 0 ))) {
  282. ctx->db->err( ctx->db, ret, "Maildir error: db->sync()" );
  283. goto bork;
  284. }
  285. return DRV_OK;
  286. }
  287. #endif /* USE_DB */
  288. static int
  289. maildir_store_uid( maildir_store_t *ctx )
  290. {
  291. int n;
  292. char buf[128];
  293. n = sprintf( buf, "%d\n%d\n", ctx->gen.uidvalidity, ctx->nuid );
  294. lseek( ctx->uvfd, 0, SEEK_SET );
  295. if (write( ctx->uvfd, buf, n ) != n || ftruncate( ctx->uvfd, n )) {
  296. fprintf( stderr, "Maildir error: cannot write UIDVALIDITY.\n" );
  297. return DRV_BOX_BAD;
  298. }
  299. return DRV_OK;
  300. }
  301. static int
  302. maildir_init_uid( maildir_store_t *ctx, const char *msg )
  303. {
  304. info( "Maildir notice: %s.\n", msg ? msg : "cannot read UIDVALIDITY, creating new" );
  305. ctx->gen.uidvalidity = time( 0 );
  306. ctx->nuid = 0;
  307. ctx->uvok = 0;
  308. #ifdef USE_DB
  309. if (ctx->db) {
  310. ctx->db->truncate( ctx->db, 0, 0 /* &u_int32_t_dummy */, 0 );
  311. return maildir_set_uid( ctx, 0, 0 );
  312. }
  313. #endif /* USE_DB */
  314. return maildir_store_uid( ctx );
  315. }
  316. static int
  317. maildir_uidval_lock( maildir_store_t *ctx )
  318. {
  319. int n;
  320. char buf[128];
  321. #ifdef LEGACY_FLOCK
  322. /* This is legacy only */
  323. if (flock( ctx->uvfd, LOCK_EX ) < 0) {
  324. fprintf( stderr, "Maildir error: cannot flock UIDVALIDITY.\n" );
  325. return DRV_BOX_BAD;
  326. }
  327. #endif
  328. /* This (theoretically) works over NFS. Let's hope nobody else did
  329. the same in the opposite order, as we'd deadlock then. */
  330. #if SEEK_SET != 0
  331. lck.l_whence = SEEK_SET;
  332. #endif
  333. lck.l_type = F_WRLCK;
  334. if (fcntl( ctx->uvfd, F_SETLKW, &lck )) {
  335. fprintf( stderr, "Maildir error: cannot fcntl lock UIDVALIDITY.\n" );
  336. return DRV_BOX_BAD;
  337. }
  338. lseek( ctx->uvfd, 0, SEEK_SET );
  339. if ((n = read( ctx->uvfd, buf, sizeof(buf) )) <= 0 ||
  340. (buf[n] = 0, sscanf( buf, "%d\n%d", &ctx->gen.uidvalidity, &ctx->nuid ) != 2)) {
  341. return maildir_init_uid( ctx, 0 );
  342. } else
  343. ctx->uvok = 1;
  344. return DRV_OK;
  345. }
  346. static void
  347. maildir_uidval_unlock( maildir_store_t *ctx )
  348. {
  349. lck.l_type = F_UNLCK;
  350. fcntl( ctx->uvfd, F_SETLK, &lck );
  351. #ifdef LEGACY_FLOCK
  352. /* This is legacy only */
  353. flock( ctx->uvfd, LOCK_UN );
  354. #endif
  355. }
  356. static int
  357. maildir_obtain_uid( maildir_store_t *ctx, int *uid )
  358. {
  359. *uid = ++ctx->nuid;
  360. return maildir_store_uid( ctx );
  361. }
  362. static int
  363. maildir_compare( const void *l, const void *r )
  364. {
  365. msg_t *lm = (msg_t *)l, *rm = (msg_t *)r;
  366. char *ldot, *rdot, *ldot2, *rdot2, *lseq, *rseq;
  367. int ret, llen, rlen;
  368. if ((ret = lm->uid - rm->uid))
  369. return ret;
  370. /* No UID, so sort by arrival date. We should not do this, but we rely
  371. on the suggested unique file name scheme - we have no choice. */
  372. /* The first field are always the seconds. Alphabetical sort should be
  373. faster than numeric. */
  374. if (!(ldot = strchr( lm->base, '.' )) || !(rdot = strchr( rm->base, '.' )))
  375. goto stronly; /* Should never happen ... */
  376. llen = ldot - lm->base, rlen = rdot - rm->base;
  377. /* The shorter number is smaller. Really. This won't trigger with any
  378. mail created after Sep 9 2001 anyway. */
  379. if ((ret = llen - rlen))
  380. return ret;
  381. if ((ret = memcmp( lm->base, rm->base, llen )))
  382. return ret;
  383. ldot++, rdot++;
  384. if ((llen = strtol( ldot, &ldot2, 10 ))) {
  385. if (!(rlen = strtol( rdot, &rdot2, 10 )))
  386. goto stronly; /* Comparing apples to oranges ... */
  387. /* Classical PID specs */
  388. if ((ret = llen - rlen)) {
  389. retpid:
  390. /* Handle PID wraparound. This works only on systems
  391. where PIDs are not reused too fast */
  392. if (ret > 20000 || ret < -20000)
  393. ret = -ret;
  394. return ret;
  395. }
  396. return (*ldot2 != '_' ? 0 : atoi( ldot2 + 1 )) -
  397. (*rdot2 != '_' ? 0 : atoi( rdot2 + 1 ));
  398. }
  399. if (!(ldot2 = strchr( ldot, '.' )) || !(rdot2 = strchr( rdot, '.' )))
  400. goto stronly; /* Should never happen ... */
  401. llen = ldot2 - ldot, rlen = rdot2 - rdot;
  402. if (((lseq = memchr( ldot, '#', llen )) && (rseq = memchr( rdot, '#', rlen ))) ||
  403. ((lseq = memchr( ldot, 'M', llen )) && (rseq = memchr( rdot, 'M', rlen ))))
  404. return atoi( lseq + 1 ) - atoi( rseq + 1 );
  405. if ((lseq = memchr( ldot, 'P', llen )) && (rseq = memchr( rdot, 'P', rlen ))) {
  406. if ((ret = atoi( lseq + 1 ) - atoi( rseq + 1 )))
  407. goto retpid;
  408. if ((lseq = memchr( ldot, 'Q', llen )) && (rseq = memchr( rdot, 'Q', rlen )))
  409. return atoi( lseq + 1 ) - atoi( rseq + 1 );
  410. }
  411. stronly:
  412. /* Fall-back, so the sort order is defined at all */
  413. return strcmp( lm->base, rm->base );
  414. }
  415. static int
  416. maildir_scan( maildir_store_t *ctx, msglist_t *msglist )
  417. {
  418. DIR *d;
  419. struct dirent *e;
  420. const char *u, *ru;
  421. #ifdef USE_DB
  422. DB *tdb;
  423. DBC *dbc;
  424. #endif /* USE_DB */
  425. msg_t *entry;
  426. int i, j, uid, bl, ml, fnl, ret;
  427. struct stat st;
  428. char buf[_POSIX_PATH_MAX], nbuf[_POSIX_PATH_MAX];
  429. #ifdef USE_DB
  430. if (!ctx->db)
  431. #endif /* USE_DB */
  432. if ((ret = maildir_uidval_lock( ctx )) != DRV_OK)
  433. return ret;
  434. again:
  435. msglist->ents = 0;
  436. msglist->nents = msglist->nalloc = 0;
  437. ctx->gen.count = ctx->gen.recent = 0;
  438. if (ctx->uvok || ctx->maxuid == INT_MAX) {
  439. #ifdef USE_DB
  440. if (ctx->db) {
  441. if (db_create( &tdb, 0, 0 )) {
  442. fputs( "Maildir error: db_create() failed\n", stderr );
  443. return DRV_BOX_BAD;
  444. }
  445. if (tdb->open( tdb, 0, 0, 0, DB_HASH, DB_CREATE, 0 )) {
  446. fputs( "Maildir error: tdb->open() failed\n", stderr );
  447. tdb->close( tdb, 0 );
  448. return DRV_BOX_BAD;
  449. }
  450. }
  451. #endif /* USE_DB */
  452. bl = nfsnprintf( buf, sizeof(buf) - 4, "%s/", ctx->gen.path );
  453. for (i = 0; i < 2; i++) {
  454. memcpy( buf + bl, subdirs[i], 4 );
  455. if (!(d = opendir( buf ))) {
  456. perror( buf );
  457. #ifdef USE_DB
  458. if (!ctx->db)
  459. #endif /* USE_DB */
  460. maildir_uidval_unlock( ctx );
  461. #ifdef USE_DB
  462. bork:
  463. #endif /* USE_DB */
  464. maildir_free_scan( msglist );
  465. #ifdef USE_DB
  466. if (ctx->db)
  467. tdb->close( tdb, 0 );
  468. #endif /* USE_DB */
  469. return DRV_BOX_BAD;
  470. }
  471. while ((e = readdir( d ))) {
  472. if (*e->d_name == '.')
  473. continue;
  474. ctx->gen.count++;
  475. ctx->gen.recent += i;
  476. #ifdef USE_DB
  477. if (ctx->db) {
  478. make_key( &key, e->d_name );
  479. if ((ret = ctx->db->get( ctx->db, 0, &key, &value, 0 ))) {
  480. if (ret != DB_NOTFOUND) {
  481. ctx->db->err( ctx->db, ret, "Maildir error: db->get()" );
  482. ctx->db->close( ctx->db, 0 );
  483. ctx->db = 0;
  484. goto bork;
  485. }
  486. uid = INT_MAX;
  487. } else {
  488. value.size = 0;
  489. if ((ret = tdb->put( tdb, 0, &key, &value, 0 ))) {
  490. tdb->err( tdb, ret, "Maildir error: tdb->put()" );
  491. goto bork;
  492. }
  493. uid = *(int *)value.data;
  494. }
  495. } else
  496. #endif /* USE_DB */
  497. {
  498. uid = (ctx->uvok && (u = strstr( e->d_name, ",U=" ))) ? atoi( u + 3 ) : 0;
  499. if (!uid)
  500. uid = INT_MAX;
  501. }
  502. if (uid <= ctx->maxuid) {
  503. if (uid < ctx->minuid) {
  504. for (j = 0; j < ctx->nexcs; j++)
  505. if (ctx->excs[j] == uid)
  506. goto oke;
  507. continue;
  508. oke: ;
  509. }
  510. if (msglist->nalloc == msglist->nents) {
  511. msglist->nalloc = msglist->nalloc * 2 + 100;
  512. msglist->ents = nfrealloc( msglist->ents, msglist->nalloc * sizeof(msg_t) );
  513. }
  514. entry = &msglist->ents[msglist->nents++];
  515. entry->base = nfstrdup( e->d_name );
  516. entry->uid = uid;
  517. entry->recent = i;
  518. entry->size = 0;
  519. }
  520. }
  521. closedir( d );
  522. }
  523. #ifdef USE_DB
  524. if (ctx->db) {
  525. if ((ret = ctx->db->cursor( ctx->db, 0, &dbc, 0 )))
  526. ctx->db->err( ctx->db, ret, "Maildir error: db->cursor()" );
  527. else {
  528. for (;;) {
  529. if ((ret = dbc->c_get( dbc, &key, &value, DB_NEXT ))) {
  530. if (ret != DB_NOTFOUND)
  531. ctx->db->err( ctx->db, ret, "Maildir error: db->c_get()" );
  532. break;
  533. }
  534. if ((key.size != 11 || memcmp( key.data, "UIDVALIDITY", 11 )) &&
  535. (ret = tdb->get( tdb, 0, &key, &value, 0 ))) {
  536. if (ret != DB_NOTFOUND) {
  537. tdb->err( tdb, ret, "Maildir error: tdb->get()" );
  538. break;
  539. }
  540. if ((ret = dbc->c_del( dbc, 0 ))) {
  541. ctx->db->err( ctx->db, ret, "Maildir error: db->c_del()" );
  542. break;
  543. }
  544. }
  545. }
  546. dbc->c_close( dbc );
  547. }
  548. tdb->close( tdb, 0 );
  549. }
  550. #endif /* USE_DB */
  551. qsort( msglist->ents, msglist->nents, sizeof(msg_t), maildir_compare );
  552. for (uid = i = 0; i < msglist->nents; i++) {
  553. entry = &msglist->ents[i];
  554. if (entry->uid != INT_MAX) {
  555. if (uid == entry->uid) {
  556. if ((ret = maildir_init_uid( ctx, "duplicate UID; changing UIDVALIDITY" )) != DRV_OK) {
  557. maildir_free_scan( msglist );
  558. return ret;
  559. }
  560. maildir_free_scan( msglist );
  561. goto again;
  562. }
  563. uid = entry->uid;
  564. if (ctx->gen.opts & OPEN_SIZE)
  565. nfsnprintf( buf + bl, sizeof(buf) - bl, "%s/%s", subdirs[entry->recent], entry->base );
  566. #ifdef USE_DB
  567. } else if (ctx->db) {
  568. if ((ret = maildir_set_uid( ctx, entry->base, &uid )) != DRV_OK) {
  569. maildir_free_scan( msglist );
  570. return ret;
  571. }
  572. entry->uid = uid;
  573. if (ctx->gen.opts & OPEN_SIZE)
  574. nfsnprintf( buf + bl, sizeof(buf) - bl, "%s/%s", subdirs[entry->recent], entry->base );
  575. #endif /* USE_DB */
  576. } else {
  577. if ((ret = maildir_obtain_uid( ctx, &uid )) != DRV_OK) {
  578. maildir_free_scan( msglist );
  579. return ret;
  580. }
  581. entry->uid = uid;
  582. if ((u = strstr( entry->base, ",U=" )))
  583. for (ru = u + 3; isdigit( (unsigned char)*ru ); ru++);
  584. else
  585. u = ru = strchr( entry->base, ':' );
  586. if (u)
  587. ml = u - entry->base;
  588. else
  589. ru = "", ml = INT_MAX;
  590. fnl = nfsnprintf( buf + bl, sizeof(buf) - bl, "%s/%.*s,U=%d%s", subdirs[entry->recent], ml, entry->base, uid, ru ) + 1 - 4;
  591. memcpy( nbuf, buf, bl + 4 );
  592. nfsnprintf( nbuf + bl + 4, sizeof(nbuf) - bl - 4, "%s", entry->base );
  593. if (rename( nbuf, buf )) {
  594. if (errno != ENOENT) {
  595. perror( buf );
  596. maildir_uidval_unlock( ctx );
  597. maildir_free_scan( msglist );
  598. return DRV_BOX_BAD;
  599. }
  600. maildir_free_scan( msglist );
  601. goto again;
  602. }
  603. free( entry->base );
  604. entry->base = nfmalloc( fnl );
  605. memcpy( entry->base, buf + bl + 4, fnl );
  606. }
  607. if (ctx->gen.opts & OPEN_SIZE) {
  608. if (stat( buf, &st )) {
  609. maildir_free_scan( msglist );
  610. goto again;
  611. }
  612. entry->size = st.st_size;
  613. }
  614. }
  615. ctx->uvok = 1;
  616. }
  617. #ifdef USE_DB
  618. if (!ctx->db)
  619. #endif /* ! USE_DB */
  620. maildir_uidval_unlock( ctx );
  621. return DRV_OK;
  622. }
  623. static void
  624. maildir_init_msg( maildir_store_t *ctx, maildir_message_t *msg, msg_t *entry )
  625. {
  626. msg->base = entry->base;
  627. entry->base = 0; /* prevent deletion */
  628. msg->gen.size = entry->size;
  629. if (entry->recent)
  630. msg->gen.status |= M_RECENT;
  631. if (ctx->gen.opts & OPEN_FLAGS) {
  632. msg->gen.status |= M_FLAGS;
  633. msg->gen.flags = maildir_parse_flags( msg->base );
  634. } else
  635. msg->gen.flags = 0;
  636. }
  637. static void
  638. maildir_app_msg( maildir_store_t *ctx, message_t ***msgapp, msg_t *entry )
  639. {
  640. maildir_message_t *msg = nfmalloc( sizeof(*msg) );
  641. msg->gen.next = **msgapp;
  642. **msgapp = &msg->gen;
  643. *msgapp = &msg->gen.next;
  644. msg->gen.uid = entry->uid;
  645. msg->gen.status = 0;
  646. maildir_init_msg( ctx, msg, entry );
  647. }
  648. static void
  649. maildir_prepare( store_t *gctx, int opts )
  650. {
  651. maildir_store_t *ctx = (maildir_store_t *)gctx;
  652. maildir_cleanup( gctx );
  653. gctx->msgs = 0;
  654. ctx->uvfd = -1;
  655. #ifdef USE_DB
  656. ctx->db = 0;
  657. #endif /* USE_DB */
  658. if (!strcmp( gctx->name, "INBOX" ))
  659. gctx->path = nfstrdup( ((maildir_store_conf_t *)gctx->conf)->inbox );
  660. else
  661. nfasprintf( &gctx->path, "%s%s", gctx->conf->path, gctx->name );
  662. if (opts & OPEN_SETFLAGS)
  663. opts |= OPEN_OLD;
  664. if (opts & OPEN_EXPUNGE)
  665. opts |= OPEN_OLD|OPEN_NEW|OPEN_FLAGS;
  666. gctx->opts = opts;
  667. }
  668. static int
  669. maildir_select( store_t *gctx, int minuid, int maxuid, int *excs, int nexcs )
  670. {
  671. maildir_store_t *ctx = (maildir_store_t *)gctx;
  672. message_t **msgapp;
  673. msglist_t msglist;
  674. int i;
  675. #ifdef USE_DB
  676. int ret;
  677. #endif /* USE_DB */
  678. char uvpath[_POSIX_PATH_MAX];
  679. ctx->minuid = minuid;
  680. ctx->maxuid = maxuid;
  681. ctx->excs = nfrealloc( excs, nexcs * sizeof(int) );
  682. ctx->nexcs = nexcs;
  683. if (maildir_validate( gctx->path, "", ctx->gen.opts & OPEN_CREATE ) != DRV_OK)
  684. return DRV_BOX_BAD;
  685. nfsnprintf( uvpath, sizeof(uvpath), "%s/.uidvalidity", gctx->path );
  686. #ifndef USE_DB
  687. if ((ctx->uvfd = open( uvpath, O_RDWR|O_CREAT, 0600 )) < 0) {
  688. perror( uvpath );
  689. return DRV_BOX_BAD;
  690. }
  691. #else
  692. if ((ctx->uvfd = open( uvpath, O_RDWR, 0600 )) < 0) {
  693. nfsnprintf( uvpath, sizeof(uvpath), "%s/.isyncuidmap.db", gctx->path );
  694. if ((ctx->uvfd = open( uvpath, O_RDWR, 0600 )) < 0) {
  695. if (((maildir_store_conf_t *)gctx->conf)->alt_map) {
  696. if ((ctx->uvfd = open( uvpath, O_RDWR|O_CREAT, 0600 )) >= 0)
  697. goto dbok;
  698. } else {
  699. nfsnprintf( uvpath, sizeof(uvpath), "%s/.uidvalidity", gctx->path );
  700. if ((ctx->uvfd = open( uvpath, O_RDWR|O_CREAT, 0600 )) >= 0)
  701. goto fnok;
  702. }
  703. perror( uvpath );
  704. return DRV_BOX_BAD;
  705. }
  706. dbok:
  707. #if SEEK_SET != 0
  708. lck.l_whence = SEEK_SET;
  709. #endif
  710. lck.l_type = F_WRLCK;
  711. if (fcntl( ctx->uvfd, F_SETLKW, &lck )) {
  712. perror( uvpath );
  713. bork:
  714. close( ctx->uvfd );
  715. ctx->uvfd = -1;
  716. return DRV_BOX_BAD;
  717. }
  718. if (db_create( &ctx->db, 0, 0 )) {
  719. fputs( "Maildir error: db_create() failed\n", stderr );
  720. goto bork;
  721. }
  722. if ((ret = ctx->db->open( ctx->db, 0, uvpath, 0, DB_HASH, DB_CREATE, 0 ))) {
  723. ctx->db->err( ctx->db, ret, "Maildir error: db->open(%s)", uvpath );
  724. dbork:
  725. ctx->db->close( ctx->db, 0 );
  726. goto bork;
  727. }
  728. key.data = (void *)"UIDVALIDITY";
  729. key.size = 11;
  730. if ((ret = ctx->db->get( ctx->db, 0, &key, &value, 0 ))) {
  731. if (ret != DB_NOTFOUND) {
  732. ctx->db->err( ctx->db, ret, "Maildir error: db->get()" );
  733. goto dbork;
  734. }
  735. if (maildir_init_uid( ctx, 0 ) != DRV_OK)
  736. goto dbork;
  737. } else {
  738. ctx->gen.uidvalidity = ((int *)value.data)[0];
  739. ctx->nuid = ((int *)value.data)[1];
  740. ctx->uvok = 1;
  741. }
  742. }
  743. fnok:
  744. #endif /* USE_DB */
  745. if (maildir_scan( ctx, &msglist ) != DRV_OK)
  746. return DRV_BOX_BAD;
  747. msgapp = &ctx->gen.msgs;
  748. for (i = 0; i < msglist.nents; i++)
  749. maildir_app_msg( ctx, &msgapp, msglist.ents + i );
  750. maildir_free_scan( &msglist );
  751. return DRV_OK;
  752. }
  753. static int
  754. maildir_rescan( maildir_store_t *ctx )
  755. {
  756. message_t **msgapp;
  757. maildir_message_t *msg;
  758. msglist_t msglist;
  759. int i;
  760. if (maildir_scan( ctx, &msglist ) != DRV_OK)
  761. return DRV_BOX_BAD;
  762. ctx->gen.recent = 0;
  763. for (msgapp = &ctx->gen.msgs, i = 0;
  764. (msg = (maildir_message_t *)*msgapp) || i < msglist.nents; )
  765. {
  766. if (!msg) {
  767. #if 0
  768. debug( "adding new message %d\n", msglist.ents[i].uid );
  769. maildir_app_msg( ctx, &msgapp, msglist.ents + i );
  770. #else
  771. debug( "ignoring new message %d\n", msglist.ents[i].uid );
  772. #endif
  773. i++;
  774. } else if (i >= msglist.nents) {
  775. debug( "purging deleted message %d\n", msg->gen.uid );
  776. msg->gen.status = M_DEAD;
  777. msgapp = &msg->gen.next;
  778. } else if (msglist.ents[i].uid < msg->gen.uid) {
  779. /* this should not happen, actually */
  780. #if 0
  781. debug( "adding new message %d\n", msglist.ents[i].uid );
  782. maildir_app_msg( ctx, &msgapp, msglist.ents + i );
  783. #else
  784. debug( "ignoring new message %d\n", msglist.ents[i].uid );
  785. #endif
  786. i++;
  787. } else if (msglist.ents[i].uid > msg->gen.uid) {
  788. debug( "purging deleted message %d\n", msg->gen.uid );
  789. msg->gen.status = M_DEAD;
  790. msgapp = &msg->gen.next;
  791. } else {
  792. debug( "updating message %d\n", msg->gen.uid );
  793. msg->gen.status &= ~(M_FLAGS|M_RECENT);
  794. free( msg->base );
  795. maildir_init_msg( ctx, msg, msglist.ents + i );
  796. i++, msgapp = &msg->gen.next;
  797. }
  798. }
  799. maildir_free_scan( &msglist );
  800. return DRV_OK;
  801. }
  802. static int
  803. maildir_again( maildir_store_t *ctx, maildir_message_t *msg, const char *fn )
  804. {
  805. int ret;
  806. if (errno != ENOENT) {
  807. perror( fn );
  808. return DRV_BOX_BAD;
  809. }
  810. if ((ret = maildir_rescan( ctx )) != DRV_OK)
  811. return ret;
  812. return (msg->gen.status & M_DEAD) ? DRV_OK : DRV_MSG_BAD;
  813. }
  814. static int
  815. maildir_fetch_msg( store_t *gctx, message_t *gmsg, msg_data_t *data )
  816. {
  817. maildir_store_t *ctx = (maildir_store_t *)gctx;
  818. maildir_message_t *msg = (maildir_message_t *)gmsg;
  819. int fd, ret;
  820. struct stat st;
  821. char buf[_POSIX_PATH_MAX];
  822. for (;;) {
  823. nfsnprintf( buf, sizeof(buf), "%s/%s/%s", gctx->path, subdirs[gmsg->status & M_RECENT], msg->base );
  824. if ((fd = open( buf, O_RDONLY )) >= 0)
  825. break;
  826. if ((ret = maildir_again( ctx, msg, buf )) != DRV_OK)
  827. return ret;
  828. }
  829. fstat( fd, &st );
  830. data->crlf = 0;
  831. data->len = st.st_size;
  832. data->data = nfmalloc( data->len );
  833. if (read( fd, data->data, data->len ) != data->len) {
  834. perror( buf );
  835. close( fd );
  836. return DRV_MSG_BAD;
  837. }
  838. close( fd );
  839. if (!(gmsg->status & M_FLAGS))
  840. data->flags = maildir_parse_flags( msg->base );
  841. return DRV_OK;
  842. }
  843. static int
  844. maildir_make_flags( int flags, char *buf )
  845. {
  846. unsigned i, d;
  847. buf[0] = ':';
  848. buf[1] = '2';
  849. buf[2] = ',';
  850. for (d = 3, i = 0; i < as(Flags); i++)
  851. if (flags & (1 << i))
  852. buf[d++] = Flags[i];
  853. buf[d] = 0;
  854. return d;
  855. }
  856. static int
  857. maildir_store_msg( store_t *gctx, msg_data_t *data, int *uid )
  858. {
  859. maildir_store_t *ctx = (maildir_store_t *)gctx;
  860. const char *prefix, *box;
  861. int ret, fd, bl;
  862. char buf[_POSIX_PATH_MAX], nbuf[_POSIX_PATH_MAX], fbuf[NUM_FLAGS + 3], base[128];
  863. bl = nfsnprintf( base, sizeof(base), "%ld.%d_%d.%s", time( 0 ), Pid, ++MaildirCount, Hostname );
  864. if (uid) {
  865. #ifdef USE_DB
  866. if (ctx->db) {
  867. if ((ret = maildir_set_uid( ctx, base, uid )) != DRV_OK) {
  868. free( data->data );
  869. return ret;
  870. }
  871. } else
  872. #endif /* USE_DB */
  873. {
  874. if ((ret = maildir_uidval_lock( ctx )) != DRV_OK ||
  875. (ret = maildir_obtain_uid( ctx, uid )) != DRV_OK)
  876. return ret;
  877. maildir_uidval_unlock( ctx );
  878. nfsnprintf( base + bl, sizeof(base) - bl, ",U=%d", *uid );
  879. }
  880. prefix = gctx->path;
  881. box = "";
  882. } else {
  883. prefix = gctx->conf->path;
  884. box = gctx->conf->trash;
  885. }
  886. maildir_make_flags( data->flags, fbuf );
  887. nfsnprintf( buf, sizeof(buf), "%s%s/tmp/%s%s", prefix, box, base, fbuf );
  888. if ((fd = open( buf, O_WRONLY|O_CREAT|O_EXCL, 0600 )) < 0) {
  889. if (errno != ENOENT) {
  890. perror( buf );
  891. free( data->data );
  892. return DRV_BOX_BAD;
  893. }
  894. if ((ret = maildir_validate( gctx->conf->path, gctx->conf->trash, gctx->opts & OPEN_CREATE )) != DRV_OK) {
  895. free( data->data );
  896. return ret;
  897. }
  898. if ((fd = open( buf, O_WRONLY|O_CREAT|O_EXCL, 0600 )) < 0) {
  899. perror( buf );
  900. free( data->data );
  901. return DRV_BOX_BAD;
  902. }
  903. }
  904. strip_cr( data );
  905. ret = write( fd, data->data, data->len );
  906. free( data->data );
  907. if (ret != data->len) {
  908. if (ret < 0)
  909. perror( buf );
  910. else
  911. fprintf( stderr, "Maildir error: %s: partial write\n", buf );
  912. close( fd );
  913. return DRV_BOX_BAD;
  914. }
  915. close( fd );
  916. nfsnprintf( nbuf, sizeof(nbuf), "%s%s/%s/%s%s", prefix, box, subdirs[!(data->flags & F_SEEN)], base, fbuf );
  917. if (rename( buf, nbuf )) {
  918. perror( nbuf );
  919. return DRV_BOX_BAD;
  920. }
  921. if (uid)
  922. gctx->count++;
  923. return DRV_OK;
  924. }
  925. static int
  926. maildir_set_flags( store_t *gctx, message_t *gmsg, int uid, int add, int del )
  927. {
  928. maildir_store_t *ctx = (maildir_store_t *)gctx;
  929. maildir_message_t *msg = (maildir_message_t *)gmsg;
  930. char *s, *p;
  931. unsigned i;
  932. int j, ret, ol, fl, bbl, bl, tl;
  933. char buf[_POSIX_PATH_MAX], nbuf[_POSIX_PATH_MAX];
  934. (void) uid;
  935. bbl = nfsnprintf( buf, sizeof(buf), "%s/", gctx->path );
  936. for (;;) {
  937. bl = bbl + nfsnprintf( buf + bbl, sizeof(buf) - bbl, "%s/", subdirs[gmsg->status & M_RECENT] );
  938. ol = strlen( msg->base );
  939. if ((int)sizeof(buf) - bl < ol + 3 + NUM_FLAGS)
  940. oob();
  941. memcpy( buf + bl, msg->base, ol + 1 );
  942. memcpy( nbuf, buf, bl + ol + 1 );
  943. if ((s = strstr( nbuf + bl, ":2," ))) {
  944. s += 3;
  945. fl = ol - (s - (nbuf + bl));
  946. for (i = 0; i < as(Flags); i++) {
  947. if ((p = strchr( s, Flags[i] ))) {
  948. if (del & (1 << i)) {
  949. memcpy( p, p + 1, fl - (p - s) );
  950. fl--;
  951. }
  952. } else if (add & (1 << i)) {
  953. for (j = 0; j < fl && Flags[i] > s[j]; j++);
  954. fl++;
  955. memmove( s + j + 1, s + j, fl - j );
  956. s[j] = Flags[i];
  957. }
  958. }
  959. tl = ol + 3 + fl;
  960. } else {
  961. tl = ol + maildir_make_flags( msg->gen.flags, nbuf + bl + ol );
  962. }
  963. if (!rename( buf, nbuf ))
  964. break;
  965. if ((ret = maildir_again( ctx, msg, buf )) != DRV_OK)
  966. return ret;
  967. }
  968. free( msg->base );
  969. msg->base = nfmalloc( tl + 1 );
  970. memcpy( msg->base, nbuf + bl, tl + 1 );
  971. msg->gen.flags |= add;
  972. msg->gen.flags &= ~del;
  973. return DRV_OK;
  974. }
  975. #ifdef USE_DB
  976. static int
  977. maildir_purge_msg( maildir_store_t *ctx, const char *name )
  978. {
  979. int ret;
  980. make_key( &key, (char *)name );
  981. if ((ret = ctx->db->del( ctx->db, 0, &key, 0 ))) {
  982. ctx->db->err( ctx->db, ret, "Maildir error: db->del()" );
  983. ctx->db->close( ctx->db, 0 );
  984. ctx->db = 0;
  985. return DRV_BOX_BAD;
  986. }
  987. return DRV_OK;
  988. }
  989. #endif /* USE_DB */
  990. static int
  991. maildir_trash_msg( store_t *gctx, message_t *gmsg )
  992. {
  993. maildir_store_t *ctx = (maildir_store_t *)gctx;
  994. maildir_message_t *msg = (maildir_message_t *)gmsg;
  995. char *s;
  996. int ret;
  997. struct stat st;
  998. char buf[_POSIX_PATH_MAX], nbuf[_POSIX_PATH_MAX];
  999. for (;;) {
  1000. nfsnprintf( buf, sizeof(buf), "%s/%s/%s", gctx->path, subdirs[gmsg->status & M_RECENT], msg->base );
  1001. s = strstr( msg->base, ":2," );
  1002. nfsnprintf( nbuf, sizeof(nbuf), "%s%s/%s/%ld.%d_%d.%s%s", gctx->conf->path, gctx->conf->trash,
  1003. subdirs[gmsg->status & M_RECENT], time( 0 ), Pid, ++MaildirCount, Hostname, s ? s : "" );
  1004. if (!rename( buf, nbuf ))
  1005. break;
  1006. if (!stat( buf, &st )) {
  1007. if ((ret = maildir_validate( gctx->conf->path, gctx->conf->trash, 1 )) != DRV_OK)
  1008. return ret;
  1009. if (!rename( buf, nbuf ))
  1010. break;
  1011. if (errno != ENOENT) {
  1012. perror( nbuf );
  1013. return DRV_BOX_BAD;
  1014. }
  1015. }
  1016. if ((ret = maildir_again( ctx, msg, buf )) != DRV_OK)
  1017. return ret;
  1018. }
  1019. gmsg->status |= M_DEAD;
  1020. gctx->count--;
  1021. #ifdef USE_DB
  1022. if (ctx->db)
  1023. return maildir_purge_msg( ctx, msg->base );
  1024. #endif /* USE_DB */
  1025. return DRV_OK;
  1026. }
  1027. static int
  1028. maildir_close( store_t *gctx )
  1029. {
  1030. #ifdef USE_DB
  1031. maildir_store_t *ctx = (maildir_store_t *)gctx;
  1032. #endif /* USE_DB */
  1033. message_t *msg;
  1034. int basel, retry, ret;
  1035. char buf[_POSIX_PATH_MAX];
  1036. for (;;) {
  1037. retry = 0;
  1038. basel = nfsnprintf( buf, sizeof(buf), "%s/", gctx->path );
  1039. for (msg = gctx->msgs; msg; msg = msg->next)
  1040. if (!(msg->status & M_DEAD) && (msg->flags & F_DELETED)) {
  1041. nfsnprintf( buf + basel, sizeof(buf) - basel, "%s/%s", subdirs[msg->status & M_RECENT], ((maildir_message_t *)msg)->base );
  1042. if (unlink( buf )) {
  1043. if (errno == ENOENT)
  1044. retry = 1;
  1045. else
  1046. perror( buf );
  1047. } else {
  1048. msg->status |= M_DEAD;
  1049. gctx->count--;
  1050. #ifdef USE_DB
  1051. if (ctx->db && (ret = maildir_purge_msg( ctx, ((maildir_message_t *)msg)->base )) != DRV_OK)
  1052. return ret;
  1053. #endif /* USE_DB */
  1054. }
  1055. }
  1056. if (!retry)
  1057. return DRV_OK;
  1058. if ((ret = maildir_rescan( (maildir_store_t *)gctx )) != DRV_OK)
  1059. return ret;
  1060. }
  1061. }
  1062. static int
  1063. maildir_check( store_t *gctx )
  1064. {
  1065. (void) gctx;
  1066. return DRV_OK;
  1067. }
  1068. static int
  1069. maildir_parse_store( conffile_t *cfg, store_conf_t **storep, int *err )
  1070. {
  1071. maildir_store_conf_t *store;
  1072. if (strcasecmp( "MaildirStore", cfg->cmd ))
  1073. return 0;
  1074. store = nfcalloc( sizeof(*store) );
  1075. store->gen.driver = &maildir_driver;
  1076. store->gen.name = nfstrdup( cfg->val );
  1077. while (getcline( cfg ) && cfg->cmd)
  1078. if (!strcasecmp( "Inbox", cfg->cmd ))
  1079. store->inbox = expand_strdup( cfg->val );
  1080. else if (!strcasecmp( "Path", cfg->cmd ))
  1081. store->gen.path = expand_strdup( cfg->val );
  1082. #ifdef USE_DB
  1083. else if (!strcasecmp( "AltMap", cfg->cmd ))
  1084. store->alt_map = parse_bool( cfg );
  1085. #endif /* USE_DB */
  1086. else
  1087. parse_generic_store( &store->gen, cfg, err );
  1088. if (!store->inbox)
  1089. store->inbox = expand_strdup( "~/Maildir" );
  1090. *storep = &store->gen;
  1091. return 1;
  1092. }
  1093. struct driver maildir_driver = {
  1094. maildir_parse_store,
  1095. maildir_open_store,
  1096. maildir_close_store,
  1097. maildir_list,
  1098. maildir_prepare,
  1099. maildir_select,
  1100. maildir_fetch_msg,
  1101. maildir_store_msg,
  1102. maildir_set_flags,
  1103. maildir_trash_msg,
  1104. maildir_check,
  1105. maildir_close
  1106. };