From 6c8edc999c44f91b74f9fe43ebb91062fd489726 Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Sun, 1 Feb 2009 22:57:16 +0100 Subject: [PATCH] Try to handle duplicates more gracefully --- lisp/eweouz.el | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lisp/eweouz.el b/lisp/eweouz.el index 82b73e8..f7a1469 100644 --- a/lisp/eweouz.el +++ b/lisp/eweouz.el @@ -20,6 +20,8 @@ ;;; 02110-1301 USA. ;;; +(require 'cl) + (defconst eweouz-version "0.3") (defconst eweouz-buffer-name "*EWEOUZ*") @@ -38,16 +40,18 @@ (defvar eweouz-buffer nil) (defvar eweouz-pop-up-target-lines 5) -(defun eweouz-search-do (func string) +(defun eweouz-search-do (func string &optional max-matches) "Search for the simple string STRING in all fields" - (block nil + (let ((i 0)) (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") + (while (and (looking-at "\n*BEGIN:VCARD") (or (eq max-matches nil) + (< i max-matches))) (let ((m-start (point))) + (incf i) (message (format "%s" (point))) (search-forward-regexp "^END:VCARD") (funcall func (vcard-parse-string (buffer-substring m-start (point))))))))) @@ -149,8 +153,8 @@ (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)))) + (record (or (eweouz-search-do identity email 1) + (eweouz-search-do identity name 1)))) (if record (eweouz-do-update record name email) (eweouz-do-add from))))) -- 2.39.5