;;; Code:
-(defalias 'nntp-header-number 'header-number)
-(defmacro header-number (header)
+(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."
(` (aref (, header) 0)))
-(defalias 'nntp-set-header-number 'header-set-number)
-(defmacro header-set-number (header number)
+(defalias 'nntp-set-header-number 'mail-header-set-number)
+(defmacro mail-header-set-number (header number)
"Set article number of HEADER to NUMBER."
(` (aset (, header) 0 (, number))))
-(defalias 'nntp-header-subject 'header-subject)
-(defmacro header-subject (header)
+(defalias 'nntp-header-subject 'mail-header-subject)
+(defmacro mail-header-subject (header)
"Return subject string in HEADER."
(` (aref (, header) 1)))
-(defalias 'nntp-set-header-subject 'header-set-subject)
-(defmacro header-set-subject (header subject)
+(defalias 'nntp-set-header-subject 'mail-header-set-subject)
+(defmacro mail-header-set-subject (header subject)
"Set article subject of HEADER to SUBJECT."
(` (aset (, header) 1 (, subject))))
-(defalias 'nntp-header-from 'header-from)
-(defmacro header-from (header)
+(defalias 'nntp-header-from 'mail-header-from)
+(defmacro mail-header-from (header)
"Return author string in HEADER."
(` (aref (, header) 2)))
-(defalias 'nntp-set-header-from 'header-set-from)
-(defmacro header-set-from (header from)
+(defalias 'nntp-set-header-from 'mail-header-set-from)
+(defmacro mail-header-set-from (header from)
"Set article author of HEADER to FROM."
(` (aset (, header) 2 (, from))))
-(defalias 'nntp-header-xref 'header-xref)
-(defmacro header-xref (header)
- "Return xref string in HEADER."
- (` (aref (, header) 8)))
-
-(defalias 'nntp-set-header-xref 'header-set-xref)
-(defmacro header-set-xref (header xref)
- "Set article xref of HEADER to xref."
- (` (aset (, header) 8 (, xref))))
-
-(defalias 'nntp-header-lines 'header-lines)
-(defmacro header-lines (header)
- "Return lines in HEADER."
- (` (aref (, header) 7)))
-
-(defalias 'nntp-set-header-lines 'header-set-lines)
-(defmacro header-set-lines (header lines)
- "Set article lines of HEADER to LINES."
- (` (aset (, header) 7 (, lines))))
-
-(defalias 'nntp-header-date 'header-date)
-(defmacro header-date (header)
+(defalias 'nntp-header-date 'mail-header-date)
+(defmacro mail-header-date (header)
"Return date in HEADER."
(` (aref (, header) 3)))
-(defalias 'nntp-set-header-date 'header-set-date)
-(defmacro header-set-date (header date)
+(defalias 'nntp-set-header-date 'mail-header-set-date)
+(defmacro mail-header-set-date (header date)
"Set article date of HEADER to DATE."
(` (aset (, header) 3 (, date))))
-(defalias 'nntp-header-id 'header-id)
-(defmacro header-id (header)
+(defalias 'nntp-header-id 'mail-header-id)
+(defmacro mail-header-id (header)
"Return Id in HEADER."
(` (aref (, header) 4)))
-(defalias 'nntp-set-header-id 'header-set-id)
-(defmacro header-set-id (header id)
+(defalias 'nntp-set-header-id 'mail-header-set-id)
+(defmacro mail-header-set-id (header id)
"Set article Id of HEADER to ID."
(` (aset (, header) 4 (, id))))
-(defalias 'nntp-header-references 'header-references)
-(defmacro header-references (header)
+(defalias 'nntp-header-references 'mail-header-references)
+(defmacro mail-header-references (header)
"Return references in HEADER."
(` (aref (, header) 5)))
-(defalias 'nntp-set-header-references 'header-set-references)
-(defmacro header-set-references (header ref)
+(defalias 'nntp-set-header-references 'mail-header-set-references)
+(defmacro mail-header-set-references (header ref)
"Set article references of HEADER to REF."
(` (aset (, header) 5 (, ref))))
-(defalias 'nntp-header-chars 'header-chars)
-(defmacro header-chars (header)
+(defalias 'nntp-header-chars 'mail-header-chars)
+(defmacro mail-header-chars (header)
"Return number of chars of article in HEADER."
(` (aref (, header) 6)))
-(defalias 'nntp-set-header-chars 'header-set-chars)
-(defmacro header-set-chars (header chars)
+(defalias 'nntp-set-header-chars 'mail-header-set-chars)
+(defmacro mail-header-set-chars (header chars)
"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))
to advanced Emacs features, such as file-name-handlers, format decoding,
find-file-hooks, etc.
This function ensures that none of these modifications will take place."
- (let ((file-name-handler-alist nil)
+ (let ( ; (file-name-handler-alist nil)
(format-alist nil)
(after-insert-file-functions nil)
(find-buffer-file-type-function
(truename (abbreviate-file-name (file-truename filename)))
(number (nthcdr 10 (file-attributes truename)))
;; Find any buffer for a file which has same truename.
- (other (and (not buf) (find-buffer-visiting filename)))
+ (other (and (not buf)
+ (if (fboundp 'find-buffer-visiting)
+ (find-buffer-visiting filename)
+ (get-file-buffer filename))))
error)
;; Let user know if there is a buffer with the same truename.
(if other
(message "%s and %s are the same file"
filename (buffer-file-name other)))
;; Optionally also find that buffer.
- (if (or find-file-existing-other-name find-file-visit-truename)
+ (if (or (and (boundp 'find-file-existing-other-name)
+ find-file-existing-other-name)
+ find-file-visit-truename)
(setq buf other))))
(if buf
(or nowarn
(buffer-name buf))
(format
(if (buffer-modified-p buf)
- "File %s changed on disk. Discard your edits? "
- "File %s changed on disk. Reread from disk? ")
+ "File %s changed on disk. Discard your edits? "
+ "File %s changed on disk. Reread from disk? ")
(file-name-nondirectory filename))
(format
(if (buffer-modified-p buf)
- "File %s changed on disk. Discard your edits in %s? "
- "File %s changed on disk. Reread from disk into %s? ")
+ "File %s changed on disk. Discard your edits in %s? "
+ "File %s changed on disk. Reread from disk into %s? ")
(file-name-nondirectory filename)
(buffer-name buf))))
(save-excursion
;;; (message "Symbolic link to file in buffer %s"
;;; (buffer-name linked-buf))))
(setq buf (create-file-buffer filename))
-;; (set-buffer-major-mode buf)
+ ;; (set-buffer-major-mode buf)
(set-buffer buf)
(erase-buffer)
(if rawfile
(insert-file-contents filename t)
(file-error
;; Run find-file-not-found-hooks until one returns non-nil.
- (or t; (run-hook-with-args-until-success 'find-file-not-found-hooks)
+ (or t ; (run-hook-with-args-until-success 'find-file-not-found-hooks)
;; If they fail too, set error.
(setq error t)))))
;; Find the file's truename, and maybe use that as visited name.
(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)