Beispiel #1
0
		/**
		 * Recursively traverse the files and dirctories under mail_root
		 * to find files that need to be indexed, directories that
		 * need to be watched for changes
		 */
		public void Crawl ()
		{
			if (!Directory.Exists (mail_root))
				return;

			mail_directories.Clear ();
			folder_directories.Clear ();
			mbox_files.Clear();

			Queue pending = new Queue ();
			pending.Enqueue (mail_root);
			folder_directories.Add (mail_root);
			// add inotify watch to root folder
			if (Inotify.Enabled)
				Inotify.Subscribe (mail_root, OnInotifyEvent,
					Inotify.EventType.Create
					| Inotify.EventType.Delete
					| Inotify.EventType.MovedFrom
					| Inotify.EventType.MovedTo
					| Inotify.EventType.Modify);

			while (pending.Count > 0) {

				string dir = (string) pending.Dequeue ();
				Logger.Log.Debug ("Searching for mbox and maildirs in " + dir);

				foreach (FileInfo fi in DirectoryWalker.GetFileInfos (dir)) {
					if (!fi.Name.EndsWith (".index"))
						continue;
					string indexFile = fi.Name;
					string mailFolderName = 
						indexFile.Substring (1, indexFile.LastIndexOf (".index")-1);
					string mailFolder = Path.Combine (dir, mailFolderName);
					if (IgnoreFolder (mailFolder))
						continue;
					if (Directory.Exists (mailFolder)) {
						mail_directories.Add (mailFolder);
						if (Inotify.Enabled)
							Watch (mailFolder);
					} else if (File.Exists (mailFolder)) {
						mbox_files.Add (mailFolder);
					}
					// if there is a directory with name .<mailFolderName>.directory
					// then it contains sub-folders
					string subFolder = 
						Path.Combine (dir, "." + mailFolderName + ".directory");
					if (Directory.Exists (subFolder)) {
						pending.Enqueue (subFolder);
						folder_directories.Add (subFolder);
						if (Inotify.Enabled)
							Inotify.Subscribe (subFolder, OnInotifyEvent,
								Inotify.EventType.Create
								| Inotify.EventType.Delete
								| Inotify.EventType.MovedFrom
								| Inotify.EventType.MovedTo
								| Inotify.EventType.Modify);
					}
				}
			}	

			// copy the contents as mail_directories, mbox_files might change due to async events
			ArrayList _mail_directories = new ArrayList (mail_directories);
			ArrayList _mbox_files = new ArrayList (mbox_files);
			
			if (queryable.ThisScheduler.ContainsByTag (mail_root)) {
				Logger.Log.Debug ("Not adding task for already running task: {0}", mail_root);
				return;
			} else {
				KMaildirIndexableGenerator generator = new KMaildirIndexableGenerator (this, _mail_directories);
				AddIIndexableTask (generator, mail_root);
			}

			foreach (string mbox_file in _mbox_files) {
				IndexMbox (mbox_file, true);
			}
		}
Beispiel #2
0
        /**
         * Recursively traverse the files and dirctories under mail_root
         * to find files that need to be indexed, directories that
         * need to be watched for changes
         */
        public void Crawl()
        {
            if (!Directory.Exists(mail_root))
            {
                return;
            }

            mail_directories.Clear();
            folder_directories.Clear();
            mbox_files.Clear();

            Queue pending = new Queue();

            pending.Enqueue(mail_root);
            folder_directories.Add(mail_root);
            // add inotify watch to root folder
            if (Inotify.Enabled)
            {
                Inotify.Subscribe(mail_root, OnInotifyEvent,
                                  Inotify.EventType.Create
                                  | Inotify.EventType.Delete
                                  | Inotify.EventType.MovedFrom
                                  | Inotify.EventType.MovedTo
                                  | Inotify.EventType.Modify);
            }

            while (pending.Count > 0)
            {
                string dir = (string)pending.Dequeue();
                Logger.Log.Debug("Searching for mbox and maildirs in " + dir);

                foreach (FileInfo fi in DirectoryWalker.GetFileInfos(dir))
                {
                    if (!fi.Name.EndsWith(".index"))
                    {
                        continue;
                    }
                    string indexFile      = fi.Name;
                    string mailFolderName =
                        indexFile.Substring(1, indexFile.LastIndexOf(".index") - 1);
                    string mailFolder = Path.Combine(dir, mailFolderName);
                    if (IgnoreFolder(mailFolder))
                    {
                        continue;
                    }
                    if (Directory.Exists(mailFolder))
                    {
                        mail_directories.Add(mailFolder);
                        if (Inotify.Enabled)
                        {
                            Watch(mailFolder);
                        }
                    }
                    else if (File.Exists(mailFolder))
                    {
                        mbox_files.Add(mailFolder);
                    }
                    // if there is a directory with name .<mailFolderName>.directory
                    // then it contains sub-folders
                    string subFolder =
                        Path.Combine(dir, "." + mailFolderName + ".directory");
                    if (Directory.Exists(subFolder))
                    {
                        pending.Enqueue(subFolder);
                        folder_directories.Add(subFolder);
                        if (Inotify.Enabled)
                        {
                            Inotify.Subscribe(subFolder, OnInotifyEvent,
                                              Inotify.EventType.Create
                                              | Inotify.EventType.Delete
                                              | Inotify.EventType.MovedFrom
                                              | Inotify.EventType.MovedTo
                                              | Inotify.EventType.Modify);
                        }
                    }
                }
            }

            // copy the contents as mail_directories, mbox_files might change due to async events
            ArrayList _mail_directories = new ArrayList(mail_directories);
            ArrayList _mbox_files       = new ArrayList(mbox_files);

            if (queryable.ThisScheduler.ContainsByTag(mail_root))
            {
                Logger.Log.Debug("Not adding task for already running task: {0}", mail_root);
                return;
            }
            else
            {
                KMaildirIndexableGenerator generator = new KMaildirIndexableGenerator(this, _mail_directories);
                AddIIndexableTask(generator, mail_root);
            }

            foreach (string mbox_file in _mbox_files)
            {
                IndexMbox(mbox_file, true);
            }
        }