2 // Contact.cs: Adds address book 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
.AddressBook
, "Address book support", true)]
42 public class ContactIndexableGenerator
: ThunderbirdIndexableGenerator
{
44 public ContactIndexableGenerator (ThunderbirdIndexer indexer
, TB
.Account account
, string abook_file
)
45 : base (indexer
, account
, abook_file
)
49 public override bool HasNextIndexable ()
52 if (DbEnumerator
== null || !DbEnumerator
.MoveNext ()) {
54 indexer
.NotificationEvent
-= OnNotification
;
55 indexer
.ChildComplete ();
58 } while ((DbEnumerator
.Current
as TB
.Contact
).GetString ("table") != "BF" ||
59 IsUpToDate ((DbEnumerator
.Current
as TB
.Contact
).Uri
));
64 public override Indexable
GetNextIndexable ()
66 return ContactToIndexable (DbEnumerator
.Current
as TB
.Contact
);
69 public override void LoadDatabase ()
72 db
= new TB
.Database (account
, DbFile
);
74 } catch (Exception e
) {
75 Logger
.Log
.Warn (e
, "Failed to load {0}:", DbFile
);
80 Logger
.Log
.Debug ("Empty file {0}; skipping", DbFile
);
84 Logger
.Log
.Info ("Indexing address book containing {0} contact(s) ({1})", db
.Count
, RelativePath
);
87 private Indexable
ContactToIndexable (TB
.Contact contact
)
89 Indexable indexable
= NewIndexable (contact
.Uri
, DateTime
.Now
.ToUniversalTime (), "Contact");
91 indexable
.AddProperty (Property
.New ("fixme:FirstName", contact
.GetString ("FirstName")));
92 indexable
.AddProperty (Property
.New ("fixme:LastName", contact
.GetString ("LastName")));
93 indexable
.AddProperty (Property
.New ("fixme:DisplayName", contact
.GetString ("LastName")));
94 indexable
.AddProperty (Property
.New ("fixme:NickName", contact
.GetString ("NickName")));
95 indexable
.AddProperty (Property
.NewKeyword ("fixme:PrimaryEmail", contact
.GetString ("PrimaryEmail")));
96 indexable
.AddProperty (Property
.NewKeyword ("fixme:SecondEmail", contact
.GetString ("SecondEmail")));
97 indexable
.AddProperty (Property
.New ("fixme:WorkPhone", contact
.GetString ("WorkPhone")));
98 indexable
.AddProperty (Property
.New ("fixme:FaxNumber", contact
.GetString ("FaxNumber")));
99 indexable
.AddProperty (Property
.New ("fixme:HomePhone", contact
.GetString ("HomePhone")));
100 indexable
.AddProperty (Property
.New ("fixme:PagerNumber", contact
.GetString ("PagerNumber")));
101 indexable
.AddProperty (Property
.New ("fixme:CellularNumber", contact
.GetString ("CellularNumber")));
102 indexable
.AddProperty (Property
.New ("fixme:HomeAddress", contact
.GetString ("HomeAddress")));
103 indexable
.AddProperty (Property
.New ("fixme:HomeAddress2", contact
.GetString ("HomeAddress2")));
104 indexable
.AddProperty (Property
.New ("fixme:HomeCity", contact
.GetString ("HomeCity")));
105 indexable
.AddProperty (Property
.New ("fixme:HomeState", contact
.GetString ("HomeState")));
106 indexable
.AddProperty (Property
.New ("fixme:HomeZipCode", contact
.GetString("HomeZipCode")));
107 indexable
.AddProperty (Property
.New ("fixme:HomeCountry", contact
.GetString ("HomeCountry")));
108 indexable
.AddProperty (Property
.New ("fixme:WorkAddress", contact
.GetString ("WorkAddress")));
109 indexable
.AddProperty (Property
.New ("fixme:WorkAddress2", contact
.GetString ("WorkAddress2")));
110 indexable
.AddProperty (Property
.New ("fixme:WorkCity", contact
.GetString ("WorkCity")));
111 indexable
.AddProperty (Property
.New ("fixme:WorkState", contact
.GetString ("WorkState")));
112 indexable
.AddProperty (Property
.New ("fixme:WorkZipCode", contact
.GetString ("WorkZipCode")));
113 indexable
.AddProperty (Property
.New ("fixme:WorkCountry", contact
.GetString ("WorkCountry")));
114 indexable
.AddProperty (Property
.New ("fixme:JobTitle", contact
.GetString ("JobTitle")));
115 indexable
.AddProperty (Property
.New ("fixme:Department", contact
.GetString ("Department")));
116 indexable
.AddProperty (Property
.New ("fixme:Company", contact
.GetString ("Company")));
117 indexable
.AddProperty (Property
.New ("fixme:_AimScreenName", contact
.GetString ("_AimScreenName")));
118 indexable
.AddProperty (Property
.New ("fixme:FamilyName", contact
.GetString ("FamilyName")));
119 indexable
.AddProperty (Property
.NewKeyword ("fixme:WebPage1", contact
.GetString ("WebPage1")));
120 indexable
.AddProperty (Property
.NewKeyword ("fixme:WebPage2", contact
.GetString ("WebPage2")));
121 indexable
.AddProperty (Property
.New ("fixme:BirthYear", contact
.GetString ("BirthYear")));
122 indexable
.AddProperty (Property
.New ("fixme:BirthMonth", contact
.GetString ("BirthMonth")));
123 indexable
.AddProperty (Property
.New ("fixme:BirthDay", contact
.GetString ("BirthDay")));
124 indexable
.AddProperty (Property
.New ("fixme:Custom1", contact
.GetString ("Custom1")));
125 indexable
.AddProperty (Property
.New ("fixme:Custom2", contact
.GetString ("Custom2")));
126 indexable
.AddProperty (Property
.New ("fixme:Custom3", contact
.GetString ("Custom3")));
127 indexable
.AddProperty (Property
.New ("fixme:Custom4", contact
.GetString ("Custom4")));
128 indexable
.AddProperty (Property
.New ("fixme:Notes", contact
.GetString ("Notes")));
129 indexable
.AddProperty (Property
.New ("fixme:PreferMailFormat", contact
.GetString ("PreferMailFormat")));
131 indexable
.AddProperty (Property
.NewKeyword ("fixme:Email", contact
.GetString ("PrimaryEmail")));
132 indexable
.AddProperty (Property
.New ("fixme:Name", contact
.GetString ("DisplayName")));
137 // Why? Because it's very likely that the user will sometimes change contact details. Current IsUpToDate
138 // (in ThunderbirdIndexableGenerator-class) only checks the "fullyIndexed" property and when the contact
139 // was indexed, thus if the user changes an email address it won't be updated until beagle is restarted.
140 // By always returning false here, we make sure that beagle always re-index contacts when something
141 // happens. It's a really fast and not a very cpu intensive task, so it doesn't really matter.
142 protected new bool IsUpToDate (Uri uri
)
144 // Remove this uri from the cache
145 if (stored_cache
!= null)
146 stored_cache
.Remove (uri
.ToString ());