(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)
(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)