[PLUGIN] vCards



This plugin indexes directories of vCards (*.vcd), allowing you to compose mail to the contacts inside.

However, I'm not sure how to create the configuration for selecting multiple directories to monitor (currently it is just hard-coded for testing).
Also, folders aren't recursively monitored--I'm not sure of the best way to do that, nor am I sure if it is necessary.

Could anyone help finish what I started?

The plugin depends on the vobject module, which hopefully isn't an issue.

Thanks!
-David
# -*- coding: UTF-8 -*-
__kupfer_name__ = _("vCard")
__kupfer_sources__ = ("vCardContactsSource", )
__kupfer_actions__ = ()
__description__ = _("vCard Contacts")
__version__ = "2010-03-05"
__author__ = "David Schneider <dnschneid gmail com>"

import os
import vobject
import gio

from kupfer.objects import Leaf, Source
from kupfer import utils
from kupfer.obj.apps import AppLeafContentMixin
from kupfer.obj.helplib import FilesystemWatchMixin
from kupfer.obj.grouping import ToplevelGroupingSource
from kupfer.obj.contacts import ContactLeaf, EmailContact


class vCardContactsSource(AppLeafContentMixin, ToplevelGroupingSource, FilesystemWatchMixin):
	appleaf_content_id = 'vcard'
	vcard_directories=[os.path.expanduser('~/.claws-mail/addrbook')]

	def __init__(self, name=_("vCard Contacts")):
		super(vCardContactsSource, self).__init__(name, "Contacts")
		#Source.__init__(self, name)
		self._version = 4

	def initialize(self):
		ToplevelGroupingSource.initialize(self)
		self.monitor_token = self.monitor_directories(*self.vcard_directories)

	def monitor_include_file(self, gfile):
		# monitor only *.vcf files
		return gfile and gfile.get_basename().endswith('.vcf')

	def get_items(self):
		for vcard_directory in self.vcard_directories:
			if not os.path.exists(vcard_directory):
				continue
			directory_file = gio.File(vcard_directory)
			for vcard_file in directory_file.enumerate_children(gio.FILE_ATTRIBUTE_STANDARD_NAME):
				try:
					if vcard_file.get_name().endswith('.vcf'):
						file = directory_file.get_child(vcard_file.get_name()).read()
						for contact in vobject.readComponents(file):
							name = ""
							addresses = []
							for attr in contact.getChildren():
								if attr.name == 'EMAIL':
									addresses.append(attr.value)
								elif attr.name == 'FN' or (attr.name == 'ORG' and not name):
									name = attr.value
							if name:
								for address in addresses:
									yield EmailContact(address, name)
				except StandardError, err:
					self.output_error(err)

	def should_sort_lexically(self):
		# since it is a grouping source, grouping and non-grouping will be
		# separate and only grouping leaves will be sorted
		return True

	def get_description(self):
		return _("Contacts from vCard Files")

	def get_icon_name(self):
		return "vcard"

	def provides(self):
		yield ContactLeaf




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