4d2745138d4564d26c5a79c481f3c46c677632f7
[gnus] / lisp / gnus-msg.el
1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995,96 Free Software Foundation, Inc.
3
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
5 ;;      Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (require 'gnus)
30 (require 'sendmail)
31 (require 'gnus-ems)
32 (eval-when-compile (require 'cl))
33
34 ;; Added by Sudish Joseph <joseph@cis.ohio-state.edu>.
35 (defvar gnus-post-method nil
36   "*Preferred method for posting USENET news.
37 If this variable is nil, Gnus will use the current method to decide
38 which method to use when posting.  If it is non-nil, it will override
39 the current method.  This method will not be used in mail groups and
40 the like, only in \"real\" newsgroups.
41
42 The value must be a valid method as discussed in the documentation of
43 `gnus-select-method'.  It can also be a list of methods.  If that is
44 the case, the user will be queried for what select method to use when
45 posting.")
46
47 (defvar gnus-organization-file "/usr/lib/news/organization"
48   "*Local news organization file.")
49
50 (defvar gnus-prepare-article-hook nil
51   "*A hook called after preparing body, but before preparing header headers.")
52
53 (defvar gnus-post-prepare-function nil
54   "*Function that is run after a post buffer has been prepared.
55 It is called with the name of the newsgroup that is posted to. It
56 might be used, for instance, for inserting signatures based on the
57 newsgroup name. (In that case, `gnus-signature-file' and
58 `mail-signature' should both be set to nil).")
59
60 (defvar gnus-post-prepare-hook nil
61   "*Hook that is run after a post buffer has been prepared.
62 If you want to insert the signature, you might put
63 `gnus-inews-insert-signature' in this hook.")
64
65 (defvar gnus-use-followup-to 'ask
66   "*Specifies what to do with Followup-To header.
67 If nil, ignore the header. If it is t, use its value, but ignore
68 \"poster\".  If it is the symbol `ask', query the user whether to
69 ignore the \"poster\" value.  If it is the symbol `use', always use
70 the value.")
71
72 (defvar gnus-followup-to-function nil
73   "*A variable that contains a function that returns a followup address.
74 The function will be called in the buffer of the article that is being
75 followed up. The buffer will be narrowed to the headers of the
76 article. To pick header headers, one might use `mail-fetch-field'.  The
77 function will be called with the name of the current newsgroup as the
78 argument.
79
80 Here's an example `gnus-followup-to-function':
81
82 (setq gnus-followup-to-function
83       (lambda (group)
84         (cond ((string= group \"mail.list\")
85                (or (mail-fetch-field \"sender\") 
86                    (mail-fetch-field \"from\")))
87               (t
88                (or (mail-fetch-field \"reply-to\") 
89                    (mail-fetch-field \"from\"))))))")
90
91 (defvar gnus-reply-to-function nil
92   "*A variable that contains a function that returns a reply address.
93 See the `gnus-followup-to-function' variable for an explanation of how
94 this variable is used.
95
96 This function should return a string that will be used to fill in the
97 header.  This function may also return a list.  In that case, every
98 list element should be a cons where the first car should be a string
99 with the header name, and the cdr should be a string with the header
100 value.")
101
102 (defvar gnus-author-copy (getenv "AUTHORCOPY")
103   "*Save outgoing articles in this file.
104 Initialized from the AUTHORCOPY environment variable.
105
106 If this variable begins with the character \"|\", outgoing articles
107 will be piped to the named program. It is possible to save an article
108 in an MH folder as follows:
109
110 \(setq gnus-author-copy \"|/usr/local/lib/mh/rcvstore +Article\")
111
112 If the first character is not a pipe, articles are saved using the
113 function specified by the `gnus-author-copy-saver' variable.")
114
115 (defvar gnus-mail-self-blind nil
116   "*Non-nil means insert a BCC header in all outgoing articles.
117 This will result in having a copy of the article mailed to yourself.
118 The BCC header is inserted when the post buffer is initialized, so you
119 can remove or alter the BCC header to override the default.")
120
121 (defvar gnus-author-copy-saver (function rmail-output)
122   "*A function called to save outgoing articles.
123 This function will be called with the same of the file to store the
124 article in. The default function is `rmail-output' which saves in Unix
125 mailbox format.")
126
127 (defvar gnus-outgoing-message-group nil
128   "*All outgoing messages will be put in this group.
129 If you want to store all your outgoing mail and articles in the group
130 \"nnml:archive\", you set this variable to that value. This variable
131 can also be a list of group names. 
132
133 If you want to have greater control over what group to put each
134 message in, you can set this variable to a function that checks the
135 current newsgroup name and then returns a suitable group name (or list
136 of names).")
137
138 (defvar gnus-message-archive-group
139   '((if (eq major-mode 'news-reply-mode) "misc-news" "misc-mail"))
140   "*Name of the group in which to save the messages you've written.
141 This can either be a string, a list of strings; or an alist
142 of regexps/functions/forms to be evaluated to return a string (or a list
143 of strings).  The functions are called with the name of the current
144 group (or nil) as a parameter.")
145
146 (defvar gnus-mailing-list-groups nil
147   "*Regexp matching groups that are really mailing lists.
148 This is useful when you're reading a mailing list that has been
149 gatewayed to a newsgroup, and you want to followup to an article in
150 the group.")
151
152 (defvar gnus-draft-group-directory 
153   (expand-file-name
154    (concat (file-name-as-directory gnus-article-save-directory)
155            "drafts"))
156   "*The directory where draft messages will be stored.")
157
158 (defvar gnus-use-draft t
159   "*Whether Gnus should use the draft group.")
160
161 (defvar gnus-posting-styles nil
162   "*Alist of styles to use when posting.")
163
164 (defvar gnus-posting-style-alist
165   '((organization . gnus-organization-file)
166     (signature . gnus-signature-file)
167     (from . gnus-user-from-line))
168   "*Mapping from style parameters to Gnus variables.")
169
170 (defvar gnus-user-login-name nil
171   "*The login name of the user.
172 Got from the function `user-login-name' if undefined.")
173
174 (defvar gnus-user-full-name nil
175   "*The full name of the user.
176 Got from the NAME environment variable if undefined.")
177
178 (defvar gnus-user-from-line nil
179   "*Your full, complete e-mail address.  
180 Overrides the other Gnus variables if it is non-nil.
181
182 Here are two example values of this variable:
183
184  \"Lars Magne Ingebrigtsen <larsi@ifi.uio.no>\"
185
186 and
187
188  \"larsi@ifi.uio.no (Lars Magne Ingebrigtsen)\"
189
190 The first version is recommended, but the name has to be quoted if it
191 contains non-alphanumerical characters.")
192
193 (defvar gnus-signature-file "~/.signature"
194   "*Your signature file.
195 If the variable is a string that doesn't correspond to a file, the
196 string itself is inserted.")
197
198 (defvar gnus-signature-function nil
199   "*A function that should return a signature file name.
200 The function will be called with the name of the newsgroup being
201 posted to.
202 If the function returns a string that doesn't correspond to a file, the
203 string itself is inserted.
204 If the function returns nil, the `gnus-signature-file' variable will
205 be used instead.")
206
207 (defvar gnus-forward-start-separator 
208   "------- Start of forwarded message -------\n"
209   "*Delimiter inserted before forwarded messages.")
210
211 (defvar gnus-forward-end-separator
212   "------- End of forwarded message -------\n"
213   "*Delimiter inserted after forwarded messages.")
214
215 (defvar gnus-signature-before-forwarded-message t
216   "*If non-nil, put the signature before any included forwarded message.")
217
218 (defvar gnus-forward-included-headers 
219   "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-\\|^Message-ID:\\|^References:"
220   "*Regexp matching headers to be included in forwarded messages.")
221
222 (defvar gnus-required-headers
223   '(From Date Newsgroups Subject Message-ID Organization Lines X-Newsreader)
224   "*Headers to be generated or prompted for when posting an article.
225 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
226 Message-ID.  Organization, Lines, In-Reply-To, Expires, and
227 X-Newsreader are optional.  If you want Gnus not to insert some
228 header, remove it from this list.")
229
230 (defvar gnus-required-mail-headers 
231   '(From Date To Subject (optional . In-Reply-To) Message-ID Organization Lines)
232   "*Headers to be generated or prompted for when mailing a message.
233 RFC822 required that From, Date, To, Subject and Message-ID be
234 included.  Organization, Lines and X-Mailer are optional.")
235
236 (defvar gnus-deletable-headers '(Message-ID Date)
237   "*Headers to be deleted if they already exists and were generated by Gnus previously.")
238
239 (defvar gnus-removable-headers '(NNTP-Posting-Host Xref)
240   "*Headers to be removed unconditionally before posting.")
241
242 (defvar gnus-article-expires 14
243   "*Number of days before your article expires.
244 This variable isn't used unless you have the `Expires' element in
245 `gnus-required-headers'.")
246
247 (defvar gnus-distribution-function nil
248   "*Function that should return the Distribution header for outgoing articles.
249 It will be called from the buffer where the outgoing article
250 is being prepared with the group name as the only parameter.
251 It should return a valid distribution.  
252
253 The function will only be called if you have the `Distribution' header in 
254 `gnus-required-headers'.")
255
256 (defvar gnus-check-before-posting 
257   '(subject-cmsg multiple-headers sendsys message-id from
258                  long-lines control-chars size new-text
259                  redirected-followup signature approved sender 
260                  empty empty-headers)
261   "In non-nil, Gnus will attempt to run some checks on outgoing posts.
262 If this variable is t, Gnus will check everything it can.  If it is a
263 list, then those elements in that list will be checked.")
264
265 (defvar gnus-delete-supersedes-headers
266   "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Supersedes:\\|^Xref:\\|^Lines:"
267   "*Header lines matching this regexp will be deleted before posting.
268 It's best to delete old Path and Date headers before posting to avoid
269 any confusion.")
270
271 (defvar gnus-auto-mail-to-author nil
272   "*If non-nil, mail the authors of articles a copy of your follow-ups.
273 If this variable is `ask', the user will be prompted for whether to
274 mail a copy.  The string given by `gnus-mail-courtesy-message' will be
275 inserted at the beginning of the mail copy.")
276
277 ;; Added by Ethan Bradford <ethanb@ptolemy.astro.washington.edu>.
278 (defvar gnus-mail-courtesy-message
279   "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
280   "*This is inserted at the start of a mailed copy of a posted message.
281 If this variable is nil, no such courtesy message will be added.")
282
283 (defvar gnus-mail-method 'sendmail
284   "*Method to use for composing mail.
285 There are three legal values: `sendmail' (which is the default), `mh', 
286 and `vm'.")
287
288 (defvar gnus-mail-reply-method (function gnus-mail-reply-using-mail)
289   "*Function to compose a reply.
290 Three pre-made functions are `gnus-mail-reply-using-mail' (sendmail);
291 `gnus-mail-reply-using-mhe' (MH-E); and `gnus-mail-reply-using-vm'.")
292
293 (defvar gnus-mail-forward-method (function gnus-mail-forward-using-mail)
294   "*Function to forward the current message to another user.
295 Three pre-made functions are `gnus-mail-forward-using-mail' (sendmail);
296 `gnus-mail-forward-using-mhe' (MH-E); and `gnus-mail-forward-using-vm'.") 
297
298 (defvar gnus-mail-other-window-method 'gnus-mail-other-window-using-mail
299   "*Function to compose mail in the other window.
300 Three pre-made functions are `gnus-mail-other-window-using-mail'
301 (sendmail); `gnus-mail-other-window-using-mhe' (MH-E); and
302 `gnus-mail-other-window-using-vm'.")
303
304 (defvar gnus-inews-article-function 'gnus-inews-article
305   "*Function to post an article.")
306
307 (defvar gnus-bounced-headers-junk "^\\(Received\\):"
308   "*Regexp that matches headers to be removed in resent bounced mail.")
309
310 (defvar gnus-inews-article-hook (list 'gnus-inews-do-fcc)
311   "*A hook called before finally posting an article.
312 The default hook (`gnus-inews-do-fcc') does FCC processing (ie. saves
313 the article to a file).")
314
315 (defvar gnus-inews-article-header-hook nil
316   "*A hook called after inserting the headers in an article to be posted.
317 The hook is called from the *post-news* buffer, narrowed to the
318 headers.")
319
320 (defvar gnus-mail-hook nil
321   "*A hook called as the last thing after setting up a mail buffer.")
322
323 (defvar gnus-message-sent-hook nil
324   "*A hook run after an article has been sent (or attempted sent).")
325
326 ;;; Internal variables.
327
328 (defvar gnus-post-news-buffer "*Post Gnus*")
329 (defvar gnus-mail-buffer "*Mail Gnus*")
330 (defvar gnus-article-copy nil)
331 (defvar gnus-reply-subject nil)
332 (defvar gnus-newsgroup-followup nil)
333 (defvar gnus-add-to-address nil)
334 (defvar gnus-in-reply-to nil)
335 (defvar gnus-last-posting-server nil)
336
337 (eval-and-compile
338   (autoload 'gnus-uu-post-news "gnus-uu" nil t)
339   (autoload 'news-setup "rnewspost")
340   (autoload 'news-reply-mode "rnewspost")
341   (autoload 'rmail-dont-reply-to "mail-utils")
342   (autoload 'rmail-output "rmailout"))
343
344 \f
345 ;;;
346 ;;; Gnus Posting Functions
347 ;;;
348
349 (gnus-define-keys 
350  (gnus-summary-send-map "S" gnus-summary-mode-map)
351  "p" gnus-summary-post-news
352  "f" gnus-summary-followup
353  "F" gnus-summary-followup-with-original
354  "b" gnus-summary-followup-and-reply
355  "B" gnus-summary-followup-and-reply-with-original
356  "c" gnus-summary-cancel-article
357  "s" gnus-summary-supersede-article
358  "r" gnus-summary-reply
359  "R" gnus-summary-reply-with-original
360  "m" gnus-summary-mail-other-window
361  "u" gnus-uu-post-news
362  "om" gnus-summary-mail-forward
363  "op" gnus-summary-post-forward
364  "Om" gnus-uu-digest-mail-forward
365  "Op" gnus-uu-digest-post-forward)
366
367 (gnus-define-keys
368  (gnus-send-bounce-map "D" gnus-summary-send-map)
369  "b" gnus-summary-resend-bounced-mail
370  "c" gnus-summary-send-draft
371  "r" gnus-summary-resend-message)
372
373 ;;; Internal functions.
374
375 (defun gnus-number-base36 (num len)
376   (if (if (< len 0) (<= num 0) (= len 0))
377       ""
378     (concat (gnus-number-base36 (/ num 36) (1- len))
379             (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
380                                   (% num 36))))))
381
382 ;;; Post news commands of Gnus group mode and summary mode
383
384 (defun gnus-group-mail ()
385   "Start composing a mail."
386   (interactive)
387   (gnus-new-mail
388    ;; We might want to prompt here.
389    (when (and gnus-interactive-post
390               (not gnus-expert-user))
391      (read-string "To: "))))
392
393 (defun gnus-group-post-news (&optional arg)
394   "Post an article.
395 The newsgroup under the cursor is used as the group to post to.
396
397 If you wish to get an empty post buffer, use a prefix ARG.  You can
398 also do this by calling this function from the bottom of the Group
399 buffer."
400   (interactive "P")
401   (let ((gnus-newsgroup-name nil)
402         (group (unless arg (gnus-group-group-name)))
403         subject)
404     ;; We might want to prompt here.
405     (when (and gnus-interactive-post
406                (not gnus-expert-user))
407       (setq gnus-newsgroup-name
408             (setq group 
409                   (completing-read "Group: " gnus-active-hashtb nil nil
410                                    (cons (or group "") 0)))))
411     (gnus-post-news 'post group nil gnus-article-buffer)))
412
413 (defun gnus-summary-post-news ()
414   "Post an article."
415   (interactive)
416   (gnus-set-global-variables)
417   (gnus-post-news 'post gnus-newsgroup-name))
418
419 (defun gnus-summary-followup (yank &optional yank-articles)
420   "Compose a followup to an article.
421 If prefix argument YANK is non-nil, original article is yanked automatically."
422   (interactive "P")
423   (gnus-set-global-variables)
424   (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
425   (save-window-excursion
426     (gnus-summary-select-article))
427   (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
428         (gnus-newsgroup-name gnus-newsgroup-name))
429     ;; Check Followup-To: poster.
430     (set-buffer gnus-article-buffer)
431     (if (and gnus-use-followup-to
432              (string-equal "poster" (gnus-fetch-field "followup-to"))
433              (or (not (memq gnus-use-followup-to '(t ask)))
434                  (not (gnus-y-or-n-p 
435                        "Do you want to ignore `Followup-To: poster'? "))))
436         ;; Mail to the poster. 
437         (gnus-summary-reply yank)
438       ;; Send a followup.
439       (gnus-post-news nil gnus-newsgroup-name
440                       headers gnus-article-buffer 
441                       (or yank-articles (not (not yank)))))))
442
443 (defun gnus-summary-followup-with-original (n)
444   "Compose a followup to an article and include the original article."
445   (interactive "P")
446   (gnus-summary-followup t (gnus-summary-work-articles n)))
447
448 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
449 (defun gnus-summary-followup-and-reply (yank &optional yank-articles)
450   "Compose a followup and do an auto mail to author."
451   (interactive "P")
452   (gnus-set-global-variables)
453   (let ((gnus-auto-mail-to-author 'force))
454     (gnus-summary-followup yank yank-articles)))
455
456 (defun gnus-summary-followup-and-reply-with-original (n)
457   "Compose a followup, include the original, and do an auto mail to author."
458   (interactive "P")
459   (gnus-summary-followup-and-reply t (gnus-summary-work-articles n)))
460
461 (defun gnus-summary-cancel-article (n)
462   "Cancel an article you posted."
463   (interactive "P")
464   (gnus-set-global-variables)
465   (let ((articles (gnus-summary-work-articles n))
466         article)
467     (while (setq article (pop articles))
468       (when (gnus-summary-select-article t nil nil article)
469         (when (gnus-eval-in-buffer-window 
470                gnus-original-article-buffer (gnus-cancel-news))
471           (gnus-summary-mark-as-read article gnus-canceled-mark))
472         (gnus-article-hide-headers-if-wanted))
473       (gnus-summary-remove-process-mark article))))
474
475 (defun gnus-summary-supersede-article ()
476   "Compose an article that will supersede a previous article.
477 This is done simply by taking the old article and adding a Supersedes
478 header line with the old Message-ID."
479   (interactive)
480   (gnus-set-global-variables)
481   (gnus-summary-select-article t)
482   ;; Check whether the user owns the article that is to be superseded. 
483   (unless (string-equal
484            (downcase (mail-strip-quoted-names 
485                       (mail-header-from gnus-current-headers)))
486            (downcase (mail-strip-quoted-names (gnus-inews-user-name))))
487     (error "This article is not yours."))
488   ;; Get a normal *Post News* buffer.
489   (gnus-new-news gnus-newsgroup-name t)
490   (erase-buffer)
491   (insert-buffer-substring gnus-original-article-buffer)
492   (nnheader-narrow-to-headers)
493   ;; Remove unwanted headers.
494   (when gnus-delete-supersedes-headers
495     (nnheader-remove-header gnus-delete-supersedes-headers t))
496   (goto-char (point-min))
497   (if (not (re-search-forward "^Message-ID: " nil t))
498       (error "No Message-ID in this article")
499     (replace-match "Supersedes: " t t))
500   (goto-char (point-max))
501   (insert mail-header-separator)
502   (widen)
503   (forward-line 1))
504
505 \f
506 ;;;###autoload
507 (defalias 'sendnews 'gnus-post-news)
508
509 ;;;###autoload
510 (defalias 'postnews 'gnus-post-news)
511
512 (defun gnus-copy-article-buffer (&optional article-buffer)
513   ;; make a copy of the article buffer with all text properties removed
514   ;; this copy is in the buffer gnus-article-copy.
515   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
516   ;; this buffer should be passed to all mail/news reply/post routines.
517   (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
518   (buffer-disable-undo gnus-article-copy)
519   (or (memq gnus-article-copy gnus-buffer-list)
520       (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
521   (let ((article-buffer (or article-buffer gnus-article-buffer)))
522     (if (and (get-buffer article-buffer)
523              (buffer-name (get-buffer article-buffer)))
524         (save-excursion
525           (set-buffer article-buffer)
526           (widen)
527           (copy-to-buffer gnus-article-copy (point-min) (point-max))
528           (gnus-set-text-properties (point-min) (point-max) 
529                                     nil gnus-article-copy)))))
530
531 (defun gnus-post-news (post &optional group header article-buffer yank subject)
532   "Begin editing a new USENET news article to be posted.
533 Type \\[describe-mode] in the buffer to get a list of commands."
534   (interactive (list t))
535   (let* ((group (or group gnus-newsgroup-name))
536          (pgroup group)
537          to-address to-group mailing-list to-list)
538     (when group
539       (setq to-address (gnus-group-get-parameter group 'to-address)
540             to-group (gnus-group-get-parameter group 'to-group)
541             to-list (gnus-group-get-parameter group 'to-list)
542             mailing-list (when gnus-mailing-list-groups
543                            (string-match gnus-mailing-list-groups group))
544             group (gnus-group-real-name group)))
545     (if (or (and to-group
546                  (gnus-news-group-p to-group))
547             (and (gnus-news-group-p 
548                   (or pgroup gnus-newsgroup-name)
549                   (if header (mail-header-number header) gnus-current-article))
550                  (not mailing-list)
551                  (not to-list)
552                  (not to-address)))
553         ;; This is news.
554         (if post
555             (gnus-new-news (or to-group group))
556           (gnus-news-followup yank (or to-group group)))
557       ;; The is mail.
558       (if post
559           (progn
560             (gnus-new-mail (or to-address to-list))
561             ;; Arrange for mail groups that have no `to-address' to
562             ;; get that when the user sends off the mail.
563             (unless to-address
564               (make-local-variable 'gnus-add-to-address)
565               (setq gnus-add-to-address group)))
566         (gnus-mail-reply yank to-address 'followup)))))
567
568 (defun gnus-post-method (group query-method &optional silent)
569   "Return the posting method based on GROUP and query-method.
570 If SILENT, don't prompt the user."
571   (let ((group-method (if (stringp group)
572                           (gnus-find-method-for-group group)
573                         group)))
574     (cond 
575      ;; If the group-method is nil (which shouldn't happen) we use 
576      ;; the default method.
577      ((null group-method)
578       (or gnus-post-method gnus-select-method))
579      ;; We want this group's method.
580      ((and query-method (not (eq query-method 0)))
581       group-method)
582      ;; We query the user for a post method.
583      ((or query-method
584           (and gnus-post-method
585                (listp (car gnus-post-method))))
586       (let* ((methods
587               ;; Collect all methods we know about.
588               (append
589                (when gnus-post-method
590                  (if (listp (car gnus-post-method))
591                      gnus-post-method
592                    (listp gnus-post-method)))
593                gnus-secondary-select-methods
594                (list gnus-select-method)
595                (list group-method)))
596              method-alist post-methods method)
597         ;; Weed out all mail methods.
598         (while methods
599           (setq method (gnus-server-get-method "" (pop methods)))
600           (when (or (gnus-method-option-p method 'post)
601                     (gnus-method-option-p method 'post-mail))
602             (push method post-methods)))
603         ;; Create a name-method alist.
604         (setq method-alist
605               (mapcar 
606                (lambda (m)
607                  (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
608                post-methods))
609         ;; Query the user.
610         (cadr
611          (assoc
612           (setq gnus-last-posting-server
613                 (if (and silent
614                          gnus-last-posting-server)
615                     ;; Just use the last value.
616                     gnus-last-posting-server
617                   (completing-read
618                    "Posting method: " method-alist nil t
619                    (cons (or gnus-last-posting-server "") 0))))
620           method-alist))))
621      ;; Override normal method.
622      ((and gnus-post-method
623            (or (gnus-method-option-p group-method 'post)
624                (gnus-method-option-p group-method 'post-mail)))
625       gnus-post-method)
626      ;; Perhaps this is a mail group?
627      ((and (not (gnus-member-of-valid 'post group))
628            (not (gnus-method-option-p group-method 'post-mail)))
629       group-method)
630      ;; Use the normal select method.
631      (t gnus-select-method))))
632
633 (defun gnus-news-group-p (group &optional article)
634   "Return non-nil if GROUP (and ARTICLE) come from a news server."
635   (or (gnus-member-of-valid 'post group) ; Ordinary news group.
636       (and (gnus-member-of-valid 'post-mail group) ; Combined group.
637            (eq (gnus-request-type group article) 'news))))
638            
639 (defun gnus-inews-news (&optional use-group-method)
640   "Send a news message.
641
642 If given a non-zero prefix and the group is a foreign group, this
643 function will attempt to use the foreign server to post the article.
644
645 If given an zero prefix, the user will be prompted for a posting
646 method to use."
647   (interactive "P")
648   (unless (gnus-alive-p)
649     (error "Gnus is dead; you can't post anything."))
650   (or gnus-current-select-method
651       (setq gnus-current-select-method gnus-select-method))
652   (let* ((case-fold-search nil)
653          (reply gnus-article-reply)
654          error post-result)
655     (save-excursion
656       (gnus-start-news-server)          ;Use default server.
657       (widen)
658       (goto-char (point-min))
659       (run-hooks 'news-inews-hook)
660
661       ;; Send to server. 
662       (gnus-message 5 "Posting to USENET...")
663       (setq post-result (funcall gnus-inews-article-function use-group-method))
664       (cond 
665        ((eq post-result 'illegal)
666         (setq error t)
667         (ding))
668        (post-result
669         (gnus-message 5 "Posting to USENET...done")
670         (set-buffer-modified-p nil)
671         ;; We mark the article as replied.
672         (when (gnus-buffer-exists-p (car-safe reply))
673           (save-excursion
674             (set-buffer gnus-summary-buffer)
675             (gnus-summary-mark-article-as-replied (cdr reply)))))
676        (t
677         ;; We cannot signal an error.
678         (setq error t)
679         (ding)
680         (gnus-message 
681          1 "Article rejected: %s" 
682          (gnus-status-message
683           (gnus-post-method gnus-newsgroup-name use-group-method t))))))
684
685     (let ((conf gnus-prev-winconf))
686       (unless error
687         (bury-buffer)
688         ;; Restore last window configuration.
689         (and conf (set-window-configuration conf))))))
690
691 (defun gnus-inews-narrow-to-headers ()
692   (widen)
693   (narrow-to-region
694    (goto-char (point-min))
695    (or (and (re-search-forward 
696              (concat "^" (regexp-quote mail-header-separator) "$") nil t)
697             (match-beginning 0))
698        (point-max)))
699   (goto-char (point-min)))
700
701 (defun gnus-inews-send-mail-copy ()
702   ;; Mail the message if To, Bcc or Cc exists.
703   (let* ((types '("to" "bcc" "cc"))
704          (ty types)
705          (buffer (current-buffer))
706          fcc)
707     (save-restriction
708       (widen)
709       (gnus-inews-narrow-to-headers)
710
711       (while ty
712         (or (mail-fetch-field (car ty) nil t)
713             (setq types (delete (car ty) types)))
714         (setq ty (cdr ty)))
715
716       (if (not types)
717           ;; We do not want to send mail.
718           ()
719         (gnus-message 5 "Sending via mail...")
720         (widen)
721         (save-excursion
722           ;; We copy the article over to a temp buffer since we are
723           ;; going to modify it a little.  
724           (nnheader-set-temp-buffer " *Gnus-mailing*")
725           (insert-buffer-substring buffer)
726           ;; We remove Fcc, because we don't want the mailer to see
727           ;; that header.  
728           (gnus-inews-narrow-to-headers)
729           (nnheader-remove-header "fcc")
730
731           ;; Insert the X-Courtesy-Message header.
732           (and (or (member "to" types)
733                    (member "cc" types))
734                (progn
735                 (goto-char (point-max))
736                 (insert "Posted-To: " 
737                         (mail-fetch-field "newsgroups") "\n")))
738           
739           (widen)
740           
741           (if (and gnus-mail-courtesy-message
742                    (or (member "to" types)
743                        (member "cc" types)))
744               ;; We only want to insert the courtesy mail message if
745               ;; we use To or Cc; Bcc should not have one. Well, if
746               ;; both Bcc and To are present, it will get one
747               ;; anyway.
748               (progn
749                 ;; Insert "courtesy" mail message.
750                 (goto-char (point-min))
751                 (re-search-forward
752                  (concat "^" (regexp-quote mail-header-separator) "$"))
753                 (forward-line 1)
754                 (insert gnus-mail-courtesy-message)))
755
756           (gnus-mail-send t)
757           (kill-buffer (current-buffer))
758           (gnus-message 5 "Sending via mail...done"))))))
759
760 (defun gnus-inews-remove-headers-after-mail ()
761   (save-excursion
762     (save-restriction
763       (let ((case-fold-search t))
764         (gnus-inews-narrow-to-headers)
765         ;; Remove Bcc completely.
766         (nnheader-remove-header "bcc")
767         ;; We transform To and Cc headers to avoid re-mailing if the user
768         ;; accidentally (or purposefully) leans on the `C-c C-c' keys
769         ;; and the news server rejects the posting.
770         (while (re-search-forward "^\\(to\\|[bcf]cc\\|cc\\):" nil t)
771           (beginning-of-line)
772           (insert "X-"))
773         (widen)))))
774
775 (defun gnus-inews-dex-headers ()
776   "Remove \"X-\" prefixes from To and Cc headers."
777   (save-excursion
778     (save-restriction
779       (let ((case-fold-search t))
780         (nnheader-narrow-to-headers)
781         (while (re-search-forward "^X-\\(to\\|[bcf]cc\\|cc\\):" nil t)
782           (beginning-of-line)
783           (delete-char 2))
784         (widen)))))
785
786 (defun gnus-inews-remove-empty-headers ()
787   "Remove empty headers from news and mail.
788 The buffer should be narrowed to the headers before this function is
789 called."
790   (save-excursion
791     (goto-char (point-min))
792     (while (re-search-forward "^[^ \t:]+:\\([ \t]*\n\\)+[^ \t]" nil t)
793       (delete-region (match-beginning 0) (1- (match-end 0)))
794       (beginning-of-line))))
795
796 (defun gnus-inews-check-post ()
797   "Check whether the post looks ok."
798   (or
799    (not gnus-check-before-posting)
800    (and 
801     ;; We narrow to the headers and check them first.
802     (save-excursion
803       (save-restriction
804         (gnus-inews-narrow-to-headers)
805         (and 
806          ;; Check for commands in Subject.
807          (or 
808           (gnus-check-before-posting 'subject-cmsg)
809           (save-excursion
810             (if (string-match "^cmsg " (mail-fetch-field "subject"))
811                 (gnus-y-or-n-p
812                  "The control code \"cmsg \" is in the subject. Really post? ")
813               t)))
814          ;; Check for multiple identical headers.
815          (or (gnus-check-before-posting 'multiple-headers)
816              (save-excursion
817                (let (found)
818                  (while (and (not found) 
819                              (re-search-forward "^[^ \t:]+: " nil t))
820                    (save-excursion
821                      (or (re-search-forward 
822                           (concat "^" (setq found
823                                             (buffer-substring 
824                                              (match-beginning 0) 
825                                              (- (match-end 0) 2))))
826                           nil t)
827                          (setq found nil))))
828                  (if found
829                      (gnus-y-or-n-p 
830                       (format "Multiple %s headers. Really post? " found))
831                    t))))
832          ;; Check for Version and Sendsys.
833          (or (gnus-check-before-posting 'sendsys)
834              (save-excursion
835                (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
836                    (gnus-y-or-n-p
837                     (format "The article contains a %s command. Really post? "
838                             (buffer-substring (match-beginning 0) 
839                                               (1- (match-end 0)))))
840                  t)))
841          ;; Check for Approved.
842          (or (gnus-check-before-posting 'approved)
843              (save-excursion
844                (if (re-search-forward "^Approved:" nil t)
845                    (gnus-y-or-n-p
846                     "The article contains an Approved header. Really post? ")
847                  t)))
848          ;; Check whether a Followup-To has redirected the newsgroup.
849          (or
850           (gnus-check-before-posting 'redirected-followup)
851           (not gnus-newsgroup-followup)
852           (save-excursion
853             (let ((followups (gnus-tokenize-header
854                               (mail-fetch-field "Newsgroups")))
855                   (newsgroups (gnus-tokenize-header
856                                (car gnus-newsgroup-followup))))
857               (while (and followups
858                           (member (car followups) newsgroups))
859                 (setq followups (cdr followups)))
860               (if (not followups)
861                   t
862                 (gnus-y-or-n-p
863                  "Followup redirected from original newsgroups.  Really post? "
864                  )))))
865          ;; Check the Message-ID header.
866          (or (gnus-check-before-posting 'message-id)
867              (save-excursion
868                (let* ((case-fold-search t)
869                       (message-id (mail-fetch-field "message-id")))
870                  (or (not message-id)
871                      (and (string-match "@" message-id)
872                           (string-match "@[^\\.]*\\." message-id))
873                      (gnus-y-or-n-p
874                       (format 
875                        "The Message-ID looks strange: \"%s\". Really post? "
876                        message-id))))))
877          ;; Check whether any headers are empty.
878          (or (gnus-check-before-posting 'empty-headers)
879              (save-excursion
880                (let ((post t))
881                  (goto-char (point-min))
882                  (while (and post (not (eobp)))
883                    (when (looking-at "\\([^ :]+\\):[ \t]\n[^ \t]")
884                      (setq post
885                            (gnus-y-or-n-p
886                             (format
887                              "The %s header is empty.  Really post? "
888                              (match-string 1)))))
889                    (forward-line 1))
890                  post)))
891          ;; Check the From header.
892          (or 
893           (gnus-check-before-posting 'from)
894           (save-excursion
895             (let* ((case-fold-search t)
896                    (from (mail-fetch-field "from")))
897               (cond
898                ((not from)
899                 (gnus-y-or-n-p "There is no From line. Really post? "))
900                ((not (string-match "@[^\\.]*\\." from))
901                 (gnus-y-or-n-p
902                  (format 
903                   "The address looks strange: \"%s\". Really post? " from)))
904                ((string-match "(.*).*(.*)" from)
905                 (gnus-y-or-n-p
906                  (format
907                   "The From header looks strange: \"%s\". Really post? " 
908                   from)))
909                ((string-match "<[^>]+> *$" from)
910                 (let ((name (substring from 0 (match-beginning 0))))
911                   (or 
912                    (string-match "^ *\"[^\"]*\" *$" name)
913                    (not (string-match "[][.!()<>@,;:\\]" name))
914                    (gnus-y-or-n-p
915                     (format
916                      "The From header name has bogus characters.  Really post? " 
917                      from)))))
918                (t t)))))
919          )))
920     ;; Check for long lines.
921     (or (gnus-check-before-posting 'long-lines)
922         (save-excursion
923           (goto-char (point-min))
924           (re-search-forward
925            (concat "^" (regexp-quote mail-header-separator) "$"))
926           (while (and
927                   (progn
928                     (end-of-line)
929                     (< (current-column) 80))
930                   (zerop (forward-line 1))))
931           (or (bolp)
932               (eobp)
933               (gnus-y-or-n-p
934                "You have lines longer than 79 characters.  Really post? "))))
935     ;; Check whether the article is empty.
936     (or (gnus-check-before-posting 'empty)
937         (save-excursion
938           (goto-char (point-min))
939           (re-search-forward
940            (concat "^" (regexp-quote mail-header-separator) "$"))
941           (forward-line 1)
942           (or (re-search-forward "[^ \n\t]" nil t)
943               (gnus-y-or-n-p "Empty article.  Really post?"))))
944     ;; Check for control characters.
945     (or (gnus-check-before-posting 'control-chars)
946         (save-excursion
947           (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
948               (gnus-y-or-n-p 
949                "The article contains control characters. Really post? ")
950             t)))
951     ;; Check excessive size.
952     (or (gnus-check-before-posting 'size)
953         (if (> (buffer-size) 60000)
954             (gnus-y-or-n-p
955              (format "The article is %d octets long. Really post? "
956                      (buffer-size)))
957           t))
958     ;; Use the (size . checksum) variable to see whether the
959     ;; article is empty or has only quoted text.
960     (or
961      (gnus-check-before-posting 'new-text)
962      (not gnus-article-check-size)
963      (if (and (= (buffer-size) (car gnus-article-check-size))
964               (= (gnus-article-checksum) (cdr gnus-article-check-size)))
965          (gnus-y-or-n-p
966           "It looks like there's no new text in your article. Really post? ")
967        t))
968     ;; Check the length of the signature.
969     (or (gnus-check-before-posting 'signature)
970         (progn
971           (goto-char (point-max))
972           (if (not (re-search-backward gnus-signature-separator nil t))
973               t
974             (if (> (count-lines (point) (point-max)) 5)
975                 (gnus-y-or-n-p
976                  (format
977                   "Your .sig is %d lines; it should be max 4.  Really post? "
978                   (count-lines (point) (point-max))))
979               t)))))))
980
981 (defun gnus-tokenize-header (header &optional separator)
982   "Split HEADER into a list of header elements.
983 \",\" is used as the separator."
984   (let* ((beg 0)
985          (separator (or separator ","))
986          (regexp
987           (format "[ \t]*\\([^%s]+\\)?\\(%s\\|\\'\\)" separator separator))
988          elems)
989     (while (and (string-match regexp header beg)
990                 (< beg (length header)))
991       (when (match-beginning 1)
992         (push (match-string 1 header) elems))
993       (setq beg (match-end 0)))
994     (nreverse elems)))
995
996 (defun gnus-article-checksum ()
997   (let ((sum 0))
998     (save-excursion
999       (while (not (eobp))
1000         (setq sum (logxor sum (following-char)))
1001         (forward-char 1)))
1002     sum))
1003
1004 ;; Returns non-nil if this type is not to be checked.
1005 (defun gnus-check-before-posting (type)
1006   (not 
1007    (or (not gnus-check-before-posting)
1008        (if (listp gnus-check-before-posting)
1009            (memq type gnus-check-before-posting)
1010          t))))
1011
1012 (defun gnus-cancel-news ()
1013   "Cancel an article you posted."
1014   (interactive)
1015   (if (or gnus-expert-user
1016           (gnus-yes-or-no-p "Do you really want to cancel this article? "))
1017       (let ((from nil)
1018             (newsgroups nil)
1019             (message-id nil)
1020             (distribution nil))
1021         (or (gnus-news-group-p gnus-newsgroup-name)
1022             (error "This backend does not support canceling"))
1023         (save-excursion
1024           ;; Get header info. from original article.
1025           (save-restriction
1026             (gnus-article-show-all-headers)
1027             (goto-char (point-min))
1028             (search-forward "\n\n" nil 'move)
1029             (narrow-to-region (point-min) (point))
1030             (setq from (mail-fetch-field "from"))
1031             (setq newsgroups (mail-fetch-field "newsgroups"))
1032             (setq message-id (mail-fetch-field "message-id"))
1033             (setq distribution (mail-fetch-field "distribution")))
1034           ;; Verify if the article is absolutely user's by comparing
1035           ;; user id with value of its From: field.
1036           (if (not
1037                (string-equal
1038                 (downcase (mail-strip-quoted-names from))
1039                 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
1040               (progn
1041                 (ding) (gnus-message 3 "This article is not yours.")
1042                 nil)
1043             ;; Make control article.
1044             (set-buffer (get-buffer-create " *Gnus-canceling*"))
1045             (buffer-disable-undo (current-buffer))
1046             (erase-buffer)
1047             (insert "Newsgroups: " newsgroups "\n"
1048                     "From: " (gnus-inews-user-name) "\n"
1049                     "Subject: cancel " message-id "\n"
1050                     "Control: cancel " message-id "\n"
1051                     (if distribution
1052                         (concat "Distribution: " distribution "\n")
1053                       "")
1054                     mail-header-separator "\n"
1055                     "This is a cancel message from " from ".\n")
1056             ;; Send the control article to NNTP server.
1057             (gnus-message 5 "Canceling your article...")
1058             (prog1
1059                 (if (funcall gnus-inews-article-function)
1060                     (gnus-message 5 "Canceling your article...done")
1061                   (progn
1062                     (ding) 
1063                     (gnus-message 1 "Cancel failed; %s" 
1064                                   (gnus-status-message gnus-newsgroup-name))
1065                     nil)
1066                   t)
1067               ;; Kill the article buffer.
1068               (kill-buffer (current-buffer))))))))
1069
1070 (defun gnus-inews-remove-signature ()
1071   "Remove the signature from the text between point and mark.
1072 The text will also be indented the normal way.
1073 This function can be used in `mail-citation-hook', for instance."
1074   (save-excursion
1075     (let ((start (point))
1076           mark)
1077     (if (not (re-search-forward gnus-signature-separator (mark t) t))
1078         ;; No signature here, so we just indent the cited text.
1079         (mail-indent-citation)
1080       ;; Find the last non-empty line.
1081       (forward-line -1)
1082       (while (looking-at "[ \t]*$")
1083         (forward-line -1))
1084       (forward-line 1)
1085       (setq mark (set-marker (make-marker) (point)))
1086       (goto-char start)
1087       (mail-indent-citation)
1088       ;; Enable undoing the deletion.
1089       (undo-boundary)
1090       (delete-region mark (mark t))
1091       (set-marker mark nil)))))
1092
1093 \f
1094
1095 ;; Dummy to avoid byte-compile warning.
1096 (defvar nnspool-rejected-article-hook)
1097
1098 (defun gnus-inews-article (&optional use-group-method)
1099   "Post an article in current buffer using NNTP protocol."
1100   (let ((artbuf (current-buffer))
1101         gcc result)
1102     (widen)
1103     (goto-char (point-max))
1104     ;; Require a newline at the end of the buffer since inews may
1105     ;; append a .signature.
1106     (or (= (preceding-char) ?\n)
1107         (insert ?\n))
1108     ;; Prepare article headers.  All message body such as signature
1109     ;; must be inserted before Lines: field is prepared.
1110     (save-restriction
1111       (gnus-inews-narrow-to-headers)
1112       ;; Fix some headers.
1113       (gnus-inews-cleanup-headers)
1114       ;; Remove some headers.
1115       (gnus-inews-remove-headers)
1116       ;; Insert some headers.
1117       (gnus-inews-insert-headers)
1118       ;; Let the user do all of the above.
1119       (run-hooks 'gnus-inews-article-header-hook)
1120       ;; Copy the Gcc header, if any.
1121       (setq gcc (mail-fetch-field "gcc"))
1122       (widen))
1123     ;; Check whether the article is a good Net Citizen.
1124     (if (not (gnus-inews-check-post))
1125         ;; Aber nein!
1126         'illegal
1127       ;; We fudge a hook for nnspool.
1128       (setq nnspool-rejected-article-hook
1129             `((lambda ()
1130                 (condition-case ()
1131                     (save-excursion
1132                       (set-buffer ,(buffer-name))
1133                       (gnus-associate-buffer-with-draft nil 'silent))
1134                   (error 
1135                    (ding)
1136                    (gnus-message 
1137                     1 "Couldn't enter rejected article into draft group"))))))
1138                                    
1139       ;; Looks ok, so we do the nasty.
1140       (save-excursion
1141         ;; This hook may insert a signature.
1142         (save-excursion
1143           (goto-char (point-min))
1144           (let ((gnus-newsgroup-name (or (mail-fetch-field "newsgroups")
1145                                          gnus-newsgroup-name)))
1146             (run-hooks 'gnus-prepare-article-hook)))
1147         ;; Send off copies using mail, if that is wanted.
1148         (gnus-inews-send-mail-copy)
1149         ;; Remove more headers.
1150         (gnus-inews-remove-headers-after-mail)
1151         ;; Copy the article over to a temp buffer.
1152         (nnheader-set-temp-buffer " *Gnus-posting*")
1153         (insert-buffer-substring artbuf)
1154         ;; Remove the header separator.
1155         (goto-char (point-min))
1156         (re-search-forward
1157          (concat "^" (regexp-quote mail-header-separator) "$"))
1158         (replace-match "" t t)
1159         ;; Remove X- prefixes to headers.
1160         (gnus-inews-dex-headers)
1161         ;; Run final inews hooks.  This hook may do FCC.
1162         ;; The article must be saved before being posted because
1163         ;; `gnus-request-post' modifies the buffer.
1164         (run-hooks 'gnus-inews-article-hook)
1165         ;; Copy the article over to some group, possibly.
1166         (and gcc (gnus-inews-do-gcc gcc))
1167         ;; Post the article.
1168         (setq result (gnus-request-post
1169                       (gnus-post-method gnus-newsgroup-name use-group-method)))
1170         (kill-buffer (current-buffer)))
1171       (run-hooks 'gnus-message-sent-hook)
1172       ;; If the posting was unsuccessful (that it, it was rejected) we
1173       ;; put it into the draft group.
1174       (or result (gnus-associate-buffer-with-draft))
1175       result)))
1176
1177 (defun gnus-inews-cleanup-headers ()
1178   ;; Remove empty lines in the header.
1179   (save-restriction
1180     (gnus-inews-narrow-to-headers)
1181     (while (re-search-forward "^[ \t]*\n" nil t)
1182       (replace-match "" t t)))
1183
1184   ;; Correct newsgroups field: change sequence of spaces to comma and 
1185   ;; eliminate spaces around commas.  Eliminate imbedded line breaks.
1186   (goto-char (point-min))
1187   (if (re-search-forward "^Newsgroups: +" nil t)
1188       (save-restriction
1189         (narrow-to-region
1190          (point)
1191          (if (re-search-forward "^[^ \t]" nil t)
1192              (match-beginning 0)
1193            (forward-line 1)
1194            (point)))
1195         (goto-char (point-min))
1196         (while (re-search-forward "\n[ \t]+" nil t)
1197           (replace-match " " t t))      ;No line breaks (too confusing)
1198         (goto-char (point-min))
1199         (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
1200           (replace-match "," t t))
1201         (goto-char (point-min))
1202         ;; Remove a trailing comma.
1203         (if (re-search-forward ",$" nil t)
1204             (replace-match "" t t))))
1205
1206   ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
1207   ;; Help save the the world!
1208   (or 
1209    gnus-expert-user
1210    (let ((newsgroups (mail-fetch-field "newsgroups"))
1211          (followup-to (mail-fetch-field "followup-to"))
1212          groups to)
1213      (if (and newsgroups
1214               (string-match "," newsgroups) (not followup-to))
1215          (progn
1216            (while (string-match "," newsgroups)
1217              (setq groups
1218                    (cons (list (substring newsgroups 0 (match-beginning 0)))
1219                          groups))
1220              (setq newsgroups (substring newsgroups (match-end 0))))
1221            (setq groups (nreverse (cons (list newsgroups) groups)))
1222
1223            (setq to (completing-read 
1224                      "Followups to: (default all groups) " groups))
1225            (if (> (length to) 0)
1226                (progn
1227                  (goto-char (point-min))
1228                  (insert "Followup-To: " to "\n")))))))
1229
1230   ;; Cleanup Followup-To.
1231   (goto-char (point-min))
1232   (if (search-forward-regexp "^Followup-To: +" nil t)
1233       (save-restriction
1234         (narrow-to-region
1235          (point)
1236          (if (re-search-forward "^[^ \t]" nil 'end)
1237              (match-beginning 0)
1238            (point-max)))
1239         (goto-char (point-min))
1240         (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
1241         (goto-char (point-min))
1242         (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ","))))
1243
1244 (defun gnus-inews-remove-headers ()
1245   (let ((case-fold-search t)
1246         (headers gnus-removable-headers))
1247     ;; Remove toxic headers.
1248     (while headers
1249       (goto-char (point-min))
1250       (and (re-search-forward 
1251             (concat "^" (downcase (format "%s" (car headers))))
1252             nil t)
1253            (delete-region (progn (beginning-of-line) (point))
1254                           (progn (forward-line 1) (point))))
1255       (setq headers (cdr headers)))))
1256
1257 ;;; Since the X-Newsreader/X-Mailer are ``vanity'' headers, they might
1258 ;;; as well include the Emacs version as well.
1259 ;;; The following function works with later GNU Emacs, and XEmacs.
1260 (defun gnus-extended-version ()
1261   "Stringified Gnus version and Emacs version"
1262   (interactive)
1263   (concat
1264    gnus-version
1265    "/"
1266    (cond
1267     ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
1268      (concat "Emacs " (substring emacs-version
1269                                  (match-beginning 1)
1270                                  (match-end 1))))
1271     ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)" emacs-version)
1272      (concat (substring emacs-version
1273                         (match-beginning 1)
1274                         (match-end 1))
1275              (format " %d.%d" emacs-major-version emacs-minor-version)))
1276     (t emacs-version))))
1277
1278 (defun gnus-inews-insert-headers (&optional headers)
1279   "Prepare article headers.
1280 Headers already prepared in the buffer are not modified.
1281 Headers in `gnus-required-headers' will be generated."
1282   (let* ((Date (gnus-inews-date))
1283          (Message-ID (gnus-inews-message-id))
1284          (Organization (gnus-inews-organization))
1285          (From (gnus-inews-user-name))
1286          (Path (gnus-inews-path))
1287          (Subject nil)
1288          (Newsgroups nil)
1289          (In-Reply-To (gnus-inews-in-reply-to))
1290          (To nil)
1291          (Distribution (gnus-inews-distribution))
1292          (Lines (gnus-inews-lines))
1293          (X-Newsreader (gnus-extended-version))
1294          (X-Mailer X-Newsreader)
1295          (Expires (gnus-inews-expires))
1296          (headers (or headers gnus-required-headers))
1297          (case-fold-search t)
1298          header value elem)
1299     ;; First we remove any old generated headers.
1300     (let ((headers gnus-deletable-headers))
1301       (while headers
1302         (goto-char (point-min))
1303         (and (re-search-forward 
1304               (concat "^" (symbol-name (car headers)) ": *") nil t)
1305              (get-text-property (1+ (match-beginning 0)) 'gnus-deletable)
1306              (gnus-delete-line))
1307         (setq headers (cdr headers))))
1308     ;; If there are References, and no "Re: ", then the thread has
1309     ;; changed name. See Son-of-1036.
1310     (if (and (mail-fetch-field "references")
1311              (get-buffer gnus-article-buffer))
1312         (let ((psubject (gnus-simplify-subject-re
1313                          (mail-fetch-field "subject"))))
1314           (or (and psubject gnus-reply-subject 
1315                    (string= (gnus-simplify-subject-re gnus-reply-subject)
1316                             psubject))
1317               (progn
1318                 (string-match "@" Message-ID)
1319                 (setq Message-ID
1320                       (concat (substring Message-ID 0 (match-beginning 0))
1321                               "_-_" 
1322                               (substring Message-ID (match-beginning 0))))))))
1323     ;; Go through all the required headers and see if they are in the
1324     ;; articles already. If they are not, or are empty, they are
1325     ;; inserted automatically - except for Subject, Newsgroups and
1326     ;; Distribution. 
1327     (while headers
1328       (goto-char (point-min))
1329       (setq elem (pop headers))
1330       (if (consp elem)
1331           (setq header (car elem))
1332         (setq header elem))
1333       (when (or (not (re-search-forward 
1334                       (concat "^" (downcase (symbol-name header)) ":") nil t))
1335                 (progn
1336                   ;; The header was found. We insert a space after the
1337                   ;; colon, if there is none.
1338                   (if (/= (following-char) ? ) (insert " "))
1339                   ;; Find out whether the header is empty...
1340                   (looking-at "[ \t]*$")))
1341         ;; So we find out what value we should insert.
1342         (setq value
1343               (cond 
1344                ((and (consp elem) (eq (car elem) 'optional))
1345                 ;; This is an optional header.  If the cdr of this
1346                 ;; is something that is nil, then we do not insert
1347                 ;; this header.
1348                 (setq header (cdr elem))
1349                 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
1350                     (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
1351                ((consp elem)
1352                 ;; The element is a cons.  Either the cdr is a
1353                 ;; string to be inserted verbatim, or it is a
1354                 ;; function, and we insert the value returned from
1355                 ;; this function.
1356                 (or (and (stringp (cdr elem)) (cdr elem))
1357                     (and (fboundp (cdr elem)) (funcall (cdr elem)))))
1358                ((and (boundp header) (symbol-value header))
1359                 ;; The element is a symbol.  We insert the value
1360                 ;; of this symbol, if any.
1361                 (symbol-value header))
1362                (t
1363                 ;; We couldn't generate a value for this header,
1364                 ;; so we just ask the user.
1365                 (read-from-minibuffer
1366                  (format "Empty header for %s; enter value: " header)))))
1367         ;; Finally insert the header.
1368         (when (and value 
1369                    (not (equal value "")))
1370           (save-excursion
1371             (if (bolp)
1372                 (progn
1373                   ;; This header didn't exist, so we insert it.
1374                   (goto-char (point-max))
1375                   (insert (symbol-name header) ": " value "\n")
1376                   (forward-line -1))
1377               ;; The value of this header was empty, so we clear
1378               ;; totally and insert the new value.
1379               (delete-region (point) (gnus-point-at-eol))
1380               (insert value))
1381             ;; Add the deletable property to the headers that require it.
1382             (and (memq header gnus-deletable-headers)
1383                  (progn (beginning-of-line) (looking-at "[^:]+: "))
1384                  (add-text-properties 
1385                   (point) (match-end 0)
1386                   '(gnus-deletable t face italic) (current-buffer)))))))
1387     ;; Insert new Sender if the From is strange. 
1388     (let ((from (mail-fetch-field "from"))
1389           (sender (mail-fetch-field "sender"))
1390           (secure-sender (gnus-inews-real-user-address)))
1391       (when (and from 
1392                  (not (gnus-check-before-posting 'sender))
1393                  (not (string=
1394                        (downcase (cadr (gnus-extract-address-components from)))
1395                        (downcase (gnus-inews-real-user-address))))
1396                  (or (null sender)
1397                      (not 
1398                       (string=
1399                        (downcase
1400                         (cadr (gnus-extract-address-components sender)))
1401                        (downcase secure-sender)))))
1402         (goto-char (point-min))    
1403         ;; Rename any old Sender headers to Original-Sender.
1404         (when (re-search-forward "^Sender:" nil t)
1405           (beginning-of-line)
1406           (insert "Original-")
1407           (beginning-of-line))
1408         (insert "Sender: " secure-sender "\n")))))
1409
1410 (defun gnus-inews-insert-signature ()
1411   "Insert a signature file.
1412 If `gnus-signature-function' is bound and returns a string, this
1413 string is used instead of the variable `gnus-signature-file'.
1414 In either case, if the string is a file name, this file is
1415 inserted. If the string is not a file name, the string itself is
1416 inserted. 
1417
1418 If you never want any signature inserted, set both of these variables to
1419 nil."
1420   (save-excursion
1421     (let ((signature 
1422            (or (and gnus-signature-function
1423                     (funcall gnus-signature-function gnus-newsgroup-name))
1424                gnus-signature-file)))
1425       (if (and signature
1426                (or (file-exists-p signature)
1427                    (string-match " " signature)
1428                    (not (string-match 
1429                          "^/[^/]+/" (expand-file-name signature)))))
1430           (progn
1431             (goto-char (point-max))
1432             (if (and mail-signature (search-backward "\n-- \n" nil t))
1433                 ()
1434               ;; Delete any previous signatures.
1435               (if (search-backward "\n-- \n" nil t)
1436                   (delete-region (point) (point-max)))
1437               (or (eolp) (insert "\n"))
1438               (insert "-- \n")
1439               (if (file-exists-p signature)
1440                   (insert-file-contents signature)
1441                 (insert signature))
1442               (goto-char (point-max))
1443               (or (bolp) (insert "\n"))))))))
1444
1445 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1446 (defun gnus-inews-insert-mime-headers ()
1447   (goto-char (point-min))
1448   (let ((mail-header-separator 
1449          (progn 
1450            (goto-char (point-min))
1451            (if (and (search-forward (concat "\n" mail-header-separator "\n")
1452                                     nil t)
1453                     (not (search-backward "\n\n" nil t)))
1454                mail-header-separator
1455              ""))))
1456     (or (mail-position-on-field "Mime-Version")
1457         (insert "1.0")
1458         (cond ((save-restriction
1459                  (widen)
1460                  (goto-char (point-min))
1461                  (re-search-forward "[\200-\377]" nil t))
1462                (or (mail-position-on-field "Content-Type")
1463                    (insert "text/plain; charset=ISO-8859-1"))
1464                (or (mail-position-on-field "Content-Transfer-Encoding")
1465                    (insert "8bit")))
1466               (t (or (mail-position-on-field "Content-Type")
1467                      (insert "text/plain; charset=US-ASCII"))
1468                  (or (mail-position-on-field "Content-Transfer-Encoding")
1469                      (insert "7bit")))))))
1470
1471 (defun gnus-inews-do-fcc ()
1472   "Process Fcc headers in the current buffer.
1473 Unless the first character of the field is `|', the article is saved
1474 to the specified file using the function specified by the variable
1475 gnus-author-copy-saver.  The default function rmail-output saves in
1476 Unix mailbox format.
1477
1478 If the first character is `|', the contents of the article is sent to
1479 a program specified by the rest of the value."
1480   (let ((case-fold-search t)            ;Should ignore case.
1481         list file)
1482     (save-excursion
1483       (save-restriction
1484         (nnheader-narrow-to-headers)
1485         (while (setq file (mail-fetch-field "fcc"))
1486           (push file list)
1487           (nnheader-remove-header "fcc" nil t))
1488         ;; Process FCC operations.
1489         (widen)
1490         (while list
1491           (setq file (pop list))
1492           (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
1493               ;; Pipe the article to the program in question.
1494               (call-process-region (point-min) (point-max) shell-file-name
1495                                    nil nil nil "-c" (match-string 1 file))
1496             ;; Save the article.
1497             (setq file (expand-file-name file))
1498             (gnus-make-directory (file-name-directory file))
1499             (if (and gnus-author-copy-saver
1500                      (not (eq gnus-author-copy-saver 'rmail-output)))
1501                 (funcall gnus-author-copy-saver file)
1502               (if (and (file-readable-p file) (mail-file-babyl-p file))
1503                   (gnus-output-to-rmail file)
1504                 (let ((mail-use-rfc822 t))
1505                   (rmail-output file 1 t t))))))))))
1506
1507 (defun gnus-inews-path ()
1508   "Return uucp path."
1509   (let ((login-name (gnus-inews-login-name)))
1510     (cond ((null gnus-use-generic-path)
1511            (concat (nth 1 gnus-select-method) "!" login-name))
1512           ((stringp gnus-use-generic-path)
1513            ;; Support GENERICPATH.  Suggested by vixie@decwrl.dec.com.
1514            (concat gnus-use-generic-path "!" login-name))
1515           (t login-name))))
1516
1517 (defun gnus-inews-user-name ()
1518   "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1519   (let ((full-name (gnus-inews-full-name))
1520         (address (if (or gnus-user-login-name gnus-use-generic-from
1521                          gnus-local-domain (getenv "DOMAINNAME"))
1522                      (concat (gnus-inews-login-name) "@"
1523                              (gnus-inews-domain-name gnus-use-generic-from))
1524                    user-mail-address))) 
1525     (or gnus-user-from-line
1526         (concat address
1527                 ;; User's full name.
1528                 (cond ((string-equal full-name "&") ;Unix hack.
1529                        (concat " (" (user-login-name) ")"))
1530                       ((string-match "[^ ]+@[^ ]+ +(.*)" address)
1531                        "")
1532                       (t
1533                        (concat " (" full-name ")")))))))
1534
1535 (defun gnus-inews-real-user-address ()
1536   "Return the \"real\" user address.
1537 This function tries to ignore all user modifications, and 
1538 give as trustworthy answer as possible."
1539   (concat (user-login-name) "@" (system-name)))
1540
1541 (defun gnus-inews-login-name ()
1542   "Return login name."
1543   (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1544
1545 (defun gnus-inews-full-name ()
1546   "Return full user name."
1547   (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1548
1549 (defun gnus-inews-domain-name (&optional genericfrom)
1550   "Return user's domain name.
1551 If optional argument GENERICFROM is a string, use it as the domain
1552 name; if it is non-nil, strip off local host name from the domain name.
1553 If the function `system-name' returns full internet name and the
1554 domain is undefined, the domain name is got from it."
1555   (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1556       (let* ((system-name (system-name))
1557              (domain 
1558               (or (if (stringp genericfrom) genericfrom)
1559                   (getenv "DOMAINNAME")
1560                   (and (boundp 'mail-host-address)
1561                        mail-host-address)
1562                   gnus-local-domain
1563                   ;; Function `system-name' may return full internet name.
1564                   ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1565                   (if (string-match "\\.." system-name)
1566                       ;; Some machines return "name.", and that's not
1567                       ;; very nice. 
1568                       (substring system-name (1- (match-end 0))))
1569                   (read-string "Domain name (no host): ")))
1570              (host (or (if (string-match "\\." system-name)
1571                            (substring system-name 0 (match-beginning 0)))
1572                        system-name)))
1573         (if (string-equal "." (substring domain 0 1))
1574             (setq domain (substring domain 1)))
1575         ;; Support GENERICFROM as same as standard Bnews system.
1576         ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1577         (cond ((null genericfrom)
1578                (concat host "." domain))
1579               ;;((stringp genericfrom) genericfrom)
1580               (t domain)))
1581     (if (string-match "\\." (system-name))
1582         (system-name)
1583       (if (string-match "@\\([^ ]+\\)\\($\\| \\)" user-mail-address)
1584           (substring user-mail-address 
1585                      (match-beginning 1) (match-end 1))
1586         "bogus-domain"))))
1587
1588 (defun gnus-inews-full-address ()
1589   (let ((domain (gnus-inews-domain-name))
1590         (system (system-name))
1591         (case-fold-search t))
1592     (if (string-match "\\." system) system
1593       (if (string-match (concat "^" (regexp-quote system)) domain) domain
1594         (concat system "." domain)))))
1595
1596 (defun gnus-inews-expires ()
1597   "Return an Expires header based on `gnus-article-expires'."
1598   (let ((current (current-time))
1599         (future (* 1.0 gnus-article-expires 60 60 24)))
1600     ;; Add the future to current.
1601     (setcar current (+ (car current) (round (/ future (expt 2 16)))))
1602     (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
1603     ;; Return the date in the future in UT.
1604     (timezone-make-date-arpa-standard 
1605      (current-time-string current) (current-time-zone) '(0 "UT"))))
1606
1607 (defun gnus-inews-distribution ()
1608   "Return the current Distribution header, if any."
1609   (when (and gnus-distribution-function
1610              (fboundp gnus-distribution-function))
1611     (funcall gnus-distribution-function (or gnus-newsgroup-name ""))))
1612
1613 (defun gnus-inews-message-id ()
1614   "Generate unique Message-ID for user."
1615   ;; Message-ID should not contain a slash and should be terminated by
1616   ;; a number.  I don't know the reason why it is so.
1617   (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1618
1619 (defvar gnus-unique-id-char nil)
1620
1621 ;; If you ever change this function, make sure the new version
1622 ;; cannot generate IDs that the old version could.
1623 ;; You might for example insert a "." somewhere (not next to another dot
1624 ;; or string boundary), or modify the newsreader name to "Ding".
1625 (defun gnus-inews-unique-id ()
1626   ;; Don't use microseconds from (current-time), they may be unsupported.
1627   ;; Instead we use this randomly inited counter.
1628   (setq gnus-unique-id-char
1629         (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1630            ;; (current-time) returns 16-bit ints,
1631            ;; and 2^16*25 just fits into 4 digits i base 36.
1632            (* 25 25)))
1633   (let ((tm (if (fboundp 'current-time)
1634                 (current-time) '(12191 46742 287898))))
1635     (concat
1636      (if (memq system-type '(ms-dos emx vax-vms))
1637          (let ((user (downcase (gnus-inews-login-name))))
1638            (while (string-match "[^a-z0-9_]" user)
1639              (aset user (match-beginning 0) ?_))
1640            user)
1641        (gnus-number-base36 (user-uid) -1))
1642      (gnus-number-base36 (+ (car   tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1643      (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1644      ;; Append the newsreader name, because while the generated
1645      ;; ID is unique to this newsreader, other newsreaders might
1646      ;; otherwise generate the same ID via another algorithm.
1647      ".fsf")))
1648
1649 (defun gnus-inews-date ()
1650   "Current time string."
1651   (let ((now (current-time)))
1652     (timezone-make-date-arpa-standard 
1653      (current-time-string now) (current-time-zone now))))
1654
1655 (defun gnus-inews-organization ()
1656   "Return user's organization.
1657 The ORGANIZATION environment variable is used if defined.
1658 If not, the variable `gnus-local-organization' is used instead.
1659 If it is a function, the function will be called with the current
1660 newsgroup name as the argument.
1661 If this is a file name, the contents of this file will be used as the
1662 organization."
1663   (let* ((organization 
1664           (or (getenv "ORGANIZATION")
1665               (if gnus-local-organization
1666                   (if (gnus-functionp gnus-local-organization)
1667                       (funcall gnus-local-organization gnus-newsgroup-name)
1668                     gnus-local-organization))
1669               gnus-organization-file
1670               "~/.organization")))
1671     (and (stringp organization)
1672          (> (length organization) 0)
1673          (or (file-exists-p organization)
1674              (string-match " " organization)
1675              (not (string-match "^/usr/lib/\\|^~/" organization)))
1676          (save-excursion
1677            (gnus-set-work-buffer)
1678            (if (file-exists-p organization)
1679                (insert-file-contents organization)
1680              (insert organization))
1681            (goto-char (point-min))
1682            (while (re-search-forward " *\n *" nil t)
1683              (replace-match " " t t))
1684            (buffer-substring (point-min) (point-max))))))
1685
1686 (defun gnus-inews-lines ()
1687   "Count the number of lines and return numeric string."
1688   (save-excursion
1689     (save-restriction
1690       (widen)
1691       (goto-char (point-min))
1692       (re-search-forward 
1693        (concat "^" (regexp-quote mail-header-separator) "$"))
1694       (forward-line 1)
1695       (int-to-string (count-lines (point) (point-max))))))
1696
1697 (defun gnus-inews-in-reply-to ()
1698   "Return the In-Reply-To header for this message."
1699   gnus-in-reply-to)
1700
1701 \f
1702 ;;;
1703 ;;; Gnus Mail Functions 
1704 ;;;
1705
1706 ;;; Mail reply commands of Gnus summary mode
1707
1708 (defun gnus-summary-reply (yank &optional yank-articles)
1709   "Reply mail to news author.
1710 If prefix argument YANK is non-nil, original article is yanked automatically.
1711 Customize the variable gnus-mail-reply-method to use another mailer."
1712   (interactive "P")
1713   ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1714   ;; Stripping headers should be specified with mail-yank-ignored-headers.
1715   (gnus-set-global-variables)
1716   (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1717   (gnus-summary-select-article)
1718   (bury-buffer gnus-article-buffer)
1719   (gnus-mail-reply (or yank-articles (not (not yank)))))
1720
1721 (defun gnus-summary-reply-with-original (n)
1722   "Reply mail to news author with original article.
1723 Customize the variable gnus-mail-reply-method to use another mailer."
1724   (interactive "P")
1725   (gnus-summary-reply t (gnus-summary-work-articles n)))
1726
1727 (defun gnus-summary-mail-forward (post)
1728   "Forward the current message to another user.
1729 Customize the variable gnus-mail-forward-method to use another mailer."
1730   (interactive "P")
1731   (gnus-set-global-variables)
1732   (gnus-summary-select-article)
1733   (gnus-copy-article-buffer)
1734   (if post
1735       (gnus-forward-using-post gnus-original-article-buffer)
1736     (gnus-mail-forward gnus-original-article-buffer)))
1737
1738 (defun gnus-summary-resend-message (address)
1739   "Resend the current article to ADDRESS."
1740   (interactive "sResend message to: ")
1741   (gnus-summary-select-article)
1742   (save-excursion
1743     (let (resent beg)
1744       ;; We first set up a normal mail buffer.
1745       (nnheader-set-temp-buffer " *Gnus resend*")
1746       ;; This code from sendmail.el
1747       (insert "To: ")
1748       (let ((fill-prefix "\t")
1749             (address-start (point)))
1750         (insert address "\n")
1751         (fill-region-as-paragraph address-start (point-max)))
1752       (insert mail-header-separator "\n")
1753       ;; Insert our usual headers.
1754       (gnus-inews-narrow-to-headers)
1755       (gnus-inews-insert-headers '(From Date To))
1756       (goto-char (point-min))
1757       ;; Rename them all to "Resent-*".
1758       (while (re-search-forward "^[A-Za-z]" nil t)
1759         (forward-char -1)
1760         (insert "Resent-"))
1761       (widen)
1762       (forward-line)
1763       (delete-region (point) (point-max))
1764       (setq beg (point))
1765       ;; Insert the message to be resent.
1766       (insert-buffer-substring gnus-original-article-buffer)
1767       (goto-char (point-min))
1768       (search-forward "\n\n")
1769       (forward-char -1)
1770       (insert mail-header-separator)
1771       ;; Rename all old ("Also-")Resent headers.
1772       (while (re-search-backward "^\\(Also-\\)?Resent-" beg t)
1773         (beginning-of-line)
1774         (insert "Also-"))
1775       ;; Send it.
1776       (mail-send)
1777       (kill-buffer (current-buffer)))))
1778
1779 (defun gnus-summary-post-forward ()
1780   "Forward the current article to a newsgroup."
1781   (interactive)
1782   (gnus-summary-mail-forward t))
1783
1784 (defvar gnus-nastygram-message 
1785   "The following article was inappropriately posted to %s.\n"
1786   "Format string to insert in nastygrams.
1787 The current group name will be inserted at \"%s\".")
1788
1789 (defun gnus-summary-mail-nastygram (n)
1790   "Send a nastygram to the author of the current article."
1791   (interactive "P")
1792   (if (or gnus-expert-user
1793           (gnus-y-or-n-p 
1794            "Really send a nastygram to the author of the current article? "))
1795       (let ((group gnus-newsgroup-name))
1796         (gnus-summary-reply-with-original n)
1797         (set-buffer gnus-mail-buffer)
1798         (insert (format gnus-nastygram-message group))
1799         (gnus-mail-send-and-exit))))
1800
1801 (defun gnus-summary-mail-other-window ()
1802   "Compose mail in other window.
1803 Customize the variable `gnus-mail-other-window-method' to use another
1804 mailer."
1805   (interactive)
1806   (gnus-set-global-variables)
1807   (gnus-new-mail
1808    ;; We might want to prompt here.
1809    (when (and gnus-interactive-post
1810               (not gnus-expert-user))
1811      (read-string "To: ")))
1812   (gnus-configure-windows 'summary-mail 'force))
1813
1814 (defun gnus-new-mail (&optional to)
1815   (let (subject)
1816     (when (and gnus-interactive-post
1817                (not gnus-expert-user))
1818       (setq subject (read-string "Subject: ")))
1819     (pop-to-buffer gnus-mail-buffer)
1820     (erase-buffer)
1821     (gnus-mail-setup 'new to subject)
1822     (gnus-inews-insert-gcc)
1823     (gnus-inews-insert-archive-gcc)
1824     (run-hooks 'gnus-mail-hook)))
1825
1826 (defun gnus-new-empty-mail ()
1827   "Create a new, virtually empty mail mode buffer."
1828   (pop-to-buffer gnus-mail-buffer)
1829   (gnus-mail-setup 'new "" ""))
1830
1831 (defun gnus-mail-reply (&optional yank to-address followup)
1832   (save-excursion
1833     (set-buffer gnus-summary-buffer)
1834     (let ((group (gnus-group-real-name gnus-newsgroup-name))
1835           (cur (cons (current-buffer) (cdr gnus-article-current)))
1836           (winconf (current-window-configuration))
1837           from subject date reply-to message-of to cc
1838           references message-id sender follow-to sendto elt new-cc new-to
1839           mct mctdo gnus-warning)
1840       (set-buffer (get-buffer-create gnus-mail-buffer))
1841       (mail-mode)
1842       (if (and (buffer-modified-p)
1843                (> (buffer-size) 0)
1844                (not (gnus-y-or-n-p 
1845                      "Unsent message being composed; erase it? ")))
1846           ()
1847         (erase-buffer)
1848         (save-excursion
1849           (gnus-copy-article-buffer)
1850           (save-restriction
1851             (set-buffer gnus-article-copy)
1852             (nnheader-narrow-to-headers)
1853             (if (not followup)
1854                 ;; This is a regular reply.
1855                 (if (gnus-functionp gnus-reply-to-function)
1856                     (setq follow-to (funcall gnus-reply-to-function group)))
1857               ;; This is a followup.
1858               (if (gnus-functionp gnus-followup-to-function)
1859                   (save-excursion
1860                     (setq follow-to
1861                           (funcall gnus-followup-to-function group)))))
1862             (setq from (mail-fetch-field "from"))
1863             (setq date (or (mail-fetch-field "date") 
1864                            (mail-header-date gnus-current-headers)))
1865             (setq message-of (gnus-message-of from date))
1866             (setq sender (mail-fetch-field "sender"))
1867             (setq subject (or (mail-fetch-field "subject") "none"))
1868             ;; Remove any (buggy) Re:'s that are present and make a
1869             ;; proper one.
1870             (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1871                  (setq subject (substring subject (match-end 0))))
1872             (setq subject (concat "Re: " subject))
1873             (setq to (mail-fetch-field "to"))
1874             (setq cc (mail-fetch-field "cc"))
1875             (setq mct (mail-fetch-field "mail-copies-to"))
1876             (setq reply-to
1877                   (unless (gnus-group-get-parameter group 'broken-reply-to)
1878                     (mail-fetch-field "reply-to")))
1879             (setq references (mail-fetch-field "references"))
1880             (setq message-id (mail-fetch-field "message-id"))
1881             (when (and (setq gnus-warning (mail-fetch-field "gnus-warning"))
1882                        (string-match "<[^>]+>" gnus-warning))
1883               (setq message-id (match-string 0 gnus-warning)))
1884             
1885             (setq mctdo (not (equal mct "never")))
1886             (when (and mct (string= (downcase mct) "always"))
1887               (setq mct (or reply-to from)))
1888
1889             (if (not (and followup (not to-address)))
1890                 (setq new-to (or reply-to from)
1891                       new-cc 
1892                       (if (and mctdo
1893                                (not (string= 
1894                                      (mail-strip-quoted-names mct)
1895                                      (mail-strip-quoted-names
1896                                       (or to-address 
1897                                           (if (and follow-to 
1898                                                    (not (stringp follow-to)))
1899                                               sendto
1900                                             (or follow-to new-to
1901                                                 sender "")))))))
1902                           mct))
1903               (let (ccalist)
1904                 (save-excursion
1905                   (gnus-set-work-buffer)
1906                   (unless (equal mct "never")
1907                     (insert (or reply-to from "")))
1908                   (insert 
1909                    (if (bolp) "" ", ") (or to "")
1910                    (if (or (not mct) (not mctdo)) ""
1911                      (concat (if (bolp) "" ", ") mct))
1912                    (if cc (concat (if (bolp) "" ", ") cc) ""))
1913                   ;; Remove addresses that match `rmail-dont-reply-to-names'. 
1914                   (insert (prog1 (rmail-dont-reply-to (buffer-string))
1915                             (erase-buffer)))
1916                   (goto-char (point-min))
1917                   (setq ccalist
1918                         (mapcar
1919                          (lambda (addr)
1920                            (cons (mail-strip-quoted-names addr) addr))
1921                          (nreverse (gnus-mail-parse-comma-list))))
1922                   (let ((s ccalist))
1923                     (while s
1924                       (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
1925                 (setq new-to (cdr (pop ccalist)))
1926                 (setq new-cc 
1927                       (mapconcat 
1928                        (lambda (addr) (cdr addr))
1929                        ccalist ", "))))
1930             (widen)))
1931
1932         (setq news-reply-yank-from (or from "(nobody)"))
1933         (setq news-reply-yank-message-id
1934               (or message-id "(unknown Message-ID)"))
1935
1936         ;; Gather the "to" addresses out of the follow-to list and remove
1937         ;; them as we go.
1938         (if (and follow-to (listp follow-to))
1939             (while (setq elt (assoc "To" follow-to))
1940               (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1941               (setq follow-to (delq elt follow-to))))
1942
1943         (gnus-mail-setup 
1944          (if followup 'followup 'reply)
1945          (or to-address 
1946              (if (and follow-to (not (stringp follow-to))) sendto
1947                (or follow-to new-to sender "")))
1948          subject message-of
1949          (if (zerop (length new-cc)) nil new-cc)
1950          gnus-article-copy)
1951
1952         (make-local-variable 'gnus-article-reply)
1953         (setq gnus-article-reply cur)
1954         (make-local-variable 'gnus-prev-winconf)
1955         (setq gnus-prev-winconf winconf)
1956         (make-local-variable 'gnus-reply-subject)
1957         (setq gnus-reply-subject subject)
1958         (make-local-variable 'gnus-in-reply-to)
1959         (setq gnus-in-reply-to message-of)
1960
1961         (auto-save-mode auto-save-default)
1962         (gnus-inews-insert-gcc)
1963         (gnus-inews-insert-archive-gcc group)
1964
1965         (when (and follow-to (listp follow-to))
1966           (let (beg)
1967             (gnus-inews-narrow-to-headers)
1968             (re-search-forward "^To:" nil t)
1969             (beginning-of-line)
1970             (forward-line 1)
1971             (setq beg (point))
1972             ;; Insert the rest of the Follow-To headers.
1973             (while follow-to
1974               (goto-char (point-min))
1975               (if (not (re-search-forward 
1976                         (concat "^" (caar follow-to) ": *") nil t))
1977                   (progn
1978                     (goto-char beg)
1979                     (insert (caar follow-to) ": " (cdar follow-to) "\n"))
1980                 (unless (eolp)
1981                   (insert ", "))
1982                 (insert (cdar follow-to)))
1983               (setq follow-to (cdr follow-to)))
1984             (widen)))
1985         (nnheader-insert-references references message-id)
1986
1987         ;; Now the headers should be ok, so we do the yanking.
1988         (goto-char (point-min))
1989         (re-search-forward
1990          (concat "^" (regexp-quote mail-header-separator) "$"))
1991         (forward-line 1)
1992         (if (not yank)
1993             (gnus-configure-windows 'reply 'force)
1994           (let ((last (point))
1995                 end)
1996             (if (not (listp yank))
1997                 (progn
1998                   ;; Just a single article being yanked.
1999                   (save-excursion
2000                     (mail-yank-original nil))
2001                   (or mail-yank-hooks mail-citation-hook
2002                       (run-hooks 'news-reply-header-hook)))
2003               (while yank
2004                 (save-window-excursion
2005                   (set-buffer gnus-summary-buffer)
2006                   (gnus-summary-select-article nil nil nil (car yank))
2007                   (gnus-summary-remove-process-mark (car yank)))
2008                 (save-excursion
2009                   (setq end (point))
2010                   (gnus-copy-article-buffer)
2011                   (mail-yank-original nil)
2012                   (save-restriction
2013                     (narrow-to-region (point-min) (point))
2014                     (goto-char (mark t))
2015                     (let ((news-reply-yank-from
2016                            (save-excursion 
2017                              (set-buffer gnus-article-buffer)
2018                              (or (mail-fetch-field "from") "(nobody)")))
2019                           (news-reply-yank-message-id
2020                            (save-excursion 
2021                              (set-buffer gnus-article-buffer)
2022                              (or (mail-fetch-field "message-id")
2023                                  "(unknown Message-ID)"))))
2024                       (or mail-yank-hooks mail-citation-hook
2025                           (run-hooks 'news-reply-header-hook))
2026                       (setq end (point-max)))))
2027                 (goto-char end)
2028                 (setq yank (cdr yank))))
2029             (goto-char last))
2030           (forward-line 2)
2031           (gnus-configure-windows 'reply-yank 'force))
2032         (run-hooks 'gnus-mail-hook)
2033         ;; Mark this buffer as unchanged.
2034         (set-buffer-modified-p nil)))))
2035
2036 (defun gnus-mail-parse-comma-list ()
2037   (let (accumulated
2038         beg)
2039     (skip-chars-forward " ")
2040     (while (not (eobp))
2041       (setq beg (point))
2042       (skip-chars-forward "^,")
2043       (while (zerop
2044               (save-excursion 
2045                 (save-restriction
2046                   (let ((i 0))
2047                     (narrow-to-region beg (point))
2048                     (goto-char beg)
2049                     (logand (progn
2050                               (while (search-forward "\"" nil t)
2051                                 (incf i))
2052                               (if (zerop i) 2 i)) 2)))))
2053         (skip-chars-forward ",")
2054         (skip-chars-forward "^,"))
2055       (skip-chars-backward " ")
2056       (setq accumulated
2057             (cons (buffer-substring beg (point))
2058                   accumulated))
2059       (skip-chars-forward "^,")
2060       (skip-chars-forward ", "))
2061     accumulated))
2062
2063 (defun gnus-new-news (&optional group inhibit-prompt)
2064   "Set up a *Post Gnus* buffer that points to GROUP.
2065 If INHIBIT-PROMPT, never prompt for a Subject."
2066   (let ((winconf (current-window-configuration))
2067         subject)
2068     (when (and gnus-interactive-post
2069                (not inhibit-prompt)
2070                (not gnus-expert-user))
2071       (setq subject (read-string "Subject: ")))
2072     (pop-to-buffer gnus-post-news-buffer)  
2073     (erase-buffer)
2074     (news-reply-mode)
2075     ;; Let posting styles be configured.
2076     (gnus-configure-posting-styles)
2077     (news-setup nil subject nil (and group (gnus-group-real-name group)) nil)
2078     ;; Associate this buffer with the draft group.
2079     (gnus-enter-buffer-into-draft)
2080     (goto-char (point-min))
2081
2082     (unless (re-search-forward 
2083              (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2084       (goto-char (point-max)))
2085     (insert "\n\n")
2086
2087     (gnus-inews-insert-bfcc)
2088     (gnus-inews-insert-gcc)
2089     (gnus-inews-insert-archive-gcc group)
2090     (gnus-inews-insert-signature)
2091     (and gnus-post-prepare-function
2092          (gnus-functionp gnus-post-prepare-function)
2093          (funcall gnus-post-prepare-function group))
2094     (run-hooks 'gnus-post-prepare-hook)
2095     (gnus-inews-set-point)
2096     (make-local-variable 'gnus-prev-winconf)
2097     (setq gnus-prev-winconf winconf)
2098     (gnus-inews-modify-mail-mode-map)
2099     (local-set-key "\C-c\C-c" 'gnus-inews-news)))
2100
2101 (defun gnus-news-followup (&optional yank group)
2102   (save-excursion
2103     (set-buffer gnus-summary-buffer)
2104     (if (not (or (not gnus-novice-user)
2105                  gnus-expert-user
2106                  (gnus-y-or-n-p
2107                   "Are you sure you want to post to all of USENET? ")))
2108         ()
2109       (let ((group (gnus-group-real-name (or group gnus-newsgroup-name)))
2110             (cur (cons (current-buffer) (cdr gnus-article-current)))
2111             (winconf (current-window-configuration))
2112             from subject date reply-to message-of
2113             references message-id sender follow-to sendto elt 
2114             followup-to distribution newsgroups gnus-warning)
2115         (set-buffer (get-buffer-create gnus-post-news-buffer))
2116         (news-reply-mode)
2117         ;; Associate this buffer with the draft group.
2118         (gnus-enter-buffer-into-draft)
2119         (if (and (buffer-modified-p)
2120                  (> (buffer-size) 0)
2121                  (not (gnus-y-or-n-p 
2122                        "Unsent message being composed; erase it? ")))
2123             ()
2124           (erase-buffer)
2125           (save-excursion
2126             (gnus-copy-article-buffer)
2127             (save-restriction
2128               (set-buffer gnus-article-copy)
2129               (nnheader-narrow-to-headers)
2130               (if (gnus-functionp gnus-followup-to-function)
2131                   (save-excursion
2132                     (setq follow-to
2133                           (funcall gnus-followup-to-function group))))
2134               (setq from (mail-fetch-field "from"))
2135               (setq date (or (mail-fetch-field "date") 
2136                              (mail-header-date gnus-current-headers)))
2137               (setq message-of (gnus-message-of from date))
2138               (setq subject (or (mail-fetch-field "subject") "none"))
2139               ;; Remove any (buggy) Re:'s that are present and make a
2140               ;; proper one.
2141               (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
2142                    (setq subject (substring subject (match-end 0))))
2143               (setq subject (concat "Re: " subject))
2144               (setq references (mail-fetch-field "references"))
2145               (setq message-id (mail-fetch-field "message-id"))
2146               (when (and (setq gnus-warning (mail-fetch-field "gnus-warning"))
2147                          (string-match "<[^>]+>" gnus-warning))
2148                 (setq message-id (match-string 0 gnus-warning)))
2149               (setq followup-to (mail-fetch-field "followup-to"))
2150               (setq newsgroups (mail-fetch-field "newsgroups"))
2151               (setq distribution (mail-fetch-field "distribution"))
2152               ;; Remove bogus distribution.
2153               (and (stringp distribution)
2154                    (string-match "world" distribution)
2155                    (setq distribution nil))
2156               (widen)))
2157
2158           (setq news-reply-yank-from (or from "(nobody)"))
2159           (setq news-reply-yank-message-id
2160                 (or message-id "(unknown Message-ID)"))
2161
2162           ;; Gather the "to" addresses out of the follow-to list and remove
2163           ;; them as we go.
2164           (if (and follow-to (listp follow-to))
2165               (while (setq elt (assoc "Newsgroups" follow-to))
2166                 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
2167                 (setq follow-to (delq elt follow-to))))
2168
2169           ;; Let posting styles be configured.
2170           (gnus-configure-posting-styles)
2171
2172           (news-setup
2173            nil subject nil 
2174            (or sendto 
2175                (and followup-to
2176                     gnus-use-followup-to
2177                     (or (not (eq gnus-use-followup-to 'ask))
2178                         (equal followup-to newsgroups)
2179                         (gnus-y-or-n-p 
2180                          (format "Use Followup-To %s? " followup-to)))
2181                     followup-to)
2182                newsgroups group "")
2183            gnus-article-copy)
2184
2185           (make-local-variable 'gnus-article-reply)
2186           (setq gnus-article-reply cur)
2187           (make-local-variable 'gnus-prev-winconf)
2188           (setq gnus-prev-winconf winconf)
2189           (make-local-variable 'gnus-reply-subject)
2190           (setq gnus-reply-subject (mail-header-subject gnus-current-headers))
2191           (make-local-variable 'gnus-in-reply-to)
2192           (setq gnus-in-reply-to message-of)
2193           (when (and followup-to newsgroups)
2194             (make-local-variable 'gnus-newsgroup-followup)
2195             (setq gnus-newsgroup-followup
2196                   (cons newsgroups followup-to)))
2197
2198           (gnus-inews-insert-signature)
2199
2200           (and gnus-post-prepare-function
2201                (gnus-functionp gnus-post-prepare-function)
2202                (funcall gnus-post-prepare-function group))
2203           (run-hooks 'gnus-post-prepare-hook)
2204
2205           (auto-save-mode auto-save-default)
2206           (gnus-inews-modify-mail-mode-map)
2207           (local-set-key "\C-c\C-c" 'gnus-inews-news)
2208
2209           (if (and follow-to (listp follow-to))
2210               (progn
2211                 (goto-char (point-min))
2212                 (and (re-search-forward "^Newsgroups:" nil t)
2213                      (forward-line 1))
2214                 (while follow-to
2215                   (insert (caar follow-to) ": " (cdar follow-to) "\n")
2216                   (setq follow-to (cdr follow-to)))))
2217           
2218           ;; If a distribution existed, we use it.
2219           (if distribution
2220               (progn
2221                 (mail-position-on-field "Distribution")
2222                 (insert distribution)))
2223           
2224           (nnheader-insert-references references message-id)
2225
2226           ;; Handle `gnus-auto-mail-to-author'.
2227           ;; Suggested by Daniel Quinlan <quinlan@best.com>.
2228           ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
2229           (let ((to (if (if (eq gnus-auto-mail-to-author 'ask)
2230                             (y-or-n-p "Also send mail to author? ")
2231                           gnus-auto-mail-to-author)
2232                         (or (save-excursion
2233                               (set-buffer gnus-article-copy)
2234                               (unless (gnus-group-get-parameter
2235                                        group 'broken-reply-to)
2236                                 (gnus-fetch-field "reply-to")))
2237                             from)))
2238                 (x-mail (save-excursion
2239                           (set-buffer gnus-article-copy)
2240                           (gnus-fetch-field "x-mail-copy-to"))))
2241             ;; Deny sending copy if there's a negative X-Mail-Copy-To
2242             ;; header. 
2243             (if x-mail
2244                 (if (and (string= x-mail "never")
2245                          (not (eq gnus-auto-mail-to-author 'force)))
2246                     (setq to nil)
2247                   (setq to x-mail)))
2248             ;; Insert a To or Cc header.
2249             (if to
2250                 (if (mail-fetch-field "To")
2251                     (progn
2252                       (beginning-of-line)
2253                       (insert "Cc: " to "\n"))
2254                   (mail-position-on-field "To")
2255                   (insert to))))
2256
2257           (gnus-inews-insert-bfcc)
2258           (gnus-inews-insert-gcc)
2259           (gnus-inews-insert-archive-gcc group)
2260
2261           ;; Now the headers should be ok, so we do the yanking.
2262           (goto-char (point-min))
2263           (re-search-forward
2264            (concat "^" (regexp-quote mail-header-separator) "$"))
2265           (forward-line 1)
2266           (if (not yank)
2267               (progn
2268                 (gnus-configure-windows 'followup 'force)
2269                 (insert "\n\n")
2270                 (forward-line -2))
2271             (let ((last (point))
2272                   end)
2273               (if (not (listp yank))
2274                   (progn
2275                     (save-excursion
2276                       (mail-yank-original nil))
2277                     (or mail-yank-hooks mail-citation-hook
2278                         (run-hooks 'news-reply-header-hook)))
2279                 (while yank
2280                   (save-window-excursion
2281                     (set-buffer gnus-summary-buffer)
2282                     (gnus-summary-select-article nil nil nil (car yank))
2283                     (gnus-summary-remove-process-mark (car yank)))
2284                   (save-excursion
2285                     (gnus-copy-article-buffer)
2286                     (mail-yank-original nil)
2287                     (setq end (point)))
2288                   (or mail-yank-hooks mail-citation-hook
2289                       (run-hooks 'news-reply-header-hook))
2290                   (goto-char end)
2291                   (setq yank (cdr yank))))
2292               (goto-char last))
2293             (gnus-configure-windows 'followup-yank 'force))
2294         
2295           (make-local-variable 'gnus-article-check-size)
2296           (setq gnus-article-check-size
2297                 (cons (buffer-size) (gnus-article-checksum)))
2298           (gnus-inews-set-point))))))
2299
2300 (defun gnus-message-of (from date)
2301   "Take a FROM and a DATE and return an IN-REPLY-TO."
2302   (when from
2303     (let ((stop-pos 
2304            (string-match "  *at \\|  *@ \\| *(\\| *<" from)))
2305       (concat (if stop-pos (substring from 0 stop-pos) from)
2306               "'s message of " 
2307               (if (or (not date) (string= date ""))
2308                   "(unknown date)" date)))))
2309
2310 (defun gnus-mail-yank-original ()
2311   (interactive)
2312   (save-excursion
2313     (mail-yank-original nil))
2314   (or mail-yank-hooks mail-citation-hook
2315       (run-hooks 'news-reply-header-hook)))
2316
2317 (defun gnus-mail-send-and-exit (&optional dont-send)
2318   "Send the current mail and return to Gnus."
2319   (interactive)
2320   (let* ((reply gnus-article-reply)
2321          (winconf gnus-prev-winconf)
2322          (address-group gnus-add-to-address)
2323          (to-address (and address-group
2324                           (mail-fetch-field "to"))))
2325     (setq gnus-add-to-address nil)
2326     (let ((buffer-file-name nil))
2327       (or dont-send (gnus-mail-send)))
2328     (bury-buffer)
2329     (when (gnus-alive-p)
2330       ;; This mail group doesn't have a `to-list', so we add one
2331       ;; here.  Magic!  
2332       (when to-address
2333         (gnus-group-add-parameter address-group (cons 'to-list to-address)))
2334       (when (and (gnus-buffer-exists-p (car reply))
2335                  (cdr reply))
2336         (save-excursion
2337           (set-buffer (car reply))
2338           (gnus-summary-mark-article-as-replied (cdr reply))))
2339       (and winconf (set-window-configuration winconf)))))
2340
2341 (defun gnus-kill-message-buffer ()
2342   "Kill the current buffer after dissociating it from the draft group."
2343   (interactive)
2344   (when (gnus-y-or-n-p "Dissociate and kill the current buffer? ")
2345     (gnus-dissociate-buffer-from-draft)
2346     (let ((winconf gnus-prev-winconf))
2347       (kill-buffer (current-buffer))
2348       (when winconf 
2349         (set-window-configuration winconf)))))
2350
2351 (defun gnus-put-message ()
2352   "Put the current message in some group and return to Gnus."
2353   (interactive)
2354   (let ((reply gnus-article-reply)
2355         (winconf gnus-prev-winconf)
2356         (group gnus-newsgroup-name)
2357         buf)
2358     
2359     (or (and group (not (gnus-group-read-only-p group)))
2360         (setq group (read-string "Put in group: " nil
2361                                  (gnus-writable-groups))))
2362     (and (gnus-gethash group gnus-newsrc-hashtb)
2363          (error "No such group: %s" group))
2364
2365     (save-excursion
2366       (save-restriction
2367         (widen)
2368         (gnus-inews-narrow-to-headers)
2369         (let (gnus-deletable-headers)
2370           (if (eq major-mode 'mail-mode)
2371               (gnus-inews-insert-headers gnus-required-mail-headers)
2372             (gnus-inews-insert-headers)))
2373         (goto-char (point-max))
2374         (insert "Gcc: " group "\n")
2375         (widen)))
2376
2377     (gnus-inews-do-gcc)
2378
2379     (if (get-buffer gnus-group-buffer)
2380         (progn
2381           (if (gnus-buffer-exists-p (car-safe reply))
2382               (progn
2383                 (set-buffer (car reply))
2384                 (and (cdr reply)
2385                      (gnus-summary-mark-article-as-replied 
2386                       (cdr reply)))))
2387           (and winconf (set-window-configuration winconf))))))
2388
2389 (defun gnus-forward-make-subject (buffer)
2390   (save-excursion
2391     (set-buffer buffer)
2392     (concat "[" (if (memq 'mail (assoc (symbol-name 
2393                                         (car (gnus-find-method-for-group 
2394                                               gnus-newsgroup-name)))
2395                                        gnus-valid-select-methods))
2396                     (gnus-fetch-field "From")
2397                   gnus-newsgroup-name)
2398             "] " (or (gnus-fetch-field "Subject") ""))))
2399
2400 (defun gnus-forward-insert-buffer (buffer)
2401   (save-excursion
2402     (save-restriction
2403       ;; Put point where we want it before inserting the forwarded
2404       ;; message. 
2405       (if gnus-signature-before-forwarded-message
2406           (goto-char (point-max))
2407         (goto-char (point-min))
2408         (re-search-forward
2409          (concat "^" (regexp-quote mail-header-separator) "$"))
2410         (forward-line 1))
2411       ;; Narrow to the area we are to insert.
2412       (narrow-to-region (point) (point))
2413       ;; Insert the separators and the forwarded buffer.
2414       (insert gnus-forward-start-separator)
2415       (insert-buffer-substring buffer)
2416       (goto-char (point-max))
2417       (insert gnus-forward-end-separator)
2418       (gnus-set-text-properties (point-min) (point-max) nil)
2419       ;; Remove all unwanted headers.
2420       (goto-char (point-min))
2421       (forward-line 1)
2422       (save-restriction
2423         (narrow-to-region (point) (if (search-forward "\n\n" nil t)
2424                                       (1- (point))
2425                                     (point)))
2426         (goto-char (point-min))
2427         (let ((case-fold-search t))
2428           (delete-non-matching-lines gnus-forward-included-headers))))))
2429
2430 (defun gnus-mail-forward (&optional buffer)
2431   "Forward the current message to another user using mail."
2432   (let* ((forward-buffer (or buffer (current-buffer)))
2433          (winconf (current-window-configuration))
2434          (subject (gnus-forward-make-subject forward-buffer)))
2435     (set-buffer (get-buffer-create gnus-mail-buffer))
2436     (if (and (buffer-modified-p)
2437              (> (buffer-size) 0)
2438              (not (gnus-y-or-n-p 
2439                    "Unsent message being composed; erase it? ")))
2440         ()
2441       (erase-buffer)
2442       (gnus-mail-setup 'forward nil subject)
2443       (make-local-variable 'gnus-prev-winconf)
2444       (setq gnus-prev-winconf winconf)
2445       (gnus-forward-insert-buffer forward-buffer)
2446       (goto-char (point-min))
2447       (re-search-forward "^To: ?" nil t)
2448       (gnus-configure-windows 'mail-forward 'force)
2449       ;; You have a chance to arrange the message.
2450       (run-hooks 'gnus-mail-forward-hook)
2451       (run-hooks 'gnus-mail-hook))))
2452
2453 (defun gnus-forward-using-post (&optional buffer)
2454   (save-excursion
2455     (let* ((forward-buffer (or buffer (current-buffer))) 
2456            (subject (gnus-forward-make-subject forward-buffer))
2457            (gnus-newsgroup-name nil))
2458       (gnus-post-news 'post nil nil nil nil subject)
2459       (save-excursion
2460         (gnus-forward-insert-buffer forward-buffer)
2461         ;; You have a chance to arrange the message.
2462         (run-hooks 'gnus-mail-forward-hook)))))
2463
2464 (defun gnus-mail-other-window-using-mail ()
2465   "Compose mail other window using mail."
2466   (let ((winconf (current-window-configuration)))
2467     (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
2468     (gnus-inews-modify-mail-mode-map)
2469     (make-local-variable 'gnus-prev-winconf)
2470     (setq gnus-prev-winconf winconf)
2471     (run-hooks 'gnus-mail-hook)
2472     (gnus-configure-windows 'summary-mail 'force)))
2473
2474 (defun gnus-article-mail (yank)
2475   "Send a reply to the address near point.
2476 If YANK is non-nil, include the original article."
2477   (interactive "P")
2478   (let ((address 
2479          (buffer-substring
2480           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
2481           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
2482     (and address
2483          (progn
2484            (switch-to-buffer gnus-summary-buffer)
2485            (gnus-mail-reply yank address)))))
2486
2487 (defun gnus-bug ()
2488   "Send a bug report to the Gnus maintainers."
2489   (interactive)
2490   (let ((winconf (current-window-configuration)))
2491     (delete-other-windows)
2492     (switch-to-buffer "*Gnus Help Bug*")
2493     (erase-buffer)
2494     (insert gnus-bug-message)
2495     (goto-char (point-min))
2496     (pop-to-buffer "*Gnus Bug*")
2497     (erase-buffer)
2498     (mail-mode)
2499     (mail-setup gnus-maintainer nil nil nil nil nil)
2500     (auto-save-mode auto-save-default)
2501     (make-local-variable 'gnus-prev-winconf)
2502     (setq gnus-prev-winconf winconf)
2503     (gnus-inews-modify-mail-mode-map)
2504     (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
2505     (goto-char (point-min))
2506     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2507     (forward-line 1)
2508     (insert (gnus-version) "\n")
2509     (insert (emacs-version))
2510     (insert "\n\n\n\n\n")
2511     (gnus-debug)
2512     (goto-char (point-min))
2513     (search-forward "Subject: " nil t)
2514     (message "")))
2515
2516 (defun gnus-bug-mail-send-and-exit ()
2517   "Send the bug message and exit."
2518   (interactive)
2519   (let ((cur (current-buffer)))
2520     (and (get-buffer "*Gnus Help Bug*")
2521          (kill-buffer "*Gnus Help Bug*"))
2522     (gnus-mail-send-and-exit)
2523     (when (buffer-name cur)
2524       (kill-buffer cur))))
2525
2526 (defun gnus-debug ()
2527   "Attemps to go through the Gnus source file and report what variables have been changed.
2528 The source file has to be in the Emacs load path."
2529   (interactive)
2530   (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el" "nnmail.el"))
2531         file dirs expr olist sym)
2532     (message "Please wait while we snoop your variables...")
2533     (sit-for 0)
2534     (save-excursion
2535       (set-buffer (get-buffer-create " *gnus bug info*"))
2536       (buffer-disable-undo (current-buffer))
2537       (while files
2538         (erase-buffer)
2539         (setq dirs load-path)
2540         (while dirs
2541           (if (or (not (car dirs))
2542                   (not (stringp (car dirs)))
2543                   (not (file-exists-p 
2544                         (setq file (concat (file-name-as-directory 
2545                                             (car dirs)) (car files))))))
2546               (setq dirs (cdr dirs))
2547             (setq dirs nil)
2548             (insert-file-contents file)
2549             (goto-char (point-min))
2550             (if (not (re-search-forward "^;;* *Internal variables" nil t))
2551                 (message "Malformed sources in file %s" file)
2552               (narrow-to-region (point-min) (point))
2553               (goto-char (point-min))
2554               (while (setq expr (condition-case () 
2555                                     (read (current-buffer)) (error nil)))
2556                 (condition-case ()
2557                     (and (eq (car expr) 'defvar)
2558                          (stringp (nth 3 expr))
2559                          (or (not (boundp (nth 1 expr)))
2560                              (not (equal (eval (nth 2 expr))
2561                                          (symbol-value (nth 1 expr)))))
2562                          (setq olist (cons (nth 1 expr) olist)))
2563                   (error nil))))))
2564         (setq files (cdr files)))
2565       (kill-buffer (current-buffer)))
2566     (when (setq olist (nreverse olist))
2567       (insert "------------------ Environment follows ------------------\n\n"))
2568     (while olist
2569       (if (boundp (car olist))
2570           (insert 
2571            (condition-case ()
2572                (pp-to-string
2573                 `(setq ,(car olist)
2574                        ,(if (or (consp (setq sym (symbol-value (car olist))))
2575                                 (and (symbolp sym)
2576                                      (not (or (eq sym nil)
2577                                               (eq sym t)))))
2578                             (list 'quote (symbol-value (car olist)))
2579                           (symbol-value (car olist)))))
2580              (error
2581               (format "(setq %s 'whatever)\n" (car olist)))))
2582         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
2583       (setq olist (cdr olist)))
2584     (insert "\n\n")
2585     ;; Remove any null chars - they seem to cause trouble for some
2586     ;; mailers. (Byte-compiled output from the stuff above.) 
2587     (goto-char (point-min))
2588     (while (re-search-forward "[\000\200]" nil t)
2589       (replace-match "" t t))))
2590
2591 ;;; Treatment of rejected articles.
2592 ;;; Bounced mail.
2593
2594 (defun gnus-summary-resend-bounced-mail (fetch)
2595   "Re-mail the current message.
2596 This only makes sense if the current message is a bounce message than
2597 contains some mail you have written which has been bounced back to
2598 you.
2599 If FETCH, try to fetch the article that this is a reply to, if indeed
2600 this is a reply."
2601   (interactive "P")
2602   (gnus-summary-select-article t)
2603   ;; Create a mail buffer.
2604   (gnus-new-empty-mail)
2605   (erase-buffer)
2606   (insert-buffer-substring gnus-article-buffer)
2607   (goto-char (point-min))
2608   (or (re-search-forward "--- *Original message.*\n" nil t)
2609       (and (search-forward "\n\n" nil t)
2610            (re-search-forward "^Return-Path:.*\n" nil t)))
2611   ;; We remove everything before the bounced mail.
2612   (delete-region 
2613    (point-min)
2614    (if (re-search-forward "[^ \t]*:" nil t)
2615        (match-beginning 0)
2616      (point)))
2617   (let (references)
2618     (save-excursion
2619       (save-restriction
2620         (nnheader-narrow-to-headers)
2621         (nnheader-remove-header gnus-bounced-headers-junk t)
2622         (setq references (mail-fetch-field "references"))
2623         (goto-char (point-max))
2624         (insert mail-header-separator)))
2625     ;; If there are references, we fetch the article we answered to.  
2626     (and fetch 
2627          references
2628          (string-match "\\(<[^]+>\\)[ \t]*$" references)
2629          (gnus-summary-refer-article 
2630           (substring references (match-beginning 1) (match-end 1)))
2631          (progn
2632            (gnus-summary-show-all-headers)
2633            (gnus-configure-windows 'compose-bounce))))
2634   (goto-char (point-min)))
2635
2636 ;;; Sending mail.
2637
2638 (defun gnus-mail-send (&optional no-generated-headers)
2639   "Send the current buffer as mail.
2640 Headers will be generated before sending."
2641   (interactive)
2642   (unless no-generated-headers
2643     (save-excursion
2644       (save-restriction
2645         (widen)
2646         (gnus-inews-narrow-to-headers)
2647         (gnus-inews-insert-headers gnus-required-mail-headers)
2648         (gnus-inews-remove-empty-headers))))
2649   (widen)
2650   ;; Remove the header separator.
2651   (goto-char (point-min))
2652   (and (re-search-forward
2653         (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2654        (replace-match "" t t))
2655   ;; Run final inews hooks.  This hook may do FCC.
2656   (run-hooks 'gnus-inews-article-hook)
2657   (gnus-inews-do-gcc)
2658   (nnheader-narrow-to-headers)
2659   (nnheader-remove-header "^[gf]cc:" t)
2660   (widen)
2661   (goto-char (point-min))
2662   (search-forward "\n\n")
2663   (forward-char -1)
2664   (insert mail-header-separator)
2665   (mail-send)
2666   (run-hooks 'gnus-message-sent-hook))
2667
2668 (defun gnus-inews-modify-mail-mode-map ()
2669   (use-local-map (copy-keymap (current-local-map)))
2670   (gnus-local-set-keys
2671    "\C-c\C-c" gnus-mail-send-and-exit
2672    "\C-c\M-\C-p" gnus-put-message
2673    "\C-c\C-q" gnus-kill-message-buffer
2674    "\C-c\M-d" gnus-dissociate-buffer-from-draft
2675    "\C-c\C-d" gnus-associate-buffer-with-draft))
2676
2677 (defun gnus-mail-setup (type &optional to subject in-reply-to cc
2678                              replybuffer actions)
2679   ;; Let posting styles be configured.
2680   (gnus-configure-posting-styles)
2681   (funcall
2682    (cond
2683     ((or 
2684       (eq gnus-mail-method 'mh)
2685       (and (or (eq type 'reply) (eq type 'followup))
2686            (eq gnus-mail-reply-method 'gnus-mail-reply-using-mhe))
2687       (and (eq type 'forward)
2688            (eq gnus-mail-forward-method 'gnus-mail-forward-using-mhe))
2689       (and (eq type 'new) 
2690            (eq gnus-mail-other-window-method 
2691                'gnus-mail-other-window-using-mhe)))
2692      'gnus-mh-mail-setup)
2693     ((or 
2694       (eq gnus-mail-method 'vm)
2695       (and (or (eq type 'reply) (eq type 'followup)) 
2696            (eq gnus-mail-reply-method 'gnus-mail-reply-using-vm))
2697       (and (eq type 'forward)
2698            (eq gnus-mail-forward-method 'gnus-mail-forward-using-vm))
2699       (and (eq type 'new) 
2700            (eq gnus-mail-other-window-method 
2701                'gnus-mail-other-window-using-vm)))
2702      'gnus-vm-mail-setup)
2703     ((or
2704       (eq gnus-mail-method 'sendmail)
2705       (and (or (eq type 'reply) (eq type 'followup)) 
2706            (eq gnus-mail-reply-method 'gnus-mail-reply-using-mail))
2707       (and (eq type 'forward)
2708            (eq gnus-mail-forward-method 'gnus-mail-forward-using-mail))
2709       (and (eq type 'new) 
2710            (eq gnus-mail-other-window-method 
2711                'gnus-mail-other-window-using-mail)))
2712      'gnus-sendmail-mail-setup)
2713     (t
2714      (cond ((or (eq type 'reply) (eq type 'followup))
2715             gnus-mail-reply-method)
2716            ((eq type 'forward)
2717             gnus-mail-forward-method)
2718            ((eq type 'new) 
2719             gnus-mail-other-window-method))))
2720    to subject in-reply-to cc replybuffer actions)
2721   ;; Associate this mail buffer with the draft group.
2722   (gnus-enter-buffer-into-draft))
2723
2724 (defun gnus-sendmail-mail-setup (to subject in-reply-to cc replybuffer actions)
2725   (mail-mode)
2726   (mail-setup to subject nil cc replybuffer actions)
2727   (gnus-inews-set-point)
2728   (gnus-inews-modify-mail-mode-map))
2729   
2730 ;;; Gcc handling.
2731
2732 ;; Do Gcc handling, which copied the message over to some group. 
2733 (defun gnus-inews-do-gcc (&optional gcc)
2734   (save-excursion
2735     (save-restriction
2736       (nnheader-narrow-to-headers)
2737       (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
2738             (cur (current-buffer))
2739             end groups group method)
2740         (when gcc
2741           (nnheader-remove-header "gcc")
2742           (widen)
2743           (setq groups (gnus-tokenize-header gcc " ,"))
2744           ;; Copy the article over to some group(s).
2745           (while (setq group (pop groups))
2746             (gnus-check-server 
2747              (setq method
2748                    (cond ((and (null (gnus-get-info group))
2749                                (eq (car gnus-message-archive-method)
2750                                    (car 
2751                                     (gnus-server-to-method
2752                                      (gnus-group-method group)))))
2753                           ;; If the group doesn't exist, we assume
2754                           ;; it's an archive group...
2755                           gnus-message-archive-method)
2756                          (t (gnus-find-method-for-group group)))))
2757             (unless (gnus-request-group group t method)
2758               (gnus-request-create-group group method))
2759             (gnus-check-server method)
2760             (save-excursion
2761               (nnheader-set-temp-buffer " *acc*")
2762               (insert-buffer-substring cur)
2763               (unless (condition-case ()
2764                           (gnus-request-accept-article group t method)
2765                         (error nil))
2766                 (gnus-message 1 "Couldn't store article in group %s: %s" 
2767                               group (gnus-status-message method))
2768                 (sit-for 2))
2769               (kill-buffer (current-buffer)))))))))
2770
2771 (defun gnus-inews-insert-bfcc ()
2772   "Insert Bcc and Fcc headers."
2773   (save-excursion
2774     ;; Handle author copy using BCC field.
2775     (when (and gnus-mail-self-blind
2776                (not (mail-fetch-field "bcc")))
2777       (mail-position-on-field "Bcc")
2778       (insert (if (stringp gnus-mail-self-blind)
2779                   gnus-mail-self-blind
2780                 (user-login-name))))
2781     ;; Handle author copy using FCC field.
2782     (when gnus-author-copy
2783       (mail-position-on-field "Fcc")
2784       (insert gnus-author-copy))))
2785
2786 (defun gnus-inews-insert-gcc ()
2787   "Insert Gcc headers based on `gnus-outgoing-message-group'."
2788   (save-excursion
2789     (save-restriction
2790       (gnus-inews-narrow-to-headers)
2791       (let* ((group gnus-outgoing-message-group)
2792              (gcc (cond 
2793                    ((gnus-functionp group)
2794                     (funcall group))
2795                    ((or (stringp group) (list group))
2796                     group))))
2797         (when gcc
2798           (insert "Gcc: "
2799                   (if (stringp gcc) gcc
2800                     (mapconcat 'identity gcc " "))
2801                   "\n"))))))
2802
2803 (defun gnus-inews-insert-archive-gcc (&optional group)
2804   "Insert the Gcc to say where the article is to be archived."
2805   (let* ((var gnus-message-archive-group)
2806          (group (or group gnus-newsgroup-name ""))
2807          result
2808          (groups
2809           (cond 
2810            ((null gnus-message-archive-method)
2811             ;; Ignore.
2812             nil)
2813            ((stringp var)
2814             ;; Just a single group.
2815             (list var))
2816            ((null var)
2817             ;; We don't want this.
2818             nil)
2819            ((and (listp var) (stringp (car var)))
2820             ;; A list of groups.
2821             var)
2822            ((gnus-functionp var)
2823             ;; A function.
2824             (funcall var group))
2825            (t
2826             ;; An alist of regexps/functions/forms.
2827             (while (and var
2828                         (not
2829                          (setq result
2830                                (cond 
2831                                 ((stringp (caar var))
2832                                  ;; Regexp.
2833                                  (when (string-match (caar var) group)
2834                                    (cdar var)))
2835                                 ((gnus-functionp (car var))
2836                                  ;; Function.
2837                                  (funcall (car var) group))
2838                                 (t
2839                                  (eval (car var)))))))
2840               (setq var (cdr var)))
2841             result))))
2842     (when groups
2843       (when (stringp groups)
2844         (setq groups (list groups)))
2845       (save-excursion
2846         (save-restriction
2847           (gnus-inews-narrow-to-headers)
2848           (goto-char (point-max))
2849           (insert "Gcc: ")
2850           (while groups
2851             (insert (gnus-group-prefixed-name 
2852                      (pop groups) gnus-message-archive-method))
2853             (insert " "))
2854           (insert "\n"))))))
2855
2856 ;;; Handling rejected (and postponed) news.
2857
2858 (defun gnus-draft-group ()
2859   "Return the name of the draft group."
2860   (gnus-group-prefixed-name 
2861    (file-name-nondirectory (directory-file-name gnus-draft-group-directory))
2862    (list 'nndraft gnus-draft-group-directory)))
2863
2864 (defun gnus-make-draft-group ()
2865   "Make the draft group or die trying."
2866   (let* ((method `(nndraft "private" 
2867                            (nndraft-directory 
2868                             ,gnus-draft-group-directory)))
2869          (group (gnus-draft-group)))
2870     (or (gnus-gethash group gnus-newsrc-hashtb)
2871         (gnus-group-make-group (gnus-group-real-name group) method)
2872         (error "Can't create the draft group"))
2873     (gnus-check-server method)
2874     group))
2875
2876 (defun gnus-associate-buffer-with-draft (&optional generate silent)
2877   "Enter the current buffer into the draft group."
2878   (interactive)
2879   (when (gnus-request-accept-article (gnus-make-draft-group) t)
2880     (unless silent
2881       ;; This function does the proper marking of articles.
2882       (gnus-mail-send-and-exit 'dont-send))
2883     (set-buffer-modified-p nil)))
2884
2885 (defun gnus-enter-buffer-into-draft ()
2886   (when gnus-use-draft
2887     (save-excursion
2888       ;; Make sure the draft group exists.
2889       (gnus-make-draft-group)
2890       ;; Associate the buffer with the draft group.
2891       (let ((article (gnus-request-associate-buffer (gnus-draft-group))))
2892         ;; Arrange for deletion of the draft after successful sending.
2893         (make-local-variable 'gnus-message-sent-hook)
2894         (setq gnus-message-sent-hook
2895               (list
2896                `(lambda ()
2897                   (let ((gnus-verbose-backends nil))
2898                     (gnus-request-expire-articles 
2899                      (quote ,(list article))
2900                      ,(gnus-draft-group) t)))))))))
2901
2902 (defun gnus-dissociate-buffer-from-draft ()
2903   "Disable auto-saving and association to the draft group of the current buffer."
2904   (interactive)
2905   (run-hooks 'gnus-message-sent-hook)
2906   (setq buffer-file-name nil)
2907   (setq buffer-auto-save-file-name nil))
2908
2909 (defun gnus-summary-send-draft ()
2910   "Enter a mail/post buffer to edit and send the draft."
2911   (interactive)
2912   (gnus-set-global-variables)
2913   (unless (equal gnus-newsgroup-name (gnus-draft-group))
2914     (error "This function can only be used in the draft buffer"))
2915   (let (buf point)
2916     (if (not (setq buf (gnus-request-restore-buffer 
2917                         (gnus-summary-article-number) gnus-newsgroup-name)))
2918         (error "Couldn't restore the article")
2919       (setq point (point))
2920       (switch-to-buffer buf)
2921       (gnus-inews-modify-mail-mode-map)
2922       (when (eq major-mode 'news-reply-mode)
2923         (local-set-key "\C-c\C-c" 'gnus-inews-news))
2924       (gnus-enter-buffer-into-draft) 
2925       ;; Insert the separator.
2926       (goto-char (point-min))
2927       (search-forward "\n\n")
2928       (forward-char -1)
2929       (insert mail-header-separator)
2930       ;; Configure windows.
2931       (let ((gnus-draft-buffer (current-buffer)))
2932         (gnus-configure-windows 'draft t)
2933         (goto-char (point))))))
2934   
2935 (defun gnus-configure-posting-styles ()
2936   "Configure posting styles according to `gnus-posting-styles'."
2937   (let ((styles gnus-posting-styles)
2938         (gnus-newsgroup-name (or gnus-newsgroup-name ""))
2939         style match variable attribute value value-value)
2940     ;; Go through all styles and look for matches.
2941     (while styles
2942       (setq style (pop styles)
2943             match (pop style))
2944       (when (cond ((stringp match)
2945                    ;; Regexp string match on the group name.
2946                    (string-match match gnus-newsgroup-name))
2947                   ((or (symbolp match)
2948                        (gnus-functionp match))
2949                    (cond ((gnus-functionp match)
2950                           ;; Function to be called.
2951                           (funcall match))
2952                          ((boundp match)
2953                           ;; Variable to be checked.
2954                           (symbol-value match))))
2955                   ((listp match)
2956                    ;; This is a form to be evaled.
2957                    (eval match)))
2958         ;; We have a match, so we set the variables.
2959         (while style
2960           (setq attribute (pop style)
2961                 value (cdr attribute))
2962           ;; We find the variable that is to be modified.
2963           (if (and (not (stringp (car attribute)))
2964                    (not (setq variable (cdr (assq (car attribute) 
2965                                                   gnus-posting-style-alist)))))
2966               (message "Couldn't find attribute %s" (car attribute))
2967             ;; We set the variable.
2968             (setq value-value
2969                   (cond ((stringp value)
2970                          value)
2971                         ((or (symbolp value)
2972                              (gnus-functionp value))
2973                          (cond ((gnus-functionp value)
2974                                 (funcall value))
2975                                ((boundp value)
2976                                 (symbol-value value))))
2977                         ((listp value)
2978                          (eval value))))
2979             (if variable
2980                 (progn
2981                   ;; This is an ordinary variable.
2982                   (make-local-variable variable)
2983                   (set variable value-value))
2984               ;; This is a header to be added to the headers when
2985               ;; posting. 
2986               (when value-value
2987                 (make-local-variable gnus-required-headers)
2988                 (make-local-variable gnus-required-mail-headers)
2989                 (push (cons (car attribute) value-value) 
2990                       gnus-required-headers)
2991                 (push (cons (car attribute) value-value) 
2992                       gnus-required-mail-headers)))))))))
2993
2994 (defun gnus-inews-set-point ()
2995   "Move point to where the user probably wants to find it."
2996   (gnus-inews-narrow-to-headers)
2997   (cond 
2998    ((re-search-forward "^[^:]+:[ \t]*$" nil t)
2999     (search-backward ":" )
3000     (widen)
3001     (forward-char 2))
3002    (t
3003     (goto-char (point-max))
3004     (widen)
3005     (forward-line 1)
3006     (unless (looking-at "$")
3007       (forward-line 2)))))
3008   
3009 ;;; Allow redefinition of functions.
3010
3011 (gnus-ems-redefine)
3012
3013 (provide 'gnus-msg)
3014
3015 ;;; gnus-msg.el ends here