1 ;;; wl-draft.el --- Message draft mode for Wanderlust.
3 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
4 ;; Copyright (C) 1998,1999,2000 Masahiro MURATA <muse@ba2.so-net.ne.jp>
6 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
7 ;; Masahiro MURATA <muse@ba2.so-net.ne.jp>
8 ;; Keywords: mail, net news
10 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
12 ;; This program is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
35 (require 'wl-template)
37 (condition-case nil (require 'timezone) (error nil))
41 (defvar x-face-add-x-face-version-header)
42 (defvar mail-reply-buffer)
43 (defvar mail-from-style)
47 (defalias-maybe 'x-face-insert 'ignore)
48 (defalias-maybe 'x-face-insert-version-header 'ignore)
49 (defalias-maybe 'wl-init 'ignore)
50 (defalias-maybe 'wl-draft-mode 'ignore))
53 (autoload 'wl-addrmgr "wl-addrmgr"))
55 (defvar wl-draft-buf-name "Draft")
56 (defvar wl-draft-cite-function 'wl-default-draft-cite)
57 (defvar wl-draft-buffer-file-name nil)
58 (defvar wl-draft-field-completion-list nil)
59 (defvar wl-draft-verbose-send t)
60 (defvar wl-draft-verbose-msg nil)
61 (defvar wl-draft-queue-flushing nil)
62 (defvar wl-draft-config-variables nil)
63 (defvar wl-draft-config-exec-flag t)
64 (defvar wl-draft-buffer-cur-summary-buffer nil)
65 (defvar wl-draft-clone-local-variable-regexp "^\\(wl\\|mime\\)")
66 (defvar wl-draft-sendlog-filename "sendlog")
67 (defvar wl-draft-queue-save-filename "qinfo")
68 (defvar wl-draft-config-save-filename "config")
69 (defvar wl-draft-queue-flush-send-function 'wl-draft-dispatch-message)
70 (defvar wl-sent-message-via nil)
71 (defvar wl-sent-message-modified nil)
72 (defvar wl-sent-message-queued nil)
73 (defvar wl-draft-fcc-list nil)
74 (defvar wl-draft-reedit nil)
75 (defvar wl-draft-reply-buffer nil)
76 (defvar wl-draft-forward nil)
77 (defvar wl-draft-parent-folder nil)
79 (defvar wl-draft-config-sub-func-alist
80 '((body . wl-draft-config-sub-body)
81 (top . wl-draft-config-sub-top)
82 (bottom . wl-draft-config-sub-bottom)
83 (header . wl-draft-config-sub-header)
84 (header-top . wl-draft-config-sub-header-top)
85 (header-bottom . wl-draft-config-sub-header)
86 (part-top . wl-draft-config-sub-part-top)
87 (part-bottom . wl-draft-config-sub-part-bottom)
88 (body-file . wl-draft-config-sub-body-file)
89 (top-file . wl-draft-config-sub-top-file)
90 (bottom-file . wl-draft-config-sub-bottom-file)
91 (header-file . wl-draft-config-sub-header-file)
92 (template . wl-draft-config-sub-template)
93 (x-face . wl-draft-config-sub-x-face)))
95 (make-variable-buffer-local 'wl-draft-buffer-file-name)
96 (make-variable-buffer-local 'wl-draft-buffer-cur-summary-buffer)
97 (make-variable-buffer-local 'wl-draft-config-variables)
98 (make-variable-buffer-local 'wl-draft-config-exec-flag)
99 (make-variable-buffer-local 'wl-sent-message-via)
100 (make-variable-buffer-local 'wl-sent-message-queued)
101 (make-variable-buffer-local 'wl-draft-fcc-list)
102 (make-variable-buffer-local 'wl-draft-reply-buffer)
103 (make-variable-buffer-local 'wl-draft-parent-folder)
105 (defsubst wl-smtp-password-key (user mechnism server)
106 (format "SMTP:%s/%s@%s"
107 user mechnism server))
109 (defmacro wl-smtp-extension-bind (&rest body)
110 (` (let* ((smtp-sasl-mechanisms
111 (if wl-smtp-authenticate-type
113 (if (listp wl-smtp-authenticate-type)
114 wl-smtp-authenticate-type
115 (list wl-smtp-authenticate-type)))))
116 (smtp-use-sasl (and smtp-sasl-mechanisms t))
117 (smtp-use-starttls (eq wl-smtp-connection-type 'starttls))
118 smtp-sasl-user-name smtp-sasl-properties sasl-read-passphrase)
119 (if (and (string= (car smtp-sasl-mechanisms) "DIGEST-MD5")
121 (string-match "^\\([^@]*\\)@\\([^@]*\\)"
122 wl-smtp-posting-user))
123 (setq smtp-sasl-user-name (match-string 1 wl-smtp-posting-user)
124 smtp-sasl-properties (list 'realm
125 (match-string 2 wl-smtp-posting-user)))
126 (setq smtp-sasl-user-name wl-smtp-posting-user
127 smtp-sasl-properties nil))
128 (setq sasl-read-passphrase
132 (wl-smtp-password-key
134 (car smtp-sasl-mechanisms)
138 (defun wl-draft-insert-date-field ()
140 (insert "Date: " (wl-make-date-string) "\n"))
142 (defun wl-draft-insert-from-field ()
144 ;; Put the "From:" field in unless for some odd reason
145 ;; they put one in themselves.
146 (let* ((login (or user-mail-address (user-login-name)))
147 (fullname (user-full-name)))
148 (cond ((eq mail-from-style 'angles)
149 (insert "From: " fullname)
150 (let ((fullname-start (+ (point-min) (length "From: ")))
151 (fullname-end (point-marker)))
152 (goto-char fullname-start)
153 ;; Look for a character that cannot appear unquoted
154 ;; according to RFC 822.
155 (if (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
158 ;; Quote fullname, escaping specials.
159 (goto-char fullname-start)
161 (while (re-search-forward "[\"\\]"
163 (replace-match "\\\\\\&" t))
165 (insert " <" login ">\n"))
166 ((eq mail-from-style 'parens)
167 (insert "From: " login " (")
168 (let ((fullname-start (point)))
170 (let ((fullname-end (point-marker)))
171 (goto-char fullname-start)
172 ;; RFC 822 says \ and nonmatching parentheses
173 ;; must be escaped in comments.
174 ;; Escape every instance of ()\ ...
175 (while (re-search-forward "[()\\]" fullname-end 1)
176 (replace-match "\\\\\\&" t))
177 ;; ... then undo escaping of matching parentheses,
178 ;; including matching nested parentheses.
179 (goto-char fullname-start)
180 (while (re-search-forward
181 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
183 (replace-match "\\1(\\3)" t)
184 (goto-char fullname-start))))
186 ((not mail-from-style)
187 (insert "From: " login "\n")))))
189 (defun wl-draft-insert-x-face-field ()
190 "Insert X-Face header."
192 (if (not (file-exists-p wl-x-face-file))
193 (error "File %s does not exist" wl-x-face-file)
194 (beginning-of-buffer)
195 (search-forward mail-header-separator nil t)
197 (wl-draft-insert-x-face-field-here)
198 (run-hooks 'wl-draft-insert-x-face-field-hook))) ; highlight it if you want.
200 (defun wl-draft-insert-x-face-field-here ()
201 "Insert X-Face field at point."
202 (let ((x-face-string (elmo-get-file-string wl-x-face-file)))
203 (when (string-match "^[ \t]*" x-face-string)
204 (setq x-face-string (substring x-face-string (match-end 0))))
205 (insert "X-Face: " x-face-string))
206 (when (not (= (preceding-char) ?\n)) ; for chomped (choped) x-face-string
208 ;; Insert X-Face-Version: field
209 (when (and (fboundp 'x-face-insert-version-header)
210 (boundp 'x-face-add-x-face-version-header)
211 x-face-add-x-face-version-header)
212 (x-face-insert-version-header)))
214 (defun wl-draft-setup ()
215 (let ((field wl-draft-fields)
218 (setq ret-val (append ret-val
219 (list (cons (concat (car field) " ")
220 (concat (car field) " ")))))
221 (setq field (cdr field)))
222 (setq wl-draft-field-completion-list ret-val)))
224 (defun wl-draft-make-mail-followup-to (recipients)
225 (if (elmo-list-member
226 (or wl-user-mail-address-list
227 (list (wl-address-header-extract-address wl-from)))
229 (let ((rlist (elmo-list-delete
230 (or wl-user-mail-address-list
231 (list (wl-address-header-extract-address wl-from)))
232 (copy-sequence recipients))))
233 (if (elmo-list-member rlist (mapcar 'downcase
234 wl-subscribed-mailing-list))
236 (append rlist (list (wl-address-header-extract-address
240 (defun wl-draft-delete-myself-from-cc (to cc)
241 (let ((myself (or wl-user-mail-address-list
242 (list (wl-address-header-extract-address wl-from)))))
243 (cond (wl-draft-always-delete-myself ; always-delete option
244 (elmo-list-delete myself cc))
245 ((elmo-list-member (append to cc) ; subscribed mailing-list
246 (mapcar 'downcase wl-subscribed-mailing-list))
247 (elmo-list-delete myself cc))
250 (defun wl-draft-forward (original-subject summary-buf)
252 (with-current-buffer (wl-message-get-original-buffer)
253 (setq references (nconc
254 (std11-field-bodies '("References" "In-Reply-To"))
255 (list (std11-field-body "Message-Id"))))
256 (setq references (delq nil references)
257 references (mapconcat 'identity references " ")
258 references (wl-draft-parse-msg-id-list-string references)
259 references (wl-delete-duplicates references)
260 references (when references
261 (mapconcat 'identity references "\n\t"))))
262 (wl-draft "" (concat "Forward: " original-subject)
263 nil nil references nil nil nil nil nil nil summary-buf))
264 (goto-char (point-max))
265 (wl-draft-insert-message)
266 (mail-position-on-field "To"))
268 (defun wl-draft-strip-subject-re (subject)
269 "Remove \"Re:\" from subject lines. Shamelessly copied from Gnus."
270 (if (string-match wl-subject-prefix-regexp subject)
271 (substring subject (match-end 0))
274 (defun wl-draft-reply-list-symbol (with-arg)
275 "Return symbol `wl-draft-reply-*-argument-list' match condition.
276 Check WITH-ARG and From: field."
277 (if (wl-address-user-mail-address-p (or (elmo-field-body "From") ""))
279 'wl-draft-reply-myself-with-argument-list
280 'wl-draft-reply-myself-without-argument-list)
282 'wl-draft-reply-with-argument-list
283 'wl-draft-reply-without-argument-list)))
285 (defun wl-draft-reply (buf with-arg summary-buf)
286 "Reply to BUF buffer message.
287 Reply to author if WITH-ARG is non-nil."
290 to mail-followup-to cc subject in-reply-to references newsgroups
291 from to-alist cc-alist decoder parent-folder)
292 (set-buffer summary-buf)
293 (setq parent-folder (wl-summary-buffer-folder-name))
295 (setq r-list (symbol-value (wl-draft-reply-list-symbol with-arg)))
298 (when (let ((condition (car (car r-list))))
299 (cond ((stringp condition)
300 (std11-field-body condition))
304 (if (not (std11-field-body (car condition)))
306 (setq condition (cdr condition)))
309 (funcall condition))))
310 (let ((r-to-list (nth 0 (cdr (car r-list))))
311 (r-cc-list (nth 1 (cdr (car r-list))))
312 (r-ng-list (nth 2 (cdr (car r-list)))))
313 (when (and (member "Followup-To" r-ng-list)
314 (string= (std11-field-body "Followup-To") "poster"))
315 (setq r-to-list (cons "From" r-to-list))
316 (setq r-ng-list (delete "Followup-To" (copy-sequence r-ng-list))))
317 (setq to (wl-concat-list (cons to
318 (elmo-multiple-fields-body-list
321 (setq cc (wl-concat-list (cons cc
322 (elmo-multiple-fields-body-list
325 (setq newsgroups (wl-concat-list (cons newsgroups
330 (setq r-list (cdr r-list)))
331 (error "No match field: check your `%s'"
332 (symbol-name (wl-draft-reply-list-symbol with-arg))))
333 (setq subject (std11-field-body "Subject"))
334 (setq to (wl-parse-addresses to)
335 cc (wl-parse-addresses cc))
336 (with-temp-buffer ; to keep raw buffer unibyte.
337 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
338 (setq decoder (mime-find-field-decoder 'Subject 'plain))
339 (setq subject (if (and subject decoder)
340 (funcall decoder subject) subject))
344 (setq decoder (mime-find-field-decoder 'To 'plain))
345 (cons (nth 1 (std11-extract-address-components addr))
346 (if decoder (funcall decoder addr) addr)))
351 (setq decoder (mime-find-field-decoder 'Cc 'plain))
352 (cons (nth 1 (std11-extract-address-components addr))
353 (if decoder (funcall decoder addr) addr)))
355 (and wl-reply-subject-prefix
356 (setq subject (concat wl-reply-subject-prefix
357 (wl-draft-strip-subject-re
359 (setq in-reply-to (std11-field-body "Message-Id"))
360 (setq references (nconc
361 (std11-field-bodies '("References" "In-Reply-To"))
363 (setq to (delq nil (mapcar 'car to-alist)))
364 (setq cc (delq nil (mapcar 'car cc-alist)))
365 ;; if subscribed mailing list is contained in cc or to
366 ;; and myself is contained in cc,
367 ;; delete myself from cc.
368 (setq cc (wl-draft-delete-myself-from-cc to cc))
369 (when wl-insert-mail-followup-to
370 (setq mail-followup-to
371 (wl-draft-make-mail-followup-to (append to cc)))
372 (setq mail-followup-to (wl-delete-duplicates mail-followup-to nil t)))
373 (with-temp-buffer ; to keep raw buffer unibyte.
374 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
375 (setq newsgroups (wl-parse newsgroups
376 "[ \t\f\r\n,]*\\([^ \t\f\r\n,]+\\)")
377 newsgroups (wl-delete-duplicates newsgroups)
382 (setq decoder (mime-find-field-decoder 'Newsgroups 'plain))
383 (if decoder (funcall decoder grp) grp))
385 (setq to (wl-delete-duplicates to nil t))
386 (setq cc (wl-delete-duplicates
387 (append (wl-delete-duplicates cc nil t)
388 to (copy-sequence to))
390 (and to (setq to (mapconcat
392 (if wl-draft-reply-use-address-with-full-name
393 (or (cdr (assoc addr to-alist)) addr)
396 (and cc (setq cc (mapconcat
398 (if wl-draft-reply-use-address-with-full-name
399 (or (cdr (assoc addr cc-alist)) addr)
402 (and mail-followup-to
403 (setq mail-followup-to
406 (if wl-draft-reply-use-address-with-full-name
407 (or (cdr (assoc addr (append to-alist cc-alist))) addr)
409 mail-followup-to ",\n\t")))
410 (and (null to) (setq to cc cc nil))
411 (setq references (delq nil references)
412 references (mapconcat 'identity references " ")
413 references (wl-draft-parse-msg-id-list-string references)
414 references (wl-delete-duplicates references)
415 references (if references
416 (mapconcat 'identity references "\n\t")))
418 to subject in-reply-to cc references newsgroups mail-followup-to
419 nil nil nil nil summary-buf nil parent-folder)
420 (setq wl-draft-reply-buffer buf))
421 (run-hooks 'wl-reply-hook))
423 (defun wl-draft-add-references ()
424 (wl-draft-add-in-reply-to "References"))
426 (defun wl-draft-add-in-reply-to (&optional alt-field)
427 (let* ((mes-id (save-excursion
428 (set-buffer mail-reply-buffer)
429 (std11-field-body "message-id")))
430 (field (or alt-field "In-Reply-To"))
431 (ref (std11-field-body field))
432 (ref-list nil) (st nil))
433 (when (and mes-id ref)
434 (while (string-match "<[^>]+>" ref st)
436 (cons (substring ref (match-beginning 0) (setq st (match-end 0)))
439 (member mes-id ref-list))
443 (when (mail-position-on-field field)
445 (while (looking-at "^[ \t]")
447 (setq mes-id (concat "\t" mes-id "\n")))
451 (defun wl-draft-yank-from-mail-reply-buffer (decode-it
452 &optional ignored-fields)
455 (narrow-to-region (point)(point))
457 (with-current-buffer mail-reply-buffer
459 (decode-mime-charset-region (point-min) (point-max)
461 (buffer-substring-no-properties
462 (point-min) (point-max))))
464 (goto-char (point-min))
465 (wl-draft-delete-fields ignored-fields))
466 (goto-char (point-max))
467 (push-mark (point) nil t)
468 (goto-char (point-min)))
470 (cond (mail-citation-hook (run-hooks 'mail-citation-hook))
471 (mail-yank-hooks (run-hooks 'mail-yank-hooks))
472 (wl-draft-cite-function (funcall wl-draft-cite-function))) ; default cite
473 (run-hooks 'wl-draft-cited-hook)
474 (when (if wl-draft-add-references
475 (wl-draft-add-references)
476 (if wl-draft-add-in-reply-to
477 (wl-draft-add-in-reply-to)))
478 (wl-highlight-headers 'for-draft)) ; highlight when added References:
479 (when wl-highlight-body-too
480 (wl-highlight-body-region beg (point-max)))))
482 (defun wl-draft-confirm ()
483 "Confirm send message."
485 (y-or-n-p (format "Send current draft as %s? "
486 (cond ((and (wl-message-mail-p) (wl-message-news-p))
488 ((wl-message-mail-p) "Mail")
489 ((wl-message-news-p) "News")))))
491 (defun wl-message-news-p ()
492 "If exist valid Newsgroups field, return non-nil."
493 (std11-field-body "Newsgroups"))
495 (defun wl-message-field-exists-p (field)
496 "If FIELD exist and FIELD value is not empty, return non-nil."
497 (let ((value (std11-field-body field)))
499 (not (string= value "")))))
501 (defun wl-message-mail-p ()
502 "If exist To, Cc or Bcc field, return non-nil."
503 (or (wl-message-field-exists-p "To")
504 (wl-message-field-exists-p "Resent-to")
505 (wl-message-field-exists-p "Cc")
506 (wl-message-field-exists-p "Bcc")
507 ;;; This may be needed..
508 ;;; (wl-message-field-exists-p "Fcc")
511 (defun wl-draft-open-file (&optional file)
512 "Open FILE for edit."
514 ;;;(interactive "*fFile to edit: ")
515 (wl-draft-edit-string (elmo-get-file-string
517 (read-file-name "File to edit: "
518 (or wl-temporary-file-directory
521 (defun wl-draft-edit-string (string)
522 (let ((cur-buf (current-buffer))
523 (tmp-buf (get-buffer-create " *wl-draft-edit-string*"))
524 to subject in-reply-to cc references newsgroups mail-followup-to
525 content-type content-transfer-encoding from
526 body-beg buffer-read-only)
530 (setq to (std11-field-body "To"))
533 (decode-mime-charset-string
536 (setq subject (std11-field-body "Subject"))
537 (setq subject (and subject
539 (decode-mime-charset-string
542 (setq from (std11-field-body "From")
545 (decode-mime-charset-string
548 (setq in-reply-to (std11-field-body "In-Reply-To"))
549 (setq cc (std11-field-body "Cc"))
552 (decode-mime-charset-string
555 (setq references (std11-field-body "References"))
556 (setq newsgroups (std11-field-body "Newsgroups"))
557 (setq mail-followup-to (std11-field-body "Mail-Followup-To"))
558 (setq content-type (std11-field-body "Content-Type"))
559 (setq content-transfer-encoding (std11-field-body "Content-Transfer-Encoding"))
560 (goto-char (point-min))
561 (or (re-search-forward "\n\n" nil t)
562 (search-forward (concat mail-header-separator "\n") nil t))
565 (wl-draft to subject in-reply-to cc references newsgroups
567 content-type content-transfer-encoding
568 (buffer-substring (point) (point-max))
570 (if (member (nth 1 (std11-extract-address-components from))
571 wl-user-mail-address-list)
573 (and to (mail-position-on-field "To"))
574 (delete-other-windows)
575 (kill-buffer tmp-buf)))
576 (setq buffer-read-only nil) ;;??
577 (run-hooks 'wl-draft-reedit-hook))
579 (defun wl-draft-insert-current-message (dummy)
581 (let (original-buffer
583 mail-citation-hook mail-yank-hooks
584 wl-draft-add-references wl-draft-add-in-reply-to
585 wl-draft-cite-function)
586 (with-current-buffer wl-draft-buffer-cur-summary-buffer
587 (with-current-buffer wl-message-buffer
588 (setq original-buffer (wl-message-get-original-buffer))
590 (with-current-buffer original-buffer
592 (error "No current message"))))
593 (setq mail-reply-buffer original-buffer)
594 (wl-draft-yank-from-mail-reply-buffer
596 wl-ignored-forwarded-headers)))
598 (defun wl-draft-insert-get-message (dummy)
599 (let ((fld (completing-read
601 (if (memq 'read-folder wl-use-folder-petname)
602 (wl-folder-get-entity-with-petname)
603 wl-folder-entity-hashtb)
604 nil nil wl-default-spec
605 'wl-read-folder-hist))
606 (number (call-interactively
607 (function (lambda (num)
608 (interactive "nNumber: ")
610 (mail-reply-buffer (get-buffer-create "*wl-draft-insert-get-message*"))
611 mail-citation-hook mail-yank-hooks
612 wl-draft-cite-function)
615 (elmo-message-fetch (wl-folder-get-elmo-folder fld)
618 (elmo-make-fetch-strategy 'entire)
619 nil mail-reply-buffer)
620 (wl-draft-yank-from-mail-reply-buffer nil))
621 (kill-buffer mail-reply-buffer))))
624 ;; default body citation func
626 (defun wl-default-draft-cite ()
627 (let ((mail-yank-ignored-headers "[^:]+:")
628 (mail-yank-prefix "> ")
629 (summary-buf wl-current-summary-buffer)
630 (message-buf (get-buffer (wl-current-message-buffer)))
631 from date cite-title num entity)
633 (buffer-live-p summary-buf)
635 (buffer-live-p message-buf))
637 (with-current-buffer summary-buf
638 (setq num (save-excursion
639 (set-buffer message-buf)
640 wl-message-buffer-cur-number))
641 (setq entity (elmo-msgdb-overview-get-entity
642 num (wl-summary-buffer-msgdb)))
643 (setq date (elmo-msgdb-overview-entity-get-date entity))
644 (setq from (elmo-msgdb-overview-entity-get-from entity)))
645 (setq cite-title (format "At %s,\n%s wrote:"
646 (or date "some time ago")
647 (wl-summary-from-func-internal
650 (insert cite-title "\n"))
651 (mail-indent-citation)))
653 (defvar wl-draft-buffer nil "Draft buffer to yank content")
654 (defun wl-draft-yank-to-draft-buffer (buffer)
655 "Yank BUFFER content to `wl-draft-buffer'."
656 (set-buffer wl-draft-buffer)
657 (let ((mail-reply-buffer buffer))
658 (wl-draft-yank-from-mail-reply-buffer nil)
659 (kill-buffer buffer)))
661 (defun wl-draft-yank-original (&optional arg)
662 "Yank original message."
665 (let (buf mail-reply-buffer)
668 (setq buf (current-buffer)))
669 (setq mail-reply-buffer buf)
670 (wl-draft-yank-from-mail-reply-buffer nil))
671 (wl-draft-yank-current-message-entity)))
673 (defun wl-draft-hide (editing-buffer)
674 "Hide the editing draft buffer if possible."
675 (when (and editing-buffer
676 (buffer-live-p editing-buffer))
677 (set-buffer editing-buffer)
678 (let ((sum-buf wl-draft-buffer-cur-summary-buffer)
679 fld-buf sum-win fld-win)
680 (if (and wl-draft-use-frame
681 (> (length (visible-frame-list)) 1))
687 ;; stay folder window if required
688 (when wl-stay-folder-window
689 (if (setq fld-buf (get-buffer wl-folder-buffer-name))
690 (if (setq fld-win (get-buffer-window fld-buf))
691 (select-window fld-win)
692 (if wl-draft-resume-folder-window ;; resume folder window
693 (switch-to-buffer fld-buf)))))
694 (if (buffer-live-p sum-buf)
695 (if (setq sum-win (get-buffer-window sum-buf t))
696 ;; if Summary is on the frame, select it.
697 (select-window sum-win)
698 ;; if summary is not on the frame, switch to it.
699 (if (and wl-stay-folder-window
700 (or wl-draft-resume-folder-window fld-win))
701 (wl-folder-select-buffer sum-buf)
702 (switch-to-buffer sum-buf)))))))
704 (defun wl-draft-delete (editing-buffer)
705 "kill the editing draft buffer and delete the file corresponds to it."
708 (set-buffer editing-buffer)
709 (if wl-draft-buffer-file-name
711 (if (file-exists-p wl-draft-buffer-file-name)
712 (delete-file wl-draft-buffer-file-name))
713 (let ((msg (and wl-draft-buffer-file-name
714 (string-match "[0-9]+$" wl-draft-buffer-file-name)
716 (match-string 0 wl-draft-buffer-file-name)))))
717 (wl-draft-config-info-operation msg 'delete))))
718 (set-buffer-modified-p nil) ; force kill
719 (kill-buffer editing-buffer))))
721 (defun wl-draft-kill (&optional force-kill)
722 "Kill current draft buffer and quit editing."
725 (when (and (or (eq major-mode 'wl-draft-mode)
726 (eq major-mode 'mail-mode))
728 (y-or-n-p "Kill Current Draft? ")))
729 (let ((cur-buf (current-buffer)))
730 (wl-draft-hide cur-buf)
731 (wl-draft-delete cur-buf)))
734 (defun wl-draft-fcc ()
735 "Add a new Fcc field, with file name completion."
737 (or (mail-position-on-field "fcc" t) ;Put new field after exiting Fcc.
738 (mail-position-on-field "to"))
741 ;; Imported from message.el.
742 (defun wl-draft-elide-region (b e)
743 "Elide the text in the region.
744 An ellipsis (from `wl-draft-elide-ellipsis') will be inserted where the
748 (insert wl-draft-elide-ellipsis))
750 ;; function for wl-sent-message-via
752 (defmacro wl-draft-sent-message-p (type)
753 (` (eq (nth 1 (assq (, type) wl-sent-message-via)) 'sent)))
755 (defmacro wl-draft-set-sent-message (type result &optional server-port)
756 (` (let ((element (assq (, type) wl-sent-message-via)))
758 (unless (eq (nth 1 element) (, result))
759 (setcdr element (list (, result) (, server-port)))
760 (setq wl-sent-message-modified t))
761 (push (list (, type) (, result) (, server-port)) wl-sent-message-via)
762 (setq wl-sent-message-modified t)))))
764 (defun wl-draft-sent-message-results ()
765 (let ((results wl-sent-message-via)
766 unplugged-via sent-via)
768 (cond ((eq (nth 1 (car results)) 'unplugged)
769 (push (caar results) unplugged-via))
770 ((eq (nth 1 (car results)) 'sent)
771 (push (caar results) sent-via)))
772 (setq results (cdr results)))
773 (list unplugged-via sent-via)))
775 (defun wl-draft-write-sendlog (status proto server to id)
776 "Write send log file, if `wl-draft-sendlog' is non-nil."
777 (when wl-draft-sendlog
779 (let* ((filename (expand-file-name wl-draft-sendlog-filename
780 elmo-msgdb-directory))
781 (filesize (nth 7 (file-attributes filename)))
782 (server (if server (concat " server=" server) ""))
784 ((memq proto '(fcc queue))
785 (format " folder=\"%s\"" to))
787 (format " ng=<%s>" to))
792 (mapcar '(lambda(x) (format "<%s>" x)) to)
795 (id (if id (concat " id=" id) ""))
796 (time (wl-sendlog-time)))
797 (insert (format "%s proto=%s stat=%s%s%s%s\n"
798 time proto status server to id))
799 (if (and wl-draft-sendlog-max-size filesize
800 (> filesize wl-draft-sendlog-max-size))
801 (rename-file filename (concat filename ".old") t))
802 (if (file-writable-p filename)
803 (write-region-as-binary (point-min) (point-max)
805 (message (format "%s is not writable." filename)))))))
807 (defun wl-draft-get-header-delimiter (&optional delete)
808 ;; If DELETE is non-nil, replace the header delimiter with a blank line
810 (goto-char (point-min))
811 (when (re-search-forward
812 (concat "^" (regexp-quote mail-header-separator) "$\\|^$") nil t)
816 (setq delimline (point-marker)))
819 (defun wl-draft-send-mail-with-qmail ()
820 "Pass the prepared message buffer to qmail-inject.
821 Refer to the documentation for the variable `send-mail-function'
822 to find out how to use this."
823 (if (and wl-draft-qmail-send-plugged
824 (not (elmo-plugged-p)))
825 (wl-draft-set-sent-message 'mail 'unplugged)
827 (let ((id (std11-field-body "Message-ID"))
828 (to (std11-field-body "To")))
832 'call-process-region 1 (point-max) wl-qmail-inject-program
834 wl-qmail-inject-args))
835 ;; qmail-inject doesn't say anything on it's stdout/stderr,
836 ;; we have to look at the retval instead
838 (wl-draft-set-sent-message 'mail 'sent)
839 (wl-draft-write-sendlog 'ok 'qmail nil (list to) id)))
840 (1 (error "`qmail-inject' reported permanent failure"))
841 (111 (error "`qmail-inject' reported transient failure"))
842 ;; should never happen
843 (t (error "`qmail-inject' reported unknown failure"))))))
845 (defun wl-draft-parse-msg-id-list-string (string)
846 "Get msg-id list from STRING."
848 (dolist (parsed-id (std11-parse-msg-ids-string string))
849 (when (eq (car parsed-id) 'msg-id)
850 (setq msg-id-list (cons (std11-msg-id-string parsed-id)
852 (nreverse msg-id-list)))
854 (defun wl-draft-std11-parse-addresses (lal)
855 (let ((ret (std11-parse-address lal)))
857 (let ((dest (list (car ret))))
859 (while (and (setq ret (std11-parse-ascii-token lal))
860 (string-equal (cdr (assq 'specials (car ret))) ",")
861 (setq ret (std11-parse-address (cdr ret)))
863 (setq dest (cons (car ret) dest))
864 (setq lal (cdr ret)))
865 (while (eq 'spaces (car (car lal)))
866 (setq lal (cdr lal)))
867 (if lal (error "Error while parsing address"))
870 (defun wl-draft-parse-mailbox-list (field &optional remove-group-list)
871 "Get mailbox list of FIELD from current buffer.
872 The buffer is expected to be narrowed to just the headers of the message.
873 If optional argument REMOVE-GROUP-LIST is non-nil, remove group list content
874 from current buffer."
876 (let ((case-fold-search t)
877 (inhibit-read-only t)
879 mailbox-list beg seq has-group-list)
880 (goto-char (point-min))
881 (while (re-search-forward (concat "^" (regexp-quote field) "[\t ]*:")
884 (re-search-forward "^[^ \t]" nil 'move)
886 (skip-chars-backward "\n")
887 (setq seq (std11-lexical-analyze
888 (buffer-substring-no-properties beg (point))))
889 (setq addresses (wl-draft-std11-parse-addresses seq))
891 (cond ((eq (car (car addresses)) 'group)
892 (setq has-group-list t)
896 'std11-address-string
897 (nth 2 (car addresses))))))
898 ((eq (car (car addresses)) 'mailbox)
899 (setq address (nth 1 (car addresses)))
903 (std11-addr-to-string
904 (if (eq (car address) 'phrase-route-addr)
907 (setq addresses (cdr addresses)))
908 (when (and remove-group-list has-group-list)
909 (delete-region beg (point))
910 (insert (wl-address-string-without-group-list-contents seq))))
913 (defun wl-draft-deduce-address-list (buffer header-start header-end)
914 "Get address list suitable for smtp RCPT TO:<address>.
915 Group list content is removed if `wl-draft-remove-group-list-contents' is
917 (let ((fields '("to" "cc" "bcc"))
918 (resent-fields '("resent-to" "resent-cc" "resent-bcc"))
923 (narrow-to-region header-start header-end)
924 (goto-char (point-min))
926 (if (re-search-forward "^resent-to[\t ]*:" nil t)
927 (setq fields resent-fields)))
931 (wl-draft-parse-mailbox-list
933 wl-draft-remove-group-list-contents)))
934 (setq fields (cdr fields)))
940 (defun wl-draft-send-mail-with-smtp ()
941 "Send the prepared message buffer with SMTP."
943 (let* ((errbuf (if mail-interactive
944 (generate-new-buffer " smtp errors")
947 (default-case-fold-search t)
948 (sender (or wl-envelope-from
949 (wl-address-header-extract-address wl-from)))
950 (delimline (save-excursion
951 (goto-char (point-min))
953 (concat "^" (regexp-quote mail-header-separator)
957 (or wl-smtp-posting-server
958 ;; Compatibility stuff for FLIM 1.12.5 or earlier.
959 ;; They don't accept a function as the value of `smtp-server'.
960 (if (functionp smtp-server)
965 (let (wl-draft-remove-group-list-contents)
966 (wl-draft-deduce-address-list
967 (current-buffer) (point-min) delimline)))
968 (or smtp-server "localhost"))))
969 (smtp-service (or wl-smtp-posting-port smtp-service))
970 (smtp-local-domain (or smtp-local-domain wl-local-domain))
971 (id (std11-field-body "message-id"))
973 (if (not (elmo-plugged-p smtp-server smtp-service))
974 (wl-draft-set-sent-message 'mail 'unplugged
975 (cons smtp-server smtp-service))
978 ;; Instead of `smtp-deduce-address-list'.
979 (setq recipients (wl-draft-deduce-address-list
980 (current-buffer) (point-min) delimline))
981 (unless recipients (error "No recipients"))
982 ;; Insert an extra newline if we need it to work around
983 ;; Sun's bug that swallows newlines.
984 (goto-char (1+ delimline))
985 (if (eval mail-mailer-swallows-blank-line)
987 ;;; (run-hooks 'wl-mail-send-pre-hook)
992 (wl-draft-delete-field "bcc" delimline)
993 (wl-draft-delete-field "resent-bcc" delimline)
994 (let (process-connection-type)
997 (wl-smtp-extension-bind
999 (smtp-send-buffer sender recipients (current-buffer))
1001 (wl-draft-write-sendlog 'failed 'smtp smtp-server
1003 (if (/= (nth 1 err) 334)
1005 (wl-smtp-password-key
1007 (car smtp-sasl-mechanisms)
1009 (signal (car err) (cdr err)))))
1010 (wl-draft-set-sent-message 'mail 'sent)
1011 (wl-draft-write-sendlog
1012 'ok 'smtp smtp-server recipients id)))))
1013 (if (bufferp errbuf)
1014 (kill-buffer errbuf))))))
1016 (defun wl-draft-send-mail-with-pop-before-smtp ()
1017 "Send the prepared message buffer with POP-before-SMTP."
1018 (require 'elmo-pop3)
1022 :user (or wl-pop-before-smtp-user
1023 elmo-pop3-default-user)
1024 :server (or wl-pop-before-smtp-server
1025 elmo-pop3-default-server)
1026 :port (or wl-pop-before-smtp-port
1027 elmo-pop3-default-port)
1028 :auth (or wl-pop-before-smtp-authenticate-type
1029 elmo-pop3-default-authenticate-type)
1030 :stream-type (or wl-pop-before-smtp-stream-type
1031 elmo-pop3-default-stream-type))))
1032 (condition-case error
1034 (elmo-pop3-get-session session)
1035 (when session (elmo-network-close-session session)))
1037 (elmo-network-close-session session)
1038 (signal (car error)(cdr error)))))
1039 (wl-draft-send-mail-with-smtp))
1041 (defun wl-draft-insert-required-fields (&optional force-msgid)
1042 "Insert Message-ID, Date, and From field.
1043 If FORCE-MSGID, ignore 'wl-insert-message-id'."
1044 ;; Insert Message-Id field...
1045 (goto-char (point-min))
1046 (when (and (or force-msgid
1047 wl-insert-message-id)
1048 (not (re-search-forward "^Message-ID[ \t]*:" nil t)))
1049 (insert (concat "Message-ID: "
1050 (funcall wl-message-id-function)
1052 ;; Insert date field.
1053 (goto-char (point-min))
1054 (or (re-search-forward "^Date[ \t]*:" nil t)
1055 (wl-draft-insert-date-field))
1056 ;; Insert from field.
1057 (goto-char (point-min))
1058 (or (re-search-forward "^From[ \t]*:" nil t)
1059 (wl-draft-insert-from-field)))
1061 (defun wl-draft-normal-send-func (editing-buffer kill-when-done)
1062 "Send the message in the current buffer."
1064 (std11-narrow-to-header mail-header-separator)
1065 (wl-draft-insert-required-fields)
1066 ;; Delete null fields.
1067 (goto-char (point-min))
1068 (while (re-search-forward "^[^ \t\n:]+:[ \t]*\n" nil t)
1070 ;; ignore any blank lines in the header
1071 (while (re-search-forward "\n\n\n*" nil t)
1072 (replace-match "\n")))
1073 (run-hooks 'wl-mail-send-pre-hook) ;; X-PGP-Sig, Cancel-Lock
1074 (wl-draft-dispatch-message)
1075 (when kill-when-done
1076 ;; hide editing-buffer.
1077 (wl-draft-hide editing-buffer)
1078 ;; delete editing-buffer and its file.
1079 (wl-draft-delete editing-buffer)))
1081 (defun wl-draft-dispatch-message (&optional mes-string)
1082 "Send the message in the current buffer. Not modified the header fields."
1084 (if (and wl-draft-verbose-send mes-string)
1085 (message mes-string))
1087 (setq delimline (wl-draft-get-header-delimiter t))
1088 (unless wl-draft-fcc-list
1089 (setq wl-draft-fcc-list (wl-draft-get-fcc-list delimline)))
1091 (setq wl-sent-message-modified nil)
1094 (if (and (wl-message-mail-p)
1095 (not (wl-draft-sent-message-p 'mail)))
1096 (if (or (not (or wl-draft-force-queuing
1097 wl-draft-force-queuing-mail))
1098 (memq 'mail wl-sent-message-queued))
1099 (funcall wl-draft-send-mail-function)
1100 (push 'mail wl-sent-message-queued)
1101 (wl-draft-set-sent-message 'mail 'unplugged)))
1102 (if (and (wl-message-news-p)
1103 (not (wl-draft-sent-message-p 'news))
1104 (not (wl-message-field-exists-p "Resent-to")))
1105 (if (or (not (or wl-draft-force-queuing
1106 wl-draft-force-queuing-news))
1107 (memq 'news wl-sent-message-queued))
1108 (funcall wl-draft-send-news-function)
1109 (push 'news wl-sent-message-queued)
1110 (wl-draft-set-sent-message 'news 'unplugged))))
1112 (let* ((status (wl-draft-sent-message-results))
1113 (unplugged-via (car status))
1114 (sent-via (nth 1 status)))
1115 ;; If one sent, process fcc folder.
1116 (if (and sent-via wl-draft-fcc-list)
1118 (wl-draft-do-fcc (wl-draft-get-header-delimiter) wl-draft-fcc-list)
1119 (setq wl-draft-fcc-list nil)))
1120 (if wl-draft-use-cache
1121 (let ((id (std11-field-body "Message-ID"))
1122 (elmo-enable-disconnected-operation t))
1123 (elmo-file-cache-save (elmo-file-cache-get-path id)
1125 ;; If one unplugged, append queue.
1126 (when (and unplugged-via
1127 wl-sent-message-modified)
1128 (if wl-draft-enable-queuing
1130 (wl-draft-queue-append wl-sent-message-via)
1131 (setq wl-sent-message-modified 'requeue))
1132 (error "Unplugged")))
1133 (when wl-draft-verbose-send
1134 (if (and unplugged-via sent-via);; combined message
1136 (setq wl-draft-verbose-msg
1137 (format "Sending%s and Queuing%s..."
1138 sent-via unplugged-via))
1139 (message (concat wl-draft-verbose-msg "done")))
1141 (message (concat mes-string
1142 (if sent-via "done" "failed")))))))))
1143 (not wl-sent-message-modified)) ;; return value
1145 (defun wl-draft-raw-send (&optional kill-when-done force-pre-hook mes-string)
1146 "Force send current buffer as raw message."
1149 (let (wl-interactive-send
1150 ;;; wl-draft-verbose-send
1151 (wl-mail-send-pre-hook (and force-pre-hook wl-mail-send-pre-hook))
1152 ;;; wl-news-send-pre-hook
1155 (wl-draft-send kill-when-done mes-string))))
1157 (defun wl-draft-clone-local-variables ()
1158 (let ((locals (buffer-local-variables))
1161 (when (and (consp (car locals))
1163 (string-match wl-draft-clone-local-variable-regexp
1164 (symbol-name (car (car locals)))))
1165 (wl-append result (list (car (car locals)))))
1166 (setq locals (cdr locals)))
1169 (defun wl-draft-send (&optional kill-when-done mes-string)
1170 "Send current draft message.
1171 If KILL-WHEN-DONE is non-nil, current draft buffer is killed"
1173 ;; Don't call this explicitly.
1174 ;; Added to 'wl-draft-send-hook (by teranisi)
1175 ;; (wl-draft-config-exec)
1176 (run-hooks 'wl-draft-send-hook)
1177 (when (or (not wl-interactive-send)
1178 (y-or-n-p "Do you really want to send current draft? "))
1179 (let ((send-mail-function 'wl-draft-raw-send)
1180 (editing-buffer (current-buffer))
1181 (sending-buffer (wl-draft-generate-clone-buffer
1182 " *wl-draft-sending-buffer*"
1183 (append wl-draft-config-variables
1184 (wl-draft-clone-local-variables))))
1185 (wl-draft-verbose-msg nil)
1188 (save-excursion (set-buffer sending-buffer)
1189 (if (and (not (wl-message-mail-p))
1190 (not (wl-message-news-p)))
1191 (error "No recipient is specified"))
1192 (expand-abbrev) ; for mail-abbrevs
1193 (run-hooks 'mail-send-hook) ; translate buffer
1194 (if wl-draft-verbose-send
1195 (message (or mes-string "Sending...")))
1196 (funcall wl-draft-send-function editing-buffer kill-when-done)
1197 ;; Now perform actions on successful sending.
1198 (while mail-send-actions
1200 (apply (car (car mail-send-actions))
1201 (cdr (car mail-send-actions)))
1203 (setq mail-send-actions (cdr mail-send-actions)))
1204 ;; (if (or (eq major-mode 'wl-draft-mode)
1205 ;; (eq major-mode 'mail-mode))
1206 ;; (local-set-key "\C-c\C-s" 'wl-draft-send)) ; override
1207 (if wl-draft-verbose-send
1208 (message (concat (or wl-draft-verbose-msg
1209 mes-string "Sending...")
1211 ;; kill sending buffer, anyway.
1212 (and (buffer-live-p sending-buffer)
1213 (kill-buffer sending-buffer))))))
1215 (defun wl-draft-save ()
1216 "Save current draft."
1219 (wl-draft-config-info-operation
1220 (and (string-match "[0-9]+$" wl-draft-buffer-file-name)
1222 (match-string 0 wl-draft-buffer-file-name)))
1225 (defun wl-draft-mimic-kill-buffer ()
1226 "Kill the current (draft) buffer with query."
1228 (let ((bufname (read-buffer (format "Kill buffer: (default %s) "
1231 (if (or (not bufname)
1232 (string-equal bufname "")
1233 (string-equal bufname (buffer-name)))
1234 (wl-draft-save-and-exit)
1235 (kill-buffer bufname))))
1237 (defun wl-draft-save-and-exit ()
1238 "Save current draft and exit current draft mode."
1241 (let ((editing-buffer (current-buffer)))
1242 (wl-draft-hide editing-buffer)
1243 (kill-buffer editing-buffer)))
1245 (defun wl-draft-send-and-exit ()
1246 "Send current draft message and kill it."
1250 (defun wl-draft-send-from-toolbar ()
1252 (let ((wl-interactive-send t))
1253 (wl-draft-send-and-exit)))
1255 (defun wl-draft-delete-field (field &optional delimline)
1256 (wl-draft-delete-fields (regexp-quote field) delimline))
1258 (defun wl-draft-delete-fields (regexp &optional delimline)
1261 (if (search-forward "\n\n" nil t)
1262 (setq delimline (point))
1263 (setq delimline (point-max))))
1264 (narrow-to-region (point-min) delimline)
1265 (goto-char (point-min))
1266 (let ((regexp (concat "^" regexp ":"))
1267 (case-fold-search t)
1270 (if (looking-at regexp)
1276 (if (re-search-forward "^[^ \t]" nil t)
1277 (goto-char (match-beginning 0))
1280 (if (re-search-forward "^[^ \t]" nil t)
1281 (goto-char (match-beginning 0))
1284 (defun wl-draft-get-fcc-list (header-end)
1286 (case-fold-search t))
1287 (or (markerp header-end) (error "HEADER-END must be a marker"))
1289 (goto-char (point-min))
1290 (while (re-search-forward "^Fcc:[ \t]*" header-end t)
1292 (cons (buffer-substring-no-properties
1296 (skip-chars-backward " \t")
1300 (wl-folder-confirm-existence
1301 (wl-folder-get-elmo-folder (eword-decode-string (car fcc-list)))))
1302 (delete-region (match-beginning 0)
1303 (progn (forward-line 1) (point)))))
1306 (defun wl-draft-do-fcc (header-end &optional fcc-list)
1307 (let ((send-mail-buffer (current-buffer))
1308 (tembuf (generate-new-buffer " fcc output"))
1309 (case-fold-search t)
1311 (or (markerp header-end) (error "HEADER-END must be a marker"))
1314 (setq fcc-list (wl-draft-get-fcc-list header-end)))
1317 ;; insert just the headers to avoid moving the gap more than
1318 ;; necessary (the message body could be arbitrarily huge.)
1319 (insert-buffer-substring send-mail-buffer 1 header-end)
1320 (wl-draft-insert-required-fields t)
1321 (goto-char (point-max))
1322 (insert-buffer-substring send-mail-buffer header-end)
1323 (let ((id (std11-field-body "Message-ID"))
1324 (elmo-enable-disconnected-operation t)
1327 (unless (or cache-saved
1328 (elmo-folder-plugged-p
1329 (wl-folder-get-elmo-folder (car fcc-list))))
1330 (elmo-file-cache-save id nil) ;; for disconnected operation
1331 (setq cache-saved t))
1332 (if (elmo-folder-append-buffer
1333 (wl-folder-get-elmo-folder
1334 (eword-decode-string (car fcc-list)))
1335 (not wl-fcc-force-as-read))
1336 (wl-draft-write-sendlog 'ok 'fcc nil (car fcc-list) id)
1337 (wl-draft-write-sendlog 'failed 'fcc nil (car fcc-list) id))
1338 (setq fcc-list (cdr fcc-list)))))
1339 (kill-buffer tembuf)))
1341 (defun wl-draft-on-field-p ()
1344 (goto-char (point-min))
1345 (search-forward (concat "\n" mail-header-separator "\n") nil 0)
1352 (if (or (looking-at ".*,[ \t]?$")
1353 (looking-at "^[^ \t]+:[ \t]+.*:$")); group list name
1355 (let ((pos (point)))
1358 (if (looking-at "^[ \t]")
1360 (if (re-search-forward ":" pos t) nil t)))))))
1362 (defun wl-draft-random-alphabet ()
1363 (let ((alphabet '(?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K ?L ?M ?N ?O ?P ?Q ?R ?S ?T ?U ?V ?W ?X ?Y ?Z)))
1364 (nth (abs (% (random) 26)) alphabet)))
1367 (defun wl-draft (&optional to subject in-reply-to cc references newsgroups
1369 content-type content-transfer-encoding
1370 body edit-again summary-buf from parent-folder)
1371 "Write and send mail/news message with Wanderlust."
1378 (wl-plugged-init t))
1379 (wl-init) ; returns immediately if already initialized.
1381 (setq summary-buf (wl-summary-get-buffer (wl-summary-buffer-folder-name))))
1382 (let ((draft-folder (wl-folder-get-elmo-folder wl-draft-folder))
1383 buf-name file-name num wl-demo change-major-mode-hook)
1384 (if (not (elmo-folder-message-file-p draft-folder))
1385 (error "%s folder cannot be used for draft folder" wl-draft-folder))
1386 (setq num (elmo-max-of-list
1387 (or (elmo-folder-list-messages draft-folder) '(0))))
1388 (setq num (+ 1 num))
1389 ;; To get unused buffer name.
1390 (while (get-buffer (concat wl-draft-folder "/" (int-to-string num)))
1391 (setq num (+ 1 num)))
1392 (setq buf-name (find-file-noselect
1394 (elmo-message-file-name
1395 (wl-folder-get-elmo-folder wl-draft-folder)
1397 (if wl-draft-use-frame
1398 (switch-to-buffer-other-frame buf-name)
1399 (switch-to-buffer buf-name))
1400 (set-buffer buf-name)
1401 (if (not (string-match (regexp-quote wl-draft-folder)
1403 (rename-buffer (concat wl-draft-folder "/" (int-to-string num))))
1404 (if (or (eq wl-draft-reply-buffer-style 'full)
1405 (eq this-command 'wl-draft)
1406 (eq this-command 'wl-summary-write)
1407 (eq this-command 'wl-summary-write-current-folder))
1408 (delete-other-windows))
1411 (make-local-variable 'truncate-partial-width-windows)
1412 (setq truncate-partial-width-windows nil)
1413 (setq truncate-lines wl-draft-truncate-lines)
1414 (setq wl-sent-message-via nil)
1415 (setq wl-sent-message-queued nil)
1416 (setq wl-draft-parent-folder parent-folder)
1417 (if (stringp (or from wl-from))
1418 (insert "From: " (or from wl-from) "\n"))
1419 (and (or (interactive-p)
1420 (eq this-command 'wl-summary-write)
1422 (insert "To: " (or to "") "\n"))
1423 (and cc (insert "Cc: " (or cc "") "\n"))
1424 (insert "Subject: " (or subject "") "\n")
1425 (and newsgroups (insert "Newsgroups: " newsgroups "\n"))
1426 (and mail-followup-to (insert "Mail-Followup-To: " mail-followup-to "\n"))
1427 (and wl-insert-mail-reply-to
1428 (insert "Mail-Reply-To: "
1429 (wl-address-header-extract-address
1431 (and in-reply-to (insert "In-Reply-To: " in-reply-to "\n"))
1432 (and references (insert "References: " references "\n"))
1433 (insert (funcall wl-generate-mailer-string-function) "\n")
1434 (setq wl-draft-buffer-file-name file-name)
1435 (if mail-default-reply-to
1436 (insert "Reply-To: " mail-default-reply-to "\n"))
1437 (wl-draft-insert-ccs "Bcc: " (or wl-bcc
1438 (and mail-self-blind (user-login-name))))
1439 (wl-draft-insert-ccs "Fcc: " wl-fcc)
1441 (insert "Organization: " wl-organization "\n"))
1442 (and wl-auto-insert-x-face
1443 (file-exists-p wl-x-face-file)
1444 (wl-draft-insert-x-face-field-here))
1445 (if mail-default-headers
1446 (insert mail-default-headers))
1447 (if (not (= (preceding-char) ?\n))
1451 (setq start (point))
1453 (insert "Content-type: " content-type "\n"))
1454 (when content-transfer-encoding
1455 (insert "Content-Transfer-Encoding: " content-transfer-encoding "\n"))
1456 (if (or content-type content-transfer-encoding)
1458 (and body (insert body))
1460 (narrow-to-region start (point))
1462 (wl-draft-decode-message-in-buffer))
1465 (put-text-property (point)
1467 (insert mail-header-separator "\n")
1469 'category 'mail-header-separator)))
1470 (put-text-property (point)
1472 (insert mail-header-separator "\n")
1474 'category 'mail-header-separator)
1475 (and body (insert body)))
1476 (as-binary-output-file
1477 (write-region (point-min)(point-max) wl-draft-buffer-file-name
1479 (wl-draft-editor-mode)
1480 (wl-draft-overload-functions)
1481 (wl-highlight-headers 'for-draft)
1482 (goto-char (point-min))
1483 (setq wl-draft-config-exec-flag t)
1485 (run-hooks 'wl-mail-setup-hook))
1486 (wl-user-agent-compose-internal) ;; user-agent
1487 (cond ((eq this-command 'wl-summary-write-current-newsgroup)
1488 (mail-position-on-field "Subject"))
1489 ((and (interactive-p) (null to))
1490 (mail-position-on-field "To"))
1492 (goto-char (point-max))))
1493 (setq wl-draft-buffer-cur-summary-buffer (or summary-buf
1495 wl-summary-buffer-name)))
1498 (defsubst wl-draft-insert-ccs (str cc)
1504 (null (and wl-draft-delete-myself-from-bcc-fcc
1506 (mapcar 'wl-address-header-extract-address
1508 (wl-parse-addresses (std11-field-body "To"))
1509 (wl-parse-addresses (std11-field-body "Cc"))))
1510 (mapcar 'downcase wl-subscribed-mailing-list)))))
1511 (insert str field "\n"))))
1513 (defun wl-draft-elmo-nntp-send ()
1514 (let ((elmo-nntp-post-pre-hook wl-news-send-pre-hook)
1515 (elmo-nntp-default-user
1516 (or wl-nntp-posting-user elmo-nntp-default-user))
1517 (elmo-nntp-default-server
1518 (or wl-nntp-posting-server elmo-nntp-default-server))
1519 (elmo-nntp-default-port
1520 (or wl-nntp-posting-port elmo-nntp-default-port))
1521 (elmo-nntp-default-stream-type
1522 (or wl-nntp-posting-stream-type elmo-nntp-default-stream-type)))
1523 (if (not (elmo-plugged-p elmo-nntp-default-server elmo-nntp-default-port))
1524 (wl-draft-set-sent-message 'news 'unplugged
1525 (cons elmo-nntp-default-server
1526 elmo-nntp-default-port))
1527 (elmo-nntp-post elmo-nntp-default-server (current-buffer))
1528 (wl-draft-set-sent-message 'news 'sent)
1529 (wl-draft-write-sendlog 'ok 'nntp elmo-nntp-default-server
1530 (std11-field-body "Newsgroups")
1531 (std11-field-body "Message-ID")))))
1533 (defun wl-draft-generate-clone-buffer (name &optional local-variables)
1534 "Generate clone of current buffer named NAME."
1535 (let ((editing-buffer (current-buffer)))
1537 (set-buffer (generate-new-buffer name))
1540 (wl-draft-editor-mode)
1541 (insert-buffer editing-buffer)
1543 (while local-variables
1544 (make-local-variable (car local-variables))
1545 (set (car local-variables)
1547 (set-buffer editing-buffer)
1548 (symbol-value (car local-variables))))
1549 (setq local-variables (cdr local-variables)))
1552 (defun wl-draft-reedit (number)
1553 (let ((draft-folder (wl-folder-get-elmo-folder wl-draft-folder))
1555 buf-name file-name change-major-mode-hook)
1556 (setq file-name (elmo-message-file-name draft-folder number))
1557 (unless (file-exists-p file-name)
1558 (error "File %s does not exist" file-name))
1559 (setq buf-name (find-file-noselect file-name))
1560 (if wl-draft-use-frame
1561 (switch-to-buffer-other-frame buf-name)
1562 (switch-to-buffer buf-name))
1563 (set-buffer buf-name)
1564 (if (not (string-match (regexp-quote wl-draft-folder)
1566 (rename-buffer (concat wl-draft-folder "/" (buffer-name))))
1569 (setq wl-sent-message-via nil)
1570 (setq wl-sent-message-queued nil)
1571 (setq wl-draft-buffer-file-name file-name)
1572 (wl-draft-config-info-operation number 'load)
1573 (goto-char (point-min))
1574 (or (re-search-forward "\n\n" nil t)
1575 (search-forward (concat mail-header-separator "\n") nil t))
1576 (write-region (point-min)(point-max) wl-draft-buffer-file-name
1578 (wl-draft-overload-functions)
1579 (wl-draft-editor-mode)
1580 (wl-highlight-headers 'for-draft)
1581 (run-hooks 'wl-draft-reedit-hook)
1582 (goto-char (point-max))
1586 (defmacro wl-draft-body-goto-top ()
1588 (goto-char (point-min))
1589 (if (re-search-forward mail-header-separator nil t)
1591 (goto-char (point-max))))))
1593 (defmacro wl-draft-body-goto-bottom ()
1594 (` (goto-char (point-max))))
1596 (defmacro wl-draft-config-body-goto-header ()
1598 (goto-char (point-min))
1599 (if (re-search-forward mail-header-separator nil t)
1601 (goto-char (point-max))))))
1603 (defun wl-draft-config-sub-body (content)
1604 (wl-draft-body-goto-top)
1605 (delete-region (point) (point-max))
1606 (if content (insert (eval content))))
1608 (defun wl-draft-config-sub-top (content)
1609 (wl-draft-body-goto-top)
1610 (if content (insert (eval content))))
1612 (defun wl-draft-config-sub-bottom (content)
1613 (wl-draft-body-goto-bottom)
1614 (if content (insert (eval content))))
1616 (defun wl-draft-config-sub-header (content)
1617 (wl-draft-config-body-goto-header)
1618 (if content (insert (concat (eval content) "\n"))))
1620 (defun wl-draft-config-sub-header-top (content)
1621 (goto-char (point-min))
1622 (if content (insert (concat (eval content) "\n"))))
1624 (defun wl-draft-config-sub-part-top (content)
1625 (goto-char (mime-edit-content-beginning))
1626 (if content (insert (concat (eval content) "\n"))))
1628 (defun wl-draft-config-sub-part-bottom (content)
1629 (goto-char (mime-edit-content-end))
1630 (if content (insert (concat (eval content) "\n"))))
1632 (defsubst wl-draft-config-sub-file (content)
1633 (let ((coding-system-for-read wl-cs-autoconv)
1634 (file (expand-file-name (eval content))))
1635 (if (file-exists-p file)
1636 (insert-file-contents file)
1637 (error "%s: no exists file" file))))
1639 (defun wl-draft-config-sub-body-file (content)
1640 (wl-draft-body-goto-top)
1641 (delete-region (point) (point-max))
1642 (wl-draft-config-sub-file content))
1644 (defun wl-draft-config-sub-top-file (content)
1645 (wl-draft-body-goto-top)
1646 (wl-draft-config-sub-file content))
1648 (defun wl-draft-config-sub-bottom-file (content)
1649 (wl-draft-body-goto-bottom)
1650 (wl-draft-config-sub-file content))
1652 (defun wl-draft-config-sub-header-file (content)
1653 (wl-draft-config-body-goto-header)
1654 (wl-draft-config-sub-file content))
1656 (defun wl-draft-config-sub-template (content)
1657 (setq wl-draft-config-variables
1658 (wl-template-insert (eval content))))
1660 (defun wl-draft-config-sub-x-face (content)
1661 (if (and (string-match "\\.xbm\\(\\.gz\\)?$" content)
1662 (fboundp 'x-face-insert)) ; x-face.el is installed.
1663 (x-face-insert content)
1664 (wl-draft-replace-field "X-Face" (elmo-get-file-string content t) t)))
1666 (defsubst wl-draft-config-sub-func (field content)
1668 (if (setq func (assq field wl-draft-config-sub-func-alist))
1669 (let (wl-draft-config-variables)
1670 (funcall (cdr func) content)
1671 ;; for wl-draft-config-sub-template
1672 (cons t wl-draft-config-variables)))))
1674 (defsubst wl-draft-config-exec-sub (clist)
1675 (let (config local-variables)
1677 (setq config (car clist))
1682 (let ((field (car config))
1683 (content (cdr config))
1687 (wl-draft-replace-field field (eval content) t))
1688 ((setq ret-val (wl-draft-config-sub-func field content))
1689 (if (cdr ret-val) ;; for wl-draft-config-sub-template
1690 (wl-append local-variables (cdr ret-val))))
1691 ((boundp field) ;; variable
1692 (make-local-variable field)
1693 (set field (eval content))
1694 (wl-append local-variables (list field)))
1696 (error "%s: not variable" field)))))
1698 (error "%s: not supported type" config)))
1699 (setq clist (cdr clist)))
1702 (defun wl-draft-prepared-config-exec (&optional config-alist reply-buf)
1703 "Change headers in draft preparation time."
1705 (unless wl-draft-reedit
1708 (and (boundp 'wl-draft-prepared-config-alist)
1709 wl-draft-prepared-config-alist) ;; For compatible.
1710 wl-draft-config-alist)))
1712 (wl-draft-config-exec config-alist reply-buf)))))
1714 (defun wl-draft-config-exec (&optional config-alist reply-buf)
1715 "Change headers in draft sending time."
1717 (let ((case-fold-search t)
1718 (alist (or config-alist wl-draft-config-alist))
1719 (reply-buf (or reply-buf (and (buffer-live-p wl-draft-reply-buffer)
1720 wl-draft-reply-buffer)))
1721 (local-variables wl-draft-config-variables)
1723 (when (and (or (interactive-p)
1724 wl-draft-config-exec-flag)
1729 (setq key (caar alist)
1736 (set-buffer reply-buf)
1738 (std11-narrow-to-header)
1739 (goto-char (point-min))
1740 (re-search-forward (car clist) nil t))))
1741 (wl-draft-config-exec-sub (cdr clist))
1744 (when (save-restriction
1745 (std11-narrow-to-header mail-header-separator)
1746 (goto-char (point-min))
1747 (re-search-forward key nil t))
1748 (wl-append local-variables
1749 (wl-draft-config-exec-sub clist))
1752 (wl-append local-variables
1753 (wl-draft-config-exec-sub clist))
1755 (if (and found wl-draft-config-matchone)
1757 (setq alist (cdr alist))))
1759 (setq wl-draft-config-exec-flag nil))
1760 (run-hooks 'wl-draft-config-exec-hook)
1761 (put-text-property (point-min)(point-max) 'face nil)
1762 (wl-highlight-message (point-min)(point-max) t)
1763 (setq wl-draft-config-variables
1764 (elmo-uniq-list local-variables))))))
1766 (defun wl-draft-replace-field (field content &optional add)
1769 (let ((case-fold-search t)
1770 (inhibit-read-only t) ;; added by teranisi.
1772 (std11-narrow-to-header mail-header-separator)
1773 (goto-char (point-min))
1774 (if (re-search-forward (concat "^" (regexp-quote field) ":") nil t)
1779 (re-search-forward "^[^ \t]" nil 'move)
1781 (skip-chars-backward "\n")
1782 (delete-region beg (point))
1783 (insert " " content))
1788 (re-search-forward "^[^ \t]" nil 'move)
1790 (delete-region beg (point)))
1791 (when (and add content)
1793 (goto-char (point-max))
1794 (insert (concat field ": " content "\n"))))))))
1796 (defun wl-draft-config-info-operation (msg operation)
1797 (let* ((msgdb-dir (elmo-folder-msgdb-path (wl-folder-get-elmo-folder
1801 (format "%s-%d" wl-draft-config-save-filename msg)
1803 element alist variable)
1805 ((eq operation 'save)
1806 (let ((variables (elmo-uniq-list wl-draft-config-variables)))
1807 (while (setq variable (pop variables))
1808 (when (boundp variable)
1810 (list (cons variable (eval variable))))))
1811 (elmo-object-save filename alist)))
1812 ((eq operation 'load)
1813 (setq alist (elmo-object-load filename))
1814 (while (setq element (pop alist))
1815 (set (make-local-variable (car element)) (cdr element))
1816 (wl-append wl-draft-config-variables (list (car element)))))
1817 ((eq operation 'delete)
1818 (if (file-exists-p filename)
1819 (delete-file filename))))))
1821 (defun wl-draft-queue-info-operation (msg operation
1822 &optional add-sent-message-via)
1823 (let* ((msgdb-dir (elmo-folder-msgdb-path
1824 (wl-folder-get-elmo-folder wl-queue-folder)))
1827 (format "%s-%d" wl-draft-queue-save-filename msg)
1829 element alist variable)
1831 ((eq operation 'save)
1832 (let ((variables (elmo-uniq-list
1833 (append wl-draft-queue-save-variables
1834 wl-draft-config-variables
1835 (list 'wl-draft-fcc-list)))))
1836 (if add-sent-message-via
1838 (push 'wl-sent-message-queued variables)
1839 (push 'wl-sent-message-via variables)))
1840 (while (setq variable (pop variables))
1841 (when (boundp variable)
1843 (list (cons variable (eval variable))))))
1844 (elmo-object-save filename alist)))
1845 ((eq operation 'load)
1846 (setq alist (elmo-object-load filename))
1847 (while (setq element (pop alist))
1848 (set (make-local-variable (car element)) (cdr element))))
1849 ((eq operation 'get-sent-via)
1850 (setq alist (elmo-object-load filename))
1851 (cdr (assq 'wl-sent-message-via alist)))
1852 ((eq operation 'delete)
1853 (if (file-exists-p filename)
1854 (delete-file filename))))))
1856 (defun wl-draft-queue-append (wl-sent-message-via)
1857 (if wl-draft-verbose-send
1858 (message "Queuing..."))
1859 (let ((send-buffer (current-buffer))
1860 (folder (wl-folder-get-elmo-folder wl-queue-folder))
1861 (message-id (std11-field-body "Message-ID")))
1862 (if (elmo-folder-append-buffer folder t)
1864 (wl-draft-queue-info-operation
1865 (car (elmo-folder-status folder))
1866 'save wl-sent-message-via)
1867 (wl-draft-write-sendlog 'ok 'queue nil wl-queue-folder message-id)
1868 (when wl-draft-verbose-send
1869 (setq wl-draft-verbose-msg "Queuing...")
1870 (message "Queuing...done")))
1871 (wl-draft-write-sendlog 'failed 'queue nil wl-queue-folder message-id)
1872 (error "Queuing failed"))))
1874 (defun wl-draft-queue-flush ()
1875 "Flush draft queue."
1877 (let* ((queue-folder (wl-folder-get-elmo-folder wl-queue-folder))
1879 (elmo-folder-open-internal queue-folder)
1880 (elmo-folder-list-messages queue-folder)))
1883 (wl-draft-queue-flushing t)
1884 msgs failure len buffer msgid sent-via)
1885 ;; get plugged send message
1887 (setq sent-via (wl-draft-queue-info-operation (car msgs2) 'get-sent-via))
1890 (when (and (eq (nth 1 (car sent-via)) 'unplugged)
1891 (or (not (nth 2 (car sent-via)))
1893 (car (nth 2 (car sent-via)))
1894 (cdr (nth 2 (car sent-via))))))
1895 (wl-append msgs (list (car msgs2)))
1897 (setq sent-via (cdr sent-via))))
1898 (setq msgs2 (cdr msgs2)))
1899 (when (> (setq len (length msgs)) 0)
1900 (if (elmo-y-or-n-p (format
1901 "%d message(s) are in the sending queue. Send now? "
1903 (not elmo-dop-flush-confirm) t)
1906 (setq buffer (get-buffer-create " *wl-draft-queue-flush*"))
1909 ;; reset buffer local variables
1910 (kill-all-local-variables)
1914 (setq wl-sent-message-via nil)
1915 (wl-draft-queue-info-operation (car msgs) 'load)
1916 (elmo-message-fetch queue-folder
1918 (elmo-make-fetch-strategy 'entire)
1919 nil (current-buffer))
1921 (setq failure (funcall
1922 wl-draft-queue-flush-send-function
1923 (format "Sending (%d/%d)..." i len)))
1924 ;;; (wl-draft-raw-send nil nil
1925 ;;; (format "Sending (%d/%d)..." i len))
1927 (elmo-display-error err t)
1931 (if (eq wl-sent-message-modified 'requeue)
1933 (elmo-folder-delete-messages
1934 queue-folder (cons (car msgs) nil))
1935 (wl-draft-queue-info-operation (car msgs) 'delete))
1937 (elmo-folder-delete-messages
1938 queue-folder (cons (car msgs) nil))
1939 (wl-draft-queue-info-operation (car msgs) 'delete)
1940 (setq performed (+ 1 performed))))
1941 (setq msgs (cdr msgs)))
1942 (kill-buffer buffer)
1943 (message "%d message(s) are sent." performed)))
1944 (message "%d message(s) are remained to be sent." len))
1945 (elmo-folder-close queue-folder)
1948 (defun wl-jump-to-draft-buffer (&optional arg)
1949 "Jump to the draft if exists."
1952 (wl-jump-to-draft-folder)
1953 (let ((bufs (buffer-list))
1954 (draft-regexp (concat
1956 (elmo-localdir-folder-directory-internal
1957 (wl-folder-get-elmo-folder wl-draft-folder)))))
1961 (setq buf (buffer-file-name (car bufs)))
1962 (string-match draft-regexp buf))
1963 (setq draft-bufs (cons (buffer-name (car bufs)) draft-bufs)))
1964 (setq bufs (cdr bufs)))
1967 (message "No draft buffer exist."))
1970 (sort draft-bufs (function (lambda (a b) (not (string< a b))))))
1971 (if (setq buf (cdr (member (buffer-name) draft-bufs)))
1972 (setq buf (car buf))
1973 (setq buf (car draft-bufs)))
1974 (switch-to-buffer buf))))))
1976 (defun wl-jump-to-draft-folder ()
1977 (let ((msgs (reverse (elmo-folder-list-messages (wl-folder-get-elmo-folder
1979 (mybuf (buffer-name))
1982 (message "No draft message exist.")
1983 (if (string-match (concat "^" wl-draft-folder "/") mybuf)
1984 (setq msg (cadr (memq
1985 (string-to-int (substring mybuf (match-end 0)))
1987 (or msg (setq msg (car msgs)))
1988 (if (setq buf (get-buffer (format "%s/%d" wl-draft-folder msg)))
1989 (switch-to-buffer buf)
1990 (wl-draft-reedit msg)))))
1992 (defun wl-draft-highlight-and-recenter (&optional n)
1994 (if wl-highlight-body-too
1995 (let ((beg (point-min))
1997 (put-text-property beg end 'face nil)
1998 (wl-highlight-message beg end t)))
2001 ;;;; user-agent support by Sen Nagata
2003 ;; this appears to be necessarily global...
2004 (defvar wl-user-agent-compose-p nil)
2005 (defvar wl-user-agent-headers-and-body-alist nil)
2007 ;; this should be a generic function for mail-mode -- i wish there was
2008 ;; something like it in sendmail.el
2009 (defun wl-user-agent-insert-header (header-name header-value)
2010 "Insert HEADER-NAME w/ value HEADER-VALUE into a message."
2011 ;; it seems like overriding existing headers is acceptable -- should
2012 ;; we provide an option?
2014 ;; plan was: unfold header (might be folded), remove existing value, insert
2016 ;; wl doesn't seem to fold header lines yet anyway :-)
2018 (let ((kill-whole-line t)
2020 (mail-position-on-field (capitalize header-name))
2021 (setq end-of-line (point))
2023 (re-search-forward ":" end-of-line)
2024 (insert (concat " " header-value "\n"))
2027 ;; this should be a generic function for mail-mode -- i wish there was
2028 ;; something like it in sendmail.el
2030 ;; ** haven't dealt w/ case where the body is already set **
2031 (defun wl-user-agent-insert-body (body-text)
2032 "Insert a body of text, BODY-TEXT, into a message."
2033 ;; code defensively... :-P
2034 (goto-char (point-min))
2035 (search-forward mail-header-separator)
2040 (defun wl-user-agent-compose (&optional to subject other-headers continue
2041 switch-function yank-action
2043 "Support the `compose-mail' interface for wl.
2044 Only support for TO, SUBJECT, and OTHER-HEADERS has been implemented.
2045 Support for CONTINUE, YANK-ACTION, and SEND-ACTIONS has not
2046 been implemented yet. Partial support for SWITCH-FUNCTION now supported."
2048 (unless (featurep 'wl)
2050 ;; protect these -- to and subject get bound at some point, so it looks
2051 ;; to be necessary to protect the values used w/in
2052 (let ((wl-user-agent-headers-and-body-alist other-headers)
2053 (wl-draft-use-frame (eq switch-function 'switch-to-buffer-other-frame))
2054 (wl-draft-reply-buffer-style 'split))
2055 (when (eq switch-function 'switch-to-buffer-other-window)
2056 (when (one-window-p t)
2057 (if (window-minibuffer-p) (other-window 1))
2061 (if (wl-string-match-assoc "to" wl-user-agent-headers-and-body-alist
2064 (wl-string-match-assoc "to" wl-user-agent-headers-and-body-alist
2067 (setq wl-user-agent-headers-and-body-alist
2068 (cons (cons "to" to)
2069 wl-user-agent-headers-and-body-alist))))
2071 (if (wl-string-match-assoc "subject"
2072 wl-user-agent-headers-and-body-alist
2075 (wl-string-match-assoc "subject"
2076 wl-user-agent-headers-and-body-alist
2079 (setq wl-user-agent-headers-and-body-alist
2080 (cons (cons "subject" subject)
2081 wl-user-agent-headers-and-body-alist))))
2082 ;; i think this is what we want to use...
2085 ;; tell the hook-function to do its stuff
2086 (setq wl-user-agent-compose-p t)
2087 ;; because to get the hooks working, wl-draft has to think it has
2088 ;; been called interactively
2089 (call-interactively 'wl-draft))
2090 (setq wl-user-agent-compose-p nil))))
2092 (defun wl-user-agent-compose-internal ()
2093 "Manipulate headers and/or a body of a draft message."
2094 ;; being called from wl-user-agent-compose?
2095 (if wl-user-agent-compose-p
2098 (let ((headers wl-user-agent-headers-and-body-alist)
2099 (case-fold-search t))
2102 (if (not (string-match "^body$" (car (car headers))))
2103 (wl-user-agent-insert-header
2104 (car (car headers)) (cdr (car headers)))
2106 (setq headers (cdr headers))))
2107 ;; highlight headers (from wl-draft in wl-draft.el)
2108 (wl-highlight-headers 'for-draft)
2110 (if (wl-string-match-assoc "body" wl-user-agent-headers-and-body-alist
2112 (wl-user-agent-insert-body
2113 (cdr (wl-string-match-assoc
2115 wl-user-agent-headers-and-body-alist 'ignore-case)))))
2119 (product-provide (provide 'wl-draft) (require 'wl-version))
2121 ;;; wl-draft.el ends here