From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Danie Roux Newsgroups: gmane.emacs.devel Subject: Re: Updated eudcb-mab.el Date: Sat, 21 Feb 2015 17:57:37 +0200 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1424534282 7084 80.91.229.3 (21 Feb 2015 15:58:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 21 Feb 2015 15:58:02 +0000 (UTC) Cc: John Wiegley , emacs-devel@gnu.org To: Thomas Fitzsimmons Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Feb 21 16:57:56 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YPCRI-0001kw-5c for ged-emacs-devel@m.gmane.org; Sat, 21 Feb 2015 16:57:56 +0100 Original-Received: from localhost ([::1]:36505 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YPCRH-00031v-Dz for ged-emacs-devel@m.gmane.org; Sat, 21 Feb 2015 10:57:55 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YPCRD-00031o-5s for emacs-devel@gnu.org; Sat, 21 Feb 2015 10:57:52 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YPCR9-0006lD-Dz for emacs-devel@gnu.org; Sat, 21 Feb 2015 10:57:51 -0500 Original-Received: from mail-wg0-x236.google.com ([2a00:1450:400c:c00::236]:37603) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YPCR9-0006l1-38 for emacs-devel@gnu.org; Sat, 21 Feb 2015 10:57:47 -0500 Original-Received: by mail-wg0-f54.google.com with SMTP id y19so18109370wgg.13 for ; Sat, 21 Feb 2015 07:57:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=danieroux.com; s=google; h=sender:references:from:to:cc:subject:in-reply-to:date:message-id :mime-version:content-type; bh=1v9LpZrkHE8kc5y0o9v5e0+q6+eOdh/tdSetK8lsdDc=; b=hGa0h5Zm73U2sraWqRqbVJUolt2o71tlq1bvk1vP/X/YibAxz6fpc3CKfQEwhdQmo3 U+Y9WaZHWnMhN7d2mG94oBslXptQvNHeNNEq0QMlTTdi+26PaldVmghN+QS1oMpPelw6 lnlp/XIaMxW31NlL5FoNAA76blwFynboicspw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:references:from:to:cc:subject:in-reply-to :date:message-id:mime-version:content-type; bh=1v9LpZrkHE8kc5y0o9v5e0+q6+eOdh/tdSetK8lsdDc=; b=Qsyb0y5XfSxjW8Bgfbup6DPJ3jlPJnTOHsmueRiVHRzDrSuo1ggDvxpRxg1k8hW08U HlsXpZG35GN7cH/8DL4jQvKadThFnIBEHx3g0A28SNBUqGpVT1DjpKiyWWs/FwLfVP1c KX4mbskQuUhGTGvGuCI4RFceOVysWQKJY6+UAzZMfn5EuJlEunwOvA13H6stBiP7w+d6 VLaqye8zpaJhdCjhy35gujRpJX27ZKI9WcnKNeco4tCsWGjFQY0xP2fioLe7hGuAoXQl bg6EeCFTFov7tKmIGCRzZuYN+VkldAmnKkm7B7Fm6fzttsqHyxe6VFtIGo2m9i5rFNdC Y+Fw== X-Gm-Message-State: ALoCoQmDvtHKj/s/qFTsp+kT8vpLOSWZWP1CF7l1ZvAsm0PIgdvVZzZ0YXUAbeGBTj2Q4XO+bUAq X-Received: by 10.194.95.200 with SMTP id dm8mr5909970wjb.122.1424534266147; Sat, 21 Feb 2015 07:57:46 -0800 (PST) Original-Received: from danie-notebook.local (196-215-180-60.dynamic.isadsl.co.za. [196.215.180.60]) by mx.google.com with ESMTPSA id o7sm7461616wix.12.2015.02.21.07.57.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Feb 2015 07:57:45 -0800 (PST) In-reply-to: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::236 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:183358 Archived-At: --=-=-= Content-Type: text/plain Thomas Fitzsimmons writes: > Danie Roux writes: > > [...] > >> Please find attached a new version and a sql file. > > Thanks. A few more comments: > > - `eudc-mab-sqlite3-dump-mac-addressbook' should not be interactive: in > general I'd like to reduce, or at least not grow, the number of > interactive entry points into EUDC Removed. > - there are some blank line additions that don't need to be there I'm unsure what you are referring to? >> Thomas Fitzsimmons writes: >>> Danie Roux writes: >>>> I've updated eudcb-mab.el to directly query the contacts database, >>>> instead of using an external application. >>> >>> It looks like you're still relying on an external application, sqlite3, >>> instead of "contacts", right? >> >> Yes, thank you for picking that up. By external I meant "no additional >> software". > > OK, I was thinking in terms of "external to Emacs". > > It's probably best not to mention OS X in the commentary, just leave it > at: > > ;; This library provides an interface to use the Mac's AddressBook, > ;; by querying a database file using the external program `sqlite3'. Changed it, thank you for the suggestion. -- Danie Roux --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=eudcb-mab.el Content-Transfer-Encoding: quoted-printable ;;; eudcb-mab.el --- Emacs Unified Directory Client - AddressBook backend ;; Copyright (C) 2003-2015 Free Software Foundation, Inc. ;; Author: John Wiegley ;; Maintainer: emacs-devel@gnu.org ;; Keywords: comm ;; Package: eudc ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;; This library provides an interface to use the Mac's AddressBook, ;; by querying a database file using the external program `sqlite3'. ;;; Code: (require 'eudc) (require 'executable) ;;{{{ Internal cooking (defvar eudc-mab-conversion-alist nil) (defvar eudc-buffer-time nil) (defvar eudc-contacts-file "~/Library/Application Support/AddressBook/AddressBook-v22.abcddb" "This is the location for the 'Local' addressbook on Mavericks. To test if the location is correct, invoke '(eudc-mab-sqlite3-dump-mac-addressbook). If you have a remote source (like Google), find the right file in: ~/Library/Application Support/AddressBook/Sources") (eudc-protocol-set 'eudc-query-function 'eudc-mab-query-internal 'mab) (eudc-protocol-set 'eudc-list-attributes-function nil 'mab) (eudc-protocol-set 'eudc-mab-conversion-alist nil 'mab) (eudc-protocol-set 'eudc-protocol-has-default-query-attributes nil 'mab) (defun eudc-mab-sqlite3-dump-mac-addressbook () "Return a colon separated list. The format is: LastName:FirstName:Phone:Email" (let ((sqlite-db (expand-file-name eudc-contacts-file))) (unless (and sqlite-db (file-readable-p sqlite-db)) (error "Cannot read sqlite database: %s" sqlite-db)) (call-process (executable-find "sqlite3") nil t nil "-separator" ":" sqlite-db "select p.ZLASTNAME, p.ZFIRSTNAME, n.ZFULLNUMBER, e.ZADDRESSNORMALIZED FROM ZABCDRECORD as p, ZABCDEMAILADDRESS as e, ZABCDPHONENUMBER as n WHERE (e.ZOWNER =3D p.Z_PK) AND (n.ZOWNER =3D p.Z_PK);")= )) (defun eudc-mab-query-internal (query &optional return-attrs) "Query MAB with QUERY. QUERY is a list of cons cells (ATTR . VALUE) where ATTRs should be valid MAB attribute names. RETURN-ATTRS is a list of attributes to return, defaulting to `eudc-default-return-attributes'." (let ((mab-buffer (get-buffer-create " *mab contacts*")) (modified (nth 5 (file-attributes eudc-contacts-file))) result) (with-current-buffer mab-buffer (make-local-variable 'eudc-buffer-time) (goto-char (point-min)) (when (or (eobp) (time-less-p eudc-buffer-time modified)) (erase-buffer) (eudc-mab-sqlite3-dump-mac-addressbook) (setq eudc-buffer-time modified)) (goto-char (point-min)) (while (not (eobp)) (let* ((args (split-string (buffer-substring (point) (line-end-position)) "\\s-*:\\s-*")) (lastname (nth 0 args)) (firstname (nth 1 args)) (phone (nth 2 args)) (mail (nth 3 args)) (matched t)) (if (string-match "\\s-+\\'" mail) (setq mail (replace-match "" nil nil mail))) (dolist (term query) (cond ((eq (car term) 'name) (unless (string-match (cdr term) (concat firstname " " lastname)) (setq matched nil))) ((eq (car term) 'email) (unless (string=3D (cdr term) mail) (setq matched nil))) ((eq (car term) 'phone)))) (when matched (setq result (cons `((firstname . ,firstname) (lastname . ,lastname) (name . ,(concat firstname " " lastname)) (phone . ,phone) (email . ,mail)) result)))) (forward-line))) (if (null return-attrs) result (let (eudc-result) (dolist (entry result) (let (entry-attrs abort) (dolist (attr entry) (when (memq (car attr) return-attrs) (if (=3D (length (cdr attr)) 0) (setq abort t) (setq entry-attrs (cons attr entry-attrs))))) (if (and entry-attrs (not abort)) (setq eudc-result (cons entry-attrs eudc-result))))) eudc-result)))) ;;}}} ;;{{{ High-level interfaces (interactive functions) (defun eudc-mab-set-server (dummy) "Set the EUDC server to MAB." (interactive) (eudc-set-server dummy 'mab) (message "MAB server selected")) ;;}}} (eudc-register-protocol 'mab) (provide 'eudcb-mab) ;;; eudcb-mab.el ends here --=-=-=--