*** empty log message ***
[gnus] / lisp / gnus-mh.el
1 ;;; gnus-mh: mh-e interface for Gnus
2 ;; Copyright (C) 1994,95 Free Software Foundation, Inc.
3
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
5 ;;      Lars Ingebrigtsen <larsi@ifi.uio.no>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 ;;; Commentary:
25
26 ;;; Send mail using mh-e.
27
28 ;; The following mh-e interface is all cooperative works of
29 ;; tanaka@flab.fujitsu.CO.JP (TANAKA Hiroshi), kawabe@sra.CO.JP
30 ;; (Yoshikatsu Kawabe), and shingu@casund.cpr.canon.co.jp (Toshiaki
31 ;; SHINGU).
32
33 ;;; Code:
34
35 (require 'mh-e)
36 (require 'mh-comp)
37 (require 'gnus)
38
39 (defun gnus-summary-save-in-folder (&optional folder)
40   "Save this article to MH folder (using `rcvstore' in MH library).
41 Optional argument FOLDER specifies folder name."
42   ;; Thanks to yuki@flab.Fujitsu.JUNET and ohm@kaba.junet.
43   (mh-find-path)
44   (let ((folder
45          (or folder
46              (mh-prompt-for-folder 
47               "Save article in"
48               (funcall gnus-folder-save-name gnus-newsgroup-name
49                        gnus-current-headers gnus-newsgroup-last-folder)
50               t)))
51         (errbuf (get-buffer-create " *Gnus rcvstore*")))
52     (gnus-eval-in-buffer-window 
53      gnus-article-buffer
54      (save-restriction
55        (widen)
56        (unwind-protect
57            (call-process-region (point-min) (point-max)
58                                 (expand-file-name "rcvstore" mh-lib)
59                                 nil errbuf nil folder)
60          (set-buffer errbuf)
61          (if (zerop (buffer-size))
62              (message "Article saved in folder: %s" folder)
63            (message "%s" (buffer-string)))
64          (kill-buffer errbuf))))
65     (setq gnus-newsgroup-last-folder folder)))
66
67 (defun gnus-mail-reply-using-mhe (&optional yank)
68   "Compose reply mail using mh-e.
69 Optional argument YANK means yank original article.
70 The command \\[mh-yank-cur-msg] yank the original message into current buffer."
71   ;; First of all, prepare mhe mail buffer.
72   ;; Bug fix by Timo METZEMAKERS <metzemakers@labri.u-bordeaux.fr>.
73   (pop-to-buffer gnus-article-buffer)
74   (let (from cc subject date to reply-to (buffer (current-buffer)))
75     (save-restriction
76       (gnus-article-show-all-headers)   ;I don't think this is really needed.
77       (setq from (gnus-fetch-field "from")
78             subject (let ((subject (or (gnus-fetch-field "subject")
79                                        "(None)")))
80                       (if (and subject
81                                (not (string-match "^[Rr][Ee]:.+$" subject)))
82                           (concat "Re: " subject) subject))
83             reply-to (gnus-fetch-field "reply-to")
84             cc (gnus-fetch-field "cc")
85             date (gnus-fetch-field "date"))
86       (setq mh-show-buffer buffer)
87       (setq to (or reply-to from))
88       (mh-find-path)
89       (mh-send to (or cc "") subject)
90       (save-excursion
91         (mh-insert-fields
92          "In-reply-to:"
93          (concat
94           (substring from 0 (string-match "  *at \\|  *@ \\| *(\\| *<" from))
95           "'s message of " date)))
96       (setq mh-sent-from-folder buffer)
97       (setq mh-sent-from-msg 1)
98       ))
99   ;; Then, yank original article if requested.
100   (if yank
101       (let ((last (point)))
102         (mh-yank-cur-msg)
103         (goto-char last)
104         )))
105
106 ;; gnus-mail-forward-using-mhe is contributed by Jun-ichiro Itoh
107 ;; <itojun@ingram.mt.cs.keio.ac.jp>
108
109 (defun gnus-mail-forward-using-mhe ()
110   "Forward the current message to another user using mh-e."
111   ;; First of all, prepare mhe mail buffer.
112   (let ((to (read-string "To: "))
113         (cc (read-string "Cc: "))
114         (buffer (current-buffer))
115         subject beg)
116     ;;(gnus-article-show-all-headers)
117     (setq subject
118           (concat "[" gnus-newsgroup-name "] "
119                   ;;(mail-strip-quoted-names (gnus-fetch-field "From")) ": "
120                   (or (gnus-fetch-field "subject") "")))
121     (setq mh-show-buffer buffer)
122     (mh-find-path)
123     (mh-send to (or cc "") subject)
124     (save-excursion
125       (goto-char (point-max))
126       (setq beg (point))
127       (insert "\n------- Forwarded Message\n\n")
128       (insert-buffer buffer)
129       (goto-char (point-max))
130       (insert "\n------- End of Forwarded Message\n")
131       (goto-char beg)
132       (while (setq beg (next-single-property-change (point) 'invisible))
133         (goto-char beg)
134         (delete-region beg (or (next-single-property-change 
135                                 (point) 'invisible)
136                                (point-max))))
137       (setq mh-sent-from-folder buffer)
138       (setq mh-sent-from-msg 1))))
139
140 (defun gnus-mail-other-window-using-mhe ()
141   "Compose mail other window using mh-e."
142   (let ((to (read-string "To: "))
143         (cc (read-string "Cc: "))
144         (subject (read-string "Subject: ")))
145     (gnus-article-show-all-headers)     ;I don't think this is really needed.
146     (setq mh-show-buffer (current-buffer))
147     (mh-find-path)
148     (mh-send-other-window to cc subject)
149     (setq mh-sent-from-folder (current-buffer))
150     (setq mh-sent-from-msg 1)))
151
152 (defun gnus-Folder-save-name (newsgroup headers &optional last-folder)
153   "Generate folder name from NEWSGROUP, HEADERS, and optional LAST-FOLDER.
154 If variable `gnus-use-long-file-name' is nil, it is +News.group.
155 Otherwise, it is like +news/group."
156   (or last-folder
157       (concat "+"
158               (if gnus-use-long-file-name
159                   (gnus-capitalize-newsgroup newsgroup)
160                 (gnus-newsgroup-directory-form newsgroup)))))
161
162 (defun gnus-folder-save-name (newsgroup headers &optional last-folder)
163   "Generate folder name from NEWSGROUP, HEADERS, and optional LAST-FOLDER.
164 If variable `gnus-use-long-file-name' is nil, it is +news.group.
165 Otherwise, it is like +news/group."
166   (or last-folder
167       (concat "+"
168               (if gnus-use-long-file-name
169                   newsgroup
170                 (gnus-newsgroup-directory-form newsgroup)))))
171
172 ;;; gnus-mh.el ends here