1 ;;; emh-comp.el --- emh functions for composing messages
3 ;; Copyright (C) 1993,94,95,96,97,98,99,2000 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;; OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
7 ;; Created: 1996/2/29 (separated from tm-mh-e.el)
8 ;; Renamed: 1997/2/21 from tmh-comp.el
9 ;; Keywords: mail composing, MH, MIME, mail
11 ;; This file is part of emh.
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
18 ;; This program is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
34 ;; Avoid byte compile warnings.
35 ;; (defvar gnus-article-buffer)
36 ;; (defvar gnus-article-copy)
37 ;; (defvar gnus-original-article-buffer)
39 ;; (fset 'gnus-copy-article-buffer 'ignore)
46 (defvar emh-forwcomps "forwcomps"
47 "Name of file to be used as a skeleton for forwarding messages.
48 Default is \"forwcomps\". If not a complete path name, the file
49 is searched for first in the user's MH directory, then in the
50 system MH lib directory.")
52 ;; (defvar emh-message-yank-function 'mh-yank-cur-msg)
58 (defun emh::make-message (folder number)
59 (vector folder number)
62 (defun emh::message/folder (message)
66 (defun emh::message/number (message)
70 (defun emh::message/file-name (message)
72 (emh::message/number message)
73 (mh-expand-file-name (emh::message/folder message))
76 ;;; modified by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
77 ;;; 1995/11/14 (cf. [tm-ja:1096])
78 (defun emh-prompt-for-message (prompt folder &optional default)
80 (directory-files (mh-expand-file-name folder) nil "^[0-9]+$")
82 (folder-buf (get-buffer folder))
86 (set-buffer folder-buf)
87 (let* ((show-buffer (get-buffer mh-show-buffer))
88 (show-buffer-file-name
89 (buffer-file-name show-buffer)))
90 (if show-buffer-file-name
91 (file-name-nondirectory show-buffer-file-name)))))))
92 (if (or (null default)
93 (not (string-match "^[0-9]+$" default)))
95 (if (and (string= folder mh-sent-from-folder)
97 (int-to-string mh-sent-from-msg)
101 (= 0 (mh-exec-cmd-quiet nil "pick" folder "cur"))
102 (set-buffer mh-temp-buffer)
103 (setq cur-msg (buffer-string))
104 (string-match "^[0-9]+$" cur-msg))
105 (substring cur-msg 0 (match-end 0))
107 (completing-read prompt
118 ;;; modified by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
119 ;;; 1995/11/14 (cf. [tm-ja:1096])
120 (defun emh-query-message (&optional message)
124 (setq folder (emh::message/folder message))
125 (setq number (emh::message/number message))
128 (setq folder (mh-prompt-for-folder
130 (if (and (stringp mh-sent-from-folder)
131 (string-match "^\\+" mh-sent-from-folder))
132 mh-sent-from-folder "+inbox")
136 (number-to-string number)
137 (emh-prompt-for-message "Message number: " folder)
139 (emh::make-message folder number)
142 (defun emh-insert-message (&optional message)
143 ;; always ignores message
144 ;; (let ((article-buffer
145 ;; (if (not (and (stringp mh-sent-from-folder)
146 ;; (numberp mh-sent-from-msg)
148 ;; (cond ((and (boundp 'gnus-original-article-buffer)
149 ;; (bufferp mh-sent-from-folder)
150 ;; (get-buffer gnus-original-article-buffer)
152 ;; gnus-original-article-buffer)
153 ;; ((and (boundp 'gnus-article-buffer)
154 ;; (get-buffer gnus-article-buffer)
155 ;; (bufferp mh-sent-from-folder)
158 ;; (set-buffer gnus-article-buffer)
159 ;; (if (eq major-mode 'mime-view-mode)
164 (if (null article-buffer)
166 (emh::make-message mh-sent-from-folder mh-sent-from-msg))
167 ;; (insert-buffer article-buffer)
168 ;; (mime-edit-inserted-message-filter)
172 (defun emh-insert-mail (&optional message)
176 (emh::message/file-name (emh-query-message message))))
177 (narrow-to-region (point) (point))
178 (insert-file-contents message-file)
179 (push-mark (point-max))
180 (mime-edit-inserted-message-filter)
183 (set-alist 'mime-edit-message-inserter-alist
184 'mh-letter-mode (function emh-insert-message))
185 (set-alist 'mime-edit-mail-inserter-alist
186 'mh-letter-mode (function emh-insert-mail))
187 (set-alist 'mime-edit-mail-inserter-alist
188 'news-reply-mode (function emh-insert-mail))
190 'mime-edit-split-message-sender-alist
193 (lambda (&optional arg)
195 (write-region (point-min) (point-max)
196 mime-edit-draft-file-name nil 'no-message)
198 (pop-to-buffer "MH mail delivery")
200 (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
203 mime-edit-draft-file-name)
204 (goto-char (point-max)) ; show the interesting part
208 (apply 'mh-exec-cmd-quiet t mh-send-prog
210 (list "-nopush" "-nodraftfolder"
211 "-noverbose" "-nowatch"
212 mh-send-args mime-edit-draft-file-name)))))
216 ;;; @ commands using tm-edit features
219 (defun emh-edit-again (msg)
220 "Clean-up a draft or a message previously sent and make it resendable.
221 Default is the current message.
222 The variable mh-new-draft-cleaned-headers specifies the headers to remove.
223 See also documentation for `\\[mh-send]' function."
224 (interactive (list (mh-get-msg-num t)))
226 (let* ((from-folder mh-current-folder)
227 (config (current-window-configuration))
229 (cond ((and mh-draft-folder (equal from-folder mh-draft-folder))
230 (let ((name (format "draft-%d" msg)))
231 (if (get-buffer name)
232 (throw 'tag (pop-to-buffer name))
235 (mh-msg-filename msg mh-draft-folder)
237 (set-buffer (get-buffer-create name))
238 (binary-insert-file-contents filename)
239 (setq buffer-file-name filename)
242 (if (re-search-forward "^-+$" nil t)
247 (let ((flag enable-multibyte-characters)
248 (coding-system-for-read 'binary))
250 (mh-read-draft "clean-up"
251 (mh-msg-filename msg) nil)
252 (set-buffer-multibyte flag)
255 (goto-char (point-min))
256 (mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil)
257 (let ((cs (detect-coding-region (point-min)(point-max))))
258 (set-buffer-file-coding-system
263 (mime-edit-again nil 'no-separator 'not-turn-on)
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 emh-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 emh-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" emh-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)))))
354 (concat "^" (regexp-quote (mime-make-tag "message" "rfc822"))))
355 orig-from orig-subject multipart-flag)
356 (goto-char (point-min))
359 (goto-char (point-max))
360 (if (not (bolp)) (insert "\n"))
362 (narrow-to-region beg beg)
363 (mh-exec-cmd-output "pick" nil folder msg-or-seq)
364 (if (> (count-lines (point) (point-max)) 1)
365 (setq multipart-flag t)
367 (while (re-search-forward "^\\([0-9]+\\)\n" nil t)
369 (buffer-substring (match-beginning 1) (match-end 1)))
370 (beg (match-beginning 0))
374 (narrow-to-region beg end)
375 ;; modified for Emacs 18
376 (delete-region beg end)
377 (insert-file-contents
378 (mh-expand-file-name forw-msg
379 (mh-expand-file-name folder))
382 (push-mark (point-max))
383 (mime-edit-inserted-message-filter))
384 (goto-char (point-max))
388 (mime-edit-insert-tag "message" "rfc822")
390 (delete-region (point) (point-max))
392 (mime-edit-enclose-digest-region beg (point))
394 (re-search-forward tag-regexp)
397 (narrow-to-region (point) (point-max))
398 (setq orig-from (eword-decode-string
399 (mh-get-header-field "From:")))
400 (setq orig-subject (eword-decode-string
401 (mh-get-header-field "Subject:")))
404 (mh-forwarded-letter-subject orig-from orig-subject)))
405 (mh-insert-fields "Subject:" forw-subject)
406 (goto-char (point-min))
407 (re-search-forward tag-regexp)
409 (delete-other-windows)
410 (if (numberp msg-or-seq)
411 (mh-add-msgs-to-seq msg-or-seq 'forwarded t)
412 (mh-add-msgs-to-seq (mh-seq-to-msgs msg-or-seq) 'forwarded t))
413 (mh-compose-and-send-mail draft "" folder msg-or-seq
415 mh-note-forw "Forwarded:"
418 (cond ((not (featurep 'mh-utils))
419 (defun emh::insert-letter (folder number verbatim)
420 (mh-insert-letter verbatim folder number)
423 ((and (boundp 'mh-e-version)
424 (string-lessp mh-e-version "5"))
425 (defun emh::insert-letter (folder number verbatim)
426 (mh-insert-letter number folder verbatim)
430 (defalias 'emh::insert-letter 'mh-insert-letter)
433 (defun emh-insert-letter (verbatim)
434 "Interface to mh-insert-letter."
437 ((folder (mh-prompt-for-folder
439 (if (and (stringp mh-sent-from-folder)
440 (string-match "^\\+" mh-sent-from-folder))
441 mh-sent-from-folder "+inbox")
443 (number (emh-prompt-for-message "Message number: " folder)))
444 (emh::insert-letter folder number verbatim)))
446 ;; (defun emh-yank-cur-msg-with-no-filter ()
447 ;; "Insert the current message into the draft buffer.
448 ;; This function makes new show-buffer from article-buffer to disable
449 ;; variable `mime-preview-text/plain-hook'. If you don't want to use text
450 ;; filters for replying message, please set it to
451 ;; `emh-message-yank-function'.
452 ;; Prefix each non-blank line in the message with the string in
453 ;; `mh-ins-buf-prefix'. The entire message will be inserted if
454 ;; `mh-yank-from-start-of-msg' is non-nil. If this variable is nil, the
455 ;; portion of the message following the point will be yanked. If
456 ;; `mh-delete-yanked-msg-window' is non-nil, any window displaying the
457 ;; yanked message will be deleted."
459 ;; (if (and mh-sent-from-folder mh-sent-from-msg)
460 ;; (let ((to-point (point))
461 ;; (to-buffer (current-buffer)))
462 ;; (set-buffer mh-sent-from-folder)
463 ;; (if mh-delete-yanked-msg-window
464 ;; (delete-windows-on mh-show-buffer))
465 ;; (set-buffer mh-show-buffer) ; Find displayed message
467 ;; (if mime-raw-buffer
468 ;; (let (mime-display-text/plain-hook buf)
470 ;; (save-window-excursion
471 ;; (set-buffer mime-raw-buffer)
472 ;; (setq buf (mime-view-mode))
479 ;; (set-buffer to-buffer)
481 ;; (narrow-to-region to-point to-point)
483 ;; (insert mh-ins-str)
484 ;; (mh-insert-prefix-string mh-ins-buf-prefix)
486 ;; (error "There is no current message")))
488 ;; (defun emh-yank-current-message ()
489 ;; "Insert the current message into the draft buffer.
490 ;; It uses variable `emh-message-yank-function'
491 ;; to select message yanking function."
493 ;; (let ((mh-sent-from-folder mh-sent-from-folder)
494 ;; (mh-sent-from-msg mh-sent-from-msg))
495 ;; (if (and (not (stringp mh-sent-from-folder))
496 ;; (boundp 'gnus-article-buffer)
497 ;; (get-buffer gnus-article-buffer)
498 ;; (bufferp mh-sent-from-folder)
499 ;; ) ; might be called from GNUS
500 ;; (if (boundp 'gnus-article-copy) ; might be sgnus
502 ;; (gnus-copy-article-buffer)
503 ;; (setq mh-sent-from-folder gnus-article-copy)
504 ;; (set-buffer mh-sent-from-folder)
505 ;; (setq mh-show-buffer gnus-article-copy)
508 ;; (setq mh-sent-from-folder gnus-article-buffer)
509 ;; (set-buffer gnus-article-buffer)
510 ;; (setq mh-show-buffer (current-buffer))
512 ;; (funcall emh-message-yank-function)
515 ;; (substitute-key-definition
516 ;; 'mh-yank-cur-msg 'emh-yank-current-message mh-letter-mode-map)
517 ;; (substitute-key-definition
518 ;; 'mh-insert-letter 'emh-insert-letter mh-letter-mode-map)
527 ;;; emh-comp.el ends here