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.
31 (defvar gnus-organization-file "/usr/lib/news/organization"
32 "*Local news organization file.")
34 (defvar gnus-post-prepare-function nil
35 "*Function that is run after a post buffer has been prepared.
36 It is called with the name of the newsgroup that is posted to. It
37 might be used, for instance, for inserting signatures based on the
38 newsgroup name. (In that case, `gnus-signature-file' and
39 `mail-signature' should both be set to nil).")
41 (defvar gnus-post-prepare-hook nil
42 "*Hook that is run after a post buffer has been prepared.
43 If you want to insert the signature, you might put
44 `gnus-inews-insert-signature' in this hook.")
46 (defvar gnus-use-followup-to 'use
47 "*Specifies what to do with Followup-To header.
48 If nil, ignore the header. If it is t, use its value, but ignore
49 `poster'. If it is neither nil nor t, which is the default, always use
52 (defvar gnus-followup-to-function nil
53 "*A variable that contains a function that returns a followup address.
54 The function will be called in the buffer of the article that is being
55 followed up. The buffer will be narrowed to the headers of the
56 article. To pick header headers, one might use `mail-fetch-field'. The
57 function will be called with the name of the current newsgroup as the
60 Here's an example `gnus-followup-to-function':
62 (setq gnus-followup-to-function
64 (cond ((string= group \"mail.list\")
65 (or (mail-fetch-field \"sender\")
66 (mail-fetch-field \"from\")))
68 (or (mail-fetch-field \"reply-to\")
69 (mail-fetch-field \"from\"))))))")
71 (defvar gnus-reply-to-function nil
72 "*A variable that contains a function that returns a reply address.
73 See the `gnus-followup-to-function' variable for an explanation of how
74 this variable is used.
76 This function should return a string that will be used to fill in the
77 header. This function may also return a list. In that case, every
78 list element should be a cons where the first car should be a string
79 with the header name, and the cdr should be a string with the header
82 (defvar gnus-author-copy (getenv "AUTHORCOPY")
83 "*Save outgoing articles in this file.
84 Initialized from the AUTHORCOPY environment variable.
86 If this variable begins with the character \"|\", outgoing articles
87 will be piped to the named program. It is possible to save an article
88 in an MH folder as follows:
90 \(setq gnus-author-copy \"|/usr/local/lib/mh/rcvstore +Article\")
92 If the first character is not a pipe, articles are saved using the
93 function specified by the `gnus-author-copy-saver' variable.")
95 (defvar gnus-mail-self-blind nil
96 "*Non-nil means insert a BCC header in all outgoing articles.
97 This will result in having a copy of the article mailed to yourself.
98 The BCC header is inserted when the post buffer is initialized, so you
99 can remove or alter the BCC header to override the default.")
101 (defvar gnus-author-copy-saver (function rmail-output)
102 "*A function called to save outgoing articles.
103 This function will be called with the same of the file to store the
104 article in. The default function is `rmail-output' which saves in Unix
107 (defvar gnus-user-login-name nil
108 "*The login name of the user.
109 Got from the function `user-login-name' if undefined.")
111 (defvar gnus-user-full-name nil
112 "*The full name of the user.
113 Got from the NAME environment variable if undefined.")
115 (defvar gnus-user-from-line nil
116 "*Your full, complete e-mail address.
117 Overrides the other Gnus variables if it is non-nil.
119 Here are two example values of this variable:
121 \"Lars Magne Ingebrigtsen <larsi@ifi.uio.no>\"
125 \"larsi@ifi.uio.no (Lars Magne Ingebrigtsen)\"
127 The first version is recommended, but the name has to be quoted if it
128 contains non-alphanumerical characters.")
130 (defvar gnus-signature-file "~/.signature"
131 "*Your signature file.
132 If the variable is a string that doesn't correspond to a file, the
133 string itself is inserted.")
135 (defvar gnus-signature-function nil
136 "*A function that should return a signature file name.
137 The function will be called with the name of the newsgroup being
139 If the function returns a string that doesn't correspond to a file, the
140 string itself is inserted.
141 If the function returns nil, the `gnus-signature-file' variable will
144 (defvar gnus-required-headers
145 '(From Date Newsgroups Subject Message-ID Organization Lines X-Newsreader)
146 "*Headers to be generated or prompted for when posting an article.
147 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
148 Message-ID. Organization, Lines and X-Newsreader are optional. If
149 you want Gnus not to insert some header, remove it from this list.")
151 (defvar gnus-deletable-headers '(Message-ID)
152 "*Headers to be deleted if they already exists.")
154 (defvar gnus-check-before-posting
155 '(subject-cmsg multiple-headers sendsys message-id from
156 long-lines control-chars size new-text
158 "In non-nil, Gnus will attempt to run some checks on outgoing posts.
159 If this variable is t, Gnus will check everything it can. If it is a
160 list, then those elements in that list will be checked.")
162 (defvar gnus-delete-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:"
163 "*Header lines matching this regexp will be deleted before posting.
164 It's best to delete old Path and Date headers before psoting to avoid
167 (defvar gnus-auto-mail-to-author nil
168 "*If non-nil, mail the authors of articles a copy of your follow-ups.
169 If this variable is `ask', the user will be prompted for whether to
170 mail a copy. The string given by `gnus-mail-courtesy-message' will be
171 inserted at the beginning of the mail copy.
173 Mail is sent using the function specified by the
174 `gnus-mail-send-method' variable.")
176 ;; Added by Ethan Bradford <ethanb@ptolemy.astro.washington.edu>.
177 (defvar gnus-mail-courtesy-message
178 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
179 "*This is inserted at the start of a mailed copy of a posted message.
180 If this variable is nil, no such courtesy message will be added.")
182 (defvar gnus-mail-reply-method (function gnus-mail-reply-using-mail)
183 "*Function to compose a reply.
184 Three pre-made functions are `gnus-mail-reply-using-mail' (sendmail);
185 `gnus-mail-reply-using-mhe' (MH-E); and `gnus-mail-reply-using-vm'.")
187 (defvar gnus-mail-forward-method (function gnus-mail-forward-using-mail)
188 "*Function to forward the current message to another user.
189 Three pre-made functions are `gnus-mail-forward-using-mail' (sendmail);
190 `gnus-mail-forward-using-mhe' (MH-E); and `gnus-mail-forward-using-vm'.")
192 (defvar gnus-mail-other-window-method 'gnus-mail-other-window-using-mail
193 "*Function to compose mail in the other window.
194 Three pre-made functions are `gnus-mail-other-window-using-mail'
195 (sendmail); `gnus-mail-other-window-using-mhe' (MH-E); and
196 `gnus-mail-other-window-using-vm'.")
198 (defvar gnus-mail-send-method send-mail-function
199 "*Function to mail a message which is also being posted as an article.
200 The message must have To or Cc header. The default is copied from
201 the variable `send-mail-function'.")
203 (defvar gnus-inews-article-function 'gnus-inews-article
204 "*Function to post an article.")
206 (defvar gnus-inews-article-hook (list 'gnus-inews-do-fcc)
207 "*A hook called before finally posting an article.
208 The default hook (`gnus-inews-do-fcc') does FCC processing (ie. saves
209 the article to a file).")
211 (defvar gnus-inews-article-header-hook nil
212 "*A hook called after inserting the headers in an article to be posted.
213 The hook is called from the *post-news* buffer, narrowed to the
216 (defvar gnus-mail-hook nil
217 "*A hook called as the last thing after setting up a mail buffer.")
219 ;;; Internal variables.
221 (defvar gnus-post-news-buffer "*post-news*")
222 (defvar gnus-mail-buffer "*mail*")
223 (defvar gnus-summary-send-map nil)
224 (defvar gnus-article-copy nil)
225 (defvar gnus-reply-subject nil)
229 ;;; Gnus Posting Functions
232 (define-prefix-command 'gnus-summary-send-map)
233 (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
234 (define-key gnus-summary-send-map "p" 'gnus-summary-post-news)
235 (define-key gnus-summary-send-map "f" 'gnus-summary-followup)
236 (define-key gnus-summary-send-map "F" 'gnus-summary-followup-with-original)
237 (define-key gnus-summary-send-map "b" 'gnus-summary-followup-and-reply)
238 (define-key gnus-summary-send-map "B" 'gnus-summary-followup-and-reply-with-original)
239 (define-key gnus-summary-send-map "c" 'gnus-summary-cancel-article)
240 (define-key gnus-summary-send-map "s" 'gnus-summary-supersede-article)
241 (define-key gnus-summary-send-map "r" 'gnus-summary-reply)
242 (define-key gnus-summary-send-map "R" 'gnus-summary-reply-with-original)
243 (define-key gnus-summary-send-map "m" 'gnus-summary-mail-other-window)
244 (define-key gnus-summary-send-map "u" 'gnus-uu-post-news)
245 (define-key gnus-summary-send-map "om" 'gnus-summary-mail-forward)
246 (define-key gnus-summary-send-map "op" 'gnus-summary-post-forward)
247 (define-key gnus-summary-send-map "Om" 'gnus-uu-digest-mail-forward)
248 (define-key gnus-summary-send-map "Op" 'gnus-uu-digest-post-forward)
250 ;;; Internal functions.
252 (defun gnus-number-base36 (num len)
253 (if (if (< len 0) (<= num 0) (= len 0))
255 (concat (gnus-number-base36 (/ num 36) (1- len))
256 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
259 ;;; Post news commands of Gnus group mode and summary mode
261 (defun gnus-group-mail ()
262 "Start composing a mail."
264 (funcall gnus-mail-other-window-method)
265 (gnus-configure-windows 'group-mail)
266 (run-hooks 'gnus-mail-hook))
268 (defun gnus-group-post-news ()
271 (let ((gnus-newsgroup-name nil))
272 (gnus-post-news 'post nil nil gnus-article-buffer)))
274 (defun gnus-summary-post-news ()
277 (gnus-set-global-variables)
278 (gnus-post-news 'post gnus-newsgroup-name))
280 (defun gnus-summary-followup (yank &optional yank-articles)
281 "Compose a followup to an article.
282 If prefix argument YANK is non-nil, original article is yanked automatically."
284 (gnus-set-global-variables)
285 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
286 (save-window-excursion
287 (gnus-summary-select-article t))
288 (let ((headers gnus-current-headers)
289 (gnus-newsgroup-name gnus-newsgroup-name))
290 ;; Check Followup-To: poster.
291 (set-buffer gnus-article-buffer)
292 (if (and gnus-use-followup-to
293 (string-equal "poster" (gnus-fetch-field "followup-to"))
294 (or (not (eq gnus-use-followup-to t))
296 "Do you want to ignore `Followup-To: poster'? "))))
297 ;; Mail to the poster. Gnus is now RFC1036 compliant.
298 (gnus-summary-reply yank)
299 (gnus-post-news nil gnus-newsgroup-name
300 headers gnus-article-buffer
301 (or yank-articles (not (not yank))))))
302 (gnus-article-hide-headers-if-wanted))
304 (defun gnus-summary-followup-with-original (n)
305 "Compose a followup to an article and include the original article."
307 (gnus-summary-followup t (gnus-summary-work-articles n)))
309 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
310 (defun gnus-summary-followup-and-reply (yank &optional yank-articles)
311 "Compose a followup and do an auto mail to author."
313 (gnus-set-global-variables)
314 (let ((gnus-auto-mail-to-author t))
315 (gnus-summary-followup yank yank-articles)))
317 (defun gnus-summary-followup-and-reply-with-original (n)
318 "Compose a followup, include the original, and do an auto mail to author."
320 (gnus-summary-followup-and-reply t (gnus-summary-work-articles n)))
322 (defun gnus-summary-cancel-article (n)
323 "Cancel an article you posted."
325 (gnus-set-global-variables)
326 (let ((articles (gnus-summary-work-articles n)))
328 (gnus-summary-select-article t nil nil (car articles))
329 (gnus-eval-in-buffer-window gnus-article-buffer (gnus-cancel-news))
330 (gnus-summary-remove-process-mark (car articles))
331 (gnus-summary-mark-as-read (car articles) gnus-canceled-mark)
332 (gnus-article-hide-headers-if-wanted)
333 (setq articles (cdr articles)))))
335 (defun gnus-summary-supersede-article ()
336 "Compose an article that will supersede a previous article.
337 This is done simply by taking the old article and adding a Supersedes
338 header line with the old Message-ID."
340 (gnus-set-global-variables)
341 (gnus-summary-select-article t)
344 (downcase (mail-strip-quoted-names
345 (header-from gnus-current-headers)))
346 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
347 (error "This article is not yours."))
349 (set-buffer gnus-article-buffer)
350 (let ((buffer-read-only nil))
351 (goto-char (point-min))
352 (search-forward "\n\n" nil t)
353 (if (not (re-search-backward "^Message-ID: " nil t))
354 (error "No Message-ID in this article"))))
355 (if (gnus-post-news 'post gnus-newsgroup-name)
358 (insert-buffer gnus-article-buffer)
359 (goto-char (point-min))
360 (search-forward "\n\n" nil t)
361 (if (not (re-search-backward "^Message-ID: " nil t))
362 (error "No Message-ID in this article")
363 (replace-match "Supersedes: " t t))
364 (search-forward "\n\n")
366 (insert mail-header-separator)
369 (narrow-to-region (point-min) (point))
370 (goto-char (point-min))
371 (and gnus-delete-supersedes-headers
372 (delete-matching-lines gnus-delete-supersedes-headers))
377 (defalias 'sendnews 'gnus-post-news)
380 (defalias 'postnews 'gnus-post-news)
382 (defun gnus-copy-article-buffer (&optional article-buffer)
383 ;; make a copy of the article buffer with all text properties removed
384 ;; this copy is in the buffer gnus-article-copy.
385 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
386 ;; this buffer should be passed to all mail/news reply/post routines.
387 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
388 (buffer-disable-undo gnus-article-copy)
389 (or (memq gnus-article-copy gnus-buffer-list)
390 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
391 (let ((article-buffer (or article-buffer gnus-article-buffer)))
392 (if (and (get-buffer article-buffer)
393 (buffer-name (get-buffer article-buffer)))
395 (set-buffer article-buffer)
397 (copy-to-buffer gnus-article-copy (point-min) (point-max))
398 (set-text-properties (point-min) (point-max)
399 nil gnus-article-copy)))))
401 (defun gnus-post-news (post &optional group header article-buffer yank subject)
402 "Begin editing a new USENET news article to be posted.
403 Type \\[describe-mode] in the buffer to get a list of commands."
404 (interactive (list t))
405 (gnus-copy-article-buffer article-buffer)
406 (if (or (not gnus-novice-user)
410 (format "%s" (car (gnus-find-method-for-group
411 gnus-newsgroup-name)))
412 gnus-valid-select-methods))))
415 (nth 5 (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))))
416 (gnus-y-or-n-p "Are you sure you want to post to all of USENET? "))
417 (let ((sumart (if (not post)
419 (set-buffer gnus-summary-buffer)
420 (cons (current-buffer) gnus-current-article))))
421 (from (and header (header-from header)))
422 (winconf (current-window-configuration))
423 follow-to real-group)
424 (and gnus-interactive-post
425 (not gnus-expert-user)
429 (completing-read "Group: " gnus-active-hashtb))
431 (setq subject (read-string "Subject: ")))))
432 (setq mail-reply-buffer gnus-article-copy)
434 (let ((newsgroup-name (or group gnus-newsgroup-name "")))
435 (setq real-group (and group (gnus-group-real-name group)))
436 (setq gnus-post-news-buffer
437 (gnus-request-post-buffer
438 post real-group subject header gnus-article-copy
439 (nth 2 (and group (gnus-gethash group gnus-newsrc-hashtb)))
440 (or (cdr (assq 'to-group
441 (nth 5 (nth 2 (gnus-gethash
443 gnus-newsrc-hashtb)))))
444 (if (and (boundp 'gnus-followup-to-function)
445 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))
536 ;; Connect to default NNTP server if necessary.
537 ;; Suggested by yuki@flab.fujitsu.junet.
538 (gnus-start-news-server) ;Use default server.
539 ;; NNTP server must be opened before current buffer is modified.
541 (goto-char (point-min))
542 (run-hooks 'news-inews-hook)
547 (goto-char (point-min))
549 (concat "^" (regexp-quote mail-header-separator) "$"))
550 (match-beginning 0)))
552 ;; Correct newsgroups field: change sequence of spaces to comma and
553 ;; eliminate spaces around commas. Eliminate imbedded line breaks.
554 (goto-char (point-min))
555 (if (search-forward-regexp "^Newsgroups: +" nil t)
559 (if (re-search-forward "^[^ \t]" nil 'end)
562 (goto-char (point-min))
563 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
564 (goto-char (point-min))
565 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ",")))
567 ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
568 ;; Help save the the world!
571 (let ((newsgroups (mail-fetch-field "newsgroups"))
572 (followup-to (mail-fetch-field "followup-to"))
574 (if (and (string-match "," newsgroups) (not followup-to))
576 (while (string-match "," newsgroups)
578 (cons (list (substring newsgroups
579 0 (match-beginning 0)))
581 (setq newsgroups (substring newsgroups (match-end 0))))
582 (setq groups (nreverse (cons (list newsgroups) groups)))
585 (completing-read "Followups to: (default all groups) "
587 (if (> (length to) 0)
589 (goto-char (point-min))
590 (insert "Followup-To: " to "\n")))))))
592 ;; Cleanup Followup-To.
593 (goto-char (point-min))
594 (if (search-forward-regexp "^Followup-To: +" nil t)
598 (if (re-search-forward "^[^ \t]" nil 'end)
601 (goto-char (point-min))
602 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
603 (goto-char (point-min))
604 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ",")))
606 ;; Mail the message too if To:, Bcc:. or Cc: exists.
607 (let* ((types '("to" "bcc" "cc"))
611 (or (mail-fetch-field (car ty) nil t)
612 (setq types (delete (car ty) types)))
616 ;; We do not want to send mail.
618 (if (not gnus-mail-send-method)
622 1 "No mailer defined. To: and/or Cc: fields ignored.")
625 ;; We want to remove Fcc, because we want to handle
626 ;; that one ourselves...
628 (goto-char (point-min))
629 (if (re-search-forward "^Fcc: " nil t)
633 (progn (beginning-of-line) (point))
634 (progn (forward-line 1) (point))))
638 ;; We generate a Message-ID so that the mail and the
639 ;; news copy of the message both get the same ID.
640 (or (mail-fetch-field "message-id")
642 (goto-char (point-max))
643 (insert "Message-ID: " (gnus-inews-message-id) "\n")))
647 (gnus-message 5 "Sending via mail...")
649 (if (and gnus-mail-courtesy-message
650 (or (member "to" types)
651 (member "cc" types)))
652 ;; We only want to insert the courtesy mail
653 ;; message if we use to or cc; bcc should not
654 ;; have one. Well, if both bcc and to are
655 ;; present, it will get one anyway.
657 ;; Insert "courtesy" mail message.
658 (goto-char (point-min))
660 (concat "^" (regexp-quote
661 mail-header-separator) "$"))
663 (insert gnus-mail-courtesy-message)
664 (funcall gnus-mail-send-method)
665 (goto-char (point-min))
666 (search-forward gnus-mail-courtesy-message)
667 (replace-match "" t t))
668 (funcall gnus-mail-send-method))
670 (gnus-message 5 "Sending via mail...done")
672 (goto-char (point-min))
676 (concat "^" (regexp-quote mail-header-separator) "$")))
677 (goto-char (point-min))
678 (delete-matching-lines "^BCC:"))
681 (goto-char (point-max))
682 (insert fcc-line))))))))
685 (gnus-message 5 "Posting to USENET...")
686 (if (funcall gnus-inews-article-function use-group-method)
688 (gnus-message 5 "Posting to USENET...done")
689 (if (gnus-buffer-exists-p (car-safe reply))
692 (set-buffer gnus-summary-buffer)
693 (gnus-summary-mark-article-as-replied
695 ;; We cannot signal an error.
696 (ding) (gnus-message 1 "Article rejected: %s"
697 (gnus-status-message gnus-select-method)))
698 (set-buffer-modified-p nil))
699 ;; If NNTP server is opened by gnus-inews-news, close it by myself.
701 (gnus-close-server (gnus-find-method-for-group gnus-newsgroup-name)))
702 (let ((conf gnus-prev-winconf))
704 ;; Restore last window configuration.
705 (and conf (set-window-configuration conf)))))
707 (defun gnus-inews-check-post ()
708 "Check whether the post looks ok."
710 (not gnus-check-before-posting)
712 ;; We narrow to the headers and check them first.
715 (goto-char (point-min))
719 (concat "^" (regexp-quote mail-header-separator) "$")))
720 (goto-char (point-min))
722 ;; Check for commands in Subject.
723 (or (gnus-check-before-posting 'subject-cmsg)
725 (if (string-match "^cmsg " (mail-fetch-field "subject"))
727 "The control code \"cmsg \" is in the subject. Really post? ")
729 ;; Check for multiple identical headers.
730 (or (gnus-check-before-posting 'multiple-headers)
733 (while (and (not found) (re-search-forward "^[^ \t:]+: " nil t))
735 (or (re-search-forward
736 (concat "^" (setq found
739 (- (match-end 0) 2))))
744 (format "Multiple %s headers. Really post? " found))
746 ;; Check for version and sendsys.
747 (or (gnus-check-before-posting 'sendsys)
749 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
751 (format "The article contains a %s command. Really post? "
752 (buffer-substring (match-beginning 0)
753 (1- (match-end 0)))))
755 ;; Check the Message-Id header.
756 (or (gnus-check-before-posting 'message-id)
758 (let* ((case-fold-search t)
759 (message-id (mail-fetch-field "message-id")))
761 (and (string-match "@" message-id)
762 (string-match "@[^\\.]*\\." message-id))
765 "The Message-ID looks strange: \"%s\". Really post? "
767 ;; Check the From header.
768 (or (gnus-check-before-posting 'from)
770 (let* ((case-fold-search t)
771 (from (mail-fetch-field "from")))
773 (and (string-match "@" from)
774 (string-match "@[^\\.]*\\." from))
776 (format "The From looks strange: \"%s\". Really post? "
778 ;; Check for long lines.
779 (or (gnus-check-before-posting 'long-lines)
781 (goto-char (point-min))
783 (concat "^" (regexp-quote mail-header-separator) "$"))
787 (< (current-column) 80))
788 (zerop (forward-line 1))))
793 "You have lines longer than 79 characters. Really post? ")))))
794 ;; Check for control characters.
795 (or (gnus-check-before-posting 'control-chars)
797 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
799 "The article contains control characters. Really post? ")
801 ;; Check excessive size.
802 (or (gnus-check-before-posting 'size)
803 (if (> (buffer-size) 60000)
805 (format "The article is %d octets long. Really post? "
808 ;; Use the (size . checksum) variable to see whether the
809 ;; article is empty or has only quoted text.
810 (or (gnus-check-before-posting 'new-text)
811 (if (and (= (buffer-size) (car gnus-article-check-size))
812 (= (gnus-article-checksum) (cdr gnus-article-check-size)))
814 "It looks like there's no new text in your article. Really post? ")
816 ;; Check the length of the signature.
817 (or (gnus-check-before-posting 'signature)
819 (goto-char (point-max))
820 (if (not (re-search-backward gnus-signature-separator nil t))
822 (if (> (count-lines (point) (point-max)) 4)
825 "Your .sig is %d lines; it should be max 4. Really post? "))
828 (defun gnus-article-checksum ()
832 (setq sum (logxor sum (following-char)))
836 ;; Returns non-nil if this type is not to be checked.
837 (defun gnus-check-before-posting (type)
838 (or (not gnus-check-before-posting)
839 (if (listp gnus-check-before-posting)
840 (memq type gnus-check-before-posting)
843 (defun gnus-cancel-news ()
844 "Cancel an article you posted."
846 (if (or gnus-expert-user
847 (gnus-yes-or-no-p "Do you really want to cancel this article? "))
852 (or (gnus-member-of-valid 'post gnus-newsgroup-name)
853 (error "This backend does not support canceling"))
855 ;; Get header info. from original article.
857 (gnus-article-show-all-headers)
858 (goto-char (point-min))
859 (search-forward "\n\n" nil 'move)
860 (narrow-to-region (point-min) (point))
861 (setq from (mail-fetch-field "from"))
862 (setq newsgroups (mail-fetch-field "newsgroups"))
863 (setq message-id (mail-fetch-field "message-id"))
864 (setq distribution (mail-fetch-field "distribution")))
865 ;; Verify if the article is absolutely user's by comparing
866 ;; user id with value of its From: field.
869 (downcase (mail-strip-quoted-names from))
870 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
872 (ding) (gnus-message 3 "This article is not yours."))
873 ;; Make control article.
874 (set-buffer (get-buffer-create " *Gnus-canceling*"))
875 (buffer-disable-undo (current-buffer))
877 (insert "Newsgroups: " newsgroups "\n"
878 "Subject: cancel " message-id "\n"
879 "Control: cancel " message-id "\n"
880 mail-header-separator "\n"
881 "This is a cancel message from " from ".\n")
882 ;; Send the control article to NNTP server.
883 (gnus-message 5 "Canceling your article...")
884 (if (funcall gnus-inews-article-function)
885 (gnus-message 5 "Canceling your article...done")
887 (gnus-message 1 "Cancel failed; %s"
888 (gnus-status-message gnus-newsgroup-name)))
889 ;; Kill the article buffer.
890 (kill-buffer (current-buffer)))))))
893 ;;; Lowlevel inews interface
895 (defun gnus-inews-article (&optional use-group-method)
896 "Post an article in current buffer using NNTP protocol."
897 (let ((artbuf (current-buffer))
898 (tmpbuf (get-buffer-create " *Gnus-posting*")))
900 (goto-char (point-max))
901 ;; require a newline at the end for inews to append .signature to
902 (or (= (preceding-char) ?\n)
904 ;; Prepare article headers. All message body such as signature
905 ;; must be inserted before Lines: field is prepared.
907 (goto-char (point-min))
912 (concat "^" (regexp-quote mail-header-separator) "$"))
913 (match-beginning 0)))
914 (gnus-inews-remove-headers)
915 (gnus-inews-insert-headers)
916 (run-hooks gnus-inews-article-header-hook)
918 ;; Check whether the article is a good Net Citizen.
919 (if (and gnus-article-check-size
920 (not (gnus-inews-check-post)))
923 ;; Looks ok, so we do the nasty.
926 (buffer-disable-undo (current-buffer))
928 (insert-buffer-substring artbuf)
929 ;; Remove the header separator.
930 (goto-char (point-min))
932 (concat "^" (regexp-quote mail-header-separator) "$"))
933 (replace-match "" t t)
934 ;; This hook may insert a signature.
935 (run-hooks 'gnus-prepare-article-hook)
936 ;; Run final inews hooks. This hook may do FCC.
937 ;; The article must be saved before being posted because
938 ;; `gnus-request-post' modifies the buffer.
939 (run-hooks 'gnus-inews-article-hook)
940 ;; Post an article to NNTP server.
941 ;; Return NIL if post failed.
945 (gnus-find-method-for-group gnus-newsgroup-name)
946 gnus-select-method) use-group-method)
947 (kill-buffer (current-buffer)))))))
949 (defun gnus-inews-remove-headers ()
950 (let ((case-fold-search t))
951 ;; Remove NNTP-posting-host.
952 (goto-char (point-min))
953 (and (re-search-forward "^nntp-posting-host:" nil t)
954 (delete-region (progn (beginning-of-line) (point))
955 (progn (forward-line 1) (point))))
957 (goto-char (point-min))
958 (and (re-search-forward "^bcc:" nil t)
959 (delete-region (progn (beginning-of-line) (point))
960 (progn (forward-line 1) (point))))))
962 (defun gnus-inews-insert-headers ()
963 "Prepare article headers.
964 Headers already prepared in the buffer are not modified.
965 Headers in `gnus-required-headers' will be generated."
966 (let ((Date (gnus-inews-date))
967 (Message-ID (gnus-inews-message-id))
968 (Organization (gnus-inews-organization))
969 (From (gnus-inews-user-name))
970 (Path (gnus-inews-path))
974 (Lines (gnus-inews-lines))
975 (X-Newsreader gnus-version)
976 (headers gnus-required-headers)
979 ;; First we remove any old generated headers.
980 (let ((headers gnus-deletable-headers))
982 (goto-char (point-min))
983 (and (re-search-forward
984 (concat "^" (symbol-name (car headers)) ": *") nil t)
985 (get-text-property (1+ (match-end 0)) 'gnus-deletable)
987 (setq headers (cdr headers))))
988 ;; Insert new Sender if the From is strange.
989 (let ((from (mail-fetch-field "from")))
990 (if (and from (not (string= (downcase from) (downcase From))))
992 (goto-char (point-min))
993 (and (re-search-forward "^Sender:" nil t)
994 (delete-region (progn (beginning-of-line) (point))
995 (progn (forward-line 1) (point))))
996 (insert "Sender: " From "\n"))))
997 ;; If there are References, and no "Re: ", then the thread has
998 ;; changed name. See Son-of-1036.
999 (if (and (mail-fetch-field "references")
1000 (get-buffer gnus-article-buffer))
1001 (let ((psubject (gnus-simplify-subject-re
1002 (mail-fetch-field "subject"))))
1003 (or (and psubject gnus-reply-subject
1004 (string= (gnus-simplify-subject-re gnus-reply-subject)
1007 (string-match "@" Message-ID)
1009 (concat (substring Message-ID 0 (match-beginning 0))
1011 (substring Message-ID (match-beginning 0))))))))
1012 ;; Go through all the required headers and see if they are in the
1013 ;; articles already. If they are not, or are empty, they are
1014 ;; inserted automatically - except for Subject, Newsgroups and
1017 (goto-char (point-min))
1018 (setq elem (car headers))
1020 (setq header (car elem))
1022 (if (or (not (re-search-forward
1023 (concat "^" (downcase (symbol-name header)) ":") nil t))
1025 (if (= (following-char) ? ) (forward-char 1) (insert " "))
1026 (looking-at "[ \t]*$")))
1029 (or (if (consp elem)
1030 ;; The element is a cons. Either the cdr is
1031 ;; a string to be inserted verbatim, or it
1032 ;; is a function, and we insert the value
1033 ;; returned from this function.
1034 (or (and (stringp (cdr elem)) (cdr elem))
1035 (and (fboundp (cdr elem)) (funcall (cdr elem))))
1036 ;; The element is a symbol. We insert the
1037 ;; value of this symbol, if any.
1038 (and (boundp header) (symbol-value header)))
1039 ;; We couldn't generate a value for this header,
1040 ;; so we just ask the user.
1041 (read-from-minibuffer
1042 (format "Empty header for %s; enter value: " header))))
1043 ;; Add the deletable property to the headers that require it.
1044 (and (memq header gnus-deletable-headers)
1045 (add-text-properties
1046 0 (length value) '(gnus-deletable t) value))
1047 ;; Finally insert the header.
1050 (goto-char (point-max))
1051 (insert (symbol-name header) ": " value "\n"))
1052 (replace-match value t t))))
1053 (setq headers (cdr headers)))))
1055 (defun gnus-inews-insert-signature ()
1056 "Insert a signature file.
1057 If `gnus-signature-function' is bound and returns a string, this
1058 string is used instead of the variable `gnus-signature-file'.
1059 In either case, if the string is a file name, this file is
1060 inserted. If the string is not a file name, the string itself is
1062 If you never want any signature inserted, set both those variables to
1066 (or (and gnus-signature-function
1067 (fboundp gnus-signature-function)
1068 (funcall gnus-signature-function gnus-newsgroup-name))
1069 gnus-signature-file))
1072 (or (file-exists-p signature)
1073 (string-match " " signature)
1075 "^/[^/]+/" (expand-file-name signature)))))
1077 (goto-char (point-max))
1078 (if (and mail-signature (search-backward "\n-- \n" nil t))
1080 ;; Delete any previous signatures.
1081 (if (search-backward "\n-- \n" nil t)
1082 (delete-region (1+ (point)) (point-max)))
1084 (if (file-exists-p signature)
1085 (insert-file-contents signature)
1087 (goto-char (point-max))
1088 (or (bolp) (insert "\n"))))))))
1090 (defun gnus-inews-do-fcc ()
1091 "Process FCC: fields in current article buffer.
1092 Unless the first character of the field is `|', the article is saved
1093 to the specified file using the function specified by the variable
1094 gnus-author-copy-saver. The default function rmail-output saves in
1095 Unix mailbox format.
1096 If the first character is `|', the contents of the article is send to
1097 a program specified by the rest of the value."
1098 (let ((fcc-list nil)
1100 (case-fold-search t)) ;Should ignore case.
1103 (goto-char (point-min))
1104 (search-forward "\n\n")
1105 (narrow-to-region (point-min) (point))
1106 (goto-char (point-min))
1107 (while (re-search-forward "^FCC:[ \t]*" nil t)
1109 (cons (buffer-substring
1113 (skip-chars-backward " \t")
1116 (delete-region (match-beginning 0)
1117 (progn (forward-line 1) (point))))
1118 ;; Process FCC operations.
1121 (setq fcc-file (car fcc-list))
1122 (setq fcc-list (cdr fcc-list))
1123 (cond ((string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" fcc-file)
1124 (let ((program (substring fcc-file
1125 (match-beginning 1) (match-end 1))))
1126 ;; Suggested by yuki@flab.fujitsu.junet.
1127 ;; Send article to named program.
1128 (call-process-region (point-min) (point-max) shell-file-name
1129 nil nil nil "-c" program)))
1131 ;; Suggested by hyoko@flab.fujitsu.junet.
1132 ;; Save article in Unix mail format by default.
1133 (gnus-make-directory (file-name-directory fcc-file))
1134 (if (and gnus-author-copy-saver
1135 (not (eq gnus-author-copy-saver 'rmail-output)))
1136 (funcall gnus-author-copy-saver fcc-file)
1137 (if (and (file-readable-p fcc-file) (rmail-file-p fcc-file))
1138 (gnus-output-to-rmail fcc-file)
1139 (rmail-output fcc-file 1 t t))))))))))
1141 (defun gnus-inews-path ()
1143 (let ((login-name (gnus-inews-login-name)))
1144 (cond ((null gnus-use-generic-path)
1145 (concat (nth 1 gnus-select-method) "!" login-name))
1146 ((stringp gnus-use-generic-path)
1147 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1148 (concat gnus-use-generic-path "!" login-name))
1151 (defun gnus-inews-user-name ()
1152 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1153 (let ((full-name (gnus-inews-full-name)))
1154 (or gnus-user-from-line
1155 (concat (if (or gnus-user-login-name gnus-use-generic-from
1156 gnus-local-domain (getenv "DOMAINNAME"))
1157 (concat (gnus-inews-login-name) "@"
1158 (gnus-inews-domain-name gnus-use-generic-from))
1160 ;; User's full name.
1161 (cond ((string-equal full-name "") "")
1162 ((string-equal full-name "&") ;Unix hack.
1163 (concat " (" (user-login-name) ")"))
1165 (concat " (" full-name ")")))))))
1167 (defun gnus-inews-login-name ()
1168 "Return login name."
1169 (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1171 (defun gnus-inews-full-name ()
1172 "Return full user name."
1173 (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1175 (defun gnus-inews-domain-name (&optional genericfrom)
1176 "Return user's domain name.
1177 If optional argument GENERICFROM is a string, use it as the domain
1178 name; if it is non-nil, strip off local host name from the domain name.
1179 If the function `system-name' returns full internet name and the
1180 domain is undefined, the domain name is got from it."
1181 (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1182 (let* ((system-name (system-name))
1184 (or (if (stringp genericfrom) genericfrom)
1185 (getenv "DOMAINNAME")
1187 ;; Function `system-name' may return full internet name.
1188 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1189 (if (string-match "\\." system-name)
1190 (substring system-name (match-end 0)))
1191 (read-string "Domain name (no host): ")))
1192 (host (or (if (string-match "\\." system-name)
1193 (substring system-name 0 (match-beginning 0)))
1195 (if (string-equal "." (substring domain 0 1))
1196 (setq domain (substring domain 1)))
1197 ;; Support GENERICFROM as same as standard Bnews system.
1198 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1199 (cond ((null genericfrom)
1200 (concat host "." domain))
1201 ;;((stringp genericfrom) genericfrom)
1203 (if (string-match "\\." (system-name))
1205 (substring user-mail-address
1206 (1+ (string-match "@" user-mail-address))))))
1208 (defun gnus-inews-full-address ()
1209 (let ((domain (gnus-inews-domain-name))
1210 (system (system-name))
1211 (case-fold-search t))
1212 (if (string-match "\\." system) system
1213 (if (string-match (concat "^" (regexp-quote system)) domain) domain
1214 (concat system "." domain)))))
1216 (defun gnus-inews-message-id ()
1217 "Generate unique Message-ID for user."
1218 ;; Message-ID should not contain a slash and should be terminated by
1219 ;; a number. I don't know the reason why it is so.
1220 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1222 (defvar gnus-unique-id-char nil)
1224 ;; If you ever change this function, make sure the new version
1225 ;; cannot generate IDs that the old version could.
1226 ;; You might for example insert a "." somewhere (not next to another dot
1227 ;; or string boundary), or modify the newsreader name to "Ding".
1228 (defun gnus-inews-unique-id ()
1229 ;; Dont use microseconds from (current-time), they may be unsupported.
1230 ;; Instead we use this randomly inited counter.
1231 (setq gnus-unique-id-char
1232 (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1233 ;; (current-time) returns 16-bit ints,
1234 ;; and 2^16*25 just fits into 4 digits i base 36.
1236 (let ((tm (if (fboundp 'current-time)
1237 (current-time) '(12191 46742 287898))))
1239 (if (memq system-type '(ms-dos emx vax-vms))
1240 (let ((user (downcase (gnus-inews-login-name))))
1241 (while (string-match "[^a-z0-9_]" user)
1242 (aset user (match-beginning 0) ?_))
1244 (gnus-number-base36 (user-uid) -1))
1245 (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1246 (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1247 ;; Append the newsreader name, because while the generated
1248 ;; ID is unique to this newsreader, other newsreaders might
1249 ;; otherwise generate the same ID via another algorithm.
1253 (defun gnus-inews-date ()
1254 "Current time string."
1255 (timezone-make-date-arpa-standard
1256 (current-time-string) (current-time-zone)))
1258 (defun gnus-inews-organization ()
1259 "Return user's organization.
1260 The ORGANIZATION environment variable is used if defined.
1261 If not, the variable `gnus-local-organization' is used instead.
1262 If it is a function, the function will be called with the current
1263 newsgroup name as the argument.
1264 If this is a file name, the contents of this file will be used as the
1266 (let* ((organization
1267 (or (getenv "ORGANIZATION")
1268 (if gnus-local-organization
1269 (if (and (symbolp gnus-local-organization)
1270 (fboundp gnus-local-organization))
1271 (funcall gnus-local-organization gnus-newsgroup-name)
1272 gnus-local-organization))
1273 gnus-organization-file
1274 "~/.organization")))
1275 (and (stringp organization)
1276 (> (length organization) 0)
1277 (or (file-exists-p organization)
1278 (string-match " " organization)
1279 (not (string-match "^/usr/lib/" organization)))
1281 (gnus-set-work-buffer)
1282 (if (file-exists-p organization)
1283 (insert-file-contents organization)
1284 (insert organization))
1285 (goto-char (point-min))
1286 (while (re-search-forward " *\n *" nil t)
1287 (replace-match " " t t))
1288 (buffer-substring (point-min) (point-max))))))
1290 (defun gnus-inews-lines ()
1291 "Count the number of lines and return numeric string."
1295 (goto-char (point-min))
1297 (concat "^" (regexp-quote mail-header-separator) "$"))
1299 (int-to-string (count-lines (point) (point-max))))))
1303 ;;; Gnus Mail Functions
1306 ;;; Mail reply commands of Gnus summary mode
1308 (defun gnus-summary-reply (yank &optional yank-articles)
1309 "Reply mail to news author.
1310 If prefix argument YANK is non-nil, original article is yanked automatically.
1311 Customize the variable gnus-mail-reply-method to use another mailer."
1313 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1314 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1315 (gnus-set-global-variables)
1316 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1317 (gnus-summary-select-article t)
1318 (let ((gnus-newsgroup-name gnus-newsgroup-name))
1319 (bury-buffer gnus-article-buffer)
1320 (funcall gnus-mail-reply-method (or yank-articles (not (not yank)))))
1321 (gnus-article-hide-headers-if-wanted))
1323 (defun gnus-summary-reply-with-original (n)
1324 "Reply mail to news author with original article.
1325 Customize the variable gnus-mail-reply-method to use another mailer."
1327 (gnus-summary-reply t (gnus-summary-work-articles n)))
1329 (defun gnus-summary-mail-forward (post)
1330 "Forward the current message to another user.
1331 Customize the variable gnus-mail-forward-method to use another mailer."
1333 (gnus-set-global-variables)
1334 (gnus-summary-select-article t)
1335 (gnus-copy-article-buffer)
1336 (let ((gnus-newsgroup-name gnus-newsgroup-name))
1338 (gnus-forward-using-post gnus-article-copy)
1339 (funcall gnus-mail-forward-method gnus-article-copy)))
1340 (gnus-article-hide-headers-if-wanted))
1342 (defun gnus-summary-post-forward ()
1343 "Forward the current article to a newsgroup."
1345 (gnus-summary-mail-forward t))
1347 (defvar gnus-nastygram-message
1348 "The following article was inappropriately posted to %s.\n"
1349 "Format string to insert in nastygrams.
1350 The current group name will be inserted at \"%s\".")
1352 (defun gnus-summary-mail-nastygram (n)
1353 "Send a nastygram to the author of the current article."
1355 (if (or gnus-expert-user
1357 "Really send a nastygram to the author of the current article? "))
1358 (let ((group gnus-newsgroup-name))
1359 (gnus-summary-reply-with-original n)
1360 (set-buffer gnus-mail-buffer)
1361 (insert (format gnus-nastygram-message group))
1362 (gnus-mail-send-and-exit))))
1364 (defun gnus-summary-mail-other-window ()
1365 "Compose mail in other window.
1366 Customize the variable `gnus-mail-other-window-method' to use another
1369 (gnus-set-global-variables)
1370 (let ((gnus-newsgroup-name gnus-newsgroup-name))
1371 (funcall gnus-mail-other-window-method)))
1373 (defun gnus-mail-reply-using-mail (&optional yank to-address)
1375 (set-buffer gnus-summary-buffer)
1376 (let ((info (nth 2 (gnus-gethash gnus-newsgroup-name gnus-newsrc-hashtb)))
1377 (group (gnus-group-real-name gnus-newsgroup-name))
1378 (cur (cons (current-buffer) (cdr gnus-article-current)))
1379 (winconf (current-window-configuration))
1380 from subject date to reply-to message-of
1381 references message-id sender follow-to cc sendto elt)
1382 (set-buffer (get-buffer-create gnus-mail-buffer))
1384 (make-local-variable 'gnus-article-reply)
1385 (setq gnus-article-reply cur)
1386 (make-local-variable 'gnus-prev-winconf)
1387 (setq gnus-prev-winconf winconf)
1388 (use-local-map (copy-keymap mail-mode-map))
1389 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1390 (if (and (buffer-modified-p)
1393 "Unsent article being composed; erase it? ")))
1397 (gnus-copy-article-buffer)
1399 (set-buffer gnus-article-copy)
1400 (gnus-narrow-to-headers)
1401 (if (and (boundp 'gnus-reply-to-function)
1402 gnus-reply-to-function)
1403 (setq follow-to (funcall gnus-reply-to-function group)))
1404 (setq from (mail-fetch-field "from"))
1405 (setq date (or (mail-fetch-field "date")
1406 (header-date gnus-current-headers)))
1409 (string-match " *at \\| *@ \\| *(\\| *<" from)))
1411 (concat (if stop-pos (substring from 0 stop-pos) from)
1412 "'s message of " date))))
1413 (setq sender (mail-fetch-field "sender"))
1414 (setq subject (or (mail-fetch-field "subject")
1416 (or (string-match "^[Rr][Ee]:" subject)
1417 (setq subject (concat "Re: " subject)))
1418 (setq cc (mail-fetch-field "cc"))
1419 (setq reply-to (mail-fetch-field "reply-to"))
1420 (setq references (mail-fetch-field "references"))
1421 (setq message-id (mail-fetch-field "message-id"))
1423 (setq news-reply-yank-from (or from "(nobody)")))
1424 (setq news-reply-yank-message-id
1425 (or message-id "(unknown Message-ID)"))
1427 ;; Gather the "to" addresses out of the follow-to list and remove
1429 (if (and follow-to (listp follow-to))
1430 (while (setq elt (assoc "To" follow-to))
1431 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1432 (setq follow-to (delq elt follow-to))))
1434 (mail-setup (or to-address
1435 (if (and follow-to (not (stringp follow-to))) sendto
1436 (or follow-to reply-to from sender "")))
1437 subject message-of nil gnus-article-copy nil)
1439 (if (and follow-to (listp follow-to))
1441 (goto-char (point-min))
1442 (re-search-forward "^To:" nil t)
1446 (insert (car (car follow-to)) ": " (cdr (car follow-to)) "\n")
1447 (setq follow-to (cdr follow-to)))))
1448 ;; Fold long references line to follow RFC1036.
1449 (mail-position-on-field "References")
1450 (let ((begin (- (point) (length "References: ")))
1453 (if references (insert references))
1454 (if (and references message-id) (insert " "))
1455 (if message-id (insert message-id))
1456 ;; The region must end with a newline to fill the region
1457 ;; without inserting extra newline.
1458 (fill-region-as-paragraph begin (1+ (point))))
1459 (goto-char (point-min))
1461 (concat "^" (regexp-quote mail-header-separator) "$"))
1464 (gnus-configure-windows 'reply)
1465 (let ((last (point))
1467 (if (not (listp yank))
1470 (mail-yank-original nil))
1471 (or mail-yank-hooks mail-citation-hook
1472 (run-hooks 'news-reply-header-hook)))
1474 (save-window-excursion
1475 (set-buffer gnus-summary-buffer)
1476 (gnus-summary-select-article nil nil nil (car yank))
1477 (gnus-summary-remove-process-mark (car yank)))
1479 (gnus-copy-article-buffer)
1480 (mail-yank-original nil)
1482 (or mail-yank-hooks mail-citation-hook
1483 (run-hooks 'news-reply-header-hook))
1485 (setq yank (cdr yank))))
1487 (gnus-configure-windows 'reply-yank))
1488 (run-hooks 'gnus-mail-hook)))))
1490 (defun gnus-mail-yank-original ()
1493 (mail-yank-original nil))
1494 (or mail-yank-hooks mail-citation-hook
1495 (run-hooks 'news-reply-header-hook)))
1497 (defun gnus-mail-send-and-exit ()
1499 (let ((reply gnus-article-reply)
1500 (winconf gnus-prev-winconf))
1501 (mail-send-and-exit nil)
1502 (if (get-buffer gnus-group-buffer)
1504 (if (gnus-buffer-exists-p (car-safe reply))
1506 (set-buffer (car reply))
1508 (gnus-summary-mark-article-as-replied
1510 (and winconf (set-window-configuration winconf))))))
1512 (defun gnus-forward-make-subject (buffer)
1515 (concat "[" (if (memq 'mail (assoc (symbol-name
1516 (car (gnus-find-method-for-group
1517 gnus-newsgroup-name)))
1518 gnus-valid-select-methods))
1519 (gnus-fetch-field "From")
1520 gnus-newsgroup-name)
1521 "] " (or (gnus-fetch-field "Subject") ""))))
1523 (defun gnus-forward-insert-buffer (buffer)
1524 (let ((beg (goto-char (point-max))))
1525 (insert "------- Start of forwarded message -------\n")
1526 (insert-buffer buffer)
1527 (goto-char (point-max))
1528 (insert "------- End of forwarded message -------\n")
1529 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
1531 (while (setq beg (next-single-property-change (point) 'invisible))
1533 (delete-region beg (or (next-single-property-change
1537 (defun gnus-mail-forward-using-mail (&optional buffer)
1538 "Forward the current message to another user using mail."
1539 ;; This is almost a carbon copy of rmail-forward in rmail.el.
1540 (let* ((forward-buffer (or buffer (current-buffer)))
1541 (winconf (current-window-configuration))
1542 (subject (gnus-forward-make-subject forward-buffer)))
1543 (set-buffer forward-buffer)
1544 (mail nil nil subject)
1545 (use-local-map (copy-keymap (current-local-map)))
1546 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1547 (make-local-variable 'gnus-prev-winconf)
1548 (setq gnus-prev-winconf winconf)
1549 (gnus-forward-insert-buffer forward-buffer)
1550 (goto-char (point-min))
1551 (re-search-forward "^To: " nil t)
1552 (gnus-configure-windows 'mail-forward)
1553 ;; You have a chance to arrange the message.
1554 (run-hooks 'gnus-mail-forward-hook)
1555 (run-hooks 'gnus-mail-hook)))
1557 (defun gnus-forward-using-post (&optional buffer)
1558 (let* ((forward-buffer (or buffer (current-buffer)))
1559 (subject (gnus-forward-make-subject forward-buffer)))
1560 (gnus-post-news 'post nil nil nil nil subject)
1562 (gnus-forward-insert-buffer forward-buffer)
1563 ;; You have a chance to arrange the message.
1564 (run-hooks 'gnus-mail-forward-hook))))
1566 (defun gnus-mail-other-window-using-mail ()
1567 "Compose mail other window using mail."
1568 (let ((winconf (current-window-configuration)))
1569 (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
1570 (use-local-map (copy-keymap (current-local-map)))
1571 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
1572 (make-local-variable 'gnus-prev-winconf)
1573 (setq gnus-prev-winconf winconf)
1574 (run-hooks 'gnus-mail-hook)))
1576 (defun gnus-article-mail (yank)
1577 "Send a reply to the address near point.
1578 If YANK is non-nil, include the original article."
1582 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
1583 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
1586 (switch-to-buffer gnus-summary-buffer)
1587 (funcall gnus-mail-reply-method yank address)))))
1589 (defun gnus-article-mail-with-original ()
1590 "Send a reply to the address near point and include the original article."
1592 (gnus-article-mail 'yank))
1596 ;;; gnus-msg.el ends here