Пример #1
0
        /**
         * To check if the path represents a kmail directory:
         * for all directories and files named "ddd" and not starting with a '.',
         * there should be matching index file named .ddd.index
         * Ignore zero length files; zero-length mbox files might not have index files.
         */
        private bool GuessLocalFolder(string path, bool verbose)
        {
            if (!Directory.Exists(path))
            {
                return(false);
            }

            if (verbose)
            {
                Log.Debug("Checking if {0} is kmail local mail directory ?", path);
            }

            bool no_content = true;

            foreach (string entry in DirectoryWalker.GetItemNames(path, null))
            {
                if (entry.StartsWith("."))
                {
                    continue;
                }

                // Ignore zero size mbox files
                string fullpath = Path.Combine(path, entry);
                if (File.Exists(fullpath))
                {
                    FileInfo fi = new FileInfo(fullpath);
                    if (fi.Length == 0)
                    {
                        continue;
                    }
                }

                // index-file name is of pattern .name.index
                string indexfile = Path.Combine(path, "." + entry + ".index");
                if (!File.Exists(indexfile))
                {
                    if (verbose)
                    {
                        Log.Warn(String.Format(
                                     "KMail backend: No index file for {0}." +
                                     "Ignoring {1}, probably not a kmail directory.",
                                     fullpath, path));
                    }
                    return(false);
                }
                else
                {
                    no_content = false;
                }
            }

            return(!no_content);
        }