2 ;;; tm-mh-e.el --- tm-mh-e functions for composing messages
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1993 .. 1996 MORIOKA Tomohiko
6 ;;; Copyright (C) 1995,1996 OKABE Yasuo
8 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
9 ;;; OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
10 ;;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
11 ;;; Created: 1996/2/29 (separated from tm-mh-e.el)
13 ;;; $Id: tmh-comp.el,v 7.5 1996/07/31 03:07:43 morioka Exp $
14 ;;; Keywords: mail, MH, MIME, multimedia, encoded-word, multilingual
16 ;;; This file is part of tm (Tools for MIME).
18 ;;; This program is free software; you can redistribute it and/or
19 ;;; modify it under the terms of the GNU General Public License as
20 ;;; published by the Free Software Foundation; either version 2, or
21 ;;; (at your option) any later version.
23 ;;; This program is distributed in the hope that it will be useful,
24 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 ;;; General Public License for more details.
28 ;;; You should have received a copy of the GNU General Public License
29 ;;; along with This program. If not, write to the Free Software
30 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
41 (defvar tm-mh-e/forwcomps "forwcomps"
42 "Name of file to be used as a skeleton for forwarding messages.
43 Default is \"forwcomps\". If not a complete path name, the file
44 is searched for first in the user's MH directory, then in the
45 system MH lib directory.")
47 (defvar tm-mh-e/message-yank-function 'mh-yank-cur-msg)
53 (defun tm-mh-e::make-message (folder number)
54 (vector folder number)
57 (defun tm-mh-e::message/folder (message)
61 (defun tm-mh-e::message/number (message)
65 (defun tm-mh-e::message/file-name (message)
67 (tm-mh-e::message/number message)
68 (mh-expand-file-name (tm-mh-e::message/folder message))
71 ;;; modified by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
72 ;;; 1995/11/14 (cf. [tm-ja:1096])
73 (defun tm-mh-e/prompt-for-message (prompt folder &optional default)
75 (directory-files (mh-expand-file-name folder) nil "^[0-9]+$")
77 (folder-buf (get-buffer folder))
81 (set-buffer folder-buf)
82 (let* ((show-buffer (get-buffer mh-show-buffer))
83 (show-buffer-file-name
84 (buffer-file-name show-buffer)))
85 (if show-buffer-file-name
86 (file-name-nondirectory show-buffer-file-name)))))))
87 (if (or (null default)
88 (not (string-match "^[0-9]+$" default)))
90 (if (and (string= folder mh-sent-from-folder)
92 (int-to-string mh-sent-from-msg)
96 (= 0 (mh-exec-cmd-quiet nil "pick" folder "cur"))
97 (set-buffer mh-temp-buffer)
98 (setq cur-msg (buffer-string))
99 (string-match "^[0-9]+$" cur-msg))
100 (substring cur-msg 0 (match-end 0))
102 (completing-read prompt
113 ;;; modified by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
114 ;;; 1995/11/14 (cf. [tm-ja:1096])
115 (defun tm-mh-e/query-message (&optional message)
119 (setq folder (tm-mh-e::message/folder message))
120 (setq number (tm-mh-e::message/number message))
123 (setq folder (mh-prompt-for-folder
125 (if (and (stringp mh-sent-from-folder)
126 (string-match "^\\+" mh-sent-from-folder))
127 mh-sent-from-folder "+inbox")
131 (number-to-string number)
132 (tm-mh-e/prompt-for-message "Message number: " folder)
134 (tm-mh-e::make-message folder number)
137 (defun tm-mh-e/insert-message (&optional message)
138 ;; always ignores message
139 (let ((article-buffer
140 (if (not (and (stringp mh-sent-from-folder)
141 (numberp mh-sent-from-msg)
143 (cond ((and (boundp 'gnus-original-article-buffer)
144 (bufferp mh-sent-from-folder)
145 (get-buffer gnus-original-article-buffer)
147 gnus-original-article-buffer)
148 ((and (boundp 'gnus-article-buffer)
149 (get-buffer gnus-article-buffer)
150 (bufferp mh-sent-from-folder)
153 (set-buffer gnus-article-buffer)
154 (if (eq major-mode 'mime/viewer-mode)
155 mime::preview/article-buffer
159 (if (null article-buffer)
161 (tm-mh-e::make-message mh-sent-from-folder mh-sent-from-msg)
163 (insert-buffer article-buffer)
164 (mime-editor/inserted-message-filter)
168 (defun tm-mh-e/insert-mail (&optional message)
172 (tm-mh-e::message/file-name (tm-mh-e/query-message message))))
173 (narrow-to-region (point) (point))
174 (insert-file-contents message-file)
175 (push-mark (point-max))
176 (mime-editor/inserted-message-filter)
179 (set-alist 'mime-editor/message-inserter-alist
180 'mh-letter-mode (function tm-mh-e/insert-message))
181 (set-alist 'mime-editor/mail-inserter-alist
182 'mh-letter-mode (function tm-mh-e/insert-mail))
183 (set-alist 'mime-editor/mail-inserter-alist
184 'news-reply-mode (function tm-mh-e/insert-mail))
186 'mime-editor/split-message-sender-alist
189 (lambda (&optional arg)
191 (write-region (point-min) (point-max)
192 mime-editor/draft-file-name nil 'no-message)
194 (pop-to-buffer "MH mail delivery")
196 (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
199 mime-editor/draft-file-name)
200 (goto-char (point-max)) ; show the interesting part
204 (apply 'mh-exec-cmd-quiet t mh-send-prog
206 (list "-nopush" "-nodraftfolder"
207 "-noverbose" "-nowatch"
208 mh-send-args mime-editor/draft-file-name)))))
212 ;;; @ commands using tm-edit features
215 (defun tm-mh-e/edit-again (msg)
216 "Clean-up a draft or a message previously sent and make it resendable.
217 Default is the current message.
218 The variable mh-new-draft-cleaned-headers specifies the headers to remove.
219 See also documentation for `\\[mh-send]' function."
220 (interactive (list (mh-get-msg-num t)))
222 (let* ((from-folder mh-current-folder)
223 (config (current-window-configuration))
226 (cond ((and mh-draft-folder (equal from-folder mh-draft-folder))
227 (let ((name (format "draft-%d" msg)))
228 (if (get-buffer name)
229 (throw 'tag (pop-to-buffer name))
231 (let ((file-coding-system-for-read *noconv*)
233 (mh-msg-filename msg mh-draft-folder)
235 (set-buffer (get-buffer-create name))
236 (insert-file-contents filename)
237 (setq buffer-file-name filename)
238 (setq code-conversion t)
241 (if (re-search-forward "\\(^$\\|^-+$\\)" nil t)
247 (let ((file-coding-system-for-read *noconv*))
248 (mh-read-draft "clean-up" (mh-msg-filename msg) nil)
250 (setq code-conversion t)
253 (goto-char (point-min))
254 (mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil)
256 (let ((cs (code-detect-region (point-min)(point-max))))
257 (set-file-coding-system
263 (mime/edit-again code-conversion t t)
264 (goto-char (point-min))
265 (mh-compose-and-send-mail draft "" from-folder nil nil nil nil nil nil
269 ;;; by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
270 ;;; 1996/2/29 (cf. [tm-ja:1643])
271 (defun tm-mh-e/extract-rejected-mail (msg)
272 "Extract a letter returned by the mail system and make it re-editable.
273 Default is the current message. The variable mh-new-draft-cleaned-headers
274 gives the headers to clean out of the original message."
275 (interactive (list (mh-get-msg-num t)))
276 (let ((from-folder mh-current-folder)
277 (config (current-window-configuration))
278 (draft (mh-read-draft "extraction" (mh-msg-filename msg) nil)))
279 (setq buffer-read-only nil)
280 (goto-char (point-min))
284 (concat "^\\($\\|[Cc]ontent-[Tt]ype:[ \t]+multipart/\\)") nil t)
286 (re-search-forward "boundary=\"\\([^\"]+\\)\"" nil t))
287 (let ((case-fold-search t)
288 (boundary (buffer-substring (match-beginning 1) (match-end 1))))
291 (concat "^--" boundary "\n"
292 "content-type:[ \t]+"
293 "\\(message/rfc822\\|text/rfc822-headers\\)\n"
294 "\\(.+\n\\)*\n") nil t)
295 (delete-region (point-min) (point))
296 (mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil)
298 (concat "\n--" boundary "--\n") nil t)
299 (delete-region (match-beginning 0) (point-max)))
301 (message "Seems no message/rfc822 part.")))))
302 ((re-search-forward mh-rejected-letter-start nil t)
303 (skip-chars-forward " \t\n")
304 (delete-region (point-min) (point))
305 (mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil))
307 (message "Does not appear to be a rejected letter.")))
308 (goto-char (point-min))
309 (if (re-search-forward "^-+$" nil t)
312 (mime/edit-again nil t t)
313 (goto-char (point-min))
314 (set-buffer-modified-p nil)
315 (mh-compose-and-send-mail draft "" from-folder msg
316 (mh-get-header-field "To:")
317 (mh-get-header-field "From:")
318 (mh-get-header-field "Cc:")
321 ;;; by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
322 ;;; 1995/11/14 (cf. [tm-ja:1099])
323 (defun tm-mh-e/forward (to cc &optional msg-or-seq)
324 "Forward a message or message sequence as MIME message/rfc822.
325 Defaults to displayed message. If optional prefix argument provided,
326 then prompt for the message sequence. See also documentation for
327 `\\[mh-send]' function."
328 (interactive (list (mh-read-address "To: ")
329 (mh-read-address "Cc: ")
330 (if current-prefix-arg
331 (mh-read-seq-default "Forward" t)
335 (setq msg-or-seq (mh-get-msg-num t)))
336 (let* ((folder mh-current-folder)
337 (config (current-window-configuration))
338 ;; uses "draft" for compatibility with forw.
339 ;; forw always leaves file in "draft" since it doesn't have -draft
340 (draft-name (expand-file-name "draft" mh-user-path))
341 (draft (cond ((or (not (file-exists-p draft-name))
342 (y-or-n-p "The file `draft' exists. Discard it? "))
344 "-noedit" "-nowhatnowproc"
345 "-form" tm-mh-e/forwcomps
348 (mh-read-draft "" draft-name t)
349 (mh-insert-fields "To:" to "Cc:" cc)
350 (set-buffer-modified-p nil)))
352 (mh-read-draft "" draft-name nil)))))
353 (let ((msubtype "digest")
354 orig-from orig-subject multipart-flag
357 (regexp-quote (mime-make-tag "message" "rfc822"))))
359 (goto-char (point-min))
362 (goto-char (point-max))
363 (if (not (bolp)) (insert "\n"))
365 (narrow-to-region beg beg)
366 (mh-exec-cmd-output "pick" nil folder msg-or-seq)
367 (if (> (count-lines (point) (point-max)) 1)
368 (setq multipart-flag t)
370 (while (re-search-forward "^\\([0-9]+\\)\n" nil t)
372 (buffer-substring (match-beginning 1) (match-end 1)))
373 (beg (match-beginning 0))
377 (narrow-to-region beg end)
378 ;; modified for Emacs 18
379 (delete-region beg end)
380 (insert-file-contents
381 (mh-expand-file-name forw-msg
382 (mh-expand-file-name folder))
385 (push-mark (point-max))
386 (mime-editor/inserted-message-filter))
387 (goto-char (point-max))
391 (mime-editor/insert-tag "message" "rfc822")
393 (delete-region (point) (point-max))
395 (mime-editor/enclose-region "digest" beg (point))
397 (re-search-forward tag-regexp)
400 (narrow-to-region (point) (point-max))
401 (setq orig-from (mime-eword/decode-string
402 (mh-get-header-field "From:")))
403 (setq orig-subject (mime-eword/decode-string
404 (mh-get-header-field "Subject:")))
407 (mh-forwarded-letter-subject orig-from orig-subject)))
408 (mh-insert-fields "Subject:" forw-subject)
409 (goto-char (point-min))
410 (re-search-forward tag-regexp)
412 (delete-other-windows)
413 (if (numberp msg-or-seq)
414 (mh-add-msgs-to-seq msg-or-seq 'forwarded t)
415 (mh-add-msgs-to-seq (mh-seq-to-msgs msg-or-seq) 'forwarded t))
416 (mh-compose-and-send-mail draft "" folder msg-or-seq
418 mh-note-forw "Forwarded:"
421 (cond ((not (featurep 'mh-utils))
422 (defun tm-mh-e::insert-letter (folder number verbatim)
423 (mh-insert-letter verbatim folder number)
426 ((and (boundp 'mh-e-version)
427 (string-lessp mh-e-version "5"))
428 (defun tm-mh-e::insert-letter (folder number verbatim)
429 (mh-insert-letter number folder verbatim)
433 (defalias 'tm-mh-e::insert-letter 'mh-insert-letter)
436 (defun tm-mh-e/insert-letter (verbatim)
437 "Interface to mh-insert-letter."
440 ((folder (mh-prompt-for-folder
442 (if (and (stringp mh-sent-from-folder)
443 (string-match "^\\+" mh-sent-from-folder))
444 mh-sent-from-folder "+inbox")
446 (number (tm-mh-e/prompt-for-message "Message number: " folder)))
447 (tm-mh-e::insert-letter folder number verbatim)))
449 (defun tm-mh-e/yank-cur-msg-with-no-filter ()
450 "Insert the current message into the draft buffer.
451 This function makes new show-buffer from article-buffer to disable
452 variable `mime-viewer/plain-text-preview-hook'. If you don't want to
453 use text filters for replying message, please set it to
454 `tm-mh-e/message-yank-function'.
455 Prefix each non-blank line in the message with the string in
456 `mh-ins-buf-prefix'. The entire message will be inserted if
457 `mh-yank-from-start-of-msg' is non-nil. If this variable is nil, the
458 portion of the message following the point will be yanked. If
459 `mh-delete-yanked-msg-window' is non-nil, any window displaying the
460 yanked message will be deleted."
462 (if (and mh-sent-from-folder mh-sent-from-msg)
463 (let ((to-point (point))
464 (to-buffer (current-buffer)))
465 (set-buffer mh-sent-from-folder)
466 (if mh-delete-yanked-msg-window
467 (delete-windows-on mh-show-buffer))
468 (set-buffer mh-show-buffer) ; Find displayed message
470 (let (mime-viewer/plain-text-preview-hook buf)
472 (save-window-excursion
473 (set-buffer mime::preview/article-buffer)
474 (setq buf (mime/viewer-mode))
477 (kill-buffer buf)))))
478 (set-buffer to-buffer)
480 (narrow-to-region to-point to-point)
483 (mh-insert-prefix-string mh-ins-buf-prefix)
485 (error "There is no current message")))
487 (defun tm-mh-e/yank-current-message ()
488 "Insert the current message into the draft buffer.
489 It uses variable `tm-mh-e/message-yank-function'
490 to select message yanking function."
492 (let ((mh-sent-from-folder mh-sent-from-folder)
493 (mh-sent-from-msg mh-sent-from-msg))
494 (if (and (not (stringp mh-sent-from-folder))
495 (boundp 'gnus-article-buffer)
496 (get-buffer gnus-article-buffer)
497 (bufferp mh-sent-from-folder)
498 ) ; might be called from GNUS
499 (if (boundp 'gnus-article-copy) ; might be sgnus
501 (gnus-copy-article-buffer)
502 (setq mh-sent-from-folder gnus-article-copy)
503 (set-buffer mh-sent-from-folder)
504 (setq mh-show-buffer gnus-article-copy)
507 (setq mh-sent-from-folder gnus-article-buffer)
508 (set-buffer gnus-article-buffer)
509 (setq mh-show-buffer (current-buffer))
511 (funcall tm-mh-e/message-yank-function)
514 (substitute-key-definition
515 'mh-yank-cur-msg 'tm-mh-e/yank-current-message mh-letter-mode-map)
516 (substitute-key-definition
517 'mh-insert-letter 'tm-mh-e/insert-letter mh-letter-mode-map)
526 ;;; tmh-comp.el ends here