(defun gnus-summary-pipe-to-bogospam (&optional command)
  "Pipe this article to subprocess."
  (gnus-eval-in-buffer-window gnus-article-buffer
    (save-restriction
      (widen)
      (shell-command-on-region (point-min) (point-max) "bogofilter -s" nil)
      (message "Message marked as SPAM"))))

(defun gnus-summary-pipe-to-bogoham (&optional command)
  "Pipe this article to subprocess."
  (gnus-eval-in-buffer-window gnus-article-buffer
    (save-restriction
      (widen)
      (shell-command-on-region (point-min) (point-max) "bogofilter -n" nil)
      (message "Message marked as HAM"))))

(defun bogo-spam (&optional arg headers)
  (interactive (gnus-interactive "P\ny"))
  (require 'gnus-art)
  (let ((gnus-default-article-saver 'gnus-summary-pipe-to-bogospam)
	(gnus-save-all-headers gnus-save-all-headers))
    (gnus-summary-save-article arg t))
  (let ((buffer (get-buffer "*Shell Command Output*")))
    (when (and buffer
	       (not (zerop (buffer-size buffer))))
      (gnus-configure-windows 'pipe))))

(defun bogo-ham (&optional arg headers)
  (interactive (gnus-interactive "P\ny"))
  (require 'gnus-art)
  (let ((gnus-default-article-saver 'gnus-summary-pipe-to-bogoham)
	(gnus-save-all-headers gnus-save-all-headers))
    (gnus-summary-save-article arg t))
  (let ((buffer (get-buffer "*Shell Command Output*")))
    (when (and buffer
	       (not (zerop (buffer-size buffer))))
      (gnus-configure-windows 'pipe))))

(gnus-define-keys gnus-summary-mode-map
  "BS" bogo-spam
  "BH" bogo-ham)