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