Function: eudc-ecomplete-query-internal

eudc-ecomplete-query-internal is an autoloaded and byte-compiled function defined in eudcb-ecomplete.el.gz.

Signature

(eudc-ecomplete-query-internal QUERY &optional RETURN-ATTRS)

Documentation

Query ecomplete with QUERY.

QUERY is a list of cons cells (ATTR . VALUE). Since ecomplete does not provide attributes in the usual sense, the back-end-specific attribute names in eudc-ecomplete-attributes-translation-alist are used as the KEY (that is, the "type" of match) when looking for matches in ecomplete-database.

RETURN-ATTRS is ignored.

Source Code

;; Defined in /usr/src/emacs/lisp/net/eudcb-ecomplete.el.gz
;;;###autoload
(defun eudc-ecomplete-query-internal (query &optional _return-attrs)
  "Query `ecomplete' with QUERY.
QUERY is a list of cons cells (ATTR . VALUE).  Since `ecomplete'
does not provide attributes in the usual sense, the
back-end-specific attribute names in
`eudc-ecomplete-attributes-translation-alist' are used as the
KEY (that is, the \"type\" of match) when looking for matches in
`ecomplete-database'.

RETURN-ATTRS is ignored." ; FIXME: why is this being ignored?
  (ecomplete-setup)
  (let ((email-attr (car (eudc-translate-attribute-list '(email))))
        result)
    (dolist (term query)
      (let* ((attr (car term))
             (value (cdr term))
             (matches (ecomplete-get-matches attr value)))
        (when matches
          (dolist (match (split-string (string-trim (substring-no-properties
                                                     matches))
                                       "[\n\r]"))
            ;; Try to decompose the email address.
            (let* ((decoded (mail-header-parse-address match t))
                   (name (cdr decoded))
                   (email (car decoded)))
              (if (and decoded (eq attr email-attr))
                  ;; The email could be decomposed, push individual
                  ;; fields.
                  (push `((,attr . ,email)
                          ,@(when name (list (cons 'name name))))
                        result)
                ;; Otherwise just forward the value as-is.
                (push (list (cons attr match)) result)))))))
    result))