From 83e86f0ae14f9fcd2eff18f9302738a689912e30 Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Thu, 30 Oct 2008 08:28:42 +0100 Subject: [PATCH] Make eweouz-add-sender-gnus update if the record exists --- lisp/eweouz.el | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/lisp/eweouz.el b/lisp/eweouz.el index d803488..82b73e8 100644 --- a/lisp/eweouz.el +++ b/lisp/eweouz.el @@ -40,16 +40,17 @@ (defun eweouz-search-do (func string) "Search for the simple string STRING in all fields" - (with-temp-buffer - (call-process eweouz-dump-path nil (current-buffer) t string) - (set-text-properties (point-min) (point-max) nil nil) - (goto-char (point-min)) - (message (format "%s" (point))) - (while (looking-at "\n*BEGIN:VCARD") - (let ((m-start (point))) - (message (format "%s" (point))) - (search-forward-regexp "^END:VCARD") - (funcall func (vcard-parse-string (buffer-substring m-start (point)))))))) + (block nil + (with-temp-buffer + (call-process eweouz-dump-path nil (current-buffer) t string) + (set-text-properties (point-min) (point-max) nil nil) + (goto-char (point-min)) + (message (format "%s" (point))) + (while (looking-at "\n*BEGIN:VCARD") + (let ((m-start (point))) + (message (format "%s" (point))) + (search-forward-regexp "^END:VCARD") + (funcall func (vcard-parse-string (buffer-substring m-start (point))))))))) ;;;###autoload (defun eweouz-complete (&optional start-pos) @@ -145,7 +146,21 @@ (interactive) (save-excursion (set-buffer gnus-article-buffer) - (eweouz-do-add (mail-header-parse-address (gnus-fetch-field "From"))))) + (let* ((from (mail-header-parse-address (gnus-fetch-field "From"))) + (email (car from)) + (name (cdr from)) + (record (or (eweouz-search-do '(lambda (x) (return x)) email) + (eweouz-search-do '(lambda (x) (return x)) name)))) + (if record + (eweouz-do-update record name email) + (eweouz-do-add from))))) + +(defun eweouz-do-update (record name email) + (interactive) + (let ((uid (cadr (assoc '("uid") record)))) + (message (format "%s %s %s" uid name email)) + (call-process eweouz-write-path nil nil nil "--id" uid "--full-name" name + "--emails" email))) (defun eweouz-do-add (record) (interactive) -- 2.39.5