1
// ThunderbirdContactItemSource.cs
3
// GNOME Do is the legal property of its developers.
4
// Please refer to the COPYRIGHT file distributed with this
5
// source distribution.
7
// This program is free software: you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation, either version 3 of the License, or
10
// (at your option) any later version.
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with this program. If not, see <http://www.gnu.org/licenses/>.
24
using System.Collections;
25
using System.Collections.Generic;
33
public class ThunderbirdContactItemSource : IItemSource
36
const string BeginProfileName = "Path=";
37
const string BeginDefaultProfile = "Name=default";
41
public ThunderbirdContactItemSource ()
43
contacts = new List<IItem> ();
47
public Type[] SupportedItemTypes {
55
public string Name { get { return "Thunderbird Contacts"; } }
56
public string Description { get { return "Thunderbird Contacts"; } }
57
public string Icon { get { return "thunderbird"; } }
59
public void UpdateItems ()
63
} catch (Exception e) {
64
Console.WriteLine ("Cannot index Thunderbird contacts because a {0} was thrown: {1}", e.GetType (), e.Message);
69
public ICollection<IItem> Items {
70
get { return contacts; }
73
public ICollection<IItem> ChildrenOfItem (IItem item)
80
MorkDatabase database;
83
database = new MorkDatabase (GetThunderbirdAddressBookFilePath ());
85
database.EnumNamespace = "ns:addrbk:db:row:scope:card:all";
87
foreach (string id in database) {
88
Hashtable contact_row;
91
contact_row = database.Compile (id, database.EnumNamespace);
92
contact = CreateThunderbirdContactItem (contact_row);
94
contacts.Add (contact);
98
ContactItem CreateThunderbirdContactItem (Hashtable row) {
102
contact = new ContactItem ();
104
// foreach (object o in row.Keys)
105
// Console.WriteLine ("\t{0} --> {1}", o, row[o]);
107
// I think this will detect deleted contacts... Hmm...
108
if (row["table"] == null || row["table"] as string == "C6")
112
name = row["DisplayName"] as string;
113
if (name == null || name == string.Empty)
114
name = string.Format ("{0} {1}", row["FirstName"], row["LastName"]);
118
email = row["PrimaryEmail"] as string;
119
if (email != null && email != string.Empty)
120
contact.Emails.Add (email);
122
ContactItemStore.SynchronizeContactWithStore (ref contact);
126
string GetThunderbirdAddressBookFilePath ()
128
string home, path, profile;
132
home = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
133
path = System.IO.Path.Combine (home, ".mozilla-thunderbird/profiles.ini");
135
reader = System.IO.File.OpenText (path);
140
bool got_default = false;
141
for (string line = reader.ReadLine (); line != null; line = reader.ReadLine ()) {
142
if (got_default && line.StartsWith (BeginProfileName)) {
144
line = line.Substring (BeginProfileName.Length);
148
else if (line.StartsWith (BeginDefaultProfile)) {
154
if (profile == null) {
157
path = System.IO.Path.Combine (home, ".mozilla-thunderbird");
158
path = System.IO.Path.Combine (path, profile);
159
path = System.IO.Path.Combine (path, "abook.mab");