Function: nntp-find-group-and-number

nntp-find-group-and-number is a byte-compiled function defined in nntp.el.gz.

Signature

(nntp-find-group-and-number &optional GROUP)

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/nntp.el.gz
(defun nntp-find-group-and-number (&optional group)
  (with-current-buffer nntp-server-buffer
    (save-restriction
      ;; FIXME: This is REALLY FISHY: set-buffer after save-restriction?!?
      (narrow-to-region (goto-char (point-min))
			(or (search-forward "\n\n" nil t) (point-max)))
      (goto-char (point-min))
      ;; We first find the number by looking at the status line.
      (let ((number (and (looking-at "2[0-9][0-9] +\\([0-9]+\\) ")
			 (string-to-number
			  (buffer-substring (match-beginning 1)
					    (match-end 1)))))
	    newsgroups xref)
	(and number (zerop number) (setq number nil))
	(if number
	    ;; Then we find the group name.
	    (setq group
		  (cond
		   ;; If there is only one group in the Newsgroups
		   ;; header, then it seems quite likely that this
		   ;; article comes from that group, I'd say.
		   ((and (setq newsgroups
			       (mail-fetch-field "newsgroups"))
			 (not (string-search "," newsgroups)))
		    newsgroups)
		   ;; If there is more than one group in the
		   ;; Newsgroups header, then the Xref header should
		   ;; be filled out.  We hazard a guess that the group
		   ;; that has this article number in the Xref header
		   ;; is the one we are looking for.  This might very
		   ;; well be wrong if this article happens to have
		   ;; the same number in several groups, but that's
		   ;; life.
		   ((and (setq xref (mail-fetch-field "xref"))
			 number
			 (string-match
			  (format "\\([^ :]+\\):%d" number) xref))
		    (match-string 1 xref))
		   (t "")))
	  (cond
	   ((and (not nntp-xref-number-is-evil)
		 (setq xref (mail-fetch-field "xref"))
		 (string-match
		  (if group
		      (concat "\\(" (regexp-quote group) "\\):\\([0-9]+\\)")
		    "\\([^ :]+\\):\\([0-9]+\\)")
		  xref))
	    (setq group (match-string 1 xref)
		  number (string-to-number (match-string 2 xref))))
	   ((and (setq newsgroups
		       (mail-fetch-field "newsgroups"))
		 (not (string-search "," newsgroups)))
	    (setq group newsgroups))
	   (group)
	   (t (setq group ""))))
	(when (string-match "\r" group)
	  (setq group (substring group 0 (match-beginning 0))))
	(cons group number)))))