Sync up with gnus-6_2_3 to gnus-6_4_0
[elisp/gnus.git-] / lisp / gnus-draft.el
index 9223727..fce8744 100644 (file)
@@ -1,8 +1,9 @@
-;;; gnus-draft.el --- draft message support for Gnus
-;; Copyright (C) 1997 Free Software Foundation, Inc.
+;;; gnus-draft.el --- draft message support for Semi-gnus
+;; Copyright (C) 1997,98 Free Software Foundation, Inc.
 
-;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
-;; Keywords: news
+;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
+;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
+;; Keywords: mail, news, MIME, offline
 
 ;; This file is part of GNU Emacs.
 
@@ -30,6 +31,7 @@
 (require 'message)
 (require 'gnus-msg)
 (require 'nndraft)
+(require 'gnus-agent)
 (eval-when-compile (require 'cl))
 
 ;;; Draft minor mode
@@ -56,7 +58,8 @@
        ["Toggle whether to send" gnus-draft-toggle-sending t]
        ["Edit" gnus-draft-edit-message t]
        ["Send selected message(s)" gnus-draft-send-message t]
-       ["Send all messages" gnus-draft-send-all-messages t]))))
+       ["Send all messages" gnus-draft-send-all-messages t]
+       ["Delete draft" gnus-summary-delete-article t]))))
 
 (defun gnus-draft-mode (&optional arg)
   "Minor mode for providing a draft summary buffers.
@@ -71,7 +74,7 @@
       (when (gnus-visual-p 'draft-menu 'menu)
        (gnus-draft-make-menu-bar))
       (gnus-add-minor-mode 'gnus-draft-mode " Draft" gnus-draft-mode-map)
-      (run-hooks 'gnus-draft-mode-hook))))
+      (gnus-run-hooks 'gnus-draft-mode-hook))))
 
 ;;; Commands
 
@@ -95,9 +98,9 @@
     (gnus-draft-setup article gnus-newsgroup-name)
     (push
      `((lambda ()
-        (when (buffer-name (get-buffer ,gnus-summary-buffer))
+        (when (gnus-buffer-exists-p ,gnus-summary-buffer)
           (save-excursion
-            (set-buffer (get-buffer ,gnus-summary-buffer))
+            (set-buffer ,gnus-summary-buffer)
             (gnus-cache-possibly-remove-article ,article nil nil nil t)))))
      message-send-actions)))
 
   "Send message ARTICLE."
   (gnus-draft-setup article (or group "nndraft:queue"))
   (let ((message-syntax-checks 'dont-check-for-anything-just-trust-me)
-       message-send-hook)
-    (message-send-and-exit)))
+       message-send-hook type method)
+    ;; We read the meta-information that says how and where
+    ;; this message is to be sent.
+    (save-restriction
+      (message-narrow-to-head)
+      (when (re-search-forward
+            (concat "^" (regexp-quote gnus-agent-meta-information-header) ":")
+            nil t)
+       (setq type (ignore-errors (read (current-buffer)))
+             method (ignore-errors (read (current-buffer))))
+       (message-remove-header gnus-agent-meta-information-header)))
+    ;; Then we send it.  If we have no meta-information, we just send
+    ;; it and let Message figure out how.
+    (if type
+       (let ((message-this-is-news (eq type 'news))
+             (message-this-is-mail (eq type 'mail))
+             (gnus-post-method method)
+             (message-post-method method))
+         (message-send-and-exit))
+      (message-send-and-exit))))
 
 (defun gnus-draft-send-all-messages ()
   "Send all the sendable drafts."
 
 ;;; Utility functions
 
+(defcustom gnus-draft-decoding-function
+  (function
+   (lambda ()
+     (mime-edit-decode-buffer nil)
+     (eword-decode-header)
+     ))
+  "*Function called to decode the message from network representation."
+  :group 'gnus-agent
+  :type 'function)
+
 ;;;!!!If this is byte-compiled, it fails miserably.
-;;;!!!I have no idea why.
+;;;!!!This is because `gnus-setup-message' uses uninterned symbols.
+;;;!!!This has been fixed in recent versions of Emacs and XEmacs,
+;;;!!!but for the time being, we'll just run this tiny function uncompiled.
 
 (progn
 (defun gnus-draft-setup (narticle group)
       (if (not (gnus-request-restore-buffer article group))
          (error "Couldn't restore the article")
        ;; Insert the separator.
+       (funcall gnus-draft-decoding-function)
        (goto-char (point-min))
        (search-forward "\n\n")
        (forward-char -1)