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