*** empty log message ***
[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-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          (cond ((and (eq folder 'default)
57                      gnus-newsgroup-last-folder)
58                 gnus-newsgroup-last-folder)
59                (folder folder)
60                (t (mh-prompt-for-folder 
61                    "Save article in"
62                    (funcall gnus-folder-save-name gnus-newsgroup-name
63                             gnus-current-headers gnus-newsgroup-last-folder)
64                    t))))
65         (errbuf (get-buffer-create " *Gnus rcvstore*")))
66     (gnus-eval-in-buffer-window 
67      gnus-original-article-buffer
68      (save-restriction
69        (widen)
70        (unwind-protect
71            (call-process-region (point-min) (point-max)
72                                 (expand-file-name "rcvstore" mh-lib)
73                                 nil errbuf nil folder)
74          (set-buffer errbuf)
75          (if (zerop (buffer-size))
76              (message "Article saved in folder: %s" folder)
77            (message "%s" (buffer-string)))
78          (kill-buffer errbuf))))
79     (setq gnus-newsgroup-last-folder folder)))
80
81 (defun gnus-mh-mail-setup (to subject in-reply-to cc replybuffer actions)
82   (let ((config (current-window-configuration))) 
83     (setq mh-show-buffer gnus-article-copy)
84     (mh-find-path)
85     (mh-send-sub (or to "") (or cc "") (or subject "") config)
86     (goto-char (point-min))
87     (and in-reply-to (insert "In-Reply-To: " in-reply-to "\n"))
88     (setq mh-sent-from-folder gnus-article-copy)
89     (setq mh-sent-from-msg 1)
90     (setq gnus-mail-buffer (buffer-name (current-buffer)))
91     (local-set-key "\C-c\C-c" 'gnus-mh-mail-send-and-exit)
92     (setq mh-previous-window-config config)))
93
94 (defun gnus-mh-mail-send-and-exit (&optional dont-send)
95   "Send the current mail and return to Gnus."
96   (interactive)
97   (let* ((reply gnus-article-reply)
98          (winconf gnus-prev-winconf)
99          (address-group gnus-add-to-address)
100          (to-address (and address-group
101                           (mail-fetch-field "to"))))
102     (setq gnus-add-to-address nil)
103     (or dont-send (mh-send-letter))
104     (bury-buffer)
105     ;; This mail group doesn't have a `to-address', so we add one
106     ;; here.  Magic!  
107     (and to-address
108          (gnus-group-add-parameter 
109           address-group (cons 'to-address to-address)))
110     (if (get-buffer gnus-group-buffer)
111         (progn
112           (if (gnus-buffer-exists-p (car-safe reply))
113               (progn
114                 (set-buffer (car reply))
115                 (and (cdr reply)
116                      (gnus-summary-mark-article-as-replied 
117                       (cdr reply)))))
118           (and winconf (set-window-configuration winconf))))))
119
120 (defun gnus-Folder-save-name (newsgroup headers &optional last-folder)
121   "Generate folder name from NEWSGROUP, HEADERS, and optional LAST-FOLDER.
122 If variable `gnus-use-long-file-name' is nil, it is +News.group.
123 Otherwise, it is like +news/group."
124   (or last-folder
125       (concat "+"
126               (if gnus-use-long-file-name
127                   (gnus-capitalize-newsgroup newsgroup)
128                 (gnus-newsgroup-directory-form newsgroup)))))
129
130 (defun gnus-folder-save-name (newsgroup headers &optional last-folder)
131   "Generate folder name from NEWSGROUP, HEADERS, and optional LAST-FOLDER.
132 If variable `gnus-use-long-file-name' is nil, it is +news.group.
133 Otherwise, it is like +news/group."
134   (or last-folder
135       (concat "+"
136               (if gnus-use-long-file-name
137                   newsgroup
138                 (gnus-newsgroup-directory-form newsgroup)))))
139
140 ;;; gnus-mh.el ends here