1
// GmailContactItemSource.boo
3
// GNOME Do is the legal property of its developers. Please refer to the
4
// 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
import System.Collections.Generic
29
class GmailContactItemSource (IItemSource):
31
static final BeginName = "FN:"
32
static final BeginEmail = "EMAIL;TYPE=INTERNET:"
33
static final EndVCard = "END:VCARD"
35
items as List[of IItem]
38
items = List[of IItem] ()
41
get: return "Gmail Contacts"
44
get: return "Indexes your Gmail contacts."
47
get: return "stock_person"
50
get: return (typeof (ContactItem),)
55
def ChildrenOfItem (parent as IItem):
60
for contact in LoadContacts ():
65
file = Paths.Combine (Paths.ApplicationData, "contacts.vcf")
67
using reader = File.OpenText (file):
68
while line = reader.ReadLine ():
69
# Read email and name fields in current vcard:
70
while line and not line.StartsWith (EndVCard):
71
if line.StartsWith (BeginName):
72
name = line [BeginName.Length:]
73
elif line.StartsWith (BeginEmail):
74
email = line [BeginEmail.Length:]
75
line = reader.ReadLine ()
76
# Skip contact if no email found
77
if not email: continue
78
# Create and save the contact.
80
contact = ContactItem.Create (name)
83
contact = ContactItem.CreateWithEmail (email)
86
contact ["email.gmail"] = email
88
Console.Error.WriteLine (
89
"Could not read Gmail contacts file ${file}: $ {e.Message}")