5 // Copyright (C) 2004 Novell, Inc.
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.
29 using System
.Collections
;
35 namespace Beagle
.Daemon
.EvolutionMailDriver
{
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
))
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
;
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
))
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; }