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.
33 ;; Avoid byte compile warnings.
34 ;; (defvar gnus-article-buffer)
35 ;; (defvar gnus-article-copy)
36 ;; (defvar gnus-original-article-buffer)
38 ;; (fset 'gnus-copy-article-buffer 'ignore)
45 (defvar emh-forwcomps "forwcomps"
46 "Name of file to be used as a skeleton for forwarding messages.
47 Default is \"forwcomps\". If not a complete path name, the file
48 is searched for first in the user's MH directory, then in the
49 system MH lib directory.")
51 ;; (defvar emh-message-yank-function 'mh-yank-cur-msg)
57 (defun emh::make-message (folder number)
58 (vector folder number)
61 (defun emh::message/folder (message)
65 (defun emh::message/number (message)
69 (defun emh::message/file-name (message)
71 (emh::message/number message)
72 (mh-expand-file-name (emh::message/folder message))
75 ;;; modified by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
76 ;;; 1995/11/14 (cf. [tm-ja:1096])
77 (defun emh-prompt-for-message (prompt folder &optional default)
79 (directory-files (mh-expand-file-name folder) nil "^[0-9]+$")
81 (folder-buf (get-buffer folder))
85 (set-buffer folder-buf)
86 (let* ((show-buffer (get-buffer mh-show-buffer))
87 (show-buffer-file-name
88 (buffer-file-name show-buffer)))
89 (if show-buffer-file-name
90 (file-name-nondirectory show-buffer-file-name)))))))
91 (if (or (null default)
92 (not (string-match "^[0-9]+$" default)))
94 (if (and (string= folder mh-sent-from-folder)
96 (int-to-string mh-sent-from-msg)
100 (= 0 (mh-exec-cmd-quiet nil "pick" folder "cur"))
101 (set-buffer mh-temp-buffer)
102 (setq cur-msg (buffer-string))
103 (string-match "^[0-9]+$" cur-msg))
104 (substring cur-msg 0 (match-end 0))
106 (completing-read prompt
117 ;;; modified by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
118 ;;; 1995/11/14 (cf. [tm-ja:1096])
119 (defun emh-query-message (&optional message)
123 (setq folder (emh::message/folder message))
124 (setq number (emh::message/number message))
127 (setq folder (mh-prompt-for-folder
129 (if (and (stringp mh-sent-from-folder)
130 (string-match "^\\+" mh-sent-from-folder))
131 mh-sent-from-folder "+inbox")
135 (number-to-string number)
136 (emh-prompt-for-message "Message number: " folder)
138 (emh::make-message folder number)
141 (defun emh-insert-message (&optional message)
142 ;; always ignores message
143 ;; (let ((article-buffer
144 ;; (if (not (and (stringp mh-sent-from-folder)
145 ;; (numberp mh-sent-from-msg)
147 ;; (cond ((and (boundp 'gnus-original-article-buffer)
148 ;; (bufferp mh-sent-from-folder)
149 ;; (get-buffer gnus-original-article-buffer)
151 ;; gnus-original-article-buffer)
152 ;; ((and (boundp 'gnus-article-buffer)
153 ;; (get-buffer gnus-article-buffer)
154 ;; (bufferp mh-sent-from-folder)
157 ;; (set-buffer gnus-article-buffer)
158 ;; (if (eq major-mode 'mime-view-mode)
163 (if (null article-buffer)
165 (emh::make-message mh-sent-from-folder mh-sent-from-msg))
166 ;; (insert-buffer article-buffer)
167 ;; (mime-edit-inserted-message-filter)
171 (defun emh-insert-mail (&optional message)
175 (emh::message/file-name (emh-query-message message))))
176 (narrow-to-region (point) (point))
177 (insert-file-contents message-file)
178 (push-mark (point-max))
179 (mime-edit-inserted-message-filter)
182 (set-alist 'mime-edit-message-inserter-alist
183 'mh-letter-mode (function emh-insert-message))
184 (set-alist 'mime-edit-mail-inserter-alist
185 'mh-letter-mode (function emh-insert-mail))
186 (set-alist 'mime-edit-mail-inserter-alist
187 'news-reply-mode (function emh-insert-mail))
189 'mime-edit-split-message-sender-alist
192 (lambda (&optional arg)
194 (write-region (point-min) (point-max)
195 mime-edit-draft-file-name nil 'no-message)
197 (pop-to-buffer "MH mail delivery")
199 (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
202 mime-edit-draft-file-name)
203 (goto-char (point-max)) ; show the interesting part
207 (apply 'mh-exec-cmd-quiet t mh-send-prog
209 (list "-nopush" "-nodraftfolder"
210 "-noverbose" "-nowatch"
211 mh-send-args mime-edit-draft-file-name)))))
215 ;;; @ commands using tm-edit features
218 (defun emh-edit-again (msg)
219 "Clean-up a draft or a message previously sent and make it resendable.
220 Default is the current message.
221 The variable mh-new-draft-cleaned-headers specifies the headers to remove.
222 See also documentation for `\\[mh-send]' function."
223 (interactive (list (mh-get-msg-num t)))
225 (let* ((from-folder mh-current-folder)
226 (config (current-window-configuration))
228 (cond ((and mh-draft-folder (equal from-folder mh-draft-folder))
229 (let ((name (format "draft-%d" msg)))
230 (if (get-buffer name)
231 (throw 'tag (pop-to-buffer name))
234 (mh-msg-filename msg mh-draft-folder)
236 (set-buffer (get-buffer-create name))
237 (as-binary-input-file (insert-file-contents filename))
238 (setq buffer-file-name filename)
241 (if (re-search-forward "^-+$" nil t)
246 (let ((flag enable-multibyte-characters))
248 (as-binary-input-file
249 (mh-read-draft "clean-up"
250 (mh-msg-filename msg) nil))
251 (set-buffer-multibyte flag)
254 (goto-char (point-min))
255 (mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil)
256 (let ((cs (detect-coding-region (point-min)(point-max))))
257 (set-buffer-file-coding-system
262 (mime-edit-again nil 'no-separator 'not-turn-on)
263 (goto-char (point-min))
264 (mh-compose-and-send-mail draft "" from-folder nil nil nil nil nil nil
268 ;;; by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
269 ;;; 1996/2/29 (cf. [tm-ja:1643])
270 (defun emh-extract-rejected-mail (msg)
271 "Extract a letter returned by the mail system and make it re-editable.
272 Default is the current message. The variable mh-new-draft-cleaned-headers
273 gives the headers to clean out of the original message."
274 (interactive (list (mh-get-msg-num t)))
275 (let ((from-folder mh-current-folder)
276 (config (current-window-configuration))
277 (draft (mh-read-draft "extraction" (mh-msg-filename msg) nil)))
278 (setq buffer-read-only nil)
279 (goto-char (point-min))
283 (concat "^\\($\\|[Cc]ontent-[Tt]ype:[ \t]+multipart/\\)") nil t)
285 (re-search-forward "boundary=\"\\([^\"]+\\)\"" nil t))
286 (let ((case-fold-search t)
287 (boundary (buffer-substring (match-beginning 1) (match-end 1))))
290 (concat "^--" boundary "\n"
291 "content-type:[ \t]+"
292 "\\(message/rfc822\\|text/rfc822-headers\\)\n"
293 "\\(.+\n\\)*\n") nil t)
294 (delete-region (point-min) (point))
295 (mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil)
297 (concat "\n--" boundary "--\n") nil t)
298 (delete-region (match-beginning 0) (point-max)))
300 (message "Seems no message/rfc822 part.")))))
301 ((re-search-forward mh-rejected-letter-start nil t)
302 (skip-chars-forward " \t\n")
303 (delete-region (point-min) (point))
304 (mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil))
306 (message "Does not appear to be a rejected letter.")))
307 (goto-char (point-min))
308 (if (re-search-forward "^-+$" nil t)
311 (mime-edit-again nil t t)
312 (goto-char (point-min))
313 (set-buffer-modified-p nil)
314 (mh-compose-and-send-mail draft "" from-folder msg
315 (mh-get-header-field "To:")
316 (mh-get-header-field "From:")
317 (mh-get-header-field "Cc:")
320 ;;; by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
321 ;;; 1995/11/14 (cf. [tm-ja:1099])
322 (defun emh-forward (to cc &optional msg-or-seq)
323 "Forward a message or message sequence as MIME message/rfc822.
324 Defaults to displayed message. If optional prefix argument provided,
325 then prompt for the message sequence. See also documentation for
326 `\\[mh-send]' function."
327 (interactive (list (mh-read-address "To: ")
328 (mh-read-address "Cc: ")
329 (if current-prefix-arg
330 (mh-read-seq-default "Forward" t)
334 (setq msg-or-seq (mh-get-msg-num t)))
335 (let* ((folder mh-current-folder)
336 (config (current-window-configuration))
337 ;; uses "draft" for compatibility with forw.
338 ;; forw always leaves file in "draft" since it doesn't have -draft
339 (draft-name (expand-file-name "draft" mh-user-path))
340 (draft (cond ((or (not (file-exists-p draft-name))
341 (y-or-n-p "The file `draft' exists. Discard it? "))
343 "-noedit" "-nowhatnowproc"
344 "-form" emh-forwcomps
347 (mh-read-draft "" draft-name t)
348 (mh-insert-fields "To:" to "Cc:" cc)
349 (set-buffer-modified-p nil)))
351 (mh-read-draft "" draft-name nil)))))
352 (let ((msubtype "digest")
353 orig-from orig-subject multipart-flag
356 (regexp-quote (mime-make-tag "message" "rfc822"))))
358 (goto-char (point-min))
361 (goto-char (point-max))
362 (if (not (bolp)) (insert "\n"))
364 (narrow-to-region beg beg)
365 (mh-exec-cmd-output "pick" nil folder msg-or-seq)
366 (if (> (count-lines (point) (point-max)) 1)
367 (setq multipart-flag t)
369 (while (re-search-forward "^\\([0-9]+\\)\n" nil t)
371 (buffer-substring (match-beginning 1) (match-end 1)))
372 (beg (match-beginning 0))
376 (narrow-to-region beg end)
377 ;; modified for Emacs 18
378 (delete-region beg end)
379 (insert-file-contents
380 (mh-expand-file-name forw-msg
381 (mh-expand-file-name folder))
384 (push-mark (point-max))
385 (mime-edit-inserted-message-filter))
386 (goto-char (point-max))
390 (mime-edit-insert-tag "message" "rfc822")
392 (delete-region (point) (point-max))
394 (mime-edit-enclose-digest-region beg (point))
396 (re-search-forward tag-regexp)
399 (narrow-to-region (point) (point-max))
400 (setq orig-from (eword-decode-string
401 (mh-get-header-field "From:")))
402 (setq orig-subject (eword-decode-string
403 (mh-get-header-field "Subject:")))
406 (mh-forwarded-letter-subject orig-from orig-subject)))
407 (mh-insert-fields "Subject:" forw-subject)
408 (goto-char (point-min))
409 (re-search-forward tag-regexp)
411 (delete-other-windows)
412 (if (numberp msg-or-seq)
413 (mh-add-msgs-to-seq msg-or-seq 'forwarded t)
414 (mh-add-msgs-to-seq (mh-seq-to-msgs msg-or-seq) 'forwarded t))
415 (mh-compose-and-send-mail draft "" folder msg-or-seq
417 mh-note-forw "Forwarded:"
420 (cond ((not (featurep 'mh-utils))
421 (defun emh::insert-letter (folder number verbatim)
422 (mh-insert-letter verbatim folder number)
425 ((and (boundp 'mh-e-version)
426 (string-lessp mh-e-version "5"))
427 (defun emh::insert-letter (folder number verbatim)
428 (mh-insert-letter number folder verbatim)
432 (defalias 'emh::insert-letter 'mh-insert-letter)
435 (defun emh-insert-letter (verbatim)
436 "Interface to mh-insert-letter."
439 ((folder (mh-prompt-for-folder
441 (if (and (stringp mh-sent-from-folder)
442 (string-match "^\\+" mh-sent-from-folder))
443 mh-sent-from-folder "+inbox")
445 (number (emh-prompt-for-message "Message number: " folder)))
446 (emh::insert-letter folder number verbatim)))
448 ;; (defun emh-yank-cur-msg-with-no-filter ()
449 ;; "Insert the current message into the draft buffer.
450 ;; This function makes new show-buffer from article-buffer to disable
451 ;; variable `mime-preview-text/plain-hook'. If you don't want to use text
452 ;; filters for replying message, please set it to
453 ;; `emh-message-yank-function'.
454 ;; Prefix each non-blank line in the message with the string in
455 ;; `mh-ins-buf-prefix'. The entire message will be inserted if
456 ;; `mh-yank-from-start-of-msg' is non-nil. If this variable is nil, the
457 ;; portion of the message following the point will be yanked. If
458 ;; `mh-delete-yanked-msg-window' is non-nil, any window displaying the
459 ;; yanked message will be deleted."
461 ;; (if (and mh-sent-from-folder mh-sent-from-msg)
462 ;; (let ((to-point (point))
463 ;; (to-buffer (current-buffer)))
464 ;; (set-buffer mh-sent-from-folder)
465 ;; (if mh-delete-yanked-msg-window
466 ;; (delete-windows-on mh-show-buffer))
467 ;; (set-buffer mh-show-buffer) ; Find displayed message
469 ;; (if mime-raw-buffer
470 ;; (let (mime-display-text/plain-hook buf)
472 ;; (save-window-excursion
473 ;; (set-buffer mime-raw-buffer)
474 ;; (setq buf (mime-view-mode))
481 ;; (set-buffer to-buffer)
483 ;; (narrow-to-region to-point to-point)
485 ;; (insert mh-ins-str)
486 ;; (mh-insert-prefix-string mh-ins-buf-prefix)
488 ;; (error "There is no current message")))
490 ;; (defun emh-yank-current-message ()
491 ;; "Insert the current message into the draft buffer.
492 ;; It uses variable `emh-message-yank-function'
493 ;; to select message yanking function."
495 ;; (let ((mh-sent-from-folder mh-sent-from-folder)
496 ;; (mh-sent-from-msg mh-sent-from-msg))
497 ;; (if (and (not (stringp mh-sent-from-folder))
498 ;; (boundp 'gnus-article-buffer)
499 ;; (get-buffer gnus-article-buffer)
500 ;; (bufferp mh-sent-from-folder)
501 ;; ) ; might be called from GNUS
502 ;; (if (boundp 'gnus-article-copy) ; might be sgnus
504 ;; (gnus-copy-article-buffer)
505 ;; (setq mh-sent-from-folder gnus-article-copy)
506 ;; (set-buffer mh-sent-from-folder)
507 ;; (setq mh-show-buffer gnus-article-copy)
510 ;; (setq mh-sent-from-folder gnus-article-buffer)
511 ;; (set-buffer gnus-article-buffer)
512 ;; (setq mh-show-buffer (current-buffer))
514 ;; (funcall emh-message-yank-function)
517 ;; (substitute-key-definition
518 ;; 'mh-yank-cur-msg 'emh-yank-current-message mh-letter-mode-map)
519 ;; (substitute-key-definition
520 ;; 'mh-insert-letter 'emh-insert-letter mh-letter-mode-map)
529 ;;; emh-comp.el ends here