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;
31
namespace Do.Addins.Thunderbird
34
public class ThunderbirdContactItemSource : ItemSource
37
const string BeginProfileName = "Path=";
38
const string BeginDefaultProfile = "Name=default";
42
public ThunderbirdContactItemSource ()
44
contacts = new List<Item> ();
48
public override IEnumerable<Type> SupportedItemTypes {
56
public override string Name { get { return "Thunderbird Contacts"; } }
57
public override string Description { get { return "Thunderbird Contacts"; } }
58
public override string Icon { get { return "thunderbird"; } }
60
public override void UpdateItems ()
64
} catch (Exception e) {
65
Console.Error.WriteLine ("Cannot index Thunderbird contacts because a {0} was thrown: {1}", e.GetType (), e.Message);
70
public override IEnumerable<Item> Items {
71
get { return contacts; }
74
public override IEnumerable<Item> ChildrenOfItem (Item item)
81
MorkDatabase database;
84
database = new MorkDatabase (GetThunderbirdAddressBookFilePath ());
86
database.EnumNamespace = "ns:addrbk:db:row:scope:card:all";
88
foreach (string id in database) {
89
Hashtable contact_row;
92
contact_row = database.Compile (id, database.EnumNamespace);
93
contact = CreateThunderbirdContactItem (contact_row);
95
contacts.Add (contact);
99
ContactItem CreateThunderbirdContactItem (Hashtable row) {
103
// foreach (object o in row.Keys)
104
// Console.WriteLine ("\t{0} --> {1}", o, row[o]);
106
// I think this will detect deleted contacts... Hmm...
107
if (row["table"] == null || row["table"] as string == "C6")
111
name = row["DisplayName"] as string;
112
if (name == null || name == string.Empty)
113
name = string.Format ("{0} {1}", row["FirstName"], row["LastName"]);
114
contact = ContactItem.Create (name);
117
email = row["PrimaryEmail"] as string;
118
if (email != null && email != string.Empty)
119
contact["email"] = email;
124
string GetThunderbirdAddressBookFilePath ()
126
string home, path, profile;
130
home = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
131
path = System.IO.Path.Combine (home, ".mozilla-thunderbird/profiles.ini");
133
reader = System.IO.File.OpenText (path);
138
bool got_default = false;
139
for (string line = reader.ReadLine (); line != null; line = reader.ReadLine ()) {
140
if (got_default && line.StartsWith (BeginProfileName)) {
142
line = line.Substring (BeginProfileName.Length);
146
else if (line.StartsWith (BeginDefaultProfile)) {
152
if (profile == null) {
155
path = System.IO.Path.Combine (home, ".mozilla-thunderbird");
156
path = System.IO.Path.Combine (path, profile);
157
path = System.IO.Path.Combine (path, "abook.mab");