static void mailbox_delete_files(const char *path)
{
    DIR *dirp;
    struct dirent *f;
    char buf[MAX_MAILBOX_PATH+1];
    char *tail;

    strlcpy(buf, path, sizeof(buf));

    if (strlen(buf) >= sizeof(buf) - 2) {
        xsyslog(LOG_ERR, "IOERROR: path too long",
                         "buf=<%s>",
                         buf);
        fatal("path too long", EX_OSFILE);
    }

    tail = buf + strlen(buf);
    *tail++ = '/';
    *tail = '\0';
    dirp = opendir(path);
    if (dirp) {
        while ((f = readdir(dirp))!=NULL) {
            if (f->d_name[0] == '.'
                && (f->d_name[1] == '\0'
                    || (f->d_name[1] == '.' &&
                        f->d_name[2] == '\0'))) {
                /* readdir() can return "." or "..", and I got a bug report
                   that SCO might blow the file system to smithereens if we
                   unlink("..").  Let's not do that. */
                continue;
            }

            if(strlen(buf) + strlen(f->d_name) >= sizeof(buf)) {
                xsyslog(LOG_ERR, "IOERROR: path too long",
                                 "buf=<%s> d_name=<%s>",
                                 buf, f->d_name);
                fatal("Path too long", EX_OSFILE);
            }
            strcpy(tail, f->d_name);
            unlink(buf);
            *tail = '\0';
        }
        closedir(dirp);
    }
}
static void mailbox_delete_files(const char *path)
{
    DIR *dirp;
    struct dirent *f;
    char buf[MAX_MAILBOX_PATH+1];
    char *tail;

    strlcpy(buf, path, sizeof(buf));

    if (strlen(buf) >= sizeof(buf) - 2) {
        xsyslog(LOG_ERR, "IOERROR: path too long",
                         "buf=<%s>",
                         buf);
        fatal("path too long", EX_OSFILE);
    }

    tail = buf + strlen(buf);
    *tail++ = '/';
    *tail = '\0';
    dirp = opendir(path);
    if (dirp) {
        while ((f = readdir(dirp))!=NULL) {
            if (f->d_name[0] == '.'
                && (f->d_name[1] == '\0'
                    || (f->d_name[1] == '.' &&
                        f->d_name[2] == '\0'))) {
                 
                continue;
            }

            if(strlen(buf) + strlen(f->d_name) >= sizeof(buf)) {
                xsyslog(LOG_ERR, "IOERROR: path too long",
                                 "buf=<%s> d_name=<%s>",
                                 buf, f->d_name);
                fatal("Path too long", EX_OSFILE);
            }
            strcpy(tail, f->d_name);
            unlink(buf);
            *tail = '\0';
        }
        closedir(dirp);
    }
}