*** 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
32 (defvar gnus-organization-file "/usr/lib/news/organization"
33   "*Local news organization file.")
34
35 (defvar gnus-prepare-article-hook (list 'gnus-inews-insert-signature)
36   "*A hook called after preparing body, but before preparing header headers.
37 The default hook (`gnus-inews-insert-signature') inserts a signature
38 file specified by the variable `gnus-signature-file'.")
39
40 (defvar gnus-post-prepare-function nil
41   "*Function that is run after a post buffer has been prepared.
42 It is called with the name of the newsgroup that is posted to. It
43 might be used, for instance, for inserting signatures based on the
44 newsgroup name. (In that case, `gnus-signature-file' and
45 `mail-signature' should both be set to nil).")
46
47 (defvar gnus-post-prepare-hook nil
48   "*Hook that is run after a post buffer has been prepared.
49 If you want to insert the signature, you might put
50 `gnus-inews-insert-signature' in this hook.")
51
52 (defvar gnus-use-followup-to t
53   "*Specifies what to do with Followup-To header.
54 If nil, ignore the header. If it is t, use its value, but ignore 
55 `poster'.  If it is the symbol `ask', query the user before posting.
56 If it is the symbol `use', always use the value.") 
57
58 (defvar gnus-followup-to-function nil
59   "*A variable that contains a function that returns a followup address.
60 The function will be called in the buffer of the article that is being
61 followed up. The buffer will be narrowed to the headers of the
62 article. To pick header headers, one might use `mail-fetch-field'.  The
63 function will be called with the name of the current newsgroup as the
64 argument.
65
66 Here's an example `gnus-followup-to-function':
67
68 (setq gnus-followup-to-function
69       (lambda (group)
70         (cond ((string= group \"mail.list\")
71                (or (mail-fetch-field \"sender\") 
72                    (mail-fetch-field \"from\")))
73               (t
74                (or (mail-fetch-field \"reply-to\") 
75                    (mail-fetch-field \"from\"))))))")
76
77 (defvar gnus-reply-to-function nil
78   "*A variable that contains a function that returns a reply address.
79 See the `gnus-followup-to-function' variable for an explanation of how
80 this variable is used.
81
82 This function should return a string that will be used to fill in the
83 header.  This function may also return a list.  In that case, every
84 list element should be a cons where the first car should be a string
85 with the header name, and the cdr should be a string with the header
86 value.")
87
88 (defvar gnus-author-copy (getenv "AUTHORCOPY")
89   "*Save outgoing articles in this file.
90 Initialized from the AUTHORCOPY environment variable.
91
92 If this variable begins with the character \"|\", outgoing articles
93 will be piped to the named program. It is possible to save an article
94 in an MH folder as follows:
95
96 \(setq gnus-author-copy \"|/usr/local/lib/mh/rcvstore +Article\")
97
98 If the first character is not a pipe, articles are saved using the
99 function specified by the `gnus-author-copy-saver' variable.")
100
101 (defvar gnus-mail-self-blind nil
102   "*Non-nil means insert a BCC header in all outgoing articles.
103 This will result in having a copy of the article mailed to yourself.
104 The BCC header is inserted when the post buffer is initialized, so you
105 can remove or alter the BCC header to override the default.")
106
107 (defvar gnus-author-copy-saver (function rmail-output)
108   "*A function called to save outgoing articles.
109 This function will be called with the same of the file to store the
110 article in. The default function is `rmail-output' which saves in Unix
111 mailbox format.")
112
113 (defvar gnus-user-login-name nil
114   "*The login name of the user.
115 Got from the function `user-login-name' if undefined.")
116
117 (defvar gnus-user-full-name nil
118   "*The full name of the user.
119 Got from the NAME environment variable if undefined.")
120
121 (defvar gnus-user-from-line nil
122   "*Your full, complete e-mail address.  
123 Overrides the other Gnus variables if it is non-nil.
124
125 Here are two example values of this variable:
126
127  \"Lars Magne Ingebrigtsen <larsi@ifi.uio.no>\"
128
129 and
130
131  \"larsi@ifi.uio.no (Lars Magne Ingebrigtsen)\"
132
133 The first version is recommended, but the name has to be quoted if it
134 contains non-alphanumerical characters.")
135
136 (defvar gnus-signature-file "~/.signature"
137   "*Your signature file.
138 If the variable is a string that doesn't correspond to a file, the
139 string itself is inserted.")
140
141 (defvar gnus-signature-function nil
142   "*A function that should return a signature file name.
143 The function will be called with the name of the newsgroup being
144 posted to.
145 If the function returns a string that doesn't correspond to a file, the
146 string itself is inserted.
147 If the function returns nil, the `gnus-signature-file' variable will
148 be used instead.")
149
150 (defvar gnus-required-headers
151   '(From Date Newsgroups Subject Message-ID Organization Lines X-Newsreader)
152   "*Headers to be generated or prompted for when posting an article.
153 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
154 Message-ID.  Organization, Lines and X-Newsreader are optional.  If
155 you want Gnus not to insert some header, remove it from this list.")
156
157 (defvar gnus-deletable-headers '(Message-ID Date)
158   "*Headers to be deleted if they already exists and were generated by Gnus previously.")
159
160 (defvar gnus-removable-headers '(NNTP-Posting-Host Bcc Xref)
161   "*Headers to be removed unconditionally before posting.")
162
163 (defvar gnus-check-before-posting 
164   '(subject-cmsg multiple-headers sendsys message-id from
165                  long-lines control-chars size new-text
166                  signature)
167   "In non-nil, Gnus will attempt to run some checks on outgoing posts.
168 If this variable is t, Gnus will check everything it can.  If it is a
169 list, then those elements in that list will be checked.")
170
171 (defvar gnus-delete-supersedes-headers
172   "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Supersedes:"
173   "*Header lines matching this regexp will be deleted before posting.
174 It's best to delete old Path and Date headers before posting to avoid
175 any confusion.")
176
177 (defvar gnus-auto-mail-to-author nil
178   "*If non-nil, mail the authors of articles a copy of your follow-ups.
179 If this variable is `ask', the user will be prompted for whether to
180 mail a copy.  The string given by `gnus-mail-courtesy-message' will be
181 inserted at the beginning of the mail copy.
182
183 Mail is sent using the function specified by the
184 `gnus-mail-send-method' variable.")
185
186 ;; Added by Ethan Bradford <ethanb@ptolemy.astro.washington.edu>.
187 (defvar gnus-mail-courtesy-message
188   "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
189   "*This is inserted at the start of a mailed copy of a posted message.
190 If this variable is nil, no such courtesy message will be added.")
191
192 (defvar gnus-mail-reply-method (function gnus-mail-reply-using-mail)
193   "*Function to compose a reply.
194 Three pre-made functions are `gnus-mail-reply-using-mail' (sendmail);
195 `gnus-mail-reply-using-mhe' (MH-E); and `gnus-mail-reply-using-vm'.")
196
197 (defvar gnus-mail-forward-method (function gnus-mail-forward-using-mail)
198   "*Function to forward the current message to another user.
199 Three pre-made functions are `gnus-mail-forward-using-mail' (sendmail);
200 `gnus-mail-forward-using-mhe' (MH-E); and `gnus-mail-forward-using-vm'.") 
201
202 (defvar gnus-mail-other-window-method 'gnus-mail-other-window-using-mail
203   "*Function to compose mail in the other window.
204 Three pre-made functions are `gnus-mail-other-window-using-mail'
205 (sendmail); `gnus-mail-other-window-using-mhe' (MH-E); and
206 `gnus-mail-other-window-using-vm'.")
207
208 (defvar gnus-mail-send-method send-mail-function
209   "*Function to mail a message which is also being posted as an article.
210 The message must have To or Cc header.  The default is copied from
211 the variable `send-mail-function'.")
212
213 (defvar gnus-inews-article-function 'gnus-inews-article
214   "*Function to post an article.")
215
216 (defvar gnus-inews-article-hook (list 'gnus-inews-do-fcc)
217   "*A hook called before finally posting an article.
218 The default hook (`gnus-inews-do-fcc') does FCC processing (ie. saves
219 the article to a file).")
220
221 (defvar gnus-inews-article-header-hook nil
222   "*A hook called after inserting the headers in an article to be posted.
223 The hook is called from the *post-news* buffer, narrowed to the
224 headers.")
225
226 (defvar gnus-mail-hook nil
227   "*A hook called as the last thing after setting up a mail buffer.")
228
229 ;;; Internal variables.
230
231 (defvar gnus-post-news-buffer "*post-news*")
232 (defvar gnus-mail-buffer "*mail*")
233 (defvar gnus-summary-send-map nil)
234 (defvar gnus-article-copy nil)
235 (defvar gnus-reply-subject nil)
236
237 (eval-and-compile
238   (autoload 'gnus-uu-post-news "gnus-uu" nil t)
239   (autoload 'rmail-output "rmailout"))
240
241 \f
242 ;;;
243 ;;; Gnus Posting Functions
244 ;;;
245
246 (define-prefix-command 'gnus-summary-send-map)
247 (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
248 (define-key gnus-summary-send-map "p" 'gnus-summary-post-news)
249 (define-key gnus-summary-send-map "f" 'gnus-summary-followup)
250 (define-key gnus-summary-send-map "F" 'gnus-summary-followup-with-original)
251 (define-key gnus-summary-send-map "b" 'gnus-summary-followup-and-reply)
252 (define-key gnus-summary-send-map "B" 'gnus-summary-followup-and-reply-with-original)
253 (define-key gnus-summary-send-map "c" 'gnus-summary-cancel-article)
254 (define-key gnus-summary-send-map "s" 'gnus-summary-supersede-article)
255 (define-key gnus-summary-send-map "r" 'gnus-summary-reply)
256 (define-key gnus-summary-send-map "R" 'gnus-summary-reply-with-original)
257 (define-key gnus-summary-send-map "m" 'gnus-summary-mail-other-window)
258 (define-key gnus-summary-send-map "u" 'gnus-uu-post-news)
259 (define-key gnus-summary-send-map "om" 'gnus-summary-mail-forward)
260 (define-key gnus-summary-send-map "op" 'gnus-summary-post-forward)
261 (define-key gnus-summary-send-map "Om" 'gnus-uu-digest-mail-forward)
262 (define-key gnus-summary-send-map "Op" 'gnus-uu-digest-post-forward)
263
264 ;;; Internal functions.
265
266 (defun gnus-number-base36 (num len)
267   (if (if (< len 0) (<= num 0) (= len 0))
268       ""
269     (concat (gnus-number-base36 (/ num 36) (1- len))
270             (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
271                                   (% num 36))))))
272
273 ;;; Post news commands of Gnus group mode and summary mode
274
275 (defun gnus-group-mail ()
276   "Start composing a mail."
277   (interactive)
278   (funcall gnus-mail-other-window-method))
279
280 (defun gnus-group-post-news ()
281   "Post an article."
282   (interactive)
283   (let ((gnus-newsgroup-name nil))
284     (gnus-post-news 'post nil nil gnus-article-buffer)))
285
286 (defun gnus-summary-post-news ()
287   "Post an article."
288   (interactive)
289   (gnus-set-global-variables)
290   (gnus-post-news 'post gnus-newsgroup-name))
291
292 (defun gnus-summary-followup (yank &optional yank-articles)
293   "Compose a followup to an article.
294 If prefix argument YANK is non-nil, original article is yanked automatically."
295   (interactive "P")
296   (gnus-set-global-variables)
297   (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
298   (save-window-excursion
299     (gnus-summary-select-article))
300   (let ((headers (gnus-get-header-by-number (gnus-summary-article-number)))
301         (gnus-newsgroup-name gnus-newsgroup-name))
302     ;; Check Followup-To: poster.
303     (set-buffer gnus-article-buffer)
304     (if (and gnus-use-followup-to
305              (string-equal "poster" (gnus-fetch-field "followup-to"))
306              (or (not (memq gnus-use-followup-to '(t ask)))
307                  (not (gnus-y-or-n-p 
308                        "Do you want to ignore `Followup-To: poster'? "))))
309         ;; Mail to the poster. 
310         (gnus-summary-reply yank)
311       (gnus-post-news nil gnus-newsgroup-name
312                       headers gnus-article-buffer 
313                       (or yank-articles (not (not yank)))))))
314
315 (defun gnus-summary-followup-with-original (n)
316   "Compose a followup to an article and include the original article."
317   (interactive "P")
318   (gnus-summary-followup t (gnus-summary-work-articles n)))
319
320 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
321 (defun gnus-summary-followup-and-reply (yank &optional yank-articles)
322   "Compose a followup and do an auto mail to author."
323   (interactive "P")
324   (gnus-set-global-variables)
325   (let ((gnus-auto-mail-to-author t))
326     (gnus-summary-followup yank yank-articles)))
327
328 (defun gnus-summary-followup-and-reply-with-original (n)
329   "Compose a followup, include the original, and do an auto mail to author."
330   (interactive "P")
331   (gnus-summary-followup-and-reply t (gnus-summary-work-articles n)))
332
333 (defun gnus-summary-cancel-article (n)
334   "Cancel an article you posted."
335   (interactive "P")
336   (gnus-set-global-variables)
337   (let ((articles (gnus-summary-work-articles n)))
338     (while articles
339       (gnus-summary-select-article t nil nil (car articles))
340       (and (gnus-eval-in-buffer-window gnus-article-buffer (gnus-cancel-news))
341            (gnus-summary-mark-as-read (car articles) gnus-canceled-mark))
342       (gnus-summary-remove-process-mark (car articles))
343       (gnus-article-hide-headers-if-wanted)
344       (setq articles (cdr articles)))))
345
346 (defun gnus-summary-supersede-article ()
347   "Compose an article that will supersede a previous article.
348 This is done simply by taking the old article and adding a Supersedes
349 header line with the old Message-ID."
350   (interactive)
351   (gnus-set-global-variables)
352   (gnus-summary-select-article t)
353   (if (not
354        (string-equal
355         (downcase (mail-strip-quoted-names 
356                    (mail-header-from gnus-current-headers)))
357         (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
358       (error "This article is not yours."))
359   (save-excursion
360     (set-buffer gnus-article-buffer)
361     (let ((buffer-read-only nil))
362       (goto-char (point-min))
363       (search-forward "\n\n" nil t)
364       (if (not (re-search-backward "^Message-ID: " nil t))
365           (error "No Message-ID in this article"))))
366   (if (gnus-post-news 'post gnus-newsgroup-name)
367       (progn
368         (erase-buffer)
369         (insert-buffer gnus-article-buffer)
370         (if (search-forward "\n\n" nil t)
371             (forward-char -1)
372           (goto-char (point-max)))
373         (narrow-to-region (point-min) (point))
374         (goto-char (point-min))
375         (and gnus-delete-supersedes-headers
376              (delete-matching-lines gnus-delete-supersedes-headers))
377         (goto-char (point-min))
378         (if (not (re-search-forward "^Message-ID: " nil t))
379             (error "No Message-ID in this article")
380           (replace-match "Supersedes: " t t))
381         (goto-char (point-max))
382         (insert mail-header-separator)
383         (widen)
384         (forward-line 1))))
385
386 \f
387 ;;;###autoload
388 (defalias 'sendnews 'gnus-post-news)
389
390 ;;;###autoload
391 (defalias 'postnews 'gnus-post-news)
392
393 (defun gnus-copy-article-buffer (&optional article-buffer)
394   ;; make a copy of the article buffer with all text properties removed
395   ;; this copy is in the buffer gnus-article-copy.
396   ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
397   ;; this buffer should be passed to all mail/news reply/post routines.
398   (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
399   (buffer-disable-undo gnus-article-copy)
400   (or (memq gnus-article-copy gnus-buffer-list)
401       (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
402   (let ((article-buffer (or article-buffer gnus-article-buffer)))
403     (if (and (get-buffer article-buffer)
404              (buffer-name (get-buffer article-buffer)))
405         (save-excursion
406           (set-buffer article-buffer)
407           (widen)
408           (copy-to-buffer gnus-article-copy (point-min) (point-max))
409           (set-text-properties (point-min) (point-max) 
410                                nil gnus-article-copy)))))
411
412 (defun gnus-post-news (post &optional group header article-buffer yank subject)
413   "Begin editing a new USENET news article to be posted.
414 Type \\[describe-mode] in the buffer to get a list of commands."
415   (interactive (list t))
416   (gnus-copy-article-buffer article-buffer)
417   (if (or (not gnus-novice-user)
418           gnus-expert-user
419           (not (eq 'post 
420                    (nth 1 (assoc 
421                            (format "%s" (car (gnus-find-method-for-group 
422                                               gnus-newsgroup-name)))
423                            gnus-valid-select-methods))))
424           (and group
425                (assq 'to-address 
426                      (nth 5 (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))))
427           (gnus-y-or-n-p "Are you sure you want to post to all of USENET? "))
428       (let ((sumart (if (not post)
429                         (save-excursion
430                           (set-buffer gnus-summary-buffer)
431                           (cons (current-buffer) gnus-current-article))))
432             (from (and header (mail-header-from header)))
433             (winconf (current-window-configuration))
434             real-group)
435         (and gnus-interactive-post
436              (not gnus-expert-user)
437              post (not group)
438              (progn
439                (setq gnus-newsgroup-name
440                      (setq group 
441                            (completing-read "Group: " gnus-active-hashtb)))
442                (or subject
443                    (setq subject (read-string "Subject: ")))))
444         (setq mail-reply-buffer gnus-article-copy)
445
446         (let ((newsgroup-name (or group gnus-newsgroup-name "")))
447           (setq real-group (and group (gnus-group-real-name group)))
448           (setq gnus-post-news-buffer 
449                 (gnus-request-post-buffer 
450                  post real-group subject header gnus-article-copy
451                  (nth 2 (and group (gnus-gethash group gnus-newsrc-hashtb)))
452                  (or (cdr (assq 'to-group
453                                 (nth 5 (nth 2 (gnus-gethash 
454                                                newsgroup-name
455                                                gnus-newsrc-hashtb)))))
456                      (if (and (boundp 'gnus-followup-to-function)
457                               gnus-followup-to-function
458                               gnus-article-copy)
459                          (save-excursion
460                            (set-buffer gnus-article-copy)
461                            (funcall gnus-followup-to-function group))))
462                  gnus-use-followup-to))
463           (if post
464               (gnus-configure-windows 'post 'force)
465             (if yank
466                 (gnus-configure-windows 'followup-yank 'force)
467               (gnus-configure-windows 'followup 'force)))
468           (gnus-overload-functions)
469           (make-local-variable 'gnus-article-reply)
470           (make-local-variable 'gnus-article-check-size)
471           (make-local-variable 'gnus-reply-subject)
472           (setq gnus-reply-subject (and header (mail-header-subject header)))
473           (setq gnus-article-reply sumart)
474           ;; Handle `gnus-auto-mail-to-author'.
475           ;; Suggested by Daniel Quinlan <quinlan@best.com>.
476           ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
477           (let ((to (and (not post)
478                          (if (if (eq gnus-auto-mail-to-author 'ask)
479                                  (y-or-n-p "Also send mail to author? ")
480                                gnus-auto-mail-to-author)
481                              (or (save-excursion
482                                    (set-buffer gnus-article-copy)
483                                    (gnus-fetch-field "reply-to"))
484                                  from)))))
485             (if to
486                 (if (mail-fetch-field "To")
487                     (progn
488                       (beginning-of-line)
489                       (insert "Cc: " to "\n"))
490                   (mail-position-on-field "To")
491                   (insert to))))
492           ;; Handle author copy using BCC field.
493           (if (and gnus-mail-self-blind
494                    (not (mail-fetch-field "bcc")))
495               (progn
496                 (mail-position-on-field "Bcc")
497                 (insert (if (stringp gnus-mail-self-blind)
498                             gnus-mail-self-blind
499                           (user-login-name)))))
500           ;; Handle author copy using FCC field.
501           (if gnus-author-copy
502               (progn
503                 (mail-position-on-field "Fcc")
504                 (insert gnus-author-copy)))
505           (goto-char (point-min))
506           (if post 
507               (cond ((not group)
508                      (re-search-forward "^Newsgroup:" nil t)
509                      (end-of-line))
510                     ((not subject)
511                      (re-search-forward "^Subject:" nil t)
512                      (end-of-line))
513                     (t
514                      (re-search-forward 
515                       (concat "^" (regexp-quote mail-header-separator) "$"))
516                      (forward-line 1)))
517             (re-search-forward 
518              (concat "^" (regexp-quote mail-header-separator) "$"))
519             (forward-line 1)
520             (if (not yank)
521                 ()
522               (save-excursion 
523                 (if (not (listp yank))
524                     (news-reply-yank-original nil)
525                   (setq yank (reverse yank))
526                   (while yank
527                     (save-excursion
528                       (save-window-excursion
529                         (set-buffer gnus-summary-buffer)
530                         (gnus-summary-select-article nil nil nil (car yank))
531                         (gnus-summary-remove-process-mark (car yank)))
532                       (let ((mail-reply-buffer gnus-article-copy))
533                         (gnus-copy-article-buffer)
534                         (let ((news-reply-yank-message-id
535                                (save-excursion
536                                  (set-buffer gnus-article-copy)
537                                  (mail-fetch-field "message-id")))
538                               (news-reply-yank-from
539                                (save-excursion
540                                  (set-buffer gnus-article-copy)
541                                  (mail-fetch-field "from"))))
542                           (news-reply-yank-original nil))
543                         (setq yank (cdr yank)))))))))
544           (if gnus-post-prepare-function
545               (funcall gnus-post-prepare-function group))
546           (run-hooks 'gnus-post-prepare-hook)
547           (make-local-variable 'gnus-prev-winconf)
548           (setq gnus-prev-winconf winconf))))
549   (setq gnus-article-check-size (cons (buffer-size) (gnus-article-checksum)))
550   (message "")
551   t)
552
553 (defun gnus-inews-news (&optional use-group-method)
554   "Send a news message.
555 If given a prefix, and the group is a foreign group, this function
556 will attempt to use the foreign server to post the article."
557   (interactive "P")
558   (or gnus-current-select-method
559       (setq gnus-current-select-method gnus-select-method))
560   (let* ((case-fold-search nil)
561          (server-running (gnus-server-opened gnus-current-select-method))
562          (reply gnus-article-reply)
563          error post-result)
564     (save-excursion
565       ;; Connect to default NNTP server if necessary.
566       ;; Suggested by yuki@flab.fujitsu.junet.
567       (gnus-start-news-server)          ;Use default server.
568       ;; NNTP server must be opened before current buffer is modified.
569       (widen)
570       (goto-char (point-min))
571       (run-hooks 'news-inews-hook)
572       (save-restriction
573         (narrow-to-region
574          (point-min)
575          (progn
576            (goto-char (point-min))
577            (re-search-forward 
578             (concat "^" (regexp-quote mail-header-separator) "$"))
579            (match-beginning 0)))
580
581         ;; Correct newsgroups field: change sequence of spaces to comma and 
582         ;; eliminate spaces around commas.  Eliminate imbedded line breaks.
583         (goto-char (point-min))
584         (if (re-search-forward "^Newsgroups: +" nil t)
585             (save-restriction
586               (narrow-to-region
587                (point)
588                (if (re-search-forward "^[^ \t]" nil t)
589                    (match-beginning 0)
590                  (forward-line 1)
591                  (point)))
592               (goto-char (point-min))
593               (while (re-search-forward "\n[ \t]+" nil t)
594                 (replace-match " " t t)) ;No line breaks (too confusing)
595               (goto-char (point-min))
596               (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
597                 (replace-match "," t t))
598               (goto-char (point-min))
599               ;; Remove a trailing comma.
600               (if (re-search-forward ",$" nil t)
601                   (replace-match "" t t))))
602
603         ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
604         ;; Help save the the world!
605         (or 
606          gnus-expert-user
607          (let ((newsgroups (mail-fetch-field "newsgroups"))
608                (followup-to (mail-fetch-field "followup-to"))
609                groups to)
610            (if (and newsgroups
611                     (string-match "," newsgroups) (not followup-to))
612                (progn
613                  (while (string-match "," newsgroups)
614                    (setq groups
615                          (cons (list (substring newsgroups
616                                                 0 (match-beginning 0)))
617                                groups))
618                    (setq newsgroups (substring newsgroups (match-end 0))))
619                  (setq groups (nreverse (cons (list newsgroups) groups)))
620
621                  (setq to
622                        (completing-read "Followups to: (default all groups) "
623                                         groups))
624                  (if (> (length to) 0)
625                      (progn
626                        (goto-char (point-min))
627                        (insert "Followup-To: " to "\n")))))))
628
629         ;; Cleanup Followup-To.
630         (goto-char (point-min))
631         (if (search-forward-regexp "^Followup-To: +" nil t)
632             (save-restriction
633               (narrow-to-region
634                (point)
635                (if (re-search-forward "^[^ \t]" nil 'end)
636                    (match-beginning 0)
637                  (point-max)))
638               (goto-char (point-min))
639               (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
640               (goto-char (point-min))
641               (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ",")))
642
643         ;; Mail the message too if To:, Bcc:. or Cc: exists.
644         (let* ((types '("to" "bcc" "cc"))
645                (ty types)
646                fcc-line)
647           (while ty
648             (or (mail-fetch-field (car ty) nil t)
649                 (setq types (delete (car ty) types)))
650             (setq ty (cdr ty)))
651
652           (if (not types)
653               ;; We do not want to send mail.
654               ()
655             (if (not gnus-mail-send-method)
656                 (progn
657                   (ding)
658                   (gnus-message 
659                    1 "No mailer defined.  To: and/or Cc: fields ignored.")
660                   (sit-for 1))
661               (save-excursion
662                 ;; We want to remove Fcc, because we want to handle
663                 ;; that one ourselves...  
664                   
665                 (goto-char (point-min))
666                 (if (re-search-forward "^Fcc: " nil t)
667                     (progn
668                       (setq fcc-line
669                             (buffer-substring
670                              (progn (beginning-of-line) (point))
671                              (progn (forward-line 1) (point))))
672                       (forward-line -1)
673                       (gnus-delete-line)))
674
675                 ;; We generate a Message-ID so that the mail and the
676                 ;; news copy of the message both get the same ID.
677                 (or (mail-fetch-field "message-id")
678                     (not (memq 'Message-ID gnus-required-headers))
679                     (progn
680                       (goto-char (point-max))
681                       (insert "Message-ID: " (gnus-inews-message-id) "\n")))
682
683                 (save-restriction
684                   (widen)
685                   (gnus-message 5 "Sending via mail...")
686
687                   (if (and gnus-mail-courtesy-message
688                            (or (member "to" types)
689                                (member "cc" types)))
690                       ;; We only want to insert the courtesy mail
691                       ;; message if we use to or cc; bcc should not
692                       ;; have one. Well, if both bcc and to are
693                       ;; present, it will get one anyway.
694                       (progn
695                         ;; Insert "courtesy" mail message.
696                         (goto-char (point-min))
697                         (re-search-forward
698                          (concat "^" (regexp-quote
699                                       mail-header-separator) "$"))
700                         (forward-line 1)
701                         (insert gnus-mail-courtesy-message)
702                         (funcall gnus-mail-send-method)
703                         (goto-char (point-min))
704                         (search-forward gnus-mail-courtesy-message)
705                         (replace-match "" t t))
706                     (funcall gnus-mail-send-method))
707
708                   (gnus-message 5 "Sending via mail...done")
709                       
710                   (goto-char (point-min))
711                   (narrow-to-region
712                    (point) 
713                    (re-search-forward 
714                     (concat "^" (regexp-quote mail-header-separator) "$")))
715                   (goto-char (point-min))
716                   (while (re-search-forward "^BCC:" nil t)
717                     (delete-region (match-beginning 0)
718                                    ;; There might be continuation headers. 
719                                    (if (re-search-forward "^[^ \t]" nil t)
720                                        (match-beginning 0)
721                                      ;; Uhm... or something like this.
722                                      (forward-line 1)
723                                      (point)))))
724                 (if fcc-line
725                     (progn
726                       (goto-char (point-max))
727                       (insert fcc-line))))))))
728
729       ;; Send to server. 
730       (gnus-message 5 "Posting to USENET...")
731       (setq post-result (funcall gnus-inews-article-function use-group-method))
732       (cond ((eq post-result 'illegal)
733              (setq error t)
734              (ding))
735             (post-result
736              (gnus-message 5 "Posting to USENET...done")
737              (if (gnus-buffer-exists-p (car-safe reply))
738                  (progn
739                    (save-excursion
740                      (set-buffer gnus-summary-buffer)
741                      (gnus-summary-mark-article-as-replied 
742                       (cdr reply)))))
743              (set-buffer-modified-p nil))
744             (t
745              ;; We cannot signal an error.
746              (setq error t)
747              (ding)
748              (gnus-message 1 "Article rejected: %s" 
749                            (gnus-status-message gnus-select-method)))))
750     ;; If NNTP server is opened by gnus-inews-news, close it by myself.
751     (or server-running
752         (gnus-close-server (gnus-find-method-for-group gnus-newsgroup-name)))
753     (let ((conf gnus-prev-winconf))
754       (if (not error)
755           (progn
756             (bury-buffer)
757             ;; Restore last window configuration.
758             (and conf (set-window-configuration conf)))))))
759
760 (defun gnus-inews-check-post ()
761   "Check whether the post looks ok."
762   (or
763    (not gnus-check-before-posting)
764    (and 
765     ;; We narrow to the headers and check them first.
766     (save-excursion
767       (save-restriction
768         (goto-char (point-min))
769         (narrow-to-region 
770          (point) 
771          (progn
772            (re-search-forward 
773             (concat "^" (regexp-quote mail-header-separator) "$"))
774            (match-beginning 0)))
775         (goto-char (point-min))
776         (and 
777          ;; Check for commands in Subject.
778          (or 
779           (gnus-check-before-posting 'subject-cmsg)
780           (save-excursion
781             (if (string-match "^cmsg " (mail-fetch-field "subject"))
782                 (gnus-y-or-n-p
783                  "The control code \"cmsg \" is in the subject. Really post? ")
784               t)))
785          ;; Check for multiple identical headers.
786          (or (gnus-check-before-posting 'multiple-headers)
787              (save-excursion
788                (let (found)
789                  (while (and (not found) (re-search-forward "^[^ \t:]+: "
790                                                             nil t))
791                    (save-excursion
792                      (or (re-search-forward 
793                           (concat "^" (setq found
794                                             (buffer-substring 
795                                              (match-beginning 0) 
796                                              (- (match-end 0) 2))))
797                           nil t)
798                          (setq found nil))))
799                  (if found
800                      (gnus-y-or-n-p 
801                       (format "Multiple %s headers. Really post? " found))
802                    t))))
803          ;; Check for version and sendsys.
804          (or (gnus-check-before-posting 'sendsys)
805              (save-excursion
806                (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
807                    (gnus-y-or-n-p
808                     (format "The article contains a %s command. Really post? "
809                             (buffer-substring (match-beginning 0) 
810                                               (1- (match-end 0)))))
811                  t)))
812          ;; Check the Message-Id header.
813          (or (gnus-check-before-posting 'message-id)
814              (save-excursion
815                (let* ((case-fold-search t)
816                       (message-id (mail-fetch-field "message-id")))
817                  (or (not message-id)
818                      (and (string-match "@" message-id)
819                           (string-match "@[^\\.]*\\." message-id))
820                      (gnus-y-or-n-p
821                       (format 
822                        "The Message-ID looks strange: \"%s\". Really post? "
823                        message-id))))))
824          ;; Check the From header.
825          (or (gnus-check-before-posting 'from)
826              (save-excursion
827                (let* ((case-fold-search t)
828                       (from (mail-fetch-field "from")))
829                  (cond
830                   ((not from)
831                    (gnus-y-or-n-p "There is no From line. Really post? "))
832                   ((not (string-match "@[^\\.]*\\." from))
833                    (gnus-y-or-n-p
834                     (format 
835                      "The address looks strange: \"%s\". Really post? " from)))
836                   ((string-match "(.*).*(.*)" from)
837                    (gnus-y-or-n-p
838                     (format
839                      "The From header looks strange: \"%s\". Really post? " 
840                      from)))
841                   (t t)))))
842          )))
843     ;; Check for long lines.
844     (or (gnus-check-before-posting 'long-lines)
845         (save-excursion
846           (goto-char (point-min))
847           (re-search-forward
848            (concat "^" (regexp-quote mail-header-separator) "$"))
849           (while (and
850                   (progn
851                     (end-of-line)
852                     (< (current-column) 80))
853                   (zerop (forward-line 1))))
854           (or (bolp)
855               (eobp)
856               (gnus-y-or-n-p
857                (format
858                 "You have lines longer than 79 characters.  Really post? ")))))
859     ;; Check for control characters.
860     (or (gnus-check-before-posting 'control-chars)
861         (save-excursion
862           (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
863               (gnus-y-or-n-p 
864                "The article contains control characters. Really post? ")
865             t)))
866     ;; Check excessive size.
867     (or (gnus-check-before-posting 'size)
868         (if (> (buffer-size) 60000)
869             (gnus-y-or-n-p
870              (format "The article is %d octets long. Really post? "
871                      (buffer-size)))
872           t))
873     ;; Use the (size . checksum) variable to see whether the
874     ;; article is empty or has only quoted text.
875     (or
876      (gnus-check-before-posting 'new-text)
877      (if (and (= (buffer-size) (car gnus-article-check-size))
878               (= (gnus-article-checksum) (cdr gnus-article-check-size)))
879          (gnus-y-or-n-p
880           "It looks like there's no new text in your article. Really post? ")
881        t))
882     ;; Check the length of the signature.
883     (or (gnus-check-before-posting 'signature)
884         (progn
885           (goto-char (point-max))
886           (if (not (re-search-backward gnus-signature-separator nil t))
887               t
888             (if (> (count-lines (point) (point-max)) 4)
889                 (gnus-y-or-n-p
890                  (format
891                   "Your .sig is %d lines; it should be max 4.  Really post? "
892                   (count-lines (point) (point-max))))
893               t)))))))
894
895 (defun gnus-article-checksum ()
896   (let ((sum 0))
897     (save-excursion
898       (while (not (eobp))
899         (setq sum (logxor sum (following-char)))
900         (forward-char 1)))
901     sum))
902
903 ;; Returns non-nil if this type is not to be checked.
904 (defun gnus-check-before-posting (type)
905   (not 
906    (or (not gnus-check-before-posting)
907        (if (listp gnus-check-before-posting)
908            (memq type gnus-check-before-posting)
909          t))))
910
911 (defun gnus-cancel-news ()
912   "Cancel an article you posted."
913   (interactive)
914   (if (or gnus-expert-user
915           (gnus-yes-or-no-p "Do you really want to cancel this article? "))
916       (let ((from nil)
917             (newsgroups nil)
918             (message-id nil)
919             (distribution nil))
920         (or (gnus-member-of-valid 'post gnus-newsgroup-name)
921             (error "This backend does not support canceling"))
922         (save-excursion
923           ;; Get header info. from original article.
924           (save-restriction
925             (gnus-article-show-all-headers)
926             (goto-char (point-min))
927             (search-forward "\n\n" nil 'move)
928             (narrow-to-region (point-min) (point))
929             (setq from (mail-fetch-field "from"))
930             (setq newsgroups (mail-fetch-field "newsgroups"))
931             (setq message-id (mail-fetch-field "message-id"))
932             (setq distribution (mail-fetch-field "distribution")))
933           ;; Verify if the article is absolutely user's by comparing
934           ;; user id with value of its From: field.
935           (if (not
936                (string-equal
937                 (downcase (mail-strip-quoted-names from))
938                 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
939               (progn
940                 (ding) (gnus-message 3 "This article is not yours.")
941                 nil)
942             ;; Make control article.
943             (set-buffer (get-buffer-create " *Gnus-canceling*"))
944             (buffer-disable-undo (current-buffer))
945             (erase-buffer)
946             (insert "Newsgroups: " newsgroups "\n"
947                     "Subject: cancel " message-id "\n"
948                     "Control: cancel " message-id "\n"
949                     (if distribution
950                         (concat "Distribution: " distribution "\n")
951                       "")
952                     mail-header-separator "\n"
953                     "This is a cancel message from " from ".\n")
954             ;; Send the control article to NNTP server.
955             (gnus-message 5 "Canceling your article...")
956             (prog1
957                 (if (funcall gnus-inews-article-function)
958                     (gnus-message 5 "Canceling your article...done")
959                   (progn
960                     (ding) 
961                     (gnus-message 1 "Cancel failed; %s" 
962                                   (gnus-status-message gnus-newsgroup-name))
963                     nil)
964                   t)
965               ;; Kill the article buffer.
966               (kill-buffer (current-buffer))))))))
967
968 \f
969 ;;; Lowlevel inews interface
970
971 (defun gnus-inews-article (&optional use-group-method)
972   "Post an article in current buffer using NNTP protocol."
973   (let ((artbuf (current-buffer))
974         (tmpbuf (get-buffer-create " *Gnus-posting*")))
975     (widen)
976     (goto-char (point-max))
977     ;; require a newline at the end for inews to append .signature to
978     (or (= (preceding-char) ?\n)
979         (insert ?\n))
980     ;; Prepare article headers.  All message body such as signature
981     ;; must be inserted before Lines: field is prepared.
982     (save-restriction
983       (goto-char (point-min))
984       (narrow-to-region 
985        (point-min) 
986        (save-excursion
987          (re-search-forward 
988           (concat "^" (regexp-quote mail-header-separator) "$"))
989          (match-beginning 0)))
990       (gnus-inews-remove-headers)
991       (gnus-inews-insert-headers)
992       (run-hooks 'gnus-inews-article-header-hook)
993       (widen))
994     ;; Check whether the article is a good Net Citizen.
995     (if (and gnus-article-check-size
996              (not (gnus-inews-check-post)))
997         ;; Aber nein!
998         'illegal
999       ;; Looks ok, so we do the nasty.
1000       (save-excursion
1001         (set-buffer tmpbuf)
1002         (buffer-disable-undo (current-buffer))
1003         (erase-buffer)
1004         (insert-buffer-substring artbuf)
1005         ;; Remove the header separator.
1006         (goto-char (point-min))
1007         (re-search-forward
1008          (concat "^" (regexp-quote mail-header-separator) "$"))
1009         (replace-match "" t t)
1010         ;; This hook may insert a signature.
1011         (save-excursion
1012           (goto-char (point-min))
1013           (let ((gnus-newsgroup-name (or (mail-fetch-field "newsgroups")
1014                                          gnus-newsgroup-name)))
1015             (run-hooks 'gnus-prepare-article-hook)))
1016         ;; Run final inews hooks.  This hook may do FCC.
1017         ;; The article must be saved before being posted because
1018         ;; `gnus-request-post' modifies the buffer.
1019         (run-hooks 'gnus-inews-article-hook)
1020         ;; Post an article to NNTP server.
1021         ;; Return NIL if post failed.
1022         (prog1
1023             (gnus-request-post 
1024              (if use-group-method
1025                  (gnus-find-method-for-group gnus-newsgroup-name)
1026                gnus-select-method) use-group-method)
1027           (kill-buffer (current-buffer)))))))
1028
1029 (defun gnus-inews-remove-headers ()
1030   (let ((case-fold-search t)
1031         (headers gnus-removable-headers))
1032     ;; Remove toxic headers.
1033     (while headers
1034       (goto-char (point-min))
1035       (and (re-search-forward 
1036             (concat "^" (downcase (format "%s" (car headers))))
1037             nil t)
1038            (delete-region (progn (beginning-of-line) (point))
1039                           (progn (forward-line 1) (point))))
1040       (setq headers (cdr headers)))))
1041   
1042 (defun gnus-inews-insert-headers ()
1043   "Prepare article headers.
1044 Headers already prepared in the buffer are not modified.
1045 Headers in `gnus-required-headers' will be generated."
1046   (let ((Date (gnus-inews-date))
1047         (Message-ID (gnus-inews-message-id))
1048         (Organization (gnus-inews-organization))
1049         (From (gnus-inews-user-name))
1050         (Path (gnus-inews-path))
1051         (Subject nil)
1052         (Newsgroups nil)
1053         (Distribution nil)
1054         (Lines (gnus-inews-lines))
1055         (X-Newsreader gnus-version)
1056         (headers gnus-required-headers)
1057         (case-fold-search t)
1058         header value elem)
1059     ;; First we remove any old generated headers.
1060     (let ((headers gnus-deletable-headers))
1061       (while headers
1062         (goto-char (point-min))
1063         (and (re-search-forward 
1064               (concat "^" (symbol-name (car headers)) ": *") nil t)
1065              (get-text-property (1+ (match-beginning 0)) 'gnus-deletable)
1066              (gnus-delete-line))
1067         (setq headers (cdr headers))))
1068     ;; If there are References, and no "Re: ", then the thread has
1069     ;; changed name. See Son-of-1036.
1070     (if (and (mail-fetch-field "references")
1071              (get-buffer gnus-article-buffer))
1072         (let ((psubject (gnus-simplify-subject-re
1073                          (mail-fetch-field "subject"))))
1074           (or (and psubject gnus-reply-subject 
1075                    (string= (gnus-simplify-subject-re gnus-reply-subject)
1076                             psubject))
1077               (progn
1078                 (string-match "@" Message-ID)
1079                 (setq Message-ID
1080                       (concat (substring Message-ID 0 (match-beginning 0))
1081                               "_-_" 
1082                               (substring Message-ID (match-beginning 0))))))))
1083     ;; Go through all the required headers and see if they are in the
1084     ;; articles already. If they are not, or are empty, they are
1085     ;; inserted automatically - except for Subject, Newsgroups and
1086     ;; Distribution. 
1087     (while headers
1088       (goto-char (point-min))
1089       (setq elem (car headers))
1090       (if (consp elem)
1091           (setq header (car elem))
1092         (setq header elem))
1093       (if (or (not (re-search-forward 
1094                     (concat "^" (downcase (symbol-name header)) ":") nil t))
1095               (progn
1096                 ;; The header was found. We insert a space after the
1097                 ;; colon, if there is none.
1098                 (if (/= (following-char) ? ) (insert " "))
1099                 ;; Find out whether the header is empty...
1100                 (looking-at "[ \t]*$")))
1101           ;; So we find out what value we should insert.
1102           (progn
1103             (setq value 
1104                   (or (if (consp elem)
1105                           ;; The element is a cons.  Either the cdr is
1106                           ;; a string to be inserted verbatim, or it
1107                           ;; is a function, and we insert the value
1108                           ;; returned from this function.
1109                           (or (and (stringp (cdr elem)) (cdr elem))
1110                               (and (fboundp (cdr elem)) (funcall (cdr elem))))
1111                         ;; The element is a symbol.  We insert the
1112                         ;; value of this symbol, if any.
1113                         (and (boundp header) (symbol-value header)))
1114                       ;; We couldn't generate a value for this header,
1115                       ;; so we just ask the user.
1116                       (read-from-minibuffer
1117                        (format "Empty header for %s; enter value: " header))))
1118             ;; Finally insert the header.
1119             (save-excursion
1120               (if (bolp)
1121                   (progn
1122                     (goto-char (point-max))
1123                     (insert (symbol-name header) ": " value "\n")
1124                     (forward-line -1))
1125                 (replace-match value t t))
1126               ;; Add the deletable property to the headers that require it.
1127               (and (memq header gnus-deletable-headers)
1128                    (progn (beginning-of-line) (looking-at "[^:]+: "))
1129                    (add-text-properties 
1130                     (point) (match-end 0)
1131                     '(gnus-deletable t face italic) (current-buffer))))))
1132       (setq headers (cdr headers)))
1133     ;; Insert new Sender if the From is strange. 
1134     (let ((from (mail-fetch-field "from"))
1135           (sender (mail-fetch-field "sender")))
1136       (if (and from 
1137                (not (string=
1138                      (downcase (car (gnus-extract-address-components from)))
1139                      (downcase (gnus-inews-real-user-address))))
1140                (or (null sender)
1141                    (not 
1142                     (string=
1143                      (downcase (car (gnus-extract-address-components sender)))
1144                      (downcase (gnus-inews-real-user-address))))))
1145           (progn
1146             (goto-char (point-min))    
1147             (and (re-search-forward "^Sender:" nil t)
1148                  (progn
1149                    (beginning-of-line)
1150                    (insert "Original-")
1151                    (beginning-of-line)))
1152             (insert "Sender: " (gnus-inews-real-user-address) "\n"))))))
1153
1154
1155 (defun gnus-inews-insert-signature ()
1156   "Insert a signature file.
1157 If `gnus-signature-function' is bound and returns a string, this
1158 string is used instead of the variable `gnus-signature-file'.
1159 In either case, if the string is a file name, this file is
1160 inserted. If the string is not a file name, the string itself is
1161 inserted. 
1162
1163 If you never want any signature inserted, set both of these variables to
1164 nil."
1165   (save-excursion
1166     (let ((signature 
1167            (or (and gnus-signature-function
1168                     (funcall gnus-signature-function gnus-newsgroup-name))
1169                gnus-signature-file)))
1170       (if (and signature
1171                (or (file-exists-p signature)
1172                    (string-match " " signature)
1173                    (not (string-match 
1174                          "^/[^/]+/" (expand-file-name signature)))))
1175           (progn
1176             (goto-char (point-max))
1177             (if (and mail-signature (search-backward "\n-- \n" nil t))
1178                 ()
1179               ;; Delete any previous signatures.
1180               (if (search-backward "\n-- \n" nil t)
1181                   (delete-region (point) (point-max)))
1182               (or (eolp) (insert "\n"))
1183               (insert "-- \n")
1184               (if (file-exists-p signature)
1185                   (insert-file-contents signature)
1186                 (insert signature))
1187               (goto-char (point-max))
1188               (or (bolp) (insert "\n"))))))))
1189
1190 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1191 (defun gnus-inews-insert-mime-headers ()
1192   (let ((mail-header-separator ""))
1193     (or (mail-position-on-field "Mime-Version")
1194         (insert "1.0")
1195         (cond ((save-excursion
1196                  (beginning-of-buffer)
1197                  (re-search-forward "[\200-\377]" nil t))
1198                (or (mail-position-on-field "Content-Type")
1199                    (insert "text/plain; charset=ISO-8859-1"))
1200                (or (mail-position-on-field "Content-Transfer-Encoding")
1201                    (insert "8bit")))
1202               (t (or (mail-position-on-field "Content-Type")
1203                      (insert "text/plain; charset=US-ASCII"))
1204                  (or (mail-position-on-field "Content-Transfer-Encoding")
1205                      (insert "7bit")))))))
1206
1207 (defun gnus-inews-do-fcc ()
1208   "Process FCC: fields in current article buffer.
1209 Unless the first character of the field is `|', the article is saved
1210 to the specified file using the function specified by the variable
1211 gnus-author-copy-saver.  The default function rmail-output saves in
1212 Unix mailbox format.
1213 If the first character is `|', the contents of the article is send to
1214 a program specified by the rest of the value."
1215   (let ((fcc-list nil)
1216         (fcc-file nil)
1217         (case-fold-search t))           ;Should ignore case.
1218     (save-excursion
1219       (save-restriction
1220         (goto-char (point-min))
1221         (search-forward "\n\n")
1222         (narrow-to-region (point-min) (point))
1223         (goto-char (point-min))
1224         (while (re-search-forward "^FCC:[ \t]*" nil t)
1225           (setq fcc-list
1226                 (cons (buffer-substring
1227                        (point)
1228                        (progn
1229                          (end-of-line)
1230                          (skip-chars-backward " \t")
1231                          (point)))
1232                       fcc-list))
1233           (delete-region (match-beginning 0)
1234                          (progn (forward-line 1) (point))))
1235         ;; Process FCC operations.
1236         (widen)
1237         (while fcc-list
1238           (setq fcc-file (car fcc-list))
1239           (setq fcc-list (cdr fcc-list))
1240           (cond ((string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" fcc-file)
1241                  (let ((program (substring fcc-file
1242                                            (match-beginning 1) (match-end 1))))
1243                    ;; Suggested by yuki@flab.fujitsu.junet.
1244                    ;; Send article to named program.
1245                    (call-process-region (point-min) (point-max) shell-file-name
1246                                         nil nil nil "-c" program)))
1247                 (t
1248                  ;; Suggested by hyoko@flab.fujitsu.junet.
1249                  ;; Save article in Unix mail format by default.
1250                  (gnus-make-directory (file-name-directory fcc-file))
1251                  (if (and gnus-author-copy-saver
1252                           (not (eq gnus-author-copy-saver 'rmail-output)))
1253                      (funcall gnus-author-copy-saver fcc-file)
1254                    (if (and (file-readable-p fcc-file) (rmail-file-p fcc-file))
1255                        (gnus-output-to-rmail fcc-file)
1256                      (rmail-output fcc-file 1 t t))))))))))
1257
1258 (defun gnus-inews-path ()
1259   "Return uucp path."
1260   (let ((login-name (gnus-inews-login-name)))
1261     (cond ((null gnus-use-generic-path)
1262            (concat (nth 1 gnus-select-method) "!" login-name))
1263           ((stringp gnus-use-generic-path)
1264            ;; Support GENERICPATH.  Suggested by vixie@decwrl.dec.com.
1265            (concat gnus-use-generic-path "!" login-name))
1266           (t login-name))))
1267
1268 (defun gnus-inews-user-name ()
1269   "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1270   (let ((full-name (gnus-inews-full-name))
1271         (address (if (or gnus-user-login-name gnus-use-generic-from
1272                          gnus-local-domain (getenv "DOMAINNAME"))
1273                      (concat (gnus-inews-login-name) "@"
1274                              (gnus-inews-domain-name gnus-use-generic-from))
1275                    user-mail-address))) 
1276     (or gnus-user-from-line
1277         (concat address
1278                 ;; User's full name.
1279                 (cond ((string-equal full-name "&") ;Unix hack.
1280                        (concat " (" (user-login-name) ")"))
1281                       ((string-match "[^ ]+@[^ ]+ +(.*)" address)
1282                        "")
1283                       (t
1284                        (concat " (" full-name ")")))))))
1285
1286 (defun gnus-inews-real-user-address ()
1287   "Return the \"real\" user address.
1288 This function tries to ignore all user modifications, and 
1289 give as trustworthy answer as possible."
1290   (concat (user-login-name) "@" (gnus-inews-full-address)))
1291
1292 (defun gnus-inews-login-name ()
1293   "Return login name."
1294   (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1295
1296 (defun gnus-inews-full-name ()
1297   "Return full user name."
1298   (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1299
1300 (defun gnus-inews-domain-name (&optional genericfrom)
1301   "Return user's domain name.
1302 If optional argument GENERICFROM is a string, use it as the domain
1303 name; if it is non-nil, strip off local host name from the domain name.
1304 If the function `system-name' returns full internet name and the
1305 domain is undefined, the domain name is got from it."
1306   (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1307       (let* ((system-name (system-name))
1308              (domain 
1309               (or (if (stringp genericfrom) genericfrom)
1310                   (getenv "DOMAINNAME")
1311                   gnus-local-domain
1312                   ;; Function `system-name' may return full internet name.
1313                   ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1314                   (if (string-match "\\." system-name)
1315                       (substring system-name (match-end 0)))
1316                   (read-string "Domain name (no host): ")))
1317              (host (or (if (string-match "\\." system-name)
1318                            (substring system-name 0 (match-beginning 0)))
1319                        system-name)))
1320         (if (string-equal "." (substring domain 0 1))
1321             (setq domain (substring domain 1)))
1322         ;; Support GENERICFROM as same as standard Bnews system.
1323         ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1324         (cond ((null genericfrom)
1325                (concat host "." domain))
1326               ;;((stringp genericfrom) genericfrom)
1327               (t domain)))
1328     (if (string-match "\\." (system-name))
1329         (system-name)
1330       (substring user-mail-address 
1331                  (1+ (string-match "@" user-mail-address))))))
1332
1333 (defun gnus-inews-full-address ()
1334   (let ((domain (gnus-inews-domain-name))
1335         (system (system-name))
1336         (case-fold-search t))
1337     (if (string-match "\\." system) system
1338       (if (string-match (concat "^" (regexp-quote system)) domain) domain
1339         (concat system "." domain)))))
1340
1341 (defun gnus-inews-message-id ()
1342   "Generate unique Message-ID for user."
1343   ;; Message-ID should not contain a slash and should be terminated by
1344   ;; a number.  I don't know the reason why it is so.
1345   (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1346
1347 (defvar gnus-unique-id-char nil)
1348
1349 ;; If you ever change this function, make sure the new version
1350 ;; cannot generate IDs that the old version could.
1351 ;; You might for example insert a "." somewhere (not next to another dot
1352 ;; or string boundary), or modify the newsreader name to "Ding".
1353 (defun gnus-inews-unique-id ()
1354   ;; Dont use microseconds from (current-time), they may be unsupported.
1355   ;; Instead we use this randomly inited counter.
1356   (setq gnus-unique-id-char
1357         (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1358            ;; (current-time) returns 16-bit ints,
1359            ;; and 2^16*25 just fits into 4 digits i base 36.
1360            (* 25 25)))
1361   (let ((tm (if (fboundp 'current-time)
1362                 (current-time) '(12191 46742 287898))))
1363     (concat
1364      (if (memq system-type '(ms-dos emx vax-vms))
1365          (let ((user (downcase (gnus-inews-login-name))))
1366            (while (string-match "[^a-z0-9_]" user)
1367              (aset user (match-beginning 0) ?_))
1368            user)
1369        (gnus-number-base36 (user-uid) -1))
1370      (gnus-number-base36 (+ (car   tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1371      (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1372      ;; Append the newsreader name, because while the generated
1373      ;; ID is unique to this newsreader, other newsreaders might
1374      ;; otherwise generate the same ID via another algorithm.
1375      ".fsf")))
1376
1377
1378 (defun gnus-inews-date ()
1379   "Current time string."
1380   (timezone-make-date-arpa-standard 
1381    (current-time-string) (current-time-zone)))
1382
1383 (defun gnus-inews-organization ()
1384   "Return user's organization.
1385 The ORGANIZATION environment variable is used if defined.
1386 If not, the variable `gnus-local-organization' is used instead.
1387 If it is a function, the function will be called with the current
1388 newsgroup name as the argument.
1389 If this is a file name, the contents of this file will be used as the
1390 organization."
1391   (let* ((organization 
1392           (or (getenv "ORGANIZATION")
1393               (if gnus-local-organization
1394                   (if (and (symbolp gnus-local-organization)
1395                            (fboundp gnus-local-organization))
1396                       (funcall gnus-local-organization gnus-newsgroup-name)
1397                     gnus-local-organization))
1398               gnus-organization-file
1399               "~/.organization")))
1400     (and (stringp organization)
1401          (> (length organization) 0)
1402          (or (file-exists-p organization)
1403              (string-match " " organization)
1404              (not (string-match "^/usr/lib/" organization)))
1405          (save-excursion
1406            (gnus-set-work-buffer)
1407            (if (file-exists-p organization)
1408                (insert-file-contents organization)
1409              (insert organization))
1410            (goto-char (point-min))
1411            (while (re-search-forward " *\n *" nil t)
1412              (replace-match " " t t))
1413            (buffer-substring (point-min) (point-max))))))
1414
1415 (defun gnus-inews-lines ()
1416   "Count the number of lines and return numeric string."
1417   (save-excursion
1418     (save-restriction
1419       (widen)
1420       (goto-char (point-min))
1421       (re-search-forward 
1422        (concat "^" (regexp-quote mail-header-separator) "$"))
1423       (forward-line 1)
1424       (int-to-string (count-lines (point) (point-max))))))
1425
1426 \f
1427 ;;;
1428 ;;; Gnus Mail Functions 
1429 ;;;
1430
1431 ;;; Mail reply commands of Gnus summary mode
1432
1433 (defun gnus-summary-reply (yank &optional yank-articles)
1434   "Reply mail to news author.
1435 If prefix argument YANK is non-nil, original article is yanked automatically.
1436 Customize the variable gnus-mail-reply-method to use another mailer."
1437   (interactive "P")
1438   ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1439   ;; Stripping headers should be specified with mail-yank-ignored-headers.
1440   (gnus-set-global-variables)
1441   (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1442   (gnus-summary-select-article)
1443   (let ((gnus-newsgroup-name gnus-newsgroup-name))
1444     (bury-buffer gnus-article-buffer)
1445     (funcall gnus-mail-reply-method (or yank-articles (not (not yank))))))
1446
1447 (defun gnus-summary-reply-with-original (n)
1448   "Reply mail to news author with original article.
1449 Customize the variable gnus-mail-reply-method to use another mailer."
1450   (interactive "P")
1451   (gnus-summary-reply t (gnus-summary-work-articles n)))
1452
1453 (defun gnus-summary-mail-forward (post)
1454   "Forward the current message to another user.
1455 Customize the variable gnus-mail-forward-method to use another mailer."
1456   (interactive "P")
1457   (gnus-set-global-variables)
1458   (gnus-summary-select-article)
1459   (gnus-copy-article-buffer)
1460   (let ((gnus-newsgroup-name gnus-newsgroup-name))
1461     (if post
1462         (gnus-forward-using-post gnus-article-copy)
1463       (funcall gnus-mail-forward-method gnus-article-copy))))
1464
1465 (defun gnus-summary-post-forward ()
1466   "Forward the current article to a newsgroup."
1467   (interactive)
1468   (gnus-summary-mail-forward t))
1469
1470 (defvar gnus-nastygram-message 
1471   "The following article was inappropriately posted to %s.\n"
1472   "Format string to insert in nastygrams.
1473 The current group name will be inserted at \"%s\".")
1474
1475 (defun gnus-summary-mail-nastygram (n)
1476   "Send a nastygram to the author of the current article."
1477   (interactive "P")
1478   (if (or gnus-expert-user
1479           (gnus-y-or-n-p 
1480            "Really send a nastygram to the author of the current article? "))
1481       (let ((group gnus-newsgroup-name))
1482         (gnus-summary-reply-with-original n)
1483         (set-buffer gnus-mail-buffer)
1484         (insert (format gnus-nastygram-message group))
1485         (gnus-mail-send-and-exit))))
1486
1487 (defun gnus-summary-mail-other-window ()
1488   "Compose mail in other window.
1489 Customize the variable `gnus-mail-other-window-method' to use another
1490 mailer."
1491   (interactive)
1492   (gnus-set-global-variables)
1493   (let ((gnus-newsgroup-name gnus-newsgroup-name))
1494     (funcall gnus-mail-other-window-method)))
1495
1496 (defun gnus-mail-reply-using-mail (&optional yank to-address)
1497   (save-excursion
1498     (set-buffer gnus-summary-buffer)
1499     (let ((group (gnus-group-real-name gnus-newsgroup-name))
1500           (cur (cons (current-buffer) (cdr gnus-article-current)))
1501           (winconf (current-window-configuration))
1502           from subject date reply-to message-of
1503           references message-id sender follow-to sendto elt)
1504       (set-buffer (get-buffer-create gnus-mail-buffer))
1505       (mail-mode)
1506       (make-local-variable 'gnus-article-reply)
1507       (setq gnus-article-reply cur)
1508       (make-local-variable 'gnus-prev-winconf)
1509       (setq gnus-prev-winconf winconf)
1510       (if (and (buffer-modified-p)
1511                (> (buffer-size) 0)
1512                (not (gnus-y-or-n-p 
1513                      "Unsent article being composed; erase it? ")))
1514           ()
1515         (erase-buffer)
1516         (save-excursion
1517           (gnus-copy-article-buffer)
1518           (save-restriction
1519             (set-buffer gnus-article-copy)
1520             (gnus-narrow-to-headers)
1521             (if (and (boundp 'gnus-reply-to-function)
1522                      gnus-reply-to-function)
1523                 (setq follow-to (funcall gnus-reply-to-function group)))
1524             (setq from (mail-fetch-field "from"))
1525             (setq date (or (mail-fetch-field "date") 
1526                            (mail-header-date gnus-current-headers)))
1527             (and from
1528                  (let ((stop-pos 
1529                         (string-match "  *at \\|  *@ \\| *(\\| *<" from)))
1530                    (setq message-of
1531                          (concat (if stop-pos (substring from 0 stop-pos) from)
1532                                  "'s message of " date))))
1533             (setq sender (mail-fetch-field "sender"))
1534             (setq subject (or (mail-fetch-field "subject")
1535                               "Re: none"))
1536             (or (string-match "^[Rr][Ee]:" subject)
1537                 (setq subject (concat "Re: " subject)))
1538             (setq reply-to (mail-fetch-field "reply-to"))
1539             (setq references (mail-fetch-field "references"))
1540             (setq message-id (mail-fetch-field "message-id"))
1541             (widen))
1542           (setq news-reply-yank-from (or from "(nobody)")))
1543         (setq news-reply-yank-message-id
1544               (or message-id "(unknown Message-ID)"))
1545
1546         ;; Gather the "to" addresses out of the follow-to list and remove
1547         ;; them as we go.
1548         (if (and follow-to (listp follow-to))
1549             (while (setq elt (assoc "To" follow-to))
1550               (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1551               (setq follow-to (delq elt follow-to))))
1552
1553         (mail-setup (or to-address 
1554                         (if (and follow-to (not (stringp follow-to))) sendto
1555                           (or follow-to reply-to from sender "")))
1556                     subject message-of nil gnus-article-copy nil)
1557
1558         (auto-save-mode auto-save-default)
1559         (use-local-map (copy-keymap mail-mode-map))
1560         (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1561
1562         (if (and follow-to (listp follow-to))
1563             (progn
1564               (goto-char (point-min))
1565               (re-search-forward "^To:" nil t)
1566               (beginning-of-line)
1567               (forward-line 1)
1568               (while follow-to
1569                 (insert (car (car follow-to)) ": " (cdr (car follow-to)) "\n")
1570                 (setq follow-to (cdr follow-to)))))
1571         (nnheader-insert-references references message-id)
1572         (goto-char (point-min))
1573         (re-search-forward
1574          (concat "^" (regexp-quote mail-header-separator) "$"))
1575         (forward-line 1)
1576         (if (not yank)
1577             (gnus-configure-windows 'reply 'force)
1578           (let ((last (point))
1579                 end)
1580             (if (not (listp yank))
1581                 (progn
1582                   (save-excursion
1583                     (mail-yank-original nil))
1584                   (or mail-yank-hooks mail-citation-hook
1585                       (run-hooks 'news-reply-header-hook)))
1586               (while yank
1587                 (save-window-excursion
1588                   (set-buffer gnus-summary-buffer)
1589                   (gnus-summary-select-article nil nil nil (car yank))
1590                   (gnus-summary-remove-process-mark (car yank)))
1591                 (save-excursion
1592                   (gnus-copy-article-buffer)
1593                   (mail-yank-original nil)
1594                   (setq end (point)))
1595                 (or mail-yank-hooks mail-citation-hook
1596                     (run-hooks 'news-reply-header-hook))
1597                 (goto-char end)
1598                 (setq yank (cdr yank))))
1599             (goto-char last))
1600           (gnus-configure-windows 'reply-yank 'force))
1601         (run-hooks 'gnus-mail-hook)))))
1602
1603 (defun gnus-mail-yank-original ()
1604   (interactive)
1605   (save-excursion
1606     (mail-yank-original nil))
1607   (or mail-yank-hooks mail-citation-hook
1608       (run-hooks 'news-reply-header-hook)))
1609
1610 (defun gnus-mail-send-and-exit ()
1611   (interactive)
1612   (let ((reply gnus-article-reply)
1613         (winconf gnus-prev-winconf))
1614     (mail-send-and-exit nil)
1615     (if (get-buffer gnus-group-buffer)
1616         (progn
1617           (if (gnus-buffer-exists-p (car-safe reply))
1618               (progn
1619                 (set-buffer (car reply))
1620                 (and (cdr reply)
1621                      (gnus-summary-mark-article-as-replied 
1622                       (cdr reply)))))
1623           (and winconf (set-window-configuration winconf))))))
1624
1625 (defun gnus-forward-make-subject (buffer)
1626   (save-excursion
1627     (set-buffer buffer)
1628     (concat "[" (if (memq 'mail (assoc (symbol-name 
1629                                         (car (gnus-find-method-for-group 
1630                                               gnus-newsgroup-name)))
1631                                        gnus-valid-select-methods))
1632                     (gnus-fetch-field "From")
1633                   gnus-newsgroup-name)
1634             "] " (or (gnus-fetch-field "Subject") ""))))
1635
1636 (defun gnus-forward-insert-buffer (buffer)
1637   (let ((beg (goto-char (point-max))))
1638     (insert "------- Start of forwarded message -------\n")
1639     (insert-buffer buffer)
1640     (goto-char (point-max))
1641     (insert "------- End of forwarded message -------\n")
1642     ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>. 
1643     (goto-char beg)
1644     (while (setq beg (next-single-property-change (point) 'invisible))
1645       (goto-char beg)
1646       (delete-region beg (or (next-single-property-change 
1647                               (point) 'invisible)
1648                              (point-max))))))
1649
1650 (defun gnus-mail-forward-using-mail (&optional buffer)
1651   "Forward the current message to another user using mail."
1652   ;; This is almost a carbon copy of rmail-forward in rmail.el.
1653   (let* ((forward-buffer (or buffer (current-buffer)))
1654          (winconf (current-window-configuration))
1655          (subject (gnus-forward-make-subject forward-buffer)))
1656     (set-buffer forward-buffer)
1657     (mail nil nil subject)
1658     (use-local-map (copy-keymap (current-local-map)))
1659     (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1660     (make-local-variable 'gnus-prev-winconf)
1661     (setq gnus-prev-winconf winconf)
1662     (gnus-forward-insert-buffer forward-buffer)
1663     (goto-char (point-min))
1664     (re-search-forward "^To: " nil t)
1665     (gnus-configure-windows 'mail-forward 'force)
1666     ;; You have a chance to arrange the message.
1667     (run-hooks 'gnus-mail-forward-hook)
1668     (run-hooks 'gnus-mail-hook)))
1669
1670 (defun gnus-forward-using-post (&optional buffer)
1671   (save-excursion
1672     (let* ((forward-buffer (or buffer (current-buffer))) 
1673            (subject (gnus-forward-make-subject forward-buffer))
1674            (gnus-newsgroup-name nil))
1675       (gnus-post-news 'post nil nil nil nil subject)
1676       (save-excursion
1677         (gnus-forward-insert-buffer forward-buffer)
1678         ;; You have a chance to arrange the message.
1679         (run-hooks 'gnus-mail-forward-hook)))))
1680
1681 (defun gnus-mail-other-window-using-mail ()
1682   "Compose mail other window using mail."
1683   (let ((winconf (current-window-configuration)))
1684     (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
1685     (use-local-map (copy-keymap (current-local-map)))
1686     (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1687     (make-local-variable 'gnus-prev-winconf)
1688     (setq gnus-prev-winconf winconf)
1689     (run-hooks 'gnus-mail-hook)
1690     (gnus-configure-windows 'summary-mail 'force)))
1691
1692 (defun gnus-article-mail (yank)
1693   "Send a reply to the address near point.
1694 If YANK is non-nil, include the original article."
1695   (interactive "P")
1696   (let ((address 
1697          (buffer-substring
1698           (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1699           (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1700     (and address
1701          (progn
1702            (switch-to-buffer gnus-summary-buffer)
1703            (funcall gnus-mail-reply-method yank address)))))
1704
1705 (defun gnus-bug ()
1706   "Send a bug report to the Gnus maintainers."
1707   (interactive)
1708   (let ((winconf (current-window-configuration)))
1709     (delete-other-windows)
1710     (switch-to-buffer "*Gnus Help Bug*")
1711     (erase-buffer)
1712     (insert gnus-bug-message)
1713     (goto-char (point-min))
1714     (pop-to-buffer "*Gnus Bug*")
1715     (erase-buffer)
1716     (mail-mode)
1717     (mail-setup gnus-maintainer nil nil nil nil nil)
1718     (auto-save-mode auto-save-default)
1719     (make-local-variable 'gnus-prev-winconf)
1720     (setq gnus-prev-winconf winconf)
1721     (use-local-map (copy-keymap mail-mode-map))
1722     (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
1723     (goto-char (point-min))
1724     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1725     (forward-line 1)
1726     (insert (format "%s\n%s\n\n\n\n\n" (gnus-version) (emacs-version)))
1727     (gnus-debug)
1728     (goto-char (point-min))
1729     (search-forward "Subject: " nil t)
1730     (message "")))
1731
1732 (defun gnus-bug-mail-send-and-exit ()
1733   "Send the bug message and exit."
1734   (interactive)
1735   (and (get-buffer "*Gnus Help Bug*")
1736        (kill-buffer "*Gnus Help Bug*"))
1737   (gnus-mail-send-and-exit))
1738
1739 (defun gnus-debug ()
1740   "Attemps to go through the Gnus source file and report what variables have been changed.
1741 The source file has to be in the Emacs load path."
1742   (interactive)
1743   (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el"))
1744         file dirs expr olist sym)
1745     (message "Please wait while we snoop your variables...")
1746     (sit-for 0)
1747     (save-excursion
1748       (set-buffer (get-buffer-create " *gnus bug info*"))
1749       (buffer-disable-undo (current-buffer))
1750       (while files
1751         (erase-buffer)
1752         (setq dirs load-path)
1753         (while dirs
1754           (if (or (not (car dirs))
1755                   (not (stringp (car dirs)))
1756                   (not (file-exists-p 
1757                         (setq file (concat (file-name-as-directory 
1758                                             (car dirs)) (car files))))))
1759               (setq dirs (cdr dirs))
1760             (setq dirs nil)
1761             (insert-file-contents file)
1762             (goto-char (point-min))
1763             (or (re-search-forward "^;;* *Internal variables" nil t)
1764                 (error "Malformed sources in file %s" file))
1765             (narrow-to-region (point-min) (point))
1766             (goto-char (point-min))
1767             (while (setq expr (condition-case () 
1768                                   (read (current-buffer)) (error nil)))
1769               (condition-case ()
1770                   (and (eq (car expr) 'defvar)
1771                        (stringp (nth 3 expr))
1772                        (or (not (boundp (nth 1 expr)))
1773                            (not (equal (eval (nth 2 expr))
1774                                        (symbol-value (nth 1 expr)))))
1775                        (setq olist (cons (nth 1 expr) olist)))
1776                 (error nil)))))
1777         (setq files (cdr files)))
1778       (kill-buffer (current-buffer)))
1779     (insert "------------------- Environment follows -------------------\n\n")
1780     (while olist
1781       (if (boundp (car olist))
1782           (insert "(setq " (symbol-name (car olist)) 
1783                   (if (or (consp (setq sym (symbol-value (car olist))))
1784                           (and (symbolp sym)
1785                                (not (or (eq sym nil)
1786                                         (eq sym t)))))
1787                       " '" " ")
1788                   (prin1-to-string (symbol-value (car olist))) ")\n")
1789         (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1790       (setq olist (cdr olist)))
1791     (insert "\n\n")
1792     ;; Remove any null chars - they seem to cause trouble for some
1793     ;; mailers. (Byte-compiled output from the stuff above.) 
1794     (goto-char (point-min))
1795     (while (re-search-forward "[\000\200]" nil t)
1796       (replace-match "" t t))))
1797
1798 (gnus-ems-redefine)
1799
1800 (provide 'gnus-msg)
1801
1802 ;;; gnus-msg.el ends here