Function: message-shorten-references
message-shorten-references is a byte-compiled function defined in
message.el.gz.
Signature
(message-shorten-references HEADER REFERENCES)
Documentation
Trim REFERENCES to be 21 Message-ID long or less, and fold them.
When sending via news, also check that the REFERENCES are less than 988 characters long, and if they are not, trim them until they are.
Source Code
;; Defined in /usr/src/emacs/lisp/gnus/message.el.gz
(defun message-shorten-references (header references)
"Trim REFERENCES to be 21 Message-ID long or less, and fold them.
When sending via news, also check that the REFERENCES are less
than 988 characters long, and if they are not, trim them until
they are."
;; 21 is the number suggested by USAGE.
(let ((maxcount 21)
(count 0)
(cut 2)
refs)
(with-temp-buffer
(insert references)
(goto-char (point-min))
;; Cons a list of valid references. GNKSA says we must not include MIDs
;; with whitespace or missing brackets (7.a "Does not propagate broken
;; Message-IDs in original References").
(while (re-search-forward "<[^ <]+@[^ <]+>" nil t)
(push (match-string 0) refs))
(setq refs (nreverse refs)
count (length refs)))
;; If the list has more than MAXCOUNT elements, trim it by
;; removing the CUTth element and the required number of
;; elements that follow.
(when (> count maxcount)
(let ((surplus (- count maxcount)))
(message-shorten-1 refs cut surplus)
(cl-decf count surplus)))
;; When sending via news, make sure the total folded length will
;; be less than 998 characters. This is to cater to broken INN
;; 2.3 which counts the total number of characters in a header
;; rather than the physical line length of each line, as it should.
;;
;; This hack should be removed when it's believed than INN 2.3 is
;; no longer widely used.
;;
;; At this point the headers have not been generated, thus we use
;; message-this-is-news directly.
(when message-this-is-news
(while (< 998
(with-temp-buffer
(message-insert-header
header (mapconcat #'identity refs " "))
(buffer-size)))
(message-shorten-1 refs cut 1)))
;; Finally, collect the references back into a string and insert
;; it into the buffer.
(message-insert-header header (mapconcat #'identity refs " "))))