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