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