mbox-list.c revision 450c93a252fea6c0ceb9353af20c2d22ab62d717
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher/* Copyright (C) 2002 Timo Sirainen */
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher#include "subscription-file/subscription-file.h"
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallaghertypedef struct {
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagherstatic int mbox_find_path(MailStorage *storage, ImapMatchGlob *glob,
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher const char *relative_dir, int *found_inbox)
2bdadc5274df42738b97045cd01cd63d3651daf9Lukas Slebodnik char fulldir[1024], path[1024], fullpath[1024];
dbea04f585a30d001b574317c068cd03a4fa332bJakub Hrozek /* skip all hidden files */
dbea04f585a30d001b574317c068cd03a4fa332bJakub Hrozek /* skip all .lock files */
fa0938a6e3cb928602633c3da0b909deb269369dLukas Slebodnik if (len > 5 && strcmp(fname+len-5, ".lock") == 0)
dbea04f585a30d001b574317c068cd03a4fa332bJakub Hrozek /* check the mask */
dbea04f585a30d001b574317c068cd03a4fa332bJakub Hrozek /* see if it's a directory */
dbea04f585a30d001b574317c068cd03a4fa332bJakub Hrozek i_snprintf(fullpath, sizeof(fullpath), "%s/%s", dir, fname);
dbea04f585a30d001b574317c068cd03a4fa332bJakub Hrozek continue; /* just deleted, ignore */
dbea04f585a30d001b574317c068cd03a4fa332bJakub Hrozek mail_storage_set_critical(storage, "stat(%s) failed: "
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher /* subdirectory, scan it too */
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher func(storage, listpath, MAILBOX_NOSELECT, context);
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher } else if (match > 0) {
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher func(storage, listpath, MAILBOX_NOINFERIORS, context);
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagherstatic const char *mask_get_dir(const char *mask)
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher const char *p, *last_dir;
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher for (p = mask; *p != '\0' && *p != '%' && *p != '*'; p++) {
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher if (*p == '/')
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher return last_dir != NULL ? t_strdup_until(mask, last_dir) : NULL;
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagherint mbox_find_mailboxes(MailStorage *storage, const char *mask,
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher /* check that we're not trying to do any "../../" lists */
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher mail_storage_set_error(storage, "Invalid mask");
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher /* if we're matching only subdirectories, don't bother scanning the
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher parent directories */
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher if (!mbox_find_path(storage, glob, func, context,
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher if (!found_inbox && relative_dir == NULL &&
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher /* INBOX always exists, even if the file doesn't. */
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher func(storage, "INBOX", MAILBOX_UNMARKED | MAILBOX_NOINFERIORS,
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagherstatic int mbox_subs_func(MailStorage *storage, const char *name,
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher /* see if the mailbox exists, don't bother with the marked flags */
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher /* inbox always exists */
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher i_snprintf(path, sizeof(path), "%s/%s", storage->dir, name);
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher flags = stat(path, &st) == 0 && !S_ISDIR(st.st_mode) ?
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher ctx->func(storage, name, flags, ctx->context);
2b4332767d299263a288e0a74bbfbc9de674de95Jakub Hrozekint mbox_find_subscribed(MailStorage *storage, const char *mask,
2b4332767d299263a288e0a74bbfbc9de674de95Jakub Hrozek if (subsfile_foreach(storage, mask, mbox_subs_func, &ctx) <= 0)
return FALSE;
return TRUE;