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>
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)
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.
33 (defvar gnus-organization-file "/usr/lib/news/organization"
34 "*Local news organization file.")
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).")
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.")
48 (defvar gnus-use-followup-to 'use
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 neither nil nor t, which is the default, always use
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
62 Here's an example `gnus-followup-to-function':
64 (setq gnus-followup-to-function
66 (cond ((string= group \"mail.list\")
67 (or (mail-fetch-field \"sender\")
68 (mail-fetch-field \"from\")))
70 (or (mail-fetch-field \"reply-to\")
71 (mail-fetch-field \"from\"))))))")
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.
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
84 (defvar gnus-author-copy (getenv "AUTHORCOPY")
85 "*Save outgoing articles in this file.
86 Initialized from the AUTHORCOPY environment variable.
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:
92 \(setq gnus-author-copy \"|/usr/local/lib/mh/rcvstore +Article\")
94 If the first character is not a pipe, articles are saved using the
95 function specified by the `gnus-author-copy-saver' variable.")
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.")
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
109 (defvar gnus-user-login-name nil
110 "*The login name of the user.
111 Got from the function `user-login-name' if undefined.")
113 (defvar gnus-user-full-name nil
114 "*The full name of the user.
115 Got from the NAME environment variable if undefined.")
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.
121 Here are two example values of this variable:
123 \"Lars Magne Ingebrigtsen <larsi@ifi.uio.no>\"
127 \"larsi@ifi.uio.no (Lars Magne Ingebrigtsen)\"
129 The first version is recommended, but the name has to be quoted if it
130 contains non-alphanumerical characters.")
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.")
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
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
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.")
153 (defvar gnus-deletable-headers '(Message-ID)
154 "*Headers to be deleted if they already exists.")
156 (defvar gnus-check-before-posting
157 '(subject-cmsg multiple-headers sendsys message-id from
158 long-lines control-chars size new-text
160 "In non-nil, Gnus will attempt to run some checks on outgoing posts.
161 If this variable is t, Gnus will check everything it can. If it is a
162 list, then those elements in that list will be checked.")
164 (defvar gnus-delete-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:"
165 "*Header lines matching this regexp will be deleted before posting.
166 It's best to delete old Path and Date headers before psoting to avoid
169 (defvar gnus-auto-mail-to-author nil
170 "*If non-nil, mail the authors of articles a copy of your follow-ups.
171 If this variable is `ask', the user will be prompted for whether to
172 mail a copy. The string given by `gnus-mail-courtesy-message' will be
173 inserted at the beginning of the mail copy.
175 Mail is sent using the function specified by the
176 `gnus-mail-send-method' variable.")
178 ;; Added by Ethan Bradford <ethanb@ptolemy.astro.washington.edu>.
179 (defvar gnus-mail-courtesy-message
180 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
181 "*This is inserted at the start of a mailed copy of a posted message.
182 If this variable is nil, no such courtesy message will be added.")
184 (defvar gnus-mail-reply-method (function gnus-mail-reply-using-mail)
185 "*Function to compose a reply.
186 Three pre-made functions are `gnus-mail-reply-using-mail' (sendmail);
187 `gnus-mail-reply-using-mhe' (MH-E); and `gnus-mail-reply-using-vm'.")
189 (defvar gnus-mail-forward-method (function gnus-mail-forward-using-mail)
190 "*Function to forward the current message to another user.
191 Three pre-made functions are `gnus-mail-forward-using-mail' (sendmail);
192 `gnus-mail-forward-using-mhe' (MH-E); and `gnus-mail-forward-using-vm'.")
194 (defvar gnus-mail-other-window-method 'gnus-mail-other-window-using-mail
195 "*Function to compose mail in the other window.
196 Three pre-made functions are `gnus-mail-other-window-using-mail'
197 (sendmail); `gnus-mail-other-window-using-mhe' (MH-E); and
198 `gnus-mail-other-window-using-vm'.")
200 (defvar gnus-mail-send-method send-mail-function
201 "*Function to mail a message which is also being posted as an article.
202 The message must have To or Cc header. The default is copied from
203 the variable `send-mail-function'.")
205 (defvar gnus-inews-article-function 'gnus-inews-article
206 "*Function to post an article.")
208 (defvar gnus-inews-article-hook (list 'gnus-inews-do-fcc)
209 "*A hook called before finally posting an article.
210 The default hook (`gnus-inews-do-fcc') does FCC processing (ie. saves
211 the article to a file).")
213 (defvar gnus-inews-article-header-hook nil
214 "*A hook called after inserting the headers in an article to be posted.
215 The hook is called from the *post-news* buffer, narrowed to the
218 (defvar gnus-mail-hook nil
219 "*A hook called as the last thing after setting up a mail buffer.")
221 ;;; Internal variables.
223 (defvar gnus-post-news-buffer "*post-news*")
224 (defvar gnus-mail-buffer "*mail*")
225 (defvar gnus-summary-send-map nil)
226 (defvar gnus-article-copy nil)
227 (defvar gnus-reply-subject nil)
231 ;;; Gnus Posting Functions
234 (define-prefix-command 'gnus-summary-send-map)
235 (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
236 (define-key gnus-summary-send-map "p" 'gnus-summary-post-news)
237 (define-key gnus-summary-send-map "f" 'gnus-summary-followup)
238 (define-key gnus-summary-send-map "F" 'gnus-summary-followup-with-original)
239 (define-key gnus-summary-send-map "b" 'gnus-summary-followup-and-reply)
240 (define-key gnus-summary-send-map "B" 'gnus-summary-followup-and-reply-with-original)
241 (define-key gnus-summary-send-map "c" 'gnus-summary-cancel-article)
242 (define-key gnus-summary-send-map "s" 'gnus-summary-supersede-article)
243 (define-key gnus-summary-send-map "r" 'gnus-summary-reply)
244 (define-key gnus-summary-send-map "R" 'gnus-summary-reply-with-original)
245 (define-key gnus-summary-send-map "m" 'gnus-summary-mail-other-window)
246 (define-key gnus-summary-send-map "u" 'gnus-uu-post-news)
247 (define-key gnus-summary-send-map "om" 'gnus-summary-mail-forward)
248 (define-key gnus-summary-send-map "op" 'gnus-summary-post-forward)
249 (define-key gnus-summary-send-map "Om" 'gnus-uu-digest-mail-forward)
250 (define-key gnus-summary-send-map "Op" 'gnus-uu-digest-post-forward)
252 ;;; Internal functions.
254 (defun gnus-number-base36 (num len)
255 (if (if (< len 0) (<= num 0) (= len 0))
257 (concat (gnus-number-base36 (/ num 36) (1- len))
258 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
261 ;;; Post news commands of Gnus group mode and summary mode
263 (defun gnus-group-mail ()
264 "Start composing a mail."
266 (funcall gnus-mail-other-window-method)
267 (gnus-configure-windows 'group-mail)
268 (run-hooks 'gnus-mail-hook))
270 (defun gnus-group-post-news ()
273 (let ((gnus-newsgroup-name nil))
274 (gnus-post-news 'post nil nil gnus-article-buffer)))
276 (defun gnus-summary-post-news ()
279 (gnus-set-global-variables)
280 (gnus-post-news 'post gnus-newsgroup-name))
282 (defun gnus-summary-followup (yank &optional yank-articles)
283 "Compose a followup to an article.
284 If prefix argument YANK is non-nil, original article is yanked automatically."
286 (gnus-set-global-variables)
287 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
288 (save-window-excursion
289 (gnus-summary-select-article))
290 (let ((headers (gnus-get-header-by-number (gnus-summary-article-number)))
291 (gnus-newsgroup-name gnus-newsgroup-name))
292 ;; Check Followup-To: poster.
293 (set-buffer gnus-article-buffer)
294 (if (and gnus-use-followup-to
295 (string-equal "poster" (gnus-fetch-field "followup-to"))
296 (or (not (eq gnus-use-followup-to t))
298 "Do you want to ignore `Followup-To: poster'? "))))
299 ;; Mail to the poster.
300 (gnus-summary-reply yank)
301 (gnus-post-news nil gnus-newsgroup-name
302 headers gnus-article-buffer
303 (or yank-articles (not (not yank)))))))
305 (defun gnus-summary-followup-with-original (n)
306 "Compose a followup to an article and include the original article."
308 (gnus-summary-followup t (gnus-summary-work-articles n)))
310 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
311 (defun gnus-summary-followup-and-reply (yank &optional yank-articles)
312 "Compose a followup and do an auto mail to author."
314 (gnus-set-global-variables)
315 (let ((gnus-auto-mail-to-author t))
316 (gnus-summary-followup yank yank-articles)))
318 (defun gnus-summary-followup-and-reply-with-original (n)
319 "Compose a followup, include the original, and do an auto mail to author."
321 (gnus-summary-followup-and-reply t (gnus-summary-work-articles n)))
323 (defun gnus-summary-cancel-article (n)
324 "Cancel an article you posted."
326 (gnus-set-global-variables)
327 (let ((articles (gnus-summary-work-articles n)))
329 (gnus-summary-select-article t nil nil (car articles))
330 (and (gnus-eval-in-buffer-window gnus-article-buffer (gnus-cancel-news))
331 (gnus-summary-mark-as-read (car articles) gnus-canceled-mark))
332 (gnus-summary-remove-process-mark (car articles))
333 (gnus-article-hide-headers-if-wanted)
334 (setq articles (cdr articles)))))
336 (defun gnus-summary-supersede-article ()
337 "Compose an article that will supersede a previous article.
338 This is done simply by taking the old article and adding a Supersedes
339 header line with the old Message-ID."
341 (gnus-set-global-variables)
342 (gnus-summary-select-article t)
345 (downcase (mail-strip-quoted-names
346 (header-from gnus-current-headers)))
347 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
348 (error "This article is not yours."))
350 (set-buffer gnus-article-buffer)
351 (let ((buffer-read-only nil))
352 (goto-char (point-min))
353 (search-forward "\n\n" nil t)
354 (if (not (re-search-backward "^Message-ID: " nil t))
355 (error "No Message-ID in this article"))))
356 (if (gnus-post-news 'post gnus-newsgroup-name)
359 (insert-buffer gnus-article-buffer)
360 (goto-char (point-min))
361 (search-forward "\n\n" nil t)
362 (if (not (re-search-backward "^Message-ID: " nil t))
363 (error "No Message-ID in this article")
364 (replace-match "Supersedes: " t t))
365 (search-forward "\n\n")
367 (insert mail-header-separator)
370 (narrow-to-region (point-min) (point))
371 (goto-char (point-min))
372 (and gnus-delete-supersedes-headers
373 (delete-matching-lines gnus-delete-supersedes-headers))
378 (defalias 'sendnews 'gnus-post-news)
381 (defalias 'postnews 'gnus-post-news)
383 (defun gnus-copy-article-buffer (&optional article-buffer)
384 ;; make a copy of the article buffer with all text properties removed
385 ;; this copy is in the buffer gnus-article-copy.
386 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
387 ;; this buffer should be passed to all mail/news reply/post routines.
388 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
389 (buffer-disable-undo gnus-article-copy)
390 (or (memq gnus-article-copy gnus-buffer-list)
391 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
392 (let ((article-buffer (or article-buffer gnus-article-buffer)))
393 (if (and (get-buffer article-buffer)
394 (buffer-name (get-buffer article-buffer)))
396 (set-buffer article-buffer)
398 (copy-to-buffer gnus-article-copy (point-min) (point-max))
399 (set-text-properties (point-min) (point-max)
400 nil gnus-article-copy)))))
402 (defun gnus-post-news (post &optional group header article-buffer yank subject)
403 "Begin editing a new USENET news article to be posted.
404 Type \\[describe-mode] in the buffer to get a list of commands."
405 (interactive (list t))
406 (gnus-copy-article-buffer article-buffer)
407 (if (or (not gnus-novice-user)
411 (format "%s" (car (gnus-find-method-for-group
412 gnus-newsgroup-name)))
413 gnus-valid-select-methods))))
416 (nth 5 (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))))
417 (gnus-y-or-n-p "Are you sure you want to post to all of USENET? "))
418 (let ((sumart (if (not post)
420 (set-buffer gnus-summary-buffer)
421 (cons (current-buffer) gnus-current-article))))
422 (from (and header (header-from header)))
423 (winconf (current-window-configuration))
425 (and gnus-interactive-post
426 (not gnus-expert-user)
430 (completing-read "Group: " gnus-active-hashtb))
432 (setq subject (read-string "Subject: ")))))
433 (setq mail-reply-buffer gnus-article-copy)
435 (let ((newsgroup-name (or group gnus-newsgroup-name "")))
436 (setq real-group (and group (gnus-group-real-name group)))
437 (setq gnus-post-news-buffer
438 (gnus-request-post-buffer
439 post real-group subject header gnus-article-copy
440 (nth 2 (and group (gnus-gethash group gnus-newsrc-hashtb)))
441 (or (cdr (assq 'to-group
442 (nth 5 (nth 2 (gnus-gethash
444 gnus-newsrc-hashtb)))))
445 (if (and (boundp 'gnus-followup-to-function)
446 gnus-followup-to-function
449 (set-buffer gnus-article-copy)
450 (funcall gnus-followup-to-function group))))
451 gnus-use-followup-to))
453 (gnus-configure-windows 'post)
455 (gnus-configure-windows 'followup-yank)
456 (gnus-configure-windows 'followup)))
457 (gnus-overload-functions)
458 (make-local-variable 'gnus-article-reply)
459 (make-local-variable 'gnus-article-check-size)
460 (make-local-variable 'gnus-reply-subject)
461 (setq gnus-reply-subject (and header (header-subject header)))
462 (setq gnus-article-reply sumart)
463 ;; Handle `gnus-auto-mail-to-author'.
464 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
465 (let ((to (and (not post)
466 (if (eq gnus-auto-mail-to-author 'ask)
467 (and (y-or-n-p "Also send mail to author? ") from)
468 (and gnus-auto-mail-to-author from)))))
471 (if (mail-fetch-field "To")
474 (insert "Cc: " to "\n"))
475 (mail-position-on-field "To")
477 ;; Handle author copy using BCC field.
478 (if (and gnus-mail-self-blind
479 (not (mail-fetch-field "bcc")))
481 (mail-position-on-field "Bcc")
482 (insert (if (stringp gnus-mail-self-blind)
484 (user-login-name)))))
485 ;; Handle author copy using FCC field.
488 (mail-position-on-field "Fcc")
489 (insert gnus-author-copy)))
490 (goto-char (point-min))
493 (re-search-forward "^Newsgroup:" nil t)
496 (re-search-forward "^Subject:" nil t)
500 (concat "^" (regexp-quote mail-header-separator) "$"))
503 (concat "^" (regexp-quote mail-header-separator) "$"))
508 (if (not (listp yank))
509 (news-reply-yank-original nil)
511 (save-window-excursion
512 (set-buffer gnus-summary-buffer)
513 (gnus-summary-select-article nil nil nil (car yank))
514 (gnus-summary-remove-process-mark (car yank)))
515 (let ((mail-reply-buffer gnus-article-copy))
516 (news-reply-yank-original nil))
517 (setq yank (cdr yank)))))))
518 (if gnus-post-prepare-function
519 (funcall gnus-post-prepare-function group))
520 (run-hooks 'gnus-post-prepare-hook)
521 (make-local-variable 'gnus-prev-winconf)
522 (setq gnus-prev-winconf winconf))))
523 (setq gnus-article-check-size (cons (buffer-size) (gnus-article-checksum)))
527 (defun gnus-inews-news (&optional use-group-method)
528 "Send a news message.
529 If given a prefix, and the group is a foreign group, this function
530 will attempt to use the foreign server to post the article."
532 (let* ((case-fold-search nil)
533 (server-running (gnus-server-opened gnus-select-method))
534 (reply gnus-article-reply)
537 ;; Connect to default NNTP server if necessary.
538 ;; Suggested by yuki@flab.fujitsu.junet.
539 (gnus-start-news-server) ;Use default server.
540 ;; NNTP server must be opened before current buffer is modified.
542 (goto-char (point-min))
543 (run-hooks 'news-inews-hook)
548 (goto-char (point-min))
550 (concat "^" (regexp-quote mail-header-separator) "$"))
551 (match-beginning 0)))
553 ;; Correct newsgroups field: change sequence of spaces to comma and
554 ;; eliminate spaces around commas. Eliminate imbedded line breaks.
555 (goto-char (point-min))
556 (if (search-forward-regexp "^Newsgroups: +" nil t)
560 (if (re-search-forward "^[^ \t]" nil 'end)
563 (goto-char (point-min))
564 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
565 (goto-char (point-min))
566 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ",")))
568 ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
569 ;; Help save the the world!
572 (let ((newsgroups (mail-fetch-field "newsgroups"))
573 (followup-to (mail-fetch-field "followup-to"))
575 (if (and (string-match "," newsgroups) (not followup-to))
577 (while (string-match "," newsgroups)
579 (cons (list (substring newsgroups
580 0 (match-beginning 0)))
582 (setq newsgroups (substring newsgroups (match-end 0))))
583 (setq groups (nreverse (cons (list newsgroups) groups)))
586 (completing-read "Followups to: (default all groups) "
588 (if (> (length to) 0)
590 (goto-char (point-min))
591 (insert "Followup-To: " to "\n")))))))
593 ;; Cleanup Followup-To.
594 (goto-char (point-min))
595 (if (search-forward-regexp "^Followup-To: +" nil t)
599 (if (re-search-forward "^[^ \t]" nil 'end)
602 (goto-char (point-min))
603 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
604 (goto-char (point-min))
605 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ",")))
607 ;; Mail the message too if To:, Bcc:. or Cc: exists.
608 (let* ((types '("to" "bcc" "cc"))
612 (or (mail-fetch-field (car ty) nil t)
613 (setq types (delete (car ty) types)))
617 ;; We do not want to send mail.
619 (if (not gnus-mail-send-method)
623 1 "No mailer defined. To: and/or Cc: fields ignored.")
626 ;; We want to remove Fcc, because we want to handle
627 ;; that one ourselves...
629 (goto-char (point-min))
630 (if (re-search-forward "^Fcc: " nil t)
634 (progn (beginning-of-line) (point))
635 (progn (forward-line 1) (point))))
639 ;; We generate a Message-ID so that the mail and the
640 ;; news copy of the message both get the same ID.
641 (or (mail-fetch-field "message-id")
643 (goto-char (point-max))
644 (insert "Message-ID: " (gnus-inews-message-id) "\n")))
648 (gnus-message 5 "Sending via mail...")
650 (if (and gnus-mail-courtesy-message
651 (or (member "to" types)
652 (member "cc" types)))
653 ;; We only want to insert the courtesy mail
654 ;; message if we use to or cc; bcc should not
655 ;; have one. Well, if both bcc and to are
656 ;; present, it will get one anyway.
658 ;; Insert "courtesy" mail message.
659 (goto-char (point-min))
661 (concat "^" (regexp-quote
662 mail-header-separator) "$"))
664 (insert gnus-mail-courtesy-message)
665 (funcall gnus-mail-send-method)
666 (goto-char (point-min))
667 (search-forward gnus-mail-courtesy-message)
668 (replace-match "" t t))
669 (funcall gnus-mail-send-method))
671 (gnus-message 5 "Sending via mail...done")
673 (goto-char (point-min))
677 (concat "^" (regexp-quote mail-header-separator) "$")))
678 (goto-char (point-min))
679 (delete-matching-lines "^BCC:"))
682 (goto-char (point-max))
683 (insert fcc-line))))))))
686 (gnus-message 5 "Posting to USENET...")
687 (if (funcall gnus-inews-article-function use-group-method)
689 (gnus-message 5 "Posting to USENET...done")
690 (if (gnus-buffer-exists-p (car-safe reply))
693 (set-buffer gnus-summary-buffer)
694 (gnus-summary-mark-article-as-replied
696 ;; We cannot signal an error.
698 (ding) (gnus-message 1 "Article rejected: %s"
699 (gnus-status-message gnus-select-method)))
700 (set-buffer-modified-p nil))
701 ;; If NNTP server is opened by gnus-inews-news, close it by myself.
703 (gnus-close-server (gnus-find-method-for-group gnus-newsgroup-name)))
704 (let ((conf gnus-prev-winconf))
708 ;; Restore last window configuration.
709 (and conf (set-window-configuration conf)))))))
711 (defun gnus-inews-check-post ()
712 "Check whether the post looks ok."
714 (not gnus-check-before-posting)
716 ;; We narrow to the headers and check them first.
719 (goto-char (point-min))
723 (concat "^" (regexp-quote mail-header-separator) "$")))
724 (goto-char (point-min))
726 ;; Check for commands in Subject.
727 (or (gnus-check-before-posting 'subject-cmsg)
729 (if (string-match "^cmsg " (mail-fetch-field "subject"))
731 "The control code \"cmsg \" is in the subject. Really post? ")
733 ;; Check for multiple identical headers.
734 (or (gnus-check-before-posting 'multiple-headers)
737 (while (and (not found) (re-search-forward "^[^ \t:]+: " nil t))
739 (or (re-search-forward
740 (concat "^" (setq found
743 (- (match-end 0) 2))))
748 (format "Multiple %s headers. Really post? " found))
750 ;; Check for version and sendsys.
751 (or (gnus-check-before-posting 'sendsys)
753 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
755 (format "The article contains a %s command. Really post? "
756 (buffer-substring (match-beginning 0)
757 (1- (match-end 0)))))
759 ;; Check the Message-Id header.
760 (or (gnus-check-before-posting 'message-id)
762 (let* ((case-fold-search t)
763 (message-id (mail-fetch-field "message-id")))
765 (and (string-match "@" message-id)
766 (string-match "@[^\\.]*\\." message-id))
769 "The Message-ID looks strange: \"%s\". Really post? "
771 ;; Check the From header.
772 (or (gnus-check-before-posting 'from)
774 (let* ((case-fold-search t)
775 (from (mail-fetch-field "from")))
778 (gnus-yes-or-no-p "There is no From line. Really post? "))
779 ((not (string-match "@[^\\.]*\\." from))
782 "The address looks strange: \"%s\". Really post? " from)))
783 ((string-match "(.*).*(.*)")
786 "The From header looks strange: \"%s\". Really post? "
789 ;; Check for long lines.
790 (or (gnus-check-before-posting 'long-lines)
792 (goto-char (point-min))
794 (concat "^" (regexp-quote mail-header-separator) "$"))
798 (< (current-column) 80))
799 (zerop (forward-line 1))))
804 "You have lines longer than 79 characters. Really post? ")))))
805 ;; Check for control characters.
806 (or (gnus-check-before-posting 'control-chars)
808 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
810 "The article contains control characters. Really post? ")
812 ;; Check excessive size.
813 (or (gnus-check-before-posting 'size)
814 (if (> (buffer-size) 60000)
816 (format "The article is %d octets long. Really post? "
819 ;; Use the (size . checksum) variable to see whether the
820 ;; article is empty or has only quoted text.
821 (or (gnus-check-before-posting 'new-text)
822 (if (and (= (buffer-size) (car gnus-article-check-size))
823 (= (gnus-article-checksum) (cdr gnus-article-check-size)))
825 "It looks like there's no new text in your article. Really post? ")
827 ;; Check the length of the signature.
828 (or (gnus-check-before-posting 'signature)
830 (goto-char (point-max))
831 (if (not (re-search-backward gnus-signature-separator nil t))
833 (if (> (count-lines (point) (point-max)) 4)
836 "Your .sig is %d lines; it should be max 4. Really post? "))
839 (defun gnus-article-checksum ()
843 (setq sum (logxor sum (following-char)))
847 ;; Returns non-nil if this type is not to be checked.
848 (defun gnus-check-before-posting (type)
849 (or (not gnus-check-before-posting)
850 (if (listp gnus-check-before-posting)
851 (memq type gnus-check-before-posting)
854 (defun gnus-cancel-news ()
855 "Cancel an article you posted."
857 (if (or gnus-expert-user
858 (gnus-yes-or-no-p "Do you really want to cancel this article? "))
863 (or (gnus-member-of-valid 'post gnus-newsgroup-name)
864 (error "This backend does not support canceling"))
866 ;; Get header info. from original article.
868 (gnus-article-show-all-headers)
869 (goto-char (point-min))
870 (search-forward "\n\n" nil 'move)
871 (narrow-to-region (point-min) (point))
872 (setq from (mail-fetch-field "from"))
873 (setq newsgroups (mail-fetch-field "newsgroups"))
874 (setq message-id (mail-fetch-field "message-id"))
875 (setq distribution (mail-fetch-field "distribution")))
876 ;; Verify if the article is absolutely user's by comparing
877 ;; user id with value of its From: field.
880 (downcase (mail-strip-quoted-names from))
881 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
883 (ding) (gnus-message 3 "This article is not yours.")
885 ;; Make control article.
886 (set-buffer (get-buffer-create " *Gnus-canceling*"))
887 (buffer-disable-undo (current-buffer))
889 (insert "Newsgroups: " newsgroups "\n"
890 "Subject: cancel " message-id "\n"
891 "Control: cancel " message-id "\n"
893 (concat "Distribution: " distribution "\n")
895 mail-header-separator "\n"
896 "This is a cancel message from " from ".\n")
897 ;; Send the control article to NNTP server.
898 (gnus-message 5 "Canceling your article...")
900 (if (funcall gnus-inews-article-function)
901 (gnus-message 5 "Canceling your article...done")
904 (gnus-message 1 "Cancel failed; %s"
905 (gnus-status-message gnus-newsgroup-name))
908 ;; Kill the article buffer.
909 (kill-buffer (current-buffer))))))))
912 ;;; Lowlevel inews interface
914 (defun gnus-inews-article (&optional use-group-method)
915 "Post an article in current buffer using NNTP protocol."
916 (let ((artbuf (current-buffer))
917 (tmpbuf (get-buffer-create " *Gnus-posting*")))
919 (goto-char (point-max))
920 ;; require a newline at the end for inews to append .signature to
921 (or (= (preceding-char) ?\n)
923 ;; Prepare article headers. All message body such as signature
924 ;; must be inserted before Lines: field is prepared.
926 (goto-char (point-min))
931 (concat "^" (regexp-quote mail-header-separator) "$"))
932 (match-beginning 0)))
933 (gnus-inews-remove-headers)
934 (gnus-inews-insert-headers)
935 (run-hooks gnus-inews-article-header-hook)
937 ;; Check whether the article is a good Net Citizen.
938 (if (and gnus-article-check-size
939 (not (gnus-inews-check-post)))
942 ;; Looks ok, so we do the nasty.
945 (buffer-disable-undo (current-buffer))
947 (insert-buffer-substring artbuf)
948 ;; Remove the header separator.
949 (goto-char (point-min))
951 (concat "^" (regexp-quote mail-header-separator) "$"))
952 (replace-match "" t t)
953 ;; This hook may insert a signature.
954 (run-hooks 'gnus-prepare-article-hook)
955 ;; Run final inews hooks. This hook may do FCC.
956 ;; The article must be saved before being posted because
957 ;; `gnus-request-post' modifies the buffer.
958 (run-hooks 'gnus-inews-article-hook)
959 ;; Post an article to NNTP server.
960 ;; Return NIL if post failed.
964 (gnus-find-method-for-group gnus-newsgroup-name)
965 gnus-select-method) use-group-method)
966 (kill-buffer (current-buffer)))))))
968 (defun gnus-inews-remove-headers ()
969 (let ((case-fold-search t))
970 ;; Remove NNTP-posting-host.
971 (goto-char (point-min))
972 (and (re-search-forward "^nntp-posting-host:" nil t)
973 (delete-region (progn (beginning-of-line) (point))
974 (progn (forward-line 1) (point))))
976 (goto-char (point-min))
977 (and (re-search-forward "^bcc:" nil t)
978 (delete-region (progn (beginning-of-line) (point))
979 (progn (forward-line 1) (point))))))
981 (defun gnus-inews-insert-headers ()
982 "Prepare article headers.
983 Headers already prepared in the buffer are not modified.
984 Headers in `gnus-required-headers' will be generated."
985 (let ((Date (gnus-inews-date))
986 (Message-ID (gnus-inews-message-id))
987 (Organization (gnus-inews-organization))
988 (From (gnus-inews-user-name))
989 (Path (gnus-inews-path))
993 (Lines (gnus-inews-lines))
994 (X-Newsreader gnus-version)
995 (headers gnus-required-headers)
998 ;; First we remove any old generated headers.
999 (let ((headers gnus-deletable-headers))
1001 (goto-char (point-min))
1002 (and (re-search-forward
1003 (concat "^" (symbol-name (car headers)) ": *") nil t)
1004 (get-text-property (1+ (match-beginning 0)) 'gnus-deletable)
1006 (setq headers (cdr headers))))
1007 ;; Insert new Sender if the From is strange.
1008 (let ((from (mail-fetch-field "from")))
1009 (if (and from (not (string= (downcase from) (downcase From))))
1011 (goto-char (point-min))
1012 (and (re-search-forward "^Sender:" nil t)
1013 (delete-region (progn (beginning-of-line) (point))
1014 (progn (forward-line 1) (point))))
1015 (insert "Sender: " From "\n"))))
1016 ;; If there are References, and no "Re: ", then the thread has
1017 ;; changed name. See Son-of-1036.
1018 (if (and (mail-fetch-field "references")
1019 (get-buffer gnus-article-buffer))
1020 (let ((psubject (gnus-simplify-subject-re
1021 (mail-fetch-field "subject"))))
1022 (or (and psubject gnus-reply-subject
1023 (string= (gnus-simplify-subject-re gnus-reply-subject)
1026 (string-match "@" Message-ID)
1028 (concat (substring Message-ID 0 (match-beginning 0))
1030 (substring Message-ID (match-beginning 0))))))))
1031 ;; Go through all the required headers and see if they are in the
1032 ;; articles already. If they are not, or are empty, they are
1033 ;; inserted automatically - except for Subject, Newsgroups and
1036 (goto-char (point-min))
1037 (setq elem (car headers))
1039 (setq header (car elem))
1041 (if (or (not (re-search-forward
1042 (concat "^" (downcase (symbol-name header)) ":") nil t))
1044 (if (= (following-char) ? ) (forward-char 1) (insert " "))
1045 (looking-at "[ \t]*$")))
1048 (or (if (consp elem)
1049 ;; The element is a cons. Either the cdr is
1050 ;; a string to be inserted verbatim, or it
1051 ;; is a function, and we insert the value
1052 ;; returned from this function.
1053 (or (and (stringp (cdr elem)) (cdr elem))
1054 (and (fboundp (cdr elem)) (funcall (cdr elem))))
1055 ;; The element is a symbol. We insert the
1056 ;; value of this symbol, if any.
1057 (and (boundp header) (symbol-value header)))
1058 ;; We couldn't generate a value for this header,
1059 ;; so we just ask the user.
1060 (read-from-minibuffer
1061 (format "Empty header for %s; enter value: " header))))
1062 ;; Finally insert the header.
1066 (goto-char (point-max))
1067 (insert (symbol-name header) ": " value "\n")
1069 (replace-match value t t))
1070 ;; Add the deletable property to the headers that require it.
1071 (and (memq header gnus-deletable-headers)
1072 (progn (beginning-of-line) (looking-at "[^:]+: "))
1073 (add-text-properties
1074 (point) (match-end 0)
1075 '(gnus-deletable t face italic) (current-buffer))))))
1076 (setq headers (cdr headers)))))
1078 (defun gnus-inews-insert-signature ()
1079 "Insert a signature file.
1080 If `gnus-signature-function' is bound and returns a string, this
1081 string is used instead of the variable `gnus-signature-file'.
1082 In either case, if the string is a file name, this file is
1083 inserted. If the string is not a file name, the string itself is
1085 If you never want any signature inserted, set both those variables to
1089 (or (and gnus-signature-function
1090 (funcall gnus-signature-function gnus-newsgroup-name))
1091 gnus-signature-file)))
1093 (or (file-exists-p signature)
1094 (string-match " " signature)
1096 "^/[^/]+/" (expand-file-name signature)))))
1098 (goto-char (point-max))
1099 (if (and mail-signature (search-backward "\n-- \n" nil t))
1101 ;; Delete any previous signatures.
1102 (if (search-backward "\n-- \n" nil t)
1103 (delete-region (1+ (point)) (point-max)))
1105 (if (file-exists-p signature)
1106 (insert-file-contents signature)
1108 (goto-char (point-max))
1109 (or (bolp) (insert "\n"))))))))
1111 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1112 (defun gnus-inews-insert-mime-headers ()
1113 (let ((mail-header-separator ""))
1114 (or (mail-position-on-field "Mime-Version")
1116 (cond ((save-excursion
1117 (beginning-of-buffer)
1118 (re-search-forward "[\200-\377]" nil t))
1119 (or (mail-position-on-field "Content-Type")
1120 (insert "text/plain; charset=ISO-8859-1"))
1121 (or (mail-position-on-field "Content-Transfer-Encoding")
1123 (t (or (mail-position-on-field "Content-Type")
1124 (insert "text/plain; charset=US-ASCII"))
1125 (or (mail-position-on-field "Content-Transfer-Encoding")
1126 (insert "7bit")))))))
1128 (defun gnus-inews-do-fcc ()
1129 "Process FCC: fields in current article buffer.
1130 Unless the first character of the field is `|', the article is saved
1131 to the specified file using the function specified by the variable
1132 gnus-author-copy-saver. The default function rmail-output saves in
1133 Unix mailbox format.
1134 If the first character is `|', the contents of the article is send to
1135 a program specified by the rest of the value."
1136 (let ((fcc-list nil)
1138 (case-fold-search t)) ;Should ignore case.
1141 (goto-char (point-min))
1142 (search-forward "\n\n")
1143 (narrow-to-region (point-min) (point))
1144 (goto-char (point-min))
1145 (while (re-search-forward "^FCC:[ \t]*" nil t)
1147 (cons (buffer-substring
1151 (skip-chars-backward " \t")
1154 (delete-region (match-beginning 0)
1155 (progn (forward-line 1) (point))))
1156 ;; Process FCC operations.
1159 (setq fcc-file (car fcc-list))
1160 (setq fcc-list (cdr fcc-list))
1161 (cond ((string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" fcc-file)
1162 (let ((program (substring fcc-file
1163 (match-beginning 1) (match-end 1))))
1164 ;; Suggested by yuki@flab.fujitsu.junet.
1165 ;; Send article to named program.
1166 (call-process-region (point-min) (point-max) shell-file-name
1167 nil nil nil "-c" program)))
1169 ;; Suggested by hyoko@flab.fujitsu.junet.
1170 ;; Save article in Unix mail format by default.
1171 (gnus-make-directory (file-name-directory fcc-file))
1172 (if (and gnus-author-copy-saver
1173 (not (eq gnus-author-copy-saver 'rmail-output)))
1174 (funcall gnus-author-copy-saver fcc-file)
1175 (if (and (file-readable-p fcc-file) (rmail-file-p fcc-file))
1176 (gnus-output-to-rmail fcc-file)
1177 (rmail-output fcc-file 1 t t))))))))))
1179 (defun gnus-inews-path ()
1181 (let ((login-name (gnus-inews-login-name)))
1182 (cond ((null gnus-use-generic-path)
1183 (concat (nth 1 gnus-select-method) "!" login-name))
1184 ((stringp gnus-use-generic-path)
1185 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1186 (concat gnus-use-generic-path "!" login-name))
1189 (defun gnus-inews-user-name ()
1190 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1191 (let ((full-name (gnus-inews-full-name)))
1192 (or gnus-user-from-line
1193 (concat (if (or gnus-user-login-name gnus-use-generic-from
1194 gnus-local-domain (getenv "DOMAINNAME"))
1195 (concat (gnus-inews-login-name) "@"
1196 (gnus-inews-domain-name gnus-use-generic-from))
1198 ;; User's full name.
1199 (cond ((string-equal full-name "") "")
1200 ((string-equal full-name "&") ;Unix hack.
1201 (concat " (" (user-login-name) ")"))
1203 (concat " (" full-name ")")))))))
1205 (defun gnus-inews-login-name ()
1206 "Return login name."
1207 (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1209 (defun gnus-inews-full-name ()
1210 "Return full user name."
1211 (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1213 (defun gnus-inews-domain-name (&optional genericfrom)
1214 "Return user's domain name.
1215 If optional argument GENERICFROM is a string, use it as the domain
1216 name; if it is non-nil, strip off local host name from the domain name.
1217 If the function `system-name' returns full internet name and the
1218 domain is undefined, the domain name is got from it."
1219 (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1220 (let* ((system-name (system-name))
1222 (or (if (stringp genericfrom) genericfrom)
1223 (getenv "DOMAINNAME")
1225 ;; Function `system-name' may return full internet name.
1226 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1227 (if (string-match "\\." system-name)
1228 (substring system-name (match-end 0)))
1229 (read-string "Domain name (no host): ")))
1230 (host (or (if (string-match "\\." system-name)
1231 (substring system-name 0 (match-beginning 0)))
1233 (if (string-equal "." (substring domain 0 1))
1234 (setq domain (substring domain 1)))
1235 ;; Support GENERICFROM as same as standard Bnews system.
1236 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1237 (cond ((null genericfrom)
1238 (concat host "." domain))
1239 ;;((stringp genericfrom) genericfrom)
1241 (if (string-match "\\." (system-name))
1243 (substring user-mail-address
1244 (1+ (string-match "@" user-mail-address))))))
1246 (defun gnus-inews-full-address ()
1247 (let ((domain (gnus-inews-domain-name))
1248 (system (system-name))
1249 (case-fold-search t))
1250 (if (string-match "\\." system) system
1251 (if (string-match (concat "^" (regexp-quote system)) domain) domain
1252 (concat system "." domain)))))
1254 (defun gnus-inews-message-id ()
1255 "Generate unique Message-ID for user."
1256 ;; Message-ID should not contain a slash and should be terminated by
1257 ;; a number. I don't know the reason why it is so.
1258 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1260 (defvar gnus-unique-id-char nil)
1262 ;; If you ever change this function, make sure the new version
1263 ;; cannot generate IDs that the old version could.
1264 ;; You might for example insert a "." somewhere (not next to another dot
1265 ;; or string boundary), or modify the newsreader name to "Ding".
1266 (defun gnus-inews-unique-id ()
1267 ;; Dont use microseconds from (current-time), they may be unsupported.
1268 ;; Instead we use this randomly inited counter.
1269 (setq gnus-unique-id-char
1270 (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1271 ;; (current-time) returns 16-bit ints,
1272 ;; and 2^16*25 just fits into 4 digits i base 36.
1274 (let ((tm (if (fboundp 'current-time)
1275 (current-time) '(12191 46742 287898))))
1277 (if (memq system-type '(ms-dos emx vax-vms))
1278 (let ((user (downcase (gnus-inews-login-name))))
1279 (while (string-match "[^a-z0-9_]" user)
1280 (aset user (match-beginning 0) ?_))
1282 (gnus-number-base36 (user-uid) -1))
1283 (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1284 (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1285 ;; Append the newsreader name, because while the generated
1286 ;; ID is unique to this newsreader, other newsreaders might
1287 ;; otherwise generate the same ID via another algorithm.
1291 (defun gnus-inews-date ()
1292 "Current time string."
1293 (timezone-make-date-arpa-standard
1294 (current-time-string) (current-time-zone)))
1296 (defun gnus-inews-organization ()
1297 "Return user's organization.
1298 The ORGANIZATION environment variable is used if defined.
1299 If not, the variable `gnus-local-organization' is used instead.
1300 If it is a function, the function will be called with the current
1301 newsgroup name as the argument.
1302 If this is a file name, the contents of this file will be used as the
1304 (let* ((organization
1305 (or (getenv "ORGANIZATION")
1306 (if gnus-local-organization
1307 (if (and (symbolp gnus-local-organization)
1308 (fboundp gnus-local-organization))
1309 (funcall gnus-local-organization gnus-newsgroup-name)
1310 gnus-local-organization))
1311 gnus-organization-file
1312 "~/.organization")))
1313 (and (stringp organization)
1314 (> (length organization) 0)
1315 (or (file-exists-p organization)
1316 (string-match " " organization)
1317 (not (string-match "^/usr/lib/" organization)))
1319 (gnus-set-work-buffer)
1320 (if (file-exists-p organization)
1321 (insert-file-contents organization)
1322 (insert organization))
1323 (goto-char (point-min))
1324 (while (re-search-forward " *\n *" nil t)
1325 (replace-match " " t t))
1326 (buffer-substring (point-min) (point-max))))))
1328 (defun gnus-inews-lines ()
1329 "Count the number of lines and return numeric string."
1333 (goto-char (point-min))
1335 (concat "^" (regexp-quote mail-header-separator) "$"))
1337 (int-to-string (count-lines (point) (point-max))))))
1341 ;;; Gnus Mail Functions
1344 ;;; Mail reply commands of Gnus summary mode
1346 (defun gnus-summary-reply (yank &optional yank-articles)
1347 "Reply mail to news author.
1348 If prefix argument YANK is non-nil, original article is yanked automatically.
1349 Customize the variable gnus-mail-reply-method to use another mailer."
1351 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1352 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1353 (gnus-set-global-variables)
1354 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1355 (gnus-summary-select-article)
1356 (let ((gnus-newsgroup-name gnus-newsgroup-name))
1357 (bury-buffer gnus-article-buffer)
1358 (funcall gnus-mail-reply-method (or yank-articles (not (not yank))))))
1360 (defun gnus-summary-reply-with-original (n)
1361 "Reply mail to news author with original article.
1362 Customize the variable gnus-mail-reply-method to use another mailer."
1364 (gnus-summary-reply t (gnus-summary-work-articles n)))
1366 (defun gnus-summary-mail-forward (post)
1367 "Forward the current message to another user.
1368 Customize the variable gnus-mail-forward-method to use another mailer."
1370 (gnus-set-global-variables)
1371 (gnus-summary-select-article)
1372 (gnus-copy-article-buffer)
1373 (let ((gnus-newsgroup-name gnus-newsgroup-name))
1375 (gnus-forward-using-post gnus-article-copy)
1376 (funcall gnus-mail-forward-method gnus-article-copy))))
1378 (defun gnus-summary-post-forward ()
1379 "Forward the current article to a newsgroup."
1381 (gnus-summary-mail-forward t))
1383 (defvar gnus-nastygram-message
1384 "The following article was inappropriately posted to %s.\n"
1385 "Format string to insert in nastygrams.
1386 The current group name will be inserted at \"%s\".")
1388 (defun gnus-summary-mail-nastygram (n)
1389 "Send a nastygram to the author of the current article."
1391 (if (or gnus-expert-user
1393 "Really send a nastygram to the author of the current article? "))
1394 (let ((group gnus-newsgroup-name))
1395 (gnus-summary-reply-with-original n)
1396 (set-buffer gnus-mail-buffer)
1397 (insert (format gnus-nastygram-message group))
1398 (gnus-mail-send-and-exit))))
1400 (defun gnus-summary-mail-other-window ()
1401 "Compose mail in other window.
1402 Customize the variable `gnus-mail-other-window-method' to use another
1405 (gnus-set-global-variables)
1406 (let ((gnus-newsgroup-name gnus-newsgroup-name))
1407 (funcall gnus-mail-other-window-method)))
1409 (defun gnus-mail-reply-using-mail (&optional yank to-address)
1411 (set-buffer gnus-summary-buffer)
1412 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1413 (cur (cons (current-buffer) (cdr gnus-article-current)))
1414 (winconf (current-window-configuration))
1415 from subject date reply-to message-of
1416 references message-id sender follow-to sendto elt)
1417 (set-buffer (get-buffer-create gnus-mail-buffer))
1419 (make-local-variable 'gnus-article-reply)
1420 (setq gnus-article-reply cur)
1421 (make-local-variable 'gnus-prev-winconf)
1422 (setq gnus-prev-winconf winconf)
1423 (if (and (buffer-modified-p)
1426 "Unsent article being composed; erase it? ")))
1430 (gnus-copy-article-buffer)
1432 (set-buffer gnus-article-copy)
1433 (gnus-narrow-to-headers)
1434 (if (and (boundp 'gnus-reply-to-function)
1435 gnus-reply-to-function)
1436 (setq follow-to (funcall gnus-reply-to-function group)))
1437 (setq from (mail-fetch-field "from"))
1438 (setq date (or (mail-fetch-field "date")
1439 (header-date gnus-current-headers)))
1442 (string-match " *at \\| *@ \\| *(\\| *<" from)))
1444 (concat (if stop-pos (substring from 0 stop-pos) from)
1445 "'s message of " date))))
1446 (setq sender (mail-fetch-field "sender"))
1447 (setq subject (or (mail-fetch-field "subject")
1449 (or (string-match "^[Rr][Ee]:" subject)
1450 (setq subject (concat "Re: " subject)))
1451 (setq reply-to (mail-fetch-field "reply-to"))
1452 (setq references (mail-fetch-field "references"))
1453 (setq message-id (mail-fetch-field "message-id"))
1455 (setq news-reply-yank-from (or from "(nobody)")))
1456 (setq news-reply-yank-message-id
1457 (or message-id "(unknown Message-ID)"))
1459 ;; Gather the "to" addresses out of the follow-to list and remove
1461 (if (and follow-to (listp follow-to))
1462 (while (setq elt (assoc "To" follow-to))
1463 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1464 (setq follow-to (delq elt follow-to))))
1466 (mail-setup (or to-address
1467 (if (and follow-to (not (stringp follow-to))) sendto
1468 (or follow-to reply-to from sender "")))
1469 subject message-of nil gnus-article-copy nil)
1471 (use-local-map (copy-keymap mail-mode-map))
1472 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1474 (if (and follow-to (listp follow-to))
1476 (goto-char (point-min))
1477 (re-search-forward "^To:" nil t)
1481 (insert (car (car follow-to)) ": " (cdr (car follow-to)) "\n")
1482 (setq follow-to (cdr follow-to)))))
1483 ;; Fold long references line to follow RFC1036.
1484 (mail-position-on-field "References")
1485 (let ((begin (- (point) (length "References: ")))
1488 (if references (insert references))
1489 (if (and references message-id) (insert " "))
1490 (if message-id (insert message-id))
1491 ;; The region must end with a newline to fill the region
1492 ;; without inserting extra newline.
1493 (fill-region-as-paragraph begin (1+ (point))))
1494 (goto-char (point-min))
1496 (concat "^" (regexp-quote mail-header-separator) "$"))
1499 (gnus-configure-windows 'reply)
1500 (let ((last (point))
1502 (if (not (listp yank))
1505 (mail-yank-original nil))
1506 (or mail-yank-hooks mail-citation-hook
1507 (run-hooks 'news-reply-header-hook)))
1509 (save-window-excursion
1510 (set-buffer gnus-summary-buffer)
1511 (gnus-summary-select-article nil nil nil (car yank))
1512 (gnus-summary-remove-process-mark (car yank)))
1514 (gnus-copy-article-buffer)
1515 (mail-yank-original nil)
1517 (or mail-yank-hooks mail-citation-hook
1518 (run-hooks 'news-reply-header-hook))
1520 (setq yank (cdr yank))))
1522 (gnus-configure-windows 'reply-yank))
1523 (run-hooks 'gnus-mail-hook)))))
1525 (defun gnus-mail-yank-original ()
1528 (mail-yank-original nil))
1529 (or mail-yank-hooks mail-citation-hook
1530 (run-hooks 'news-reply-header-hook)))
1532 (defun gnus-mail-send-and-exit ()
1534 (let ((reply gnus-article-reply)
1535 (winconf gnus-prev-winconf))
1536 (mail-send-and-exit nil)
1537 (if (get-buffer gnus-group-buffer)
1539 (if (gnus-buffer-exists-p (car-safe reply))
1541 (set-buffer (car reply))
1543 (gnus-summary-mark-article-as-replied
1545 (and winconf (set-window-configuration winconf))))))
1547 (defun gnus-forward-make-subject (buffer)
1550 (concat "[" (if (memq 'mail (assoc (symbol-name
1551 (car (gnus-find-method-for-group
1552 gnus-newsgroup-name)))
1553 gnus-valid-select-methods))
1554 (gnus-fetch-field "From")
1555 gnus-newsgroup-name)
1556 "] " (or (gnus-fetch-field "Subject") ""))))
1558 (defun gnus-forward-insert-buffer (buffer)
1559 (let ((beg (goto-char (point-max))))
1560 (insert "------- Start of forwarded message -------\n")
1561 (insert-buffer buffer)
1562 (goto-char (point-max))
1563 (insert "------- End of forwarded message -------\n")
1564 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
1566 (while (setq beg (next-single-property-change (point) 'invisible))
1568 (delete-region beg (or (next-single-property-change
1572 (defun gnus-mail-forward-using-mail (&optional buffer)
1573 "Forward the current message to another user using mail."
1574 ;; This is almost a carbon copy of rmail-forward in rmail.el.
1575 (let* ((forward-buffer (or buffer (current-buffer)))
1576 (winconf (current-window-configuration))
1577 (subject (gnus-forward-make-subject forward-buffer)))
1578 (set-buffer forward-buffer)
1579 (mail nil nil subject)
1580 (use-local-map (copy-keymap (current-local-map)))
1581 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1582 (make-local-variable 'gnus-prev-winconf)
1583 (setq gnus-prev-winconf winconf)
1584 (gnus-forward-insert-buffer forward-buffer)
1585 (goto-char (point-min))
1586 (re-search-forward "^To: " nil t)
1587 (gnus-configure-windows 'mail-forward)
1588 ;; You have a chance to arrange the message.
1589 (run-hooks 'gnus-mail-forward-hook)
1590 (run-hooks 'gnus-mail-hook)))
1592 (defun gnus-forward-using-post (&optional buffer)
1593 (let* ((forward-buffer (or buffer (current-buffer)))
1594 (subject (gnus-forward-make-subject forward-buffer)))
1595 (gnus-post-news 'post nil nil nil nil subject)
1597 (gnus-forward-insert-buffer forward-buffer)
1598 ;; You have a chance to arrange the message.
1599 (run-hooks 'gnus-mail-forward-hook))))
1601 (defun gnus-mail-other-window-using-mail ()
1602 "Compose mail other window using mail."
1603 (let ((winconf (current-window-configuration)))
1604 (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
1605 (use-local-map (copy-keymap (current-local-map)))
1606 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1607 (make-local-variable 'gnus-prev-winconf)
1608 (setq gnus-prev-winconf winconf)
1609 (run-hooks 'gnus-mail-hook)))
1611 (defun gnus-article-mail (yank)
1612 "Send a reply to the address near point.
1613 If YANK is non-nil, include the original article."
1617 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1618 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1621 (switch-to-buffer gnus-summary-buffer)
1622 (funcall gnus-mail-reply-method yank address)))))
1624 (defun gnus-article-mail-with-original ()
1625 "Send a reply to the address near point and include the original article."
1627 (gnus-article-mail 'yank))
1630 "Send a bug report to the Gnus maintainers."
1632 (let ((winconf (current-window-configuration)))
1633 (delete-other-windows)
1634 (switch-to-buffer "*Gnus Help Bug*")
1636 (insert gnus-bug-message)
1637 (goto-char (point-min))
1638 (pop-to-buffer "*Gnus Bug*")
1641 (mail-setup gnus-maintainer nil nil nil nil nil)
1642 (make-local-variable 'gnus-prev-winconf)
1643 (setq gnus-prev-winconf winconf)
1644 (use-local-map (copy-keymap mail-mode-map))
1645 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1646 (goto-char (point-min))
1647 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1649 (insert (format "%s\n%s\n\n\n\n\n" (gnus-version) (emacs-version)))
1652 (goto-char (- b 3)))
1655 (defun gnus-debug ()
1656 "Attemps to go through the Gnus source file and report what variables have been changed.
1657 The source file has to be in the Emacs load path."
1659 (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el"))
1660 file dirs expr olist)
1661 (message "Please wait while we snoop your variables...")
1664 (set-buffer (get-buffer-create " *gnus bug info*"))
1665 (buffer-disable-undo (current-buffer))
1668 (setq dirs load-path)
1670 (if (or (not (car dirs))
1671 (not (stringp (car dirs)))
1673 (setq file (concat (file-name-as-directory
1674 (car dirs)) (car files))))))
1675 (setq dirs (cdr dirs))
1677 (insert-file-contents file)
1678 (goto-char (point-min))
1679 (or (re-search-forward "^;;* *Internal variables" nil t)
1680 (error "Malformed sources in file %s" file))
1681 (narrow-to-region (point-min) (point))
1682 (goto-char (point-min))
1683 (while (setq expr (condition-case ()
1684 (read (current-buffer)) (error nil)))
1685 (and (eq (car expr) 'defvar)
1686 (stringp (nth 3 expr))
1687 (or (not (boundp (nth 1 expr)))
1688 (not (equal (eval (nth 2 expr))
1689 (symbol-value (nth 1 expr)))))
1690 (setq olist (cons (nth 1 expr) olist))))))
1691 (setq files (cdr files)))
1692 (kill-buffer (current-buffer)))
1693 (insert "------------------- Environment follows -------------------\n\n")
1695 (if (boundp (car olist))
1696 (insert "(setq " (symbol-name (car olist)) " '"
1697 (prin1-to-string (symbol-value (car olist))) ")\n")
1698 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1699 (setq olist (cdr olist)))
1706 ;;; gnus-msg.el ends here