Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / EvolutionMailDriver / MailCrawler.cs
blobe434606351b5e19f877f37a52fe8c79664e4a7fc
2 //
3 // MailCrawler.cs
4 //
5 // Copyright (C) 2004 Novell, Inc.
6 //
7 //
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a
10 // copy of this software and associated documentation files (the "Software"),
11 // to deal in the Software without restriction, including without limitation
12 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 // and/or sell copies of the Software, and to permit persons to whom the
14 // Software is furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
28 using System;
29 using System.Collections;
30 using System.IO;
32 using Beagle.Util;
33 using Beagle.Daemon;
35 namespace Beagle.Daemon.EvolutionMailDriver {
37 class MailCrawler {
38 ArrayList roots = new ArrayList ();
40 Hashtable last_write_time_cache = new Hashtable ();
41 ArrayList summaries = new ArrayList ();
42 ArrayList mboxes = new ArrayList ();
44 public MailCrawler (params string[] paths)
46 foreach (string p in paths) {
47 if (Directory.Exists (p))
48 roots.Add (p);
52 private bool FileIsInteresting (FileInfo file)
54 DateTime cached_time = new DateTime ();
55 if (last_write_time_cache.Contains (file.FullName))
56 cached_time = (DateTime) last_write_time_cache [file.FullName];
58 last_write_time_cache [file.FullName] = file.LastWriteTime;
60 return cached_time < file.LastWriteTime;
63 public void Crawl ()
65 summaries.Clear ();
66 mboxes.Clear ();
68 Queue pending = new Queue ();
70 foreach (string root in roots)
71 pending.Enqueue (root);
73 while (pending.Count > 0) {
75 string dir = (string) pending.Dequeue ();
77 foreach (string subdir in DirectoryWalker.GetDirectories (dir))
78 pending.Enqueue (subdir);
80 foreach (FileInfo file in DirectoryWalker.GetFileInfos (dir)) {
81 if (file.Name == "summary") {
82 if (FileIsInteresting (file))
83 summaries.Add (file);
84 } else if (file.Extension == ".ev-summary") {
85 string mbox_name = Path.Combine (file.DirectoryName,
86 Path.GetFileNameWithoutExtension (file.Name));
87 FileInfo mbox_file = new FileInfo (mbox_name);
88 if (FileIsInteresting (mbox_file))
89 mboxes.Add (mbox_file);
95 public ICollection Summaries {
96 get { return summaries; }
99 public ICollection Mboxes {
100 get { return mboxes; }