Skip to content

Instantly share code, notes, and snippets.

@darthoctopus
Created April 5, 2017 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darthoctopus/75ec2097680a248aa4a8daa26180ee2b to your computer and use it in GitHub Desktop.
Save darthoctopus/75ec2097680a248aa4a8daa26180ee2b to your computer and use it in GitHub Desktop.
Geary plugin for Kupfer launcher (adapted from Thunderbird plugin)
# -*- coding: utf-8 -*-
__kupfer_name__ = _("Geary")
__kupfer_sources__ = ("ContactsSource", )
__kupfer_actions__ = ("NewMailAction", )
__description__ = _("Geary Contacts and Actions")
__version__ = "2017.4"
__author__ = "Joel Ong <joel.ong@yale.edu>, Karol Będkowski <karol.bedkowski@gmail.com>, US"
from kupfer.objects import Action
from kupfer.objects import TextLeaf, UrlLeaf, RunnableLeaf, FileLeaf
from kupfer.obj.apps import AppLeafContentMixin
from kupfer.obj.helplib import FilesystemWatchMixin
from kupfer import utils, icons
from kupfer.obj.grouping import ToplevelGroupingSource
from kupfer.obj.contacts import ContactLeaf, EmailContact, email_from_leaf
import os
from glob import glob
import sqlite3
"""
Changes:
2017-04-02: Joel Ong
+ Geary
2012-03-15: Karol Będkowski
+ activate_multiple for new mail action
"""
class ComposeMail(RunnableLeaf):
''' Create new mail without recipient '''
def __init__(self):
RunnableLeaf.__init__(self, name=_("Compose New Email"))
def run(self):
utils.spawn_async(['geary', 'mailto:'])
def get_description(self):
return _("Compose a new message in Geary")
def get_icon_name(self):
return "mail-sent-symbolic"
class NewMailAction(Action):
''' Createn new mail to selected leaf (Contact or TextLeaf)'''
def __init__(self):
Action.__init__(self, _('Compose Email To'))
def activate(self, leaf):
self.activate_multiple((leaf, ))
def activate_multiple(self, objects):
recipients = ",".join(email_from_leaf(L) for L in objects)
utils.spawn_async(['geary', 'mailto:%s' % recipients])
def get_description(self):
return _("Compose a new message with Geary")
def get_icon_name(self):
return "mail-sent-symbolic"
def item_types(self):
yield ContactLeaf
# we can enter email
yield TextLeaf
yield UrlLeaf
def valid_for_item(self, item):
return bool(email_from_leaf(item))
# Support
def get_addressbook_dirs():
l = sorted(glob('%s/geary/account_*/' % os.path.expanduser('~/.local/share')))
for p in l:
if os.path.isdir(p):
yield p
def get_contacts():
for path in get_addressbook_dirs():
conn = sqlite3.connect('%s/geary.db'%path)
c = conn.cursor()
r = c.execute('SELECT real_name, email FROM ContactTable').fetchall()
conn.close()
for row in r:
yield row
class ContactsSource(AppLeafContentMixin, ToplevelGroupingSource,
FilesystemWatchMixin):
appleaf_content_id = ('geary',)
def __init__(self, name=_("Geary Address Book")):
ToplevelGroupingSource.__init__(self, name, "Contacts")
self._version = 2
def initialize(self):
ToplevelGroupingSource.initialize(self)
abook_dirs = list(get_addressbook_dirs())
if abook_dirs:
self.monitor_token = self.monitor_directories(*abook_dirs)
def monitor_include_file(self, gfile):
return gfile and gfile.get_basename() == 'geary.db'
def get_items(self):
for name, email in get_contacts():
yield EmailContact(email, name)
yield ComposeMail()
def should_sort_lexically(self):
return True
def get_description(self):
return _("Contacts from Geary Address Book")
def get_gicon(self):
return icons.get_gicon_with_fallbacks(None, ("geary",))
def provides(self):
yield ContactLeaf
yield RunnableLeaf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment