@ -87,14 +87,18 @@ their canonical counterpart; useful as an example."
" mu4e 1.3.2 " )
" mu4e 1.3.2 " )
( defcustom mu4e-contact-process-function
( defcustom mu4e-contact-process-function
( lambda ( addr ) ;; filter-out no-reply addresses
( lambda ( addr )
( unless ( string-match-p " no[t]?[- \\ .]?repl \\ (y \\ |ies \\ ) " addr )
( cond
addr ) )
( ( string-match-p " reply " addr )
;; no-reply adresses are not useful of course, but neither are are
;; reply-xxxx addresses since they're autogenerated only useful for direct
;; replies.
nil )
( t addr ) ) )
" Function for processing contact information for use in auto-completion.
" Function for processing contact information for use in auto-completion.
The function receives the contact as a string, e.g
The function receives the contact as a string, e.g \" Foo Bar
\" Foo Bar <foo.bar@example.com> \"
<foo.bar@example.com> \" \" cuux@example.com \"
\" cuux@example.com \"
The function should return either:
The function should return either:
- nil: do not use this contact for completion
- nil: do not use this contact for completion
@ -121,11 +125,8 @@ predicate function. A value of nil keeps all the addresses."
( defvar mu4e--contacts-tstamp " 0 "
( defvar mu4e--contacts-tstamp " 0 "
" Timestamp for the most recent contacts update. " )
" Timestamp for the most recent contacts update. " )
( defvar mu4e--contacts-hash nil
( defvar mu4e--contacts-set nil
" Hash that maps contacts (ie. 'name <e-mail>') to an integer for sorting.
" Set with the full contact addresses for autocompletion. " )
We need to keep this information around to quickly re-sort
subsets of the contacts in the completions function in
mu4e-compose. " )
;;; user mail address
;;; user mail address
( defun mu4e-personal-addresses ( &optional no-regexp )
( defun mu4e-personal-addresses ( &optional no-regexp )
@ -236,36 +237,24 @@ case a phrase contains a quote, it will be escaped."
( defun mu4e--update-contacts ( contacts &optional tstamp )
( defun mu4e--update-contacts ( contacts &optional tstamp )
" Receive a sorted list of CONTACTS newer than TSTAMP.
" Receive a sorted list of CONTACTS newer than TSTAMP.
Each of the contacts has the form
Update an internal set with it.
(FULL_EMAIL_ADDRESS . RANK) and fill `mu4e--contacts-hash' with
it, with each contact mapped to an integer for their ranking.
This is used by the completion function in mu4e-compose. "
This is used by the completion function in mu4e-compose. "
;; We have our nicely sorted list, map them to a list
;; of increasing integers. We use that map in the composer
;; to sort them there. It would have been so much easier if emacs
;; allowed us to use the sorted-list as-is, but no such luck.
( let ( ( n 0 ) )
( let ( ( n 0 ) )
( unless mu4e--contacts-hash
( unless mu4e--contacts-set
( setq mu4e--contacts-hash ( make-hash-table :test 'equal :weakness nil
( setq mu4e--contacts-set ( make-hash-table :test 'equal :weakness nil
:size ( length contacts ) ) ) )
:size ( length contacts ) ) ) )
( dolist ( contact contacts )
( dolist ( contact contacts )
( cl-incf n )
( cl-incf n )
( let* ( ( address ( plist-get contact :address ) )
( when ( functionp mu4e-contact-process-function )
( address
( setq contact ( funcall mu4e-contact-process-function contact ) ) )
( if ( functionp mu4e-contact-process-function )
( when contact ;; note the explicit deccode; the strings we get are
( funcall mu4e-contact-process-function address )
address ) ) )
( when address ;; note the explicit deccode; the strings we get are
;; utf-8, but emacs doesn't know yet.
;; utf-8, but emacs doesn't know yet.
( puthash ( decode-coding-string address 'utf-8 )
( puthash ( decode-coding-string contact 'utf-8 ) t mu4e--contacts-set ) ) )
( plist-get contact :rank ) mu4e--contacts-hash ) ) ) )
( setq mu4e--contacts-tstamp ( or tstamp " 0 " ) )
( setq mu4e--contacts-tstamp ( or tstamp " 0 " ) )
( unless ( zerop n )
( unless ( zerop n )
( mu4e-index-message " Contacts updated: %d; total %d "
( mu4e-index-message " Contacts updated: %d; total %d "
n ( hash-table-count mu4e--contacts-hash ) ) ) ) )
n ( hash-table-count mu4e--contacts-set ) ) ) ) )
( defun mu4e-contacts-info ( )
( defun mu4e-contacts-info ( )
" Display information about the contacts-cache.
" Display information about the contacts-cache.
@ -274,31 +263,26 @@ For testing/debugging."
( with-current-buffer ( get-buffer-create " *mu4e-contacts-info* " )
( with-current-buffer ( get-buffer-create " *mu4e-contacts-info* " )
( erase-buffer )
( erase-buffer )
( insert ( format " complete addresses: %s \n "
( insert ( format " complete addresses: %s \n "
( if mu4e-compose-complete-addresses " yes " " no " ) ) )
( if mu4e-compose-complete-addresses " yes " " no " ) ) )
( insert ( format " only personal addresses: %s \n "
( insert ( format " only personal addresses: %s \n "
( if mu4e-compose-complete-only-personal " yes " " no " ) ) )
( if mu4e-compose-complete-only-personal " yes " " no " ) ) )
( insert ( format " only addresses seen after: %s \n "
( insert ( format " only addresses seen after: %s \n "
( or mu4e-compose-complete-only-after " no restrictions " ) ) )
( or mu4e-compose-complete-only-after " no restrictions " ) ) )
( when mu4e--contacts-hash
( when mu4e--contacts-set
( insert ( format " number of contacts cached: %d \n \n "
( insert ( format " number of contacts cached: %d \n \n "
( hash-table-count mu4e--contacts-hash ) ) )
( hash-table-count mu4e--contacts-set ) ) )
( let ( ( contacts ) )
( maphash ( lambda ( contact _ )
( maphash ( lambda ( addr rank )
( insert ( format " %s \n " contact ) ) ) mu4e--contacts-set ) )
( setq contacts ( cons ( cons rank addr ) contacts ) ) )
mu4e--contacts-hash )
( setq contacts ( sort contacts
( lambda ( cell1 cell2 ) ( < ( car cell1 ) ( car cell2 ) ) ) ) )
( dolist ( contact contacts )
( insert ( format " %s \n " ( cdr contact ) ) ) ) ) )
( pop-to-buffer " *mu4e-contacts-info* " ) ) )
( pop-to-buffer " *mu4e-contacts-info* " ) ) )
( declare-function mu4e--server-contacts " mu4e-server " )
( declare-function mu4e--server-contacts " mu4e-server " )
( defun mu4e--request-contacts-maybe ( )
( defun mu4e--request-contacts-maybe ( )
" If `mu4e-compose-complete-addresses' is non-nil, get/update
" Maybe update the set of contacts for autocompletion.