* etc/icons/*.xbm: Replaced "-" with "_" to make them can be handled by
[elisp/wanderlust.git] / wl / wl-draft.el
index 22132f0..c30d60f 100644 (file)
@@ -1,4 +1,4 @@
-;;; wl-draft.el -- Message draft mode for Wanderlust.
+;;; wl-draft.el --- Message draft mode for Wanderlust.
 
 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
 ;; Copyright (C) 1998,1999,2000 Masahiro MURATA <muse@ba2.so-net.ne.jp>
 (defvar wl-draft-parent-folder nil)
 
 (defvar wl-draft-config-sub-func-alist
-  '((body          . wl-draft-config-sub-body)
-    (top           . wl-draft-config-sub-top)
-    (bottom        . wl-draft-config-sub-bottom)
-    (header        . wl-draft-config-sub-header)
-    (header-top    . wl-draft-config-sub-header-top)
-    (header-bottom . wl-draft-config-sub-header)
-    (body-file     . wl-draft-config-sub-body-file)
-    (top-file      . wl-draft-config-sub-top-file)
-    (bottom-file   . wl-draft-config-sub-bottom-file)
-    (header-file   . wl-draft-config-sub-header-file)
-    (template      . wl-draft-config-sub-template)
-    (x-face        . wl-draft-config-sub-x-face)))
+  '((body              . wl-draft-config-sub-body)
+    (top               . wl-draft-config-sub-top)
+    (bottom            . wl-draft-config-sub-bottom)
+    (header            . wl-draft-config-sub-header)
+    (header-top                . wl-draft-config-sub-header-top)
+    (header-bottom     . wl-draft-config-sub-header)
+    (part-top          . wl-draft-config-sub-part-top)
+    (part-bottom       . wl-draft-config-sub-part-bottom)
+    (body-file         . wl-draft-config-sub-body-file)
+    (top-file          . wl-draft-config-sub-top-file)
+    (bottom-file       . wl-draft-config-sub-bottom-file)
+    (header-file       . wl-draft-config-sub-header-file)
+    (template          . wl-draft-config-sub-template)
+    (x-face            . wl-draft-config-sub-x-face)))
 
 (make-variable-buffer-local 'wl-draft-buffer-file-name)
 (make-variable-buffer-local 'wl-draft-buffer-cur-summary-buffer)
@@ -412,10 +414,14 @@ Reply to author if WITH-ARG is non-nil."
   (run-hooks 'wl-reply-hook))
 
 (defun wl-draft-add-references ()
+  (wl-draft-add-in-reply-to "References"))
+
+(defun wl-draft-add-in-reply-to (&optional alt-field)
   (let* ((mes-id (save-excursion
                   (set-buffer mail-reply-buffer)
                   (std11-field-body "message-id")))
-        (ref (std11-field-body "References"))
+        (field (or alt-field "In-Reply-To"))
+        (ref (std11-field-body field))
         (ref-list nil) (st nil))
     (when (and mes-id ref)
       (while (string-match "<[^>]+>" ref st)
@@ -427,7 +433,7 @@ Reply to author if WITH-ARG is non-nil."
        (setq mes-id nil)))
     (when mes-id
       (save-excursion
-       (when (mail-position-on-field "References")
+       (when (mail-position-on-field field)
          (forward-line)
          (while (looking-at "^[ \t]")
            (forward-line))
@@ -458,8 +464,10 @@ Reply to author if WITH-ARG is non-nil."
          (mail-yank-hooks (run-hooks 'mail-yank-hooks))
          (wl-draft-cite-function (funcall wl-draft-cite-function))) ; default cite
     (run-hooks 'wl-draft-cited-hook)
-    (when (and wl-draft-add-references
-              (wl-draft-add-references))
+    (when (if wl-draft-add-references
+             (wl-draft-add-references)
+           (if wl-draft-add-in-reply-to
+               (wl-draft-add-in-reply-to)))
       (wl-highlight-headers 'for-draft)) ; highlight when added References:
     (when wl-highlight-body-too
       (wl-highlight-body-region beg (point-max)))))
@@ -565,7 +573,8 @@ Reply to author if WITH-ARG is non-nil."
   (let (original-buffer
        mail-reply-buffer
        mail-citation-hook mail-yank-hooks
-       wl-draft-add-references wl-draft-cite-function)
+       wl-draft-add-references wl-draft-add-in-reply-to
+       wl-draft-cite-function)
     (with-current-buffer wl-draft-buffer-cur-summary-buffer
       (with-current-buffer wl-message-buffer
        (setq original-buffer (wl-message-get-original-buffer))
@@ -750,9 +759,8 @@ Reply to author if WITH-ARG is non-nil."
 (defun wl-draft-write-sendlog (status proto server to id)
   "Write send log file, if `wl-draft-sendlog' is non-nil."
   (when wl-draft-sendlog
-    (save-excursion
-      (let* ((tmp-buf (get-buffer-create " *wl-draft-sendlog*"))
-            (filename (expand-file-name wl-draft-sendlog-filename
+    (with-temp-buffer
+      (let* ((filename (expand-file-name wl-draft-sendlog-filename
                                         elmo-msgdb-dir))
             (filesize (nth 7 (file-attributes filename)))
             (server (if server (concat " server=" server) ""))
@@ -770,18 +778,15 @@ Reply to author if WITH-ARG is non-nil."
                   ""))
             (id (if id (concat " id=" id) ""))
             (time (wl-sendlog-time)))
-       (set-buffer tmp-buf)
-       (erase-buffer)
        (insert (format "%s proto=%s stat=%s%s%s%s\n"
                        time proto status server to id))
        (if (and wl-draft-sendlog-max-size filesize
                 (> filesize wl-draft-sendlog-max-size))
            (rename-file filename (concat filename ".old") t))
        (if (file-writable-p filename)
-           (write-region (point-min) (point-max)
-                         filename t 'no-msg)
-         (message (format "%s is not writable." filename)))
-       (kill-buffer tmp-buf)))))
+           (write-region-as-binary (point-min) (point-max)
+                                   filename t 'no-msg)
+         (message (format "%s is not writable." filename)))))))
 
 (defun wl-draft-get-header-delimiter (&optional delete)
   ;; If DELETE is non-nil, replace the header delimiter with a blank line
@@ -893,7 +898,7 @@ from current buffer."
   "Get address list suitable for smtp RCPT TO:<address>.
 Group list content is removed if `wl-draft-remove-group-list-contents' is
 non-nil."
-  (let ((fields        '("to" "cc" "bcc"))
+  (let ((fields '("to" "cc" "bcc"))
        (resent-fields '("resent-to" "resent-cc" "resent-bcc"))
        (case-fold-search t)
        addrs recipients)
@@ -1327,8 +1332,7 @@ If KILL-WHEN-DONE is non-nil, current draft buffer is killed"
                           body edit-again summary-buf from parent-folder)
   "Write and send mail/news message with Wanderlust."
   (interactive)
-  (unless (featurep 'wl)
-    (require 'wl))
+  (require 'wl)
   (unless wl-init
     (wl-load-profile)
     (wl-folder-init)
@@ -1569,12 +1573,20 @@ If KILL-WHEN-DONE is non-nil, current draft buffer is killed"
   (wl-draft-body-goto-bottom)
   (if content (insert (eval content))))
 
+(defun wl-draft-config-sub-header (content)
+  (wl-draft-config-body-goto-header)
+  (if content (insert (concat (eval content) "\n"))))
+
 (defun wl-draft-config-sub-header-top (content)
   (goto-char (point-min))
   (if content (insert (concat (eval content) "\n"))))
 
-(defun wl-draft-config-sub-header (content)
-  (wl-draft-config-body-goto-header)
+(defun wl-draft-config-sub-part-top (content)
+  (goto-char (mime-edit-content-beginning))
+  (if content (insert (concat (eval content) "\n"))))
+
+(defun wl-draft-config-sub-part-bottom (content)
+  (goto-char (mime-edit-content-end))
   (if content (insert (concat (eval content) "\n"))))
 
 (defsubst wl-draft-config-sub-file (content)