commit-womb
[Top][All Lists]
Advanced

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

[Commit-womb] addressbook ChangeLog addressbook.el


From: Xavier Maillard
Subject: [Commit-womb] addressbook ChangeLog addressbook.el
Date: Tue, 08 May 2007 15:56:09 +0000

CVSROOT:        /sources/womb
Module name:    addressbook
Changes by:     Xavier Maillard <zeDek> 07/05/08 15:56:09

Modified files:
        .              : ChangeLog addressbook.el 

Log message:
        Add vCard import/export support

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/addressbook/ChangeLog?cvsroot=womb&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/addressbook/addressbook.el?cvsroot=womb&r1=1.24&r2=1.25

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/womb/addressbook/ChangeLog,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- ChangeLog   8 May 2007 11:04:37 -0000       1.22
+++ ChangeLog   8 May 2007 15:56:09 -0000       1.23
@@ -1,3 +1,16 @@
+2007-05-08  Xavier Maillard  <address@hidden>
+
+       * vcard.el (vcard-parse-file): New helper function used in 
addrbook-import-vcard.
+
+       * addressbook.el (addrbook-bury): New function.
+       (addrbook-summary-mode, addrbook-contact-mode): Bind b key to
+       addrbook-bury.
+       (addrbook-write-data-1): New function. Take one VCARD and write
+       its data in a FILE.
+       (addrbook-import-vcard, addrbook-export-vcard): New functions. Use
+       it. Import and Export VCARDs from addrbook-summary buffer.
+       (addrbook-summary-mode): Bind i and x to import/export.
+
 2007-05-08  Jose E. Marchesi  <address@hidden>
 
        * addressbook.el (addrbook-summary-display): expand line to frame-width

Index: addressbook.el
===================================================================
RCS file: /sources/womb/addressbook/addressbook.el,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- addressbook.el      8 May 2007 12:18:23 -0000       1.24
+++ addressbook.el      8 May 2007 15:56:09 -0000       1.25
@@ -5,7 +5,7 @@
 ;; Maintainer: Jose E. Marchesi
 ;; Keywords: contacts, applications
 
-;; $Id: addressbook.el,v 1.24 2007/05/08 12:18:23 zeDek Exp $
+;; $Id: addressbook.el,v 1.25 2007/05/08 15:56:09 zeDek Exp $
 
 ;; This file is NOT part of GNU Emacs.
 
@@ -1591,6 +1591,8 @@
   (define-key addrbook-summary-mode-map (kbd "RET") 
'addrbook-summary-show-contact)
   (define-key addrbook-summary-mode-map "b" 'addrbook-bury)
   (define-key addrbook-summary-mode-map "q" 'addrbook-quit)
+  (define-key addrbook-summary-mode-map "i" 'addrbook-import-vcard)
+  (define-key addrbook-summary-mode-map "x" 'addrbook-export-vcard)
   (define-key addrbook-summary-mode-map "m" 'addrbook-send-email)
   (use-local-map addrbook-summary-mode-map)
   (setq mode-name "AddressBook Summary")
@@ -1650,6 +1652,75 @@
     (if new-card-index
         (addrbook-contact-display-card new-card-index))))
 
+(defun addrbook-import-vcard (filename)
+  "Import vCard from FILENAME and add it into our contact database and return 
index card number."
+  (interactive
+   (list
+    (expand-file-name
+     (read-file-name "vCard file to import: "))))
+
+  (let ((index nil)
+       vcard)
+    (addrbook-read-cards)
+    (save-excursion
+      (unwind-protect
+         (if (and (setq index (length addrbook-cards))
+                  (setq vcard (vcard-parse-file filename)))
+             (progn
+               (addrbook-set-card index (car vcard))
+               (add-to-list 'addrbook-modified-cards index))
+           (error "Vcard import failed!"))
+       ;; Just to be sure, call save-cards
+       (addrbook-save-cards nil)))
+    index))
+
+;; FIXME: does not work in contact mode
+(defun addrbook-export-vcard ()
+  "Export current card data to a file."
+  (interactive)
+  (let* ((index (addrbook-summary-get-current-card))
+        (fullname (addrbook-get-card-fn nil index ))
+        (filename (read-file-name "Export vCard to file: " nil nil
+                                  nil (concat fullname ".vcf"))))
+    (addrbook-write-data-1 filename (addrbook-get-card index))
+    (message "vCard exported")))
+
+(defun addrbook-write-data-1 (filename &optional vcard)
+  "Save raw vCard formatted data into FILENAME.
+If optional VCARD parameter is not set, use `addrbook-current-card'."
+  (let ((vcard (or vcard (addrbook-get-card addrbook-current-card))))
+    (with-temp-file filename
+      (vcard-insert vcard))))
+
+(defun addrbook-send-email ()
+  "Send an email to current contact"
+  (interactive)
+  (let* ((card (addrbook-get-card addrbook-current-card))
+         (mail-addresses (vcard-ref card (list "email")))
+         mail-names name i attr sendto-address letter)
+    (dotimes (i (length mail-addresses))
+      (let* ((attr (nth i mail-addresses))
+             (attr-type (car (vcard-attr-get-parameter attr "type"))))
+        (if (equal attr-type "internet")
+            (setq mail-names (cons (list (car (vcard-attr-get-values attr))
+                                         (+ ?a i))
+                                   mail-names)))))
+    (setq mail-names (reverse mail-names))
+    (if (not mail-names)
+        (message "Contact doesnt have a suitable smtp address")
+      (if (equal (length mail-names) 1)
+          (setq sendto-address (car (car mail-names)))
+        (setq letter (addrbook-fast-selection mail-names "Select email address 
to send mail to"))
+        (dolist (name mail-names)
+          (if (equal letter
+                     (cadr name))
+              (setq sendto-address (car name)))))
+      ;; Send the email
+      (if sendto-address
+          (compose-mail-other-frame (concat
+                                     "\"" (addrbook-get-card-fn) "\""
+                                     " <" sendto-address ">"))))))
+
 (defun addrbook-save-cards (prefix)
   "Save cards into addrbook-file"
   (interactive "P")




reply via email to

[Prev in Thread] Current Thread [Next in Thread]