(gnus-bug-message): About Semi-gnus.
[elisp/gnus.git-] / lisp / gnus-msg.el
1 ;;; gnus-msg.el --- mail and post interface for Semi-gnus
2 ;; Copyright (C) 1995,96,97,98 Free Software Foundation, Inc.
3
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
5 ;;      Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;      MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;      Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile (require 'cl))
32
33 (require 'gnus)
34 (require 'gnus-ems)
35 (require 'message)
36 (require 'gnus-art)
37
38 (defcustom gnus-post-method nil
39   "*Preferred method for posting USENET news.
40
41 If this variable is `current', Gnus will use the \"current\" select
42 method when posting.  If it is nil (which is the default), Gnus will
43 use the native posting method of the server.
44
45 This method will not be used in mail groups and the like, only in
46 \"real\" newsgroups.
47
48 If not nil nor `native', the value must be a valid method as discussed
49 in the documentation of `gnus-select-method'. It can also be a list of
50 methods. If that is the case, the user will be queried for what select
51 method to use when posting."
52   :group 'gnus-group-foreign
53   :type `(choice (const nil)
54                  (const current)
55                  (const native)
56                  (sexp :tag "Methods" ,gnus-select-method)))
57
58 (defvar gnus-outgoing-message-group nil
59   "*All outgoing messages will be put in this group.
60 If you want to store all your outgoing mail and articles in the group
61 \"nnml:archive\", you set this variable to that value.  This variable
62 can also be a list of group names.
63
64 If you want to have greater control over what group to put each
65 message in, you can set this variable to a function that checks the
66 current newsgroup name and then returns a suitable group name (or list
67 of names).")
68
69 (defvar gnus-mailing-list-groups nil
70   "*Regexp matching groups that are really mailing lists.
71 This is useful when you're reading a mailing list that has been
72 gatewayed to a newsgroup, and you want to followup to an article in
73 the group.")
74
75 (defvar gnus-add-to-list nil
76   "*If non-nil, add a `to-list' parameter automatically.")
77
78 (defvar gnus-crosspost-complaint
79   "Hi,
80
81 You posted the article below with the following Newsgroups header:
82
83 Newsgroups: %s
84
85 The %s group, at least, was an inappropriate recipient
86 of this message.  Please trim your Newsgroups header to exclude this
87 group before posting in the future.
88
89 Thank you.
90
91 "
92   "Format string to be inserted when complaining about crossposts.
93 The first %s will be replaced by the Newsgroups header;
94 the second with the current group name.")
95
96 (defvar gnus-message-setup-hook nil
97   "Hook run after setting up a message buffer.")
98
99 (defvar gnus-bug-create-help-buffer t
100   "*Should we create the *Gnus Help Bug* buffer?")
101
102 (defvar gnus-posting-styles nil
103   "*Alist of styles to use when posting.")
104
105 (defvar gnus-posting-style-alist
106   '((organization . message-user-organization)
107     (signature . message-signature)
108     (signature-file . message-signature-file)
109     (address . user-mail-address)
110     (name . user-full-name))
111   "*Mapping from style parameters to variables.")
112
113 ;;; Internal variables.
114
115 (defvar gnus-inhibit-posting-styles nil
116   "Inhibit the use of posting styles.")
117
118 (defvar gnus-message-buffer "*Mail Gnus*")
119 (defvar gnus-article-copy nil)
120 (defvar gnus-last-posting-server nil)
121 (defvar gnus-message-group-art nil)
122
123 (defconst gnus-bug-message
124   (format "Sending a bug report to the Gnus Towers.
125 ========================================
126
127 This gnus is the %s%s.
128 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
129 Developers. (the addresses below are mailing list addresses)
130
131 ========================================
132
133 The buffer below is a mail buffer.  When you press `C-c C-c', it will
134 be sent to the Gnus Bug Exterminators.
135
136 At the bottom of the buffer you'll see lots of variable settings.
137 Please do not delete those.  They will tell the Bug People what your
138 environment is, so that it will be easier to locate the bugs.
139
140 If you have found a bug that makes Emacs go \"beep\", set
141 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
142 and include the backtrace in your bug report.
143
144 Please describe the bug in annoying, painstaking detail.
145
146 Thank you for your help in stamping out bugs.
147 "
148           gnus-product-name
149           (if (string= gnus-product-name "Semi-gnus")
150               ""
151             ", a modified version of Semi-gnus")))
152
153 (eval-and-compile
154   (autoload 'gnus-uu-post-news "gnus-uu" nil t)
155   (autoload 'news-setup "rnewspost")
156   (autoload 'news-reply-mode "rnewspost")
157   (autoload 'rmail-dont-reply-to "mail-utils")
158   (autoload 'rmail-output "rmailout"))
159
160 \f
161 ;;;
162 ;;; Gnus Posting Functions
163 ;;;
164
165 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
166   "p" gnus-summary-post-news
167   "f" gnus-summary-followup
168   "F" gnus-summary-followup-with-original
169   "c" gnus-summary-cancel-article
170   "s" gnus-summary-supersede-article
171   "r" gnus-summary-reply
172   "R" gnus-summary-reply-with-original
173   "w" gnus-summary-wide-reply
174   "W" gnus-summary-wide-reply-with-original
175   "n" gnus-summary-followup-to-mail
176   "N" gnus-summary-followup-to-mail-with-original
177   "m" gnus-summary-mail-other-window
178   "u" gnus-uu-post-news
179   "\M-c" gnus-summary-mail-crosspost-complaint
180   "om" gnus-summary-mail-forward
181   "op" gnus-summary-post-forward
182   "Om" gnus-summary-mail-digest
183   "Op" gnus-summary-post-digest)
184
185 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
186   "b" gnus-summary-resend-bounced-mail
187   ;; "c" gnus-summary-send-draft
188   "r" gnus-summary-resend-message)
189
190 ;;; Internal functions.
191
192 (defun gnus-extended-version ()
193   "Stringified gnus version."
194   (interactive) ; ???
195   (concat gnus-product-name "/" gnus-version-number))
196
197 (defvar gnus-article-reply nil)
198 (defmacro gnus-setup-message (config &rest forms)
199   (let ((winconf (make-symbol "gnus-setup-message-winconf"))
200         (buffer (make-symbol "gnus-setup-message-buffer"))
201         (article (make-symbol "gnus-setup-message-article"))
202         (group (make-symbol "gnus-setup-message-group")))
203     `(let ((,winconf (current-window-configuration))
204            (,buffer (buffer-name (current-buffer)))
205            (,article (and gnus-article-reply (gnus-summary-article-number)))
206            (,group gnus-newsgroup-name)
207            (message-header-setup-hook
208             (copy-sequence message-header-setup-hook))
209            (message-mode-hook (copy-sequence message-mode-hook)))
210        (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
211        (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
212        (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
213        (add-hook 'message-mode-hook
214                  (lambda ()
215                    (setq message-user-agent (gnus-extended-version))))
216        (unwind-protect
217            (progn
218              ,@forms)
219          (gnus-inews-add-send-actions ,winconf ,buffer ,article)
220          (setq gnus-message-buffer (current-buffer))
221          (set (make-local-variable 'gnus-message-group-art)
222               (cons ,group ,article))
223          (make-local-variable 'gnus-newsgroup-name)
224          (gnus-run-hooks 'gnus-message-setup-hook))
225        (gnus-add-buffer)
226        (gnus-configure-windows ,config t)
227        (set-buffer-modified-p nil))))
228
229 (defun gnus-inews-add-send-actions (winconf buffer article)
230   (make-local-hook 'message-sent-hook)
231   (add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t)
232   (setq message-post-method
233         `(lambda (arg)
234            (gnus-post-method arg ,gnus-newsgroup-name)))
235   (message-add-action
236    `(set-window-configuration ,winconf) 'exit 'postpone 'kill)
237   (message-add-action
238    `(when (gnus-buffer-exists-p ,buffer)
239       (save-excursion
240         (set-buffer ,buffer)
241         ,(when article
242            `(gnus-summary-mark-article-as-replied ,article))))
243    'send))
244
245 (put 'gnus-setup-message 'lisp-indent-function 1)
246 (put 'gnus-setup-message 'edebug-form-spec '(form body))
247
248 ;;; Post news commands of Gnus group mode and summary mode
249
250 (defun gnus-group-mail ()
251   "Start composing a mail."
252   (interactive)
253   (gnus-setup-message 'message
254     (message-mail)))
255
256 (defun gnus-group-post-news (&optional arg)
257   "Start composing a news message.
258 If ARG, post to the group under point.
259 If ARG is 1, prompt for a group name."
260   (interactive "P")
261   ;; Bind this variable here to make message mode hooks work ok.
262   (let ((gnus-newsgroup-name
263          (if arg
264              (if (= 1 (prefix-numeric-value arg))
265                  (completing-read "Newsgroup: " gnus-active-hashtb nil
266                                   (gnus-read-active-file-p))
267                (gnus-group-group-name))
268            "")))
269     (gnus-post-news 'post gnus-newsgroup-name)))
270
271 (defun gnus-summary-post-news ()
272   "Start composing a news message."
273   (interactive)
274   (gnus-post-news 'post gnus-newsgroup-name))
275
276 (defun gnus-summary-followup (yank &optional force-news)
277   "Compose a followup to an article.
278 If prefix argument YANK is non-nil, original article is yanked automatically."
279   (interactive
280    (list (and current-prefix-arg
281               (gnus-summary-work-articles 1))))
282   (when yank
283     (gnus-summary-goto-subject (car yank)))
284   (save-window-excursion
285     (gnus-summary-select-article))
286   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
287         (gnus-newsgroup-name gnus-newsgroup-name))
288     ;; Send a followup.
289     (gnus-post-news nil gnus-newsgroup-name
290                     headers gnus-article-buffer
291                     yank nil force-news)))
292
293 (defun gnus-summary-followup-with-original (n &optional force-news)
294   "Compose a followup to an article and include the original article."
295   (interactive "P")
296   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
297
298 (defun gnus-summary-followup-to-mail (&optional arg)
299   "Followup to the current mail message via news."
300   (interactive
301    (list (and current-prefix-arg
302               (gnus-summary-work-articles 1))))
303   (gnus-summary-followup arg t))
304
305 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
306   "Followup to the current mail message via news."
307   (interactive "P")
308   (gnus-summary-followup (gnus-summary-work-articles arg) t))
309
310 (defun gnus-inews-yank-articles (articles)
311   (let (beg article)
312     (message-goto-body)
313     (while (setq article (pop articles))
314       (save-window-excursion
315         (set-buffer gnus-summary-buffer)
316         (gnus-summary-select-article nil nil nil article)
317         (gnus-summary-remove-process-mark article))
318       (gnus-copy-article-buffer)
319       (let ((message-reply-buffer gnus-article-copy)
320             (message-reply-headers gnus-current-headers))
321         (message-yank-original)
322         (setq beg (or beg (mark t))))
323       (when articles
324         (insert "\n")))
325     (push-mark)
326     (goto-char beg)))
327
328 (defun gnus-summary-cancel-article (&optional n symp)
329   "Cancel an article you posted.
330 Uses the process-prefix convention.  If given the symbolic
331 prefix `a', cancel using the standard posting method; if not
332 post using the current select method."
333   (interactive (gnus-interactive "P\ny"))
334   (let ((articles (gnus-summary-work-articles n))
335         (message-post-method
336          `(lambda (arg)
337             (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
338         article)
339     (while (setq article (pop articles))
340       (when (gnus-summary-select-article t nil nil article)
341         (when (gnus-eval-in-buffer-window gnus-article-buffer
342                 (save-excursion
343                   (set-buffer gnus-original-article-buffer)
344                   (message-cancel-news)))
345           (gnus-summary-mark-as-read article gnus-canceled-mark)
346           (gnus-cache-remove-article 1))
347         (gnus-article-hide-headers-if-wanted))
348       (gnus-summary-remove-process-mark article))))
349
350 (defun gnus-summary-supersede-article ()
351   "Compose an article that will supersede a previous article.
352 This is done simply by taking the old article and adding a Supersedes
353 header line with the old Message-ID."
354   (interactive)
355   (let ((article (gnus-summary-article-number)))
356     (gnus-setup-message 'reply-yank
357       (gnus-summary-select-article t)
358       (set-buffer gnus-original-article-buffer)
359       (message-supersede)
360       (push
361        `((lambda ()
362            (when (gnus-buffer-exists-p ,gnus-summary-buffer)
363              (save-excursion
364                (set-buffer ,gnus-summary-buffer)
365                (gnus-cache-possibly-remove-article ,article nil nil nil t)
366                (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
367        message-send-actions))))
368
369 \f
370
371 (defun gnus-copy-article-buffer (&optional article-buffer)
372   ;; make a copy of the article buffer with all text properties removed
373   ;; this copy is in the buffer gnus-article-copy.
374   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
375   ;; this buffer should be passed to all mail/news reply/post routines.
376   (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
377   (buffer-disable-undo gnus-article-copy)
378   (let ((article-buffer (or article-buffer gnus-article-buffer))
379         end beg contents)
380     (if (not (and (get-buffer article-buffer)
381                   (gnus-buffer-exists-p article-buffer)))
382         (error "Can't find any article buffer")
383       (save-excursion
384         (set-buffer article-buffer)
385         (save-restriction
386           ;; Copy over the (displayed) article buffer, delete
387           ;; hidden text and remove text properties.
388           (widen)
389           (copy-to-buffer gnus-article-copy (point-min) (point-max))
390           (set-buffer gnus-article-copy)
391           (gnus-article-delete-text-of-type 'annotation)
392           (gnus-remove-text-with-property 'gnus-prev)
393           (gnus-remove-text-with-property 'gnus-next)
394           (insert
395            (prog1
396                (format "%s" (buffer-string))
397              (erase-buffer)))
398           ;; Find the original headers.
399           (set-buffer gnus-original-article-buffer)
400           (goto-char (point-min))
401           (while (looking-at message-unix-mail-delimiter)
402             (forward-line 1))
403           (setq beg (point))
404           (setq end (or (search-forward "\n\n" nil t) (point)))
405           ;; Delete the headers from the displayed articles.
406           (set-buffer gnus-article-copy)
407           (delete-region (goto-char (point-min))
408                          (or (search-forward "\n\n" nil t) (point)))
409           ;; Insert the original article headers.
410           (insert-buffer-substring gnus-original-article-buffer beg end)
411           (gnus-article-decode-rfc1522)))
412       gnus-article-copy)))
413
414 (defun gnus-post-news (post &optional group header article-buffer yank subject
415                             force-news)
416   (when article-buffer
417     (gnus-copy-article-buffer))
418   (let ((gnus-article-reply article-buffer)
419         (add-to-list gnus-add-to-list))
420     (gnus-setup-message (cond (yank 'reply-yank)
421                               (article-buffer 'reply)
422                               (t 'message))
423       (let* ((group (or group gnus-newsgroup-name))
424              (pgroup group)
425              to-address to-group mailing-list to-list
426              newsgroup-p)
427         (when group
428           (setq to-address (gnus-group-find-parameter group 'to-address)
429                 to-group (gnus-group-find-parameter group 'to-group)
430                 to-list (gnus-group-find-parameter group 'to-list)
431                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
432                 mailing-list (when gnus-mailing-list-groups
433                                (string-match gnus-mailing-list-groups group))
434                 group (gnus-group-real-name group)))
435         (if (or (and to-group
436                      (gnus-news-group-p to-group))
437                 newsgroup-p
438                 force-news
439                 (and (gnus-news-group-p
440                       (or pgroup gnus-newsgroup-name)
441                       (if header (mail-header-number header)
442                         gnus-current-article))
443                      (not mailing-list)
444                      (not to-list)
445                      (not to-address)))
446             ;; This is news.
447             (if post
448                 (message-news (or to-group group))
449               (set-buffer gnus-article-copy)
450               (gnus-msg-treat-broken-reply-to)
451               (message-followup (if (or newsgroup-p force-news) nil to-group)))
452           ;; The is mail.
453           (if post
454               (progn
455                 (message-mail (or to-address to-list))
456                 ;; Arrange for mail groups that have no `to-address' to
457                 ;; get that when the user sends off the mail.
458                 (when (and (not to-list)
459                            (not to-address)
460                            add-to-list)
461                   (push (list 'gnus-inews-add-to-address pgroup)
462                         message-send-actions)))
463             (set-buffer gnus-article-copy)
464             (gnus-msg-treat-broken-reply-to)
465             (message-wide-reply to-address)))
466         (when yank
467           (gnus-inews-yank-articles yank))))))
468
469 (defun gnus-msg-treat-broken-reply-to ()
470   "Remove the Reply-to header iff broken-reply-to."
471   (when (gnus-group-find-parameter
472          gnus-newsgroup-name 'broken-reply-to)
473     (save-restriction
474       (message-narrow-to-head)
475       (message-remove-header "reply-to"))))
476
477 (defun gnus-post-method (arg group &optional silent)
478   "Return the posting method based on GROUP and ARG.
479 If SILENT, don't prompt the user."
480   (let ((group-method (gnus-find-method-for-group group)))
481     (cond
482      ;; If the group-method is nil (which shouldn't happen) we use
483      ;; the default method.
484      ((null group-method)
485       (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
486                gnus-select-method message-post-method))
487      ;; We want the inverse of the default
488      ((and arg (not (eq arg 0)))
489       (if (eq gnus-post-method 'active)
490           gnus-select-method
491         group-method))
492      ;; We query the user for a post method.
493      ((or arg
494           (and gnus-post-method
495                (not (eq gnus-post-method 'current))
496                (listp (car gnus-post-method))))
497       (let* ((methods
498               ;; Collect all methods we know about.
499               (append
500                (when (and gnus-post-method
501                           (not (eq gnus-post-method 'current)))
502                  (if (listp (car gnus-post-method))
503                      gnus-post-method
504                    (list gnus-post-method)))
505                gnus-secondary-select-methods
506                (mapcar 'cdr gnus-server-alist)
507                (list gnus-select-method)
508                (list group-method)))
509              method-alist post-methods method)
510         ;; Weed out all mail methods.
511         (while methods
512           (setq method (gnus-server-get-method "" (pop methods)))
513           (when (or (gnus-method-option-p method 'post)
514                     (gnus-method-option-p method 'post-mail))
515             (push method post-methods)))
516         ;; Create a name-method alist.
517         (setq method-alist
518               (mapcar
519                (lambda (m)
520                  (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
521                post-methods))
522         ;; Query the user.
523         (cadr
524          (assoc
525           (setq gnus-last-posting-server
526                 (if (and silent
527                          gnus-last-posting-server)
528                     ;; Just use the last value.
529                     gnus-last-posting-server
530                   (completing-read
531                    "Posting method: " method-alist nil t
532                    (cons (or gnus-last-posting-server "") 0))))
533           method-alist))))
534      ;; Override normal method.
535      ((and (eq gnus-post-method 'current)
536            (not (eq (car group-method) 'nndraft))
537            (not arg))
538       group-method) 
539      ((and gnus-post-method
540            (not (eq gnus-post-method 'current)))
541       gnus-post-method)
542      ;; Use the normal select method.
543      (t gnus-select-method))))
544
545 \f
546 ;;;
547 ;;; Gnus Mail Functions
548 ;;;
549
550 ;;; Mail reply commands of Gnus summary mode
551
552 (defun gnus-summary-reply (&optional yank wide)
553   "Start composing a reply mail to the current message.
554 If prefix argument YANK is non-nil, the original article is yanked
555 automatically."
556   (interactive
557    (list (and current-prefix-arg
558               (gnus-summary-work-articles 1))))
559   ;; Stripping headers should be specified with mail-yank-ignored-headers.
560   (when yank
561     (gnus-summary-goto-subject (car yank)))
562   (let ((gnus-article-reply t)
563         (gnus-inhibit-posting-styles t))
564     (gnus-setup-message (if yank 'reply-yank 'reply)
565       (gnus-summary-select-article)
566       (set-buffer (gnus-copy-article-buffer))
567       (gnus-msg-treat-broken-reply-to)
568       (message-reply nil wide)
569       (when yank
570         (gnus-inews-yank-articles yank)))))
571
572 (defun gnus-summary-reply-with-original (n &optional wide)
573   "Start composing a reply mail to the current message.
574 The original article will be yanked."
575   (interactive "P")
576   (gnus-summary-reply (gnus-summary-work-articles n) wide))
577
578 (defun gnus-summary-wide-reply (&optional yank)
579   "Start composing a wide reply mail to the current message.
580 If prefix argument YANK is non-nil, the original article is yanked
581 automatically."
582   (interactive
583    (list (and current-prefix-arg
584               (gnus-summary-work-articles 1))))
585   (gnus-summary-reply yank t))
586
587 (defun gnus-summary-wide-reply-with-original (n)
588   "Start composing a wide reply mail to the current message.
589 The original article will be yanked."
590   (interactive "P")
591   (gnus-summary-reply-with-original n t))
592
593 (defun gnus-summary-mail-forward (&optional full-headers post)
594   "Forward the current message to another user.
595 If FULL-HEADERS (the prefix), include full headers when forwarding."
596   (interactive "P")
597   (gnus-setup-message 'forward
598     (gnus-summary-select-article)
599     (let ((charset default-mime-charset))
600       (set-buffer gnus-original-article-buffer)
601       (make-local-variable 'default-mime-charset)
602       (setq default-mime-charset charset)
603       )
604     (let ((message-included-forward-headers
605            (if full-headers "" message-included-forward-headers)))
606       (message-forward post))))
607
608 (defun gnus-summary-post-forward (&optional full-headers)
609   "Forward the current article to a newsgroup.
610 If FULL-HEADERS (the prefix), include full headers when forwarding."
611   (interactive "P")
612   (gnus-summary-mail-forward full-headers t))
613
614 ;;; XXX: generate Subject and ``Topics''?
615 (defun gnus-summary-mail-digest (&optional n post)
616   "Digests and forwards all articles in this series."
617   (interactive "P")
618   (let ((subject "Digested Articles")
619         (articles (gnus-summary-work-articles n))
620         article)
621     (gnus-setup-message 'forward
622       (gnus-summary-select-article)
623       (if post (message-news nil subject) (message-mail nil subject))
624       (message-goto-body)
625       (while (setq article (pop articles))
626         (save-window-excursion
627           (set-buffer gnus-summary-buffer)
628           (gnus-summary-select-article nil nil nil article)
629           (gnus-summary-remove-process-mark article))
630         (insert (mime-make-tag "message" "rfc822") "\n")
631         (insert-buffer-substring gnus-original-article-buffer))
632       (push-mark)
633       (message-goto-body)
634       (mime-edit-enclose-digest-region (point)(mark t)))))
635
636 (defun gnus-summary-post-digest (&optional n)
637   "Digest and forwards all articles in this series to a newsgroup."
638   (interactive "P")
639   (gnus-summary-mail-digest n t))
640  
641 (defun gnus-summary-resend-message (address n)
642   "Resend the current article to ADDRESS."
643   (interactive "sResend message(s) to: \nP")
644   (let ((articles (gnus-summary-work-articles n))
645         article)
646     (while (setq article (pop articles))
647       (gnus-summary-select-article nil nil nil article)
648       (save-excursion
649         (set-buffer gnus-original-article-buffer)
650         (message-resend address)))))
651
652 (defvar gnus-nastygram-message
653   "The following article was inappropriately posted to %s.\n\n"
654   "Format string to insert in nastygrams.
655 The current group name will be inserted at \"%s\".")
656
657 (defun gnus-summary-mail-nastygram (n)
658   "Send a nastygram to the author of the current article."
659   (interactive "P")
660   (when (or gnus-expert-user
661             (gnus-y-or-n-p
662              "Really send a nastygram to the author of the current article? "))
663     (let ((group gnus-newsgroup-name))
664       (gnus-summary-reply-with-original n)
665       (set-buffer gnus-message-buffer)
666       (message-goto-body)
667       (insert (format gnus-nastygram-message group))
668       (message-send-and-exit))))
669
670 (defun gnus-summary-mail-crosspost-complaint (n)
671   "Send a complaint about crossposting to the current article(s)."
672   (interactive "P")
673   (let ((articles (gnus-summary-work-articles n))
674         article)
675     (while (setq article (pop articles))
676       (set-buffer gnus-summary-buffer)
677       (gnus-summary-goto-subject article)
678       (let ((group (gnus-group-real-name gnus-newsgroup-name))
679             newsgroups followup-to)
680         (gnus-summary-select-article)
681         (set-buffer gnus-original-article-buffer)
682         (if (and (<= (length (message-tokenize-header
683                               (setq newsgroups (mail-fetch-field "newsgroups"))
684                               ", "))
685                      1)
686                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
687                      (not (member group (message-tokenize-header
688                                          followup-to ", ")))))
689             (if followup-to
690                 (gnus-message 1 "Followup-to restricted")
691               (gnus-message 1 "Not a crossposted article"))
692           (set-buffer gnus-summary-buffer)
693           (gnus-summary-reply-with-original 1)
694           (set-buffer gnus-message-buffer)
695           (message-goto-body)
696           (insert (format gnus-crosspost-complaint newsgroups group))
697           (message-goto-subject)
698           (re-search-forward " *$")
699           (replace-match " (crosspost notification)" t t)
700           (gnus-deactivate-mark)
701           (when (gnus-y-or-n-p "Send this complaint? ")
702             (message-send-and-exit)))))))
703
704 (defun gnus-summary-mail-other-window ()
705   "Compose mail in other window."
706   (interactive)
707   (gnus-setup-message 'message
708     (message-mail)))
709
710 (defun gnus-mail-parse-comma-list ()
711   (let (accumulated
712         beg)
713     (skip-chars-forward " ")
714     (while (not (eobp))
715       (setq beg (point))
716       (skip-chars-forward "^,")
717       (while (zerop
718               (save-excursion
719                 (save-restriction
720                   (let ((i 0))
721                     (narrow-to-region beg (point))
722                     (goto-char beg)
723                     (logand (progn
724                               (while (search-forward "\"" nil t)
725                                 (incf i))
726                               (if (zerop i) 2 i))
727                             2)))))
728         (skip-chars-forward ",")
729         (skip-chars-forward "^,"))
730       (skip-chars-backward " ")
731       (push (buffer-substring beg (point))
732             accumulated)
733       (skip-chars-forward "^,")
734       (skip-chars-forward ", "))
735     accumulated))
736
737 (defun gnus-inews-add-to-address (group)
738   (let ((to-address (mail-fetch-field "to")))
739     (when (and to-address
740                (gnus-alive-p))
741       ;; This mail group doesn't have a `to-list', so we add one
742       ;; here.  Magic!
743       (when (gnus-y-or-n-p
744              (format "Do you want to add this as `to-list': %s " to-address))
745         (gnus-group-add-parameter group (cons 'to-list to-address))))))
746
747 (defun gnus-put-message ()
748   "Put the current message in some group and return to Gnus."
749   (interactive)
750   (let ((reply gnus-article-reply)
751         (winconf gnus-prev-winconf)
752         (group gnus-newsgroup-name))
753
754     (or (and group (not (gnus-group-read-only-p group)))
755         (setq group (read-string "Put in group: " nil
756                                  (gnus-writable-groups))))
757     (when (gnus-gethash group gnus-newsrc-hashtb)
758       (error "No such group: %s" group))
759
760     (save-excursion
761       (save-restriction
762         (widen)
763         (message-narrow-to-headers)
764         (let (gnus-deletable-headers)
765           (if (message-news-p)
766               (message-generate-headers message-required-news-headers)
767             (message-generate-headers message-required-mail-headers)))
768         (goto-char (point-max))
769         (insert "Gcc: " group "\n")
770         (widen)))
771
772     (gnus-inews-do-gcc)
773
774     (when (get-buffer gnus-group-buffer)
775       (when (gnus-buffer-exists-p (car-safe reply))
776         (set-buffer (car reply))
777         (and (cdr reply)
778              (gnus-summary-mark-article-as-replied
779               (cdr reply))))
780       (when winconf
781         (set-window-configuration winconf)))))
782
783 (defun gnus-article-mail (yank)
784   "Send a reply to the address near point.
785 If YANK is non-nil, include the original article."
786   (interactive "P")
787   (let ((address
788          (buffer-substring
789           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
790           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
791     (when address
792       (message-reply address)
793       (when yank
794         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
795
796 (defvar nntp-server-type)
797 (defun gnus-bug ()
798   "Send a bug report to the Gnus maintainers."
799   (interactive)
800   (unless (gnus-alive-p)
801     (error "Gnus has been shut down"))
802   (gnus-setup-message 'bug
803     (delete-other-windows)
804     (when gnus-bug-create-help-buffer
805       (switch-to-buffer "*Gnus Help Bug*")
806       (erase-buffer)
807       (insert gnus-bug-message)
808       (goto-char (point-min)))
809     (message-pop-to-buffer "*Gnus Bug*")
810     (message-setup
811      `((To . ,gnus-maintainer) (Cc . ,semi-gnus-developers) (Subject . "")))
812     (when gnus-bug-create-help-buffer
813       (push `(gnus-bug-kill-buffer) message-send-actions))
814     (goto-char (point-min))
815     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
816     (forward-line 1)
817     (insert (gnus-version) "\n"
818             (emacs-version) "\n")
819     (when (and (boundp 'nntp-server-type)
820                (stringp nntp-server-type))
821       (insert nntp-server-type))
822     (insert "\n\n\n\n\n")
823     (gnus-debug)
824     (goto-char (point-min))
825     (search-forward "Subject: " nil t)
826     (message "")))
827
828 (defun gnus-bug-kill-buffer ()
829   (when (get-buffer "*Gnus Help Bug*")
830     (kill-buffer "*Gnus Help Bug*")))
831
832 (defun gnus-debug ()
833   "Attempts to go through the Gnus source file and report what variables have been changed.
834 The source file has to be in the Emacs load path."
835   (interactive)
836   (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
837                  "gnus-art.el" "gnus-start.el" "gnus-async.el"
838                  "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
839                  "nnmail.el" "message.el"))
840         (point (point))
841         file expr olist sym)
842     (gnus-message 4 "Please wait while we snoop your variables...")
843     (sit-for 0)
844     ;; Go through all the files looking for non-default values for variables.
845     (save-excursion
846       (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
847       (buffer-disable-undo (current-buffer))
848       (while files
849         (erase-buffer)
850         (when (and (setq file (locate-library (pop files)))
851                    (file-exists-p file))
852           (insert-file-contents file)
853           (goto-char (point-min))
854           (if (not (re-search-forward "^;;* *Internal variables" nil t))
855               (gnus-message 4 "Malformed sources in file %s" file)
856             (narrow-to-region (point-min) (point))
857             (goto-char (point-min))
858             (while (setq expr (ignore-errors (read (current-buffer))))
859               (ignore-errors
860                 (and (or (eq (car expr) 'defvar)
861                          (eq (car expr) 'defcustom))
862                      (stringp (nth 3 expr))
863                      (or (not (boundp (nth 1 expr)))
864                          (not (equal (eval (nth 2 expr))
865                                      (symbol-value (nth 1 expr)))))
866                      (push (nth 1 expr) olist)))))))
867       (kill-buffer (current-buffer)))
868     (when (setq olist (nreverse olist))
869       (insert "------------------ Environment follows ------------------\n\n"))
870     (while olist
871       (if (boundp (car olist))
872           (condition-case ()
873               (pp `(setq ,(car olist)
874                          ,(if (or (consp (setq sym (symbol-value (car olist))))
875                                   (and (symbolp sym)
876                                        (not (or (eq sym nil)
877                                                 (eq sym t)))))
878                               (list 'quote (symbol-value (car olist)))
879                             (symbol-value (car olist))))
880                   (current-buffer))
881             (error
882              (format "(setq %s 'whatever)\n" (car olist))))
883         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
884       (setq olist (cdr olist)))
885     (insert "\n\n")
886     ;; Remove any control chars - they seem to cause trouble for some
887     ;; mailers.  (Byte-compiled output from the stuff above.)
888     (goto-char point)
889     (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
890       (replace-match (format "\\%03o" (string-to-char (match-string 0)))
891                      t t))))
892
893 ;;; Treatment of rejected articles.
894 ;;; Bounced mail.
895
896 (defun gnus-summary-resend-bounced-mail (&optional fetch)
897   "Re-mail the current message.
898 This only makes sense if the current message is a bounce message than
899 contains some mail you have written which has been bounced back to
900 you.
901 If FETCH, try to fetch the article that this is a reply to, if indeed
902 this is a reply."
903   (interactive "P")
904   (gnus-summary-select-article t)
905   (set-buffer gnus-original-article-buffer)
906   (gnus-setup-message 'compose-bounce
907     (let* ((references (mail-fetch-field "references"))
908            (parent (and references (gnus-parent-id references))))
909       (message-bounce)
910       ;; If there are references, we fetch the article we answered to.
911       (and fetch parent
912            (gnus-summary-refer-article parent)
913            (gnus-summary-show-all-headers)))))
914
915 ;;; Gcc handling.
916
917 ;; Do Gcc handling, which copied the message over to some group.
918 (defun gnus-inews-do-gcc (&optional gcc)
919   (interactive)
920   (when (gnus-alive-p)
921     (save-excursion
922       (save-restriction
923         (message-narrow-to-headers)
924         (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
925               (coding-system-for-write 'raw-text)
926               groups group method)
927           (when gcc
928             (message-remove-header "gcc")
929             (widen)
930             (setq groups (message-tokenize-header gcc " ,"))
931             ;; Copy the article over to some group(s).
932             (while (setq group (pop groups))
933               (gnus-check-server
934                (setq method
935                      (cond ((and (null (gnus-get-info group))
936                                  (eq (car gnus-message-archive-method)
937                                      (car
938                                       (gnus-server-to-method
939                                        (gnus-group-method group)))))
940                             ;; If the group doesn't exist, we assume
941                             ;; it's an archive group...
942                             gnus-message-archive-method)
943                            ;; Use the method.
944                            ((gnus-info-method (gnus-get-info group))
945                             (gnus-info-method (gnus-get-info group)))
946                            ;; Find the method.
947                            (t (gnus-group-method group)))))
948               (gnus-check-server method)
949               (unless (gnus-request-group group t method)
950                 (gnus-request-create-group group method))
951               (save-excursion
952                 (nnheader-set-temp-buffer " *acc*")
953                 (insert-buffer-substring message-encoding-buffer)
954                 (gnus-run-hooks 'gnus-before-do-gcc-hook)
955                 (goto-char (point-min))
956                 (when (re-search-forward
957                        (concat "^" (regexp-quote mail-header-separator) "$")
958                        nil t)
959                   (replace-match "" t t ))
960                 (unless (gnus-request-accept-article group method t)
961                   (gnus-message 1 "Couldn't store article in group %s: %s"
962                                 group (gnus-status-message method))
963                   (sit-for 2))
964                 (kill-buffer (current-buffer))))))))))
965
966 (defun gnus-inews-insert-gcc ()
967   "Insert Gcc headers based on `gnus-outgoing-message-group'."
968   (save-excursion
969     (save-restriction
970       (message-narrow-to-headers)
971       (let* ((group gnus-outgoing-message-group)
972              (gcc (cond
973                    ((gnus-functionp group)
974                     (funcall group))
975                    ((or (stringp group) (list group))
976                     group))))
977         (when gcc
978           (insert "Gcc: "
979                   (if (stringp gcc) gcc
980                     (mapconcat 'identity gcc " "))
981                   "\n"))))))
982
983 (defun gnus-inews-insert-archive-gcc (&optional group)
984   "Insert the Gcc to say where the article is to be archived."
985   (let* ((var gnus-message-archive-group)
986          (group (or group gnus-newsgroup-name ""))
987          (gcc-self-val
988           (and gnus-newsgroup-name
989                (gnus-group-find-parameter
990                 gnus-newsgroup-name 'gcc-self)))
991          result 
992          (groups
993           (cond
994            ((null gnus-message-archive-method)
995             ;; Ignore.
996             nil)
997            ((stringp var)
998             ;; Just a single group.
999             (list var))
1000            ((null var)
1001             ;; We don't want this.
1002             nil)
1003            ((and (listp var) (stringp (car var)))
1004             ;; A list of groups.
1005             var)
1006            ((gnus-functionp var)
1007             ;; A function.
1008             (funcall var group))
1009            (t
1010             ;; An alist of regexps/functions/forms.
1011             (while (and var
1012                         (not
1013                          (setq result
1014                                (cond
1015                                 ((stringp (caar var))
1016                                  ;; Regexp.
1017                                  (when (string-match (caar var) group)
1018                                    (cdar var)))
1019                                 ((gnus-functionp (car var))
1020                                  ;; Function.
1021                                  (funcall (car var) group))
1022                                 (t
1023                                  (eval (car var)))))))
1024               (setq var (cdr var)))
1025             result)))
1026          name)
1027     (when (or groups gcc-self-val)
1028       (when (stringp groups)
1029         (setq groups (list groups)))
1030       (save-excursion
1031         (save-restriction
1032           (message-narrow-to-headers)
1033           (goto-char (point-max))
1034           (insert "Gcc: ")
1035           (if gcc-self-val
1036               ;; Use the `gcc-self' param value instead.
1037               (progn
1038                 (insert
1039                  (if (stringp gcc-self-val)
1040                      gcc-self-val
1041                    group))
1042                 (if (not (eq gcc-self-val 'none))
1043                     (insert "\n")
1044                   (progn
1045                     (beginning-of-line)
1046                     (kill-line))))
1047             ;; Use the list of groups.
1048             (while (setq name (pop groups))
1049               (insert (if (string-match ":" name)
1050                           name
1051                         (gnus-group-prefixed-name
1052                          name gnus-message-archive-method)))
1053               (when groups
1054                 (insert " ")))
1055             (insert "\n")))))))
1056
1057 ;;; Posting styles.
1058
1059 (defvar gnus-message-style-insertions nil)
1060
1061 (defun gnus-configure-posting-styles ()
1062   "Configure posting styles according to `gnus-posting-styles'."
1063   (unless gnus-inhibit-posting-styles
1064     (let ((styles gnus-posting-styles)
1065           (gnus-newsgroup-name (or gnus-newsgroup-name ""))
1066           style match variable attribute value value-value)
1067       (make-local-variable 'gnus-message-style-insertions)
1068       ;; Go through all styles and look for matches.
1069       (while styles
1070         (setq style (pop styles)
1071               match (pop style))
1072         (when (cond ((stringp match)
1073                      ;; Regexp string match on the group name.
1074                      (string-match match gnus-newsgroup-name))
1075                     ((or (symbolp match)
1076                          (gnus-functionp match))
1077                      (cond ((gnus-functionp match)
1078                             ;; Function to be called.
1079                             (funcall match))
1080                            ((boundp match)
1081                             ;; Variable to be checked.
1082                             (symbol-value match))))
1083                     ((listp match)
1084                      ;; This is a form to be evaled.
1085                      (eval match)))
1086           ;; We have a match, so we set the variables.
1087           (while style
1088             (setq attribute (pop style)
1089                   value (cadr attribute)
1090                   variable nil)
1091             ;; We find the variable that is to be modified.
1092             (if (and (not (stringp (car attribute)))
1093                      (not (eq 'body (car attribute)))
1094                      (not (setq variable
1095                                 (cdr (assq (car attribute) 
1096                                            gnus-posting-style-alist)))))
1097                 (message "Couldn't find attribute %s" (car attribute))
1098               ;; We get the value.
1099               (setq value-value
1100                     (cond ((stringp value)
1101                            value)
1102                           ((or (symbolp value)
1103                                (gnus-functionp value))
1104                            (cond ((gnus-functionp value)
1105                                   (funcall value))
1106                                  ((boundp value)
1107                                   (symbol-value value))))
1108                           ((listp value)
1109                            (eval value))))
1110               (if variable
1111                   ;; This is an ordinary variable.
1112                   (set (make-local-variable variable) value-value)
1113                 ;; This is either a body or a header to be inserted in the
1114                 ;; message.
1115                 (when value-value
1116                   (let ((attr (car attribute)))
1117                     (make-local-variable 'message-setup-hook)
1118                     (if (eq 'body attr)
1119                         (add-hook 'message-setup-hook
1120                                   `(lambda ()
1121                                      (save-excursion
1122                                        (message-goto-body)
1123                                        (insert ,value-value))))
1124                       (add-hook 'message-setup-hook
1125                                 'gnus-message-insert-stylings)
1126                       (push (cons (if (stringp attr) attr
1127                                     (symbol-name attr))
1128                                   value-value)
1129                             gnus-message-style-insertions))))))))))))
1130
1131 (defun gnus-message-insert-stylings ()
1132   (let (val)
1133     (save-excursion
1134       (message-goto-eoh)
1135       (while (setq val (pop gnus-message-style-insertions))
1136         (when (cdr val)
1137           (insert (car val) ": " (cdr val) "\n"))
1138         (gnus-pull (car val) gnus-message-style-insertions)))))
1139
1140 ;;; Allow redefinition of functions.
1141
1142 (gnus-ems-redefine)
1143
1144 (provide 'gnus-msg)
1145
1146 ;;; gnus-msg.el ends here