
(defvar nntp/rcs-revision "$Revision: 1.10 $")

(provide (quote nntp))

(require (quote backquote))

(require (quote chat))

(or (fboundp (quote open-network-stream)) (require (quote tcp)))

(or (fboundp (quote last)) (defun last (x) "Returns the last link in the list LIST." (while (cdr x) (setq x (cdr x))) x))

(defvar nntp/default-nntp-port "nntp" "\
The default tcp port to use for nntp connections.")

(defvar nntp/connection nil "\
The current NNTP connection.")

(defvar nntp/error-message nil "\
The error message from the last NNTP command.  'nil if no error.")

(defvar nntp/can-xover t "\
Does this server understand the XOVER command?")

(defvar nntp-version (concat "flee/nntp " (substring nntp/rcs-revision 10)))

(defvar nntp-server-buffer nil "\
Buffer that GNUS looks at when it wants data.")

(defun nntp-open-server (host service) "\
Start a connection to the given HOST and SERVICE.  Returns true
if successful." (byte-code "† 	‰ˆÃ‰ˆÅ‰ˆÊË!‰ˆÌ!ˆÍÎ$‰ˆÏÐ\"ˆÑ!ˆÒ 		Ó=†B 	Ô=)‡" [service nntp/default-nntp-port nntp/error-message nil nntp/can-xover t nntp-server-buffer nntp/connection host code generate-new-buffer "*nntp*" buffer-flush-undo open-network-stream "nntp" set-process-sentinel nntp/sentinel process-kill-without-query nntp/response 200 201] 8))

(defun nntp-server-opened nil "\
Are we currently connected?" (byte-code "…	 Á!Â>‡" [nntp/connection process-status (run open)] 3))

(defun nntp-close-server nil "\
Terminate the connection.  Returns nothing." (byte-code "	Ä‰ˆÄ‰ˆ… Å!ˆ
… Æ
!*‡" [proc nntp/connection buffer nntp-server-buffer nil delete-process kill-buffer] 3))

(defun nntp-status-message nil "\
Returns the error message from the last NNTP request." (byte-code "† Á‡" [nntp/error-message "okay"] 1))

(defun nntp-request-list nil "\
Retrieve the list of newsgroups into 'nntp-server-buffer.
Returns true if successful." (byte-code "ÀÁ!ˆÂ Ã=… Ä ‡" [nntp/command "LIST" nntp/response 215 nntp/wait-for-text] 4))

(defun nntp-request-group (group) "\
Select group GROUP.  Returns true if successful." (byte-code "ÁÂ\"ˆÃ Ä=‡" [group nntp/command "GROUP" nntp/response 211] 4))

(defun nntp-request-article (id) "\
Retrieve article ID (either a number or a message-id) into
'nntp-server-buffer.  Returns true if successful." (byte-code "ÁÂ\"ˆÃ Ä=… Å ‡" [id nntp/command "ARTICLE" nntp/response 220 nntp/get-text] 4))

(defun nntp-request-post nil "\
Modify and post the current buffer.  Returns true if successful." (byte-code "ÄÅ!ˆÆ Ç=…\" ÁÈŽÉ ˆÊ
ed#ˆÃ‰ˆÆ Ë=))‡" [finished nil nntp/connection t nntp/command "POST" nntp/response 340 ((byte-code "† Ã	Ä\"† Â‡" [finished nntp/connection nil process-send-string "
.
"] 3)) nntp/unix-to-smtp-text process-send-region 240] 7))

(defun nntp-retrieve-headers (sequence) "\
Returns the header data for SEQUENCE in the current group.
SEQUENCE is a sorted list of article numbers.
XXX describe the return value." (byte-code "…% ÂÄÅ!ˆ… Æ!‰ˆ?… Ç!‰ˆÄÈ!ˆ	)‡" [sequence result nil nntp/can-xover message "retrieving..." nntp/try-xover nntp/headers "retrieving...done"] 5))

(defun nntp/sentinel (proc delta) (byte-code "À † ÁÂ!‡" [nntp-server-opened error "NNTP connection closed."] 3))

(defun nntp/clear nil (byte-code "Á!‡" [nntp/connection chat/delete-pending-data] 2))

(defun nntp/command (&rest strings) "\
Start a new NNTP command." (byte-code "Â ˆÃÄÅ	Æ#ÇP\"‡" [nntp/connection strings nntp/clear process-send-string mapconcat identity " " "
"] 7))

(defun nntp/response nil "\
Wait for an NNTP response and return the response code.  Also sets
'nntp/error-message." (byte-code "Å!ˆÆÇ	\"ˆŠÈ	!qˆŒÉe
\"ˆÊËeeÌ\\\"!ÍX…, ËeÎ\\dÏZ\"‰ˆ))Ðe
\"ˆ)‡" [nntp-server-buffer nntp/connection chat/data-marker code nntp/error-message buffer-flush-undo chat/wait-for-string "
" process-buffer narrow-to-region string-to-int buffer-substring 3 400 4 2 delete-region] 11))

(defun nntp/wait-for-text nil "\
Wait for an NNTP text response.  Returns true." (byte-code "Á!‡" [nntp/connection chat/wait-for-dot-crlf] 2))

(defun nntp/get-text nil "\
Wait for an NNTP text response and convert it to Unix text format.
Returns true." (byte-code "Â ˆŠqˆÃ )ˆÁ‡" [nntp-server-buffer t nntp/wait-for-text nntp/smtp-to-unix-text] 3))

(defun nntp/smtp-to-unix-text nil "\
Convert the current buffer from SMTP text format to Unix text
format.  Modifies point.  Returns nothing." (byte-code "ebˆm?…% gÀ=… ÁÂ!ˆÃ ˆhÄ=… ÁÅ!ˆÆ ˆ‚ ˆÇ ˆhÈ=…2 ÁÂ!‡" [46 delete-char 1 end-of-line 13 -1 forward-char backward-char 10] 7))

(defun nntp/unix-to-smtp-text nil "\
Convert the current buffer form Unix text format to SMTP text
format.  Modifies point.  Returns nothing." (byte-code "ebˆm?… gÀ=… ÀcˆÁ ˆÂcˆÃ ˆ‚ ˆo†* hÄ=†* ÅcˆÆc‡" [46 end-of-line 13 forward-line 10 "
" ".
"] 4))

(defun nntp/try-xover (sequence) "\
Try using the XOVER command to retrieve headers." (byte-code "	@Ç	!@ÈÉÊ!ËÊ
!Q\"ˆÌ Í=ƒ8 Î!ˆŠÏ!qˆŒÐe\"ˆÑ	!)Òe\"ˆ)‚= Æ‰ˆÆ*‡" [lo sequence hi nntp/connection chat/data-marker nntp/can-xover nil last nntp/command "XOVER" int-to-string "-" nntp/response 224 chat/wait-for-dot-crlf process-buffer narrow-to-region nov/parse delete-region] 13))

(defmacro nov/skip-field nil (byte-code "À‡" [(search-forward "	" eol (quote end))] 1))

(defmacro nov/field nil (byte-code "À‡" [(buffer-substring (point) (progn (nov/skip-field) (1- (point))))] 1))

(defmacro nov/read-integer nil "Read an integer from the current point at the buffer." (byte-code "À‡" [(string-to-int (buffer-substring (point) (progn (skip-chars-forward "0-9") (point))))] 1))

(defun nov/parse (sequence) "\
Parse the news overview data in the current buffer, and return a
list of headers that match SEQUENCE (see 'nntp-retrieve-headers)." (byte-code "ÁÁÁÁebˆ… m?…å ÇÈ`ÉÊ!ˆ`\"!‰ˆ…) @W…4 A‰ˆ‚! ˆ…= @=…Þ A‰ˆŠË ˆ`‰)ˆÌÍÁ\"‰ˆ
ÎIˆÏ ˆ
ÐÈ`ÑÒÓ#ˆ`S\"Iˆ
ÔÈ`ÑÒÓ#ˆ`S\"Iˆ
ÕÈ`ÑÒÓ#ˆ`S\"Iˆ
ÖÈ`ÑÒÓ#ˆ`S\"Iˆ
×È`ÑÒÓ#ˆ`S\"IˆÑÒÓ#ˆ
ØÇÈ`ÑÒÓ#ˆ`S\"!IˆÙ ˆÑÚÆ#…Ø 
ÛÈ`ÑÒÓ#ˆ`S\"Iˆ
B‰ˆÜ ˆ‚ ˆÝ!‰ˆ,‡" [number nil header headers eol sequence t string-to-int buffer-substring skip-chars-forward "0-9" end-of-line make-vector 8 0 forward-char 1 search-forward "	" end 2 5 6 7 4 backward-char "	xref: " 3 forward-line nreverse] 31))

(defun nntp/add-to-hook (hook-name value) (byte-code "ÁÄ
!… 
J‰ˆÅ!†% … 9†% <…% @Æ=…, C‰ˆ>†8 B‰ˆ
L)‡" [hook nil hook-name value boundp subrp lambda] 4))

(nntp/add-to-hook (quote gnus-Article-prepare-hook) (quote nntp/article-get-xrefs))

(defvar gnus-current-headers nil)

(defun nntp/article-get-xrefs nil "\
Fill in the Xref value in 'gnus-current-headers, if necessary.
This is meant to be called in 'gnus-Article-prepare-hook." (byte-code "ÄH†D ÂebˆÅÆÂÇ#ˆŒÈe`\"ˆebˆÉg!Ê=…% ËÌ!†- ÅÍÂÃ#…B ÎÏ!bˆÐ ˆÄÑ`Ò ˆ`\"I))‡" [gnus-current-headers case-fold-search nil t 3 search-forward "

" end narrow-to-region downcase 120 looking-at "Xref:" "
Xref:" match-end 0 forward-char buffer-substring end-of-line] 13))

(defun nntp/headers (sequence) (byte-code "Á ˆÂÃ!ˆÄ!ˆÂÅ!ˆÆ!‡" [sequence nntp/clear message "request..." nntp/send-head-requests "parsing..." nntp/parse-headers] 6))

(defun nntp/send-head-requests (sequence) (byte-code "… Â ˆÃ	Ä@ÅQ\"ˆA‰ˆ‚  ‡" [sequence nntp/connection accept-process-output process-send-string "HEAD " "
"] 7))

(defun nntp/parse-headers (sequence) (byte-code "ÁÁÁ…d ÇÈ\"ˆŠÉ!qˆŒÊe\"ˆËÌeeÍ\\\"!‰)Îe\"ˆ)ˆ
Ï=ƒY Ð!ˆŠÉ!qˆŒÊe\"ˆÑ@!B‰)Îe\"ˆ)‚[ Ò ˆA‰ˆ‚ ˆÓ!+‡" [headers nil code number sequence nntp/connection chat/data-marker chat/wait-for-string "
" process-buffer narrow-to-region string-to-int buffer-substring 4 delete-region 221 chat/wait-for-dot-crlf nntp/parse-header forward-line nreverse] 15))

(defun nntp/header-value nil (byte-code "ÀÁ!bˆÂÃ!ˆÄ`Å ˆhÆ=… ÇÈ!ˆÉ ˆgÊ>…/ ÇÈ!ˆÇË!ˆÌcˆ‚ ˆ`S\"‡" [match-end 0 skip-chars-forward "	 " buffer-substring end-of-line 13 delete-char -1 forward-char (9 32) 1 32] 11))

(defun nntp/parse-header (number) (byte-code "ÆÇÁ\"ÃÁÈIˆÉÈIˆm?…— ÊË!?ƒ$ Ì ‚“ Íg!Î=ƒ4 ÏÐ I‚“ Íg!Ñ=ƒD ÒÐ I‚“ Íg!Ó=ƒT ÔÐ I‚“ Íg!Õ=ƒf ÉÖÐ !I‚“ Íg!×=ƒv ØÐ I‚“ Íg!Ù=ƒ† ÚÐ I‚“ Íg!Û=…“ ÜÐ Iˆ‚ ˆ+‡" [header nil case-fold-search t fields number make-vector 8 0 4 looking-at "subject:\\|from:\\|xref:\\|lines:\\|date:\\|message-id:\\|references:" forward-line downcase 115 1 nntp/header-value 102 2 120 3 108 string-to-int 100 5 109 6 114 7] 22))
