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.
32 (defvar gnus-organization-file "/usr/lib/news/organization"
33 "*Local news organization file.")
35 (defvar gnus-prepare-article-hook nil
36 "*A hook called after preparing body, but before preparing header headers.")
38 (defvar gnus-post-prepare-function nil
39 "*Function that is run after a post buffer has been prepared.
40 It is called with the name of the newsgroup that is posted to. It
41 might be used, for instance, for inserting signatures based on the
42 newsgroup name. (In that case, `gnus-signature-file' and
43 `mail-signature' should both be set to nil).")
45 (defvar gnus-post-prepare-hook nil
46 "*Hook that is run after a post buffer has been prepared.
47 If you want to insert the signature, you might put
48 `gnus-inews-insert-signature' in this hook.")
50 (defvar gnus-use-followup-to t
51 "*Specifies what to do with Followup-To header.
52 If nil, ignore the header. If it is t, use its value, but ignore
53 `poster'. If it is the symbol `ask', query the user before posting.
54 If it is the symbol `use', always use the value.")
56 (defvar gnus-followup-to-function nil
57 "*A variable that contains a function that returns a followup address.
58 The function will be called in the buffer of the article that is being
59 followed up. The buffer will be narrowed to the headers of the
60 article. To pick header headers, one might use `mail-fetch-field'. The
61 function will be called with the name of the current newsgroup as the
64 Here's an example `gnus-followup-to-function':
66 (setq gnus-followup-to-function
68 (cond ((string= group \"mail.list\")
69 (or (mail-fetch-field \"sender\")
70 (mail-fetch-field \"from\")))
72 (or (mail-fetch-field \"reply-to\")
73 (mail-fetch-field \"from\"))))))")
75 (defvar gnus-reply-to-function nil
76 "*A variable that contains a function that returns a reply address.
77 See the `gnus-followup-to-function' variable for an explanation of how
78 this variable is used.
80 This function should return a string that will be used to fill in the
81 header. This function may also return a list. In that case, every
82 list element should be a cons where the first car should be a string
83 with the header name, and the cdr should be a string with the header
86 (defvar gnus-author-copy (getenv "AUTHORCOPY")
87 "*Save outgoing articles in this file.
88 Initialized from the AUTHORCOPY environment variable.
90 If this variable begins with the character \"|\", outgoing articles
91 will be piped to the named program. It is possible to save an article
92 in an MH folder as follows:
94 \(setq gnus-author-copy \"|/usr/local/lib/mh/rcvstore +Article\")
96 If the first character is not a pipe, articles are saved using the
97 function specified by the `gnus-author-copy-saver' variable.")
99 (defvar gnus-mail-self-blind nil
100 "*Non-nil means insert a BCC header in all outgoing articles.
101 This will result in having a copy of the article mailed to yourself.
102 The BCC header is inserted when the post buffer is initialized, so you
103 can remove or alter the BCC header to override the default.")
105 (defvar gnus-author-copy-saver (function rmail-output)
106 "*A function called to save outgoing articles.
107 This function will be called with the same of the file to store the
108 article in. The default function is `rmail-output' which saves in Unix
111 (defvar gnus-outgoing-message-group nil
112 "*All outgoing messages will be put in this group.
113 If you want to store all your outgoing mail and articles in the group
114 \"nnml:archive\", you set this variable to that value. This variable
115 can also be a list of group names.
117 If you want to have greater control over what group to put each
118 message in, you can set this variable to a function that checks the
119 current newsgroup name and then returns a suitable group name (or list
122 (defvar gnus-mailing-list-groups nil
123 "*Regexp matching groups that are really mailing lists.
124 This is useful when you're reading a mailing list that has been
125 gatewayed to a newsgroup, and you want to followup to an article in
128 (defvar gnus-draft-group-directory
130 (concat (file-name-as-directory gnus-article-save-directory)
132 "*The directory where draft messages will be stored.")
134 (defvar gnus-user-login-name nil
135 "*The login name of the user.
136 Got from the function `user-login-name' if undefined.")
138 (defvar gnus-user-full-name nil
139 "*The full name of the user.
140 Got from the NAME environment variable if undefined.")
142 (defvar gnus-user-from-line nil
143 "*Your full, complete e-mail address.
144 Overrides the other Gnus variables if it is non-nil.
146 Here are two example values of this variable:
148 \"Lars Magne Ingebrigtsen <larsi@ifi.uio.no>\"
152 \"larsi@ifi.uio.no (Lars Magne Ingebrigtsen)\"
154 The first version is recommended, but the name has to be quoted if it
155 contains non-alphanumerical characters.")
157 (defvar gnus-signature-file "~/.signature"
158 "*Your signature file.
159 If the variable is a string that doesn't correspond to a file, the
160 string itself is inserted.")
162 (defvar gnus-signature-function nil
163 "*A function that should return a signature file name.
164 The function will be called with the name of the newsgroup being
166 If the function returns a string that doesn't correspond to a file, the
167 string itself is inserted.
168 If the function returns nil, the `gnus-signature-file' variable will
171 (defvar gnus-required-headers
172 '(From Date Newsgroups Subject Message-ID Organization Lines X-Newsreader)
173 "*Headers to be generated or prompted for when posting an article.
174 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
175 Message-ID. Organization, Lines, In-Reply-To and X-Newsreader are
176 optional. If you want Gnus not to insert some header, remove it from
179 (defvar gnus-required-mail-headers
180 '(From Date To Subject (optional . In-Reply-To) Message-ID Organization Lines)
181 "*Headers to be generated or prompted for when mailing a message.
182 RFC822 required that From, Date, To, Subject and Message-ID be
183 included. Organization, Lines and X-Mailer are optional.")
185 (defvar gnus-deletable-headers '(Message-ID Date)
186 "*Headers to be deleted if they already exists and were generated by Gnus previously.")
188 (defvar gnus-removable-headers '(NNTP-Posting-Host Bcc Xref)
189 "*Headers to be removed unconditionally before posting.")
191 (defvar gnus-check-before-posting
192 '(subject-cmsg multiple-headers sendsys message-id from
193 long-lines control-chars size new-text
194 signature approved sender)
195 "In non-nil, Gnus will attempt to run some checks on outgoing posts.
196 If this variable is t, Gnus will check everything it can. If it is a
197 list, then those elements in that list will be checked.")
199 (defvar gnus-delete-supersedes-headers
200 "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Supersedes:"
201 "*Header lines matching this regexp will be deleted before posting.
202 It's best to delete old Path and Date headers before posting to avoid
205 (defvar gnus-auto-mail-to-author nil
206 "*If non-nil, mail the authors of articles a copy of your follow-ups.
207 If this variable is `ask', the user will be prompted for whether to
208 mail a copy. The string given by `gnus-mail-courtesy-message' will be
209 inserted at the beginning of the mail copy.
211 Mail is sent using the function specified by the
212 `gnus-mail-send-method' variable.")
214 ;; Added by Ethan Bradford <ethanb@ptolemy.astro.washington.edu>.
215 (defvar gnus-mail-courtesy-message
216 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
217 "*This is inserted at the start of a mailed copy of a posted message.
218 If this variable is nil, no such courtesy message will be added.")
220 (defvar gnus-mail-reply-method (function gnus-mail-reply-using-mail)
221 "*Function to compose a reply.
222 Three pre-made functions are `gnus-mail-reply-using-mail' (sendmail);
223 `gnus-mail-reply-using-mhe' (MH-E); and `gnus-mail-reply-using-vm'.")
225 (defvar gnus-mail-forward-method (function gnus-mail-forward-using-mail)
226 "*Function to forward the current message to another user.
227 Three pre-made functions are `gnus-mail-forward-using-mail' (sendmail);
228 `gnus-mail-forward-using-mhe' (MH-E); and `gnus-mail-forward-using-vm'.")
230 (defvar gnus-mail-other-window-method 'gnus-mail-other-window-using-mail
231 "*Function to compose mail in the other window.
232 Three pre-made functions are `gnus-mail-other-window-using-mail'
233 (sendmail); `gnus-mail-other-window-using-mhe' (MH-E); and
234 `gnus-mail-other-window-using-vm'.")
236 (defvar gnus-mail-send-method send-mail-function
237 "*Function to mail a message which is also being posted as an article.
238 The message must have To or Cc header. The default is copied from
239 the variable `send-mail-function'.")
241 (defvar gnus-inews-article-function 'gnus-inews-article
242 "*Function to post an article.")
244 (defvar gnus-bounced-headers-junk "^\\(Received\\):"
245 "*Regexp that matches headers to be removed in resent bounced mail.")
247 (defvar gnus-inews-article-hook (list 'gnus-inews-do-fcc)
248 "*A hook called before finally posting an article.
249 The default hook (`gnus-inews-do-fcc') does FCC processing (ie. saves
250 the article to a file).")
252 (defvar gnus-inews-article-header-hook nil
253 "*A hook called after inserting the headers in an article to be posted.
254 The hook is called from the *post-news* buffer, narrowed to the
257 (defvar gnus-mail-hook nil
258 "*A hook called as the last thing after setting up a mail buffer.")
260 (defvar gnus-message-sent-hook nil
261 "*A hook run after an article has been sent (or attempted sent).")
263 ;;; Internal variables.
265 (defvar gnus-post-news-buffer "*post-news*")
266 (defvar gnus-mail-buffer "*mail*")
267 (defvar gnus-summary-send-map nil)
268 (defvar gnus-article-copy nil)
269 (defvar gnus-reply-subject nil)
270 (defvar gnus-add-to-address nil)
271 (defvar gnus-in-reply-to nil)
274 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
275 (autoload 'news-setup "rnewspost")
276 (autoload 'news-reply-mode "rnewspost")
277 (autoload 'rmail-output "rmailout"))
281 ;;; Gnus Posting Functions
284 (define-prefix-command 'gnus-summary-send-map)
285 (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
286 (define-key gnus-summary-send-map "p" 'gnus-summary-post-news)
287 (define-key gnus-summary-send-map "f" 'gnus-summary-followup)
288 (define-key gnus-summary-send-map "F" 'gnus-summary-followup-with-original)
289 (define-key gnus-summary-send-map "b" 'gnus-summary-followup-and-reply)
290 (define-key gnus-summary-send-map "B" 'gnus-summary-followup-and-reply-with-original)
291 (define-key gnus-summary-send-map "c" 'gnus-summary-cancel-article)
292 (define-key gnus-summary-send-map "s" 'gnus-summary-supersede-article)
293 (define-key gnus-summary-send-map "r" 'gnus-summary-reply)
294 (define-key gnus-summary-send-map "R" 'gnus-summary-reply-with-original)
295 (define-key gnus-summary-send-map "m" 'gnus-summary-mail-other-window)
296 (define-key gnus-summary-send-map "Db" 'gnus-summary-resend-bounced-mail)
297 (define-key gnus-summary-send-map "Dc" 'gnus-summary-send-draft)
298 (define-key gnus-summary-send-map "u" 'gnus-uu-post-news)
299 (define-key gnus-summary-send-map "om" 'gnus-summary-mail-forward)
300 (define-key gnus-summary-send-map "op" 'gnus-summary-post-forward)
301 (define-key gnus-summary-send-map "Om" 'gnus-uu-digest-mail-forward)
302 (define-key gnus-summary-send-map "Op" 'gnus-uu-digest-post-forward)
304 ;;; Internal functions.
306 (defun gnus-number-base36 (num len)
307 (if (if (< len 0) (<= num 0) (= len 0))
309 (concat (gnus-number-base36 (/ num 36) (1- len))
310 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
313 ;;; Post news commands of Gnus group mode and summary mode
315 (defun gnus-group-mail ()
316 "Start composing a mail."
320 (defun gnus-group-post-news ()
323 (let ((gnus-newsgroup-name nil))
324 (gnus-post-news 'post nil nil gnus-article-buffer)))
326 (defun gnus-summary-post-news ()
329 (gnus-set-global-variables)
330 (gnus-post-news 'post gnus-newsgroup-name))
332 (defun gnus-summary-followup (yank &optional yank-articles)
333 "Compose a followup to an article.
334 If prefix argument YANK is non-nil, original article is yanked automatically."
336 (gnus-set-global-variables)
337 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
338 (save-window-excursion
339 (gnus-summary-select-article))
340 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
341 (gnus-newsgroup-name gnus-newsgroup-name))
342 ;; Check Followup-To: poster.
343 (set-buffer gnus-article-buffer)
344 (if (and gnus-use-followup-to
345 (string-equal "poster" (gnus-fetch-field "followup-to"))
346 (or (not (memq gnus-use-followup-to '(t ask)))
348 "Do you want to ignore `Followup-To: poster'? "))))
349 ;; Mail to the poster.
350 (gnus-summary-reply yank)
352 (gnus-post-news nil gnus-newsgroup-name
353 headers gnus-article-buffer
354 (or yank-articles (not (not yank)))))))
356 (defun gnus-summary-followup-with-original (n)
357 "Compose a followup to an article and include the original article."
359 (gnus-summary-followup t (gnus-summary-work-articles n)))
361 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
362 (defun gnus-summary-followup-and-reply (yank &optional yank-articles)
363 "Compose a followup and do an auto mail to author."
365 (gnus-set-global-variables)
366 (let ((gnus-auto-mail-to-author 'force))
367 (gnus-summary-followup yank yank-articles)))
369 (defun gnus-summary-followup-and-reply-with-original (n)
370 "Compose a followup, include the original, and do an auto mail to author."
372 (gnus-summary-followup-and-reply t (gnus-summary-work-articles n)))
374 (defun gnus-summary-cancel-article (n)
375 "Cancel an article you posted."
377 (gnus-set-global-variables)
378 (let ((articles (gnus-summary-work-articles n)))
380 (gnus-summary-select-article t nil nil (car articles))
381 (and (gnus-eval-in-buffer-window gnus-article-buffer (gnus-cancel-news))
382 (gnus-summary-mark-as-read (car articles) gnus-canceled-mark))
383 (gnus-summary-remove-process-mark (car articles))
384 (gnus-article-hide-headers-if-wanted)
385 (setq articles (cdr articles)))))
387 (defun gnus-summary-supersede-article ()
388 "Compose an article that will supersede a previous article.
389 This is done simply by taking the old article and adding a Supersedes
390 header line with the old Message-ID."
392 (gnus-set-global-variables)
393 (gnus-summary-select-article t)
396 (downcase (mail-strip-quoted-names
397 (mail-header-from gnus-current-headers)))
398 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
399 (error "This article is not yours."))
401 (set-buffer gnus-article-buffer)
402 (let ((buffer-read-only nil))
403 (goto-char (point-min))
404 (search-forward "\n\n" nil t)
405 (if (not (re-search-backward "^Message-ID: " nil t))
406 (error "No Message-ID in this article"))))
407 (if (gnus-post-news 'post gnus-newsgroup-name)
410 (insert-buffer-substring gnus-article-buffer)
411 (if (search-forward "\n\n" nil t)
413 (goto-char (point-max)))
414 (narrow-to-region (point-min) (point))
415 (goto-char (point-min))
416 (and gnus-delete-supersedes-headers
417 (delete-matching-lines gnus-delete-supersedes-headers))
418 (goto-char (point-min))
419 (if (not (re-search-forward "^Message-ID: " nil t))
420 (error "No Message-ID in this article")
421 (replace-match "Supersedes: " t t))
422 (goto-char (point-max))
423 (insert mail-header-separator)
429 (defalias 'sendnews 'gnus-post-news)
432 (defalias 'postnews 'gnus-post-news)
434 (defun gnus-copy-article-buffer (&optional article-buffer)
435 ;; make a copy of the article buffer with all text properties removed
436 ;; this copy is in the buffer gnus-article-copy.
437 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
438 ;; this buffer should be passed to all mail/news reply/post routines.
439 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
440 (buffer-disable-undo gnus-article-copy)
441 (or (memq gnus-article-copy gnus-buffer-list)
442 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
443 (let ((article-buffer (or article-buffer gnus-article-buffer)))
444 (if (and (get-buffer article-buffer)
445 (buffer-name (get-buffer article-buffer)))
447 (set-buffer article-buffer)
449 (copy-to-buffer gnus-article-copy (point-min) (point-max))
450 (set-text-properties (point-min) (point-max)
451 nil gnus-article-copy)))))
453 (defun gnus-post-news (post &optional group header article-buffer yank subject)
454 "Begin editing a new USENET news article to be posted.
455 Type \\[describe-mode] in the buffer to get a list of commands."
456 (interactive (list t))
457 (let* ((group (or group gnus-newsgroup-name))
462 (nth 5 (nth 2 (gnus-gethash
463 group gnus-newsrc-hashtb)))))))
465 (and group gnus-mailing-list-groups
466 (string-match gnus-mailing-list-groups group))))
467 (if (and (gnus-member-of-valid 'post (or group gnus-newsgroup-name))
472 (gnus-new-news group)
473 (gnus-news-followup yank group))
477 (gnus-new-mail to-address)
478 ;; Arrange for mail groups that have no `to-address' to
479 ;; get that when the user sends off the mail.
482 (make-local-variable 'gnus-add-to-address)
483 (setq gnus-add-to-address group))))
484 (gnus-mail-reply yank to-address 'followup)))))
486 (defun gnus-inews-news (&optional use-group-method)
487 "Send a news message.
488 If given a prefix, and the group is a foreign group, this function
489 will attempt to use the foreign server to post the article."
491 (let* ((case-fold-search nil)
492 (server-running (gnus-server-opened gnus-current-select-method))
493 (reply gnus-article-reply)
496 (gnus-start-news-server) ;Use default server.
498 (goto-char (point-min))
499 (run-hooks 'news-inews-hook)
502 (gnus-message 5 "Posting to USENET...")
503 (setq post-result (funcall gnus-inews-article-function use-group-method))
504 (cond ((eq post-result 'illegal)
508 (gnus-message 5 "Posting to USENET...done")
509 (if (gnus-buffer-exists-p (car-safe reply))
512 (set-buffer gnus-summary-buffer)
513 (gnus-summary-mark-article-as-replied
515 (set-buffer-modified-p nil))
517 ;; We cannot signal an error.
520 (gnus-message 1 "Article rejected: %s"
521 (gnus-status-message gnus-select-method)))))
523 (let ((conf gnus-prev-winconf))
527 ;; Restore last window configuration.
528 (and conf (set-window-configuration conf)))))))
530 (defun gnus-inews-narrow-to-headers ()
533 (goto-char (point-min))
534 (or (and (re-search-forward
535 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
539 (defun gnus-inews-send-mail-copy ()
540 ;; Mail the message if To, Bcc or Cc exists.
541 (let* ((types '("to" "bcc" "cc"))
543 (buffer (current-buffer))
547 (gnus-inews-narrow-to-headers)
550 (or (mail-fetch-field (car ty) nil t)
551 (setq types (delete (car ty) types)))
555 ;; We do not want to send mail.
557 (gnus-message 5 "Sending via mail...")
560 ;; We copy the article over to a temp buffer since we are
561 ;; going to modify it a little.
562 (nnheader-set-temp-buffer " *Gnus-mailing*")
563 (insert-buffer-substring buffer)
564 ;; We remove Fcc, because we don't want the mailer to see
566 (gnus-inews-narrow-to-headers)
567 (nnheader-remove-header "fcc")
569 ;; Insert the X-Courtesy-Message header.
570 (and (or (member "to" types)
573 (goto-char (point-max))
574 (insert "X-Courtesy-Message: "
575 (mail-fetch-field "newsgroups"))))
579 (if (and gnus-mail-courtesy-message
580 (or (member "to" types)
581 (member "cc" types)))
582 ;; We only want to insert the courtesy mail message if
583 ;; we use To or Cc; Bcc should not have one. Well, if
584 ;; both Bcc and To are present, it will get one
587 ;; Insert "courtesy" mail message.
588 (goto-char (point-min))
590 (concat "^" (regexp-quote mail-header-separator) "$"))
592 (insert gnus-mail-courtesy-message)))
595 (kill-buffer (current-buffer))
596 (gnus-message 5 "Sending via mail...done"))))))
598 (defun gnus-inews-remove-headers-after-mail ()
601 (gnus-inews-narrow-to-headers)
602 (nnheader-remove-header "bcc"))))
604 (defun gnus-inews-check-post ()
605 "Check whether the post looks ok."
607 (not gnus-check-before-posting)
609 ;; We narrow to the headers and check them first.
612 (goto-char (point-min))
617 (concat "^" (regexp-quote mail-header-separator) "$"))
618 (match-beginning 0)))
619 (goto-char (point-min))
621 ;; Check for commands in Subject.
623 (gnus-check-before-posting 'subject-cmsg)
625 (if (string-match "^cmsg " (mail-fetch-field "subject"))
627 "The control code \"cmsg \" is in the subject. Really post? ")
629 ;; Check for multiple identical headers.
630 (or (gnus-check-before-posting 'multiple-headers)
633 (while (and (not found) (re-search-forward "^[^ \t:]+: "
636 (or (re-search-forward
637 (concat "^" (setq found
640 (- (match-end 0) 2))))
645 (format "Multiple %s headers. Really post? " found))
647 ;; Check for Version and Sendsys.
648 (or (gnus-check-before-posting 'sendsys)
650 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
652 (format "The article contains a %s command. Really post? "
653 (buffer-substring (match-beginning 0)
654 (1- (match-end 0)))))
656 ;; Check for Approved.
657 (or (gnus-check-before-posting 'approved)
659 (if (re-search-forward "^Approved:" nil t)
661 "The article contains an Approved header. Really post? ")
663 ;; Check the Message-ID header.
664 (or (gnus-check-before-posting 'message-id)
666 (let* ((case-fold-search t)
667 (message-id (mail-fetch-field "message-id")))
669 (and (string-match "@" message-id)
670 (string-match "@[^\\.]*\\." message-id))
673 "The Message-ID looks strange: \"%s\". Really post? "
675 ;; Check the From header.
676 (or (gnus-check-before-posting 'from)
678 (let* ((case-fold-search t)
679 (from (mail-fetch-field "from")))
682 (gnus-y-or-n-p "There is no From line. Really post? "))
683 ((not (string-match "@[^\\.]*\\." from))
686 "The address looks strange: \"%s\". Really post? " from)))
687 ((string-match "(.*).*(.*)" from)
690 "The From header looks strange: \"%s\". Really post? "
692 ((string-match "<[^>]+> *$" from)
693 (let ((name (substring from 0 (match-beginning 0))))
695 (string-match "^ *\"[^\"]*\" *$" name)
696 (not (string-match "[][.!()<>@,;:\\]" name))
699 "The From header name has bogus characters. Really post? "
703 ;; Check for long lines.
704 (or (gnus-check-before-posting 'long-lines)
706 (goto-char (point-min))
708 (concat "^" (regexp-quote mail-header-separator) "$"))
712 (< (current-column) 80))
713 (zerop (forward-line 1))))
718 "You have lines longer than 79 characters. Really post? ")))))
719 ;; Check for control characters.
720 (or (gnus-check-before-posting 'control-chars)
722 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
724 "The article contains control characters. Really post? ")
726 ;; Check excessive size.
727 (or (gnus-check-before-posting 'size)
728 (if (> (buffer-size) 60000)
730 (format "The article is %d octets long. Really post? "
733 ;; Use the (size . checksum) variable to see whether the
734 ;; article is empty or has only quoted text.
736 (gnus-check-before-posting 'new-text)
737 (if (and (= (buffer-size) (car gnus-article-check-size))
738 (= (gnus-article-checksum) (cdr gnus-article-check-size)))
740 "It looks like there's no new text in your article. Really post? ")
742 ;; Check the length of the signature.
743 (or (gnus-check-before-posting 'signature)
745 (goto-char (point-max))
746 (if (not (re-search-backward gnus-signature-separator nil t))
748 (if (> (count-lines (point) (point-max)) 4)
751 "Your .sig is %d lines; it should be max 4. Really post? "
752 (count-lines (point) (point-max))))
755 (defun gnus-article-checksum ()
759 (setq sum (logxor sum (following-char)))
763 ;; Returns non-nil if this type is not to be checked.
764 (defun gnus-check-before-posting (type)
766 (or (not gnus-check-before-posting)
767 (if (listp gnus-check-before-posting)
768 (memq type gnus-check-before-posting)
771 (defun gnus-cancel-news ()
772 "Cancel an article you posted."
774 (if (or gnus-expert-user
775 (gnus-yes-or-no-p "Do you really want to cancel this article? "))
780 (or (gnus-member-of-valid 'post gnus-newsgroup-name)
781 (error "This backend does not support canceling"))
783 ;; Get header info. from original article.
785 (gnus-article-show-all-headers)
786 (goto-char (point-min))
787 (search-forward "\n\n" nil 'move)
788 (narrow-to-region (point-min) (point))
789 (setq from (mail-fetch-field "from"))
790 (setq newsgroups (mail-fetch-field "newsgroups"))
791 (setq message-id (mail-fetch-field "message-id"))
792 (setq distribution (mail-fetch-field "distribution")))
793 ;; Verify if the article is absolutely user's by comparing
794 ;; user id with value of its From: field.
797 (downcase (mail-strip-quoted-names from))
798 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
800 (ding) (gnus-message 3 "This article is not yours.")
802 ;; Make control article.
803 (set-buffer (get-buffer-create " *Gnus-canceling*"))
804 (buffer-disable-undo (current-buffer))
806 (insert "Newsgroups: " newsgroups "\n"
807 "From: " (gnus-inews-real-user-address) "\n"
808 "Subject: cancel " message-id "\n"
809 "Control: cancel " message-id "\n"
811 (concat "Distribution: " distribution "\n")
813 mail-header-separator "\n"
814 "This is a cancel message from " from ".\n")
815 ;; Send the control article to NNTP server.
816 (gnus-message 5 "Canceling your article...")
818 (if (funcall gnus-inews-article-function)
819 (gnus-message 5 "Canceling your article...done")
822 (gnus-message 1 "Cancel failed; %s"
823 (gnus-status-message gnus-newsgroup-name))
826 ;; Kill the article buffer.
827 (kill-buffer (current-buffer))))))))
830 ;;; Lowlevel inews interface.
832 ;; Dummy to avoid byte-compile warning.
833 (defvar nnspool-rejected-article-hook)
835 (defun gnus-inews-article (&optional use-group-method)
836 "Post an article in current buffer using NNTP protocol."
837 (let ((artbuf (current-buffer))
840 (goto-char (point-max))
841 ;; Require a newline at the end of the buffer since inews may
842 ;; append a .signature.
843 (or (= (preceding-char) ?\n)
845 ;; Prepare article headers. All message body such as signature
846 ;; must be inserted before Lines: field is prepared.
848 (gnus-inews-narrow-to-headers)
850 (gnus-inews-cleanup-headers)
851 ;; Remove some headers.
852 (gnus-inews-remove-headers)
853 ;; Insert some headers.
854 (gnus-inews-insert-headers)
855 ;; Let the user do all of the above.
856 (run-hooks 'gnus-inews-article-header-hook)
857 ;; Copy the Gcc header, if any.
858 (setq gcc (mail-fetch-field "gcc"))
860 ;; Check whether the article is a good Net Citizen.
861 (if (and gnus-article-check-size
862 (not (gnus-inews-check-post)))
865 ;; We fudge a hook for nnspool.
866 (setq nnspool-rejected-article-hook
872 (set-buffer (, (buffer-name)))
873 (gnus-put-in-draft-group nil 'silent))
877 1 "Couldn't enter rejected article into draft group")))))))
879 ;; Looks ok, so we do the nasty.
881 ;; This hook may insert a signature.
883 (goto-char (point-min))
884 (let ((gnus-newsgroup-name (or (mail-fetch-field "newsgroups")
885 gnus-newsgroup-name)))
886 (run-hooks 'gnus-prepare-article-hook)))
887 ;; Send off copies using mail, if that is wanted.
888 (gnus-inews-send-mail-copy)
889 ;; Remove more headers.
890 (gnus-inews-remove-headers-after-mail)
891 ;; Copy the article over to a temp buffer.
892 (nnheader-set-temp-buffer " *Gnus-posting*")
893 (insert-buffer-substring artbuf)
894 ;; Remove the header separator.
895 (goto-char (point-min))
897 (concat "^" (regexp-quote mail-header-separator) "$"))
898 (replace-match "" t t)
899 ;; Run final inews hooks. This hook may do FCC.
900 ;; The article must be saved before being posted because
901 ;; `gnus-request-post' modifies the buffer.
902 (run-hooks 'gnus-inews-article-hook)
903 ;; Copy the article over to some group, possibly.
904 (and gcc (gnus-inews-do-gcc gcc))
909 (gnus-find-method-for-group gnus-newsgroup-name)
910 gnus-select-method) use-group-method))
911 (kill-buffer (current-buffer)))
912 (run-hooks 'gnus-message-sent-hook)
913 ;; We remove To and Cc headers to avoid re-mailing if the user
914 ;; accidentally (or purposefully) leans on the `C-c C-c' keys
915 ;; and the news server rejects the posting.
916 (gnus-inews-narrow-to-headers)
917 (nnheader-remove-header "^\\(to\\|[bcf]cc\\|cc\\):" t)
919 ;; If the posting was unsuccessful (that it, it was rejected) we
920 ;; put it into the draft group.
921 (or result (gnus-put-in-draft-group))
924 (defun gnus-inews-cleanup-headers ()
925 ;; Correct newsgroups field: change sequence of spaces to comma and
926 ;; eliminate spaces around commas. Eliminate imbedded line breaks.
927 (goto-char (point-min))
928 (if (re-search-forward "^Newsgroups: +" nil t)
932 (if (re-search-forward "^[^ \t]" nil t)
936 (goto-char (point-min))
937 (while (re-search-forward "\n[ \t]+" nil t)
938 (replace-match " " t t)) ;No line breaks (too confusing)
939 (goto-char (point-min))
940 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
941 (replace-match "," t t))
942 (goto-char (point-min))
943 ;; Remove a trailing comma.
944 (if (re-search-forward ",$" nil t)
945 (replace-match "" t t))))
947 ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
948 ;; Help save the the world!
951 (let ((newsgroups (mail-fetch-field "newsgroups"))
952 (followup-to (mail-fetch-field "followup-to"))
955 (string-match "," newsgroups) (not followup-to))
957 (while (string-match "," newsgroups)
959 (cons (list (substring newsgroups 0 (match-beginning 0)))
961 (setq newsgroups (substring newsgroups (match-end 0))))
962 (setq groups (nreverse (cons (list newsgroups) groups)))
964 (setq to (completing-read
965 "Followups to: (default all groups) " groups))
966 (if (> (length to) 0)
968 (goto-char (point-min))
969 (insert "Followup-To: " to "\n")))))))
971 ;; Cleanup Followup-To.
972 (goto-char (point-min))
973 (if (search-forward-regexp "^Followup-To: +" nil t)
977 (if (re-search-forward "^[^ \t]" nil 'end)
980 (goto-char (point-min))
981 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
982 (goto-char (point-min))
983 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ","))))
986 (defun gnus-inews-remove-headers ()
987 (let ((case-fold-search t)
988 (headers gnus-removable-headers))
989 ;; Remove toxic headers.
991 (goto-char (point-min))
992 (and (re-search-forward
993 (concat "^" (downcase (format "%s" (car headers))))
995 (delete-region (progn (beginning-of-line) (point))
996 (progn (forward-line 1) (point))))
997 (setq headers (cdr headers)))))
999 (defun gnus-inews-insert-headers (&optional headers)
1000 "Prepare article headers.
1001 Headers already prepared in the buffer are not modified.
1002 Headers in `gnus-required-headers' will be generated."
1003 (let ((Date (gnus-inews-date))
1004 (Message-ID (gnus-inews-message-id))
1005 (Organization (gnus-inews-organization))
1006 (From (gnus-inews-user-name))
1007 (Path (gnus-inews-path))
1010 (In-Reply-To (gnus-inews-in-reply-to))
1013 (Lines (gnus-inews-lines))
1014 (X-Newsreader gnus-version)
1015 (X-Mailer gnus-version)
1016 (headers (or headers gnus-required-headers))
1017 (case-fold-search t)
1019 ;; First we remove any old generated headers.
1020 (let ((headers gnus-deletable-headers))
1022 (goto-char (point-min))
1023 (and (re-search-forward
1024 (concat "^" (symbol-name (car headers)) ": *") nil t)
1025 (get-text-property (1+ (match-beginning 0)) 'gnus-deletable)
1027 (setq headers (cdr headers))))
1028 ;; If there are References, and no "Re: ", then the thread has
1029 ;; changed name. See Son-of-1036.
1030 (if (and (mail-fetch-field "references")
1031 (get-buffer gnus-article-buffer))
1032 (let ((psubject (gnus-simplify-subject-re
1033 (mail-fetch-field "subject"))))
1034 (or (and psubject gnus-reply-subject
1035 (string= (gnus-simplify-subject-re gnus-reply-subject)
1038 (string-match "@" Message-ID)
1040 (concat (substring Message-ID 0 (match-beginning 0))
1042 (substring Message-ID (match-beginning 0))))))))
1043 ;; Go through all the required headers and see if they are in the
1044 ;; articles already. If they are not, or are empty, they are
1045 ;; inserted automatically - except for Subject, Newsgroups and
1048 (goto-char (point-min))
1049 (setq elem (car headers))
1051 (setq header (car elem))
1053 (if (or (not (re-search-forward
1054 (concat "^" (downcase (symbol-name header)) ":") nil t))
1056 ;; The header was found. We insert a space after the
1057 ;; colon, if there is none.
1058 (if (/= (following-char) ? ) (insert " "))
1059 ;; Find out whether the header is empty...
1060 (looking-at "[ \t]*$")))
1061 ;; So we find out what value we should insert.
1065 ((and (consp elem) (eq (car elem) 'optional))
1066 ;; This is an optional header. If the cdr of this
1067 ;; is something that is nil, then we do not insert
1069 (setq header (cdr elem))
1070 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
1071 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
1073 ;; The element is a cons. Either the cdr is a
1074 ;; string to be inserted verbatim, or it is a
1075 ;; function, and we insert the value returned from
1077 (or (and (stringp (cdr elem)) (cdr elem))
1078 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
1079 ((and (boundp header) (symbol-value header))
1080 ;; The element is a symbol. We insert the value
1081 ;; of this symbol, if any.
1082 (symbol-value header))
1084 ;; We couldn't generate a value for this header,
1085 ;; so we just ask the user.
1086 (read-from-minibuffer
1087 (format "Empty header for %s; enter value: " header)))))
1088 ;; Finally insert the header.
1094 (goto-char (point-max))
1095 (insert (symbol-name header) ": " value "\n")
1097 (replace-match value t t))
1098 ;; Add the deletable property to the headers that require it.
1099 (and (memq header gnus-deletable-headers)
1100 (progn (beginning-of-line) (looking-at "[^:]+: "))
1101 (add-text-properties
1102 (point) (match-end 0)
1103 '(gnus-deletable t face italic) (current-buffer)))))))
1104 (setq headers (cdr headers)))
1105 ;; Insert new Sender if the From is strange.
1106 (let ((from (mail-fetch-field "from"))
1107 (sender (mail-fetch-field "sender")))
1109 (not (gnus-check-before-posting 'sender))
1111 (downcase (car (gnus-extract-address-components from)))
1112 (downcase (gnus-inews-real-user-address))))
1116 (downcase (car (gnus-extract-address-components sender)))
1117 (downcase (gnus-inews-real-user-address))))))
1119 (goto-char (point-min))
1120 (and (re-search-forward "^Sender:" nil t)
1123 (insert "Original-")
1124 (beginning-of-line)))
1125 (insert "Sender: " (gnus-inews-real-user-address) "\n"))))))
1128 (defun gnus-inews-insert-signature ()
1129 "Insert a signature file.
1130 If `gnus-signature-function' is bound and returns a string, this
1131 string is used instead of the variable `gnus-signature-file'.
1132 In either case, if the string is a file name, this file is
1133 inserted. If the string is not a file name, the string itself is
1136 If you never want any signature inserted, set both of these variables to
1140 (or (and gnus-signature-function
1141 (funcall gnus-signature-function gnus-newsgroup-name))
1142 gnus-signature-file)))
1144 (or (file-exists-p signature)
1145 (string-match " " signature)
1147 "^/[^/]+/" (expand-file-name signature)))))
1149 (goto-char (point-max))
1150 (if (and mail-signature (search-backward "\n-- \n" nil t))
1152 ;; Delete any previous signatures.
1153 (if (search-backward "\n-- \n" nil t)
1154 (delete-region (point) (point-max)))
1155 (or (eolp) (insert "\n"))
1157 (if (file-exists-p signature)
1158 (insert-file-contents signature)
1160 (goto-char (point-max))
1161 (or (bolp) (insert "\n"))))))))
1163 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1164 (defun gnus-inews-insert-mime-headers ()
1165 (goto-char (point-min))
1166 (let ((mail-header-separator
1168 (goto-char (point-min))
1169 (if (and (search-forward (concat "\n" mail-header-separator "\n")
1171 (not (search-backward "\n\n" nil t)))
1172 mail-header-separator
1174 (or (mail-position-on-field "Mime-Version")
1177 (goto-char (point-min))
1178 (re-search-forward "[\200-\377]" nil t))
1179 (or (mail-position-on-field "Content-Type")
1180 (insert "text/plain; charset=ISO-8859-1"))
1181 (or (mail-position-on-field "Content-Transfer-Encoding")
1183 (t (or (mail-position-on-field "Content-Type")
1184 (insert "text/plain; charset=US-ASCII"))
1185 (or (mail-position-on-field "Content-Transfer-Encoding")
1186 (insert "7bit")))))))
1188 (defun gnus-inews-do-fcc ()
1189 "Process FCC: fields in current article buffer.
1190 Unless the first character of the field is `|', the article is saved
1191 to the specified file using the function specified by the variable
1192 gnus-author-copy-saver. The default function rmail-output saves in
1193 Unix mailbox format.
1194 If the first character is `|', the contents of the article is send to
1195 a program specified by the rest of the value."
1196 (let ((fcc-list nil)
1198 (case-fold-search t)) ;Should ignore case.
1201 (goto-char (point-min))
1202 (search-forward "\n\n")
1203 (narrow-to-region (point-min) (point))
1204 (goto-char (point-min))
1205 (while (re-search-forward "^FCC:[ \t]*" nil t)
1207 (cons (buffer-substring
1211 (skip-chars-backward " \t")
1214 (delete-region (match-beginning 0)
1215 (progn (forward-line 1) (point))))
1216 ;; Process FCC operations.
1219 (setq fcc-file (car fcc-list))
1220 (setq fcc-list (cdr fcc-list))
1221 (cond ((string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" fcc-file)
1222 (let ((program (substring fcc-file
1223 (match-beginning 1) (match-end 1))))
1224 ;; Suggested by yuki@flab.fujitsu.junet.
1225 ;; Send article to named program.
1226 (call-process-region (point-min) (point-max) shell-file-name
1227 nil nil nil "-c" program)))
1229 ;; Suggested by hyoko@flab.fujitsu.junet.
1230 ;; Save article in Unix mail format by default.
1231 (gnus-make-directory (file-name-directory fcc-file))
1232 (if (and gnus-author-copy-saver
1233 (not (eq gnus-author-copy-saver 'rmail-output)))
1234 (funcall gnus-author-copy-saver fcc-file)
1235 (if (and (file-readable-p fcc-file) (rmail-file-p fcc-file))
1236 (gnus-output-to-rmail fcc-file)
1237 (rmail-output fcc-file 1 t t))))))))))
1239 (defun gnus-inews-path ()
1241 (let ((login-name (gnus-inews-login-name)))
1242 (cond ((null gnus-use-generic-path)
1243 (concat (nth 1 gnus-select-method) "!" login-name))
1244 ((stringp gnus-use-generic-path)
1245 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1246 (concat gnus-use-generic-path "!" login-name))
1249 (defun gnus-inews-user-name ()
1250 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1251 (let ((full-name (gnus-inews-full-name))
1252 (address (if (or gnus-user-login-name gnus-use-generic-from
1253 gnus-local-domain (getenv "DOMAINNAME"))
1254 (concat (gnus-inews-login-name) "@"
1255 (gnus-inews-domain-name gnus-use-generic-from))
1256 user-mail-address)))
1257 (or gnus-user-from-line
1259 ;; User's full name.
1260 (cond ((string-equal full-name "&") ;Unix hack.
1261 (concat " (" (user-login-name) ")"))
1262 ((string-match "[^ ]+@[^ ]+ +(.*)" address)
1265 (concat " (" full-name ")")))))))
1267 (defun gnus-inews-real-user-address ()
1268 "Return the \"real\" user address.
1269 This function tries to ignore all user modifications, and
1270 give as trustworthy answer as possible."
1271 (concat (user-login-name) "@" (gnus-inews-full-address)))
1273 (defun gnus-inews-login-name ()
1274 "Return login name."
1275 (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1277 (defun gnus-inews-full-name ()
1278 "Return full user name."
1279 (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1281 (defun gnus-inews-domain-name (&optional genericfrom)
1282 "Return user's domain name.
1283 If optional argument GENERICFROM is a string, use it as the domain
1284 name; if it is non-nil, strip off local host name from the domain name.
1285 If the function `system-name' returns full internet name and the
1286 domain is undefined, the domain name is got from it."
1287 (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1288 (let* ((system-name (system-name))
1290 (or (if (stringp genericfrom) genericfrom)
1291 (getenv "DOMAINNAME")
1293 ;; Function `system-name' may return full internet name.
1294 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1295 (if (string-match "\\.." system-name)
1296 ;; Some machines return "name.", and that's not
1298 (substring system-name (1- (match-end 0))))
1299 (read-string "Domain name (no host): ")))
1300 (host (or (if (string-match "\\." system-name)
1301 (substring system-name 0 (match-beginning 0)))
1303 (if (string-equal "." (substring domain 0 1))
1304 (setq domain (substring domain 1)))
1305 ;; Support GENERICFROM as same as standard Bnews system.
1306 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1307 (cond ((null genericfrom)
1308 (concat host "." domain))
1309 ;;((stringp genericfrom) genericfrom)
1311 (if (string-match "\\." (system-name))
1313 (substring user-mail-address
1314 (1+ (string-match "@" user-mail-address))))))
1316 (defun gnus-inews-full-address ()
1317 (let ((domain (gnus-inews-domain-name))
1318 (system (system-name))
1319 (case-fold-search t))
1320 (if (string-match "\\." system) system
1321 (if (string-match (concat "^" (regexp-quote system)) domain) domain
1322 (concat system "." domain)))))
1324 (defun gnus-inews-message-id ()
1325 "Generate unique Message-ID for user."
1326 ;; Message-ID should not contain a slash and should be terminated by
1327 ;; a number. I don't know the reason why it is so.
1328 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1330 (defvar gnus-unique-id-char nil)
1332 ;; If you ever change this function, make sure the new version
1333 ;; cannot generate IDs that the old version could.
1334 ;; You might for example insert a "." somewhere (not next to another dot
1335 ;; or string boundary), or modify the newsreader name to "Ding".
1336 (defun gnus-inews-unique-id ()
1337 ;; Dont use microseconds from (current-time), they may be unsupported.
1338 ;; Instead we use this randomly inited counter.
1339 (setq gnus-unique-id-char
1340 (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1341 ;; (current-time) returns 16-bit ints,
1342 ;; and 2^16*25 just fits into 4 digits i base 36.
1344 (let ((tm (if (fboundp 'current-time)
1345 (current-time) '(12191 46742 287898))))
1347 (if (memq system-type '(ms-dos emx vax-vms))
1348 (let ((user (downcase (gnus-inews-login-name))))
1349 (while (string-match "[^a-z0-9_]" user)
1350 (aset user (match-beginning 0) ?_))
1352 (gnus-number-base36 (user-uid) -1))
1353 (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1354 (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1355 ;; Append the newsreader name, because while the generated
1356 ;; ID is unique to this newsreader, other newsreaders might
1357 ;; otherwise generate the same ID via another algorithm.
1361 (defun gnus-inews-date ()
1362 "Current time string."
1363 (timezone-make-date-arpa-standard
1364 (current-time-string) (current-time-zone)))
1366 (defun gnus-inews-organization ()
1367 "Return user's organization.
1368 The ORGANIZATION environment variable is used if defined.
1369 If not, the variable `gnus-local-organization' is used instead.
1370 If it is a function, the function will be called with the current
1371 newsgroup name as the argument.
1372 If this is a file name, the contents of this file will be used as the
1374 (let* ((organization
1375 (or (getenv "ORGANIZATION")
1376 (if gnus-local-organization
1377 (if (and (symbolp gnus-local-organization)
1378 (fboundp gnus-local-organization))
1379 (funcall gnus-local-organization gnus-newsgroup-name)
1380 gnus-local-organization))
1381 gnus-organization-file
1382 "~/.organization")))
1383 (and (stringp organization)
1384 (> (length organization) 0)
1385 (or (file-exists-p organization)
1386 (string-match " " organization)
1387 (not (string-match "^/usr/lib/" organization)))
1389 (gnus-set-work-buffer)
1390 (if (file-exists-p organization)
1391 (insert-file-contents organization)
1392 (insert organization))
1393 (goto-char (point-min))
1394 (while (re-search-forward " *\n *" nil t)
1395 (replace-match " " t t))
1396 (buffer-substring (point-min) (point-max))))))
1398 (defun gnus-inews-lines ()
1399 "Count the number of lines and return numeric string."
1403 (goto-char (point-min))
1405 (concat "^" (regexp-quote mail-header-separator) "$"))
1407 (int-to-string (count-lines (point) (point-max))))))
1409 (defun gnus-inews-in-reply-to ()
1410 "Return the In-Reply-To header for this message."
1415 ;;; Gnus Mail Functions
1418 ;;; Mail reply commands of Gnus summary mode
1420 (defun gnus-summary-reply (yank &optional yank-articles)
1421 "Reply mail to news author.
1422 If prefix argument YANK is non-nil, original article is yanked automatically.
1423 Customize the variable gnus-mail-reply-method to use another mailer."
1425 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1426 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1427 (gnus-set-global-variables)
1428 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1429 (gnus-summary-select-article)
1430 (bury-buffer gnus-article-buffer)
1431 (gnus-mail-reply (or yank-articles (not (not yank)))))
1433 (defun gnus-summary-reply-with-original (n)
1434 "Reply mail to news author with original article.
1435 Customize the variable gnus-mail-reply-method to use another mailer."
1437 (gnus-summary-reply t (gnus-summary-work-articles n)))
1439 (defun gnus-summary-mail-forward (post)
1440 "Forward the current message to another user.
1441 Customize the variable gnus-mail-forward-method to use another mailer."
1443 (gnus-set-global-variables)
1444 (gnus-summary-select-article)
1445 (gnus-copy-article-buffer)
1447 (gnus-forward-using-post gnus-article-copy)
1448 (gnus-mail-forward gnus-article-copy)))
1450 (defun gnus-summary-post-forward ()
1451 "Forward the current article to a newsgroup."
1453 (gnus-summary-mail-forward t))
1455 (defvar gnus-nastygram-message
1456 "The following article was inappropriately posted to %s.\n"
1457 "Format string to insert in nastygrams.
1458 The current group name will be inserted at \"%s\".")
1460 (defun gnus-summary-mail-nastygram (n)
1461 "Send a nastygram to the author of the current article."
1463 (if (or gnus-expert-user
1465 "Really send a nastygram to the author of the current article? "))
1466 (let ((group gnus-newsgroup-name))
1467 (gnus-summary-reply-with-original n)
1468 (set-buffer gnus-mail-buffer)
1469 (insert (format gnus-nastygram-message group))
1470 (gnus-mail-send-and-exit))))
1472 (defun gnus-summary-mail-other-window ()
1473 "Compose mail in other window.
1474 Customize the variable `gnus-mail-other-window-method' to use another
1477 (gnus-set-global-variables)
1480 (defun gnus-new-mail (&optional to)
1481 (pop-to-buffer gnus-mail-buffer)
1483 (gnus-mail-setup 'new to)
1484 (gnus-inews-modify-mail-mode-map))
1486 (defun gnus-mail-reply (&optional yank to-address followup)
1488 (set-buffer gnus-summary-buffer)
1489 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1490 (cur (cons (current-buffer) (cdr gnus-article-current)))
1491 (winconf (current-window-configuration))
1492 from subject date reply-to message-of to cc
1493 references message-id sender follow-to sendto elt new-cc)
1494 (set-buffer (get-buffer-create gnus-mail-buffer))
1496 (if (and (buffer-modified-p)
1499 "Unsent message being composed; erase it? ")))
1503 (gnus-copy-article-buffer)
1505 (set-buffer gnus-article-copy)
1506 (gnus-narrow-to-headers)
1508 ;; This is a regular reply.
1509 (if (and (symbolp gnus-reply-to-function)
1510 (fboundp gnus-reply-to-function))
1511 (setq follow-to (funcall gnus-reply-to-function group)))
1512 ;; This is a followup.
1513 (if (and (symbolp gnus-followup-to-function)
1514 (fboundp gnus-followup-to-function))
1517 (funcall gnus-followup-to-function group)))))
1518 (setq from (mail-fetch-field "from"))
1519 (setq date (or (mail-fetch-field "date")
1520 (mail-header-date gnus-current-headers)))
1521 (setq message-of (gnus-message-of from date))
1522 (setq sender (mail-fetch-field "sender"))
1523 (setq subject (or (mail-fetch-field "subject") "none"))
1524 ;; Remove any (buggy) Re:'s that are present and make a
1526 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1527 (setq subject (substring subject (match-end 0))))
1528 (setq subject (concat "Re: " subject))
1529 (setq to (mail-fetch-field "to"))
1530 (setq cc (mail-fetch-field "cc"))
1531 (setq reply-to (mail-fetch-field "reply-to"))
1532 (setq references (mail-fetch-field "references"))
1533 (setq message-id (mail-fetch-field "message-id"))
1537 ;; When we followup, we want all the headers, I would think.
1538 (setq new-cc (rmail-dont-reply-to
1540 (if cc (concat (if to ", " "") cc) ""))))
1541 (let ((rmail-dont-reply-to-names
1542 (regexp-quote (mail-strip-quoted-names
1543 (or to-address reply-to from "")))))
1544 (setq new-cc (rmail-dont-reply-to new-cc))))
1548 (setq news-reply-yank-from (or from "(nobody)"))
1549 (setq news-reply-yank-message-id
1550 (or message-id "(unknown Message-ID)"))
1552 ;; Gather the "to" addresses out of the follow-to list and remove
1554 (if (and follow-to (listp follow-to))
1555 (while (setq elt (assoc "To" follow-to))
1556 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1557 (setq follow-to (delq elt follow-to))))
1560 (if followup 'followup 'reply)
1562 (if (and follow-to (not (stringp follow-to))) sendto
1563 (or follow-to reply-to from sender "")))
1565 (if (zerop (length new-cc)) nil new-cc)
1568 (make-local-variable 'gnus-article-reply)
1569 (setq gnus-article-reply cur)
1570 (make-local-variable 'gnus-prev-winconf)
1571 (setq gnus-prev-winconf winconf)
1572 (make-local-variable 'gnus-reply-subject)
1573 (setq gnus-reply-subject subject)
1574 (make-local-variable 'gnus-in-reply-to)
1575 (setq gnus-in-reply-to message-of)
1577 (auto-save-mode auto-save-default)
1578 (gnus-inews-modify-mail-mode-map)
1580 (if (and follow-to (listp follow-to))
1582 (goto-char (point-min))
1583 (re-search-forward "^To:" nil t)
1587 (insert (car (car follow-to)) ": " (cdr (car follow-to)) "\n")
1588 (setq follow-to (cdr follow-to)))))
1589 (nnheader-insert-references references message-id)
1591 ;; Now the headers should be ok, so we do the yanking.
1592 (goto-char (point-min))
1594 (concat "^" (regexp-quote mail-header-separator) "$"))
1597 (gnus-configure-windows 'reply 'force)
1598 (let ((last (point))
1600 (if (not (listp yank))
1603 (mail-yank-original nil))
1604 (or mail-yank-hooks mail-citation-hook
1605 (run-hooks 'news-reply-header-hook)))
1607 (save-window-excursion
1608 (set-buffer gnus-summary-buffer)
1609 (gnus-summary-select-article nil nil nil (car yank))
1610 (gnus-summary-remove-process-mark (car yank)))
1612 (gnus-copy-article-buffer)
1613 (mail-yank-original nil)
1615 (or mail-yank-hooks mail-citation-hook
1616 (run-hooks 'news-reply-header-hook))
1618 (setq yank (cdr yank))))
1620 (gnus-configure-windows 'reply-yank 'force))
1621 (run-hooks 'gnus-mail-hook)))))
1623 (defun gnus-new-news (&optional group)
1624 (let ((winconf (current-window-configuration))
1626 (and gnus-interactive-post
1627 (not gnus-expert-user)
1630 (setq gnus-newsgroup-name
1632 (completing-read "Group: " gnus-active-hashtb)))
1633 (setq subject (read-string "Subject: "))))
1634 (pop-to-buffer gnus-post-news-buffer)
1637 (news-setup nil subject nil group nil)
1638 (gnus-inews-insert-signature)
1639 (and gnus-post-prepare-function
1640 (symbolp gnus-post-prepare-function)
1641 (fboundp gnus-post-prepare-function)
1642 (funcall gnus-post-prepare-function group))
1643 (run-hooks 'gnus-post-prepare-hook)
1644 (make-local-variable 'gnus-prev-winconf)
1645 (setq gnus-prev-winconf winconf)
1646 (gnus-inews-modify-mail-mode-map)
1647 (local-set-key "\C-c\C-c" 'gnus-inews-news)))
1649 (defun gnus-news-followup (&optional yank group)
1651 (set-buffer gnus-summary-buffer)
1652 (if (not (or (not gnus-novice-user)
1655 "Are you sure you want to post to all of USENET? ")))
1657 (let ((group (gnus-group-real-name (or group gnus-newsgroup-name)))
1658 (cur (cons (current-buffer) (cdr gnus-article-current)))
1659 (winconf (current-window-configuration))
1660 from subject date reply-to message-of
1661 references message-id sender follow-to sendto elt
1662 followup-to distribution)
1663 (set-buffer (get-buffer-create gnus-post-news-buffer))
1665 (if (and (buffer-modified-p)
1668 "Unsent message being composed; erase it? ")))
1672 (gnus-copy-article-buffer)
1674 (set-buffer gnus-article-copy)
1675 (gnus-narrow-to-headers)
1676 (if (and (symbolp gnus-followup-to-function)
1677 (fboundp gnus-followup-to-function))
1680 (funcall gnus-followup-to-function group))))
1681 (setq from (mail-fetch-field "from"))
1682 (setq date (or (mail-fetch-field "date")
1683 (mail-header-date gnus-current-headers)))
1684 (setq message-of (gnus-message-of from date))
1685 (setq subject (or (mail-fetch-field "subject") "none"))
1686 ;; Remove any (buggy) Re:'s that are present and make a
1688 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1689 (setq subject (substring subject (match-end 0))))
1690 (setq subject (concat "Re: " subject))
1691 (setq references (mail-fetch-field "references"))
1692 (setq message-id (mail-fetch-field "message-id"))
1693 (setq followup-to (mail-fetch-field "followup-to"))
1694 (setq distribution (mail-fetch-field "distribution"))
1695 ;; Remove bogus distribution.
1696 (and (stringp distribution)
1697 (string-match "world" distribution)
1698 (setq distribution nil))
1701 (setq news-reply-yank-from (or from "(nobody)"))
1702 (setq news-reply-yank-message-id
1703 (or message-id "(unknown Message-ID)"))
1705 ;; Gather the "to" addresses out of the follow-to list and remove
1707 (if (and follow-to (listp follow-to))
1708 (while (setq elt (assoc "Newsgroups" follow-to))
1709 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1710 (setq follow-to (delq elt follow-to))))
1712 (news-setup nil subject nil
1715 gnus-use-followup-to
1716 (or (not (eq gnus-use-followup-to 'ask))
1719 "Use Followup-To %s? " follow-to))))
1723 (make-local-variable 'gnus-article-reply)
1724 (setq gnus-article-reply cur)
1725 (make-local-variable 'gnus-prev-winconf)
1726 (setq gnus-prev-winconf winconf)
1727 (make-local-variable 'gnus-reply-subject)
1728 (setq gnus-reply-subject (mail-header-subject gnus-current-headers))
1729 (make-local-variable 'gnus-in-reply-to)
1730 (setq gnus-in-reply-to message-of)
1732 (gnus-inews-insert-signature)
1734 (and gnus-post-prepare-function
1735 (symbolp gnus-post-prepare-function)
1736 (fboundp gnus-post-prepare-function)
1737 (funcall gnus-post-prepare-function group))
1738 (run-hooks 'gnus-post-prepare-hook)
1740 (auto-save-mode auto-save-default)
1741 (gnus-inews-modify-mail-mode-map)
1742 (local-set-key "\C-c\C-c" 'gnus-inews-news)
1744 (if (and follow-to (listp follow-to))
1746 (goto-char (point-min))
1747 (and (re-search-forward "^Newsgroups:" nil t)
1750 (insert (car (car follow-to)) ": "
1751 (cdr (car follow-to)) "\n")
1752 (setq follow-to (cdr follow-to)))))
1754 ;; If a distribution existed, we use it.
1757 (mail-position-on-field "Distribution")
1758 (insert distribution)))
1760 (nnheader-insert-references references message-id)
1762 ;; Handle `gnus-auto-mail-to-author'.
1763 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
1764 ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
1765 (let ((to (if (if (eq gnus-auto-mail-to-author 'ask)
1766 (y-or-n-p "Also send mail to author? ")
1767 gnus-auto-mail-to-author)
1769 (set-buffer gnus-article-copy)
1770 (gnus-fetch-field "reply-to"))
1772 (x-mail (save-excursion
1773 (set-buffer gnus-article-copy)
1774 (gnus-fetch-field "x-mail-copy-to"))))
1775 ;; Deny sending copy if there's a negative X-Mail-Copy-To
1778 (if (and (string= x-mail "never")
1779 (not (eq gnus-auto-mail-to-author 'force)))
1782 ;; Insert a To or Cc header.
1784 (if (mail-fetch-field "To")
1787 (insert "Cc: " to "\n"))
1788 (mail-position-on-field "To")
1791 ;; Handle author copy using BCC field.
1792 (if (and gnus-mail-self-blind
1793 (not (mail-fetch-field "bcc")))
1795 (mail-position-on-field "Bcc")
1796 (insert (if (stringp gnus-mail-self-blind)
1797 gnus-mail-self-blind
1798 (user-login-name)))))
1799 ;; Handle author copy using FCC field.
1800 (if gnus-author-copy
1802 (mail-position-on-field "Fcc")
1803 (insert gnus-author-copy)))
1805 ;; Now the headers should be ok, so we do the yanking.
1806 (goto-char (point-min))
1808 (concat "^" (regexp-quote mail-header-separator) "$"))
1811 (gnus-configure-windows 'followup 'force)
1812 (let ((last (point))
1814 (if (not (listp yank))
1817 (mail-yank-original nil))
1818 (or mail-yank-hooks mail-citation-hook
1819 (run-hooks 'news-reply-header-hook)))
1821 (save-window-excursion
1822 (set-buffer gnus-summary-buffer)
1823 (gnus-summary-select-article nil nil nil (car yank))
1824 (gnus-summary-remove-process-mark (car yank)))
1826 (gnus-copy-article-buffer)
1827 (mail-yank-original nil)
1829 (or mail-yank-hooks mail-citation-hook
1830 (run-hooks 'news-reply-header-hook))
1832 (setq yank (cdr yank))))
1834 (gnus-configure-windows 'followup-yank 'force))
1836 (make-local-variable 'gnus-article-check-size)
1837 (setq gnus-article-check-size
1838 (cons (buffer-size) (gnus-article-checksum))))))))
1840 (defun gnus-message-of (from date)
1841 "Take a FROM and a DATE and create an IN-REPLY-TO."
1847 (string-match " *at \\| *@ \\| *(\\| *<" from)))
1848 (concat (if stop-pos (substring from 0 stop-pos) from)
1850 (if (or (not date) (string= date ""))
1851 "(unknown date)" date))))))
1853 (defun gnus-mail-yank-original ()
1856 (mail-yank-original nil))
1857 (or mail-yank-hooks mail-citation-hook
1858 (run-hooks 'news-reply-header-hook)))
1860 (defun gnus-mail-send-and-exit (&optional dont-send)
1861 "Send the current mail and return to Gnus."
1863 (let* ((reply gnus-article-reply)
1864 (winconf gnus-prev-winconf)
1865 (address-group gnus-add-to-address)
1866 (to-address (and address-group
1867 (mail-fetch-field "to"))))
1868 (setq gnus-add-to-address nil)
1869 (or dont-send (gnus-mail-send))
1871 ;; This mail group doesn't have a `to-address', so we add one
1874 (gnus-group-add-parameter
1875 address-group (cons 'to-address to-address)))
1876 (if (get-buffer gnus-group-buffer)
1878 (if (gnus-buffer-exists-p (car-safe reply))
1880 (set-buffer (car reply))
1882 (gnus-summary-mark-article-as-replied
1884 (and winconf (set-window-configuration winconf))))))
1886 (defun gnus-put-message ()
1887 "Put the current message in some group and return to Gnus."
1889 (let ((reply gnus-article-reply)
1890 (winconf gnus-prev-winconf)
1891 (group gnus-newsgroup-name)
1894 (or (and group (not (gnus-group-read-only-p group)))
1895 (setq group (read-string "Put in group: " nil
1896 (gnus-writable-groups))))
1897 (and (gnus-gethash group gnus-newsrc-hashtb)
1898 (error "No such group: %s" group))
1903 (gnus-inews-narrow-to-headers)
1904 (let (gnus-deletable-headers)
1905 (if (eq major-mode 'mail-mode)
1906 (gnus-inews-insert-headers gnus-required-mail-headers)
1907 (gnus-inews-insert-headers)))
1908 (goto-char (point-max))
1909 (insert "Gcc: " group "\n")
1914 (if (get-buffer gnus-group-buffer)
1916 (if (gnus-buffer-exists-p (car-safe reply))
1918 (set-buffer (car reply))
1920 (gnus-summary-mark-article-as-replied
1922 (and winconf (set-window-configuration winconf))))))
1925 (defun gnus-forward-make-subject (buffer)
1928 (concat "[" (if (memq 'mail (assoc (symbol-name
1929 (car (gnus-find-method-for-group
1930 gnus-newsgroup-name)))
1931 gnus-valid-select-methods))
1932 (gnus-fetch-field "From")
1933 gnus-newsgroup-name)
1934 "] " (or (gnus-fetch-field "Subject") ""))))
1936 (defun gnus-forward-insert-buffer (buffer)
1937 (let ((beg (goto-char (point-max))))
1938 (insert "------- Start of forwarded message -------\n")
1939 (insert-buffer-substring buffer)
1940 (goto-char (point-max))
1941 (insert "------- End of forwarded message -------\n")
1942 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
1944 (while (setq beg (next-single-property-change (point) 'invisible))
1946 (delete-region beg (or (next-single-property-change
1950 (defun gnus-mail-forward (&optional buffer)
1951 "Forward the current message to another user using mail."
1952 (let* ((forward-buffer (or buffer (current-buffer)))
1953 (winconf (current-window-configuration))
1954 (subject (gnus-forward-make-subject forward-buffer)))
1955 (set-buffer (get-buffer-create gnus-mail-buffer))
1957 (if (and (buffer-modified-p)
1960 "Unsent message being composed; erase it? ")))
1963 (gnus-mail-setup 'forward nil subject)
1964 (gnus-inews-modify-mail-mode-map)
1965 (make-local-variable 'gnus-prev-winconf)
1966 (setq gnus-prev-winconf winconf)
1967 (gnus-forward-insert-buffer forward-buffer)
1968 (goto-char (point-min))
1969 (re-search-forward "^To: " nil t)
1970 (gnus-configure-windows 'mail-forward 'force)
1971 ;; You have a chance to arrange the message.
1972 (run-hooks 'gnus-mail-forward-hook)
1973 (run-hooks 'gnus-mail-hook))))
1975 (defun gnus-forward-using-post (&optional buffer)
1977 (let* ((forward-buffer (or buffer (current-buffer)))
1978 (subject (gnus-forward-make-subject forward-buffer))
1979 (gnus-newsgroup-name nil))
1980 (gnus-post-news 'post nil nil nil nil subject)
1982 (gnus-forward-insert-buffer forward-buffer)
1983 ;; You have a chance to arrange the message.
1984 (run-hooks 'gnus-mail-forward-hook)))))
1986 (defun gnus-mail-other-window-using-mail ()
1987 "Compose mail other window using mail."
1988 (let ((winconf (current-window-configuration)))
1989 (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
1990 (gnus-inews-modify-mail-mode-map)
1991 (make-local-variable 'gnus-prev-winconf)
1992 (setq gnus-prev-winconf winconf)
1993 (run-hooks 'gnus-mail-hook)
1994 (gnus-configure-windows 'summary-mail 'force)))
1996 (defun gnus-article-mail (yank)
1997 "Send a reply to the address near point.
1998 If YANK is non-nil, include the original article."
2002 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
2003 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
2006 (switch-to-buffer gnus-summary-buffer)
2007 (gnus-mail-reply yank address)))))
2010 "Send a bug report to the Gnus maintainers."
2012 (let ((winconf (current-window-configuration)))
2013 (delete-other-windows)
2014 (switch-to-buffer "*Gnus Help Bug*")
2016 (insert gnus-bug-message)
2017 (goto-char (point-min))
2018 (pop-to-buffer "*Gnus Bug*")
2021 (mail-setup gnus-maintainer nil nil nil nil nil)
2022 (auto-save-mode auto-save-default)
2023 (make-local-variable 'gnus-prev-winconf)
2024 (setq gnus-prev-winconf winconf)
2025 (gnus-inews-modify-mail-mode-map)
2026 (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
2027 (goto-char (point-min))
2028 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2030 (insert (format "%s\n%s\n\n\n\n\n" (gnus-version) (emacs-version)))
2032 (goto-char (point-min))
2033 (search-forward "Subject: " nil t)
2036 (defun gnus-bug-mail-send-and-exit ()
2037 "Send the bug message and exit."
2039 (and (get-buffer "*Gnus Help Bug*")
2040 (kill-buffer "*Gnus Help Bug*"))
2041 (gnus-mail-send-and-exit))
2043 (defun gnus-debug ()
2044 "Attemps to go through the Gnus source file and report what variables have been changed.
2045 The source file has to be in the Emacs load path."
2047 (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el"))
2048 file dirs expr olist sym)
2049 (message "Please wait while we snoop your variables...")
2052 (set-buffer (get-buffer-create " *gnus bug info*"))
2053 (buffer-disable-undo (current-buffer))
2056 (setq dirs load-path)
2058 (if (or (not (car dirs))
2059 (not (stringp (car dirs)))
2061 (setq file (concat (file-name-as-directory
2062 (car dirs)) (car files))))))
2063 (setq dirs (cdr dirs))
2065 (insert-file-contents file)
2066 (goto-char (point-min))
2067 (or (re-search-forward "^;;* *Internal variables" nil t)
2068 (error "Malformed sources in file %s" file))
2069 (narrow-to-region (point-min) (point))
2070 (goto-char (point-min))
2071 (while (setq expr (condition-case ()
2072 (read (current-buffer)) (error nil)))
2074 (and (eq (car expr) 'defvar)
2075 (stringp (nth 3 expr))
2076 (or (not (boundp (nth 1 expr)))
2077 (not (equal (eval (nth 2 expr))
2078 (symbol-value (nth 1 expr)))))
2079 (setq olist (cons (nth 1 expr) olist)))
2081 (setq files (cdr files)))
2082 (kill-buffer (current-buffer)))
2083 (insert "------------------- Environment follows -------------------\n\n")
2085 (if (boundp (car olist))
2086 (insert "(setq " (symbol-name (car olist))
2087 (if (or (consp (setq sym (symbol-value (car olist))))
2089 (not (or (eq sym nil)
2092 (prin1-to-string (symbol-value (car olist))) ")\n")
2093 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
2094 (setq olist (cdr olist)))
2096 ;; Remove any null chars - they seem to cause trouble for some
2097 ;; mailers. (Byte-compiled output from the stuff above.)
2098 (goto-char (point-min))
2099 (while (re-search-forward "[\000\200]" nil t)
2100 (replace-match "" t t))))
2103 ;;; Treatment of rejected articles.
2108 (defun gnus-summary-resend-bounced-mail (fetch)
2109 "Re-mail the current message.
2110 This only makes sense if the current message is a bounce message than
2111 contains some mail you have written which has been bounced back to
2113 If FETCH, try to fetch the article that this is a reply to, if indeed
2116 (gnus-summary-select-article t)
2117 ;; Create a mail buffer.
2120 (insert-buffer-substring gnus-article-buffer)
2121 (goto-char (point-min))
2122 (search-forward "\n\n")
2123 ;; We remove everything before the bounced mail.
2126 (if (re-search-forward "[^ \t]*:" nil t)
2132 (gnus-narrow-to-headers)
2133 (nnheader-remove-header gnus-bounced-headers-junk t)
2134 (setq references (mail-fetch-field "references"))
2135 (goto-char (point-max))
2136 (insert mail-header-separator)))
2137 ;; If there are references, we fetch the article we answered to.
2140 (string-match "\\(<[^]+>\\)[ \t]*$" references)
2141 (gnus-summary-refer-article
2142 (substring references (match-beginning 1) (match-end 1)))
2144 (gnus-summary-show-all-headers)
2145 (gnus-configure-windows 'compose-bounce))))
2146 (goto-char (point-min)))
2150 (defun gnus-mail-send ()
2151 "Send the current buffer as mail.
2152 Headers will be generated before sending."
2157 (gnus-inews-narrow-to-headers)
2158 (gnus-inews-insert-headers gnus-required-mail-headers)))
2160 ;; Remove the header separator.
2161 (goto-char (point-min))
2162 (and (re-search-forward
2163 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2164 (replace-match "" t t))
2165 ;; Run final inews hooks. This hook may do FCC.
2166 (run-hooks 'gnus-inews-article-hook)
2168 (gnus-narrow-to-headers)
2169 (nnheader-remove-header "^[gf]cc:" t)
2171 (goto-char (point-min))
2172 (search-forward "\n\n")
2174 (insert mail-header-separator)
2176 (run-hooks 'gnus-message-sent-hook))
2178 (defun gnus-inews-modify-mail-mode-map ()
2179 (use-local-map (copy-keymap (current-local-map)))
2180 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
2181 (local-set-key "\C-c\C-p" 'gnus-put-message)
2182 (local-set-key "\C-c\C-d" 'gnus-enter-into-draft-group))
2184 (defun gnus-mail-setup (type &optional to subject in-reply-to cc
2185 replybuffer actions)
2189 (and (eq type 'reply)
2190 (eq gnus-mail-reply-method 'gnus-mail-reply-using-mhe))
2191 (and (eq type 'forward)
2192 (eq gnus-mail-forward-method 'gnus-mail-forward-using-mhe))
2194 (eq gnus-mail-other-window-method
2195 'gnus-mail-other-window-using-mhe)))
2196 'gnus-mh-mail-setup)
2198 (and (eq type 'reply)
2199 (eq gnus-mail-reply-method 'gnus-mail-reply-using-vm))
2200 (and (eq type 'forward)
2201 (eq gnus-mail-forward-method 'gnus-mail-forward-using-vm))
2203 (eq gnus-mail-other-window-method
2204 'gnus-mail-other-window-using-vm)))
2205 'gnus-vm-mail-setup)
2206 (t 'gnus-sendmail-mail-setup))
2207 to subject in-reply-to cc replybuffer actions))
2209 (defun gnus-sendmail-mail-setup (to subject in-reply-to cc replybuffer actions)
2211 (mail-setup to subject in-reply-to cc replybuffer actions))
2215 ;; Do Gcc handling, which copied the message over to some group.
2216 (defun gnus-inews-do-gcc (&optional gcc)
2219 (gnus-narrow-to-headers)
2220 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
2223 () ; Nothing to be done.
2224 (nnheader-remove-header "gcc")
2225 ;; Copy the article over to some group(s).
2226 (while (string-match
2227 "^[ \t]*\\([^ \t]+\\)\\([ \t]+\\|$\\)" gcc)
2228 (setq end (match-end 0))
2230 (gnus-request-accept-article
2231 (substring gcc (match-beginning 1) (match-end 1)) t)
2233 (setq gcc (substring gcc end))))))))
2235 (defun gnus-inews-insert-gcc ()
2236 (let* ((group gnus-outgoing-message-group)
2238 ((and (symbolp group) (fboundp group))
2240 ((or (stringp group) (list group))
2245 (if (stringp group) group
2246 (mapconcat 'identity group " "))
2249 ;;; Handling rejected (and postponed) news.
2251 (defun gnus-draft-group ()
2252 "Return the name of the draft group."
2253 (gnus-group-prefixed-name
2254 (file-name-nondirectory gnus-draft-group-directory)
2255 (list 'nndir gnus-draft-group-directory)))
2257 (defun gnus-make-draft-group ()
2258 "Make the draft group or die trying."
2259 (let* ((method (` (nndir "private"
2260 (nndir-directory (, gnus-draft-group-directory)))))
2261 (group (gnus-group-prefixed-name
2262 (file-name-nondirectory gnus-draft-group-directory)
2264 (or (gnus-gethash group gnus-newsrc-hashtb)
2265 (gnus-group-make-group (gnus-group-real-name group) method)
2266 (error "Can't create the draft group"))
2269 (defun gnus-enter-into-draft-group ()
2270 "Enter the current buffer into the draft group."
2272 (gnus-put-in-draft-group t))
2274 (defun gnus-put-in-draft-group (&optional generate silent)
2275 "Does the actual putting."
2276 (let ((group (gnus-make-draft-group))
2277 (type (list major-mode (buffer-name) gnus-newsgroup-name
2280 (buf (current-buffer)))
2283 (nnheader-set-temp-buffer " *enter-draft*")
2284 (insert-buffer-substring buf)
2287 (gnus-inews-narrow-to-headers)
2288 (let (gnus-deletable-headers)
2289 (if (eq mode 'mail-mode)
2290 (gnus-inews-insert-headers gnus-required-mail-headers)
2291 (gnus-inews-insert-headers)))
2294 (goto-char (point-min))
2295 ;; We have to store whether we are in a mail group or news group.
2296 (insert (format "X-Gnus-Draft-Type: %S\n" type))
2297 (and (re-search-forward
2298 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2299 (replace-match "" t t))
2301 (gnus-request-accept-article group t)
2302 (kill-buffer (current-buffer)))
2304 (gnus-mail-send-and-exit 'dont-send))))
2305 (set-buffer-modified-p nil)))
2307 (defun gnus-summary-send-draft ()
2308 "Enter a mail/post buffer to edit and send the draft."
2310 (gnus-set-global-variables)
2311 (gnus-summary-select-article t)
2312 ;; First we find the draft type.
2315 (set-buffer gnus-article-buffer)
2317 (gnus-narrow-to-headers)
2318 (setq type (condition-case ()
2319 (read (mail-fetch-field "x-gnus-draft-type"))
2323 (error "Unknown draft type"))
2324 ;; Get to the proper buffer.
2325 (set-buffer (get-buffer-create (nth 1 type)))
2326 ;; It might be modified.
2327 (and (buffer-modified-p)
2328 (or (gnus-yes-or-no-p "Unsent message being composed; discard it? ")
2330 (setq buffer-read-only nil)
2331 (buffer-enable-undo (current-buffer))
2334 (funcall (car type))
2335 (and (eq major-mode 'mail-mode)
2336 (gnus-inews-modify-mail-mode-map))
2337 ;; Arrange for deletion of the draft after successful sending.
2338 (make-local-variable 'gnus-message-sent-hook)
2339 (setq gnus-message-sent-hook
2343 (gnus-request-expire-articles
2344 (quote (, (list (cdr gnus-article-current))))
2345 (, gnus-newsgroup-name) t)))))
2346 ;; Insert the draft.
2347 (insert-buffer-substring gnus-article-buffer)
2348 ;; Insert the separator.
2349 (goto-char (point-min))
2350 (search-forward "\n\n")
2352 (insert mail-header-separator)
2353 ;; Remove the draft header.
2354 (gnus-inews-narrow-to-headers)
2355 (nnheader-remove-header "x-gnus-draft-type")
2357 ;; Configure windows.
2358 (let ((gnus-draft-buffer (current-buffer)))
2359 (gnus-configure-windows 'draft))
2360 ;; Put point where you left it.
2361 (goto-char (nth 3 type))))
2364 ;;; Allow redefinition of functions.
2370 ;;; gnus-msg.el ends here