Function: eudc-mailabbrev-query-internal

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

Signature

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

Documentation

Query mailabbrev with QUERY.

QUERY is a list of cons cells (ATTR . VALUE). Since mailabbrev does not provide attributes in the usual sense, only the email, name, and firstname attributes in the QUERY are considered, and their values are matched against the alias names in the mailrc file. When a mailrc alias is a distribution list, that is it expands to more that one email address, the individual recipient specifications are formatted using eudc-rfc5322-make-address, and returned as a comma-separated list in the email address attribute.

RETURN-ATTRS is a list of attributes to return, defaulting to eudc-default-return-attributes.

Source Code

;; Defined in /usr/src/emacs/lisp/net/eudcb-mailabbrev.el.gz
;;;###autoload
(defun eudc-mailabbrev-query-internal (query &optional _return-attrs)
  "Query `mailabbrev' with QUERY.
QUERY is a list of cons cells (ATTR . VALUE).  Since `mailabbrev'
does not provide attributes in the usual sense, only the email,
name, and firstname attributes in the QUERY are considered, and
their values are matched against the alias names in the mailrc
file.  When a mailrc alias is a distribution list, that is it
expands to more that one email address, the individual recipient
specifications are formatted using `eudc-rfc5322-make-address',
and returned as a comma-separated list in the email address
attribute.

RETURN-ATTRS is a list of attributes to return, defaulting to
`eudc-default-return-attributes'."
  (mail-abbrevs-setup)
  (let (result)
    (dolist (term query)
      (let* ((attr (car term))
             (value (cdr term))
             (soft (intern-soft value mail-abbrevs))
             (raw-matches (and
                           (boundp soft)
                           (symbol-value soft))))
        (when (and raw-matches
                   (memq attr '(email firstname name)))
          (let* ((matches (split-string raw-matches ", "))
                 (num-matches (length matches)))
            (if (> num-matches 1)
                ;; multiple matches: distribution list
                (let ((distr-str (string)))
                  (dolist (recipient matches)
                    ;; try to decompose email construct
                    (let* ((decoded (mail-header-parse-address recipient t))
                           (name (cdr decoded))
                           (email (car decoded)))
                      (if decoded
                          ;; decoding worked, push rfc5322 rendered address
                          (setq distr-str
                                (copy-sequence
                                 (concat distr-str ", "
                                         (eudc-rfc5322-make-address email
                                                                    nil
                                                                    name))))
                        ;; else, just forward the value as-is
                        (setq distr-str
                              (copy-sequence
                               (concat distr-str ", " recipient))))))
                  ;; push result, removing the leading ", "
                  (push (list (cons 'email (substring distr-str 2 -1)))
                        result))
              ;; simple case: single match
              (let* ((match (car matches))
                     (decoded (mail-header-parse-address match t))
                     (name (cdr decoded))
                     (email (car decoded)))
                (if decoded
                    ;; decoding worked, push individual fields
                    (push `((email . ,email)
                            ,@(when name (list (cons 'name name))))
                          result)
                  ;; else, just forward the value as-is
                  (push (list (cons 'email match)) result))))))))
    result))