- (let ((file nil)
- (number (length sequence))
- (count 0)
- beg article)
- (nnmh-possibly-change-directory newsgroup)
- (while sequence
- (setq article (car sequence))
- (setq file
- (concat nnmh-current-directory (prin1-to-string article)))
- (if (and (file-exists-p file)
- (not (file-directory-p file)))
- (progn
- (insert (format "221 %d Article retrieved.\n" article))
- (setq beg (point))
- (insert-file-contents file)
- (goto-char beg)
- (if (search-forward "\n\n" nil t)
- (forward-char -1)
- (goto-char (point-max))
- (insert "\n\n"))
- (insert ".\n")
- (delete-region (point) (point-max))))
- (setq sequence (cdr sequence))
- (setq count (1+ count))
- (and (numberp nnmail-large-newsgroup)
- (> number nnmail-large-newsgroup)
- (zerop (% count 20))
- (message "nnmh: Receiving headers... %d%%"
- (/ (* count 100) number))))
-
- (and (numberp nnmail-large-newsgroup)
- (> number nnmail-large-newsgroup)
- (message "nnmh: Receiving headers... done"))
-
- ;; Fold continuation lines.
- (goto-char 1)
- (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
- (replace-match " " t t))
- 'headers)))
-
-(defun nnmh-open-server (host &optional service)
- "Open nnmh mail backend."
- (setq nnmh-status-string "")
- (nnmh-open-server-internal host service))
-
-(defun nnmh-close-server (&optional server)
- "Close news server."
- (nnmh-close-server-internal))
-
-(fset 'nnmh-request-quit (symbol-function 'nnmh-close-server))
-
-(defun nnmh-server-opened (&optional server)
- "Return server process status, T or NIL.
-If the stream is opened, return T, otherwise return NIL."
- (and nntp-server-buffer
- (get-buffer nntp-server-buffer)))
-
-(defun nnmh-status-message ()
- "Return server status response as string."
- nnmh-status-string)
-
-(defun nnmh-request-article (id &optional newsgroup server buffer)
- "Select article by message ID (or number)."
- (nnmh-possibly-change-directory newsgroup)
+ (let* ((file nil)
+ (number (length articles))
+ (large (and (numberp nnmail-large-newsgroup)
+ (> number nnmail-large-newsgroup)))
+ (count 0)
+ (file-name-coding-system nnmail-pathname-coding-system)
+ beg article)
+ (nnmh-possibly-change-directory newsgroup server)
+ ;; We don't support fetching by Message-ID.
+ (if (stringp (car articles))
+ 'headers
+ (while articles
+ (when (and (file-exists-p
+ (setq file (concat (file-name-as-directory
+ nnmh-current-directory)
+ (int-to-string
+ (setq article (pop articles))))))
+ (not (file-directory-p file)))
+ (insert (format "221 %d Article retrieved.\n" article))
+ (setq beg (point))
+ (nnheader-insert-head file)
+ (goto-char beg)
+ (if (search-forward "\n\n" nil t)
+ (forward-char -1)
+ (goto-char (point-max))
+ (insert "\n\n"))
+ (insert ".\n")
+ (delete-region (point) (point-max)))
+ (setq count (1+ count))
+
+ (and large
+ (zerop (% count 20))
+ (nnheader-message 5 "nnmh: Receiving headers... %d%%"
+ (/ (* count 100) number))))
+
+ (when large
+ (nnheader-message 5 "nnmh: Receiving headers...done"))
+
+ (nnheader-fold-continuation-lines)
+ 'headers))))
+
+(deffoo nnmh-open-server (server &optional defs)
+ (nnoo-change-server 'nnmh server defs)
+ (when (not (file-exists-p nnmh-directory))
+ (condition-case ()
+ (make-directory nnmh-directory t)
+ (error t)))
+ (cond
+ ((not (file-exists-p nnmh-directory))
+ (nnmh-close-server)
+ (nnheader-report 'nnmh "Couldn't create directory: %s" nnmh-directory))
+ ((not (file-directory-p (file-truename nnmh-directory)))
+ (nnmh-close-server)
+ (nnheader-report 'nnmh "Not a directory: %s" nnmh-directory))
+ (t
+ (nnheader-report 'nnmh "Opened server %s using directory %s"
+ server nnmh-directory)
+ t)))
+
+(deffoo nnmh-request-article (id &optional newsgroup server buffer)
+ (nnmh-possibly-change-directory newsgroup server)