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