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 t
49 "*Specifies what to do with Followup-To header.
50 If nil, ignore the header. If it is t, use its value, but ignore
51 `poster'. If it is the symbol `ask', query the user before posting.
52 If it is the symbol `use', always use the value.")
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 Date)
154 "*Headers to be deleted if they already exists and were generated by Gnus previously.")
156 (defvar gnus-removable-headers '(NNTP-Posting-Host Bcc Xref)
157 "*Headers to be removed unconditionally before posting.")
159 (defvar gnus-check-before-posting
160 '(subject-cmsg multiple-headers sendsys message-id from
161 long-lines control-chars size new-text
163 "In non-nil, Gnus will attempt to run some checks on outgoing posts.
164 If this variable is t, Gnus will check everything it can. If it is a
165 list, then those elements in that list will be checked.")
167 (defvar gnus-delete-supersedes-headers
168 "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Supersedes:"
169 "*Header lines matching this regexp will be deleted before posting.
170 It's best to delete old Path and Date headers before psoting to avoid
173 (defvar gnus-auto-mail-to-author nil
174 "*If non-nil, mail the authors of articles a copy of your follow-ups.
175 If this variable is `ask', the user will be prompted for whether to
176 mail a copy. The string given by `gnus-mail-courtesy-message' will be
177 inserted at the beginning of the mail copy.
179 Mail is sent using the function specified by the
180 `gnus-mail-send-method' variable.")
182 ;; Added by Ethan Bradford <ethanb@ptolemy.astro.washington.edu>.
183 (defvar gnus-mail-courtesy-message
184 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
185 "*This is inserted at the start of a mailed copy of a posted message.
186 If this variable is nil, no such courtesy message will be added.")
188 (defvar gnus-mail-reply-method (function gnus-mail-reply-using-mail)
189 "*Function to compose a reply.
190 Three pre-made functions are `gnus-mail-reply-using-mail' (sendmail);
191 `gnus-mail-reply-using-mhe' (MH-E); and `gnus-mail-reply-using-vm'.")
193 (defvar gnus-mail-forward-method (function gnus-mail-forward-using-mail)
194 "*Function to forward the current message to another user.
195 Three pre-made functions are `gnus-mail-forward-using-mail' (sendmail);
196 `gnus-mail-forward-using-mhe' (MH-E); and `gnus-mail-forward-using-vm'.")
198 (defvar gnus-mail-other-window-method 'gnus-mail-other-window-using-mail
199 "*Function to compose mail in the other window.
200 Three pre-made functions are `gnus-mail-other-window-using-mail'
201 (sendmail); `gnus-mail-other-window-using-mhe' (MH-E); and
202 `gnus-mail-other-window-using-vm'.")
204 (defvar gnus-mail-send-method send-mail-function
205 "*Function to mail a message which is also being posted as an article.
206 The message must have To or Cc header. The default is copied from
207 the variable `send-mail-function'.")
209 (defvar gnus-inews-article-function 'gnus-inews-article
210 "*Function to post an article.")
212 (defvar gnus-inews-article-hook (list 'gnus-inews-do-fcc)
213 "*A hook called before finally posting an article.
214 The default hook (`gnus-inews-do-fcc') does FCC processing (ie. saves
215 the article to a file).")
217 (defvar gnus-inews-article-header-hook nil
218 "*A hook called after inserting the headers in an article to be posted.
219 The hook is called from the *post-news* buffer, narrowed to the
222 (defvar gnus-mail-hook nil
223 "*A hook called as the last thing after setting up a mail buffer.")
225 ;;; Internal variables.
227 (defvar gnus-post-news-buffer "*post-news*")
228 (defvar gnus-mail-buffer "*mail*")
229 (defvar gnus-summary-send-map nil)
230 (defvar gnus-article-copy nil)
231 (defvar gnus-reply-subject nil)
234 (autoload 'gnus-uu-post-news "gnus-uu" nil t))
238 ;;; Gnus Posting Functions
241 (define-prefix-command 'gnus-summary-send-map)
242 (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
243 (define-key gnus-summary-send-map "p" 'gnus-summary-post-news)
244 (define-key gnus-summary-send-map "f" 'gnus-summary-followup)
245 (define-key gnus-summary-send-map "F" 'gnus-summary-followup-with-original)
246 (define-key gnus-summary-send-map "b" 'gnus-summary-followup-and-reply)
247 (define-key gnus-summary-send-map "B" 'gnus-summary-followup-and-reply-with-original)
248 (define-key gnus-summary-send-map "c" 'gnus-summary-cancel-article)
249 (define-key gnus-summary-send-map "s" 'gnus-summary-supersede-article)
250 (define-key gnus-summary-send-map "r" 'gnus-summary-reply)
251 (define-key gnus-summary-send-map "R" 'gnus-summary-reply-with-original)
252 (define-key gnus-summary-send-map "m" 'gnus-summary-mail-other-window)
253 (define-key gnus-summary-send-map "u" 'gnus-uu-post-news)
254 (define-key gnus-summary-send-map "om" 'gnus-summary-mail-forward)
255 (define-key gnus-summary-send-map "op" 'gnus-summary-post-forward)
256 (define-key gnus-summary-send-map "Om" 'gnus-uu-digest-mail-forward)
257 (define-key gnus-summary-send-map "Op" 'gnus-uu-digest-post-forward)
259 ;;; Internal functions.
261 (defun gnus-number-base36 (num len)
262 (if (if (< len 0) (<= num 0) (= len 0))
264 (concat (gnus-number-base36 (/ num 36) (1- len))
265 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
268 ;;; Post news commands of Gnus group mode and summary mode
270 (defun gnus-group-mail ()
271 "Start composing a mail."
273 (funcall gnus-mail-other-window-method))
275 (defun gnus-group-post-news ()
278 (let ((gnus-newsgroup-name nil))
279 (gnus-post-news 'post nil nil gnus-article-buffer)))
281 (defun gnus-summary-post-news ()
284 (gnus-set-global-variables)
285 (gnus-post-news 'post gnus-newsgroup-name))
287 (defun gnus-summary-followup (yank &optional yank-articles)
288 "Compose a followup to an article.
289 If prefix argument YANK is non-nil, original article is yanked automatically."
291 (gnus-set-global-variables)
292 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
293 (save-window-excursion
294 (gnus-summary-select-article))
295 (let ((headers (gnus-get-header-by-number (gnus-summary-article-number)))
296 (gnus-newsgroup-name gnus-newsgroup-name))
297 ;; Check Followup-To: poster.
298 (set-buffer gnus-article-buffer)
299 (if (and gnus-use-followup-to
300 (string-equal "poster" (gnus-fetch-field "followup-to"))
301 (or (not (memq gnus-use-followup-to '(t ask)))
303 "Do you want to ignore `Followup-To: poster'? "))))
304 ;; Mail to the poster.
305 (gnus-summary-reply yank)
306 (gnus-post-news nil gnus-newsgroup-name
307 headers gnus-article-buffer
308 (or yank-articles (not (not yank)))))))
310 (defun gnus-summary-followup-with-original (n)
311 "Compose a followup to an article and include the original article."
313 (gnus-summary-followup t (gnus-summary-work-articles n)))
315 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
316 (defun gnus-summary-followup-and-reply (yank &optional yank-articles)
317 "Compose a followup and do an auto mail to author."
319 (gnus-set-global-variables)
320 (let ((gnus-auto-mail-to-author t))
321 (gnus-summary-followup yank yank-articles)))
323 (defun gnus-summary-followup-and-reply-with-original (n)
324 "Compose a followup, include the original, and do an auto mail to author."
326 (gnus-summary-followup-and-reply t (gnus-summary-work-articles n)))
328 (defun gnus-summary-cancel-article (n)
329 "Cancel an article you posted."
331 (gnus-set-global-variables)
332 (let ((articles (gnus-summary-work-articles n)))
334 (gnus-summary-select-article t nil nil (car articles))
335 (and (gnus-eval-in-buffer-window gnus-article-buffer (gnus-cancel-news))
336 (gnus-summary-mark-as-read (car articles) gnus-canceled-mark))
337 (gnus-summary-remove-process-mark (car articles))
338 (gnus-article-hide-headers-if-wanted)
339 (setq articles (cdr articles)))))
341 (defun gnus-summary-supersede-article ()
342 "Compose an article that will supersede a previous article.
343 This is done simply by taking the old article and adding a Supersedes
344 header line with the old Message-ID."
346 (gnus-set-global-variables)
347 (gnus-summary-select-article t)
350 (downcase (mail-strip-quoted-names
351 (mail-header-from gnus-current-headers)))
352 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
353 (error "This article is not yours."))
355 (set-buffer gnus-article-buffer)
356 (let ((buffer-read-only nil))
357 (goto-char (point-min))
358 (search-forward "\n\n" nil t)
359 (if (not (re-search-backward "^Message-ID: " nil t))
360 (error "No Message-ID in this article"))))
361 (if (gnus-post-news 'post gnus-newsgroup-name)
364 (insert-buffer gnus-article-buffer)
365 (if (search-forward "\n\n" nil t)
367 (goto-char (point-max)))
368 (narrow-to-region (point-min) (point))
369 (goto-char (point-min))
370 (and gnus-delete-supersedes-headers
371 (delete-matching-lines gnus-delete-supersedes-headers))
372 (goto-char (point-min))
373 (if (not (re-search-forward "^Message-ID: " nil t))
374 (error "No Message-ID in this article")
375 (replace-match "Supersedes: " t t))
376 (goto-char (point-max))
377 (insert mail-header-separator)
383 (defalias 'sendnews 'gnus-post-news)
386 (defalias 'postnews 'gnus-post-news)
388 (defun gnus-copy-article-buffer (&optional article-buffer)
389 ;; make a copy of the article buffer with all text properties removed
390 ;; this copy is in the buffer gnus-article-copy.
391 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
392 ;; this buffer should be passed to all mail/news reply/post routines.
393 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
394 (buffer-disable-undo gnus-article-copy)
395 (or (memq gnus-article-copy gnus-buffer-list)
396 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
397 (let ((article-buffer (or article-buffer gnus-article-buffer)))
398 (if (and (get-buffer article-buffer)
399 (buffer-name (get-buffer article-buffer)))
401 (set-buffer article-buffer)
403 (copy-to-buffer gnus-article-copy (point-min) (point-max))
404 (set-text-properties (point-min) (point-max)
405 nil gnus-article-copy)))))
407 (defun gnus-post-news (post &optional group header article-buffer yank subject)
408 "Begin editing a new USENET news article to be posted.
409 Type \\[describe-mode] in the buffer to get a list of commands."
410 (interactive (list t))
411 (gnus-copy-article-buffer article-buffer)
412 (if (or (not gnus-novice-user)
416 (format "%s" (car (gnus-find-method-for-group
417 gnus-newsgroup-name)))
418 gnus-valid-select-methods))))
421 (nth 5 (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))))
422 (gnus-y-or-n-p "Are you sure you want to post to all of USENET? "))
423 (let ((sumart (if (not post)
425 (set-buffer gnus-summary-buffer)
426 (cons (current-buffer) gnus-current-article))))
427 (from (and header (mail-header-from header)))
428 (winconf (current-window-configuration))
430 (and gnus-interactive-post
431 (not gnus-expert-user)
434 (setq gnus-newsgroup-name
436 (completing-read "Group: " gnus-active-hashtb)))
438 (setq subject (read-string "Subject: ")))))
439 (setq mail-reply-buffer gnus-article-copy)
441 (let ((newsgroup-name (or group gnus-newsgroup-name "")))
442 (setq real-group (and group (gnus-group-real-name group)))
443 (setq gnus-post-news-buffer
444 (gnus-request-post-buffer
445 post real-group subject header gnus-article-copy
446 (nth 2 (and group (gnus-gethash group gnus-newsrc-hashtb)))
447 (or (cdr (assq 'to-group
448 (nth 5 (nth 2 (gnus-gethash
450 gnus-newsrc-hashtb)))))
451 (if (and (boundp 'gnus-followup-to-function)
452 gnus-followup-to-function
455 (set-buffer gnus-article-copy)
456 (funcall gnus-followup-to-function group))))
457 gnus-use-followup-to))
459 (gnus-configure-windows 'post 'force)
461 (gnus-configure-windows 'followup-yank 'force)
462 (gnus-configure-windows 'followup 'force)))
463 (gnus-overload-functions)
464 (make-local-variable 'gnus-article-reply)
465 (make-local-variable 'gnus-article-check-size)
466 (make-local-variable 'gnus-reply-subject)
467 (setq gnus-reply-subject (and header (mail-header-subject header)))
468 (setq gnus-article-reply sumart)
469 ;; Handle `gnus-auto-mail-to-author'.
470 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
471 ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
472 (let ((to (and (not post)
473 (if (if (eq gnus-auto-mail-to-author 'ask)
474 (y-or-n-p "Also send mail to author? ")
475 gnus-auto-mail-to-author)
477 (set-buffer gnus-article-copy)
478 (gnus-fetch-field "reply-to"))
482 (if (mail-fetch-field "To")
485 (insert "Cc: " to "\n"))
486 (mail-position-on-field "To")
488 ;; Handle author copy using BCC field.
489 (if (and gnus-mail-self-blind
490 (not (mail-fetch-field "bcc")))
492 (mail-position-on-field "Bcc")
493 (insert (if (stringp gnus-mail-self-blind)
495 (user-login-name)))))
496 ;; Handle author copy using FCC field.
499 (mail-position-on-field "Fcc")
500 (insert gnus-author-copy)))
501 (goto-char (point-min))
504 (re-search-forward "^Newsgroup:" nil t)
507 (re-search-forward "^Subject:" nil t)
511 (concat "^" (regexp-quote mail-header-separator) "$"))
514 (concat "^" (regexp-quote mail-header-separator) "$"))
519 (if (not (listp yank))
520 (news-reply-yank-original nil)
521 (setq yank (reverse yank))
524 (save-window-excursion
525 (set-buffer gnus-summary-buffer)
526 (gnus-summary-select-article nil nil nil (car yank))
527 (gnus-summary-remove-process-mark (car yank)))
528 (let ((mail-reply-buffer gnus-article-copy))
529 (gnus-copy-article-buffer)
530 (let ((news-reply-yank-message-id
532 (set-buffer gnus-article-copy)
533 (mail-fetch-field "message-id")))
534 (news-reply-yank-from
536 (set-buffer gnus-article-copy)
537 (mail-fetch-field "from"))))
538 (news-reply-yank-original nil))
539 (setq yank (cdr yank)))))))))
540 (if gnus-post-prepare-function
541 (funcall gnus-post-prepare-function group))
542 (run-hooks 'gnus-post-prepare-hook)
543 (make-local-variable 'gnus-prev-winconf)
544 (setq gnus-prev-winconf winconf))))
545 (setq gnus-article-check-size (cons (buffer-size) (gnus-article-checksum)))
549 (defun gnus-inews-news (&optional use-group-method)
550 "Send a news message.
551 If given a prefix, and the group is a foreign group, this function
552 will attempt to use the foreign server to post the article."
554 (let* ((case-fold-search nil)
555 (server-running (gnus-server-opened gnus-current-select-method))
556 (reply gnus-article-reply)
559 ;; Connect to default NNTP server if necessary.
560 ;; Suggested by yuki@flab.fujitsu.junet.
561 (gnus-start-news-server) ;Use default server.
562 ;; NNTP server must be opened before current buffer is modified.
564 (goto-char (point-min))
565 (run-hooks 'news-inews-hook)
570 (goto-char (point-min))
572 (concat "^" (regexp-quote mail-header-separator) "$"))
573 (match-beginning 0)))
575 ;; Correct newsgroups field: change sequence of spaces to comma and
576 ;; eliminate spaces around commas. Eliminate imbedded line breaks.
577 (goto-char (point-min))
578 (if (re-search-forward "^Newsgroups: +" nil t)
582 (if (re-search-forward "^[^ \t]" nil t)
586 (goto-char (point-min))
587 (while (re-search-forward "\n[ \t]+" nil t)
588 (replace-match " " t t)) ;No line breaks (too confusing)
589 (goto-char (point-min))
590 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
591 (replace-match "," t t))
592 (goto-char (point-min))
593 ;; Remove a trailing comma.
594 (if (re-search-forward ",$" nil t)
595 (replace-match "" t t))))
597 ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
598 ;; Help save the the world!
601 (let ((newsgroups (mail-fetch-field "newsgroups"))
602 (followup-to (mail-fetch-field "followup-to"))
605 (string-match "," newsgroups) (not followup-to))
607 (while (string-match "," newsgroups)
609 (cons (list (substring newsgroups
610 0 (match-beginning 0)))
612 (setq newsgroups (substring newsgroups (match-end 0))))
613 (setq groups (nreverse (cons (list newsgroups) groups)))
616 (completing-read "Followups to: (default all groups) "
618 (if (> (length to) 0)
620 (goto-char (point-min))
621 (insert "Followup-To: " to "\n")))))))
623 ;; Cleanup Followup-To.
624 (goto-char (point-min))
625 (if (search-forward-regexp "^Followup-To: +" nil t)
629 (if (re-search-forward "^[^ \t]" nil 'end)
632 (goto-char (point-min))
633 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
634 (goto-char (point-min))
635 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ",")))
637 ;; Mail the message too if To:, Bcc:. or Cc: exists.
638 (let* ((types '("to" "bcc" "cc"))
642 (or (mail-fetch-field (car ty) nil t)
643 (setq types (delete (car ty) types)))
647 ;; We do not want to send mail.
649 (if (not gnus-mail-send-method)
653 1 "No mailer defined. To: and/or Cc: fields ignored.")
656 ;; We want to remove Fcc, because we want to handle
657 ;; that one ourselves...
659 (goto-char (point-min))
660 (if (re-search-forward "^Fcc: " nil t)
664 (progn (beginning-of-line) (point))
665 (progn (forward-line 1) (point))))
669 ;; We generate a Message-ID so that the mail and the
670 ;; news copy of the message both get the same ID.
671 (or (mail-fetch-field "message-id")
672 (not (memq 'Message-ID gnus-required-headers))
674 (goto-char (point-max))
675 (insert "Message-ID: " (gnus-inews-message-id) "\n")))
679 (gnus-message 5 "Sending via mail...")
681 (if (and gnus-mail-courtesy-message
682 (or (member "to" types)
683 (member "cc" types)))
684 ;; We only want to insert the courtesy mail
685 ;; message if we use to or cc; bcc should not
686 ;; have one. Well, if both bcc and to are
687 ;; present, it will get one anyway.
689 ;; Insert "courtesy" mail message.
690 (goto-char (point-min))
692 (concat "^" (regexp-quote
693 mail-header-separator) "$"))
695 (insert gnus-mail-courtesy-message)
696 (funcall gnus-mail-send-method)
697 (goto-char (point-min))
698 (search-forward gnus-mail-courtesy-message)
699 (replace-match "" t t))
700 (funcall gnus-mail-send-method))
702 (gnus-message 5 "Sending via mail...done")
704 (goto-char (point-min))
708 (concat "^" (regexp-quote mail-header-separator) "$")))
709 (goto-char (point-min))
710 (delete-matching-lines "^BCC:"))
713 (goto-char (point-max))
714 (insert fcc-line))))))))
717 (gnus-message 5 "Posting to USENET...")
718 (setq post-result (funcall gnus-inews-article-function use-group-method))
719 (cond ((eq post-result 'illegal)
723 (gnus-message 5 "Posting to USENET...done")
724 (if (gnus-buffer-exists-p (car-safe reply))
727 (set-buffer gnus-summary-buffer)
728 (gnus-summary-mark-article-as-replied
730 (set-buffer-modified-p nil))
732 ;; We cannot signal an error.
735 (gnus-message 1 "Article rejected: %s"
736 (gnus-status-message gnus-select-method)))))
737 ;; If NNTP server is opened by gnus-inews-news, close it by myself.
739 (gnus-close-server (gnus-find-method-for-group gnus-newsgroup-name)))
740 (let ((conf gnus-prev-winconf))
744 ;; Restore last window configuration.
745 (and conf (set-window-configuration conf)))))))
747 (defun gnus-inews-check-post ()
748 "Check whether the post looks ok."
750 (not gnus-check-before-posting)
752 ;; We narrow to the headers and check them first.
755 (goto-char (point-min))
760 (concat "^" (regexp-quote mail-header-separator) "$"))
761 (match-beginning 0)))
762 (goto-char (point-min))
764 ;; Check for commands in Subject.
766 (gnus-check-before-posting 'subject-cmsg)
768 (if (string-match "^cmsg " (mail-fetch-field "subject"))
770 "The control code \"cmsg \" is in the subject. Really post? ")
772 ;; Check for multiple identical headers.
773 (or (gnus-check-before-posting 'multiple-headers)
776 (while (and (not found) (re-search-forward "^[^ \t:]+: "
779 (or (re-search-forward
780 (concat "^" (setq found
783 (- (match-end 0) 2))))
788 (format "Multiple %s headers. Really post? " found))
790 ;; Check for version and sendsys.
791 (or (gnus-check-before-posting 'sendsys)
793 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
795 (format "The article contains a %s command. Really post? "
796 (buffer-substring (match-beginning 0)
797 (1- (match-end 0)))))
799 ;; Check the Message-Id header.
800 (or (gnus-check-before-posting 'message-id)
802 (let* ((case-fold-search t)
803 (message-id (mail-fetch-field "message-id")))
805 (and (string-match "@" message-id)
806 (string-match "@[^\\.]*\\." message-id))
809 "The Message-ID looks strange: \"%s\". Really post? "
811 ;; Check the From header.
812 (or (gnus-check-before-posting 'from)
814 (let* ((case-fold-search t)
815 (from (mail-fetch-field "from")))
818 (gnus-y-or-n-p "There is no From line. Really post? "))
819 ((not (string-match "@[^\\.]*\\." from))
822 "The address looks strange: \"%s\". Really post? " from)))
823 ((string-match "(.*).*(.*)" from)
826 "The From header looks strange: \"%s\". Really post? "
830 ;; Check for long lines.
831 (or (gnus-check-before-posting 'long-lines)
833 (goto-char (point-min))
835 (concat "^" (regexp-quote mail-header-separator) "$"))
839 (< (current-column) 80))
840 (zerop (forward-line 1))))
845 "You have lines longer than 79 characters. Really post? ")))))
846 ;; Check for control characters.
847 (or (gnus-check-before-posting 'control-chars)
849 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
851 "The article contains control characters. Really post? ")
853 ;; Check excessive size.
854 (or (gnus-check-before-posting 'size)
855 (if (> (buffer-size) 60000)
857 (format "The article is %d octets long. Really post? "
860 ;; Use the (size . checksum) variable to see whether the
861 ;; article is empty or has only quoted text.
863 (gnus-check-before-posting 'new-text)
864 (if (and (= (buffer-size) (car gnus-article-check-size))
865 (= (gnus-article-checksum) (cdr gnus-article-check-size)))
867 "It looks like there's no new text in your article. Really post? ")
869 ;; Check the length of the signature.
870 (or (gnus-check-before-posting 'signature)
872 (goto-char (point-max))
873 (if (not (re-search-backward gnus-signature-separator nil t))
875 (if (> (count-lines (point) (point-max)) 4)
878 "Your .sig is %d lines; it should be max 4. Really post? "
879 (count-lines (point) (point-max))))
882 (defun gnus-article-checksum ()
886 (setq sum (logxor sum (following-char)))
890 ;; Returns non-nil if this type is not to be checked.
891 (defun gnus-check-before-posting (type)
893 (or (not gnus-check-before-posting)
894 (if (listp gnus-check-before-posting)
895 (memq type gnus-check-before-posting)
898 (defun gnus-cancel-news ()
899 "Cancel an article you posted."
901 (if (or gnus-expert-user
902 (gnus-yes-or-no-p "Do you really want to cancel this article? "))
907 (or (gnus-member-of-valid 'post gnus-newsgroup-name)
908 (error "This backend does not support canceling"))
910 ;; Get header info. from original article.
912 (gnus-article-show-all-headers)
913 (goto-char (point-min))
914 (search-forward "\n\n" nil 'move)
915 (narrow-to-region (point-min) (point))
916 (setq from (mail-fetch-field "from"))
917 (setq newsgroups (mail-fetch-field "newsgroups"))
918 (setq message-id (mail-fetch-field "message-id"))
919 (setq distribution (mail-fetch-field "distribution")))
920 ;; Verify if the article is absolutely user's by comparing
921 ;; user id with value of its From: field.
924 (downcase (mail-strip-quoted-names from))
925 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
927 (ding) (gnus-message 3 "This article is not yours.")
929 ;; Make control article.
930 (set-buffer (get-buffer-create " *Gnus-canceling*"))
931 (buffer-disable-undo (current-buffer))
933 (insert "Newsgroups: " newsgroups "\n"
934 "Subject: cancel " message-id "\n"
935 "Control: cancel " message-id "\n"
937 (concat "Distribution: " distribution "\n")
939 mail-header-separator "\n"
940 "This is a cancel message from " from ".\n")
941 ;; Send the control article to NNTP server.
942 (gnus-message 5 "Canceling your article...")
944 (if (funcall gnus-inews-article-function)
945 (gnus-message 5 "Canceling your article...done")
948 (gnus-message 1 "Cancel failed; %s"
949 (gnus-status-message gnus-newsgroup-name))
952 ;; Kill the article buffer.
953 (kill-buffer (current-buffer))))))))
956 ;;; Lowlevel inews interface
958 (defun gnus-inews-article (&optional use-group-method)
959 "Post an article in current buffer using NNTP protocol."
960 (let ((artbuf (current-buffer))
961 (tmpbuf (get-buffer-create " *Gnus-posting*")))
963 (goto-char (point-max))
964 ;; require a newline at the end for inews to append .signature to
965 (or (= (preceding-char) ?\n)
967 ;; Prepare article headers. All message body such as signature
968 ;; must be inserted before Lines: field is prepared.
970 (goto-char (point-min))
975 (concat "^" (regexp-quote mail-header-separator) "$"))
976 (match-beginning 0)))
977 (gnus-inews-remove-headers)
978 (gnus-inews-insert-headers)
979 (run-hooks 'gnus-inews-article-header-hook)
981 ;; Check whether the article is a good Net Citizen.
982 (if (and gnus-article-check-size
983 (not (gnus-inews-check-post)))
986 ;; Looks ok, so we do the nasty.
989 (buffer-disable-undo (current-buffer))
991 (insert-buffer-substring artbuf)
992 ;; Remove the header separator.
993 (goto-char (point-min))
995 (concat "^" (regexp-quote mail-header-separator) "$"))
996 (replace-match "" t t)
997 ;; This hook may insert a signature.
998 (run-hooks 'gnus-prepare-article-hook)
999 ;; Run final inews hooks. This hook may do FCC.
1000 ;; The article must be saved before being posted because
1001 ;; `gnus-request-post' modifies the buffer.
1002 (run-hooks 'gnus-inews-article-hook)
1003 ;; Post an article to NNTP server.
1004 ;; Return NIL if post failed.
1007 (if use-group-method
1008 (gnus-find-method-for-group gnus-newsgroup-name)
1009 gnus-select-method) use-group-method)
1010 (kill-buffer (current-buffer)))))))
1012 (defun gnus-inews-remove-headers ()
1013 (let ((case-fold-search t)
1014 (headers gnus-removable-headers))
1015 ;; Remove toxic headers.
1017 (goto-char (point-min))
1018 (and (re-search-forward
1019 (concat "^" (downcase (format "%s" (car headers))))
1021 (delete-region (progn (beginning-of-line) (point))
1022 (progn (forward-line 1) (point))))
1023 (setq headers (cdr headers)))))
1025 (defun gnus-inews-insert-headers ()
1026 "Prepare article headers.
1027 Headers already prepared in the buffer are not modified.
1028 Headers in `gnus-required-headers' will be generated."
1029 (let ((Date (gnus-inews-date))
1030 (Message-ID (gnus-inews-message-id))
1031 (Organization (gnus-inews-organization))
1032 (From (gnus-inews-user-name))
1033 (Path (gnus-inews-path))
1037 (Lines (gnus-inews-lines))
1038 (X-Newsreader gnus-version)
1039 (headers gnus-required-headers)
1040 (case-fold-search t)
1042 ;; First we remove any old generated headers.
1043 (let ((headers gnus-deletable-headers))
1045 (goto-char (point-min))
1046 (and (re-search-forward
1047 (concat "^" (symbol-name (car headers)) ": *") nil t)
1048 (get-text-property (1+ (match-beginning 0)) 'gnus-deletable)
1050 (setq headers (cdr headers))))
1051 ;; If there are References, and no "Re: ", then the thread has
1052 ;; changed name. See Son-of-1036.
1053 (if (and (mail-fetch-field "references")
1054 (get-buffer gnus-article-buffer))
1055 (let ((psubject (gnus-simplify-subject-re
1056 (mail-fetch-field "subject"))))
1057 (or (and psubject gnus-reply-subject
1058 (string= (gnus-simplify-subject-re gnus-reply-subject)
1061 (string-match "@" Message-ID)
1063 (concat (substring Message-ID 0 (match-beginning 0))
1065 (substring Message-ID (match-beginning 0))))))))
1066 ;; Go through all the required headers and see if they are in the
1067 ;; articles already. If they are not, or are empty, they are
1068 ;; inserted automatically - except for Subject, Newsgroups and
1071 (goto-char (point-min))
1072 (setq elem (car headers))
1074 (setq header (car elem))
1076 (if (or (not (re-search-forward
1077 (concat "^" (downcase (symbol-name header)) ":") nil t))
1079 ;; The header was found. We insert a space after the
1080 ;; colon, if there is none.
1081 (if (/= (following-char) ? ) (insert " "))
1082 ;; Find out whether the header is empty...
1083 (looking-at "[ \t]*$")))
1084 ;; So we find out what value we should insert.
1087 (or (if (consp elem)
1088 ;; The element is a cons. Either the cdr is
1089 ;; a string to be inserted verbatim, or it
1090 ;; is a function, and we insert the value
1091 ;; returned from this function.
1092 (or (and (stringp (cdr elem)) (cdr elem))
1093 (and (fboundp (cdr elem)) (funcall (cdr elem))))
1094 ;; The element is a symbol. We insert the
1095 ;; value of this symbol, if any.
1096 (and (boundp header) (symbol-value header)))
1097 ;; We couldn't generate a value for this header,
1098 ;; so we just ask the user.
1099 (read-from-minibuffer
1100 (format "Empty header for %s; enter value: " header))))
1101 ;; Finally insert the header.
1105 (goto-char (point-max))
1106 (insert (symbol-name header) ": " value "\n")
1108 (replace-match value t t))
1109 ;; Add the deletable property to the headers that require it.
1110 (and (memq header gnus-deletable-headers)
1111 (progn (beginning-of-line) (looking-at "[^:]+: "))
1112 (add-text-properties
1113 (point) (match-end 0)
1114 '(gnus-deletable t face italic) (current-buffer))))))
1115 (setq headers (cdr headers)))
1116 ;; Insert new Sender if the From is strange.
1117 (let ((from (mail-fetch-field "from"))
1118 (sender (mail-fetch-field "sender")))
1121 (downcase (car (gnus-extract-address-components from)))
1122 (downcase (gnus-inews-real-user-address))))
1126 (downcase (car (gnus-extract-address-components sender)))
1127 (downcase (gnus-inews-real-user-address))))))
1129 (goto-char (point-min))
1130 (and (re-search-forward "^Sender:" nil t)
1133 (insert "Original-")
1134 (beginning-of-line)))
1135 (insert "Sender: " (gnus-inews-real-user-address) "\n"))))))
1138 (defun gnus-inews-insert-signature ()
1139 "Insert a signature file.
1140 If `gnus-signature-function' is bound and returns a string, this
1141 string is used instead of the variable `gnus-signature-file'.
1142 In either case, if the string is a file name, this file is
1143 inserted. If the string is not a file name, the string itself is
1145 If you never want any signature inserted, set both those variables to
1149 (or (and gnus-signature-function
1150 (funcall gnus-signature-function gnus-newsgroup-name))
1151 gnus-signature-file)))
1153 (or (file-exists-p signature)
1154 (string-match " " signature)
1156 "^/[^/]+/" (expand-file-name signature)))))
1158 (goto-char (point-max))
1159 (if (and mail-signature (search-backward "\n-- \n" nil t))
1161 ;; Delete any previous signatures.
1162 (if (search-backward "\n-- \n" nil t)
1163 (delete-region (point) (point-max)))
1164 (or (eolp) (insert "\n"))
1166 (if (file-exists-p signature)
1167 (insert-file-contents signature)
1169 (goto-char (point-max))
1170 (or (bolp) (insert "\n"))))))))
1172 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1173 (defun gnus-inews-insert-mime-headers ()
1174 (let ((mail-header-separator ""))
1175 (or (mail-position-on-field "Mime-Version")
1177 (cond ((save-excursion
1178 (beginning-of-buffer)
1179 (re-search-forward "[\200-\377]" nil t))
1180 (or (mail-position-on-field "Content-Type")
1181 (insert "text/plain; charset=ISO-8859-1"))
1182 (or (mail-position-on-field "Content-Transfer-Encoding")
1184 (t (or (mail-position-on-field "Content-Type")
1185 (insert "text/plain; charset=US-ASCII"))
1186 (or (mail-position-on-field "Content-Transfer-Encoding")
1187 (insert "7bit")))))))
1189 (defun gnus-inews-do-fcc ()
1190 "Process FCC: fields in current article buffer.
1191 Unless the first character of the field is `|', the article is saved
1192 to the specified file using the function specified by the variable
1193 gnus-author-copy-saver. The default function rmail-output saves in
1194 Unix mailbox format.
1195 If the first character is `|', the contents of the article is send to
1196 a program specified by the rest of the value."
1197 (let ((fcc-list nil)
1199 (case-fold-search t)) ;Should ignore case.
1202 (goto-char (point-min))
1203 (search-forward "\n\n")
1204 (narrow-to-region (point-min) (point))
1205 (goto-char (point-min))
1206 (while (re-search-forward "^FCC:[ \t]*" nil t)
1208 (cons (buffer-substring
1212 (skip-chars-backward " \t")
1215 (delete-region (match-beginning 0)
1216 (progn (forward-line 1) (point))))
1217 ;; Process FCC operations.
1220 (setq fcc-file (car fcc-list))
1221 (setq fcc-list (cdr fcc-list))
1222 (cond ((string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" fcc-file)
1223 (let ((program (substring fcc-file
1224 (match-beginning 1) (match-end 1))))
1225 ;; Suggested by yuki@flab.fujitsu.junet.
1226 ;; Send article to named program.
1227 (call-process-region (point-min) (point-max) shell-file-name
1228 nil nil nil "-c" program)))
1230 ;; Suggested by hyoko@flab.fujitsu.junet.
1231 ;; Save article in Unix mail format by default.
1232 (gnus-make-directory (file-name-directory fcc-file))
1233 (if (and gnus-author-copy-saver
1234 (not (eq gnus-author-copy-saver 'rmail-output)))
1235 (funcall gnus-author-copy-saver fcc-file)
1236 (if (and (file-readable-p fcc-file) (rmail-file-p fcc-file))
1237 (gnus-output-to-rmail fcc-file)
1238 (rmail-output fcc-file 1 t t))))))))))
1240 (defun gnus-inews-path ()
1242 (let ((login-name (gnus-inews-login-name)))
1243 (cond ((null gnus-use-generic-path)
1244 (concat (nth 1 gnus-select-method) "!" login-name))
1245 ((stringp gnus-use-generic-path)
1246 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1247 (concat gnus-use-generic-path "!" login-name))
1250 (defun gnus-inews-user-name ()
1251 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1252 (let ((full-name (gnus-inews-full-name)))
1253 (or gnus-user-from-line
1254 (concat (if (or gnus-user-login-name gnus-use-generic-from
1255 gnus-local-domain (getenv "DOMAINNAME"))
1256 (concat (gnus-inews-login-name) "@"
1257 (gnus-inews-domain-name gnus-use-generic-from))
1259 ;; User's full name.
1260 (cond ((string-equal full-name "") "")
1261 ((string-equal full-name "&") ;Unix hack.
1262 (concat " (" (user-login-name) ")"))
1264 (concat " (" full-name ")")))))))
1266 (defun gnus-inews-real-user-address ()
1267 "Return the \"real\" user address.
1268 This function tries to ignore all user modifications, and
1269 give as trustworthy answer as possible."
1270 (concat (user-login-name) "@" (gnus-inews-full-address)))
1272 (defun gnus-inews-login-name ()
1273 "Return login name."
1274 (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1276 (defun gnus-inews-full-name ()
1277 "Return full user name."
1278 (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1280 (defun gnus-inews-domain-name (&optional genericfrom)
1281 "Return user's domain name.
1282 If optional argument GENERICFROM is a string, use it as the domain
1283 name; if it is non-nil, strip off local host name from the domain name.
1284 If the function `system-name' returns full internet name and the
1285 domain is undefined, the domain name is got from it."
1286 (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1287 (let* ((system-name (system-name))
1289 (or (if (stringp genericfrom) genericfrom)
1290 (getenv "DOMAINNAME")
1292 ;; Function `system-name' may return full internet name.
1293 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1294 (if (string-match "\\." system-name)
1295 (substring system-name (match-end 0)))
1296 (read-string "Domain name (no host): ")))
1297 (host (or (if (string-match "\\." system-name)
1298 (substring system-name 0 (match-beginning 0)))
1300 (if (string-equal "." (substring domain 0 1))
1301 (setq domain (substring domain 1)))
1302 ;; Support GENERICFROM as same as standard Bnews system.
1303 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1304 (cond ((null genericfrom)
1305 (concat host "." domain))
1306 ;;((stringp genericfrom) genericfrom)
1308 (if (string-match "\\." (system-name))
1310 (substring user-mail-address
1311 (1+ (string-match "@" user-mail-address))))))
1313 (defun gnus-inews-full-address ()
1314 (let ((domain (gnus-inews-domain-name))
1315 (system (system-name))
1316 (case-fold-search t))
1317 (if (string-match "\\." system) system
1318 (if (string-match (concat "^" (regexp-quote system)) domain) domain
1319 (concat system "." domain)))))
1321 (defun gnus-inews-message-id ()
1322 "Generate unique Message-ID for user."
1323 ;; Message-ID should not contain a slash and should be terminated by
1324 ;; a number. I don't know the reason why it is so.
1325 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1327 (defvar gnus-unique-id-char nil)
1329 ;; If you ever change this function, make sure the new version
1330 ;; cannot generate IDs that the old version could.
1331 ;; You might for example insert a "." somewhere (not next to another dot
1332 ;; or string boundary), or modify the newsreader name to "Ding".
1333 (defun gnus-inews-unique-id ()
1334 ;; Dont use microseconds from (current-time), they may be unsupported.
1335 ;; Instead we use this randomly inited counter.
1336 (setq gnus-unique-id-char
1337 (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1338 ;; (current-time) returns 16-bit ints,
1339 ;; and 2^16*25 just fits into 4 digits i base 36.
1341 (let ((tm (if (fboundp 'current-time)
1342 (current-time) '(12191 46742 287898))))
1344 (if (memq system-type '(ms-dos emx vax-vms))
1345 (let ((user (downcase (gnus-inews-login-name))))
1346 (while (string-match "[^a-z0-9_]" user)
1347 (aset user (match-beginning 0) ?_))
1349 (gnus-number-base36 (user-uid) -1))
1350 (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1351 (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1352 ;; Append the newsreader name, because while the generated
1353 ;; ID is unique to this newsreader, other newsreaders might
1354 ;; otherwise generate the same ID via another algorithm.
1358 (defun gnus-inews-date ()
1359 "Current time string."
1360 (timezone-make-date-arpa-standard
1361 (current-time-string) (current-time-zone)))
1363 (defun gnus-inews-organization ()
1364 "Return user's organization.
1365 The ORGANIZATION environment variable is used if defined.
1366 If not, the variable `gnus-local-organization' is used instead.
1367 If it is a function, the function will be called with the current
1368 newsgroup name as the argument.
1369 If this is a file name, the contents of this file will be used as the
1371 (let* ((organization
1372 (or (getenv "ORGANIZATION")
1373 (if gnus-local-organization
1374 (if (and (symbolp gnus-local-organization)
1375 (fboundp gnus-local-organization))
1376 (funcall gnus-local-organization gnus-newsgroup-name)
1377 gnus-local-organization))
1378 gnus-organization-file
1379 "~/.organization")))
1380 (and (stringp organization)
1381 (> (length organization) 0)
1382 (or (file-exists-p organization)
1383 (string-match " " organization)
1384 (not (string-match "^/usr/lib/" organization)))
1386 (gnus-set-work-buffer)
1387 (if (file-exists-p organization)
1388 (insert-file-contents organization)
1389 (insert organization))
1390 (goto-char (point-min))
1391 (while (re-search-forward " *\n *" nil t)
1392 (replace-match " " t t))
1393 (buffer-substring (point-min) (point-max))))))
1395 (defun gnus-inews-lines ()
1396 "Count the number of lines and return numeric string."
1400 (goto-char (point-min))
1402 (concat "^" (regexp-quote mail-header-separator) "$"))
1404 (int-to-string (count-lines (point) (point-max))))))
1408 ;;; Gnus Mail Functions
1411 ;;; Mail reply commands of Gnus summary mode
1413 (defun gnus-summary-reply (yank &optional yank-articles)
1414 "Reply mail to news author.
1415 If prefix argument YANK is non-nil, original article is yanked automatically.
1416 Customize the variable gnus-mail-reply-method to use another mailer."
1418 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1419 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1420 (gnus-set-global-variables)
1421 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1422 (gnus-summary-select-article)
1423 (let ((gnus-newsgroup-name gnus-newsgroup-name))
1424 (bury-buffer gnus-article-buffer)
1425 (funcall gnus-mail-reply-method (or yank-articles (not (not yank))))))
1427 (defun gnus-summary-reply-with-original (n)
1428 "Reply mail to news author with original article.
1429 Customize the variable gnus-mail-reply-method to use another mailer."
1431 (gnus-summary-reply t (gnus-summary-work-articles n)))
1433 (defun gnus-summary-mail-forward (post)
1434 "Forward the current message to another user.
1435 Customize the variable gnus-mail-forward-method to use another mailer."
1437 (gnus-set-global-variables)
1438 (gnus-summary-select-article)
1439 (gnus-copy-article-buffer)
1440 (let ((gnus-newsgroup-name gnus-newsgroup-name))
1442 (gnus-forward-using-post gnus-article-copy)
1443 (funcall gnus-mail-forward-method gnus-article-copy))))
1445 (defun gnus-summary-post-forward ()
1446 "Forward the current article to a newsgroup."
1448 (gnus-summary-mail-forward t))
1450 (defvar gnus-nastygram-message
1451 "The following article was inappropriately posted to %s.\n"
1452 "Format string to insert in nastygrams.
1453 The current group name will be inserted at \"%s\".")
1455 (defun gnus-summary-mail-nastygram (n)
1456 "Send a nastygram to the author of the current article."
1458 (if (or gnus-expert-user
1460 "Really send a nastygram to the author of the current article? "))
1461 (let ((group gnus-newsgroup-name))
1462 (gnus-summary-reply-with-original n)
1463 (set-buffer gnus-mail-buffer)
1464 (insert (format gnus-nastygram-message group))
1465 (gnus-mail-send-and-exit))))
1467 (defun gnus-summary-mail-other-window ()
1468 "Compose mail in other window.
1469 Customize the variable `gnus-mail-other-window-method' to use another
1472 (gnus-set-global-variables)
1473 (let ((gnus-newsgroup-name gnus-newsgroup-name))
1474 (funcall gnus-mail-other-window-method)))
1476 (defun gnus-mail-reply-using-mail (&optional yank to-address)
1478 (set-buffer gnus-summary-buffer)
1479 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1480 (cur (cons (current-buffer) (cdr gnus-article-current)))
1481 (winconf (current-window-configuration))
1482 from subject date reply-to message-of
1483 references message-id sender follow-to sendto elt)
1484 (set-buffer (get-buffer-create gnus-mail-buffer))
1486 (make-local-variable 'gnus-article-reply)
1487 (setq gnus-article-reply cur)
1488 (make-local-variable 'gnus-prev-winconf)
1489 (setq gnus-prev-winconf winconf)
1490 (if (and (buffer-modified-p)
1493 "Unsent article being composed; erase it? ")))
1497 (gnus-copy-article-buffer)
1499 (set-buffer gnus-article-copy)
1500 (gnus-narrow-to-headers)
1501 (if (and (boundp 'gnus-reply-to-function)
1502 gnus-reply-to-function)
1503 (setq follow-to (funcall gnus-reply-to-function group)))
1504 (setq from (mail-fetch-field "from"))
1505 (setq date (or (mail-fetch-field "date")
1506 (mail-header-date gnus-current-headers)))
1509 (string-match " *at \\| *@ \\| *(\\| *<" from)))
1511 (concat (if stop-pos (substring from 0 stop-pos) from)
1512 "'s message of " date))))
1513 (setq sender (mail-fetch-field "sender"))
1514 (setq subject (or (mail-fetch-field "subject")
1516 (or (string-match "^[Rr][Ee]:" subject)
1517 (setq subject (concat "Re: " subject)))
1518 (setq reply-to (mail-fetch-field "reply-to"))
1519 (setq references (mail-fetch-field "references"))
1520 (setq message-id (mail-fetch-field "message-id"))
1522 (setq news-reply-yank-from (or from "(nobody)")))
1523 (setq news-reply-yank-message-id
1524 (or message-id "(unknown Message-ID)"))
1526 ;; Gather the "to" addresses out of the follow-to list and remove
1528 (if (and follow-to (listp follow-to))
1529 (while (setq elt (assoc "To" follow-to))
1530 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1531 (setq follow-to (delq elt follow-to))))
1533 (mail-setup (or to-address
1534 (if (and follow-to (not (stringp follow-to))) sendto
1535 (or follow-to reply-to from sender "")))
1536 subject message-of nil gnus-article-copy nil)
1538 (auto-save-mode auto-save-default)
1539 (use-local-map (copy-keymap mail-mode-map))
1540 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1542 (if (and follow-to (listp follow-to))
1544 (goto-char (point-min))
1545 (re-search-forward "^To:" nil t)
1549 (insert (car (car follow-to)) ": " (cdr (car follow-to)) "\n")
1550 (setq follow-to (cdr follow-to)))))
1551 (nnheader-insert-references references message-id)
1552 (goto-char (point-min))
1554 (concat "^" (regexp-quote mail-header-separator) "$"))
1557 (gnus-configure-windows 'reply 'force)
1558 (let ((last (point))
1560 (if (not (listp yank))
1563 (mail-yank-original nil))
1564 (or mail-yank-hooks mail-citation-hook
1565 (run-hooks 'news-reply-header-hook)))
1567 (save-window-excursion
1568 (set-buffer gnus-summary-buffer)
1569 (gnus-summary-select-article nil nil nil (car yank))
1570 (gnus-summary-remove-process-mark (car yank)))
1572 (gnus-copy-article-buffer)
1573 (mail-yank-original nil)
1575 (or mail-yank-hooks mail-citation-hook
1576 (run-hooks 'news-reply-header-hook))
1578 (setq yank (cdr yank))))
1580 (gnus-configure-windows 'reply-yank 'force))
1581 (run-hooks 'gnus-mail-hook)))))
1583 (defun gnus-mail-yank-original ()
1586 (mail-yank-original nil))
1587 (or mail-yank-hooks mail-citation-hook
1588 (run-hooks 'news-reply-header-hook)))
1590 (defun gnus-mail-send-and-exit ()
1592 (let ((reply gnus-article-reply)
1593 (winconf gnus-prev-winconf))
1594 (mail-send-and-exit nil)
1595 (if (get-buffer gnus-group-buffer)
1597 (if (gnus-buffer-exists-p (car-safe reply))
1599 (set-buffer (car reply))
1601 (gnus-summary-mark-article-as-replied
1603 (and winconf (set-window-configuration winconf))))))
1605 (defun gnus-forward-make-subject (buffer)
1608 (concat "[" (if (memq 'mail (assoc (symbol-name
1609 (car (gnus-find-method-for-group
1610 gnus-newsgroup-name)))
1611 gnus-valid-select-methods))
1612 (gnus-fetch-field "From")
1613 gnus-newsgroup-name)
1614 "] " (or (gnus-fetch-field "Subject") ""))))
1616 (defun gnus-forward-insert-buffer (buffer)
1617 (let ((beg (goto-char (point-max))))
1618 (insert "------- Start of forwarded message -------\n")
1619 (insert-buffer buffer)
1620 (goto-char (point-max))
1621 (insert "------- End of forwarded message -------\n")
1622 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
1624 (while (setq beg (next-single-property-change (point) 'invisible))
1626 (delete-region beg (or (next-single-property-change
1630 (defun gnus-mail-forward-using-mail (&optional buffer)
1631 "Forward the current message to another user using mail."
1632 ;; This is almost a carbon copy of rmail-forward in rmail.el.
1633 (let* ((forward-buffer (or buffer (current-buffer)))
1634 (winconf (current-window-configuration))
1635 (subject (gnus-forward-make-subject forward-buffer)))
1636 (set-buffer forward-buffer)
1637 (mail nil nil subject)
1638 (use-local-map (copy-keymap (current-local-map)))
1639 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1640 (make-local-variable 'gnus-prev-winconf)
1641 (setq gnus-prev-winconf winconf)
1642 (gnus-forward-insert-buffer forward-buffer)
1643 (goto-char (point-min))
1644 (re-search-forward "^To: " nil t)
1645 (gnus-configure-windows 'mail-forward 'force)
1646 ;; You have a chance to arrange the message.
1647 (run-hooks 'gnus-mail-forward-hook)
1648 (run-hooks 'gnus-mail-hook)))
1650 (defun gnus-forward-using-post (&optional buffer)
1652 (let* ((forward-buffer (or buffer (current-buffer)))
1653 (subject (gnus-forward-make-subject forward-buffer))
1654 (gnus-newsgroup-name nil))
1655 (gnus-post-news 'post nil nil nil nil subject)
1657 (gnus-forward-insert-buffer forward-buffer)
1658 ;; You have a chance to arrange the message.
1659 (run-hooks 'gnus-mail-forward-hook)))))
1661 (defun gnus-mail-other-window-using-mail ()
1662 "Compose mail other window using mail."
1663 (let ((winconf (current-window-configuration)))
1664 (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
1665 (use-local-map (copy-keymap (current-local-map)))
1666 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1667 (make-local-variable 'gnus-prev-winconf)
1668 (setq gnus-prev-winconf winconf)
1669 (run-hooks 'gnus-mail-hook)
1670 (gnus-configure-windows 'summary-mail 'force)))
1672 (defun gnus-article-mail (yank)
1673 "Send a reply to the address near point.
1674 If YANK is non-nil, include the original article."
1678 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1679 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1682 (switch-to-buffer gnus-summary-buffer)
1683 (funcall gnus-mail-reply-method yank address)))))
1685 (defun gnus-article-mail-with-original ()
1686 "Send a reply to the address near point and include the original article."
1688 (gnus-article-mail 'yank))
1691 "Send a bug report to the Gnus maintainers."
1693 (let ((winconf (current-window-configuration)))
1694 (delete-other-windows)
1695 (switch-to-buffer "*Gnus Help Bug*")
1697 (insert gnus-bug-message)
1698 (goto-char (point-min))
1699 (pop-to-buffer "*Gnus Bug*")
1702 (mail-setup gnus-maintainer nil nil nil nil nil)
1703 (auto-save-mode auto-save-default)
1704 (make-local-variable 'gnus-prev-winconf)
1705 (setq gnus-prev-winconf winconf)
1706 (use-local-map (copy-keymap mail-mode-map))
1707 (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
1708 (goto-char (point-min))
1709 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1711 (insert (format "%s\n%s\n\n\n\n\n" (gnus-version) (emacs-version)))
1713 (goto-char (point-min))
1714 (search-forward "Subject: " nil t)
1717 (defun gnus-bug-mail-send-and-exit ()
1718 "Send the bug message and exit."
1720 (and (get-buffer "*Gnus Help Bug*")
1721 (kill-buffer "*Gnus Help Bug*"))
1722 (gnus-mail-send-and-exit))
1724 (defun gnus-debug ()
1725 "Attemps to go through the Gnus source file and report what variables have been changed.
1726 The source file has to be in the Emacs load path."
1728 (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el"))
1729 file dirs expr olist sym)
1730 (message "Please wait while we snoop your variables...")
1733 (set-buffer (get-buffer-create " *gnus bug info*"))
1734 (buffer-disable-undo (current-buffer))
1737 (setq dirs load-path)
1739 (if (or (not (car dirs))
1740 (not (stringp (car dirs)))
1742 (setq file (concat (file-name-as-directory
1743 (car dirs)) (car files))))))
1744 (setq dirs (cdr dirs))
1746 (insert-file-contents file)
1747 (goto-char (point-min))
1748 (or (re-search-forward "^;;* *Internal variables" nil t)
1749 (error "Malformed sources in file %s" file))
1750 (narrow-to-region (point-min) (point))
1751 (goto-char (point-min))
1752 (while (setq expr (condition-case ()
1753 (read (current-buffer)) (error nil)))
1755 (and (eq (car expr) 'defvar)
1756 (stringp (nth 3 expr))
1757 (or (not (boundp (nth 1 expr)))
1758 (not (equal (eval (nth 2 expr))
1759 (symbol-value (nth 1 expr)))))
1760 (setq olist (cons (nth 1 expr) olist)))
1762 (setq files (cdr files)))
1763 (kill-buffer (current-buffer)))
1764 (insert "------------------- Environment follows -------------------\n\n")
1766 (if (boundp (car olist))
1767 (insert "(setq " (symbol-name (car olist))
1768 (if (or (consp (setq sym (symbol-value (car olist))))
1770 (not (or (eq sym nil)
1773 (prin1-to-string (symbol-value (car olist))) ")\n")
1774 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
1775 (setq olist (cdr olist)))
1777 ;; Remove any null chars - they seem to cause trouble for some
1778 ;; mailers. (Byte-compiled output from the stuff above.)
1779 (goto-char (point-min))
1780 (while (re-search-forward "[\000\200]" nil t)
1781 (replace-match "" t t))))
1787 ;;; gnus-msg.el ends here