From: Tollef Fog Heen Date: Thu, 30 Oct 2008 07:28:42 +0000 (+0100) Subject: Make eweouz-add-sender-gnus update if the record exists X-Git-Tag: 0.5~8 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83e86f0ae14f9fcd2eff18f9302738a689912e30;p=eweouz Make eweouz-add-sender-gnus update if the record exists --- 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)