;;; Code:
+(require 'mail-utils)
+(require 'sendmail)
+(eval-when-compile (require 'cl))
+
+(defvar nnheader-max-head-length 4096
+ "*Max length of the head of articles.")
+
(defalias 'nntp-header-number 'mail-header-number)
(defmacro mail-header-number (header)
"Return article number in HEADER."
"Set article author of HEADER to FROM."
(` (aset (, header) 2 (, from))))
-(defalias 'nntp-header-xref 'mail-header-xref)
-(defmacro mail-header-xref (header)
- "Return xref string in HEADER."
- (` (aref (, header) 8)))
-
-(defalias 'nntp-set-header-xref 'mail-header-set-xref)
-(defmacro mail-header-set-xref (header xref)
- "Set article xref of HEADER to xref."
- (` (aset (, header) 8 (, xref))))
-
-(defalias 'nntp-header-lines 'mail-header-lines)
-(defmacro mail-header-lines (header)
- "Return lines in HEADER."
- (` (aref (, header) 7)))
-
-(defalias 'nntp-set-header-lines 'mail-header-set-lines)
-(defmacro mail-header-set-lines (header lines)
- "Set article lines of HEADER to LINES."
- (` (aset (, header) 7 (, lines))))
-
(defalias 'nntp-header-date 'mail-header-date)
(defmacro mail-header-date (header)
"Return date in HEADER."
"Set number of chars in article of HEADER to CHARS."
(` (aset (, header) 6 (, chars))))
+(defalias 'nntp-header-lines 'mail-header-lines)
+(defmacro mail-header-lines (header)
+ "Return lines in HEADER."
+ (` (aref (, header) 7)))
+
+(defalias 'nntp-set-header-lines 'mail-header-set-lines)
+(defmacro mail-header-set-lines (header lines)
+ "Set article lines of HEADER to LINES."
+ (` (aset (, header) 7 (, lines))))
+
+(defalias 'nntp-header-xref 'mail-header-xref)
+(defmacro mail-header-xref (header)
+ "Return xref string in HEADER."
+ (` (aref (, header) 8)))
+
+(defalias 'nntp-set-header-xref 'mail-header-set-xref)
+(defmacro mail-header-set-xref (header xref)
+ "Set article xref of HEADER to xref."
+ (` (aset (, header) 8 (, xref))))
+
+
;; Various cruft the backends and Gnus need to communicate.
(defvar nntp-server-buffer nil)
;; Read the head of an article.
(defun nnheader-insert-head (file)
- (let ((beg 0)
- (chop 1024))
- (while (and (eq chop (nth 1 (nnheader-insert-file-contents-literally
- file nil beg (setq beg (+ chop beg)))))
- (prog1 (not (search-backward "\n\n" nil t))
- (goto-char (point-max)))))))
+ (if (eq nnheader-max-head-length t)
+ ;; Just read the entire file.
+ (nnheader-insert-file-contents-literally file)
+ (let ((beg 0)
+ (chop 1024))
+ ;; Read 1K blocks until we find a separator.
+ (while (and (eq chop (nth 1 (nnheader-insert-file-contents-literally
+ file nil beg (setq beg (+ chop beg)))))
+ (prog1 (not (search-backward "\n\n" nil t))
+ (goto-char (point-max)))
+ (or (null nnheader-max-head-length)
+ (< beg nnheader-max-head-length)))))))
(defun nnheader-article-p ()
(goto-char (point-min))
(after-find-file error (not nowarn)))))
buf)))
+(defun nnheader-insert-references (references message-id)
+ (if (and (not references) (not message-id))
+ () ; This is illegal, but not all articles have Message-IDs.
+ ;; Fold long references line to follow RFC1036.
+ (mail-position-on-field "References")
+ (let ((begin (save-excursion (beginning-of-line) (point)))
+ (fill-column 78)
+ (fill-prefix "\t"))
+ (if references (insert references))
+ (if (and references message-id) (insert " "))
+ (if message-id (insert message-id))
+ ;; The region must end with a newline to fill the region
+ ;; without inserting extra newline.
+ (fill-region-as-paragraph begin (1+ (point))))))
+
+(defun nnheader-remove-header (header &optional is-regexp first)
+ "Remove HEADER.
+If FIRST, only remove the first instance if the header.
+Return the number of headers removed."
+ (goto-char (point-min))
+ (let ((regexp (if is-regexp header (concat "^" header ":")))
+ (number 0)
+ (case-fold-search t)
+ last)
+ (while (and (re-search-forward regexp nil t)
+ (not last))
+ (incf number)
+ (when first
+ (setq last t))
+ (delete-region
+ (match-beginning 0)
+ ;; There might be a continuation header, so we have to search
+ ;; until we find a new non-continuation line.
+ (if (re-search-forward "^[^ \t]" nil t)
+ (match-beginning 0)
+ (point-max))))
+ number))
+
+(defun nnheader-set-temp-buffer (name)
+ (set-buffer (get-buffer-create name))
+ (buffer-disable-undo (current-buffer))
+ (erase-buffer))
+
+(defvar jka-compr-compression-info-list)
+(defvar nnheader-numerical-files
+ (if (boundp 'jka-compr-compression-info-list)
+ (concat "\\([0-9]+\\)\\("
+ (mapconcat (lambda (i) (aref i 0))
+ jka-compr-compression-info-list "\\|")
+ "\\)?")
+ "[0-9]+$")
+ "Regexp that match numerical files.")
+
+(defvar nnheader-numerical-short-files (concat "^" nnheader-numerical-files)
+ "Regexp that matches numerical file names.")
+
+(defvar nnheader-numerical-full-files (concat "/" nnheader-numerical-files)
+ "Regexp that matches numerical full file paths.")
+
+(defun nnheader-file-to-number (file)
+ (if (not (boundp 'jka-compr-compression-info-list))
+ (string-to-int file)
+ (string-match nnheader-numerical-short-files file)
+ (match-string 1 file)))
+
+(defun nnheader-directory-articles (dir)
+ (mapcar 'nnheader-file-to-number
+ (directory-files dir nil nnheader-numerical-short-files t)))
(provide 'nnheader)