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