2 // MoveMail: Adds Unix Mailspool (MoveMail) indexing support to the Thunderbird backend
4 // Copyright (C) 2006 Pierre Östlund
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 using System
.Collections
;
30 using System
.Reflection
;
31 using System
.Text
.RegularExpressions
;
35 using TB
= Beagle
.Util
.Thunderbird
;
39 namespace Beagle
.Daemon
.ThunderbirdQueryable
{
41 [ThunderbirdIndexableGenerator (TB
.AccountType
.MoveMail
, "Movemail Support", false)]
42 public class MoveMailIndexableGenerator
: ThunderbirdIndexableGenerator
{
44 public MoveMailIndexableGenerator (ThunderbirdIndexer indexer
, TB
.Account account
, string file
)
45 : base (indexer
, account
, file
)
49 public override bool HasNextIndexable ()
52 if (DbEnumerator
== null || !DbEnumerator
.MoveNext ()) {
54 indexer
.NotificationEvent
-= OnNotification
;
55 indexer
.ChildComplete ();
58 } while (IsUpToDate ((DbEnumerator
.Current
as TB
.MoveMail
).Uri
));
63 public override Indexable
GetNextIndexable ()
65 TB
.MoveMail message
= DbEnumerator
.Current
as TB
.MoveMail
;
67 // If status is different, than something happend when loading this mail and we dont'
68 // want to change it's status.
69 if (message
.GetObject ("FullIndex") == null)
70 message
.SetObject ("FullIndex", (object) FullIndex
);
72 return MoveMailToIndexable (message
);
75 public override void LoadDatabase ()
78 db
= new TB
.Database (account
, DbFile
);
80 } catch (Exception e
) {
81 Logger
.Log
.Warn (e
, "Failed to load {0}", DbFile
);
86 Logger
.Log
.Debug ("Empty file {0}; skipping", DbFile
);
90 FullIndex
= (Thunderbird
.IsFullyIndexable (DbFile
) ? true : false);
91 Logger
.Log
.Info ("Indexing {0} Movemails ({1})", db
.Count
, RelativePath
);
94 // FIXME: This need some more info
95 private Indexable
MoveMailToIndexable (TB
.MoveMail mail
)
99 indexable
= NewIndexable (mail
.Uri
, DateTime
.UtcNow
, "MailMessage");
100 indexable
.MimeType
= "message/rfc822";
102 string subject
= GMime
.Utils
.HeaderDecodePhrase (mail
.GetString ("subject"));
103 indexable
.AddProperty (Property
.New ("dc:title", subject
));