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