* lisp/gnus-msg.el (gnus-debug): Use `sit-for' in the inside of
[elisp/gnus.git-] / lisp / gnus-msg.el
1 ;;; gnus-msg.el --- mail and post interface for Semi-gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;;      Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;;      MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;      Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
9 ;;      Katsumi Yamaoka  <yamaoka@jpl.org>
10 ;;      Kiyokazu SUTO    <suto@merry.xmath.ous.ac.jp>
11 ;; Keywords: mail, news, MIME
12
13 ;; This file is part of GNU Emacs.
14
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; any later version.
19
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 ;; GNU General Public License for more details.
24
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
29
30 ;;; Commentary:
31
32 ;;; Code:
33
34 (eval-when-compile (require 'cl))
35 (eval-when-compile (require 'static))
36
37 (require 'gnus)
38 (require 'gnus-ems)
39 (require 'message)
40 (require 'gnus-art)
41
42 (defcustom gnus-post-method 'current
43   "*Preferred method for posting USENET news.
44
45 If this variable is `current', Gnus will use the \"current\" select
46 method when posting.  If it is nil (which is the default), Gnus will
47 use the native select method when posting.
48
49 This method will not be used in mail groups and the like, only in
50 \"real\" newsgroups.
51
52 If not nil nor `native', the value must be a valid method as discussed
53 in the documentation of `gnus-select-method'.  It can also be a list of
54 methods.  If that is the case, the user will be queried for what select
55 method to use when posting."
56   :group 'gnus-group-foreign
57   :type `(choice (const nil)
58                  (const current)
59                  (const native)
60                  (sexp :tag "Methods" ,gnus-select-method)))
61
62 (defvar gnus-outgoing-message-group nil
63   "*All outgoing messages will be put in this group.
64 If you want to store all your outgoing mail and articles in the group
65 \"nnml:archive\", you set this variable to that value.  This variable
66 can also be a list of group names.
67
68 If you want to have greater control over what group to put each
69 message in, you can set this variable to a function that checks the
70 current newsgroup name and then returns a suitable group name (or list
71 of names).")
72
73 (defvar gnus-mailing-list-groups nil
74   "*Regexp matching groups that are really mailing lists.
75 This is useful when you're reading a mailing list that has been
76 gatewayed to a newsgroup, and you want to followup to an article in
77 the group.")
78
79 (defvar gnus-add-to-list nil
80   "*If non-nil, add a `to-list' parameter automatically.")
81
82 (defvar gnus-crosspost-complaint
83   "Hi,
84
85 You posted the article below with the following Newsgroups header:
86
87 Newsgroups: %s
88
89 The %s group, at least, was an inappropriate recipient
90 of this message.  Please trim your Newsgroups header to exclude this
91 group before posting in the future.
92
93 Thank you.
94
95 "
96   "Format string to be inserted when complaining about crossposts.
97 The first %s will be replaced by the Newsgroups header;
98 the second with the current group name.")
99
100 (defvar gnus-message-setup-hook '(gnus-maybe-setup-default-charset)
101   "Hook run after setting up a message buffer.")
102
103 (defvar gnus-bug-create-help-buffer t
104   "*Should we create the *Gnus Help Bug* buffer?")
105
106 (defvar gnus-posting-styles nil
107   "*Alist of styles to use when posting.")
108
109 (defvar gnus-inews-mark-gcc-as-read nil
110   "If non-nil, automatically mark Gcc articles as read.")
111
112 (defcustom gnus-group-posting-charset-alist
113   '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
114     ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
115     (message-this-is-mail nil nil)
116     (message-this-is-news nil t))
117   "Alist of regexps and permitted unencoded charsets for posting.
118 Each element of the alist has the form (TEST HEADER BODY-LIST), where
119 TEST is either a regular expression matching the newsgroup header or a
120 variable to query,
121 HEADER is the charset which may be left unencoded in the header (nil
122 means encode all charsets),
123 BODY-LIST is a list of charsets which may be encoded using 8bit
124 content-transfer encoding in the body, or one of the special values
125 nil (always encode using quoted-printable) or t (always use 8bit).
126
127 Note that any value other than nil for HEADER infringes some RFCs, so
128 use this option with care."
129   :type '(repeat (list :tag "Permitted unencoded charsets"
130                   (choice :tag "Where"
131                    (regexp :tag "Group")
132                    (const :tag "Mail message" :value message-this-is-mail)
133                    (const :tag "News article" :value message-this-is-news))
134                   (choice :tag "Header"
135                    (const :tag "None" nil)
136                    (symbol :tag "Charset"))
137                   (choice :tag "Body"
138                           (const :tag "Any" :value t)
139                           (const :tag "None" :value nil)
140                           (repeat :tag "Charsets"
141                                   (symbol :tag "Charset")))))
142   :group 'gnus-charset)
143
144 ;;; Internal variables.
145
146 (defvar gnus-inhibit-posting-styles nil
147   "Inhibit the use of posting styles.")
148
149 (defvar gnus-message-buffer "*Mail Gnus*")
150 (defvar gnus-article-copy nil)
151 (defvar gnus-check-before-posting nil)
152 (defvar gnus-last-posting-server nil)
153 (defvar gnus-message-group-art nil)
154
155 (defconst gnus-bug-message
156   (format "Sending a bug report to the Gnus Towers.
157 ========================================
158
159 This gnus is the %s%s.
160 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
161 Developers. (the addresses below are mailing list addresses)
162
163 ========================================
164
165 The buffer below is a mail buffer.  When you press `C-c C-c', it will
166 be sent to the Gnus Bug Exterminators.
167
168 The thing near the bottom of the buffer is how the environment
169 settings will be included in the mail.  Please do not delete that.
170 They will tell the Bug People what your environment is, so that it
171 will be easier to locate the bugs.
172
173 If you have found a bug that makes Emacs go \"beep\", set
174 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
175 and include the backtrace in your bug report.
176
177 Please describe the bug in annoying, painstaking detail.
178
179 Thank you for your help in stamping out bugs.
180 "
181           gnus-product-name
182           (if (string= gnus-product-name "Semi-gnus")
183               ""
184             ", a modified version of Semi-gnus")))
185
186 (eval-and-compile
187   (autoload 'gnus-uu-post-news "gnus-uu" nil t)
188   (autoload 'news-setup "rnewspost")
189   (autoload 'news-reply-mode "rnewspost")
190   (autoload 'rmail-dont-reply-to "mail-utils")
191   (autoload 'rmail-output "rmailout"))
192
193 \f
194 ;;;
195 ;;; Gnus Posting Functions
196 ;;;
197
198 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
199   "p" gnus-summary-post-news
200   "f" gnus-summary-followup
201   "F" gnus-summary-followup-with-original
202   "c" gnus-summary-cancel-article
203   "s" gnus-summary-supersede-article
204   "r" gnus-summary-reply
205   "y" gnus-summary-yank-message
206   "R" gnus-summary-reply-with-original
207   "w" gnus-summary-wide-reply
208   "W" gnus-summary-wide-reply-with-original
209   "n" gnus-summary-followup-to-mail
210   "N" gnus-summary-followup-to-mail-with-original
211   "m" gnus-summary-mail-other-window
212   "u" gnus-uu-post-news
213   "\M-c" gnus-summary-mail-crosspost-complaint
214   "om" gnus-summary-mail-forward
215   "op" gnus-summary-post-forward
216   "Om" gnus-uu-digest-mail-forward
217   "Op" gnus-uu-digest-post-forward)
218
219 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
220   "b" gnus-summary-resend-bounced-mail
221   ;; "c" gnus-summary-send-draft
222   "r" gnus-summary-resend-message)
223
224 ;;; Internal functions.
225
226 (defvar gnus-article-reply nil)
227 (defmacro gnus-setup-message (config &rest forms)
228   (let ((winconf (make-symbol "gnus-setup-message-winconf"))
229         (buffer (make-symbol "gnus-setup-message-buffer"))
230         (article (make-symbol "gnus-setup-message-article"))
231         (group (make-symbol "gnus-setup-message-group")))
232     `(let ((,winconf (current-window-configuration))
233            (,buffer (buffer-name (current-buffer)))
234            (,article (and gnus-article-reply (gnus-summary-article-number)))
235            (,group gnus-newsgroup-name)
236            (message-header-setup-hook
237             (copy-sequence message-header-setup-hook))
238            (message-mode-hook (copy-sequence message-mode-hook))
239            (message-startup-parameter-alist
240             '((reply-buffer . gnus-copy-article-buffer)
241               (original-buffer . gnus-original-article-buffer)
242               (user-agent . Gnus))))
243        (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
244        (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
245        (add-hook 'message-mode-hook 'gnus-configure-posting-styles)
246        (unwind-protect
247            (progn
248              ,@forms)
249          (gnus-inews-add-send-actions ,winconf ,buffer ,article)
250          (setq gnus-message-buffer (current-buffer))
251          (set (make-local-variable 'gnus-message-group-art)
252               (cons ,group ,article))
253          (set (make-local-variable 'gnus-newsgroup-name) ,group)
254          (gnus-run-hooks 'gnus-message-setup-hook))
255        (gnus-add-buffer)
256        (gnus-configure-windows ,config t)
257        (set-buffer-modified-p nil))))
258
259 ;;;###autoload
260 (defun gnus-msg-mail (&rest args)
261   "Start editing a mail message to be sent.
262 Like `message-mail', but with Gnus paraphernalia, particularly the
263 Gcc: header for archiving purposes."
264   (interactive)
265   (gnus-setup-message 'message
266     (apply 'message-mail args))
267   ;; COMPOSEFUNC should return t if succeed.  Undocumented ???
268   t)
269
270 ;;;###autoload
271 (define-mail-user-agent 'gnus-user-agent
272       'gnus-msg-mail 'message-send-and-exit
273       'message-kill-buffer 'message-send-hook)
274
275 (defun gnus-setup-posting-charset (group)
276   (let ((alist gnus-group-posting-charset-alist)
277         (group (or group ""))
278         elem)
279     (when group
280       (catch 'found
281         (while (setq elem (pop alist))
282           (when (or (and (stringp (car elem))
283                          (string-match (car elem) group))
284                     (and (gnus-functionp (car elem))
285                          (funcall (car elem) group))
286                     (and (symbolp (car elem))
287                          (symbol-value (car elem))))
288             (throw 'found (cons (cadr elem) (caddr elem)))))))))
289
290 (defun gnus-inews-add-send-actions (winconf buffer article)
291   (make-local-hook 'message-sent-hook)
292   (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
293                                  'gnus-inews-do-gcc) nil t)
294   (when gnus-agent
295     (make-local-hook 'message-header-hook)
296     (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
297   (setq message-post-method
298         `(lambda (arg)
299            (gnus-post-method arg ,gnus-newsgroup-name)))
300   (setq message-user-agent (gnus-extended-version))
301   (when (not message-use-multi-frames)
302     (message-add-action
303      `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
304   (message-add-action
305    `(when (gnus-buffer-exists-p ,buffer)
306       (save-excursion
307         (set-buffer ,buffer)
308         ,(when article
309            `(gnus-summary-mark-article-as-replied ,article))))
310    'send))
311
312 (put 'gnus-setup-message 'lisp-indent-function 1)
313 (put 'gnus-setup-message 'edebug-form-spec '(form body))
314
315 ;;; Post news commands of Gnus group mode and summary mode
316
317 (defun gnus-group-mail (&optional arg)
318   "Start composing a mail.
319 If ARG, use the group under the point to find a posting style.
320 If ARG is 1, prompt for a group name to find the posting style."
321   (interactive "P")
322   ;; We can't `let' gnus-newsgroup-name here, since that leads
323   ;; to local variables leaking.
324   (let ((group gnus-newsgroup-name)
325         (buffer (current-buffer)))
326     (unwind-protect
327         (progn
328           (setq gnus-newsgroup-name
329                 (if arg
330                     (if (= 1 (prefix-numeric-value arg))
331                         (completing-read "Use posting style of group: "
332                                          gnus-active-hashtb nil
333                                          (gnus-read-active-file-p))
334                       (gnus-group-group-name))
335                   ""))
336           (gnus-setup-message 'message (message-mail)))
337       (save-excursion
338         (set-buffer buffer)
339         (setq gnus-newsgroup-name group)))))
340
341 (defun gnus-group-post-news (&optional arg)
342   "Start composing a news message.
343 If ARG, post to the group under point.
344 If ARG is 1, prompt for a group name."
345   (interactive "P")
346   ;; Bind this variable here to make message mode hooks work ok.
347   (let ((gnus-newsgroup-name
348          (if arg
349              (if (= 1 (prefix-numeric-value arg))
350                  (completing-read "Newsgroup: " gnus-active-hashtb nil
351                                   (gnus-read-active-file-p))
352                (gnus-group-group-name))
353            "")))
354     (gnus-post-news 'post gnus-newsgroup-name)))
355
356 (defun gnus-summary-post-news ()
357   "Start composing a news message."
358   (interactive)
359   (gnus-post-news 'post gnus-newsgroup-name))
360
361 (defun gnus-summary-followup (yank &optional force-news)
362   "Compose a followup to an article.
363 If prefix argument YANK is non-nil, original article is yanked automatically."
364   (interactive
365    (list (and current-prefix-arg
366               (gnus-summary-work-articles 1))))
367   (when yank
368     (gnus-summary-goto-subject (car yank)))
369   (save-window-excursion
370     (gnus-summary-select-article))
371   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
372         (gnus-newsgroup-name gnus-newsgroup-name))
373     ;; Send a followup.
374     (gnus-post-news nil gnus-newsgroup-name
375                     headers gnus-article-buffer
376                     yank nil force-news)))
377
378 (defun gnus-summary-followup-with-original (n &optional force-news)
379   "Compose a followup to an article and include the original article."
380   (interactive "P")
381   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
382
383 (defun gnus-summary-followup-to-mail (&optional arg)
384   "Followup to the current mail message via news."
385   (interactive
386    (list (and current-prefix-arg
387               (gnus-summary-work-articles 1))))
388   (gnus-summary-followup arg t))
389
390 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
391   "Followup to the current mail message via news."
392   (interactive "P")
393   (gnus-summary-followup (gnus-summary-work-articles arg) t))
394
395 (defun gnus-inews-yank-articles (articles)
396   (let* ((more-than-one (cdr articles))
397          (frame (when (and message-use-multi-frames more-than-one)
398                   (window-frame (get-buffer-window (current-buffer)))))
399          refs beg article)
400     (message-goto-body)
401     (while (setq article (pop articles))
402       (save-window-excursion
403         (set-buffer gnus-summary-buffer)
404         (gnus-summary-select-article nil nil nil article)
405         (gnus-summary-remove-process-mark article))
406       (when frame
407         (select-frame frame))
408
409       ;; Gathering references.
410       (when more-than-one
411         (setq refs (message-list-references
412                     refs
413                     (mail-header-references gnus-current-headers)
414                     (mail-header-message-id gnus-current-headers))))
415
416       (gnus-copy-article-buffer)
417       (let ((message-reply-buffer gnus-article-copy)
418             (message-reply-headers gnus-current-headers))
419         (message-yank-original)
420         (setq beg (or beg (mark t))))
421       (when articles
422         (insert "\n")))
423     (push-mark)
424
425     ;; Replace with the gathered references.
426     (when refs
427       (push-mark beg)
428       (save-restriction
429         (message-narrow-to-headers)
430         (let ((case-fold-search t))
431           (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
432               (replace-match "")
433             (goto-char (point-max))))
434         (mail-header-format
435          (list (or (assq 'References message-header-format-alist)
436                    '(References . message-shorten-references)))
437          (list (cons 'References
438                      (mapconcat 'identity (nreverse refs) " "))))
439         (backward-delete-char 1))
440       (setq beg (mark t))
441       (pop-mark))
442
443     (goto-char beg)))
444
445 (defun gnus-summary-cancel-article (&optional n symp)
446   "Cancel an article you posted.
447 Uses the process-prefix convention.  If given the symbolic
448 prefix `a', cancel using the standard posting method; if not
449 post using the current select method."
450   (interactive (gnus-interactive "P\ny"))
451   (let ((articles (gnus-summary-work-articles n))
452         (message-post-method
453          `(lambda (arg)
454             (gnus-post-method (not (eq symp 'a)) ,gnus-newsgroup-name)))
455         article)
456     (while (setq article (pop articles))
457       (when (gnus-summary-select-article t nil nil article)
458         (when (gnus-eval-in-buffer-window gnus-article-buffer
459                 (save-excursion
460                   (set-buffer gnus-original-article-buffer)
461                   (message-cancel-news)))
462           (gnus-summary-mark-as-read article gnus-canceled-mark)
463           (gnus-cache-remove-article 1))
464         (gnus-article-hide-headers-if-wanted))
465       (gnus-summary-remove-process-mark article))))
466
467 (defun gnus-summary-supersede-article ()
468   "Compose an article that will supersede a previous article.
469 This is done simply by taking the old article and adding a Supersedes
470 header line with the old Message-ID."
471   (interactive)
472   (let ((article (gnus-summary-article-number))
473         (gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
474     (gnus-setup-message 'reply-yank
475       (gnus-summary-select-article t)
476       (set-buffer gnus-original-article-buffer)
477       (message-supersede)
478       (push
479        `((lambda ()
480            (when (gnus-buffer-exists-p ,gnus-summary-buffer)
481              (save-excursion
482                (set-buffer ,gnus-summary-buffer)
483                (gnus-cache-possibly-remove-article ,article nil nil nil t)
484                (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
485        message-send-actions))))
486
487 \f
488
489 (defun gnus-copy-article-buffer (&optional article-buffer)
490   ;; make a copy of the article buffer with all text properties removed
491   ;; this copy is in the buffer gnus-article-copy.
492   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
493   ;; this buffer should be passed to all mail/news reply/post routines.
494   (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
495   (let ((article-buffer (or article-buffer gnus-article-buffer))
496         end beg)
497     (if (not (and (get-buffer article-buffer)
498                   (gnus-buffer-exists-p article-buffer)))
499         (error "Can't find any article buffer")
500       (save-excursion
501         (set-buffer article-buffer)
502         (let ((gnus-newsgroup-charset (or gnus-article-charset
503                                           gnus-newsgroup-charset))
504               (gnus-newsgroup-ignored-charsets
505                (or gnus-article-ignored-charsets
506                    gnus-newsgroup-ignored-charsets)))
507           (save-restriction
508             ;; Copy over the (displayed) article buffer, delete
509             ;; hidden text and remove text properties.
510             (widen)
511             (let ((inhibit-read-only t))
512               (copy-to-buffer gnus-article-copy (point-min) (point-max))
513               (set-buffer gnus-article-copy)
514               ;; Encode bitmap smileys to ordinary text.
515               ;; Possibly, the original text might be restored.
516               (static-unless (featurep 'xemacs)
517                 (when (featurep 'smiley-mule)
518                   (smiley-encode-buffer)))
519               (gnus-article-delete-text-of-type 'annotation)
520               (gnus-remove-text-with-property 'gnus-prev)
521               (gnus-remove-text-with-property 'gnus-next)
522               (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
523               (insert
524                (prog1
525                    (buffer-substring-no-properties (point-min) (point-max))
526                  (erase-buffer))))
527             ;; Find the original headers.
528             (set-buffer gnus-original-article-buffer)
529             (goto-char (point-min))
530             (while (looking-at message-unix-mail-delimiter)
531               (forward-line 1))
532             (setq beg (point))
533             (setq end (or (search-forward "\n\n" nil t) (point)))
534             ;; Delete the headers from the displayed articles.
535             (set-buffer gnus-article-copy)
536             (delete-region (goto-char (point-min))
537                            (or (search-forward "\n\n" nil t) (point-max)))
538             ;; Insert the original article headers.
539             (insert-buffer-substring gnus-original-article-buffer beg end)
540             (article-decode-encoded-words))))
541       gnus-article-copy)))
542
543 (defun gnus-post-news (post &optional group header article-buffer yank subject
544                             force-news)
545   (when article-buffer
546     (gnus-copy-article-buffer))
547   (let ((gnus-article-reply article-buffer)
548         (add-to-list gnus-add-to-list))
549     (gnus-setup-message (cond (yank 'reply-yank)
550                               (article-buffer 'reply)
551                               (t 'message))
552       (let* ((group (or group gnus-newsgroup-name))
553              (charset (gnus-group-name-charset nil group))
554              (pgroup group)
555              to-address to-group mailing-list to-list
556              newsgroup-p)
557         (when group
558           (setq to-address (gnus-group-find-parameter group 'to-address)
559                 to-group (gnus-group-find-parameter group 'to-group)
560                 to-list (gnus-group-find-parameter group 'to-list)
561                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
562                 mailing-list (when gnus-mailing-list-groups
563                                (string-match gnus-mailing-list-groups group))
564                 group (gnus-group-name-decode (gnus-group-real-name group)
565                                               charset)))
566         (if (or (and to-group
567                      (gnus-news-group-p to-group))
568                 newsgroup-p
569                 force-news
570                 (and (gnus-news-group-p
571                       (or pgroup gnus-newsgroup-name)
572                       (if header (mail-header-number header)
573                         gnus-current-article))
574                      (not mailing-list)
575                      (not to-list)
576                      (not to-address)))
577             ;; This is news.
578             (if post
579                 (message-news (or to-group group))
580               (set-buffer gnus-article-copy)
581               (gnus-msg-treat-broken-reply-to)
582               (message-followup (if (or newsgroup-p force-news) nil to-group)))
583           ;; The is mail.
584           (if post
585               (progn
586                 (message-mail (or to-address to-list))
587                 ;; Arrange for mail groups that have no `to-address' to
588                 ;; get that when the user sends off the mail.
589                 (when (and (not to-list)
590                            (not to-address)
591                            add-to-list)
592                   (push (list 'gnus-inews-add-to-address pgroup)
593                         message-send-actions)))
594             (set-buffer gnus-article-copy)
595             (gnus-msg-treat-broken-reply-to)
596             (message-wide-reply to-address)))
597         (when yank
598           (gnus-inews-yank-articles yank))))))
599
600 (defun gnus-msg-treat-broken-reply-to ()
601   "Remove the Reply-to header iff broken-reply-to."
602   (when (gnus-group-find-parameter
603          gnus-newsgroup-name 'broken-reply-to)
604     (save-restriction
605       (message-narrow-to-head)
606       (message-remove-header "reply-to"))))
607
608 (defun gnus-post-method (arg group &optional silent)
609   "Return the posting method based on GROUP and ARG.
610 If SILENT, don't prompt the user."
611   (let ((group-method (gnus-find-method-for-group group)))
612     (cond
613      ;; If the group-method is nil (which shouldn't happen) we use
614      ;; the default method.
615      ((null group-method)
616       (or (and (null (eq gnus-post-method 'active)) gnus-post-method)
617           gnus-select-method message-post-method))
618      ;; We want the inverse of the default
619      ((and arg (not (eq arg 0)))
620       (if (eq gnus-post-method 'active)
621           gnus-select-method
622         group-method))
623      ;; We query the user for a post method.
624      ((or arg
625           (and gnus-post-method
626                (not (eq gnus-post-method 'current))
627                (listp (car gnus-post-method))))
628       (let* ((methods
629               ;; Collect all methods we know about.
630               (append
631                (when (and gnus-post-method
632                           (not (eq gnus-post-method 'current)))
633                  (if (listp (car gnus-post-method))
634                      gnus-post-method
635                    (list gnus-post-method)))
636                gnus-secondary-select-methods
637                (mapcar 'cdr gnus-server-alist)
638                (mapcar 'car gnus-opened-servers)
639                (list gnus-select-method)
640                (list group-method)))
641              method-alist post-methods method)
642         ;; Weed out all mail methods.
643         (while methods
644           (setq method (gnus-server-get-method "" (pop methods)))
645           (when (and (or (gnus-method-option-p method 'post)
646                          (gnus-method-option-p method 'post-mail))
647                      (not (member method post-methods)))
648             (push method post-methods)))
649         ;; Create a name-method alist.
650         (setq method-alist
651               (mapcar
652                (lambda (m)
653                  (if (equal (cadr m) "")
654                      (list (symbol-name (car m)) m)
655                    (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
656                post-methods))
657         ;; Query the user.
658         (cadr
659          (assoc
660           (setq gnus-last-posting-server
661                 (if (and silent
662                          gnus-last-posting-server)
663                     ;; Just use the last value.
664                     gnus-last-posting-server
665                   (completing-read
666                    "Posting method: " method-alist nil t
667                    (cons (or gnus-last-posting-server "") 0))))
668           method-alist))))
669      ;; Override normal method.
670      ((and (eq gnus-post-method 'current)
671            (not (eq (car group-method) 'nndraft))
672            (gnus-get-function group-method 'request-post t)
673            (not arg))
674       group-method)
675      ((and gnus-post-method
676            (not (eq gnus-post-method 'current)))
677       gnus-post-method)
678      ;; Use the normal select method.
679      (t gnus-select-method))))
680
681 \f
682
683 (defun gnus-message-make-user-agent (&optional include-mime-info max-column)
684   "Return user-agent info.
685 INCLUDE-MIME-INFO the optional first argument if it is non-nil and the variable
686   `mime-edit-user-agent-value' exists, the return value will include it.
687 MAX-COLUMN the optional second argument if it is specified, the return value
688   will be folded up in the proper way."
689   (let ((user-agent (if (and include-mime-info
690                              (boundp 'mime-edit-user-agent-value))
691                         (concat (gnus-extended-version)
692                                 " "
693                                 mime-edit-user-agent-value)
694                       (gnus-extended-version))))
695     (if max-column
696         (let (boundary)
697           (unless (natnump max-column) (setq max-column 76))
698           (with-temp-buffer
699             (insert "            " user-agent)
700             (goto-char 13)
701             (while (re-search-forward "[\n\t ]+" nil t)
702               (replace-match " "))
703             (goto-char 13)
704             (while (re-search-forward "[^ ()/]+\\(/[^ ()/]+\\)? ?" nil t)
705               (while (eq ?\( (char-after (point)))
706                 (forward-list)
707                 (skip-chars-forward " "))
708               (skip-chars-backward " ")
709               (if (> (current-column) max-column)
710                   (progn
711                     (if (or (not boundary) (eq ?\n (char-after boundary)))
712                         (progn
713                           (setq boundary (point))
714                           (unless (eobp)
715                             (delete-char 1)
716                             (insert "\n ")))
717                       (goto-char boundary)
718                       (delete-char 1)
719                       (insert "\n ")))
720                 (setq boundary (point))))
721             (buffer-substring 13 (point-max))))
722       user-agent)))
723
724 \f
725 ;;;
726 ;;; Gnus Mail Functions
727 ;;;
728
729 ;;; Mail reply commands of Gnus summary mode
730
731 (defun gnus-summary-reply (&optional yank wide)
732   "Start composing a reply mail to the current message.
733 If prefix argument YANK is non-nil, the original article is yanked
734 automatically."
735   (interactive
736    (list (and current-prefix-arg
737               (gnus-summary-work-articles 1))))
738   ;; Stripping headers should be specified with mail-yank-ignored-headers.
739   (when yank
740     (gnus-summary-goto-subject (car yank)))
741   (let ((gnus-article-reply t))
742     (gnus-setup-message (if yank 'reply-yank 'reply)
743       (gnus-summary-select-article)
744       (set-buffer (gnus-copy-article-buffer))
745       (gnus-msg-treat-broken-reply-to)
746       (message-reply nil wide)
747       (when yank
748         (gnus-inews-yank-articles yank)))))
749
750 (defun gnus-summary-reply-with-original (n &optional wide)
751   "Start composing a reply mail to the current message.
752 The original article will be yanked."
753   (interactive "P")
754   (gnus-summary-reply (gnus-summary-work-articles n) wide))
755
756 (defun gnus-summary-wide-reply (&optional yank)
757   "Start composing a wide reply mail to the current message.
758 If prefix argument YANK is non-nil, the original article is yanked
759 automatically."
760   (interactive
761    (list (and current-prefix-arg
762               (gnus-summary-work-articles 1))))
763   (gnus-summary-reply yank t))
764
765 (defun gnus-summary-wide-reply-with-original (n)
766   "Start composing a wide reply mail to the current message.
767 The original article will be yanked."
768   (interactive "P")
769   (gnus-summary-reply-with-original n t))
770
771 (defun gnus-summary-mail-forward (&optional full-headers post)
772   "Forward the current message to another user.
773 If FULL-HEADERS (the prefix), include full headers when forwarding."
774   (interactive "P")
775   (gnus-setup-message 'forward
776     (gnus-summary-select-article)
777     (let ((charset default-mime-charset))
778       (set-buffer gnus-original-article-buffer)
779       (make-local-variable 'default-mime-charset)
780       (setq default-mime-charset charset))
781     (let ((message-included-forward-headers
782            (if full-headers "" message-included-forward-headers)))
783       (message-forward post))))
784
785 ;;;;; XXX: generate Subject and ``Topics''?
786 ;;(defun gnus-summary-mail-digest (&optional n post)
787 ;;  "Digests and forwards all articles in this series."
788 ;;  (interactive "P")
789 ;;  (let ((subject "Digested Articles")
790 ;;      (articles (gnus-summary-work-articles n))
791 ;;      article frame)
792 ;;    (gnus-setup-message 'forward
793 ;;      (gnus-summary-select-article)
794 ;;      (if post (message-news nil subject) (message-mail nil subject))
795 ;;      (when (and message-use-multi-frames (cdr articles))
796 ;;      (setq frame (window-frame (get-buffer-window (current-buffer)))))
797 ;;      (message-goto-body)
798 ;;      (while (setq article (pop articles))
799 ;;      (save-window-excursion
800 ;;        (set-buffer gnus-summary-buffer)
801 ;;        (gnus-summary-select-article nil nil nil article)
802 ;;        (gnus-summary-remove-process-mark article))
803 ;;      (when frame
804 ;;        (select-frame frame))
805 ;;      (insert (mime-make-tag "message" "rfc822") "\n")
806 ;;      (insert-buffer-substring gnus-original-article-buffer))
807 ;;      (push-mark)
808 ;;      (message-goto-body)
809 ;;      (mime-edit-enclose-digest-region (point)(mark t)))))
810 ;;
811 ;;(defun gnus-summary-post-digest (&optional n)
812 ;;  "Digest and forwards all articles in this series to a newsgroup."
813 ;;  (interactive "P")
814 ;;  (gnus-summary-mail-digest n t))
815
816 (defun gnus-summary-resend-message (address n)
817   "Resend the current article to ADDRESS."
818   (interactive "sResend message(s) to: \nP")
819   (let ((articles (gnus-summary-work-articles n))
820         article)
821     (while (setq article (pop articles))
822       (gnus-summary-select-article nil nil nil article)
823       (save-excursion
824         (set-buffer gnus-original-article-buffer)
825         (message-resend address)))))
826
827 (defun gnus-summary-post-forward (&optional full-headers)
828   "Forward the current article to a newsgroup.
829 If FULL-HEADERS (the prefix), include full headers when forwarding."
830   (interactive "P")
831   (gnus-summary-mail-forward full-headers t))
832
833 (defvar gnus-nastygram-message
834   "The following article was inappropriately posted to %s.\n\n"
835   "Format string to insert in nastygrams.
836 The current group name will be inserted at \"%s\".")
837
838 (defun gnus-summary-mail-nastygram (n)
839   "Send a nastygram to the author of the current article."
840   (interactive "P")
841   (when (or gnus-expert-user
842             (gnus-y-or-n-p
843              "Really send a nastygram to the author of the current article? "))
844     (let ((group gnus-newsgroup-name))
845       (gnus-summary-reply-with-original n)
846       (set-buffer gnus-message-buffer)
847       (message-goto-body)
848       (insert (format gnus-nastygram-message group))
849       (message-send-and-exit))))
850
851 (defun gnus-summary-mail-crosspost-complaint (n)
852   "Send a complaint about crossposting to the current article(s)."
853   (interactive "P")
854   (let ((articles (gnus-summary-work-articles n))
855         article)
856     (while (setq article (pop articles))
857       (set-buffer gnus-summary-buffer)
858       (gnus-summary-goto-subject article)
859       (let ((group (gnus-group-real-name gnus-newsgroup-name))
860             newsgroups followup-to)
861         (gnus-summary-select-article)
862         (set-buffer gnus-original-article-buffer)
863         (if (and (<= (length (message-tokenize-header
864                               (setq newsgroups
865                                     (mail-fetch-field "newsgroups"))
866                               ", "))
867                      1)
868                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
869                      (not (member group (message-tokenize-header
870                                          followup-to ", ")))))
871             (if followup-to
872                 (gnus-message 1 "Followup-to restricted")
873               (gnus-message 1 "Not a crossposted article"))
874           (set-buffer gnus-summary-buffer)
875           (gnus-summary-reply-with-original 1)
876           (set-buffer gnus-message-buffer)
877           (message-goto-body)
878           (insert (format gnus-crosspost-complaint newsgroups group))
879           (message-goto-subject)
880           (re-search-forward " *$")
881           (replace-match " (crosspost notification)" t t)
882           (gnus-deactivate-mark)
883           (when (gnus-y-or-n-p "Send this complaint? ")
884             (message-send-and-exit)))))))
885
886 (defun gnus-summary-mail-other-window ()
887   "Compose mail in other window."
888   (interactive)
889   (gnus-setup-message 'message
890     (message-mail)))
891
892 (defun gnus-mail-parse-comma-list ()
893   (let (accumulated
894         beg)
895     (skip-chars-forward " ")
896     (while (not (eobp))
897       (setq beg (point))
898       (skip-chars-forward "^,")
899       (while (zerop
900               (save-excursion
901                 (save-restriction
902                   (let ((i 0))
903                     (narrow-to-region beg (point))
904                     (goto-char beg)
905                     (logand (progn
906                               (while (search-forward "\"" nil t)
907                                 (incf i))
908                               (if (zerop i) 2 i))
909                             2)))))
910         (skip-chars-forward ",")
911         (skip-chars-forward "^,"))
912       (skip-chars-backward " ")
913       (push (buffer-substring beg (point))
914             accumulated)
915       (skip-chars-forward "^,")
916       (skip-chars-forward ", "))
917     accumulated))
918
919 (defun gnus-inews-add-to-address (group)
920   (let ((to-address (mail-fetch-field "to")))
921     (when (and to-address
922                (gnus-alive-p))
923       ;; This mail group doesn't have a `to-list', so we add one
924       ;; here.  Magic!
925       (when (gnus-y-or-n-p
926              (format "Do you want to add this as `to-list': %s " to-address))
927         (gnus-group-add-parameter group (cons 'to-list to-address))))))
928
929 (defun gnus-put-message ()
930   "Put the current message in some group and return to Gnus."
931   (interactive)
932   (let ((reply gnus-article-reply)
933         (winconf gnus-prev-winconf)
934         (group gnus-newsgroup-name))
935
936     (or (and group (not (gnus-group-read-only-p group)))
937         (setq group (read-string "Put in group: " nil
938                                  (gnus-writable-groups))))
939     (when (gnus-gethash group gnus-newsrc-hashtb)
940       (error "No such group: %s" group))
941
942     (save-excursion
943       (save-restriction
944         (widen)
945         (message-narrow-to-headers)
946         (let (gnus-deletable-headers)
947           (if (message-news-p)
948               (message-generate-headers message-required-news-headers)
949             (message-generate-headers message-required-mail-headers)))
950         (goto-char (point-max))
951         (insert "Gcc: " group "\n")
952         (widen)))
953
954     (gnus-inews-do-gcc)
955
956     (when (get-buffer gnus-group-buffer)
957       (when (gnus-buffer-exists-p (car-safe reply))
958         (set-buffer (car reply))
959         (and (cdr reply)
960              (gnus-summary-mark-article-as-replied
961               (cdr reply))))
962       (when winconf
963         (set-window-configuration winconf)))))
964
965 (defun gnus-article-mail (yank)
966   "Send a reply to the address near point.
967 If YANK is non-nil, include the original article."
968   (interactive "P")
969   (let ((address
970          (buffer-substring
971           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
972           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
973     (when address
974       (message-reply address)
975       (when yank
976         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
977
978 (defvar nntp-server-type)
979 (defun gnus-bug ()
980   "Send a bug report to the Gnus maintainers."
981   (interactive)
982   (unless (gnus-alive-p)
983     (error "Gnus has been shut down"))
984   (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
985     (unless (message-mail-user-agent)
986       (message-pop-to-buffer "*Gnus Bug*")
987       (delete-other-windows)
988       (when gnus-bug-create-help-buffer
989         (switch-to-buffer "*Gnus Help Bug*")
990         (erase-buffer)
991         (insert gnus-bug-message)
992         (goto-char (point-min))
993         (sit-for 0)
994         (set-buffer "*Gnus Bug*")))
995     (let ((message-this-is-mail t))
996       (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
997     (when gnus-bug-create-help-buffer
998       (push `(gnus-bug-kill-buffer) message-send-actions))
999     (goto-char (point-min))
1000     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1001     (forward-line 1)
1002     (insert gnus-product-name " " gnus-version-number
1003             " (r" gnus-revision-number ") "
1004             "based on " gnus-original-product-name " v"
1005             gnus-original-version-number "\n"
1006             (emacs-version) "\n")
1007     (when (and (boundp 'nntp-server-type)
1008                (stringp nntp-server-type))
1009       (insert nntp-server-type))
1010     (insert "\n\n\n\n\n")
1011     (let (mime-content-types)
1012       (mime-edit-insert-tag "text" "plain" "; type=emacs-lisp"))
1013     (insert (with-temp-buffer
1014               (gnus-debug)
1015               (buffer-string)))
1016     (let (mime-content-types)
1017       (mime-edit-insert-tag "text" "plain"))
1018     (goto-char (point-min))
1019     (search-forward "Subject: " nil t)
1020     (message "")))
1021
1022 (defun gnus-bug-kill-buffer ()
1023   (when (get-buffer "*Gnus Help Bug*")
1024     (kill-buffer "*Gnus Help Bug*")))
1025
1026 (defun gnus-summary-yank-message (buffer n)
1027   "Yank the current article into a composed message."
1028   (interactive
1029    (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1030          current-prefix-arg))
1031   (when (gnus-buffer-live-p buffer)
1032     (let ((summary-frame (selected-frame))
1033           (message-frame (when (static-if (featurep 'xemacs)
1034                                    (device-on-window-system-p)
1035                                  window-system)
1036                            (let ((window (get-buffer-window buffer t)))
1037                              (when window
1038                                (window-frame window)))))
1039           (separator (concat "^" (regexp-quote mail-header-separator)
1040                              "\n")))
1041       (gnus-summary-iterate n
1042         (gnus-summary-select-article)
1043         (gnus-copy-article-buffer)
1044         (when (frame-live-p message-frame)
1045           (raise-frame message-frame)
1046           (select-frame message-frame))
1047         (with-current-buffer buffer
1048           (when (save-excursion
1049                   (beginning-of-line)
1050                   (let (case-fold-search)
1051                     (and (not (re-search-backward separator nil t))
1052                          (re-search-forward separator nil t))))
1053             (goto-char (match-end 0)))
1054           (message-yank-buffer gnus-article-copy))
1055         (select-frame summary-frame))
1056       (when (frame-live-p message-frame)
1057         (select-frame message-frame)))))
1058
1059 (defun gnus-debug ()
1060   "Attempts to go through the Gnus source file and report what variables have been changed.
1061 The source file has to be in the Emacs load path."
1062   (interactive)
1063   (let ((files '("gnus.el" "gnus-sum.el" "gnus-group.el"
1064                  "gnus-art.el" "gnus-start.el" "gnus-async.el"
1065                  "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
1066                  "nnmail.el" "nntp.el" "message.el"))
1067         (point (point))
1068         file expr olist sym)
1069     (gnus-message 4 "Please wait while we snoop your variables...")
1070     ;; Go through all the files looking for non-default values for variables.
1071     (save-excursion
1072       (sit-for 0)
1073       (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1074       (while files
1075         (erase-buffer)
1076         (when (and (setq file (locate-library (pop files)))
1077                    (file-exists-p file))
1078           (insert-file-contents file)
1079           (goto-char (point-min))
1080           (if (not (re-search-forward "^;;* *Internal variables" nil t))
1081               (gnus-message 4 "Malformed sources in file %s" file)
1082             (narrow-to-region (point-min) (point))
1083             (goto-char (point-min))
1084             (while (setq expr (ignore-errors (read (current-buffer))))
1085               (ignore-errors
1086                 (and (memq (car expr) '(defvar defcustom defvoo))
1087                      (stringp (nth 3 expr))
1088                      (or (not (boundp (nth 1 expr)))
1089                          (not (equal (eval (nth 2 expr))
1090                                      (symbol-value (nth 1 expr)))))
1091                      (push (nth 1 expr) olist)))))))
1092       (kill-buffer (current-buffer)))
1093     (when (setq olist (nreverse olist))
1094       (insert ";----------------- Environment follows ------------------\n\n"))
1095     (while olist
1096       (if (boundp (car olist))
1097           (condition-case ()
1098               (pp `(setq ,(car olist)
1099                          ,(if (or (consp (setq sym (symbol-value (car olist))))
1100                                   (and (symbolp sym)
1101                                        (not (or (eq sym nil)
1102                                                 (eq sym t)))))
1103                               (list 'quote (symbol-value (car olist)))
1104                             (symbol-value (car olist))))
1105                   (current-buffer))
1106             (error
1107              (format "(setq %s 'whatever)\n" (car olist))))
1108         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1109       (setq olist (cdr olist)))
1110     ;; Remove any control chars - they seem to cause trouble for some
1111     ;; mailers.  (Byte-compiled output from the stuff above.)
1112     (goto-char point)
1113     (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1114       (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1115                      t t))
1116     ;; Break MIME tags purposely.
1117     (goto-char point)
1118     (while (re-search-forward mime-edit-tag-regexp nil t)
1119       (goto-char (1+ (match-beginning 0)))
1120       (insert "X"))))
1121
1122 ;;; Treatment of rejected articles.
1123 ;;; Bounced mail.
1124
1125 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1126   "Re-mail the current message.
1127 This only makes sense if the current message is a bounce message than
1128 contains some mail you have written which has been bounced back to
1129 you.
1130 If FETCH, try to fetch the article that this is a reply to, if indeed
1131 this is a reply."
1132   (interactive "P")
1133   (gnus-summary-select-article t)
1134   (set-buffer gnus-original-article-buffer)
1135   (let ((gnus-message-setup-hook '(gnus-maybe-setup-default-charset)))
1136     (gnus-setup-message 'compose-bounce
1137       (let* ((references (mail-fetch-field "references"))
1138              (parent (and references (gnus-parent-id references))))
1139         (message-bounce)
1140         ;; If there are references, we fetch the article we answered to.
1141         (and fetch parent
1142              (gnus-summary-refer-article parent)
1143              (gnus-summary-show-all-headers))))))
1144
1145 ;;; Gcc handling.
1146
1147 (defun gnus-inews-group-method (group)
1148   (cond ((and (null (gnus-get-info group))
1149               (eq (car gnus-message-archive-method)
1150                   (car
1151                    (gnus-server-to-method
1152                     (gnus-group-method group)))))
1153          ;; If the group doesn't exist, we assume
1154          ;; it's an archive group...
1155          gnus-message-archive-method)
1156         ;; Use the method.
1157         ((gnus-info-method (gnus-get-info group))
1158          (gnus-info-method (gnus-get-info group)))
1159         ;; Find the method.
1160         (t (gnus-group-method group))))
1161
1162 ;; Do Gcc handling, which copied the message over to some group.
1163 (defun gnus-inews-do-gcc (&optional gcc)
1164   (interactive)
1165   (when (gnus-alive-p)
1166     (save-excursion
1167       (save-restriction
1168         (message-narrow-to-headers)
1169         (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1170               (coding-system-for-write 'raw-text)
1171               (output-coding-system 'raw-text)
1172               groups group method group-art)
1173           (when gcc
1174             (message-remove-header "gcc")
1175             (widen)
1176             (setq groups (message-unquote-tokens
1177                           (message-tokenize-header gcc " ,")))
1178             ;; Copy the article over to some group(s).
1179             (while (setq group (pop groups))
1180               (gnus-check-server
1181                (setq method (gnus-inews-group-method group)))
1182               (unless (gnus-request-group group t method)
1183                 (gnus-request-create-group group method))
1184               (save-excursion
1185                 (nnheader-set-temp-buffer " *acc*")
1186                 (insert-buffer-substring message-encoding-buffer)
1187                 (gnus-run-hooks 'gnus-before-do-gcc-hook)
1188                 (goto-char (point-min))
1189                 (when (re-search-forward
1190                        (concat "^" (regexp-quote mail-header-separator) "$")
1191                        nil t)
1192                   (replace-match "" t t ))
1193                 (unless (setq group-art 
1194                               (gnus-request-accept-article group method t t))
1195                   (gnus-message 1 "Couldn't store article in group %s: %s"
1196                                 group (gnus-status-message method))
1197                   (sit-for 2))
1198                 (when (and group-art gnus-inews-mark-gcc-as-read)
1199                   (let ((active (gnus-active group)))
1200                     (if active
1201                         (if (< (cdr active) (cdr group-art))
1202                             (gnus-set-active group (cons (car active) 
1203                                                          (cdr group-art))))
1204                       (gnus-activate-group group)))
1205                   (let ((buffer (concat "*Summary " group "*"))
1206                         (mark gnus-read-mark)
1207                         (article (cdr group-art)))
1208                     (unless 
1209                         (and 
1210                          (get-buffer buffer)
1211                          (with-current-buffer buffer
1212                            (when gnus-newsgroup-prepared
1213                              (when (and gnus-newsgroup-auto-expire
1214                                         (memq mark gnus-auto-expirable-marks))
1215                                (setq mark gnus-expirable-mark))
1216                              (setq mark (gnus-request-update-mark 
1217                                          group article mark))
1218                              (gnus-mark-article-as-read article mark)
1219                              (setq gnus-newsgroup-active (gnus-active group))
1220                              t)))
1221                       (gnus-group-make-articles-read group 
1222                                                      (list article))
1223                       (when (gnus-group-auto-expirable-p group)
1224                         (gnus-add-marked-articles
1225                          group 'expire (list article))))))
1226                 (kill-buffer (current-buffer))))))))))
1227
1228 (defun gnus-inews-insert-gcc ()
1229   "Insert Gcc headers based on `gnus-outgoing-message-group'."
1230   (save-excursion
1231     (save-restriction
1232       (message-narrow-to-headers)
1233       (let* ((group gnus-outgoing-message-group)
1234              (gcc (cond
1235                    ((gnus-functionp group)
1236                     (funcall group))
1237                    ((or (stringp group) (list group))
1238                     group))))
1239         (when gcc
1240           (insert "Gcc: "
1241                   (if (stringp gcc) gcc
1242                     (mapconcat 'identity gcc " "))
1243                   "\n"))))))
1244
1245 (defun gnus-inews-insert-archive-gcc (&optional group)
1246   "Insert the Gcc to say where the article is to be archived."
1247   (let* ((var gnus-message-archive-group)
1248          (group (or group gnus-newsgroup-name ""))
1249          (gcc-self-val
1250           (and gnus-newsgroup-name
1251                (not (equal gnus-newsgroup-name ""))
1252                (gnus-group-find-parameter
1253                 gnus-newsgroup-name 'gcc-self)))
1254          result
1255          (groups
1256           (cond
1257            ((null gnus-message-archive-method)
1258             ;; Ignore.
1259             nil)
1260            ((stringp var)
1261             ;; Just a single group.
1262             (list var))
1263            ((null var)
1264             ;; We don't want this.
1265             nil)
1266            ((and (listp var) (stringp (car var)))
1267             ;; A list of groups.
1268             var)
1269            ((gnus-functionp var)
1270             ;; A function.
1271             (funcall var group))
1272            (t
1273             ;; An alist of regexps/functions/forms.
1274             (while (and var
1275                         (not
1276                          (setq result
1277                                (cond
1278                                 ((stringp (caar var))
1279                                  ;; Regexp.
1280                                  (when (string-match (caar var) group)
1281                                    (cdar var)))
1282                                 ((gnus-functionp (car var))
1283                                  ;; Function.
1284                                  (funcall (car var) group))
1285                                 (t
1286                                  (eval (car var)))))))
1287               (setq var (cdr var)))
1288             result)))
1289          name)
1290     (when (or groups gcc-self-val)
1291       (when (stringp groups)
1292         (setq groups (list groups)))
1293       (save-excursion
1294         (save-restriction
1295           (message-narrow-to-headers)
1296           (goto-char (point-max))
1297           (insert "Gcc: ")
1298           (if gcc-self-val
1299               ;; Use the `gcc-self' param value instead.
1300               (progn
1301                 (insert
1302                  (if (stringp gcc-self-val)
1303                      gcc-self-val
1304                    group))
1305                 (if (not (eq gcc-self-val 'none))
1306                     (insert "\n")
1307                   (progn
1308                     (beginning-of-line)
1309                     (kill-line))))
1310             ;; Use the list of groups.
1311             (while (setq name (pop groups))
1312               (insert (if (string-match ":" name)
1313                           name
1314                         (gnus-group-prefixed-name
1315                          name gnus-message-archive-method)))
1316               (when groups
1317                 (insert " ")))
1318             (insert "\n")))))))
1319
1320 ;;; Posting styles.
1321
1322 (defun gnus-configure-posting-styles ()
1323   "Configure posting styles according to `gnus-posting-styles'."
1324   (unless gnus-inhibit-posting-styles
1325     (let ((group (or gnus-newsgroup-name ""))
1326           (styles gnus-posting-styles)
1327           style match variable attribute value v results
1328           filep name address element)
1329       ;; If the group has a posting-style parameter, add it at the end with a
1330       ;; regexp matching everything, to be sure it takes precedence over all
1331       ;; the others.
1332       (when gnus-newsgroup-name
1333         (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1334           (when tmp-style
1335             (setq styles (append styles (list (cons ".*" tmp-style)))))))
1336       ;; Go through all styles and look for matches.
1337       (dolist (style styles)
1338         (setq match (pop style))
1339         (goto-char (point-min))
1340         (when (cond
1341                ((stringp match)
1342                 ;; Regexp string match on the group name.
1343                 (string-match match group))
1344                ((eq match 'header)
1345                 (let ((header (message-fetch-field (pop style))))
1346                   (and header
1347                        (string-match (pop style) header))))
1348                ((or (symbolp match)
1349                     (gnus-functionp match))
1350                 (cond
1351                  ((gnus-functionp match)
1352                   ;; Function to be called.
1353                   (funcall match))
1354                  ((boundp match)
1355                   ;; Variable to be checked.
1356                   (symbol-value match))))
1357                ((listp match)
1358                 ;; This is a form to be evaled.
1359                 (eval match)))
1360           ;; We have a match, so we set the variables.
1361           (dolist (attribute style)
1362             (setq element (pop attribute)
1363                   variable nil
1364                   filep nil)
1365             (setq value
1366                   (cond
1367                    ((eq (car attribute) ':file)
1368                     (setq filep t)
1369                     (cadr attribute))
1370                    ((eq (car attribute) :value)
1371                     (cadr attribute))
1372                    (t
1373                     (car attribute))))
1374             ;; We get the value.
1375             (setq v
1376                   (cond
1377                    ((stringp value)
1378                     value)
1379                    ((or (symbolp value)
1380                         (gnus-functionp value))
1381                     (cond ((gnus-functionp value)
1382                            (funcall value))
1383                           ((boundp value)
1384                            (symbol-value value))))
1385                    ((listp value)
1386                     (eval value))))
1387             ;; Translate obsolescent value.
1388             (when (eq element 'signature-file)
1389               (setq element 'signature
1390                     filep t))
1391             ;; Get the contents of file elems.
1392             (when (and filep v)
1393               (setq v (with-temp-buffer
1394                         (insert-file-contents v)
1395                         (buffer-string))))
1396             (setq results (delq (assoc element results) results))
1397             (push (cons element v) results))))
1398       ;; Now we have all the styles, so we insert them.
1399       (setq name (assq 'name results)
1400             address (assq 'address results))
1401       (setq results (delq name (delq address results)))
1402       (make-local-variable 'message-setup-hook)
1403       (dolist (result results)
1404         (add-hook 'message-setup-hook
1405                   (cond
1406                    ((eq 'eval (car result))
1407                     'ignore)
1408                    ((eq 'body (car result))
1409                     `(lambda ()
1410                        (save-excursion
1411                          (message-goto-body)
1412                          (insert ,(cdr result)))))
1413                    ((eq 'signature (car result))
1414                     (set (make-local-variable 'message-signature) nil)
1415                     (set (make-local-variable 'message-signature-file) nil)
1416                     (if (not (cdr result))
1417                         'ignore
1418                       `(lambda ()
1419                          (save-excursion
1420                            (let ((message-signature ,(cdr result)))
1421                              (when message-signature
1422                                (message-insert-signature)))))))
1423                    (t
1424                     (let ((header
1425                            (if (symbolp (car result))
1426                                (capitalize (symbol-name (car result)))
1427                              (car result))))
1428                       `(lambda ()
1429                          (save-excursion
1430                            (message-remove-header ,header)
1431                            (let ((value ,(cdr result)))
1432                              (when value
1433                                (message-goto-eoh)
1434                                (insert ,header ": " value "\n"))))))))))
1435       (when (or name address)
1436         (add-hook 'message-setup-hook
1437                   `(lambda ()
1438                      (set (make-local-variable 'user-mail-address)
1439                           ,(or (cdr address) user-mail-address))
1440                      (let ((user-full-name ,(or (cdr name) (user-full-name)))
1441                            (user-mail-address
1442                             ,(or (cdr address) user-mail-address)))
1443                        (save-excursion
1444                          (message-remove-header "From")
1445                          (message-goto-eoh)
1446                          (insert "From: " (message-make-from) "\n")))))))))
1447
1448
1449 ;;; @ for MIME Edit mode
1450 ;;;
1451
1452 (defun gnus-maybe-setup-default-charset ()
1453   (let ((charset
1454          (and (boundp 'gnus-summary-buffer)
1455               (buffer-live-p gnus-summary-buffer)
1456               (save-excursion
1457                 (set-buffer gnus-summary-buffer)
1458                 default-mime-charset))))
1459     (if charset
1460         (progn
1461           (make-local-variable 'default-mime-charset)
1462           (setq default-mime-charset charset)
1463           ))))
1464
1465
1466 ;;; @ for MIME view mode
1467 ;;;
1468
1469 (defun gnus-following-method (buf)
1470   (gnus-setup-message 'reply-yank
1471     (set-buffer buf)
1472     (if (message-news-p)
1473         (message-followup)
1474       (message-reply nil 'wide))
1475     (let ((message-reply-buffer buf))
1476       (message-yank-original))
1477     (message-goto-body))
1478   (kill-buffer buf))
1479
1480
1481 ;;; Allow redefinition of functions.
1482
1483 (gnus-ems-redefine)
1484
1485 (provide 'gnus-msg)
1486
1487 ;;; gnus-msg.el ends here