[kupfer] thunderbird: load all adress books founded in thunderbird profile dir



commit 0b8a77cd6d5f2c7cce80cfe1ddabe19d1e0f9668
Author: Karol BÄ?dkowski <karol bedkowsk+gh gmail com>
Date:   Mon Jan 4 21:02:13 2010 +0100

    thunderbird: load all adress books founded in thunderbird profile dir

 kupfer/plugin/thunderbird.py         |    4 +-
 kupfer/plugin/thunderbird_support.py |   38 +++++++++++++++------------------
 2 files changed, 19 insertions(+), 23 deletions(-)
---
diff --git a/kupfer/plugin/thunderbird.py b/kupfer/plugin/thunderbird.py
index 9d4a777..f245912 100644
--- a/kupfer/plugin/thunderbird.py
+++ b/kupfer/plugin/thunderbird.py
@@ -1,4 +1,4 @@
-# -*- coding: UTF-8 -*-
+# -*- coding: utf-8 -*-
 
 from __future__ import with_statement
 
@@ -106,7 +106,7 @@ class ContactsSource(AppLeafContentMixin, Source, FilesystemWatchMixin):
 		self.monitor_token = self.monitor_directories(abook_dir)
 
 	def monitor_include_file(self, gfile):
-		return gfile and gfile.get_basename() == support.ABOOK_FILE
+		return gfile and gfile.get_basename().endswith('.mab')
 
 	def get_items(self):
 		for name, email in support.get_contacts():
diff --git a/kupfer/plugin/thunderbird_support.py b/kupfer/plugin/thunderbird_support.py
index 4ff1e21..33e78c7 100644
--- a/kupfer/plugin/thunderbird_support.py
+++ b/kupfer/plugin/thunderbird_support.py
@@ -1,4 +1,4 @@
-# -*- coding: UTF-8 -*-
+# -*- coding: utf-8 -*-
 
 from __future__ import with_statement
 
@@ -25,7 +25,6 @@ THUNDERBIRD_HOME = map(os.path.expanduser,
 THUNDERBIRD_PROFILES = [ 
 		(thome, os.path.join(thome, 'profiles.ini'))
 		for thome in THUNDERBIRD_HOME ]
-ABOOK_FILE = 'abook.mab'
 
 
 RE_COLS = re.compile(r'<\s*<\(a=c\)>\s*(\/\/)?\s*(\(.+?\))\s*>')
@@ -234,11 +233,10 @@ def _mork2contacts(tables):
 
 def get_addressbook_dir():
 	''' Get path to addressbook file from default profile. '''
-	thunderbird_home, thunderbird_profile = None, None
+	thunderbird_home = None
 	for thome, tprofile in THUNDERBIRD_PROFILES:
 		if os.path.isfile(tprofile):
 			thunderbird_home = thome
-			thunderbird_profile = tprofile
 			break
 
 	if not thunderbird_home:
@@ -262,33 +260,31 @@ def get_addressbook_dir():
 	return path
 
 
-def get_addressbook_file():
-	''' Get full path to the Thunderbird address book file.
-		Return None if it don't exists '''
+def get_addressbook_files():
+	''' Get full path to all Thunderbird address book files. '''
 	path = get_addressbook_dir()
 	if not path:
-		return None
-
-	fullpath = os.path.join(path, ABOOK_FILE)
-	if os.path.isfile(fullpath):
-		return fullpath
+		return
 
-	return None
+	files = os.listdir(path)
+	for filename in files:
+		if filename.endswith('.mab'):
+			fullpath = os.path.join(path, filename)
+			if os.path.isfile(fullpath):
+				yield fullpath
 
 
 def get_contacts():
-	''' Get all contacts from Thunderbird address book as
-		[(contact name, contact email)] '''
-	abook = get_addressbook_file()
-	if abook:
+	''' Get all contacts from all Thunderbird address books as
+		((contact name, contact email)) '''
+	for abook in get_addressbook_files():
 		try:
 			tables = _read_mork(abook)
 		except IOError, err:
-			pretty.print_error(__name__, 'get_contacts error', err)
+			pretty.print_error(__name__, 'get_contacts error', abook, err)
 		else:
-			return list(_mork2contacts(tables))
-	
-	return []
+			for item in _mork2contacts(tables):
+				yield item
 
 
 if __name__ == '__main__':



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]