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: Updated eudcb-mab.el Date: Tue, 17 Feb 2015 15:50:41 +0200 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1424183548 3513 80.91.229.3 (17 Feb 2015 14:32:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 17 Feb 2015 14:32:28 +0000 (UTC) Cc: John Wiegley To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Feb 17 15:32:21 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 1YNjCF-0001if-8b for ged-emacs-devel@m.gmane.org; Tue, 17 Feb 2015 15:32:19 +0100 Original-Received: from localhost ([::1]:45724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNjC4-0005c3-Iu for ged-emacs-devel@m.gmane.org; Tue, 17 Feb 2015 09:32:08 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNiYC-0006Ny-7D for emacs-devel@gnu.org; Tue, 17 Feb 2015 08:50:57 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YNiY7-0000Qp-KT for emacs-devel@gnu.org; Tue, 17 Feb 2015 08:50:56 -0500 Original-Received: from mail-wg0-x230.google.com ([2a00:1450:400c:c00::230]:46978) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNiY7-0000QN-7P for emacs-devel@gnu.org; Tue, 17 Feb 2015 08:50:51 -0500 Original-Received: by mail-wg0-f48.google.com with SMTP id l18so32550609wgh.7 for ; Tue, 17 Feb 2015 05:50:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=danieroux.com; s=google; h=sender:from:to:subject:cc:date:message-id:mime-version:content-type; bh=khg/GwD0GLeOXUukb4OvzkX3g85lhPT2NfkzRP3xBvE=; b=4P6tn7XOOmjEt9pW9B0V5IEQe8Q73oaKQJR1z2fZ7hszgBKs+TXshTVbxOeHrEtc/t /qb/a2f7QwJXxoti8EYXEO0tEiME9xgGFZ8p90/WxTPnB2kLKgCokdKsO1atPBZdyzda zm/jJLsvpOeo9qLm7EdDHgcV0V4uWO8YuhTlQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:cc:date:message-id :mime-version:content-type; bh=khg/GwD0GLeOXUukb4OvzkX3g85lhPT2NfkzRP3xBvE=; b=cQ5DjtKXIY+L+kd7+A7jHXpUNiTyUx2m7+1jV4bA9GSa0M079hb5jvY8/of12AFbTy ZM9v0NFS1/DkNzcN2q3FyHtj6nXGuOB6tPAVtWsqlQNJbPKiRkiovu3C0PBn//KpSpA0 kQdyDXTXCEhVu84i+WxwM2GvCrLKz51Hz5t3laoPDxzxCx2ztJaivWNcXkfg65AeDLP1 BJjvda7el4Mkmphh700EmLULbl7wvmNwUZYGf7LfuI8Okb490J9lhP/wKH9tnM6EXzvo Bw/s65AqwKwIxz4DxiDiqprLLqptUuahhNxa1jvCv0SGPtwiq/2kxDFM7gyscmF5ZoAm C+qw== X-Gm-Message-State: ALoCoQkXIy0fOxZnygYozu2tozPsig9pIQGZPoRIsotyAiJmmSPxI1pQS+sMN7Oi1hqL6eW3rbcn X-Received: by 10.180.88.193 with SMTP id bi1mr54214882wib.70.1424181049739; Tue, 17 Feb 2015 05:50:49 -0800 (PST) Original-Received: from danie-notebook.local ([154.66.208.158]) by mx.google.com with ESMTPSA id k1sm27504818wjn.9.2015.02.17.05.50.47 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Feb 2015 05:50:48 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::230 X-Mailman-Approved-At: Tue, 17 Feb 2015 09:32:03 -0500 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:183192 Archived-At: --=-=-= Content-Type: text/plain Dear Emacs-devel, I've updated eudcb-mab.el to directly query the contacts database, instead of using an external application. Is this useful, what do I need to do to get the official version updated? Please find the changed version attached. -- Danie Roux --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=eudcb-mab.el Content-Transfer-Encoding: quoted-printable ;;; eudcb-mab-sqlite.el --- Emacs Unified Directory Client - AddressBook ba= ckend ;; 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 the database using sqlite3. No additional software ;; need to be installed. ;;; 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. If you ha= ve a remote source (like Google), find the right file in ~/Library/Applicat= ion 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 sqlite3-dump-mac-addressbook () "LastName:FirstName:Phone:Email" (interactive) (call-process (executable-find "sqlite3") nil t nil "-separator" ":" (expand-file-name eudc-contacts-file)=20 "select p.ZLASTNAME,p.ZFIRSTNAME,n.ZFULLNUMBER,e.ZADDRESSNORMALIZED from = ZABCDRECORD as p,ZABCDEMAILADDRESS as e,ZABCDPHONENUMBER as n WHERE (e.ZOWN= ER =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) (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-sqlite) ;;; eudcb-mab-sqlite.el ends here --=-=-=--