Function: message-insert-formatted-citation-line

message-insert-formatted-citation-line is a byte-compiled function defined in message.el.gz.

Signature

(message-insert-formatted-citation-line &optional FROM DATE TZ)

Documentation

Function that inserts a formatted citation line.

The optional FROM, and DATE are strings containing the contents of the From header and the Date header respectively.

The optional TZ is omitted or nil for Emacs local time, t for Universal Time, wall for system wall clock time, or a string as in the TZ environment variable. It can also be a list (as from current-time-zone) or an integer (as from decode-time) applied without consideration for daylight saving time.

See message-citation-line-format.

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/message.el.gz
(defun message-insert-formatted-citation-line (&optional from date tz)
  "Function that inserts a formatted citation line.
The optional FROM, and DATE are strings containing the contents of
the From header and the Date header respectively.

The optional TZ is omitted or nil for Emacs local time, t for
Universal Time, `wall' for system wall clock time, or a string as
in the TZ environment variable.  It can also be a list (as from
`current-time-zone') or an integer (as from `decode-time')
applied without consideration for daylight saving time.

See `message-citation-line-format'."
  ;; The optional args are for testing/debugging.  They will disappear later.
  ;; Example:
  ;; (with-temp-buffer
  ;;   (message-insert-formatted-citation-line
  ;;    "John Doe <john.doe@example.invalid>"
  ;;    (message-make-date))
  ;;   (buffer-string))
  (when (or message-reply-headers (and from date))
    (unless from
      (setq from (mail-header-from message-reply-headers)))
    (let* ((data (ignore-errors
                   (funcall (or (bound-and-true-p
                                 gnus-extract-address-components)
                                #'mail-extract-address-components)
                            from)))
	   (name (car data))
	   (fname name)
	   (lname name)
           (net (cadr data))
           (name-or-net (or name net from))
	   (time
            (when (string-match-p "%[^FLNfn]" message-citation-line-format)
	      (cond ((numberp (car-safe date)) date) ;; backward compatibility
		    (date (gnus-date-get-time date))
		    (t
		     (gnus-date-get-time
		      (setq date (mail-header-date message-reply-headers)))))))
	   (tz (or tz
		   (when (stringp date)
		     (nth 8 (parse-time-string date)))))
           spec)
      (when (stringp name)
        ;; Guess first name and last name:
        (let* ((names (seq-filter
                       (lambda (s)
                         (string-match-p (rx bos (+ (in word ?. ?-)) eos) s))
                       (split-string name "[ \t]+")))
               (count (length names)))
          (cond ((= count 1)
                 (setq fname (car names)
                       lname ""))
                ((or (= count 2) (= count 3))
                 (setq fname (car names)
                       lname (string-join (cdr names) " ")))
                ((> count 3)
                 (setq fname (string-join (butlast names (- count 2))
                                          " ")
                       lname (string-join (nthcdr 2 names) " "))))
          (when (string-match "\\(.*\\),\\'" fname)
            (let ((newlname (match-string 1 fname)))
              (setq fname lname lname newlname)))))
      ;; The following letters are not used in `format-time-string':
      (push (cons ?E "<E>") spec)
      (push (cons ?F (or fname name-or-net)) spec)
      ;; We might want to use "" instead of "<X>" later.
      (push (cons ?J "<J>") spec)
      (push (cons ?K "<K>") spec)
      (push (cons ?L lname) spec)
      (push (cons ?N name-or-net) spec)
      (push (cons ?O "<O>") spec)
      (push (cons ?P "<P>") spec)
      (push (cons ?Q "<Q>") spec)
      (push (cons ?f from) spec)
      (push (cons ?i "<i>") spec)
      (push (cons ?n net) spec)
      (push (cons ?o "<o>") spec)
      (push (cons ?q "<q>") spec)
      (push (cons ?t "<t>") spec)
      (push (cons ?v "<v>") spec)
      ;; Delegate the rest to `format-time-string':
      (dolist (c (nconc (number-sequence ?A ?Z)
                        (number-sequence ?a ?z)))
        (unless (assq c spec)
          (push (cons c (condition-case nil
                            (format-time-string (format "%%%c" c) time tz)
                          (error (format ">%c<" c))))
                spec)))
      (insert (format-spec message-citation-line-format spec)))
    (newline)))