*** 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 Magne 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   (let (from cc subject date to reply-to to-userid orig-to
72              (config (current-window-configuration))
73              buffer)
74     (pop-to-buffer gnus-article-buffer)
75     (setq buffer (current-buffer))
76     (save-excursion
77       (save-restriction
78         (or gnus-user-login-name ; we need this
79             (setq gnus-user-login-name (or (getenv "USER")
80                                            (getenv "LOGNAME"))))
81
82         (gnus-article-show-all-headers) ;; so colors are happy
83         ;; lots of junk to avoid mh-send deleting other windows
84         (setq from (gnus-fetch-field "from")
85               subject (let ((subject (or (gnus-fetch-field "subject")
86                                          "(None)")))
87                         (if (and subject
88                                  (not (string-match "^[Rr][Ee]:.+$" subject)))
89                             (concat "Re: " subject) subject))
90               reply-to (gnus-fetch-field "reply-to")
91               cc (gnus-fetch-field "cc")
92               orig-to (or (gnus-fetch-field "to") "")
93               date (gnus-fetch-field "date"))
94         (setq to (or reply-to from))
95         (setq to-userid (mail-strip-quoted-names orig-to))
96         (if (or (string-match "," orig-to)
97                 (not (string-match (substring to-userid 0 (string-match "@" to-userid))
98                                    gnus-user-login-name)))
99             (setq cc (concat (if cc (concat cc ", ") "") orig-to))
100           )
101         ;; mh-yank-cur-msg needs to have mh-show-buffer set in the 
102         ;; *Article* buffer
103         (setq mh-show-buffer buffer)
104         )) ;; save excursion/restriction
105
106     (mh-find-path)
107     (mh-send-sub to (or cc "") (or subject "(None)") config) ;; Erik Selberg 1/23/94
108
109     (let ((draft (current-buffer))
110           mail-buf)
111       (if (not yank)
112           (gnus-configure-windows 'reply)
113         (gnus-configure-windows 'reply-yank))
114       (setq mail-buf (cdr (assq 'mail gnus-window-to-buffer)))
115       (pop-to-buffer mail-buf) ;; always in the display, so won't have window probs
116       (switch-to-buffer draft)
117       (kill-buffer mail-buf) ;; mh-e don't use it!
118       )
119
120     ;;    (mh-send to (or cc "") subject);; shouldn't use according to mhe
121     
122     ;; note - current buffer is now draft!
123     (save-excursion
124       (mh-insert-fields
125        "In-reply-to:"
126        (concat
127         (substring from 0 (string-match "  *at \\|  *@ \\| *(\\| *<" from))
128         "'s message of " date)))
129
130     ;; need this for mh-yank-cur-msg
131     (setq mh-sent-from-folder buffer)
132     (setq mh-sent-from-msg 1)
133     (setq mh-show-buffer buffer)
134     (setq mh-previous-window-config config)
135     )
136
137     ;; Then, yank original article if requested.
138   (if yank
139       (let ((last (point)))
140         (mh-yank-cur-msg)
141         (goto-char last)
142         )))
143
144 ;; gnus-mail-forward-using-mhe is contributed by Jun-ichiro Itoh
145 ;; <itojun@ingram.mt.cs.keio.ac.jp>
146
147 (defun gnus-mail-forward-using-mhe ()
148   "Forward the current message to another user using mh-e."
149   ;; First of all, prepare mhe mail buffer.
150   (let ((to (read-string "To: "))
151         (cc (read-string "Cc: "))
152         (buffer (current-buffer))
153         subject
154         (config (current-window-configuration))) ;; need to add this - erik
155     ;;(gnus-article-show-all-headers)
156     (setq subject
157           (concat "[" gnus-newsgroup-name "] "
158                   ;;(mail-strip-quoted-names (gnus-fetch-field "From")) ": "
159                   (or (gnus-fetch-field "subject") "")))
160     (setq mh-show-buffer buffer)
161     (mh-find-path)
162     (mh-send-sub to (or cc "") (or subject "(None)") config) ;; Erik Selberg 1/23/94
163     (let ((draft (current-buffer))
164           mail-buf)
165       (gnus-configure-windows 'reply-yank)
166       (setq mail-buf (cdr (assq 'mail gnus-window-to-buffer)))
167       (pop-to-buffer mail-buf) ;; always in the display, so won't have window probs
168       (switch-to-buffer draft)
169       (kill-buffer mail-buf) ;; mh-e don't use it!
170       )
171     (save-excursion
172       (goto-char (point-max))
173       (insert "\n------- Forwarded Message\n\n")
174       (insert-buffer buffer)
175       (goto-char (point-max))
176       (insert "\n------- End of Forwarded Message\n")
177       (setq mh-sent-from-folder buffer)
178       (setq mh-sent-from-msg 1)
179       (setq mh-previous-window-config config)
180       )))
181
182 (defun gnus-mail-other-window-using-mhe ()
183   "Compose mail other window using mh-e."
184   (let ((to (read-string "To: "))
185         (cc (read-string "Cc: "))
186         (subject (read-string "Subject: ")))
187     (gnus-article-show-all-headers)     ;I don't think this is really needed.
188     (setq mh-show-buffer (current-buffer))
189     (mh-find-path)
190     (mh-send-other-window to cc subject)
191     (setq mh-sent-from-folder (current-buffer))
192     (setq mh-sent-from-msg 1)))
193
194 (defun gnus-Folder-save-name (newsgroup headers &optional last-folder)
195   "Generate folder name from NEWSGROUP, HEADERS, and optional LAST-FOLDER.
196 If variable `gnus-use-long-file-name' is nil, it is +News.group.
197 Otherwise, it is like +news/group."
198   (or last-folder
199       (concat "+"
200               (if gnus-use-long-file-name
201                   (gnus-capitalize-newsgroup newsgroup)
202                 (gnus-newsgroup-directory-form newsgroup)))))
203
204 (defun gnus-folder-save-name (newsgroup headers &optional last-folder)
205   "Generate folder name from NEWSGROUP, HEADERS, and optional LAST-FOLDER.
206 If variable `gnus-use-long-file-name' is nil, it is +news.group.
207 Otherwise, it is like +news/group."
208   (or last-folder
209       (concat "+"
210               (if gnus-use-long-file-name
211                   newsgroup
212                 (gnus-newsgroup-directory-form newsgroup)))))
213
214 ;;; gnus-mh.el ends here