(menu-bar-epatch-menu, menu-bar-ediff-merge-menu)
[emacs.git] / lisp / gnus-msg.el
blob89d4c3e98d4d4531256190e263f2f38ceea12540
1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
5 ;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
6 ;; Keywords: news
8 ;; This file is part of GNU Emacs.
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.
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.
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.
24 ;;; Commentary:
26 ;;; Code:
28 (require 'gnus)
29 (require 'sendmail)
30 (require 'gnus-ems)
32 (defvar gnus-organization-file "/usr/lib/news/organization"
33 "*Local news organization file.")
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'.")
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).")
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.")
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.")
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.
66 Here's an example `gnus-followup-to-function':
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\")))
74 (or (mail-fetch-field \"reply-to\")
75 (mail-fetch-field \"from\"))))))")
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.
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.")
88 (defvar gnus-author-copy (getenv "AUTHORCOPY")
89 "*Save outgoing articles in this file.
90 Initialized from the AUTHORCOPY environment variable.
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:
96 \(setq gnus-author-copy \"|/usr/local/lib/mh/rcvstore +Article\")
98 If the first character is not a pipe, articles are saved using the
99 function specified by the `gnus-author-copy-saver' variable.")
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.")
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.")
113 (defvar gnus-user-login-name nil
114 "*The login name of the user.
115 Got from the function `user-login-name' if undefined.")
117 (defvar gnus-user-full-name nil
118 "*The full name of the user.
119 Got from the NAME environment variable if undefined.")
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.
125 Here are two example values of this variable:
127 \"Lars Magne Ingebrigtsen <larsi@ifi.uio.no>\"
131 \"larsi@ifi.uio.no (Lars Magne Ingebrigtsen)\"
133 The first version is recommended, but the name has to be quoted if it
134 contains non-alphanumerical characters.")
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.")
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.")
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.")
157 (defvar gnus-deletable-headers '(Message-ID Date)
158 "*Headers to be deleted if they already exists and were generated by Gnus previously.")
160 (defvar gnus-removable-headers '(NNTP-Posting-Host Bcc Xref)
161 "*Headers to be removed unconditionally before posting.")
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.")
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.")
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.
183 Mail is sent using the function specified by the
184 `gnus-mail-send-method' variable.")
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.")
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'.")
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'.")
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'.")
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'.")
213 (defvar gnus-inews-article-function 'gnus-inews-article
214 "*Function to post an article.")
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).")
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.")
226 (defvar gnus-mail-hook nil
227 "*A hook called as the last thing after setting up a mail buffer.")
229 ;;; Internal variables.
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)
237 (eval-and-compile
238 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
239 (autoload 'rmail-output "rmailout"))
243 ;;; Gnus Posting Functions
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)
264 ;;; Internal functions.
266 (defun gnus-number-base36 (num len)
267 (if (if (< len 0) (<= num 0) (= len 0))
269 (concat (gnus-number-base36 (/ num 36) (1- len))
270 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
271 (% num 36))))))
273 ;;; Post news commands of Gnus group mode and summary mode
275 (defun gnus-group-mail ()
276 "Start composing a mail."
277 (interactive)
278 (funcall gnus-mail-other-window-method))
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)))
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))
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)))))))
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)))
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)))
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)))
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)))))
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))))
387 ;;;###autoload
388 (defalias 'sendnews 'gnus-post-news)
390 ;;;###autoload
391 (defalias 'postnews 'gnus-post-news)
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)))))
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)
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))
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)
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 "")
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)))
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))))
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)))
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")))))))
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]+" ",")))
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)))
652 (if (not types)
653 ;; We do not want to send mail.
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...
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)))
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")))
683 (save-restriction
684 (widen)
685 (gnus-message 5 "Sending via mail...")
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))
708 (gnus-message 5 "Sending via mail...done")
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))))))))
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))
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)))))))
760 (defun gnus-inews-check-post ()
761 "Check whether the post looks ok."
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)))))
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)))
873 ;; Use the (size . checksum) variable to see whether the
874 ;; article is empty or has only quoted text.
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? ")
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))
888 (if (> (count-lines (point) (point-max)) 5)
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)))))))
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))
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))))
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")
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)
965 ;; Kill the article buffer.
966 (kill-buffer (current-buffer))))))))
969 ;;; Lowlevel inews interface
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)))))))
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)))))
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"))))))
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.
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))
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"))))))))
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")))))))
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)))
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)
1255 (mail-file-babyl-p fcc-file))
1256 (gnus-output-to-rmail fcc-file)
1257 (rmail-output fcc-file 1 t t))))))))))
1259 (defun gnus-inews-path ()
1260 "Return uucp path."
1261 (let ((login-name (gnus-inews-login-name)))
1262 (cond ((null gnus-use-generic-path)
1263 (concat (nth 1 gnus-select-method) "!" login-name))
1264 ((stringp gnus-use-generic-path)
1265 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1266 (concat gnus-use-generic-path "!" login-name))
1267 (t login-name))))
1269 (defun gnus-inews-user-name ()
1270 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1271 (let ((full-name (gnus-inews-full-name))
1272 (address (if (or gnus-user-login-name gnus-use-generic-from
1273 gnus-local-domain (getenv "DOMAINNAME"))
1274 (concat (gnus-inews-login-name) "@"
1275 (gnus-inews-domain-name gnus-use-generic-from))
1276 user-mail-address)))
1277 (or gnus-user-from-line
1278 (concat address
1279 ;; User's full name.
1280 (cond ((string-equal full-name "&") ;Unix hack.
1281 (concat " (" (user-login-name) ")"))
1282 ((string-match "[^ ]+@[^ ]+ +(.*)" address)
1285 (concat " (" full-name ")")))))))
1287 (defun gnus-inews-real-user-address ()
1288 "Return the \"real\" user address.
1289 This function tries to ignore all user modifications, and
1290 give as trustworthy answer as possible."
1291 (concat (user-login-name) "@" (gnus-inews-full-address)))
1293 (defun gnus-inews-login-name ()
1294 "Return login name."
1295 (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1297 (defun gnus-inews-full-name ()
1298 "Return full user name."
1299 (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1301 (defun gnus-inews-domain-name (&optional genericfrom)
1302 "Return user's domain name.
1303 If optional argument GENERICFROM is a string, use it as the domain
1304 name; if it is non-nil, strip off local host name from the domain name.
1305 If the function `system-name' returns full internet name and the
1306 domain is undefined, the domain name is got from it."
1307 (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1308 (let* ((system-name (system-name))
1309 (domain
1310 (or (if (stringp genericfrom) genericfrom)
1311 (getenv "DOMAINNAME")
1312 gnus-local-domain
1313 ;; Function `system-name' may return full internet name.
1314 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1315 (if (string-match "\\." system-name)
1316 (substring system-name (match-end 0)))
1317 (read-string "Domain name (no host): ")))
1318 (host (or (if (string-match "\\." system-name)
1319 (substring system-name 0 (match-beginning 0)))
1320 system-name)))
1321 (if (string-equal "." (substring domain 0 1))
1322 (setq domain (substring domain 1)))
1323 ;; Support GENERICFROM as same as standard Bnews system.
1324 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1325 (cond ((null genericfrom)
1326 (concat host "." domain))
1327 ;;((stringp genericfrom) genericfrom)
1328 (t domain)))
1329 (if (string-match "\\." (system-name))
1330 (system-name)
1331 (substring user-mail-address
1332 (1+ (string-match "@" user-mail-address))))))
1334 (defun gnus-inews-full-address ()
1335 (let ((domain (gnus-inews-domain-name))
1336 (system (system-name))
1337 (case-fold-search t))
1338 (if (string-match "\\." system) system
1339 (if (string-match (concat "^" (regexp-quote system)) domain) domain
1340 (concat system "." domain)))))
1342 (defun gnus-inews-message-id ()
1343 "Generate unique Message-ID for user."
1344 ;; Message-ID should not contain a slash and should be terminated by
1345 ;; a number. I don't know the reason why it is so.
1346 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1348 (defvar gnus-unique-id-char nil)
1350 ;; If you ever change this function, make sure the new version
1351 ;; cannot generate IDs that the old version could.
1352 ;; You might for example insert a "." somewhere (not next to another dot
1353 ;; or string boundary), or modify the newsreader name to "Ding".
1354 (defun gnus-inews-unique-id ()
1355 ;; Dont use microseconds from (current-time), they may be unsupported.
1356 ;; Instead we use this randomly inited counter.
1357 (setq gnus-unique-id-char
1358 (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1359 ;; (current-time) returns 16-bit ints,
1360 ;; and 2^16*25 just fits into 4 digits i base 36.
1361 (* 25 25)))
1362 (let ((tm (if (fboundp 'current-time)
1363 (current-time) '(12191 46742 287898))))
1364 (concat
1365 (if (memq system-type '(ms-dos emx vax-vms))
1366 (let ((user (downcase (gnus-inews-login-name))))
1367 (while (string-match "[^a-z0-9_]" user)
1368 (aset user (match-beginning 0) ?_))
1369 user)
1370 (gnus-number-base36 (user-uid) -1))
1371 (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1372 (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1373 ;; Append the newsreader name, because while the generated
1374 ;; ID is unique to this newsreader, other newsreaders might
1375 ;; otherwise generate the same ID via another algorithm.
1376 ".fsf")))
1379 (defun gnus-inews-date ()
1380 "Current time string."
1381 (timezone-make-date-arpa-standard
1382 (current-time-string) (current-time-zone)))
1384 (defun gnus-inews-organization ()
1385 "Return user's organization.
1386 The ORGANIZATION environment variable is used if defined.
1387 If not, the variable `gnus-local-organization' is used instead.
1388 If it is a function, the function will be called with the current
1389 newsgroup name as the argument.
1390 If this is a file name, the contents of this file will be used as the
1391 organization."
1392 (let* ((organization
1393 (or (getenv "ORGANIZATION")
1394 (if gnus-local-organization
1395 (if (and (symbolp gnus-local-organization)
1396 (fboundp gnus-local-organization))
1397 (funcall gnus-local-organization gnus-newsgroup-name)
1398 gnus-local-organization))
1399 gnus-organization-file
1400 "~/.organization")))
1401 (and (stringp organization)
1402 (> (length organization) 0)
1403 (or (file-exists-p organization)
1404 (string-match " " organization)
1405 (not (string-match "^/usr/lib/" organization)))
1406 (save-excursion
1407 (gnus-set-work-buffer)
1408 (if (file-exists-p organization)
1409 (insert-file-contents organization)
1410 (insert organization))
1411 (goto-char (point-min))
1412 (while (re-search-forward " *\n *" nil t)
1413 (replace-match " " t t))
1414 (buffer-substring (point-min) (point-max))))))
1416 (defun gnus-inews-lines ()
1417 "Count the number of lines and return numeric string."
1418 (save-excursion
1419 (save-restriction
1420 (widen)
1421 (goto-char (point-min))
1422 (re-search-forward
1423 (concat "^" (regexp-quote mail-header-separator) "$"))
1424 (forward-line 1)
1425 (int-to-string (count-lines (point) (point-max))))))
1429 ;;; Gnus Mail Functions
1432 ;;; Mail reply commands of Gnus summary mode
1434 (defun gnus-summary-reply (yank &optional yank-articles)
1435 "Reply mail to news author.
1436 If prefix argument YANK is non-nil, original article is yanked automatically.
1437 Customize the variable gnus-mail-reply-method to use another mailer."
1438 (interactive "P")
1439 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1440 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1441 (gnus-set-global-variables)
1442 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1443 (gnus-summary-select-article)
1444 (let ((gnus-newsgroup-name gnus-newsgroup-name))
1445 (bury-buffer gnus-article-buffer)
1446 (funcall gnus-mail-reply-method (or yank-articles (not (not yank))))))
1448 (defun gnus-summary-reply-with-original (n)
1449 "Reply mail to news author with original article.
1450 Customize the variable gnus-mail-reply-method to use another mailer."
1451 (interactive "P")
1452 (gnus-summary-reply t (gnus-summary-work-articles n)))
1454 (defun gnus-summary-mail-forward (post)
1455 "Forward the current message to another user.
1456 Customize the variable gnus-mail-forward-method to use another mailer."
1457 (interactive "P")
1458 (gnus-set-global-variables)
1459 (gnus-summary-select-article)
1460 (gnus-copy-article-buffer)
1461 (let ((gnus-newsgroup-name gnus-newsgroup-name))
1462 (if post
1463 (gnus-forward-using-post gnus-article-copy)
1464 (funcall gnus-mail-forward-method gnus-article-copy))))
1466 (defun gnus-summary-post-forward ()
1467 "Forward the current article to a newsgroup."
1468 (interactive)
1469 (gnus-summary-mail-forward t))
1471 (defvar gnus-nastygram-message
1472 "The following article was inappropriately posted to %s.\n"
1473 "Format string to insert in nastygrams.
1474 The current group name will be inserted at \"%s\".")
1476 (defun gnus-summary-mail-nastygram (n)
1477 "Send a nastygram to the author of the current article."
1478 (interactive "P")
1479 (if (or gnus-expert-user
1480 (gnus-y-or-n-p
1481 "Really send a nastygram to the author of the current article? "))
1482 (let ((group gnus-newsgroup-name))
1483 (gnus-summary-reply-with-original n)
1484 (set-buffer gnus-mail-buffer)
1485 (insert (format gnus-nastygram-message group))
1486 (gnus-mail-send-and-exit))))
1488 (defun gnus-summary-mail-other-window ()
1489 "Compose mail in other window.
1490 Customize the variable `gnus-mail-other-window-method' to use another
1491 mailer."
1492 (interactive)
1493 (gnus-set-global-variables)
1494 (let ((gnus-newsgroup-name gnus-newsgroup-name))
1495 (funcall gnus-mail-other-window-method)))
1497 (defun gnus-mail-reply-using-mail (&optional yank to-address)
1498 (save-excursion
1499 (set-buffer gnus-summary-buffer)
1500 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1501 (cur (cons (current-buffer) (cdr gnus-article-current)))
1502 (winconf (current-window-configuration))
1503 from subject date reply-to message-of
1504 references message-id sender follow-to sendto elt)
1505 (set-buffer (get-buffer-create gnus-mail-buffer))
1506 (mail-mode)
1507 (make-local-variable 'gnus-article-reply)
1508 (setq gnus-article-reply cur)
1509 (make-local-variable 'gnus-prev-winconf)
1510 (setq gnus-prev-winconf winconf)
1511 (if (and (buffer-modified-p)
1512 (> (buffer-size) 0)
1513 (not (gnus-y-or-n-p
1514 "Unsent article being composed; erase it? ")))
1516 (erase-buffer)
1517 (save-excursion
1518 (gnus-copy-article-buffer)
1519 (save-restriction
1520 (set-buffer gnus-article-copy)
1521 (gnus-narrow-to-headers)
1522 (if (and (boundp 'gnus-reply-to-function)
1523 gnus-reply-to-function)
1524 (setq follow-to (funcall gnus-reply-to-function group)))
1525 (setq from (mail-fetch-field "from"))
1526 (setq date (or (mail-fetch-field "date")
1527 (mail-header-date gnus-current-headers)))
1528 (and from
1529 (let ((stop-pos
1530 (string-match " *at \\| *@ \\| *(\\| *<" from)))
1531 (setq message-of
1532 (concat (if stop-pos (substring from 0 stop-pos) from)
1533 "'s message of " date))))
1534 (setq sender (mail-fetch-field "sender"))
1535 (setq subject (or (mail-fetch-field "subject")
1536 "Re: none"))
1537 (or (string-match "^[Rr][Ee]:" subject)
1538 (setq subject (concat "Re: " subject)))
1539 (setq reply-to (mail-fetch-field "reply-to"))
1540 (setq references (mail-fetch-field "references"))
1541 (setq message-id (mail-fetch-field "message-id"))
1542 (widen))
1543 (setq news-reply-yank-from (or from "(nobody)")))
1544 (setq news-reply-yank-message-id
1545 (or message-id "(unknown Message-ID)"))
1547 ;; Gather the "to" addresses out of the follow-to list and remove
1548 ;; them as we go.
1549 (if (and follow-to (listp follow-to))
1550 (while (setq elt (assoc "To" follow-to))
1551 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1552 (setq follow-to (delq elt follow-to))))
1554 (mail-setup (or to-address
1555 (if (and follow-to (not (stringp follow-to))) sendto
1556 (or follow-to reply-to from sender "")))
1557 subject message-of nil gnus-article-copy nil)
1559 (auto-save-mode auto-save-default)
1560 (use-local-map (copy-keymap mail-mode-map))
1561 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1563 (if (and follow-to (listp follow-to))
1564 (progn
1565 (goto-char (point-min))
1566 (re-search-forward "^To:" nil t)
1567 (beginning-of-line)
1568 (forward-line 1)
1569 (while follow-to
1570 (insert (car (car follow-to)) ": " (cdr (car follow-to)) "\n")
1571 (setq follow-to (cdr follow-to)))))
1572 (nnheader-insert-references references message-id)
1573 (goto-char (point-min))
1574 (re-search-forward
1575 (concat "^" (regexp-quote mail-header-separator) "$"))
1576 (forward-line 1)
1577 (if (not yank)
1578 (gnus-configure-windows 'reply 'force)
1579 (let ((last (point))
1580 end)
1581 (if (not (listp yank))
1582 (progn
1583 (save-excursion
1584 (mail-yank-original nil))
1585 (or mail-yank-hooks mail-citation-hook
1586 (run-hooks 'news-reply-header-hook)))
1587 (while yank
1588 (save-window-excursion
1589 (set-buffer gnus-summary-buffer)
1590 (gnus-summary-select-article nil nil nil (car yank))
1591 (gnus-summary-remove-process-mark (car yank)))
1592 (save-excursion
1593 (gnus-copy-article-buffer)
1594 (mail-yank-original nil)
1595 (setq end (point)))
1596 (or mail-yank-hooks mail-citation-hook
1597 (run-hooks 'news-reply-header-hook))
1598 (goto-char end)
1599 (setq yank (cdr yank))))
1600 (goto-char last))
1601 (gnus-configure-windows 'reply-yank 'force))
1602 (run-hooks 'gnus-mail-hook)))))
1604 (defun gnus-mail-yank-original ()
1605 (interactive)
1606 (save-excursion
1607 (mail-yank-original nil))
1608 (or mail-yank-hooks mail-citation-hook
1609 (run-hooks 'news-reply-header-hook)))
1611 (defun gnus-mail-send-and-exit ()
1612 (interactive)
1613 (let ((reply gnus-article-reply)
1614 (winconf gnus-prev-winconf))
1615 (mail-send-and-exit nil)
1616 (if (get-buffer gnus-group-buffer)
1617 (progn
1618 (if (gnus-buffer-exists-p (car-safe reply))
1619 (progn
1620 (set-buffer (car reply))
1621 (and (cdr reply)
1622 (gnus-summary-mark-article-as-replied
1623 (cdr reply)))))
1624 (and winconf (set-window-configuration winconf))))))
1626 (defun gnus-forward-make-subject (buffer)
1627 (save-excursion
1628 (set-buffer buffer)
1629 (concat "[" (if (memq 'mail (assoc (symbol-name
1630 (car (gnus-find-method-for-group
1631 gnus-newsgroup-name)))
1632 gnus-valid-select-methods))
1633 (gnus-fetch-field "From")
1634 gnus-newsgroup-name)
1635 "] " (or (gnus-fetch-field "Subject") ""))))
1637 (defun gnus-forward-insert-buffer (buffer)
1638 (let ((beg (goto-char (point-max))))
1639 (insert "------- Start of forwarded message -------\n")
1640 (insert-buffer buffer)
1641 (goto-char (point-max))
1642 (insert "------- End of forwarded message -------\n")
1643 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
1644 (goto-char beg)
1645 (while (setq beg (next-single-property-change (point) 'invisible))
1646 (goto-char beg)
1647 (delete-region beg (or (next-single-property-change
1648 (point) 'invisible)
1649 (point-max))))))
1651 (defun gnus-mail-forward-using-mail (&optional buffer)
1652 "Forward the current message to another user using mail."
1653 ;; This is almost a carbon copy of rmail-forward in rmail.el.
1654 (let* ((forward-buffer (or buffer (current-buffer)))
1655 (winconf (current-window-configuration))
1656 (subject (gnus-forward-make-subject forward-buffer)))
1657 (set-buffer forward-buffer)
1658 (mail nil nil subject)
1659 (use-local-map (copy-keymap (current-local-map)))
1660 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1661 (make-local-variable 'gnus-prev-winconf)
1662 (setq gnus-prev-winconf winconf)
1663 (gnus-forward-insert-buffer forward-buffer)
1664 (goto-char (point-min))
1665 (re-search-forward "^To: " nil t)
1666 (gnus-configure-windows 'mail-forward 'force)
1667 ;; You have a chance to arrange the message.
1668 (run-hooks 'gnus-mail-forward-hook)
1669 (run-hooks 'gnus-mail-hook)))
1671 (defun gnus-forward-using-post (&optional buffer)
1672 (save-excursion
1673 (let* ((forward-buffer (or buffer (current-buffer)))
1674 (subject (gnus-forward-make-subject forward-buffer))
1675 (gnus-newsgroup-name nil))
1676 (gnus-post-news 'post nil nil nil nil subject)
1677 (save-excursion
1678 (gnus-forward-insert-buffer forward-buffer)
1679 ;; You have a chance to arrange the message.
1680 (run-hooks 'gnus-mail-forward-hook)))))
1682 (defun gnus-mail-other-window-using-mail ()
1683 "Compose mail other window using mail."
1684 (let ((winconf (current-window-configuration)))
1685 (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
1686 (use-local-map (copy-keymap (current-local-map)))
1687 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1688 (make-local-variable 'gnus-prev-winconf)
1689 (setq gnus-prev-winconf winconf)
1690 (run-hooks 'gnus-mail-hook)
1691 (gnus-configure-windows 'summary-mail 'force)))
1693 (defun gnus-article-mail (yank)
1694 "Send a reply to the address near point.
1695 If YANK is non-nil, include the original article."
1696 (interactive "P")
1697 (let ((address
1698 (buffer-substring
1699 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1700 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1701 (and address
1702 (progn
1703 (switch-to-buffer gnus-summary-buffer)
1704 (funcall gnus-mail-reply-method yank address)))))
1706 (defun gnus-bug ()
1707 "Send a bug report to the Gnus maintainers."
1708 (interactive)
1709 (let ((winconf (current-window-configuration)))
1710 (delete-other-windows)
1711 (switch-to-buffer "*Gnus Help Bug*")
1712 (erase-buffer)
1713 (insert gnus-bug-message)
1714 (goto-char (point-min))
1715 (pop-to-buffer "*Gnus Bug*")
1716 (erase-buffer)
1717 (mail-mode)
1718 (mail-setup gnus-maintainer nil nil nil nil nil)
1719 (auto-save-mode auto-save-default)
1720 (make-local-variable 'gnus-prev-winconf)
1721 (setq gnus-prev-winconf winconf)
1722 (use-local-map (copy-keymap mail-mode-map))
1723 (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
1724 (goto-char (point-min))
1725 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1726 (forward-line 1)
1727 (insert (format "%s\n%s\n\n\n\n\n" (gnus-version) (emacs-version)))
1728 (gnus-debug)
1729 (goto-char (point-min))
1730 (search-forward "Subject: " nil t)
1731 (message "")))
1733 (defun gnus-bug-mail-send-and-exit ()
1734 "Send the bug message and exit."
1735 (interactive)
1736 (and (get-buffer "*Gnus Help Bug*")
1737 (kill-buffer "*Gnus Help Bug*"))
1738 (gnus-mail-send-and-exit))
1740 (defun gnus-debug ()
1741 "Attemps to go through the Gnus source file and report what variables have been changed.
1742 The source file has to be in the Emacs load path."
1743 (interactive)
1744 (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el"))
1745 file dirs expr olist sym)
1746 (message "Please wait while we snoop your variables...")
1747 (sit-for 0)
1748 (save-excursion
1749 (set-buffer (get-buffer-create " *gnus bug info*"))
1750 (buffer-disable-undo (current-buffer))
1751 (while files
1752 (erase-buffer)
1753 (setq dirs load-path)
1754 (while dirs
1755 (if (or (not (car dirs))
1756 (not (stringp (car dirs)))
1757 (not (file-exists-p
1758 (setq file (concat (file-name-as-directory
1759 (car dirs)) (car files))))))
1760 (setq dirs (cdr dirs))
1761 (setq dirs nil)
1762 (insert-file-contents file)
1763 (goto-char (point-min))
1764 (or (re-search-forward "^;;* *Internal variables" nil t)
1765 (error "Malformed sources in file %s" file))
1766 (narrow-to-region (point-min) (point))
1767 (goto-char (point-min))
1768 (while (setq expr (condition-case ()
1769 (read (current-buffer)) (error nil)))
1770 (condition-case ()
1771 (and (eq (car expr) 'defvar)
1772 (stringp (nth 3 expr))
1773 (or (not (boundp (nth 1 expr)))
1774 (not (equal (eval (nth 2 expr))
1775 (symbol-value (nth 1 expr)))))
1776 (setq olist (cons (nth 1 expr) olist)))
1777 (error nil)))))
1778 (setq files (cdr files)))
1779 (kill-buffer (current-buffer)))
1780 (insert "------------------- Environment follows -------------------\n\n")
1781 (while olist
1782 (if (boundp (car olist))
1783 (insert "(setq " (symbol-name (car olist))
1784 (if (or (consp (setq sym (symbol-value (car olist))))
1785 (and (symbolp sym)
1786 (not (or (eq sym nil)
1787 (eq sym t)))))
1788 " '" " ")
1789 (prin1-to-string (symbol-value (car olist))) ")\n")
1790 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1791 (setq olist (cdr olist)))
1792 (insert "\n\n")
1793 ;; Remove any null chars - they seem to cause trouble for some
1794 ;; mailers. (Byte-compiled output from the stuff above.)
1795 (goto-char (point-min))
1796 (while (re-search-forward "[\000\200]" nil t)
1797 (replace-match "" t t))))
1799 (gnus-ems-redefine)
1801 (provide 'gnus-msg)
1803 ;;; gnus-msg.el ends here