*** empty log message ***
[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 (car (cdr (gnus-extract-address-components
1395                                             from))))
1396                        (downcase (gnus-inews-real-user-address))))
1397                  (or (null sender)
1398                      (not 
1399                       (string=
1400                        (downcase (car (cdr (gnus-extract-address-components
1401                                             sender))))
1402                        (downcase secure-sender)))))
1403         (goto-char (point-min))    
1404         ;; Rename any old Sender headers to Original-Sender.
1405         (when (re-search-forward "^Sender:" nil t)
1406           (beginning-of-line)
1407           (insert "Original-")
1408           (beginning-of-line))
1409         (insert "Sender: " secure-sender "\n")))))
1410
1411 (defun gnus-inews-insert-signature ()
1412   "Insert a signature file.
1413 If `gnus-signature-function' is bound and returns a string, this
1414 string is used instead of the variable `gnus-signature-file'.
1415 In either case, if the string is a file name, this file is
1416 inserted. If the string is not a file name, the string itself is
1417 inserted. 
1418
1419 If you never want any signature inserted, set both of these variables to
1420 nil."
1421   (save-excursion
1422     (let ((signature 
1423            (or (and gnus-signature-function
1424                     (funcall gnus-signature-function gnus-newsgroup-name))
1425                gnus-signature-file)))
1426       (if (and signature
1427                (or (file-exists-p signature)
1428                    (string-match " " signature)
1429                    (not (string-match 
1430                          "^/[^/]+/" (expand-file-name signature)))))
1431           (progn
1432             (goto-char (point-max))
1433             (if (and mail-signature (search-backward "\n-- \n" nil t))
1434                 ()
1435               ;; Delete any previous signatures.
1436               (if (search-backward "\n-- \n" nil t)
1437                   (delete-region (point) (point-max)))
1438               (or (eolp) (insert "\n"))
1439               (insert "-- \n")
1440               (if (file-exists-p signature)
1441                   (insert-file-contents signature)
1442                 (insert signature))
1443               (goto-char (point-max))
1444               (or (bolp) (insert "\n"))))))))
1445
1446 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1447 (defun gnus-inews-insert-mime-headers ()
1448   (goto-char (point-min))
1449   (let ((mail-header-separator 
1450          (progn 
1451            (goto-char (point-min))
1452            (if (and (search-forward (concat "\n" mail-header-separator "\n")
1453                                     nil t)
1454                     (not (search-backward "\n\n" nil t)))
1455                mail-header-separator
1456              ""))))
1457     (or (mail-position-on-field "Mime-Version")
1458         (insert "1.0")
1459         (cond ((save-restriction
1460                  (widen)
1461                  (goto-char (point-min))
1462                  (re-search-forward "[\200-\377]" nil t))
1463                (or (mail-position-on-field "Content-Type")
1464                    (insert "text/plain; charset=ISO-8859-1"))
1465                (or (mail-position-on-field "Content-Transfer-Encoding")
1466                    (insert "8bit")))
1467               (t (or (mail-position-on-field "Content-Type")
1468                      (insert "text/plain; charset=US-ASCII"))
1469                  (or (mail-position-on-field "Content-Transfer-Encoding")
1470                      (insert "7bit")))))))
1471
1472 (defun gnus-inews-do-fcc ()
1473   "Process Fcc headers in the current buffer.
1474 Unless the first character of the field is `|', the article is saved
1475 to the specified file using the function specified by the variable
1476 gnus-author-copy-saver.  The default function rmail-output saves in
1477 Unix mailbox format.
1478
1479 If the first character is `|', the contents of the article is sent to
1480 a program specified by the rest of the value."
1481   (let ((case-fold-search t)            ;Should ignore case.
1482         list file)
1483     (save-excursion
1484       (save-restriction
1485         (nnheader-narrow-to-headers)
1486         (while (setq file (mail-fetch-field "fcc"))
1487           (push file list)
1488           (nnheader-remove-header "fcc" nil t))
1489         ;; Process FCC operations.
1490         (widen)
1491         (while list
1492           (setq file (pop list))
1493           (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
1494               ;; Pipe the article to the program in question.
1495               (call-process-region (point-min) (point-max) shell-file-name
1496                                    nil nil nil "-c" (match-string 1 file))
1497             ;; Save the article.
1498             (setq file (expand-file-name file))
1499             (gnus-make-directory (file-name-directory file))
1500             (if (and gnus-author-copy-saver
1501                      (not (eq gnus-author-copy-saver 'rmail-output)))
1502                 (funcall gnus-author-copy-saver file)
1503               (if (and (file-readable-p file) (mail-file-babyl-p file))
1504                   (gnus-output-to-rmail file)
1505                 (let ((mail-use-rfc822 t))
1506                   (rmail-output file 1 t t))))))))))
1507
1508 (defun gnus-inews-path ()
1509   "Return uucp path."
1510   (let ((login-name (gnus-inews-login-name)))
1511     (cond ((null gnus-use-generic-path)
1512            (concat (nth 1 gnus-select-method) "!" login-name))
1513           ((stringp gnus-use-generic-path)
1514            ;; Support GENERICPATH.  Suggested by vixie@decwrl.dec.com.
1515            (concat gnus-use-generic-path "!" login-name))
1516           (t login-name))))
1517
1518 (defun gnus-inews-user-name ()
1519   "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1520   (let ((full-name (gnus-inews-full-name))
1521         (address (if (or gnus-user-login-name gnus-use-generic-from
1522                          gnus-local-domain (getenv "DOMAINNAME"))
1523                      (concat (gnus-inews-login-name) "@"
1524                              (gnus-inews-domain-name gnus-use-generic-from))
1525                    user-mail-address))) 
1526     (or gnus-user-from-line
1527         (concat address
1528                 ;; User's full name.
1529                 (cond ((string-equal full-name "&") ;Unix hack.
1530                        (concat " (" (user-login-name) ")"))
1531                       ((string-match "[^ ]+@[^ ]+ +(.*)" address)
1532                        "")
1533                       (t
1534                        (concat " (" full-name ")")))))))
1535
1536 (defun gnus-inews-real-user-address ()
1537   "Return the \"real\" user address.
1538 This function tries to ignore all user modifications, and 
1539 give as trustworthy answer as possible."
1540   (concat (user-login-name) "@" (system-name)))
1541
1542 (defun gnus-inews-login-name ()
1543   "Return login name."
1544   (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1545
1546 (defun gnus-inews-full-name ()
1547   "Return full user name."
1548   (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1549
1550 (defun gnus-inews-domain-name (&optional genericfrom)
1551   "Return user's domain name.
1552 If optional argument GENERICFROM is a string, use it as the domain
1553 name; if it is non-nil, strip off local host name from the domain name.
1554 If the function `system-name' returns full internet name and the
1555 domain is undefined, the domain name is got from it."
1556   (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1557       (let* ((system-name (system-name))
1558              (domain 
1559               (or (if (stringp genericfrom) genericfrom)
1560                   (getenv "DOMAINNAME")
1561                   (and (boundp 'mail-host-address)
1562                        mail-host-address)
1563                   gnus-local-domain
1564                   ;; Function `system-name' may return full internet name.
1565                   ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1566                   (if (string-match "\\.." system-name)
1567                       ;; Some machines return "name.", and that's not
1568                       ;; very nice. 
1569                       (substring system-name (1- (match-end 0))))
1570                   (read-string "Domain name (no host): ")))
1571              (host (or (if (string-match "\\." system-name)
1572                            (substring system-name 0 (match-beginning 0)))
1573                        system-name)))
1574         (if (string-equal "." (substring domain 0 1))
1575             (setq domain (substring domain 1)))
1576         ;; Support GENERICFROM as same as standard Bnews system.
1577         ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1578         (cond ((null genericfrom)
1579                (concat host "." domain))
1580               ;;((stringp genericfrom) genericfrom)
1581               (t domain)))
1582     (if (string-match "\\." (system-name))
1583         (system-name)
1584       (if (string-match "@\\([^ ]+\\)\\($\\| \\)" user-mail-address)
1585           (substring user-mail-address 
1586                      (match-beginning 1) (match-end 1))
1587         "bogus-domain"))))
1588
1589 (defun gnus-inews-full-address ()
1590   (let ((domain (gnus-inews-domain-name))
1591         (system (system-name))
1592         (case-fold-search t))
1593     (if (string-match "\\." system) system
1594       (if (string-match (concat "^" (regexp-quote system)) domain) domain
1595         (concat system "." domain)))))
1596
1597 (defun gnus-inews-expires ()
1598   "Return an Expires header based on `gnus-article-expires'."
1599   (let ((current (current-time))
1600         (future (* 1.0 gnus-article-expires 60 60 24)))
1601     ;; Add the future to current.
1602     (setcar current (+ (car current) (round (/ future (expt 2 16)))))
1603     (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
1604     ;; Return the date in the future in UT.
1605     (timezone-make-date-arpa-standard 
1606      (current-time-string current) (current-time-zone) '(0 "UT"))))
1607
1608 (defun gnus-inews-distribution ()
1609   "Return the current Distribution header, if any."
1610   (when (and gnus-distribution-function
1611              (fboundp gnus-distribution-function))
1612     (funcall gnus-distribution-function (or gnus-newsgroup-name ""))))
1613
1614 (defun gnus-inews-message-id ()
1615   "Generate unique Message-ID for user."
1616   ;; Message-ID should not contain a slash and should be terminated by
1617   ;; a number.  I don't know the reason why it is so.
1618   (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1619
1620 (defvar gnus-unique-id-char nil)
1621
1622 ;; If you ever change this function, make sure the new version
1623 ;; cannot generate IDs that the old version could.
1624 ;; You might for example insert a "." somewhere (not next to another dot
1625 ;; or string boundary), or modify the newsreader name to "Ding".
1626 (defun gnus-inews-unique-id ()
1627   ;; Don't use microseconds from (current-time), they may be unsupported.
1628   ;; Instead we use this randomly inited counter.
1629   (setq gnus-unique-id-char
1630         (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1631            ;; (current-time) returns 16-bit ints,
1632            ;; and 2^16*25 just fits into 4 digits i base 36.
1633            (* 25 25)))
1634   (let ((tm (if (fboundp 'current-time)
1635                 (current-time) '(12191 46742 287898))))
1636     (concat
1637      (if (memq system-type '(ms-dos emx vax-vms))
1638          (let ((user (downcase (gnus-inews-login-name))))
1639            (while (string-match "[^a-z0-9_]" user)
1640              (aset user (match-beginning 0) ?_))
1641            user)
1642        (gnus-number-base36 (user-uid) -1))
1643      (gnus-number-base36 (+ (car   tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1644      (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1645      ;; Append the newsreader name, because while the generated
1646      ;; ID is unique to this newsreader, other newsreaders might
1647      ;; otherwise generate the same ID via another algorithm.
1648      ".fsf")))
1649
1650 (defun gnus-inews-date ()
1651   "Current time string."
1652   (let ((now (current-time)))
1653     (timezone-make-date-arpa-standard 
1654      (current-time-string now) (current-time-zone now))))
1655
1656 (defun gnus-inews-organization ()
1657   "Return user's organization.
1658 The ORGANIZATION environment variable is used if defined.
1659 If not, the variable `gnus-local-organization' is used instead.
1660 If it is a function, the function will be called with the current
1661 newsgroup name as the argument.
1662 If this is a file name, the contents of this file will be used as the
1663 organization."
1664   (let* ((organization 
1665           (or (getenv "ORGANIZATION")
1666               (if gnus-local-organization
1667                   (if (gnus-functionp gnus-local-organization)
1668                       (funcall gnus-local-organization gnus-newsgroup-name)
1669                     gnus-local-organization))
1670               gnus-organization-file
1671               "~/.organization")))
1672     (and (stringp organization)
1673          (> (length organization) 0)
1674          (or (file-exists-p organization)
1675              (string-match " " organization)
1676              (not (string-match "^/usr/lib/\\|^~/" organization)))
1677          (save-excursion
1678            (gnus-set-work-buffer)
1679            (if (file-exists-p organization)
1680                (insert-file-contents organization)
1681              (insert organization))
1682            (goto-char (point-min))
1683            (while (re-search-forward " *\n *" nil t)
1684              (replace-match " " t t))
1685            (buffer-substring (point-min) (point-max))))))
1686
1687 (defun gnus-inews-lines ()
1688   "Count the number of lines and return numeric string."
1689   (save-excursion
1690     (save-restriction
1691       (widen)
1692       (goto-char (point-min))
1693       (re-search-forward 
1694        (concat "^" (regexp-quote mail-header-separator) "$"))
1695       (forward-line 1)
1696       (int-to-string (count-lines (point) (point-max))))))
1697
1698 (defun gnus-inews-in-reply-to ()
1699   "Return the In-Reply-To header for this message."
1700   gnus-in-reply-to)
1701
1702 \f
1703 ;;;
1704 ;;; Gnus Mail Functions 
1705 ;;;
1706
1707 ;;; Mail reply commands of Gnus summary mode
1708
1709 (defun gnus-summary-reply (yank &optional yank-articles)
1710   "Reply mail to news author.
1711 If prefix argument YANK is non-nil, original article is yanked automatically.
1712 Customize the variable gnus-mail-reply-method to use another mailer."
1713   (interactive "P")
1714   ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1715   ;; Stripping headers should be specified with mail-yank-ignored-headers.
1716   (gnus-set-global-variables)
1717   (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1718   (gnus-summary-select-article)
1719   (bury-buffer gnus-article-buffer)
1720   (gnus-mail-reply (or yank-articles (not (not yank)))))
1721
1722 (defun gnus-summary-reply-with-original (n)
1723   "Reply mail to news author with original article.
1724 Customize the variable gnus-mail-reply-method to use another mailer."
1725   (interactive "P")
1726   (gnus-summary-reply t (gnus-summary-work-articles n)))
1727
1728 (defun gnus-summary-mail-forward (post)
1729   "Forward the current message to another user.
1730 Customize the variable gnus-mail-forward-method to use another mailer."
1731   (interactive "P")
1732   (gnus-set-global-variables)
1733   (gnus-summary-select-article)
1734   (gnus-copy-article-buffer)
1735   (if post
1736       (gnus-forward-using-post gnus-original-article-buffer)
1737     (gnus-mail-forward gnus-original-article-buffer)))
1738
1739 (defun gnus-summary-resend-message (address)
1740   "Resend the current article to ADDRESS."
1741   (interactive "sResend message to: ")
1742   (gnus-summary-select-article)
1743   (save-excursion
1744     (let (resent beg)
1745       ;; We first set up a normal mail buffer.
1746       (nnheader-set-temp-buffer " *Gnus resend*")
1747       ;; This code from sendmail.el
1748       (insert "To: ")
1749       (let ((fill-prefix "\t")
1750             (address-start (point)))
1751         (insert address "\n")
1752         (fill-region-as-paragraph address-start (point-max)))
1753       (insert mail-header-separator "\n")
1754       ;; Insert our usual headers.
1755       (gnus-inews-narrow-to-headers)
1756       (gnus-inews-insert-headers '(From Date To))
1757       (goto-char (point-min))
1758       ;; Rename them all to "Resent-*".
1759       (while (re-search-forward "^[A-Za-z]" nil t)
1760         (forward-char -1)
1761         (insert "Resent-"))
1762       (widen)
1763       (forward-line)
1764       (delete-region (point) (point-max))
1765       (setq beg (point))
1766       ;; Insert the message to be resent.
1767       (insert-buffer-substring gnus-original-article-buffer)
1768       (goto-char (point-min))
1769       (search-forward "\n\n")
1770       (forward-char -1)
1771       (insert mail-header-separator)
1772       ;; Rename all old ("Also-")Resent headers.
1773       (while (re-search-backward "^\\(Also-\\)?Resent-" beg t)
1774         (beginning-of-line)
1775         (insert "Also-"))
1776       ;; Send it.
1777       (mail-send)
1778       (kill-buffer (current-buffer)))))
1779
1780 (defun gnus-summary-post-forward ()
1781   "Forward the current article to a newsgroup."
1782   (interactive)
1783   (gnus-summary-mail-forward t))
1784
1785 (defvar gnus-nastygram-message 
1786   "The following article was inappropriately posted to %s.\n"
1787   "Format string to insert in nastygrams.
1788 The current group name will be inserted at \"%s\".")
1789
1790 (defun gnus-summary-mail-nastygram (n)
1791   "Send a nastygram to the author of the current article."
1792   (interactive "P")
1793   (if (or gnus-expert-user
1794           (gnus-y-or-n-p 
1795            "Really send a nastygram to the author of the current article? "))
1796       (let ((group gnus-newsgroup-name))
1797         (gnus-summary-reply-with-original n)
1798         (set-buffer gnus-mail-buffer)
1799         (insert (format gnus-nastygram-message group))
1800         (gnus-mail-send-and-exit))))
1801
1802 (defun gnus-summary-mail-other-window ()
1803   "Compose mail in other window.
1804 Customize the variable `gnus-mail-other-window-method' to use another
1805 mailer."
1806   (interactive)
1807   (gnus-set-global-variables)
1808   (gnus-new-mail
1809    ;; We might want to prompt here.
1810    (when (and gnus-interactive-post
1811               (not gnus-expert-user))
1812      (read-string "To: ")))
1813   (gnus-configure-windows 'summary-mail 'force))
1814
1815 (defun gnus-new-mail (&optional to)
1816   (let (subject)
1817     (when (and gnus-interactive-post
1818                (not gnus-expert-user))
1819       (setq subject (read-string "Subject: ")))
1820     (pop-to-buffer gnus-mail-buffer)
1821     (erase-buffer)
1822     (gnus-mail-setup 'new to subject)
1823     (gnus-inews-insert-gcc)
1824     (gnus-inews-insert-archive-gcc)
1825     (run-hooks 'gnus-mail-hook)))
1826
1827 (defun gnus-new-empty-mail ()
1828   "Create a new, virtually empty mail mode buffer."
1829   (pop-to-buffer gnus-mail-buffer)
1830   (gnus-mail-setup 'new "" ""))
1831
1832 (defun gnus-mail-reply (&optional yank to-address followup)
1833   (save-excursion
1834     (set-buffer gnus-summary-buffer)
1835     (let ((group (gnus-group-real-name gnus-newsgroup-name))
1836           (cur (cons (current-buffer) (cdr gnus-article-current)))
1837           (winconf (current-window-configuration))
1838           from subject date reply-to message-of to cc
1839           references message-id sender follow-to sendto elt new-cc new-to
1840           mct mctdo gnus-warning)
1841       (set-buffer (get-buffer-create gnus-mail-buffer))
1842       (mail-mode)
1843       (if (and (buffer-modified-p)
1844                (> (buffer-size) 0)
1845                (not (gnus-y-or-n-p 
1846                      "Unsent message being composed; erase it? ")))
1847           ()
1848         (erase-buffer)
1849         (save-excursion
1850           (gnus-copy-article-buffer)
1851           (save-restriction
1852             (set-buffer gnus-article-copy)
1853             (nnheader-narrow-to-headers)
1854             (if (not followup)
1855                 ;; This is a regular reply.
1856                 (if (gnus-functionp gnus-reply-to-function)
1857                     (setq follow-to (funcall gnus-reply-to-function group)))
1858               ;; This is a followup.
1859               (if (gnus-functionp gnus-followup-to-function)
1860                   (save-excursion
1861                     (setq follow-to
1862                           (funcall gnus-followup-to-function group)))))
1863             (setq from (mail-fetch-field "from"))
1864             (setq date (or (mail-fetch-field "date") 
1865                            (mail-header-date gnus-current-headers)))
1866             (setq message-of (gnus-message-of from date))
1867             (setq sender (mail-fetch-field "sender"))
1868             (setq subject (or (mail-fetch-field "subject") "none"))
1869             ;; Remove any (buggy) Re:'s that are present and make a
1870             ;; proper one.
1871             (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1872                  (setq subject (substring subject (match-end 0))))
1873             (setq subject (concat "Re: " subject))
1874             (setq to (mail-fetch-field "to"))
1875             (setq cc (mail-fetch-field "cc"))
1876             (setq mct (mail-fetch-field "mail-copies-to"))
1877             (setq reply-to
1878                   (unless (gnus-group-get-parameter group 'broken-reply-to)
1879                     (mail-fetch-field "reply-to")))
1880             (setq references (mail-fetch-field "references"))
1881             (setq message-id (mail-fetch-field "message-id"))
1882             (when (and (setq gnus-warning (mail-fetch-field "gnus-warning"))
1883                        (string-match "<[^>]+>" gnus-warning))
1884               (setq message-id (match-string 0 gnus-warning)))
1885             
1886             (setq mctdo (not (equal mct "never")))
1887
1888             (if (not (and followup (not to-address)))
1889                 (setq new-to (or reply-to from))
1890               (let (ccalist)
1891                 (save-excursion
1892                   (gnus-set-work-buffer)
1893                   (unless (equal mct "never")
1894                     (insert (or reply-to from "")))
1895                   (insert 
1896                    (if (bolp) "" ", ") (or to "")
1897                    (if (or (not mct) (not mctdo)) ""
1898                      (concat (if (bolp) "" ", ") mct))
1899                    (if cc (concat (if (bolp) "" ", ") cc) ""))
1900                   ;; Remove addresses that match `rmail-dont-reply-to-names'. 
1901                   (insert (prog1 (rmail-dont-reply-to (buffer-string))
1902                             (erase-buffer)))
1903                   (goto-char (point-min))
1904                   (setq ccalist
1905                         (mapcar
1906                          (lambda (addr)
1907                            (cons (mail-strip-quoted-names addr) addr))
1908                          (nreverse (gnus-mail-parse-comma-list))))
1909                   (let ((s ccalist))
1910                     (while s
1911                       (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
1912                 (setq new-to (cdr (pop ccalist)))
1913                 (setq new-cc 
1914                       (mapconcat 
1915                        (lambda (addr) (cdr addr))
1916                        ccalist ", "))))
1917             (widen)))
1918
1919         (setq news-reply-yank-from (or from "(nobody)"))
1920         (setq news-reply-yank-message-id
1921               (or message-id "(unknown Message-ID)"))
1922
1923         ;; Gather the "to" addresses out of the follow-to list and remove
1924         ;; them as we go.
1925         (if (and follow-to (listp follow-to))
1926             (while (setq elt (assoc "To" follow-to))
1927               (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1928               (setq follow-to (delq elt follow-to))))
1929
1930         (gnus-mail-setup 
1931          (if followup 'followup 'reply)
1932          (or to-address 
1933              (if (and follow-to (not (stringp follow-to))) sendto
1934                (or follow-to new-to sender "")))
1935          subject message-of
1936          (if (zerop (length new-cc)) nil new-cc)
1937          gnus-article-copy)
1938
1939         (make-local-variable 'gnus-article-reply)
1940         (setq gnus-article-reply cur)
1941         (make-local-variable 'gnus-prev-winconf)
1942         (setq gnus-prev-winconf winconf)
1943         (make-local-variable 'gnus-reply-subject)
1944         (setq gnus-reply-subject subject)
1945         (make-local-variable 'gnus-in-reply-to)
1946         (setq gnus-in-reply-to message-of)
1947
1948         (auto-save-mode auto-save-default)
1949         (gnus-inews-insert-gcc)
1950         (gnus-inews-insert-archive-gcc)
1951
1952         (when (and follow-to (listp follow-to))
1953           (let (beg)
1954             (gnus-inews-narrow-to-headers)
1955             (re-search-forward "^To:" nil t)
1956             (beginning-of-line)
1957             (forward-line 1)
1958             (setq beg (point))
1959             ;; Insert the rest of the Follow-To headers.
1960             (while follow-to
1961               (goto-char (point-min))
1962               (if (not (re-search-forward 
1963                         (concat "^" (caar follow-to) ": *") nil t))
1964                   (progn
1965                     (goto-char beg)
1966                     (insert (caar follow-to) ": " (cdar follow-to) "\n"))
1967                 (unless (eolp)
1968                   (insert ", "))
1969                 (insert (cdar follow-to)))
1970               (setq follow-to (cdr follow-to)))
1971             (widen)))
1972         (nnheader-insert-references references message-id)
1973
1974         ;; Now the headers should be ok, so we do the yanking.
1975         (goto-char (point-min))
1976         (re-search-forward
1977          (concat "^" (regexp-quote mail-header-separator) "$"))
1978         (forward-line 1)
1979         (if (not yank)
1980             (gnus-configure-windows 'reply 'force)
1981           (let ((last (point))
1982                 end)
1983             (if (not (listp yank))
1984                 (progn
1985                   ;; Just a single article being yanked.
1986                   (save-excursion
1987                     (mail-yank-original nil))
1988                   (or mail-yank-hooks mail-citation-hook
1989                       (run-hooks 'news-reply-header-hook)))
1990               (while yank
1991                 (save-window-excursion
1992                   (set-buffer gnus-summary-buffer)
1993                   (gnus-summary-select-article nil nil nil (car yank))
1994                   (gnus-summary-remove-process-mark (car yank)))
1995                 (save-excursion
1996                   (setq end (point))
1997                   (gnus-copy-article-buffer)
1998                   (mail-yank-original nil)
1999                   (save-restriction
2000                     (narrow-to-region (point-min) (point))
2001                     (goto-char (mark t))
2002                     (let ((news-reply-yank-from
2003                            (save-excursion 
2004                              (set-buffer gnus-article-buffer)
2005                              (or (mail-fetch-field "from") "(nobody)")))
2006                           (news-reply-yank-message-id
2007                            (save-excursion 
2008                              (set-buffer gnus-article-buffer)
2009                              (or (mail-fetch-field "message-id")
2010                                  "(unknown Message-ID)"))))
2011                       (or mail-yank-hooks mail-citation-hook
2012                           (run-hooks 'news-reply-header-hook))
2013                       (setq end (point-max)))))
2014                 (goto-char end)
2015                 (setq yank (cdr yank))))
2016             (goto-char last))
2017           (forward-line 2)
2018           (gnus-configure-windows 'reply-yank 'force))
2019         (run-hooks 'gnus-mail-hook)
2020         ;; Mark this buffer as unchanged.
2021         (set-buffer-modified-p nil)))))
2022
2023 (defun gnus-mail-parse-comma-list ()
2024   (let (accumulated
2025         beg)
2026     (skip-chars-forward " ")
2027     (while (not (eobp))
2028       (setq beg (point))
2029       (skip-chars-forward "^,")
2030       (while (zerop
2031               (save-excursion 
2032                 (save-restriction
2033                   (let ((i 0))
2034                     (narrow-to-region beg (point))
2035                     (goto-char beg)
2036                     (logand (progn
2037                               (while (search-forward "\"" nil t)
2038                                 (incf i))
2039                               (if (zerop i) 2 i)) 2)))))
2040         (skip-chars-forward ",")
2041         (skip-chars-forward "^,"))
2042       (skip-chars-backward " ")
2043       (setq accumulated
2044             (cons (buffer-substring beg (point))
2045                   accumulated))
2046       (skip-chars-forward "^,")
2047       (skip-chars-forward ", "))
2048     accumulated))
2049
2050 (defun gnus-new-news (&optional group inhibit-prompt)
2051   "Set up a *Post Gnus* buffer that points to GROUP.
2052 If INHIBIT-PROMPT, never prompt for a Subject."
2053   (let ((winconf (current-window-configuration))
2054         subject)
2055     (when (and gnus-interactive-post
2056                (not inhibit-prompt)
2057                (not gnus-expert-user))
2058       (setq subject (read-string "Subject: ")))
2059     (pop-to-buffer gnus-post-news-buffer)  
2060     (erase-buffer)
2061     (news-reply-mode)
2062     ;; Let posting styles be configured.
2063     (gnus-configure-posting-styles)
2064     (news-setup nil subject nil (and group (gnus-group-real-name group)) nil)
2065     ;; Associate this buffer with the draft group.
2066     (gnus-enter-buffer-into-draft)
2067     (goto-char (point-min))
2068
2069     (unless (re-search-forward 
2070              (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2071       (goto-char (point-max)))
2072     (insert "\n\n")
2073
2074     (gnus-inews-insert-bfcc)
2075     (gnus-inews-insert-gcc)
2076     (gnus-inews-insert-archive-gcc)
2077     (gnus-inews-insert-signature)
2078     (and gnus-post-prepare-function
2079          (gnus-functionp gnus-post-prepare-function)
2080          (funcall gnus-post-prepare-function group))
2081     (run-hooks 'gnus-post-prepare-hook)
2082     (gnus-inews-set-point)
2083     (make-local-variable 'gnus-prev-winconf)
2084     (setq gnus-prev-winconf winconf)
2085     (gnus-inews-modify-mail-mode-map)
2086     (local-set-key "\C-c\C-c" 'gnus-inews-news)))
2087
2088 (defun gnus-news-followup (&optional yank group)
2089   (save-excursion
2090     (set-buffer gnus-summary-buffer)
2091     (if (not (or (not gnus-novice-user)
2092                  gnus-expert-user
2093                  (gnus-y-or-n-p
2094                   "Are you sure you want to post to all of USENET? ")))
2095         ()
2096       (let ((group (gnus-group-real-name (or group gnus-newsgroup-name)))
2097             (cur (cons (current-buffer) (cdr gnus-article-current)))
2098             (winconf (current-window-configuration))
2099             from subject date reply-to message-of
2100             references message-id sender follow-to sendto elt 
2101             followup-to distribution newsgroups gnus-warning)
2102         (set-buffer (get-buffer-create gnus-post-news-buffer))
2103         (news-reply-mode)
2104         ;; Associate this buffer with the draft group.
2105         (gnus-enter-buffer-into-draft)
2106         (if (and (buffer-modified-p)
2107                  (> (buffer-size) 0)
2108                  (not (gnus-y-or-n-p 
2109                        "Unsent message being composed; erase it? ")))
2110             ()
2111           (erase-buffer)
2112           (save-excursion
2113             (gnus-copy-article-buffer)
2114             (save-restriction
2115               (set-buffer gnus-article-copy)
2116               (nnheader-narrow-to-headers)
2117               (if (gnus-functionp gnus-followup-to-function)
2118                   (save-excursion
2119                     (setq follow-to
2120                           (funcall gnus-followup-to-function group))))
2121               (setq from (mail-fetch-field "from"))
2122               (setq date (or (mail-fetch-field "date") 
2123                              (mail-header-date gnus-current-headers)))
2124               (setq message-of (gnus-message-of from date))
2125               (setq subject (or (mail-fetch-field "subject") "none"))
2126               ;; Remove any (buggy) Re:'s that are present and make a
2127               ;; proper one.
2128               (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
2129                    (setq subject (substring subject (match-end 0))))
2130               (setq subject (concat "Re: " subject))
2131               (setq references (mail-fetch-field "references"))
2132               (setq message-id (mail-fetch-field "message-id"))
2133               (when (and (setq gnus-warning (mail-fetch-field "gnus-warning"))
2134                          (string-match "<[^>]+>" gnus-warning))
2135                 (setq message-id (match-string 0 gnus-warning)))
2136               (setq followup-to (mail-fetch-field "followup-to"))
2137               (setq newsgroups (mail-fetch-field "newsgroups"))
2138               (setq distribution (mail-fetch-field "distribution"))
2139               ;; Remove bogus distribution.
2140               (and (stringp distribution)
2141                    (string-match "world" distribution)
2142                    (setq distribution nil))
2143               (widen)))
2144
2145           (setq news-reply-yank-from (or from "(nobody)"))
2146           (setq news-reply-yank-message-id
2147                 (or message-id "(unknown Message-ID)"))
2148
2149           ;; Gather the "to" addresses out of the follow-to list and remove
2150           ;; them as we go.
2151           (if (and follow-to (listp follow-to))
2152               (while (setq elt (assoc "Newsgroups" follow-to))
2153                 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
2154                 (setq follow-to (delq elt follow-to))))
2155
2156           ;; Let posting styles be configured.
2157           (gnus-configure-posting-styles)
2158
2159           (news-setup
2160            nil subject nil 
2161            (or sendto 
2162                (and followup-to
2163                     gnus-use-followup-to
2164                     (or (not (eq gnus-use-followup-to 'ask))
2165                         (equal followup-to newsgroups)
2166                         (gnus-y-or-n-p 
2167                          (format "Use Followup-To %s? " followup-to)))
2168                     followup-to)
2169                newsgroups group "")
2170            gnus-article-copy)
2171
2172           (make-local-variable 'gnus-article-reply)
2173           (setq gnus-article-reply cur)
2174           (make-local-variable 'gnus-prev-winconf)
2175           (setq gnus-prev-winconf winconf)
2176           (make-local-variable 'gnus-reply-subject)
2177           (setq gnus-reply-subject (mail-header-subject gnus-current-headers))
2178           (make-local-variable 'gnus-in-reply-to)
2179           (setq gnus-in-reply-to message-of)
2180           (when (and followup-to newsgroups)
2181             (make-local-variable 'gnus-newsgroup-followup)
2182             (setq gnus-newsgroup-followup
2183                   (cons newsgroups followup-to)))
2184
2185           (gnus-inews-insert-signature)
2186
2187           (and gnus-post-prepare-function
2188                (gnus-functionp gnus-post-prepare-function)
2189                (funcall gnus-post-prepare-function group))
2190           (run-hooks 'gnus-post-prepare-hook)
2191
2192           (auto-save-mode auto-save-default)
2193           (gnus-inews-modify-mail-mode-map)
2194           (local-set-key "\C-c\C-c" 'gnus-inews-news)
2195
2196           (if (and follow-to (listp follow-to))
2197               (progn
2198                 (goto-char (point-min))
2199                 (and (re-search-forward "^Newsgroups:" nil t)
2200                      (forward-line 1))
2201                 (while follow-to
2202                   (insert (car (car follow-to)) ": " 
2203                           (cdr (car follow-to)) "\n")
2204                   (setq follow-to (cdr follow-to)))))
2205           
2206           ;; If a distribution existed, we use it.
2207           (if distribution
2208               (progn
2209                 (mail-position-on-field "Distribution")
2210                 (insert distribution)))
2211           
2212           (nnheader-insert-references references message-id)
2213
2214           ;; Handle `gnus-auto-mail-to-author'.
2215           ;; Suggested by Daniel Quinlan <quinlan@best.com>.
2216           ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
2217           (let ((to (if (if (eq gnus-auto-mail-to-author 'ask)
2218                             (y-or-n-p "Also send mail to author? ")
2219                           gnus-auto-mail-to-author)
2220                         (or (save-excursion
2221                               (set-buffer gnus-article-copy)
2222                               (unless (gnus-group-get-parameter
2223                                        group 'broken-reply-to)
2224                                 (gnus-fetch-field "reply-to")))
2225                             from)))
2226                 (x-mail (save-excursion
2227                           (set-buffer gnus-article-copy)
2228                           (gnus-fetch-field "x-mail-copy-to"))))
2229             ;; Deny sending copy if there's a negative X-Mail-Copy-To
2230             ;; header. 
2231             (if x-mail
2232                 (if (and (string= x-mail "never")
2233                          (not (eq gnus-auto-mail-to-author 'force)))
2234                     (setq to nil)
2235                   (setq to x-mail)))
2236             ;; Insert a To or Cc header.
2237             (if to
2238                 (if (mail-fetch-field "To")
2239                     (progn
2240                       (beginning-of-line)
2241                       (insert "Cc: " to "\n"))
2242                   (mail-position-on-field "To")
2243                   (insert to))))
2244
2245           (gnus-inews-insert-bfcc)
2246           (gnus-inews-insert-gcc)
2247           (gnus-inews-insert-archive-gcc)
2248
2249           ;; Now the headers should be ok, so we do the yanking.
2250           (goto-char (point-min))
2251           (re-search-forward
2252            (concat "^" (regexp-quote mail-header-separator) "$"))
2253           (forward-line 1)
2254           (if (not yank)
2255               (progn
2256                 (gnus-configure-windows 'followup 'force)
2257                 (insert "\n\n")
2258                 (forward-line -2))
2259             (let ((last (point))
2260                   end)
2261               (if (not (listp yank))
2262                   (progn
2263                     (save-excursion
2264                       (mail-yank-original nil))
2265                     (or mail-yank-hooks mail-citation-hook
2266                         (run-hooks 'news-reply-header-hook)))
2267                 (while yank
2268                   (save-window-excursion
2269                     (set-buffer gnus-summary-buffer)
2270                     (gnus-summary-select-article nil nil nil (car yank))
2271                     (gnus-summary-remove-process-mark (car yank)))
2272                   (save-excursion
2273                     (gnus-copy-article-buffer)
2274                     (mail-yank-original nil)
2275                     (setq end (point)))
2276                   (or mail-yank-hooks mail-citation-hook
2277                       (run-hooks 'news-reply-header-hook))
2278                   (goto-char end)
2279                   (setq yank (cdr yank))))
2280               (goto-char last))
2281             (gnus-configure-windows 'followup-yank 'force))
2282         
2283           (make-local-variable 'gnus-article-check-size)
2284           (setq gnus-article-check-size
2285                 (cons (buffer-size) (gnus-article-checksum)))
2286           (gnus-inews-set-point))))))
2287
2288 (defun gnus-message-of (from date)
2289   "Take a FROM and a DATE and return an IN-REPLY-TO."
2290   (when from
2291     (let ((stop-pos 
2292            (string-match "  *at \\|  *@ \\| *(\\| *<" from)))
2293       (concat (if stop-pos (substring from 0 stop-pos) from)
2294               "'s message of " 
2295               (if (or (not date) (string= date ""))
2296                   "(unknown date)" date)))))
2297
2298 (defun gnus-mail-yank-original ()
2299   (interactive)
2300   (save-excursion
2301     (mail-yank-original nil))
2302   (or mail-yank-hooks mail-citation-hook
2303       (run-hooks 'news-reply-header-hook)))
2304
2305 (defun gnus-mail-send-and-exit (&optional dont-send)
2306   "Send the current mail and return to Gnus."
2307   (interactive)
2308   (let* ((reply gnus-article-reply)
2309          (winconf gnus-prev-winconf)
2310          (address-group gnus-add-to-address)
2311          (to-address (and address-group
2312                           (mail-fetch-field "to"))))
2313     (setq gnus-add-to-address nil)
2314     (let ((buffer-file-name nil))
2315       (or dont-send (gnus-mail-send)))
2316     (bury-buffer)
2317     (when (gnus-alive-p)
2318       ;; This mail group doesn't have a `to-list', so we add one
2319       ;; here.  Magic!  
2320       (when to-address
2321         (gnus-group-add-parameter address-group (cons 'to-list to-address)))
2322       (when (and (gnus-buffer-exists-p (car reply))
2323                  (cdr reply))
2324         (save-excursion
2325           (set-buffer (car reply))
2326           (gnus-summary-mark-article-as-replied (cdr reply))))
2327       (and winconf (set-window-configuration winconf)))))
2328
2329 (defun gnus-kill-message-buffer ()
2330   "Kill the current buffer after dissociating it from the draft group."
2331   (interactive)
2332   (when (gnus-y-or-n-p "Dissociate and kill the current buffer? ")
2333     (gnus-dissociate-buffer-from-draft)
2334     (let ((winconf gnus-prev-winconf))
2335       (kill-buffer (current-buffer))
2336       (when winconf 
2337         (set-window-configuration winconf)))))
2338
2339 (defun gnus-put-message ()
2340   "Put the current message in some group and return to Gnus."
2341   (interactive)
2342   (let ((reply gnus-article-reply)
2343         (winconf gnus-prev-winconf)
2344         (group gnus-newsgroup-name)
2345         buf)
2346     
2347     (or (and group (not (gnus-group-read-only-p group)))
2348         (setq group (read-string "Put in group: " nil
2349                                  (gnus-writable-groups))))
2350     (and (gnus-gethash group gnus-newsrc-hashtb)
2351          (error "No such group: %s" group))
2352
2353     (save-excursion
2354       (save-restriction
2355         (widen)
2356         (gnus-inews-narrow-to-headers)
2357         (let (gnus-deletable-headers)
2358           (if (eq major-mode 'mail-mode)
2359               (gnus-inews-insert-headers gnus-required-mail-headers)
2360             (gnus-inews-insert-headers)))
2361         (goto-char (point-max))
2362         (insert "Gcc: " group "\n")
2363         (widen)))
2364
2365     (gnus-inews-do-gcc)
2366
2367     (if (get-buffer gnus-group-buffer)
2368         (progn
2369           (if (gnus-buffer-exists-p (car-safe reply))
2370               (progn
2371                 (set-buffer (car reply))
2372                 (and (cdr reply)
2373                      (gnus-summary-mark-article-as-replied 
2374                       (cdr reply)))))
2375           (and winconf (set-window-configuration winconf))))))
2376
2377 (defun gnus-forward-make-subject (buffer)
2378   (save-excursion
2379     (set-buffer buffer)
2380     (concat "[" (if (memq 'mail (assoc (symbol-name 
2381                                         (car (gnus-find-method-for-group 
2382                                               gnus-newsgroup-name)))
2383                                        gnus-valid-select-methods))
2384                     (gnus-fetch-field "From")
2385                   gnus-newsgroup-name)
2386             "] " (or (gnus-fetch-field "Subject") ""))))
2387
2388 (defun gnus-forward-insert-buffer (buffer)
2389   (save-excursion
2390     (save-restriction
2391       ;; Put point where we want it before inserting the forwarded
2392       ;; message. 
2393       (if gnus-signature-before-forwarded-message
2394           (goto-char (point-max))
2395         (goto-char (point-min))
2396         (re-search-forward
2397          (concat "^" (regexp-quote mail-header-separator) "$"))
2398         (forward-line 1))
2399       ;; Narrow to the area we are to insert.
2400       (narrow-to-region (point) (point))
2401       ;; Insert the separators and the forwarded buffer.
2402       (insert gnus-forward-start-separator)
2403       (insert-buffer-substring buffer)
2404       (goto-char (point-max))
2405       (insert gnus-forward-end-separator)
2406       (gnus-set-text-properties (point-min) (point-max) nil)
2407       ;; Remove all unwanted headers.
2408       (goto-char (point-min))
2409       (forward-line 1)
2410       (save-restriction
2411         (narrow-to-region (point) (if (search-forward "\n\n" nil t)
2412                                       (1- (point))
2413                                     (point)))
2414         (goto-char (point-min))
2415         (let ((case-fold-search t))
2416           (delete-non-matching-lines gnus-forward-included-headers))))))
2417
2418 (defun gnus-mail-forward (&optional buffer)
2419   "Forward the current message to another user using mail."
2420   (let* ((forward-buffer (or buffer (current-buffer)))
2421          (winconf (current-window-configuration))
2422          (subject (gnus-forward-make-subject forward-buffer)))
2423     (set-buffer (get-buffer-create gnus-mail-buffer))
2424     (if (and (buffer-modified-p)
2425              (> (buffer-size) 0)
2426              (not (gnus-y-or-n-p 
2427                    "Unsent message being composed; erase it? ")))
2428         ()
2429       (erase-buffer)
2430       (gnus-mail-setup 'forward nil subject)
2431       (make-local-variable 'gnus-prev-winconf)
2432       (setq gnus-prev-winconf winconf)
2433       (gnus-forward-insert-buffer forward-buffer)
2434       (goto-char (point-min))
2435       (re-search-forward "^To: ?" nil t)
2436       (gnus-configure-windows 'mail-forward 'force)
2437       ;; You have a chance to arrange the message.
2438       (run-hooks 'gnus-mail-forward-hook)
2439       (run-hooks 'gnus-mail-hook))))
2440
2441 (defun gnus-forward-using-post (&optional buffer)
2442   (save-excursion
2443     (let* ((forward-buffer (or buffer (current-buffer))) 
2444            (subject (gnus-forward-make-subject forward-buffer))
2445            (gnus-newsgroup-name nil))
2446       (gnus-post-news 'post nil nil nil nil subject)
2447       (save-excursion
2448         (gnus-forward-insert-buffer forward-buffer)
2449         ;; You have a chance to arrange the message.
2450         (run-hooks 'gnus-mail-forward-hook)))))
2451
2452 (defun gnus-mail-other-window-using-mail ()
2453   "Compose mail other window using mail."
2454   (let ((winconf (current-window-configuration)))
2455     (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
2456     (gnus-inews-modify-mail-mode-map)
2457     (make-local-variable 'gnus-prev-winconf)
2458     (setq gnus-prev-winconf winconf)
2459     (run-hooks 'gnus-mail-hook)
2460     (gnus-configure-windows 'summary-mail 'force)))
2461
2462 (defun gnus-article-mail (yank)
2463   "Send a reply to the address near point.
2464 If YANK is non-nil, include the original article."
2465   (interactive "P")
2466   (let ((address 
2467          (buffer-substring
2468           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
2469           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
2470     (and address
2471          (progn
2472            (switch-to-buffer gnus-summary-buffer)
2473            (gnus-mail-reply yank address)))))
2474
2475 (defun gnus-bug ()
2476   "Send a bug report to the Gnus maintainers."
2477   (interactive)
2478   (let ((winconf (current-window-configuration)))
2479     (delete-other-windows)
2480     (switch-to-buffer "*Gnus Help Bug*")
2481     (erase-buffer)
2482     (insert gnus-bug-message)
2483     (goto-char (point-min))
2484     (pop-to-buffer "*Gnus Bug*")
2485     (erase-buffer)
2486     (mail-mode)
2487     (mail-setup gnus-maintainer nil nil nil nil nil)
2488     (auto-save-mode auto-save-default)
2489     (make-local-variable 'gnus-prev-winconf)
2490     (setq gnus-prev-winconf winconf)
2491     (gnus-inews-modify-mail-mode-map)
2492     (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
2493     (goto-char (point-min))
2494     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2495     (forward-line 1)
2496     (insert (gnus-version) "\n")
2497     (insert (emacs-version))
2498     (insert "\n\n\n\n\n")
2499     (gnus-debug)
2500     (goto-char (point-min))
2501     (search-forward "Subject: " nil t)
2502     (message "")))
2503
2504 (defun gnus-bug-mail-send-and-exit ()
2505   "Send the bug message and exit."
2506   (interactive)
2507   (let ((cur (current-buffer)))
2508     (and (get-buffer "*Gnus Help Bug*")
2509          (kill-buffer "*Gnus Help Bug*"))
2510     (gnus-mail-send-and-exit)
2511     (when (buffer-name cur)
2512       (kill-buffer cur))))
2513
2514 (defun gnus-debug ()
2515   "Attemps to go through the Gnus source file and report what variables have been changed.
2516 The source file has to be in the Emacs load path."
2517   (interactive)
2518   (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el" "nnmail.el"))
2519         file dirs expr olist sym)
2520     (message "Please wait while we snoop your variables...")
2521     (sit-for 0)
2522     (save-excursion
2523       (set-buffer (get-buffer-create " *gnus bug info*"))
2524       (buffer-disable-undo (current-buffer))
2525       (while files
2526         (erase-buffer)
2527         (setq dirs load-path)
2528         (while dirs
2529           (if (or (not (car dirs))
2530                   (not (stringp (car dirs)))
2531                   (not (file-exists-p 
2532                         (setq file (concat (file-name-as-directory 
2533                                             (car dirs)) (car files))))))
2534               (setq dirs (cdr dirs))
2535             (setq dirs nil)
2536             (insert-file-contents file)
2537             (goto-char (point-min))
2538             (if (not (re-search-forward "^;;* *Internal variables" nil t))
2539                 (message "Malformed sources in file %s" file)
2540               (narrow-to-region (point-min) (point))
2541               (goto-char (point-min))
2542               (while (setq expr (condition-case () 
2543                                     (read (current-buffer)) (error nil)))
2544                 (condition-case ()
2545                     (and (eq (car expr) 'defvar)
2546                          (stringp (nth 3 expr))
2547                          (or (not (boundp (nth 1 expr)))
2548                              (not (equal (eval (nth 2 expr))
2549                                          (symbol-value (nth 1 expr)))))
2550                          (setq olist (cons (nth 1 expr) olist)))
2551                   (error nil))))))
2552         (setq files (cdr files)))
2553       (kill-buffer (current-buffer)))
2554     (when (setq olist (nreverse olist))
2555       (insert "------------------ Environment follows ------------------\n\n"))
2556     (while olist
2557       (if (boundp (car olist))
2558           (insert 
2559            (pp-to-string
2560             `(setq ,(symbol-name (car olist))
2561                    ,(if (or (consp (setq sym (symbol-value (car olist))))
2562                             (and (symbolp sym)
2563                                  (not (or (eq sym nil)
2564                                           (eq sym t)))))
2565                         (list 'quote (symbol-value (car olist)))
2566                       (symbol-value (car olist)))
2567                    "\n")))
2568         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
2569       (setq olist (cdr olist)))
2570     (insert "\n\n")
2571     ;; Remove any null chars - they seem to cause trouble for some
2572     ;; mailers. (Byte-compiled output from the stuff above.) 
2573     (goto-char (point-min))
2574     (while (re-search-forward "[\000\200]" nil t)
2575       (replace-match "" t t))))
2576
2577 ;;; Treatment of rejected articles.
2578 ;;; Bounced mail.
2579
2580 (defun gnus-summary-resend-bounced-mail (fetch)
2581   "Re-mail the current message.
2582 This only makes sense if the current message is a bounce message than
2583 contains some mail you have written which has been bounced back to
2584 you.
2585 If FETCH, try to fetch the article that this is a reply to, if indeed
2586 this is a reply."
2587   (interactive "P")
2588   (gnus-summary-select-article t)
2589   ;; Create a mail buffer.
2590   (gnus-new-empty-mail)
2591   (erase-buffer)
2592   (insert-buffer-substring gnus-article-buffer)
2593   (goto-char (point-min))
2594   (or (re-search-forward "--- *Original message.*\n" nil t)
2595       (and (search-forward "\n\n" nil t)
2596            (re-search-forward "^Return-Path:.*\n" nil t)))
2597   ;; We remove everything before the bounced mail.
2598   (delete-region 
2599    (point-min)
2600    (if (re-search-forward "[^ \t]*:" nil t)
2601        (match-beginning 0)
2602      (point)))
2603   (let (references)
2604     (save-excursion
2605       (save-restriction
2606         (nnheader-narrow-to-headers)
2607         (nnheader-remove-header gnus-bounced-headers-junk t)
2608         (setq references (mail-fetch-field "references"))
2609         (goto-char (point-max))
2610         (insert mail-header-separator)))
2611     ;; If there are references, we fetch the article we answered to.  
2612     (and fetch 
2613          references
2614          (string-match "\\(<[^]+>\\)[ \t]*$" references)
2615          (gnus-summary-refer-article 
2616           (substring references (match-beginning 1) (match-end 1)))
2617          (progn
2618            (gnus-summary-show-all-headers)
2619            (gnus-configure-windows 'compose-bounce))))
2620   (goto-char (point-min)))
2621
2622 ;;; Sending mail.
2623
2624 (defun gnus-mail-send (&optional no-generated-headers)
2625   "Send the current buffer as mail.
2626 Headers will be generated before sending."
2627   (interactive)
2628   (unless no-generated-headers
2629     (save-excursion
2630       (save-restriction
2631         (widen)
2632         (gnus-inews-narrow-to-headers)
2633         (gnus-inews-insert-headers gnus-required-mail-headers)
2634         (gnus-inews-remove-empty-headers))))
2635   (widen)
2636   ;; Remove the header separator.
2637   (goto-char (point-min))
2638   (and (re-search-forward
2639         (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2640        (replace-match "" t t))
2641   ;; Run final inews hooks.  This hook may do FCC.
2642   (run-hooks 'gnus-inews-article-hook)
2643   (gnus-inews-do-gcc)
2644   (nnheader-narrow-to-headers)
2645   (nnheader-remove-header "^[gf]cc:" t)
2646   (widen)
2647   (goto-char (point-min))
2648   (search-forward "\n\n")
2649   (forward-char -1)
2650   (insert mail-header-separator)
2651   (mail-send)
2652   (run-hooks 'gnus-message-sent-hook))
2653
2654 (defun gnus-inews-modify-mail-mode-map ()
2655   (use-local-map (copy-keymap (current-local-map)))
2656   (gnus-local-set-keys
2657    "\C-c\C-c" gnus-mail-send-and-exit
2658    "\C-c\M-\C-p" gnus-put-message
2659    "\C-c\C-q" gnus-kill-message-buffer
2660    "\C-c\M-d" gnus-dissociate-buffer-from-draft
2661    "\C-c\C-d" gnus-associate-buffer-with-draft))
2662
2663 (defun gnus-mail-setup (type &optional to subject in-reply-to cc
2664                              replybuffer actions)
2665   ;; Let posting styles be configured.
2666   (gnus-configure-posting-styles)
2667   (funcall
2668    (cond
2669     ((or 
2670       (eq gnus-mail-method 'mh)
2671       (and (or (eq type 'reply) (eq type 'followup))
2672            (eq gnus-mail-reply-method 'gnus-mail-reply-using-mhe))
2673       (and (eq type 'forward)
2674            (eq gnus-mail-forward-method 'gnus-mail-forward-using-mhe))
2675       (and (eq type 'new) 
2676            (eq gnus-mail-other-window-method 
2677                'gnus-mail-other-window-using-mhe)))
2678      'gnus-mh-mail-setup)
2679     ((or 
2680       (eq gnus-mail-method 'vm)
2681       (and (or (eq type 'reply) (eq type 'followup)) 
2682            (eq gnus-mail-reply-method 'gnus-mail-reply-using-vm))
2683       (and (eq type 'forward)
2684            (eq gnus-mail-forward-method 'gnus-mail-forward-using-vm))
2685       (and (eq type 'new) 
2686            (eq gnus-mail-other-window-method 
2687                'gnus-mail-other-window-using-vm)))
2688      'gnus-vm-mail-setup)
2689     ((or
2690       (eq gnus-mail-method 'sendmail)
2691       (and (or (eq type 'reply) (eq type 'followup)) 
2692            (eq gnus-mail-reply-method 'gnus-mail-reply-using-mail))
2693       (and (eq type 'forward)
2694            (eq gnus-mail-forward-method 'gnus-mail-forward-using-mail))
2695       (and (eq type 'new) 
2696            (eq gnus-mail-other-window-method 
2697                'gnus-mail-other-window-using-mail)))
2698      'gnus-sendmail-mail-setup)
2699     (t
2700      (cond ((or (eq type 'reply) (eq type 'followup))
2701             gnus-mail-reply-method)
2702            ((eq type 'forward)
2703             gnus-mail-forward-method)
2704            ((eq type 'new) 
2705             gnus-mail-other-window-method))))
2706    to subject in-reply-to cc replybuffer actions)
2707   ;; Associate this mail buffer with the draft group.
2708   (gnus-enter-buffer-into-draft))
2709
2710 (defun gnus-sendmail-mail-setup (to subject in-reply-to cc replybuffer actions)
2711   (mail-mode)
2712   (mail-setup to subject nil cc replybuffer actions)
2713   (gnus-inews-set-point)
2714   (gnus-inews-modify-mail-mode-map))
2715   
2716 ;;; Gcc handling.
2717
2718 ;; Do Gcc handling, which copied the message over to some group. 
2719 (defun gnus-inews-do-gcc (&optional gcc)
2720   (save-excursion
2721     (save-restriction
2722       (nnheader-narrow-to-headers)
2723       (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
2724             (cur (current-buffer))
2725             end groups group method)
2726         (when gcc
2727           (nnheader-remove-header "gcc")
2728           (widen)
2729           (setq groups (gnus-tokenize-header gcc " ,"))
2730           ;; Copy the article over to some group(s).
2731           (while (setq group (pop groups))
2732             (gnus-check-server 
2733              (setq method
2734                    (cond ((and (null (gnus-get-info group))
2735                                (eq (car gnus-message-archive-method)
2736                                    (car 
2737                                     (gnus-server-to-method
2738                                      (gnus-group-method group)))))
2739                           ;; If the group doesn't exist, we assume
2740                           ;; it's an archive group...
2741                           gnus-message-archive-method)
2742                          (t (gnus-find-method-for-group group)))))
2743             (unless (gnus-request-group group t method)
2744               (gnus-request-create-group group method))
2745             (gnus-check-server method)
2746             (save-excursion
2747               (nnheader-set-temp-buffer " *acc*")
2748               (insert-buffer-substring cur)
2749               (unless (condition-case ()
2750                           (gnus-request-accept-article group t method)
2751                         (error nil))
2752                 (gnus-message 1 "Couldn't store article in group %s: %s" 
2753                               group (gnus-status-message method))
2754                 (sit-for 2))
2755               (kill-buffer (current-buffer)))))))))
2756
2757 (defun gnus-inews-insert-bfcc ()
2758   "Insert Bcc and Fcc headers."
2759   (save-excursion
2760     ;; Handle author copy using BCC field.
2761     (when (and gnus-mail-self-blind
2762                (not (mail-fetch-field "bcc")))
2763       (mail-position-on-field "Bcc")
2764       (insert (if (stringp gnus-mail-self-blind)
2765                   gnus-mail-self-blind
2766                 (user-login-name))))
2767     ;; Handle author copy using FCC field.
2768     (when gnus-author-copy
2769       (mail-position-on-field "Fcc")
2770       (insert gnus-author-copy))))
2771
2772 (defun gnus-inews-insert-gcc ()
2773   "Insert Gcc headers based on `gnus-outgoing-message-group'."
2774   (save-excursion
2775     (save-restriction
2776       (gnus-inews-narrow-to-headers)
2777       (let* ((group gnus-outgoing-message-group)
2778              (gcc (cond 
2779                    ((gnus-functionp group)
2780                     (funcall group))
2781                    ((or (stringp group) (list group))
2782                     group))))
2783         (when gcc
2784           (insert "Gcc: "
2785                   (if (stringp gcc) gcc
2786                     (mapconcat 'identity gcc " "))
2787                   "\n"))))))
2788
2789 (defun gnus-inews-insert-archive-gcc ()
2790   "Insert the Gcc to say where the article is to be archived."
2791   (let* ((var gnus-message-archive-group)
2792          result
2793          (groups
2794           (cond 
2795            ((stringp var)
2796             ;; Just a single group.
2797             (list var))
2798            ((null var)
2799             ;; We don't want this.
2800             nil)
2801            ((and (listp var) (stringp (car var)))
2802             ;; A list of groups.
2803             var)
2804            ((gnus-functionp var)
2805             ;; A function.
2806             (funcall var gnus-newsgroup-name))
2807            (t
2808             ;; An alist of regexps/functions/forms.
2809             (while (and var
2810                         (not
2811                          (setq result
2812                                (cond 
2813                                 ((stringp (caar var))
2814                                  ;; Regexp.
2815                                  (when (string-match (caar var)
2816                                                      gnus-newsgroup-name)
2817                                    (cdar var)))
2818                                 ((gnus-functionp (car var))
2819                                  ;; Function.
2820                                  (funcall (car var) gnus-newsgroup-name))
2821                                 (t
2822                                  (eval (car var)))))))
2823               (setq var (cdr var)))
2824             result))))
2825     (when groups
2826       (when (stringp groups)
2827         (setq groups (list groups)))
2828       (save-excursion
2829         (save-restriction
2830           (gnus-inews-narrow-to-headers)
2831           (goto-char (point-max))
2832           (insert "Gcc: ")
2833           (while groups
2834             (insert (gnus-group-prefixed-name 
2835                      (pop groups) gnus-message-archive-method))
2836             (insert " "))
2837           (insert "\n"))))))
2838
2839 ;;; Handling rejected (and postponed) news.
2840
2841 (defun gnus-draft-group ()
2842   "Return the name of the draft group."
2843   (gnus-group-prefixed-name 
2844    (file-name-nondirectory gnus-draft-group-directory)
2845    (list 'nndraft gnus-draft-group-directory)))
2846
2847 (defun gnus-make-draft-group ()
2848   "Make the draft group or die trying."
2849   (let* ((method `(nndraft "private" 
2850                            (nndraft-directory 
2851                             ,gnus-draft-group-directory)))
2852          (group (gnus-draft-group)))
2853     (or (gnus-gethash group gnus-newsrc-hashtb)
2854         (gnus-group-make-group (gnus-group-real-name group) method)
2855         (error "Can't create the draft group"))
2856     (gnus-check-server method)
2857     group))
2858
2859 (defun gnus-associate-buffer-with-draft (&optional generate silent)
2860   "Enter the current buffer into the draft group."
2861   (interactive)
2862   (when (gnus-request-accept-article (gnus-make-draft-group) t)
2863     (unless silent
2864       ;; This function does the proper marking of articles.
2865       (gnus-mail-send-and-exit 'dont-send))
2866     (set-buffer-modified-p nil)))
2867
2868 (defun gnus-enter-buffer-into-draft ()
2869   (when gnus-use-draft
2870     (save-excursion
2871       ;; Make sure the draft group exists.
2872       (gnus-make-draft-group)
2873       ;; Associate the buffer with the draft group.
2874       (let ((article (gnus-request-associate-buffer (gnus-draft-group))))
2875         ;; Arrange for deletion of the draft after successful sending.
2876         (make-local-variable 'gnus-message-sent-hook)
2877         (setq gnus-message-sent-hook
2878               (list
2879                `(lambda ()
2880                   (let ((gnus-verbose-backends nil))
2881                     (gnus-request-expire-articles 
2882                      (quote ,(list article))
2883                      ,(gnus-draft-group) t)))))))))
2884
2885 (defun gnus-dissociate-buffer-from-draft ()
2886   "Disable auto-saving and association to the draft group of the current buffer."
2887   (interactive)
2888   (run-hooks 'gnus-message-sent-hook)
2889   (setq buffer-file-name nil)
2890   (setq buffer-auto-save-file-name nil))
2891
2892 (defun gnus-summary-send-draft ()
2893   "Enter a mail/post buffer to edit and send the draft."
2894   (interactive)
2895   (gnus-set-global-variables)
2896   (unless (equal gnus-newsgroup-name (gnus-draft-group))
2897     (error "This function can only be used in the draft buffer"))
2898   (let (buf point)
2899     (if (not (setq buf (gnus-request-restore-buffer 
2900                         (gnus-summary-article-number) gnus-newsgroup-name)))
2901         (error "Couldn't restore the article")
2902       (setq point (point))
2903       (switch-to-buffer buf)
2904       (gnus-inews-modify-mail-mode-map)
2905       (when (eq major-mode 'news-reply-mode)
2906         (local-set-key "\C-c\C-c" 'gnus-inews-news))
2907       (gnus-enter-buffer-into-draft) 
2908       ;; Insert the separator.
2909       (goto-char (point-min))
2910       (search-forward "\n\n")
2911       (forward-char -1)
2912       (insert mail-header-separator)
2913       ;; Configure windows.
2914       (let ((gnus-draft-buffer (current-buffer)))
2915         (gnus-configure-windows 'draft t)
2916         (goto-char (point))))))
2917   
2918 (defun gnus-configure-posting-styles ()
2919   "Configure posting styles according to `gnus-posting-styles'."
2920   (let ((styles gnus-posting-styles)
2921         (gnus-newsgroup-name (or gnus-newsgroup-name ""))
2922         style match variable attribute value value-value)
2923     ;; Go through all styles and look for matches.
2924     (while styles
2925       (setq style (pop styles)
2926             match (pop style))
2927       (when (cond ((stringp match)
2928                    ;; Regexp string match on the group name.
2929                    (string-match match gnus-newsgroup-name))
2930                   ((or (symbolp match)
2931                        (gnus-functionp match))
2932                    (cond ((gnus-functionp match)
2933                           ;; Function to be called.
2934                           (funcall match))
2935                          ((boundp match)
2936                           ;; Variable to be checked.
2937                           (symbol-value match))))
2938                   ((listp match)
2939                    ;; This is a form to be evaled.
2940                    (eval match)))
2941         ;; We have a match, so we set the variables.
2942         (while style
2943           (setq attribute (pop style)
2944                 value (cdr attribute))
2945           ;; We find the variable that is to be modified.
2946           (if (and (not (stringp (car attribute)))
2947                    (not (setq variable (cdr (assq (car attribute) 
2948                                                   gnus-posting-style-alist)))))
2949               (message "Couldn't find attribute %s" (car attribute))
2950             ;; We set the variable.
2951             (setq value-value
2952                   (cond ((stringp value)
2953                          value)
2954                         ((or (symbolp value)
2955                              (gnus-functionp value))
2956                          (cond ((gnus-functionp value)
2957                                 (funcall value))
2958                                ((boundp value)
2959                                 (symbol-value value))))
2960                         ((listp value)
2961                          (eval value))))
2962             (if variable
2963                 (progn
2964                   ;; This is an ordinary variable.
2965                   (make-local-variable variable)
2966                   (set variable value-value))
2967               ;; This is a header to be added to the headers when
2968               ;; posting. 
2969               (when value-value
2970                 (make-local-variable gnus-required-headers)
2971                 (make-local-variable gnus-required-mail-headers)
2972                 (push (cons (car attribute) value-value) 
2973                       gnus-required-headers)
2974                 (push (cons (car attribute) value-value) 
2975                       gnus-required-mail-headers)))))))))
2976
2977 (defun gnus-inews-set-point ()
2978   "Move point to where the user probably wants to find it."
2979   (gnus-inews-narrow-to-headers)
2980   (cond 
2981    ((re-search-forward "^[^:]+:[ \t]*$" nil t)
2982     (search-backward ":" )
2983     (widen)
2984     (forward-char 2))
2985    (t
2986     (goto-char (point-max))
2987     (widen)
2988     (forward-line 1)
2989     (unless (looking-at "$")
2990       (forward-line 2)))))
2991   
2992 ;;; Allow redefinition of functions.
2993
2994 (gnus-ems-redefine)
2995
2996 (provide 'gnus-msg)
2997
2998 ;;; gnus-msg.el ends here