;;; 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."
;; 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))
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.
- (mail-position-on-field "References")
- ;; Fold long references line to follow RFC1036.
- (let ((begin (gnus-point-at-bol))
- (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))))))
+ (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)