;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;; Code:
-(require 'gnus-msg)
+(require 'gnus-load)
+(require 'gnus-art)
+(require 'message)
+(require 'gnus-start)
(require 'gnus)
+(require 'gnus-range)
;;; User Variables:
(defvar gnus-soup-packer "tar cf - %s | gzip > $HOME/Soupout%d.tgz"
"Format string command for packing a SOUP packet.
The SOUP files will be inserted where the %s is in the string.
-This string MUST contain both %s and %d. The file number will be
+This string MUST contain both %s and %d. The file number will be
inserted where %d appears.")
(defvar gnus-soup-unpacker "gunzip -c %s | tar xvf -"
(defvar gnus-soup-packet-regexp "Soupin"
"*Regular expression matching SOUP REPLIES packets in `gnus-soup-packet-directory'.")
+(defvar gnus-soup-ignored-headers "^Xref:"
+ "*Regexp to match headers to be removed when brewing SOUP packets.")
+
;;; Internal Variables:
(defvar gnus-soup-encoding-type ?n
(defvar gnus-soup-index-type ?c
"*Soup index type.
`n' means no index file and `c' means standard Cnews overview
-format.")
+format.")
(defvar gnus-soup-areas nil)
(defvar gnus-soup-last-prefix nil)
;;; Access macros:
(defmacro gnus-soup-area-prefix (area)
- (` (aref (, area) 0)))
+ `(aref ,area 0))
+(defmacro gnus-soup-set-area-prefix (area prefix)
+ `(aset ,area 0 ,prefix))
(defmacro gnus-soup-area-name (area)
- (` (aref (, area) 1)))
+ `(aref ,area 1))
(defmacro gnus-soup-area-encoding (area)
- (` (aref (, area) 2)))
+ `(aref ,area 2))
(defmacro gnus-soup-area-description (area)
- (` (aref (, area) 3)))
+ `(aref ,area 3))
(defmacro gnus-soup-area-number (area)
- (` (aref (, area) 4)))
+ `(aref ,area 4))
(defmacro gnus-soup-area-set-number (area value)
- (` (aset (, area) 4 (, value))))
+ `(aset ,area 4 ,value))
(defmacro gnus-soup-encoding-format (encoding)
- (` (aref (, encoding) 0)))
+ `(aref ,encoding 0))
(defmacro gnus-soup-encoding-index (encoding)
- (` (aref (, encoding) 1)))
+ `(aref ,encoding 1))
(defmacro gnus-soup-encoding-kind (encoding)
- (` (aref (, encoding) 2)))
+ `(aref ,encoding 2))
(defmacro gnus-soup-reply-prefix (reply)
- (` (aref (, reply) 0)))
+ `(aref ,reply 0))
(defmacro gnus-soup-reply-kind (reply)
- (` (aref (, reply) 1)))
+ `(aref ,reply 1))
(defmacro gnus-soup-reply-encoding (reply)
- (` (aref (, reply) 2)))
+ `(aref ,reply 2))
;;; Commands:
(let ((packets (directory-files
gnus-soup-packet-directory t gnus-soup-packet-regexp)))
(while packets
- (and (gnus-soup-send-packet (car packets))
- (delete-file (car packets)))
+ (when (gnus-soup-send-packet (car packets))
+ (delete-file (car packets)))
(setq packets (cdr packets)))))
(defun gnus-soup-add-article (n)
(while articles
;; Find the header of the article.
(set-buffer gnus-summary-buffer)
- (setq headers (gnus-summary-article-header (car articles)))
- ;; Put the article in a buffer.
- (set-buffer tmp-buf)
- (gnus-request-article-this-buffer
- (car articles) gnus-newsgroup-name)
- (gnus-soup-store gnus-soup-directory prefix headers
- gnus-soup-encoding-type
- gnus-soup-index-type)
- (gnus-soup-area-set-number area
- (1+ (or (gnus-soup-area-number area) 0)))
+ (when (setq headers (gnus-summary-article-header (car articles)))
+ ;; Put the article in a buffer.
+ (set-buffer tmp-buf)
+ (when (gnus-request-article-this-buffer
+ (car articles) gnus-newsgroup-name)
+ (save-restriction
+ (message-narrow-to-head)
+ (message-remove-header gnus-soup-ignored-headers t))
+ (gnus-soup-store gnus-soup-directory prefix headers
+ gnus-soup-encoding-type
+ gnus-soup-index-type)
+ (gnus-soup-area-set-number
+ area (1+ (or (gnus-soup-area-number area) 0)))))
;; Mark article as read.
(set-buffer gnus-summary-buffer)
(gnus-summary-remove-process-mark (car articles))
(let ((groups (gnus-group-process-prefix n)))
(while groups
(gnus-group-remove-mark (car groups))
- (gnus-soup-group-brew (car groups))
+ (gnus-soup-group-brew (car groups) t)
(setq groups (cdr groups)))
(gnus-soup-save-areas)))
(let ((level (or level gnus-level-subscribed))
(newsrc (cdr gnus-newsrc-alist)))
(while newsrc
- (and (<= (nth 1 (car newsrc)) level)
- (gnus-soup-group-brew (car (car newsrc))))
+ (when (<= (nth 1 (car newsrc)) level)
+ (gnus-soup-group-brew (caar newsrc) t))
(setq newsrc (cdr newsrc)))
(gnus-soup-save-areas)))
;; Store the current buffer.
(defun gnus-soup-store (directory prefix headers format index)
;; Create the directory, if needed.
- (or (file-directory-p directory)
- (gnus-make-directory directory))
+ (gnus-make-directory directory)
(let* ((msg-buf (find-file-noselect
(concat directory prefix ".MSG")))
(idx-buf (if (= index ?n)
from head-line beg type)
(setq gnus-soup-buffers (cons msg-buf (delq msg-buf gnus-soup-buffers)))
(buffer-disable-undo msg-buf)
- (and idx-buf
- (progn
- (setq gnus-soup-buffers (cons idx-buf gnus-soup-buffers))
- (buffer-disable-undo idx-buf)))
+ (when idx-buf
+ (push idx-buf gnus-soup-buffers)
+ (buffer-disable-undo idx-buf))
(save-excursion
;; Make sure the last char in the buffer is a newline.
(goto-char (point-max))
- (or (= (current-column) 0)
- (insert "\n"))
+ (unless (= (current-column) 0)
+ (insert "\n"))
;; Find the "from".
(goto-char (point-min))
(setq from
- (mail-strip-quoted-names
+ (gnus-mail-strip-quoted-names
(or (mail-fetch-field "from")
(mail-fetch-field "really-from")
(mail-fetch-field "sender"))))
;; Return the MSG buf.
msg-buf)))
-(defun gnus-soup-group-brew (group)
+(defun gnus-soup-group-brew (group &optional not-all)
+ "Enter GROUP and add all articles to a SOUP package.
+If NOT-ALL, don't pack ticked articles."
(let ((gnus-expert-user t)
- (gnus-large-newsgroup nil))
- (and (gnus-summary-read-group group)
- (let ((gnus-newsgroup-processable
- (gnus-sorted-complement
- gnus-newsgroup-unreads
- (append gnus-newsgroup-dormant gnus-newsgroup-marked))))
- (gnus-soup-add-article nil)))
- (gnus-summary-exit)))
+ (gnus-large-newsgroup nil)
+ (entry (gnus-gethash group gnus-newsrc-hashtb)))
+ (when (or (null entry)
+ (eq (car entry) t)
+ (and (car entry)
+ (> (car entry) 0))
+ (and (not not-all)
+ (gnus-range-length (cdr (assq 'tick (gnus-info-marks
+ (nth 2 entry)))))))
+ (when (gnus-summary-read-group group nil t)
+ (setq gnus-newsgroup-processable
+ (reverse
+ (if (not not-all)
+ (append gnus-newsgroup-marked gnus-newsgroup-unreads)
+ gnus-newsgroup-unreads)))
+ (gnus-soup-add-article nil)
+ (gnus-summary-exit)))))
(defun gnus-soup-insert-idx (offset header)
;; [number subject from date id references chars lines xref]
(goto-char (point-max))
(insert
- (format "%d\t%s\t%s\t%s\t%s\t%s\t%d\t%s\t%s\t\n"
+ (format "%d\t%s\t%s\t%s\t%s\t%s\t%d\t%s\t\t\n"
offset
(or (mail-header-subject header) "(none)")
(or (mail-header-from header) "(nobody)")
(lambda (time) (int-to-string time))
(current-time) "-")))
(or (mail-header-references header) "")
- (or (mail-header-chars header) 0)
- (or (mail-header-lines header) "0")
- (or (mail-header-xref header) ""))))
+ (or (mail-header-chars header) 0)
+ (or (mail-header-lines header) "0"))))
(defun gnus-soup-save-areas ()
(gnus-soup-write-areas)
(if (not (buffer-name buf))
()
(set-buffer buf)
- (and (buffer-modified-p) (save-buffer))
+ (when (buffer-modified-p)
+ (save-buffer))
(kill-buffer (current-buffer)))))
(gnus-soup-write-prefixes)))
(defun gnus-soup-write-prefixes ()
- (let ((prefix gnus-soup-last-prefix))
+ (let ((prefixes gnus-soup-last-prefix)
+ prefix)
(save-excursion
- (while prefix
- (gnus-set-work-buffer)
- (insert (format "(setq gnus-soup-prev-prefix %d)\n"
- (cdr (car prefix))))
- (gnus-make-directory (car (car prefix)))
- (write-region (point-min) (point-max)
- (concat (car (car prefix))
- gnus-soup-prefix-file)
- nil 'nomesg)
- (setq prefix (cdr prefix))))))
+ (gnus-set-work-buffer)
+ (while (setq prefix (pop prefixes))
+ (erase-buffer)
+ (insert (format "(setq gnus-soup-prev-prefix %d)\n" (cdr prefix)))
+ (gnus-write-buffer (concat (car prefix) gnus-soup-prefix-file))))))
(defun gnus-soup-pack (dir packer)
(let* ((files (mapconcat 'identity
(string-to-int (gnus-soup-unique-prefix dir))
files)))
(dir (expand-file-name dir)))
- (or (file-directory-p dir)
- (gnus-make-directory dir))
+ (gnus-make-directory dir)
(setq gnus-soup-areas nil)
- (message "Packing %s..." packer)
- (if (zerop (call-process "sh" nil nil nil "-c"
+ (gnus-message 4 "Packing %s..." packer)
+ (if (zerop (call-process shell-file-name
+ nil nil nil shell-command-switch
(concat "cd " dir " ; " packer)))
(progn
- (call-process "sh" nil nil nil "-c"
+ (call-process shell-file-name nil nil nil shell-command-switch
(concat "cd " dir " ; rm " files))
- (message "Packing...done" packer))
+ (gnus-message 4 "Packing...done" packer))
(error "Couldn't pack packet."))))
(defun gnus-soup-parse-areas (file)
(buffer-disable-undo (current-buffer))
(goto-char (point-min))
(while (not (eobp))
- (setq areas
- (cons (vector (gnus-soup-field)
- (gnus-soup-field)
- (gnus-soup-field)
- (and (eq (preceding-char) ?\t)
- (gnus-soup-field))
- (and (eq (preceding-char) ?\t)
- (string-to-int (gnus-soup-field))))
- areas))
- (if (eq (preceding-char) ?\t)
- (beginning-of-line 2)))
+ (push (vector (gnus-soup-field)
+ (gnus-soup-field)
+ (gnus-soup-field)
+ (and (eq (preceding-char) ?\t)
+ (gnus-soup-field))
+ (and (eq (preceding-char) ?\t)
+ (string-to-int (gnus-soup-field))))
+ areas)
+ (when (eq (preceding-char) ?\t)
+ (beginning-of-line 2)))
(kill-buffer (current-buffer)))
areas))
(defun gnus-soup-parse-replies (file)
"Parse soup REPLIES file FILE.
The result is a of vectors, each containing one entry from the REPLIES
-file. The vector contain three strings, [prefix name encoding]."
+file. The vector contain three strings, [prefix name encoding]."
(let (replies)
(save-excursion
(set-buffer (find-file-noselect file))
(buffer-disable-undo (current-buffer))
(goto-char (point-min))
(while (not (eobp))
- (setq replies
- (cons (vector (gnus-soup-field) (gnus-soup-field)
- (gnus-soup-field))
- replies))
- (if (eq (preceding-char) ?\t)
- (beginning-of-line 2)))
+ (push (vector (gnus-soup-field) (gnus-soup-field)
+ (gnus-soup-field))
+ replies)
+ (when (eq (preceding-char) ?\t)
+ (beginning-of-line 2)))
(kill-buffer (current-buffer)))
replies))
(gnus-soup-parse-areas (concat gnus-soup-directory "AREAS")))))
(defun gnus-soup-write-areas ()
- "Write all areas to disk."
+ "Write the AREAS file."
(interactive)
- (if (not gnus-soup-areas)
- ()
- (save-excursion
- (set-buffer (find-file-noselect
- (concat gnus-soup-directory "AREAS")))
- (buffer-disable-undo (current-buffer))
- (erase-buffer)
+ (when gnus-soup-areas
+ (nnheader-temp-write (concat gnus-soup-directory "AREAS")
(let ((areas gnus-soup-areas)
area)
- (while areas
- (setq area (car areas)
- areas (cdr areas))
- (insert (format "%s\t%s\t%s%s\n"
- (gnus-soup-area-prefix area)
- (gnus-soup-area-name area)
- (gnus-soup-area-encoding area)
- (if (or (gnus-soup-area-description area)
- (gnus-soup-area-number area))
- (concat "\t" (or (gnus-soup-area-description
- area)
- "")
- (if (gnus-soup-area-number area)
- (concat "\t"
- (int-to-string
- (gnus-soup-area-number
- area)))
- "")) "")))))
- (write-region (point-min) (point-max)
- (concat gnus-soup-directory "AREAS") nil 'silent)
- (set-buffer-modified-p nil)
- (kill-buffer (current-buffer)))))
+ (while (setq area (pop areas))
+ (insert
+ (format
+ "%s\t%s\t%s%s\n"
+ (gnus-soup-area-prefix area)
+ (gnus-soup-area-name area)
+ (gnus-soup-area-encoding area)
+ (if (or (gnus-soup-area-description area)
+ (gnus-soup-area-number area))
+ (concat "\t" (or (gnus-soup-area-description
+ area) "")
+ (if (gnus-soup-area-number area)
+ (concat "\t" (int-to-string
+ (gnus-soup-area-number area)))
+ "")) ""))))))))
(defun gnus-soup-write-replies (dir areas)
- (or (file-directory-p dir)
- (gnus-make-directory dir))
- (save-excursion
- (set-buffer (find-file-noselect (concat dir "REPLIES")))
- (buffer-disable-undo (current-buffer))
- (erase-buffer)
+ "Write a REPLIES file in DIR containing AREAS."
+ (nnheader-temp-write (concat dir "REPLIES")
(let (area)
- (while areas
- (setq area (car areas)
- areas (cdr areas))
+ (while (setq area (pop areas))
(insert (format "%s\t%s\t%s\n"
(gnus-soup-reply-prefix area)
- (gnus-soup-reply-kind area)
- (gnus-soup-reply-encoding area)))))
- (write-region (point-min) (point-max) (concat dir "REPLIES") nil 'silent)
- (set-buffer-modified-p nil)
- (kill-buffer (current-buffer))))
+ (gnus-soup-reply-kind area)
+ (gnus-soup-reply-encoding area)))))))
(defun gnus-soup-area (group)
(gnus-soup-read-areas)
(while areas
(setq area (car areas)
areas (cdr areas))
- (if (equal (gnus-soup-area-name area) real-group)
- (setq result area)))
- (or result
- (setq result
- (vector (gnus-soup-unique-prefix)
- real-group
- (format "%c%c%c"
- gnus-soup-encoding-type
- gnus-soup-index-type
- (if (gnus-member-of-valid 'mail group) ?m ?n))
- nil nil)
- gnus-soup-areas (cons result gnus-soup-areas)))
+ (when (equal (gnus-soup-area-name area) real-group)
+ (setq result area)))
+ (unless result
+ (setq result
+ (vector (gnus-soup-unique-prefix)
+ real-group
+ (format "%c%c%c"
+ gnus-soup-encoding-type
+ gnus-soup-index-type
+ (if (gnus-member-of-valid 'mail group) ?m ?n))
+ nil nil)
+ gnus-soup-areas (cons result gnus-soup-areas)))
result))
(defun gnus-soup-unique-prefix (&optional dir)
gnus-soup-prev-prefix)
(if entry
()
- (and (file-exists-p (concat dir gnus-soup-prefix-file))
- (condition-case nil
- (load (concat dir gnus-soup-prefix-file) nil t t)
- (error nil)))
- (setq gnus-soup-last-prefix
- (cons (setq entry (cons dir (or gnus-soup-prev-prefix 0)))
- gnus-soup-last-prefix)))
+ (when (file-exists-p (concat dir gnus-soup-prefix-file))
+ (condition-case nil
+ (load (concat dir gnus-soup-prefix-file) nil t t)
+ (error nil)))
+ (push (setq entry (cons dir (or gnus-soup-prev-prefix 0)))
+ gnus-soup-last-prefix))
(setcdr entry (1+ (cdr entry)))
(gnus-soup-write-prefixes)
(int-to-string (cdr entry))))
(defun gnus-soup-unpack-packet (dir unpacker packet)
+ "Unpack PACKET into DIR using UNPACKER.
+Return whether the unpacking was successful."
(gnus-make-directory dir)
- (message "Unpacking: %s" (format unpacker packet))
- (call-process
- "sh" nil nil nil "-c"
- (format "cd %s ; %s" (expand-file-name dir) (format unpacker packet)))
- (message "Unpacking...done"))
+ (gnus-message 4 "Unpacking: %s" (format unpacker packet))
+ (prog1
+ (zerop (call-process
+ shell-file-name nil nil nil shell-command-switch
+ (format "cd %s ; %s" (expand-file-name dir)
+ (format unpacker packet))))
+ (gnus-message 4 "Unpacking...done")))
(defun gnus-soup-send-packet (packet)
(gnus-soup-unpack-packet
beg end)
(cond
((/= (gnus-soup-encoding-format
- (gnus-soup-reply-encoding (car replies))) ?n)
+ (gnus-soup-reply-encoding (car replies)))
+ ?n)
(error "Unsupported encoding"))
((null msg-buf)
t)
(set-buffer msg-buf)
(goto-char (point-min))
(while (not (eobp))
- (or (looking-at "#! *rnews +\\([0-9]+\\)")
- (error "Bad header."))
+ (unless (looking-at "#! *rnews +\\([0-9]+\\)")
+ (error "Bad header."))
(forward-line 1)
(setq beg (point)
end (+ (point) (string-to-int
(search-forward "\n\n")
(forward-char -1)
(insert mail-header-separator)
+ (setq message-newsreader (setq message-mailer
+ (gnus-extended-version)))
(cond
((string= (gnus-soup-reply-kind (car replies)) "news")
- (message "Sending news message to %s..."
- (mail-fetch-field "newsgroups"))
+ (gnus-message 5 "Sending news message to %s..."
+ (mail-fetch-field "newsgroups"))
(sit-for 1)
- (gnus-inews-article))
+ (let ((message-syntax-checks
+ 'dont-check-for-anything-just-trust-me))
+ (funcall message-send-news-function)))
((string= (gnus-soup-reply-kind (car replies)) "mail")
- (message "Sending mail to %s..."
- (mail-fetch-field "to"))
+ (gnus-message 5 "Sending mail to %s..."
+ (mail-fetch-field "to"))
(sit-for 1)
- (gnus-mail-send-and-exit))
+ (message-send-mail))
(t
(error "Unknown reply kind")))
(set-buffer msg-buf)
(delete-file (buffer-file-name))
(kill-buffer msg-buf)
(kill-buffer tmp-buf)
- (message "Sent packet"))))
+ (gnus-message 4 "Sent packet"))))
(setq replies (cdr replies)))
t)))