Synch with Oort Gnus.
[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, 2001, 2002
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' (which is the default), Gnus will use
46 the \"current\" select method when posting.  If it is `native', Gnus
47 will 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 `native' nor `current', 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   :link '(custom-manual "(gnus)Posting Server")
58   :type `(choice (const native)
59                  (const current)
60                  (sexp :tag "Methods" ,gnus-select-method)))
61
62 (defcustom 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   :group 'gnus-message
73   :type '(choice (string :tag "Group")
74                  (function)))
75
76 (defcustom gnus-mailing-list-groups nil
77   "*Regexp matching groups that are really mailing lists.
78 This is useful when you're reading a mailing list that has been
79 gatewayed to a newsgroup, and you want to followup to an article in
80 the group."
81   :group 'gnus-message
82   :type 'regexp)
83
84 (defcustom gnus-add-to-list nil
85   "*If non-nil, add a `to-list' parameter automatically."
86   :group 'gnus-message
87   :type 'boolean)
88
89 (defcustom gnus-crosspost-complaint
90   "Hi,
91
92 You posted the article below with the following Newsgroups header:
93
94 Newsgroups: %s
95
96 The %s group, at least, was an inappropriate recipient
97 of this message.  Please trim your Newsgroups header to exclude this
98 group before posting in the future.
99
100 Thank you.
101
102 "
103   "Format string to be inserted when complaining about crossposts.
104 The first %s will be replaced by the Newsgroups header;
105 the second with the current group name."
106   :group 'gnus-message
107   :type 'string)
108
109 (defcustom gnus-message-setup-hook nil
110   "Hook run after setting up a message buffer."
111   :group 'gnus-message
112   :type 'hook)
113
114 (defcustom gnus-bug-create-help-buffer t
115   "*Should we create the *Gnus Help Bug* buffer?"
116   :group 'gnus-message
117   :type 'boolean)
118
119 (defcustom gnus-posting-styles nil
120   "*Alist of styles to use when posting.
121 See Info node `(gnus)Posting Styles'."
122   :group 'gnus-message
123   :type '(repeat (cons (choice (regexp)
124                                (variable)
125                                (list (const header)
126                                      (string :tag "Header")
127                                      (regexp :tag "Regexp"))
128                                (function)
129                                (sexp))
130                        (repeat (list
131                                 (choice (const signature)
132                                         (const signature-file)
133                                         (const organization)
134                                         (const address)
135                                         (const x-face-file)
136                                         (const name)
137                                         (const body)
138                                         (symbol)
139                                         (string :tag "Header"))
140                                 (choice (string)
141                                         (function)
142                                         (variable)
143                                         (sexp)))))))
144
145 (defcustom gnus-gcc-mark-as-read nil
146   "If non-nil, automatically mark Gcc articles as read."
147   :version "21.1"
148   :group 'gnus-message
149   :type 'boolean)
150
151 (defvar gnus-inews-mark-gcc-as-read nil
152   "Obsolete variable. Use `gnus-gcc-mark-as-read' instead.")
153
154 (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
155                         'gnus-gcc-mark-as-read)
156
157 (defcustom gnus-gcc-externalize-attachments nil
158   "Should local-file attachments be included as external parts in Gcc copies?
159 If it is `all', attach files as external parts;
160 if a regexp and matches the Gcc group name, attach files as external parts;
161 If nil, attach files as normal parts."
162   :version "21.1"
163   :group 'gnus-message
164   :type '(choice (const nil :tag "None")
165                  (const all :tag "Any")
166                  (string :tag "Regexp")))
167
168 (gnus-define-group-parameter
169  posting-charset-alist
170  :type list
171  :function-document
172  "Return the permitted unencoded charsets for posting of GROUP."
173  :variable gnus-group-posting-charset-alist
174  :variable-default
175  '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
176    ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
177    (message-this-is-mail nil nil)
178    (message-this-is-news nil t))
179  :variable-document
180  "Alist of regexps and permitted unencoded charsets for posting.
181 Each element of the alist has the form (TEST HEADER BODY-LIST), where
182 TEST is either a regular expression matching the newsgroup header or a
183 variable to query,
184 HEADER is the charset which may be left unencoded in the header (nil
185 means encode all charsets),
186 BODY-LIST is a list of charsets which may be encoded using 8bit
187 content-transfer encoding in the body, or one of the special values
188 nil (always encode using quoted-printable) or t (always use 8bit).
189
190 Note that any value other than nil for HEADER infringes some RFCs, so
191 use this option with care."
192  :variable-group gnus-charset
193  :variable-type
194  '(repeat (list :tag "Permitted unencoded charsets"
195                 (choice :tag "Where"
196                         (regexp :tag "Group")
197                         (const :tag "Mail message" :value message-this-is-mail)
198                         (const :tag "News article" :value message-this-is-news))
199                 (choice :tag "Header"
200                         (const :tag "None" nil)
201                         (symbol :tag "Charset"))
202                 (choice :tag "Body"
203                         (const :tag "Any" :value t)
204                         (const :tag "None" :value nil)
205                         (repeat :tag "Charsets"
206                                 (symbol :tag "Charset")))))
207  :parameter-type '(choice :tag "Permitted unencoded charsets"
208                           :value nil
209                           (repeat (symbol)))
210  :parameter-document       "\
211 List of charsets that are permitted to be unencoded.")
212
213 (defcustom gnus-debug-files
214   '("gnus.el" "gnus-sum.el" "gnus-group.el"
215     "gnus-art.el" "gnus-start.el" "gnus-async.el"
216     "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
217     "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
218     "mm-util.el" "mm-decode.el" "nnmail.el" "nntp.el" "message.el")
219   "Files whose variables will be reported in `gnus-bug'."
220   :version "21.1"
221   :group 'gnus-message
222   :type '(repeat (string :tag "File")))
223
224 (defcustom gnus-debug-exclude-variables
225   '(mm-mime-mule-charset-alist
226     nnmail-split-fancy message-minibuffer-local-map)
227   "Variables that should not be reported in `gnus-bug'."
228   :version "21.1"
229   :group 'gnus-message
230   :type '(repeat (symbol :tag "Variable")))
231
232 (defcustom gnus-discouraged-post-methods
233   '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
234   "A list of back ends that are not used in \"real\" newsgroups.
235 This variable is used only when `gnus-post-method' is `current'."
236   :version "21.3"
237   :group 'gnus-group-foreign
238   :type '(repeat (symbol :tag "Back end")))
239
240 (defcustom gnus-message-replysign
241   nil
242   "Automatically sign replys to signed messages.
243 See also the `mml-default-sign-method' variable."
244   :group 'gnus-message
245   :type 'boolean)
246
247 (defcustom gnus-message-replyencrypt
248   nil
249   "Automatically encrypt replys to encrypted messages.
250 See also the `mml-default-encrypt-method' variable."
251   :group 'gnus-message
252   :type 'boolean)
253
254 (defcustom gnus-message-replysignencrypted
255   t
256   "Setting this causes automatically encryped messages to also be signed."
257   :group 'gnus-message
258   :type 'boolean)
259
260 (defcustom gnus-confirm-mail-reply-to-news nil
261   "If non-nil, Gnus requests confirmation when replying to news.
262 This is done because new users often reply by mistake when reading
263 news."
264   :group 'gnus-message
265   :type 'boolean)
266
267 (defcustom gnus-summary-resend-default-address t
268   "If non-nil, Gnus tries to suggest a default address to resend to.
269 If nil, the address field will always be empty after invoking
270 `gnus-summary-resend-message'."
271   :group 'gnus-message
272   :type 'boolean)
273
274 ;;; Internal variables.
275
276 (defvar gnus-inhibit-posting-styles nil
277   "Inhibit the use of posting styles.")
278
279 (defvar gnus-message-buffer "*Mail Gnus*")
280 (defvar gnus-article-copy nil)
281 (defvar gnus-check-before-posting nil)
282 (defvar gnus-last-posting-server nil)
283 (defvar gnus-message-group-art nil)
284
285 (defvar gnus-msg-force-broken-reply-to nil)
286
287 (defconst gnus-bug-message
288   (format "Sending a bug report to the Gnus Towers.
289 ========================================
290
291 This gnus is the %s%s.
292 If you think the bug is a Semi-gnus bug, send a bug report to Semi-gnus
293 Developers. (the addresses below are mailing list addresses)
294
295 ========================================
296
297 The buffer below is a mail buffer.  When you press `C-c C-c', it will
298 be sent to the Gnus Bug Exterminators.
299
300 The thing near the bottom of the buffer is how the environment
301 settings will be included in the mail.  Please do not delete that.
302 They will tell the Bug People what your environment is, so that it
303 will be easier to locate the bugs.
304
305 If you have found a bug that makes Emacs go \"beep\", set
306 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
307 and include the backtrace in your bug report.
308
309 Please describe the bug in annoying, painstaking detail.
310
311 Thank you for your help in stamping out bugs.
312 "
313           gnus-product-name
314           (if (string= gnus-product-name "Semi-gnus")
315               ""
316             ", a modified version of Semi-gnus")))
317
318 (eval-and-compile
319   (autoload 'gnus-uu-post-news "gnus-uu" nil t)
320   (autoload 'news-setup "rnewspost")
321   (autoload 'news-reply-mode "rnewspost")
322   (autoload 'rmail-dont-reply-to "mail-utils")
323   (autoload 'rmail-output "rmailout"))
324
325 \f
326 ;;;
327 ;;; Gnus Posting Functions
328 ;;;
329
330 (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
331   "p" gnus-summary-post-news
332   "i" gnus-summary-news-other-window
333   "f" gnus-summary-followup
334   "F" gnus-summary-followup-with-original
335   "c" gnus-summary-cancel-article
336   "s" gnus-summary-supersede-article
337   "r" gnus-summary-reply
338   "y" gnus-summary-yank-message
339   "R" gnus-summary-reply-with-original
340   "w" gnus-summary-wide-reply
341   "W" gnus-summary-wide-reply-with-original
342   "v" gnus-summary-very-wide-reply
343   "V" gnus-summary-very-wide-reply-with-original
344   "n" gnus-summary-followup-to-mail
345   "N" gnus-summary-followup-to-mail-with-original
346   "m" gnus-summary-mail-other-window
347   "u" gnus-uu-post-news
348   "\M-c" gnus-summary-mail-crosspost-complaint
349   "Br" gnus-summary-reply-broken-reply-to
350   "BR" gnus-summary-reply-broken-reply-to-with-original
351   "om" gnus-summary-mail-forward
352   "op" gnus-summary-post-forward
353   "Om" gnus-summary-digest-mail-forward
354   "Op" gnus-summary-digest-post-forward)
355
356 (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
357   "b" gnus-summary-resend-bounced-mail
358   ;; "c" gnus-summary-send-draft
359   "r" gnus-summary-resend-message
360   "e" gnus-summary-resend-message-edit)
361
362 ;;; Internal functions.
363
364 (defvar gnus-article-reply nil)
365 (defmacro gnus-setup-message (config &rest forms)
366   (let ((winconf (make-symbol "gnus-setup-message-winconf"))
367         (buffer (make-symbol "gnus-setup-message-buffer"))
368         (article (make-symbol "gnus-setup-message-article"))
369         (group (make-symbol "gnus-setup-message-group")))
370     `(let ((,winconf (current-window-configuration))
371            (,buffer (buffer-name (current-buffer)))
372            (,article gnus-article-reply)
373            (,group gnus-newsgroup-name)
374            (message-header-setup-hook
375             (copy-sequence message-header-setup-hook))
376            (message-mode-hook (copy-sequence message-mode-hook))
377            (message-startup-parameter-alist
378             '((reply-buffer . gnus-copy-article-buffer)
379               (original-buffer . gnus-original-article-buffer)
380               (user-agent . Gnus))))
381        (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
382        (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc)
383        ;; #### FIXME: for a reason that I did not manage to identify yet,
384        ;; the variable `gnus-newsgroup-name' does not honor a dynamically
385        ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
386        ;; After evaluation of @forms below, it gets the value we actually want
387        ;; to override, and the posting styles are used. For that reason, I've
388        ;; added an optional argument to `gnus-configure-posting-styles' to
389        ;; make sure that the correct value for the group name is used. -- drv
390        (add-hook 'message-mode-hook
391                  (lambda ()
392                    (gnus-configure-posting-styles ,group)))
393        (unwind-protect
394            (progn
395              ,@forms)
396          (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config)
397          (gnus-inews-insert-draft-meta-information ,group ,article)
398          (setq gnus-message-buffer (current-buffer))
399          (set (make-local-variable 'gnus-message-group-art)
400               (cons ,group ,article))
401          (set (make-local-variable 'gnus-newsgroup-name) ,group)
402          (gnus-maybe-setup-default-charset)
403          (gnus-run-hooks 'gnus-message-setup-hook))
404        (gnus-add-buffer)
405        (gnus-configure-windows ,config t)
406        (run-hooks 'post-command-hook)
407        (set-buffer-modified-p nil))))
408
409 (defun gnus-inews-insert-draft-meta-information (group article)
410   (save-excursion
411     (when (and group
412                (not (string= group ""))
413                (not (message-fetch-field gnus-draft-meta-information-header)))
414       (goto-char (point-min))
415       (insert gnus-draft-meta-information-header ": (\"" group "\" "
416               (if article (number-to-string
417                            (if (listp article)
418                                (car article)
419                              article)) "\"\"")
420               ")\n"))))
421
422 ;;;###autoload
423 (defun gnus-msg-mail (&optional to subject other-headers continue
424                                 switch-action yank-action send-actions)
425   "Start editing a mail message to be sent.
426 Like `message-mail', but with Gnus paraphernalia, particularly the
427 Gcc: header for archiving purposes."
428   (interactive)
429   (let ((buf (current-buffer))
430         mail-buf)
431     (gnus-setup-message 'message
432       (message-mail to subject other-headers continue
433                     nil yank-action send-actions))
434     (when switch-action
435       (setq mail-buf (current-buffer))
436       (switch-to-buffer buf)
437       (apply switch-action mail-buf nil)))
438   ;; COMPOSEFUNC should return t if succeed.  Undocumented ???
439   t)
440
441 (defvar save-selected-window-window)
442
443 ;;;###autoload
444 (defun gnus-button-mailto (address)
445   "Mail to ADDRESS."
446   (set-buffer (gnus-copy-article-buffer))
447   (gnus-setup-message 'message
448     (message-reply address))
449   (and (boundp 'save-selected-window-window)
450        (not (window-live-p save-selected-window-window))
451        (setq save-selected-window-window (selected-window))))
452
453 ;;;###autoload
454 (defun gnus-button-reply (&optional to-address wide)
455   "Like `message-reply'."
456   (interactive)
457   (gnus-setup-message 'message
458     (message-reply to-address wide))
459   (and (boundp 'save-selected-window-window)
460        (not (window-live-p save-selected-window-window))
461        (setq save-selected-window-window (selected-window))))
462
463 ;;;###autoload
464 (define-mail-user-agent 'gnus-user-agent
465   'gnus-msg-mail 'message-send-and-exit
466   'message-kill-buffer 'message-send-hook)
467
468 (defun gnus-setup-posting-charset (group)
469   (let ((alist gnus-group-posting-charset-alist)
470         (group (or group ""))
471         elem)
472     (when group
473       (catch 'found
474         (while (setq elem (pop alist))
475           (when (or (and (stringp (car elem))
476                          (string-match (car elem) group))
477                     (and (gnus-functionp (car elem))
478                          (funcall (car elem) group))
479                     (and (symbolp (car elem))
480                          (symbol-value (car elem))))
481             (throw 'found (cons (cadr elem) (caddr elem)))))))))
482
483 (defun gnus-inews-add-send-actions (winconf buffer article &optional config)
484   (make-local-hook 'message-sent-hook)
485   (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
486                                  'gnus-inews-do-gcc) nil t)
487   (when gnus-agent
488     (make-local-hook 'message-header-hook)
489     (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
490   (setq message-post-method
491         `(lambda (arg)
492            (gnus-post-method arg ,gnus-newsgroup-name)))
493   (setq message-user-agent (gnus-extended-version))
494   (when (not message-use-multi-frames)
495     (message-add-action
496      `(set-window-configuration ,winconf) 'exit 'postpone 'kill))
497   (message-add-action
498    `(when (gnus-buffer-exists-p ,buffer)
499       (save-excursion
500         (set-buffer ,buffer)
501         ,(when article
502            (if (eq config 'forward)
503                `(gnus-summary-mark-article-as-forwarded ',article)
504              `(gnus-summary-mark-article-as-replied ',article)))))
505    'send))
506
507 (put 'gnus-setup-message 'lisp-indent-function 1)
508 (put 'gnus-setup-message 'edebug-form-spec '(form body))
509
510 ;;; Post news commands of Gnus group mode and summary mode
511
512 (defun gnus-group-mail (&optional arg)
513   "Start composing a mail.
514 If ARG, use the group under the point to find a posting style.
515 If ARG is 1, prompt for a group name to find the posting style."
516   (interactive "P")
517   ;; We can't `let' gnus-newsgroup-name here, since that leads
518   ;; to local variables leaking.
519   (let ((group gnus-newsgroup-name)
520         ;; make sure last viewed article doesn't affect posting styles:
521         (gnus-article-copy)
522         (buffer (current-buffer)))
523     (unwind-protect
524         (progn
525           (setq gnus-newsgroup-name
526                 (if arg
527                     (if (= 1 (prefix-numeric-value arg))
528                         (completing-read "Use posting style of group: "
529                                          gnus-active-hashtb nil
530                                          (gnus-read-active-file-p))
531                       (gnus-group-group-name))
532                   ""))
533           ;; #### see comment in gnus-setup-message -- drv
534           (gnus-setup-message 'message (message-mail)))
535       (save-excursion
536         (set-buffer buffer)
537         (setq gnus-newsgroup-name group)))))
538
539 (defun gnus-group-news (&optional arg)
540   "Start composing a news.
541 If ARG, post to group under point.
542 If ARG is 1, prompt for group name to post to.
543
544 This function prepares a news even when using mail groups.  This is useful
545 for posting messages to mail groups without actually sending them over the
546 network.  The corresponding backend must have a 'request-post method."
547   (interactive "P")
548   ;; We can't `let' gnus-newsgroup-name here, since that leads
549   ;; to local variables leaking.
550   (let ((group gnus-newsgroup-name)
551         ;; make sure last viewed article doesn't affect posting styles:
552         (gnus-article-copy)
553         (buffer (current-buffer)))
554     (unwind-protect
555         (progn
556           (setq gnus-newsgroup-name
557                 (if arg
558                     (if (= 1 (prefix-numeric-value arg))
559                         (completing-read "Use group: "
560                                          gnus-active-hashtb nil
561                                          (gnus-read-active-file-p))
562                       (gnus-group-group-name))
563                   ""))
564           ;; #### see comment in gnus-setup-message -- drv
565           (gnus-setup-message 'message
566             (message-news (gnus-group-real-name gnus-newsgroup-name))))
567       (save-excursion
568         (set-buffer buffer)
569         (setq gnus-newsgroup-name group)))))
570
571 (defun gnus-group-post-news (&optional arg)
572   "Start composing a message (a news by default).
573 If ARG, post to group under point.  If ARG is 1, prompt for group name.
574 Depending on the selected group, the message might be either a mail or
575 a news."
576   (interactive "P")
577   ;; Bind this variable here to make message mode hooks work ok.
578   (let ((gnus-newsgroup-name
579          (if arg
580              (if (= 1 (prefix-numeric-value arg))
581                  (completing-read "Newsgroup: " gnus-active-hashtb nil
582                                   (gnus-read-active-file-p))
583                (gnus-group-group-name))
584            ""))
585         ;; make sure last viewed article doesn't affect posting styles:
586         (gnus-article-copy))
587     (gnus-post-news 'post gnus-newsgroup-name)))
588
589 (defun gnus-summary-mail-other-window (&optional arg)
590   "Start composing a mail in another window.
591 Use the posting of the current group by default.
592 If ARG, don't do that.  If ARG is 1, prompt for group name to find the
593 posting style."
594   (interactive "P")
595   ;; We can't `let' gnus-newsgroup-name here, since that leads
596   ;; to local variables leaking.
597   (let ((group gnus-newsgroup-name)
598         ;; make sure last viewed article doesn't affect posting styles:
599         (gnus-article-copy)
600         (buffer (current-buffer)))
601     (unwind-protect
602         (progn
603           (setq gnus-newsgroup-name
604                 (if arg
605                     (if (= 1 (prefix-numeric-value arg))
606                         (completing-read "Use group: "
607                                          gnus-active-hashtb nil
608                                          (gnus-read-active-file-p))
609                       "")
610                   gnus-newsgroup-name))
611           ;; #### see comment in gnus-setup-message -- drv
612           (gnus-setup-message 'message (message-mail)))
613       (save-excursion
614         (set-buffer buffer)
615         (setq gnus-newsgroup-name group)))))
616
617 (defun gnus-summary-news-other-window (&optional arg)
618   "Start composing a news in another window.
619 Post to the current group by default.
620 If ARG, don't do that.  If ARG is 1, prompt for group name to post to.
621
622 This function prepares a news even when using mail groups.  This is useful
623 for posting messages to mail groups without actually sending them over the
624 network.  The corresponding backend must have a 'request-post method."
625   (interactive "P")
626   ;; We can't `let' gnus-newsgroup-name here, since that leads
627   ;; to local variables leaking.
628   (let ((group gnus-newsgroup-name)
629         ;; make sure last viewed article doesn't affect posting styles:
630         (gnus-article-copy)
631         (buffer (current-buffer)))
632     (unwind-protect
633         (progn
634           (setq gnus-newsgroup-name
635                 (if arg
636                     (if (= 1 (prefix-numeric-value arg))
637                         (completing-read "Use group: "
638                                          gnus-active-hashtb nil
639                                          (gnus-read-active-file-p))
640                       "")
641                   gnus-newsgroup-name))
642           ;; #### see comment in gnus-setup-message -- drv
643           (gnus-setup-message 'message
644             (message-news (gnus-group-real-name gnus-newsgroup-name))))
645       (save-excursion
646         (set-buffer buffer)
647         (setq gnus-newsgroup-name group)))))
648
649 (defun gnus-summary-post-news (&optional arg)
650   "Start composing a message.  Post to the current group by default.
651 If ARG, don't do that.  If ARG is 1, prompt for a group name to post to.
652 Depending on the selected group, the message might be either a mail or
653 a news."
654   (interactive "P")
655   ;; Bind this variable here to make message mode hooks work ok.
656   (let ((gnus-newsgroup-name
657          (if arg
658              (if (= 1 (prefix-numeric-value arg))
659                  (completing-read "Newsgroup: " gnus-active-hashtb nil
660                                   (gnus-read-active-file-p))
661                "")
662            gnus-newsgroup-name))
663         ;; make sure last viewed article doesn't affect posting styles:
664         (gnus-article-copy))
665     (gnus-post-news 'post gnus-newsgroup-name)))
666
667
668 (defun gnus-summary-followup (yank &optional force-news)
669   "Compose a followup to an article.
670 If prefix argument YANK is non-nil, the original article is yanked
671 automatically.
672 YANK is a list of elements, where the car of each element is the
673 article number, and the two following numbers is the region to be
674 yanked."
675   (interactive
676    (list (and current-prefix-arg
677               (gnus-summary-work-articles 1))))
678   (when yank
679     (gnus-summary-goto-subject
680      (if (listp (car yank))
681          (caar yank)
682        (car yank))))
683   (save-window-excursion
684     (gnus-summary-select-article))
685   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
686         (gnus-newsgroup-name gnus-newsgroup-name))
687     ;; Send a followup.
688     (gnus-post-news nil gnus-newsgroup-name
689                     headers gnus-article-buffer
690                     yank nil force-news)
691     (gnus-summary-handle-replysign)))
692
693 (defun gnus-summary-followup-with-original (n &optional force-news)
694   "Compose a followup to an article and include the original article."
695   (interactive "P")
696   (gnus-summary-followup (gnus-summary-work-articles n) force-news))
697
698 (defun gnus-summary-followup-to-mail (&optional arg)
699   "Followup to the current mail message via news."
700   (interactive
701    (list (and current-prefix-arg
702               (gnus-summary-work-articles 1))))
703   (gnus-summary-followup arg t))
704
705 (defun gnus-summary-followup-to-mail-with-original (&optional arg)
706   "Followup to the current mail message via news."
707   (interactive "P")
708   (gnus-summary-followup (gnus-summary-work-articles arg) t))
709
710 (defun gnus-inews-yank-articles (articles)
711   (let (beg article yank-string
712             (more-than-one (cdr articles))
713             (cur (current-buffer))
714             refs window)
715     (message-goto-body)
716     (while (setq article (pop articles))
717       (when (listp article)
718         (setq yank-string (nth 1 article)
719               article (nth 0 article)))
720       (save-window-excursion
721         (set-buffer gnus-summary-buffer)
722         (gnus-summary-select-article nil nil nil article)
723         (gnus-summary-remove-process-mark article))
724
725       ;; Gathering references.
726       (when more-than-one
727         (setq refs (message-list-references
728                     refs
729                     (mail-header-references gnus-current-headers)
730                     (mail-header-message-id gnus-current-headers)))
731         (when message-use-multi-frames
732           (when (setq window (get-buffer-window cur t))
733             (select-frame (window-frame window)))))
734
735       (gnus-copy-article-buffer nil yank-string)
736       (let ((message-reply-buffer gnus-article-copy)
737             (message-reply-headers
738              ;; The headers are decoded.
739              (with-current-buffer gnus-article-copy
740                (save-restriction
741                  (nnheader-narrow-to-headers)
742                  (ietf-drums-unfold-fws)
743                  (nnheader-parse-head t)))))
744         (message-yank-original)
745         (setq beg (or beg (mark t))))
746       (when articles
747         (insert "\n")))
748     (push-mark)
749
750     ;; Replace with the gathered references.
751     (when refs
752       (push-mark beg)
753       (save-restriction
754         (message-narrow-to-headers)
755         (let ((case-fold-search t))
756           (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
757               (replace-match "")
758             (goto-char (point-max))))
759         (mail-header-format
760          (list (or (assq 'References message-header-format-alist)
761                    '(References . message-shorten-references)))
762          (list (cons 'References
763                      (mapconcat 'identity (nreverse refs) " "))))
764         (backward-delete-char 1))
765       (setq beg (mark t))
766       (pop-mark))
767
768     (goto-char beg)))
769
770 (defun gnus-summary-cancel-article (&optional n symp)
771   "Cancel an article you posted.
772 Uses the process-prefix convention.  If given the symbolic
773 prefix `a', cancel using the standard posting method; if not
774 post using the current select method."
775   (interactive (gnus-interactive "P\ny"))
776   (let ((articles (gnus-summary-work-articles n))
777         (message-post-method
778          `(lambda (arg)
779             (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name)))
780         article)
781     (while (setq article (pop articles))
782       (when (gnus-summary-select-article t nil nil article)
783         (when (gnus-eval-in-buffer-window gnus-article-buffer
784                 (save-excursion
785                   (set-buffer gnus-original-article-buffer)
786                   (message-cancel-news)))
787           (gnus-summary-mark-as-read article gnus-canceled-mark)
788           (gnus-cache-remove-article 1))
789         (gnus-article-hide-headers-if-wanted))
790       (gnus-summary-remove-process-mark article))))
791
792 (defun gnus-summary-supersede-article ()
793   "Compose an article that will supersede a previous article.
794 This is done simply by taking the old article and adding a Supersedes
795 header line with the old Message-ID."
796   (interactive)
797   (let ((article (gnus-summary-article-number)))
798     (gnus-setup-message 'reply-yank
799       (gnus-summary-select-article t)
800       (set-buffer gnus-original-article-buffer)
801       (message-supersede)
802       (push
803        `((lambda ()
804            (when (gnus-buffer-exists-p ,gnus-summary-buffer)
805              (save-excursion
806                (set-buffer ,gnus-summary-buffer)
807                (gnus-cache-possibly-remove-article ,article nil nil nil t)
808                (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
809        message-send-actions))))
810
811 \f
812
813 (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
814   ;; make a copy of the article buffer with all text properties removed
815   ;; this copy is in the buffer gnus-article-copy.
816   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
817   ;; this buffer should be passed to all mail/news reply/post routines.
818   (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
819   (let ((article-buffer (or article-buffer gnus-article-buffer))
820         end beg)
821     (if (not (and (get-buffer article-buffer)
822                   (gnus-buffer-exists-p article-buffer)))
823         (error "Can't find any article buffer")
824       (save-excursion
825         (set-buffer article-buffer)
826         (let ((gnus-newsgroup-charset (or gnus-article-charset
827                                           gnus-newsgroup-charset))
828               (gnus-newsgroup-ignored-charsets
829                (or gnus-article-ignored-charsets
830                    gnus-newsgroup-ignored-charsets)))
831           (save-restriction
832             ;; Copy over the (displayed) article buffer, delete
833             ;; hidden text and remove text properties.
834             (widen)
835             (let ((inhibit-read-only t))
836               (copy-to-buffer gnus-article-copy (point-min) (point-max))
837               (set-buffer gnus-article-copy)
838               (when yank-string
839                 (message-goto-body)
840                 (delete-region (point) (point-max))
841                 (insert yank-string))
842               ;; Encode bitmap smileys to ordinary text.
843               ;; Possibly, the original text might be restored.
844               (static-unless (featurep 'xemacs)
845                 (when (featurep 'smiley-mule)
846                   (smiley-encode-buffer)))
847               (gnus-article-delete-text-of-type 'annotation)
848               (gnus-remove-text-with-property 'gnus-prev)
849               (gnus-remove-text-with-property 'gnus-next)
850               (gnus-remove-text-with-property 'gnus-decoration)
851               (gnus-remove-text-with-property 'x-face-mule-bitmap-image)
852               (insert
853                (prog1
854                    (static-if (featurep 'xemacs)
855                        ;; Revome smiley extents for (possibly) XEmacs 21.1.
856                        (format "%s"
857                                (buffer-substring-no-properties (point-min)
858                                                                (point-max)))
859                      (buffer-substring-no-properties (point-min) (point-max)))
860                  (erase-buffer))))
861             ;; Find the original headers.
862             (set-buffer gnus-original-article-buffer)
863             (goto-char (point-min))
864             (while (looking-at message-unix-mail-delimiter)
865               (forward-line 1))
866             (setq beg (point)
867                   end (or (message-goto-body) beg))
868             ;; Delete the headers from the displayed articles.
869             (set-buffer gnus-article-copy)
870             (delete-region (goto-char (point-min))
871                            (or (message-goto-body) (point-max)))
872             ;; Insert the original article headers.
873             (insert-buffer-substring gnus-original-article-buffer beg end)
874             ;; Decode charsets.
875             (let ((gnus-article-decode-hook
876                    (delq 'article-decode-charset
877                          (copy-sequence gnus-article-decode-hook))))
878               ;; Needed for T-gnus.
879               (add-hook 'gnus-article-decode-hook
880                         'article-decode-encoded-words)
881               (run-hooks 'gnus-article-decode-hook)))))
882       gnus-article-copy)))
883
884 (defun gnus-post-news (post &optional group header article-buffer yank subject
885                             force-news)
886   (when article-buffer
887     (gnus-copy-article-buffer))
888   (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
889         (add-to-list gnus-add-to-list))
890     (gnus-setup-message (cond (yank 'reply-yank)
891                               (article-buffer 'reply)
892                               (t 'message))
893       (let* ((group (or group gnus-newsgroup-name))
894              (charset (gnus-group-name-charset nil group))
895              (pgroup group)
896              to-address to-group mailing-list to-list
897              newsgroup-p)
898         (when group
899           (setq to-address (gnus-parameter-to-address group)
900                 to-group (gnus-group-find-parameter group 'to-group)
901                 to-list (gnus-parameter-to-list group)
902                 newsgroup-p (gnus-group-find-parameter group 'newsgroup)
903                 mailing-list (when gnus-mailing-list-groups
904                                (string-match gnus-mailing-list-groups group))
905                 group (gnus-group-name-decode (gnus-group-real-name group)
906                                               charset)))
907         (if (or (and to-group
908                      (gnus-news-group-p to-group))
909                 newsgroup-p
910                 force-news
911                 (and (gnus-news-group-p
912                       (or pgroup gnus-newsgroup-name)
913                       (or header gnus-current-article))
914                      (not mailing-list)
915                      (not to-list)
916                      (not to-address)))
917             ;; This is news.
918             (if post
919                 (message-news (or to-group group))
920               (set-buffer gnus-article-copy)
921               (gnus-msg-treat-broken-reply-to)
922               (message-followup (if (or newsgroup-p force-news)
923                                     (if (save-restriction
924                                           (article-narrow-to-head)
925                                           (message-fetch-field "newsgroups"))
926                                         nil
927                                       "")
928                                   to-group)))
929           ;; The is mail.
930           (if post
931               (progn
932                 (message-mail (or to-address to-list))
933                 ;; Arrange for mail groups that have no `to-address' to
934                 ;; get that when the user sends off the mail.
935                 (when (and (not to-list)
936                            (not to-address)
937                            add-to-list)
938                   (push (list 'gnus-inews-add-to-address pgroup)
939                         message-send-actions)))
940             (set-buffer gnus-article-copy)
941             (gnus-msg-treat-broken-reply-to)
942             (message-wide-reply to-address)))
943         (when yank
944           (gnus-inews-yank-articles yank))))))
945
946 (defun gnus-msg-treat-broken-reply-to (&optional force)
947   "Remove the Reply-to header iff broken-reply-to."
948   (when (or force
949             (gnus-group-find-parameter
950              gnus-newsgroup-name 'broken-reply-to))
951     (save-restriction
952       (message-narrow-to-head)
953       (message-remove-header "reply-to"))))
954
955 (defun gnus-post-method (arg group &optional silent)
956   "Return the posting method based on GROUP and ARG.
957 If SILENT, don't prompt the user."
958   (let ((gnus-post-method (or (gnus-parameter-post-method group)
959                               gnus-post-method))
960         (group-method (gnus-find-method-for-group group)))
961     (cond
962      ;; If the group-method is nil (which shouldn't happen) we use
963      ;; the default method.
964      ((null group-method)
965       (or (and (listp gnus-post-method) ;If not current/native/nil
966                (not (listp (car gnus-post-method))) ; and not a list of methods
967                gnus-post-method)        ;then use it.
968           gnus-select-method
969           message-post-method))
970      ;; We want the inverse of the default
971      ((and arg (not (eq arg 0)))
972       (if (eq gnus-post-method 'current)
973           gnus-select-method
974         group-method))
975      ;; We query the user for a post method.
976      ((or arg
977           (and (listp gnus-post-method)
978                (listp (car gnus-post-method))))
979       (let* ((methods
980               ;; Collect all methods we know about.
981               (append
982                (when (listp gnus-post-method)
983                  (if (listp (car gnus-post-method))
984                      gnus-post-method
985                    (list gnus-post-method)))
986                gnus-secondary-select-methods
987                (mapcar 'cdr gnus-server-alist)
988                (mapcar 'car gnus-opened-servers)
989                (list gnus-select-method)
990                (list group-method)))
991              method-alist post-methods method)
992         ;; Weed out all mail methods.
993         (while methods
994           (setq method (gnus-server-get-method "" (pop methods)))
995           (when (and (or (gnus-method-option-p method 'post)
996                          (gnus-method-option-p method 'post-mail))
997                      (not (member method post-methods)))
998             (push method post-methods)))
999         ;; Create a name-method alist.
1000         (setq method-alist
1001               (mapcar
1002                (lambda (m)
1003                  (if (equal (cadr m) "")
1004                      (list (symbol-name (car m)) m)
1005                    (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
1006                post-methods))
1007         ;; Query the user.
1008         (cadr
1009          (assoc
1010           (setq gnus-last-posting-server
1011                 (if (and silent
1012                          gnus-last-posting-server)
1013                     ;; Just use the last value.
1014                     gnus-last-posting-server
1015                   (completing-read
1016                    "Posting method: " method-alist nil t
1017                    (cons (or gnus-last-posting-server "") 0))))
1018           method-alist))))
1019      ;; Override normal method.
1020      ((and (eq gnus-post-method 'current)
1021            (not (memq (car group-method) gnus-discouraged-post-methods))
1022            (gnus-get-function group-method 'request-post t))
1023       (assert (not arg))
1024       group-method)
1025      ;; Use gnus-post-method.
1026      ((listp gnus-post-method)          ;A method...
1027       (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
1028       gnus-post-method)
1029      ;; Use the normal select method (nil or native).
1030      (t gnus-select-method))))
1031
1032 \f
1033 (defun gnus-message-make-user-agent (&optional include-mime-info max-column
1034                                                  newline-product)
1035   "Return a user-agent info.  If INCLUDE-MIME-INFO is non-nil and the
1036 variable `mime-edit-user-agent-value' is bound, the value will be
1037 included in the return value.  If MAX-COLUMN is specified, the return
1038 value will be folded up as it were filled.  NEWLINE-PRODUCT specifies
1039 whether a newline should be inserted in front of each product-token.
1040 If the value is t or `hard', it works strictly.  Otherwise, if it is
1041 non-nil (e.g. `soft'), it works semi-strictly.
1042
1043 Here is an example of how to use this function:
1044
1045 \(add-hook 'gnus-message-setup-hook
1046           (lambda nil
1047             (setq message-user-agent nil)
1048             (save-excursion
1049               (save-restriction
1050                 (message-narrow-to-headers)
1051                 (goto-char (point-max))
1052                 (insert \"User-Agent: \"
1053                         (gnus-message-make-user-agent t 76 'soft)
1054                         \"\\n\")))))
1055 "
1056   (let ((user-agent (if (and include-mime-info
1057                              (boundp 'mime-edit-user-agent-value))
1058                         (concat (gnus-extended-version)
1059                                 " "
1060                                 mime-edit-user-agent-value)
1061                       (gnus-extended-version))))
1062     (when max-column
1063       (unless (natnump max-column)
1064         (setq max-column 76))
1065       (with-temp-buffer
1066         (set-buffer-multibyte t)
1067         (insert (mapconcat 'identity (split-string user-agent) " "))
1068         (goto-char (point-min))
1069         (let ((bol t)
1070               start agent agents width element swidth)
1071           (while (re-search-forward "\\([^ ]+\\) ?" nil t)
1072             (setq start (match-beginning 0))
1073             (if (eq (char-after start) ?\()
1074                 (progn
1075                   (goto-char start)
1076                   (forward-list)
1077                   (push (buffer-substring start (point)) agent))
1078               (when agent
1079                 (push (nreverse agent) agents))
1080               (setq agent (list (match-string 1)))))
1081           (when agent
1082             (push (nreverse agent) agents))
1083           (setq agents (nreverse agents))
1084           (if (> (+ 12 (string-width (caar agents))) max-column)
1085               (setq user-agent "\n"
1086                     width 0)
1087             (setq user-agent ""
1088                   width 11))
1089           (while agents
1090             (setq agent (car agents)
1091                   agents (cdr agents))
1092             (when (and (not bol)
1093                        (or (memq newline-product '(t hard))
1094                            (and newline-product
1095                                 (> (+ width 1
1096                                       (string-width (mapconcat 'identity
1097                                                                agent " ")))
1098                                    max-column))))
1099               (setq user-agent (concat user-agent "\n")
1100                     width 0
1101                     bol t))
1102             (while agent
1103               (setq element (car agent)
1104                     swidth (string-width element)
1105                     agent (cdr agent))
1106               (if bol
1107                   (setq user-agent (if (member user-agent '("" "\n"))
1108                                        (concat user-agent element)
1109                                      (concat user-agent " " element))
1110                         width (+ width 1 swidth)
1111                         bol nil)
1112                 (if (> (+ width 1 swidth) max-column)
1113                     (setq user-agent (concat user-agent "\n " element)
1114                           width (1+ swidth))
1115                   (setq user-agent (concat user-agent " " element)
1116                         width (+ width 1 swidth)))))))))
1117     user-agent))
1118
1119 \f
1120 ;;;
1121 ;;; Gnus Mail Functions
1122 ;;;
1123
1124 ;;; Mail reply commands of Gnus summary mode
1125
1126 (defun gnus-summary-reply (&optional yank wide very-wide)
1127   "Start composing a mail reply to the current message.
1128 If prefix argument YANK is non-nil, the original article is yanked
1129 automatically.
1130 If WIDE, make a wide reply.
1131 If VERY-WIDE, make a very wide reply."
1132   (interactive
1133    (list (and current-prefix-arg
1134               (gnus-summary-work-articles 1))))
1135   ;; Allow user to require confirmation before replying by mail to the
1136   ;; author of a news article.
1137   (when (or (not (gnus-news-group-p gnus-newsgroup-name))
1138             (not gnus-confirm-mail-reply-to-news)
1139             (y-or-n-p "Really reply by mail to article author? "))
1140     (let* ((article
1141             (if (listp (car yank))
1142                 (caar yank)
1143               (car yank)))
1144            (gnus-article-reply (or article (gnus-summary-article-number)))
1145            (headers ""))
1146       ;; Stripping headers should be specified with mail-yank-ignored-headers.
1147       (when yank
1148         (gnus-summary-goto-subject article))
1149       (gnus-setup-message (if yank 'reply-yank 'reply)
1150         (if (not very-wide)
1151             (gnus-summary-select-article)
1152           (dolist (article very-wide)
1153             (gnus-summary-select-article nil nil nil article)
1154             (save-excursion
1155               (set-buffer (gnus-copy-article-buffer))
1156               (gnus-msg-treat-broken-reply-to)
1157               (save-restriction
1158                 (message-narrow-to-head)
1159                 (setq headers (concat headers (buffer-string)))))))
1160         (set-buffer (gnus-copy-article-buffer))
1161         (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
1162         (save-restriction
1163           (message-narrow-to-head)
1164           (when very-wide
1165             (erase-buffer)
1166             (insert headers))
1167           (goto-char (point-max)))
1168         (message-reply nil wide)
1169         (when yank
1170           (gnus-inews-yank-articles yank))
1171         (gnus-summary-handle-replysign)))))
1172
1173 (defun gnus-summary-handle-replysign ()
1174   "Check the various replysign variables and take action accordingly."
1175   (when nil;;(or gnus-message-replysign gnus-message-replyencrypt)
1176     (let (signed encrypted)
1177       (save-excursion
1178         (set-buffer gnus-article-buffer)
1179         (setq signed (memq 'signed gnus-article-wash-types))
1180         (setq encrypted (memq 'encrypted gnus-article-wash-types)))
1181       (cond ((and gnus-message-replyencrypt encrypted)
1182              (mml-secure-message mml-default-encrypt-method
1183                                  (if gnus-message-replysignencrypted
1184                                      'signencrypt
1185                                    'encrypt)))
1186             ((and gnus-message-replysign signed)
1187              (mml-secure-message mml-default-sign-method 'sign))))))
1188
1189 (defun gnus-summary-reply-with-original (n &optional wide)
1190   "Start composing a reply mail to the current message.
1191 The original article will be yanked."
1192   (interactive "P")
1193   (gnus-summary-reply (gnus-summary-work-articles n) wide))
1194
1195 (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
1196   "Like `gnus-summary-reply' except removing reply-to field.
1197 If prefix argument YANK is non-nil, the original article is yanked
1198 automatically.
1199 If WIDE, make a wide reply.
1200 If VERY-WIDE, make a very wide reply."
1201   (interactive
1202    (list (and current-prefix-arg
1203               (gnus-summary-work-articles 1))))
1204   (let ((gnus-msg-force-broken-reply-to t))
1205     (gnus-summary-reply yank wide very-wide)))
1206
1207 (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
1208   "Like `gnus-summary-reply-with-original' except removing reply-to field.
1209 The original article will be yanked."
1210   (interactive "P")
1211   (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
1212
1213 (defun gnus-summary-wide-reply (&optional yank)
1214   "Start composing a wide reply mail to the current message.
1215 If prefix argument YANK is non-nil, the original article is yanked
1216 automatically."
1217   (interactive
1218    (list (and current-prefix-arg
1219               (gnus-summary-work-articles 1))))
1220   (gnus-summary-reply yank t))
1221
1222 (defun gnus-summary-wide-reply-with-original (n)
1223   "Start composing a wide reply mail to the current message.
1224 The original article will be yanked."
1225   (interactive "P")
1226   (gnus-summary-reply-with-original n t))
1227
1228 (defun gnus-summary-very-wide-reply (&optional yank)
1229   "Start composing a very wide reply mail to the current message.
1230 If prefix argument YANK is non-nil, the original article is yanked
1231 automatically."
1232   (interactive
1233    (list (and current-prefix-arg
1234               (gnus-summary-work-articles 1))))
1235   (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
1236
1237 (defun gnus-summary-very-wide-reply-with-original (n)
1238   "Start composing a very wide reply mail to the current message.
1239 The original article will be yanked."
1240   (interactive "P")
1241   (gnus-summary-reply
1242    (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
1243
1244 (defun gnus-summary-mail-forward (&optional full-headers post)
1245   "Forward the current message(s) to another user.
1246 If process marks exist, forward all marked messages;
1247 If FULL-HEADERS (the prefix), include full headers when forwarding.
1248
1249 Note that this function definition for T-gnus is totally different
1250 from the original Gnus."
1251   (interactive "P")
1252   (if (null (cdr (gnus-summary-work-articles nil)))
1253       (gnus-setup-message 'forward
1254         (gnus-summary-select-article)
1255         (let ((charset default-mime-charset))
1256           (set-buffer gnus-original-article-buffer)
1257           (make-local-variable 'default-mime-charset)
1258           (setq default-mime-charset charset))
1259         (let ((message-included-forward-headers
1260                (if full-headers "" message-included-forward-headers)))
1261           (message-forward post)))
1262     (gnus-summary-digest-mail-forward nil post)))
1263
1264 (defun gnus-summary-digest-mail-forward (&optional n post)
1265   "Digests and forwards all articles in this series.
1266 If N is a positive number, forward the N next articles.
1267 If N is a negative number, forward the N previous articles.
1268 If N is nil and any articles have been marked with the process mark,
1269 forward those articles instead.
1270 Optional POST will use news to forward instead of mail."
1271   (interactive "P")
1272   (let ((articles (gnus-summary-work-articles n))
1273         (topics "Topics:\n")
1274         subject article frame)
1275     (when (car articles)
1276       (gnus-setup-message 'forward
1277         (gnus-summary-select-article)
1278         (if (cdr articles)
1279             (setq articles (sort articles '<)
1280                   subject "Digested Articles")
1281           (with-current-buffer gnus-original-article-buffer
1282             (setq subject (message-make-forward-subject))))
1283         (if post
1284             (message-news nil subject)
1285           (message-mail nil subject))
1286         (when (and message-use-multi-frames (cdr articles))
1287           (setq frame (window-frame (get-buffer-window (current-buffer)))))
1288         (message-goto-body)
1289         (while (setq article (pop articles))
1290           (save-window-excursion
1291             (set-buffer gnus-summary-buffer)
1292             (gnus-summary-select-article nil nil nil article)
1293             (setq topics (concat topics "    "
1294                                  (mail-header-subject gnus-current-headers)
1295                                  "\n"))
1296             (gnus-summary-remove-process-mark article))
1297           (when frame
1298             (select-frame frame))
1299           (insert (mime-make-tag "message" "rfc822") "\n")
1300           (narrow-to-region (point) (point))
1301           (insert-buffer-substring gnus-original-article-buffer)
1302           (save-restriction
1303             (article-narrow-to-head)
1304             (message-remove-header message-included-forward-headers t nil t))
1305           (goto-char (point-max))
1306           (widen))
1307         (push-mark)
1308         (message-goto-body)
1309         (insert topics)
1310         (message-goto-body)
1311         (mime-edit-enclose-digest-region (point)(mark t))))))
1312
1313 (defun gnus-summary-digest-post-forward (&optional n)
1314   "Digest and forwards all articles in this series to a newsgroup.
1315 If N is a positive number, forward the N next articles.
1316 If N is a negative number, forward the N previous articles.
1317 If N is nil and any articles have been marked with the process mark,
1318 forward those articles instead."
1319   (interactive "P")
1320   (gnus-summary-digest-mail-forward n t))
1321
1322 (defun gnus-summary-resend-message (address n)
1323   "Resend the current article to ADDRESS."
1324   (interactive
1325    (list (message-read-from-minibuffer
1326           "Resend message(s) to: "
1327           (when (and gnus-summary-resend-default-address
1328                      (gnus-buffer-live-p gnus-original-article-buffer))
1329             ;; If some other article is currently selected, the
1330             ;; initial-contents is wrong. Whatever, it is just the
1331             ;; initial-contents.
1332             (with-current-buffer gnus-original-article-buffer
1333               (nnmail-fetch-field "to"))))
1334          current-prefix-arg))
1335   (let ((articles (gnus-summary-work-articles n))
1336         article)
1337     (while (setq article (pop articles))
1338       (gnus-summary-select-article nil nil nil article)
1339       (save-excursion
1340         (set-buffer gnus-original-article-buffer)
1341         (message-resend address))
1342       (gnus-summary-mark-article-as-forwarded article))))
1343
1344 ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
1345 (defun gnus-summary-resend-message-edit ()
1346   "Resend an article that has already been sent.
1347 A new buffer will be created to allow the user to modify body and
1348 contents of the message, and then, everything will happen as when
1349 composing a new message."
1350   (interactive)
1351   (let ((article (gnus-summary-article-number)))
1352     (gnus-setup-message 'reply-yank
1353       (gnus-summary-select-article t)
1354       (set-buffer gnus-original-article-buffer)
1355       (let ((cur (current-buffer))
1356             (to (message-fetch-field "to")))
1357         ;; Get a normal message buffer.
1358         (message-pop-to-buffer (message-buffer-name "Resend" to))
1359         (insert-buffer-substring cur)
1360
1361         ;; T-gnus change: Use MIME-Edit to recompose a message.
1362         ;;(mime-to-mml)
1363         (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
1364           (fset 'mime-edit-decode-single-part-in-buffer
1365                 (lambda (&rest args)
1366                   (if (let ((content-type (car args)))
1367                         (and (eq 'message (mime-content-type-primary-type
1368                                            content-type))
1369                              (eq 'rfc822 (mime-content-type-subtype
1370                                           content-type))))
1371                       (setcar (cdr args) 'not-decode-text))
1372                   (apply ofn args)))
1373           (unwind-protect
1374               (mime-edit-again nil t)
1375             (fset 'mime-edit-decode-single-part-in-buffer ofn)))
1376         (message-narrow-to-head-1)
1377         (insert "From: " (message-make-from) "\n")
1378         (while (re-search-forward "^From:" nil t)
1379           (beginning-of-line)
1380           (insert "Original-"))
1381         (message-remove-header "^>From[\t ]" t)
1382
1383         ;; Gnus will generate a new one when sending.
1384         (message-remove-header "Message-ID")
1385         (message-remove-header message-ignored-resent-headers t)
1386         ;; Remove unwanted headers.
1387         (goto-char (point-max))
1388         (insert mail-header-separator)
1389         (goto-char (point-min))
1390         (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
1391         (forward-char 1)
1392         (widen)))))
1393
1394 (defun gnus-summary-post-forward (&optional full-headers)
1395   "Forward the current article to a newsgroup.
1396 If FULL-HEADERS (the prefix), include full headers when forwarding."
1397   (interactive "P")
1398   (gnus-summary-mail-forward full-headers t))
1399
1400 (defvar gnus-nastygram-message
1401   "The following article was inappropriately posted to %s.\n\n"
1402   "Format string to insert in nastygrams.
1403 The current group name will be inserted at \"%s\".")
1404
1405 (defun gnus-summary-mail-nastygram (n)
1406   "Send a nastygram to the author of the current article."
1407   (interactive "P")
1408   (when (or gnus-expert-user
1409             (gnus-y-or-n-p
1410              "Really send a nastygram to the author of the current article? "))
1411     (let ((group gnus-newsgroup-name))
1412       (gnus-summary-reply-with-original n)
1413       (set-buffer gnus-message-buffer)
1414       (message-goto-body)
1415       (insert (format gnus-nastygram-message group))
1416       (message-send-and-exit))))
1417
1418 (defun gnus-summary-mail-crosspost-complaint (n)
1419   "Send a complaint about crossposting to the current article(s)."
1420   (interactive "P")
1421   (let ((articles (gnus-summary-work-articles n))
1422         article)
1423     (while (setq article (pop articles))
1424       (set-buffer gnus-summary-buffer)
1425       (gnus-summary-goto-subject article)
1426       (let ((group (gnus-group-real-name gnus-newsgroup-name))
1427             newsgroups followup-to)
1428         (gnus-summary-select-article)
1429         (set-buffer gnus-original-article-buffer)
1430         (if (and (<= (length (message-tokenize-header
1431                               (setq newsgroups
1432                                     (mail-fetch-field "newsgroups"))
1433                               ", "))
1434                      1)
1435                  (or (not (setq followup-to (mail-fetch-field "followup-to")))
1436                      (not (member group (message-tokenize-header
1437                                          followup-to ", ")))))
1438             (if followup-to
1439                 (gnus-message 1 "Followup-to restricted")
1440               (gnus-message 1 "Not a crossposted article"))
1441           (set-buffer gnus-summary-buffer)
1442           (gnus-summary-reply-with-original 1)
1443           (set-buffer gnus-message-buffer)
1444           (message-goto-body)
1445           (insert (format gnus-crosspost-complaint newsgroups group))
1446           (message-goto-subject)
1447           (re-search-forward " *$")
1448           (replace-match " (crosspost notification)" t t)
1449           (gnus-deactivate-mark)
1450           (when (gnus-y-or-n-p "Send this complaint? ")
1451             (message-send-and-exit)))))))
1452
1453 (defun gnus-mail-parse-comma-list ()
1454   (let (accumulated
1455         beg)
1456     (skip-chars-forward " ")
1457     (while (not (eobp))
1458       (setq beg (point))
1459       (skip-chars-forward "^,")
1460       (while (zerop
1461               (save-excursion
1462                 (save-restriction
1463                   (let ((i 0))
1464                     (narrow-to-region beg (point))
1465                     (goto-char beg)
1466                     (logand (progn
1467                               (while (search-forward "\"" nil t)
1468                                 (incf i))
1469                               (if (zerop i) 2 i))
1470                             2)))))
1471         (skip-chars-forward ",")
1472         (skip-chars-forward "^,"))
1473       (skip-chars-backward " ")
1474       (push (buffer-substring beg (point))
1475             accumulated)
1476       (skip-chars-forward "^,")
1477       (skip-chars-forward ", "))
1478     accumulated))
1479
1480 (defun gnus-inews-add-to-address (group)
1481   (let ((to-address (mail-fetch-field "to")))
1482     (when (and to-address
1483                (gnus-alive-p))
1484       ;; This mail group doesn't have a `to-list', so we add one
1485       ;; here.  Magic!
1486       (when (gnus-y-or-n-p
1487              (format "Do you want to add this as `to-list': %s " to-address))
1488         (gnus-group-add-parameter group (cons 'to-list to-address))))))
1489
1490 (defun gnus-put-message ()
1491   "Put the current message in some group and return to Gnus."
1492   (interactive)
1493   (let ((reply gnus-article-reply)
1494         (winconf gnus-prev-winconf)
1495         (group gnus-newsgroup-name))
1496     (unless (and group
1497                  (not (gnus-group-read-only-p group)))
1498       (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
1499
1500     (when (gnus-gethash group gnus-newsrc-hashtb)
1501       (error "No such group: %s" group))
1502     (save-excursion
1503       (save-restriction
1504         (widen)
1505         (message-narrow-to-headers)
1506         (let ((gnus-deletable-headers nil))
1507           (message-generate-headers
1508            (if (message-news-p)
1509                message-required-news-headers
1510              message-required-mail-headers)))
1511         (goto-char (point-max))
1512         (if (string-match " " group)
1513             (insert "Gcc: \"" group "\"\n")
1514           (insert "Gcc: " group "\n"))
1515         (widen)))
1516     (gnus-inews-do-gcc)
1517     (when (and (get-buffer gnus-group-buffer)
1518                (gnus-buffer-exists-p (car-safe reply))
1519                (cdr reply))
1520       (set-buffer (car reply))
1521       (gnus-summary-mark-article-as-replied (cdr reply)))
1522     (when winconf
1523       (set-window-configuration winconf))))
1524
1525 (defun gnus-article-mail (yank)
1526   "Send a reply to the address near point.
1527 If YANK is non-nil, include the original article."
1528   (interactive "P")
1529   (let ((address
1530          (buffer-substring
1531           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1532           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1533     (when address
1534       (gnus-msg-mail address)
1535       (when yank
1536         (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
1537
1538 (defvar nntp-server-type)
1539 (defun gnus-bug ()
1540   "Send a bug report to the Gnus maintainers."
1541   (interactive)
1542   (unless (gnus-alive-p)
1543     (error "Gnus has been shut down"))
1544   (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
1545     (unless (message-mail-user-agent)
1546       (message-pop-to-buffer "*Gnus Bug*")
1547       (delete-other-windows)
1548       (when gnus-bug-create-help-buffer
1549         (switch-to-buffer "*Gnus Help Bug*")
1550         (erase-buffer)
1551         (insert gnus-bug-message)
1552         (goto-char (point-min))
1553         (sit-for 0)
1554         (set-buffer "*Gnus Bug*")))
1555     (let ((message-this-is-mail t))
1556       (message-setup `((To . ,gnus-maintainer) (Subject . ""))))
1557     (when gnus-bug-create-help-buffer
1558       (push `(gnus-bug-kill-buffer) message-send-actions))
1559     (goto-char (point-min))
1560     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1561     (forward-line 1)
1562     (insert gnus-product-name " " gnus-version-number
1563             " (r" gnus-revision-number ") "
1564             "based on " gnus-original-product-name " v"
1565             gnus-original-version-number "\n"
1566             (emacs-version) "\n")
1567     (when (and (boundp 'nntp-server-type)
1568                (stringp nntp-server-type))
1569       (insert nntp-server-type))
1570     (insert "\n\n\n\n\n")
1571     (let (mime-content-types)
1572       (mime-edit-insert-tag
1573        "application" "emacs-lisp"
1574        "\nContent-Disposition: inline\nContent-Description: User settings"))
1575     (insert (with-temp-buffer
1576               (gnus-debug)
1577               (buffer-string)))
1578     (let (mime-content-types)
1579       (mime-edit-insert-tag "text" "plain"))
1580     (goto-char (point-min))
1581     (search-forward "Subject: " nil t)
1582     (message "")))
1583
1584 (defun gnus-bug-kill-buffer ()
1585   (when (get-buffer "*Gnus Help Bug*")
1586     (kill-buffer "*Gnus Help Bug*")))
1587
1588 (defun gnus-summary-yank-message (buffer n)
1589   "Yank the current article into a composed message."
1590   (interactive
1591    (list (completing-read "Buffer: " (mapcar 'list (message-buffers)) nil t)
1592          current-prefix-arg))
1593   (when (gnus-buffer-live-p buffer)
1594     (let ((summary-frame (selected-frame))
1595           (message-frame (when (static-if (featurep 'xemacs)
1596                                    (device-on-window-system-p)
1597                                  window-system)
1598                            (let ((window (get-buffer-window buffer t)))
1599                              (when window
1600                                (window-frame window)))))
1601           (separator (concat "^" (regexp-quote mail-header-separator)
1602                              "\n")))
1603       (gnus-summary-iterate n
1604         (gnus-summary-select-article)
1605         (gnus-copy-article-buffer)
1606         (when (frame-live-p message-frame)
1607           (raise-frame message-frame)
1608           (select-frame message-frame))
1609         (with-current-buffer buffer
1610           (when (save-excursion
1611                   (beginning-of-line)
1612                   (let (case-fold-search)
1613                     (and (not (re-search-backward separator nil t))
1614                          (re-search-forward separator nil t))))
1615             (goto-char (match-end 0)))
1616           (message-yank-buffer gnus-article-copy))
1617         (select-frame summary-frame))
1618       (when (frame-live-p message-frame)
1619         (select-frame message-frame)))))
1620
1621 (defun gnus-debug ()
1622   "Attempts to go through the Gnus source file and report what variables have been changed.
1623 The source file has to be in the Emacs load path."
1624   (interactive)
1625   (let ((files gnus-debug-files)
1626         (point (point))
1627         file expr olist sym)
1628     (gnus-message 4 "Please wait while we snoop your variables...")
1629     ;; Go through all the files looking for non-default values for variables.
1630     (save-excursion
1631       (sit-for 0)
1632       (set-buffer (gnus-get-buffer-create " *gnus bug info*"))
1633       (while files
1634         (erase-buffer)
1635         (when (and (setq file (locate-library (pop files)))
1636                    (file-exists-p file))
1637           (insert-file-contents file)
1638           (goto-char (point-min))
1639           (if (not (re-search-forward "^;;* *Internal variables" nil t))
1640               (gnus-message 4 "Malformed sources in file %s" file)
1641             (narrow-to-region (point-min) (point))
1642             (goto-char (point-min))
1643             (while (setq expr (ignore-errors (read (current-buffer))))
1644               (ignore-errors
1645                 (and (memq (car expr) '(defvar defcustom defvoo))
1646                      (stringp (nth 3 expr))
1647                      (not (memq (nth 1 expr) gnus-debug-exclude-variables))
1648                      (or (not (boundp (nth 1 expr)))
1649                          (not (equal (eval (nth 2 expr))
1650                                      (symbol-value (nth 1 expr)))))
1651                      (push (nth 1 expr) olist)))))))
1652       (kill-buffer (current-buffer)))
1653     (when (setq olist (nreverse olist))
1654       (insert ";----------------- Environment follows ------------------\n\n"))
1655     (while olist
1656       (if (boundp (car olist))
1657           (condition-case ()
1658               (pp `(setq ,(car olist)
1659                          ,(if (or (consp (setq sym (symbol-value (car olist))))
1660                                   (and (symbolp sym)
1661                                        (not (or (eq sym nil)
1662                                                 (eq sym t)))))
1663                               (list 'quote (symbol-value (car olist)))
1664                             (symbol-value (car olist))))
1665                   (current-buffer))
1666             (error
1667              (format "(setq %s 'whatever)\n" (car olist))))
1668         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1669       (setq olist (cdr olist)))
1670     ;; Remove any control chars - they seem to cause trouble for some
1671     ;; mailers.  (Byte-compiled output from the stuff above.)
1672     (goto-char point)
1673     (while (re-search-forward "[\000-\010\013-\037\200-\237]" nil t)
1674       (replace-match (format "\\%03o" (string-to-char (match-string 0)))
1675                      t t))
1676     ;; Break MIME tags purposely.
1677     (goto-char point)
1678     (while (re-search-forward mime-edit-tag-regexp nil t)
1679       (goto-char (1+ (match-beginning 0)))
1680       (insert "X"))))
1681
1682 ;;; Treatment of rejected articles.
1683 ;;; Bounced mail.
1684
1685 (defun gnus-summary-resend-bounced-mail (&optional fetch)
1686   "Re-mail the current message.
1687 This only makes sense if the current message is a bounce message than
1688 contains some mail you have written which has been bounced back to
1689 you.
1690 If FETCH, try to fetch the article that this is a reply to, if indeed
1691 this is a reply."
1692   (interactive "P")
1693   (gnus-summary-select-article t)
1694   (set-buffer gnus-original-article-buffer)
1695   (gnus-setup-message 'compose-bounce
1696     (let* ((references (mail-fetch-field "references"))
1697            (parent (and references (gnus-parent-id references))))
1698       (message-bounce)
1699       ;; If there are references, we fetch the article we answered to.
1700       (and fetch parent
1701            (gnus-summary-refer-article parent)
1702            (gnus-summary-show-all-headers)))))
1703
1704 ;;; Gcc handling.
1705
1706 (defun gnus-inews-group-method (group)
1707   (cond
1708    ;; If the group doesn't exist, we assume
1709    ;; it's an archive group...
1710    ((and (null (gnus-get-info group))
1711          (eq (car (gnus-server-to-method gnus-message-archive-method))
1712              (car (gnus-server-to-method (gnus-group-method group)))))
1713     gnus-message-archive-method)
1714    ;; Use the method.
1715    ((gnus-info-method (gnus-get-info group))
1716     (gnus-info-method (gnus-get-info group)))
1717    ;; Find the method.
1718    (t (gnus-server-to-method (gnus-group-method group)))))
1719
1720 ;; Do Gcc handling, which copied the message over to some group.
1721 (defun gnus-inews-do-gcc (&optional gcc)
1722   (interactive)
1723   (save-excursion
1724     (save-restriction
1725       (message-narrow-to-headers)
1726       (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
1727             (coding-system-for-write 'raw-text)
1728             (output-coding-system 'raw-text)
1729             groups group method group-art
1730             mml-externalize-attachments)
1731         (when gcc
1732           (message-remove-header "gcc")
1733           (widen)
1734           (setq groups (message-unquote-tokens
1735                         (message-tokenize-header gcc " ,")))
1736           ;; Copy the article over to some group(s).
1737           (while (setq group (pop groups))
1738             (unless (gnus-check-server
1739                      (setq method (gnus-inews-group-method group)))
1740               (error "Can't open server %s" (if (stringp method) method
1741                                               (car method))))
1742             (unless (gnus-request-group group nil method)
1743               (gnus-request-create-group group method))
1744             (setq mml-externalize-attachments
1745                   (if (stringp gnus-gcc-externalize-attachments)
1746                       (string-match gnus-gcc-externalize-attachments group)
1747                     gnus-gcc-externalize-attachments))
1748             (save-excursion
1749               (nnheader-set-temp-buffer " *acc*")
1750               (insert-buffer-substring message-encoding-buffer)
1751               (gnus-run-hooks 'gnus-before-do-gcc-hook)
1752               (goto-char (point-min))
1753               (when (re-search-forward
1754                      (concat "^" (regexp-quote mail-header-separator) "$")
1755                      nil t)
1756                 (replace-match "" t t ))
1757               (unless (setq group-art
1758                             (gnus-request-accept-article group method t t))
1759                 (gnus-message 1 "Couldn't store article in group %s: %s"
1760                               group (gnus-status-message method))
1761                 (sit-for 2))
1762               (when (and group-art
1763                          (or gnus-gcc-mark-as-read
1764                              gnus-inews-mark-gcc-as-read))
1765                 (gnus-group-mark-article-read group (cdr group-art)))
1766               (kill-buffer (current-buffer)))))))))
1767
1768 (defun gnus-inews-insert-gcc ()
1769   "Insert Gcc headers based on `gnus-outgoing-message-group'."
1770   (save-excursion
1771     (save-restriction
1772       (message-narrow-to-headers)
1773       (let* ((group gnus-outgoing-message-group)
1774              (gcc (cond
1775                    ((gnus-functionp group)
1776                     (funcall group))
1777                    ((or (stringp group) (list group))
1778                     group))))
1779         (when gcc
1780           (insert "Gcc: "
1781                   (if (stringp gcc) 
1782                       (if (string-match " " gcc)
1783                           (concat "\"" gcc "\"")
1784                         gcc)
1785                     (mapconcat (lambda (group)
1786                                  (if (string-match " " group)
1787                                      (concat "\"" group "\"")
1788                                    group))
1789                                gcc " "))
1790                   "\n"))))))
1791
1792 (defun gnus-inews-insert-archive-gcc (&optional group)
1793   "Insert the Gcc to say where the article is to be archived."
1794   (let* ((var gnus-message-archive-group)
1795          (group (or group gnus-newsgroup-name ""))
1796          (gcc-self-val
1797           (and gnus-newsgroup-name
1798                (not (equal gnus-newsgroup-name ""))
1799                (gnus-group-find-parameter
1800                 gnus-newsgroup-name 'gcc-self)))
1801          result
1802          (groups
1803           (cond
1804            ((null gnus-message-archive-method)
1805             ;; Ignore.
1806             nil)
1807            ((stringp var)
1808             ;; Just a single group.
1809             (list var))
1810            ((null var)
1811             ;; We don't want this.
1812             nil)
1813            ((and (listp var) (stringp (car var)))
1814             ;; A list of groups.
1815             var)
1816            ((gnus-functionp var)
1817             ;; A function.
1818             (funcall var group))
1819            (t
1820             ;; An alist of regexps/functions/forms.
1821             (while (and var
1822                         (not
1823                          (setq result
1824                                (cond
1825                                 ((stringp (caar var))
1826                                  ;; Regexp.
1827                                  (when (string-match (caar var) group)
1828                                    (cdar var)))
1829                                 ((gnus-functionp (car var))
1830                                  ;; Function.
1831                                  (funcall (car var) group))
1832                                 (t
1833                                  (eval (car var)))))))
1834               (setq var (cdr var)))
1835             result)))
1836          name)
1837     (when (or groups gcc-self-val)
1838       (when (stringp groups)
1839         (setq groups (list groups)))
1840       (save-excursion
1841         (save-restriction
1842           (message-narrow-to-headers)
1843           (goto-char (point-max))
1844           (insert "Gcc: ")
1845           (if gcc-self-val
1846               ;; Use the `gcc-self' param value instead.
1847               (progn
1848                 (insert
1849                  (if (stringp gcc-self-val)
1850                      (if (string-match " " gcc-self-val)
1851                          (concat "\"" gcc-self-val "\"")
1852                        gcc-self-val)
1853                    (if (string-match " " group)
1854                        (concat "\"" group "\"")
1855                      group)))
1856                 (if (not (eq gcc-self-val 'none))
1857                     (insert "\n")
1858                   (progn
1859                     (beginning-of-line)
1860                     (kill-line))))
1861             ;; Use the list of groups.
1862             (while (setq name (pop groups))
1863               (let ((str (if (string-match ":" name)
1864                              name
1865                            (gnus-group-prefixed-name
1866                             name gnus-message-archive-method))))
1867                 (insert (if (string-match " " str)
1868                             (concat "\"" str "\"")
1869                           str)))
1870               (when groups
1871                 (insert " ")))
1872             (insert "\n")))))))
1873
1874 ;;; Posting styles.
1875
1876 (defun gnus-configure-posting-styles (&optional group-name)
1877   "Configure posting styles according to `gnus-posting-styles'."
1878   (unless gnus-inhibit-posting-styles
1879     (let ((group (or group-name gnus-newsgroup-name ""))
1880           (styles gnus-posting-styles)
1881           style match variable attribute value v results
1882           filep name address element)
1883       ;; If the group has a posting-style parameter, add it at the end with a
1884       ;; regexp matching everything, to be sure it takes precedence over all
1885       ;; the others.
1886       (when gnus-newsgroup-name
1887         (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
1888           (when tmp-style
1889             (setq styles (append styles (list (cons ".*" tmp-style)))))))
1890       ;; Go through all styles and look for matches.
1891       (dolist (style styles)
1892         (setq match (pop style))
1893         (goto-char (point-min))
1894         (when (cond
1895                ((stringp match)
1896                 ;; Regexp string match on the group name.
1897                 (string-match match group))
1898                ((eq match 'header)
1899                 ;; Obsolete format of header match.
1900                 (and (gnus-buffer-live-p gnus-article-copy)
1901                      (with-current-buffer gnus-article-copy
1902                        (let ((header (message-fetch-field (pop style))))
1903                          (and header
1904                               (string-match (pop style) header))))))
1905                ((or (symbolp match)
1906                     (gnus-functionp match))
1907                 (cond
1908                  ((gnus-functionp match)
1909                   ;; Function to be called.
1910                   (funcall match))
1911                  ((boundp match)
1912                   ;; Variable to be checked.
1913                   (symbol-value match))))
1914                ((listp match)
1915                 (cond
1916                  ((eq (car match) 'header)
1917                   ;; New format of header match.
1918                   (and (gnus-buffer-live-p gnus-article-copy)
1919                        (with-current-buffer gnus-article-copy
1920                          (let ((header (message-fetch-field (nth 1 match))))
1921                            (and header
1922                                 (string-match (nth 2 match) header))))))
1923                  (t
1924                   ;; This is a form to be evaled.
1925                   (eval match)))))
1926           ;; We have a match, so we set the variables.
1927           (dolist (attribute style)
1928             (setq element (pop attribute)
1929                   variable nil
1930                   filep nil)
1931             (setq value
1932                   (cond
1933                    ((eq (car attribute) ':file)
1934                     (setq filep t)
1935                     (cadr attribute))
1936                    ((eq (car attribute) :value)
1937                     (cadr attribute))
1938                    (t
1939                     (car attribute))))
1940             ;; We get the value.
1941             (setq v
1942                   (cond
1943                    ((stringp value)
1944                     value)
1945                    ((or (symbolp value)
1946                         (gnus-functionp value))
1947                     (cond ((gnus-functionp value)
1948                            (funcall value))
1949                           ((boundp value)
1950                            (symbol-value value))))
1951                    ((listp value)
1952                     (eval value))))
1953             ;; Translate obsolescent value.
1954             (cond
1955              ((eq element 'signature-file)
1956               (setq element 'signature
1957                     filep t))
1958              ((eq element 'x-face-file)
1959               (setq element 'x-face
1960                     filep t)))
1961             ;; Get the contents of file elems.
1962             (when (and filep v)
1963               (setq v (with-temp-buffer
1964                         (insert-file-contents v)
1965                         (goto-char (point-max))
1966                         (while (bolp)
1967                           (delete-char -1))
1968                         (buffer-string))))
1969             (setq results (delq (assoc element results) results))
1970             (push (cons element v) results))))
1971       ;; Now we have all the styles, so we insert them.
1972       (setq name (assq 'name results)
1973             address (assq 'address results))
1974       (setq results (delq name (delq address results)))
1975       ;; make-local-hook is not obsolete in Emacs 20 or XEmacs.
1976       (make-local-hook 'message-setup-hook)
1977       (dolist (result results)
1978         (add-hook 'message-setup-hook
1979                   (cond
1980                    ((eq 'eval (car result))
1981                     'ignore)
1982                    ((eq 'body (car result))
1983                     `(lambda ()
1984                        (save-excursion
1985                          (message-goto-body)
1986                          (insert ,(cdr result)))))
1987                    ((eq 'signature (car result))
1988                     (set (make-local-variable 'message-signature) nil)
1989                     (set (make-local-variable 'message-signature-file) nil)
1990                     (if (not (cdr result))
1991                         'ignore
1992                       `(lambda ()
1993                          (save-excursion
1994                            (let ((message-signature ,(cdr result)))
1995                              (when message-signature
1996                                (message-insert-signature)))))))
1997                    (t
1998                     (let ((header
1999                            (if (symbolp (car result))
2000                                (capitalize (symbol-name (car result)))
2001                              (car result))))
2002                       `(lambda ()
2003                          (save-excursion
2004                            (message-remove-header ,header)
2005                            (let ((value ,(cdr result)))
2006                              (when value
2007                                (message-goto-eoh)
2008                                (insert ,header ": " value "\n"))))))))
2009                   nil 'local))
2010       (when (or name address)
2011         (add-hook 'message-setup-hook
2012                   `(lambda ()
2013                      (set (make-local-variable 'user-mail-address)
2014                           ,(or (cdr address) user-mail-address))
2015                      (let ((user-full-name ,(or (cdr name) (user-full-name)))
2016                            (user-mail-address
2017                             ,(or (cdr address) user-mail-address)))
2018                        (save-excursion
2019                          (message-remove-header "From")
2020                          (message-goto-eoh)
2021                          (insert "From: " (message-make-from) "\n"))))
2022                   nil 'local)))))
2023
2024
2025 ;;; @ for MIME Edit mode
2026 ;;;
2027
2028 (defun gnus-maybe-setup-default-charset ()
2029   (let ((charset
2030          (and (boundp 'gnus-summary-buffer)
2031               (buffer-live-p gnus-summary-buffer)
2032               (save-excursion
2033                 (set-buffer gnus-summary-buffer)
2034                 default-mime-charset))))
2035     (if charset
2036         (progn
2037           (make-local-variable 'default-mime-charset)
2038           (setq default-mime-charset charset)
2039           ))))
2040
2041
2042 ;;; @ for MIME view mode
2043 ;;;
2044
2045 (defun gnus-following-method (buf)
2046   (gnus-setup-message 'reply-yank
2047     (set-buffer buf)
2048     (if (message-news-p)
2049         (message-followup)
2050       (message-reply nil 'wide))
2051     (let ((message-reply-buffer buf))
2052       (message-yank-original))
2053     (message-goto-body))
2054   (kill-buffer buf))
2055
2056
2057 ;;; Allow redefinition of functions.
2058
2059 (gnus-ems-redefine)
2060
2061 (provide 'gnus-msg)
2062
2063 ;;; gnus-msg.el ends here