Function: gnus-registry--munge-group-names

gnus-registry--munge-group-names is a byte-compiled function defined in gnus-registry.el.gz.

Signature

(gnus-registry--munge-group-names DB &optional ENCODE)

Documentation

Encode/decode group names in DB, before saving or after loading.

Encode names if ENCODE is non-nil, otherwise decode.

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/gnus-registry.el.gz
;; Remove this from the save routine (and fix it to only decode) at
;; next Gnus version bump.
(defun gnus-registry--munge-group-names (db &optional encode)
  "Encode/decode group names in DB, before saving or after loading.
Encode names if ENCODE is non-nil, otherwise decode."
  (let ((datahash (slot-value db 'data))
	(grouphash (registry-lookup-secondary db 'group))
	reset-pairs)
    (when (hash-table-p grouphash)
      (maphash
       (lambda (group-name val)
	 (if encode
	     (when (multibyte-string-p group-name)
	       (remhash group-name grouphash)
	       (puthash (encode-coding-string group-name 'utf-8-emacs)
			val grouphash))
	   (when (string-match-p "[^[:ascii:]]" group-name)
	     (remhash group-name grouphash)
	     (puthash (decode-coding-string group-name 'utf-8-emacs) val grouphash))))
       grouphash))
    (maphash
     (lambda (id data)
       (let ((groups (cdr-safe (assq 'group data))))
	 (when (seq-some (lambda (g)
			   (if encode
			       (multibyte-string-p g)
			     (string-match-p "[^[:ascii:]]" g)))
			 groups)
	   ;; Create a replacement DATA.
	   (push (list id (cons (cons 'group (mapcar
			   (lambda (g)
			     (funcall
			      (if encode
				  #'encode-coding-string
				#'decode-coding-string)
			      g 'utf-8-emacs))
			   groups))
				(assq-delete-all 'group data)))
		 reset-pairs))))
     datahash)
    (pcase-dolist (`(,id ,data) reset-pairs)
      (remhash id datahash)
      (puthash id data datahash))))