1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995,96 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 (eval-when-compile (require 'cl))
33 ;; Added by Sudish Joseph <joseph@cis.ohio-state.edu>.
34 (defvar gnus-post-method nil
35 "*Preferred method for posting USENET news.
36 If this variable is nil, Gnus will use the current method to decide
37 which method to use when posting. If it is non-nil, it will override
38 the current method. This method will not be used in mail groups and
39 the like, only in \"real\" newsgroups.
41 The value must be a valid method as discussed in the documentation of
42 `gnus-select-method'. It can also be a list of methods. If that is
43 the case, the user will be queried for what select method to use when
46 (defvar gnus-organization-file "/usr/lib/news/organization"
47 "*Local news organization file.")
49 (defvar gnus-prepare-article-hook nil
50 "*A hook called after preparing body, but before preparing header headers.")
52 (defvar gnus-post-prepare-function nil
53 "*Function that is run after a post buffer has been prepared.
54 It is called with the name of the newsgroup that is posted to. It
55 might be used, for instance, for inserting signatures based on the
56 newsgroup name. (In that case, `gnus-signature-file' and
57 `mail-signature' should both be set to nil).")
59 (defvar gnus-post-prepare-hook nil
60 "*Hook that is run after a post buffer has been prepared.
61 If you want to insert the signature, you might put
62 `gnus-inews-insert-signature' in this hook.")
64 (defvar gnus-use-followup-to 'ask
65 "*Specifies what to do with Followup-To header.
66 If nil, ignore the header. If it is t, use its value, but ignore
67 \"poster\". If it is the symbol `ask', query the user whether to
68 ignore the \"poster\" value. If it is the symbol `use', always use
71 (defvar gnus-followup-to-function nil
72 "*A variable that contains a function that returns a followup address.
73 The function will be called in the buffer of the article that is being
74 followed up. The buffer will be narrowed to the headers of the
75 article. To pick header headers, one might use `mail-fetch-field'. The
76 function will be called with the name of the current newsgroup as the
79 Here's an example `gnus-followup-to-function':
81 (setq gnus-followup-to-function
83 (cond ((string= group \"mail.list\")
84 (or (mail-fetch-field \"sender\")
85 (mail-fetch-field \"from\")))
87 (or (mail-fetch-field \"reply-to\")
88 (mail-fetch-field \"from\"))))))")
90 (defvar gnus-reply-to-function nil
91 "*A variable that contains a function that returns a reply address.
92 See the `gnus-followup-to-function' variable for an explanation of how
93 this variable is used.
95 This function should return a string that will be used to fill in the
96 header. This function may also return a list. In that case, every
97 list element should be a cons where the first car should be a string
98 with the header name, and the cdr should be a string with the header
101 (defvar gnus-author-copy (getenv "AUTHORCOPY")
102 "*Save outgoing articles in this file.
103 Initialized from the AUTHORCOPY environment variable.
105 If this variable begins with the character \"|\", outgoing articles
106 will be piped to the named program. It is possible to save an article
107 in an MH folder as follows:
109 \(setq gnus-author-copy \"|/usr/local/lib/mh/rcvstore +Article\")
111 If the first character is not a pipe, articles are saved using the
112 function specified by the `gnus-author-copy-saver' variable.")
114 (defvar gnus-mail-self-blind nil
115 "*Non-nil means insert a BCC header in all outgoing articles.
116 This will result in having a copy of the article mailed to yourself.
117 The BCC header is inserted when the post buffer is initialized, so you
118 can remove or alter the BCC header to override the default.")
120 (defvar gnus-author-copy-saver (function rmail-output)
121 "*A function called to save outgoing articles.
122 This function will be called with the same of the file to store the
123 article in. The default function is `rmail-output' which saves in Unix
126 (defvar gnus-outgoing-message-group nil
127 "*All outgoing messages will be put in this group.
128 If you want to store all your outgoing mail and articles in the group
129 \"nnml:archive\", you set this variable to that value. This variable
130 can also be a list of group names.
132 If you want to have greater control over what group to put each
133 message in, you can set this variable to a function that checks the
134 current newsgroup name and then returns a suitable group name (or list
137 (defvar gnus-message-archive-group
138 '((if (eq major-mode 'news-reply-mode) "misc-news" "misc-mail"))
139 "*Name of the group in which to save the messages you've written.
140 This can either be a string, a list of strings; or an alist
141 of regexps/functions/forms to be evaluated to return a string (or a list
142 of strings). The functions are called with the name of the current
143 group (or nil) as a parameter.")
145 (defvar gnus-mailing-list-groups nil
146 "*Regexp matching groups that are really mailing lists.
147 This is useful when you're reading a mailing list that has been
148 gatewayed to a newsgroup, and you want to followup to an article in
151 (defvar gnus-draft-group-directory
153 (concat (file-name-as-directory gnus-article-save-directory)
155 "*The directory where draft messages will be stored.")
157 (defvar gnus-posting-styles nil
158 "*Alist of styles to use when posting.")
160 (defvar gnus-posting-style-alist
161 '((organization . gnus-organization-file)
162 (signature . gnus-signature-file)
163 (from . gnus-user-from-line)))
165 (defvar gnus-user-login-name nil
166 "*The login name of the user.
167 Got from the function `user-login-name' if undefined.")
169 (defvar gnus-user-full-name nil
170 "*The full name of the user.
171 Got from the NAME environment variable if undefined.")
173 (defvar gnus-user-from-line nil
174 "*Your full, complete e-mail address.
175 Overrides the other Gnus variables if it is non-nil.
177 Here are two example values of this variable:
179 \"Lars Magne Ingebrigtsen <larsi@ifi.uio.no>\"
183 \"larsi@ifi.uio.no (Lars Magne Ingebrigtsen)\"
185 The first version is recommended, but the name has to be quoted if it
186 contains non-alphanumerical characters.")
188 (defvar gnus-signature-file "~/.signature"
189 "*Your signature file.
190 If the variable is a string that doesn't correspond to a file, the
191 string itself is inserted.")
193 (defvar gnus-signature-function nil
194 "*A function that should return a signature file name.
195 The function will be called with the name of the newsgroup being
197 If the function returns a string that doesn't correspond to a file, the
198 string itself is inserted.
199 If the function returns nil, the `gnus-signature-file' variable will
202 (defvar gnus-forward-start-separator
203 "------- Start of forwarded message -------\n"
204 "*Delimiter inserted before forwarded messages.")
206 (defvar gnus-forward-end-separator
207 "------- End of forwarded message -------\n"
208 "*Delimiter inserted after forwarded messages.")
210 (defvar gnus-signature-before-forwarded-message t
211 "*If non-nil, put the signature before any included forwarded message.")
213 (defvar gnus-forward-included-headers gnus-visible-headers
214 "*Regexp matching headers to be included in forwarded messages.")
216 (defvar gnus-required-headers
217 '(From Date Newsgroups Subject Message-ID Organization Lines X-Newsreader)
218 "*Headers to be generated or prompted for when posting an article.
219 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
220 Message-ID. Organization, Lines, In-Reply-To, Expires, and
221 X-Newsreader are optional. If you want Gnus not to insert some
222 header, remove it from this list.")
224 (defvar gnus-required-mail-headers
225 '(From Date To Subject (optional . In-Reply-To) Message-ID Organization Lines)
226 "*Headers to be generated or prompted for when mailing a message.
227 RFC822 required that From, Date, To, Subject and Message-ID be
228 included. Organization, Lines and X-Mailer are optional.")
230 (defvar gnus-deletable-headers '(Message-ID Date)
231 "*Headers to be deleted if they already exists and were generated by Gnus previously.")
233 (defvar gnus-removable-headers '(NNTP-Posting-Host Bcc Xref)
234 "*Headers to be removed unconditionally before posting.")
236 (defvar gnus-article-expires 14
237 "*Number of days before your article expires.
238 This variable isn't used unless you have the `Expires' element in
239 `gnus-required-headers'.")
241 (defvar gnus-distribution-function nil
242 "*Function that should return the Distribution header for outgoing articles.
243 It will be called from the buffer where the outgoing article
244 is being prepared with the group name as the only parameter.
245 It should return a valid distribution.
247 The function will only be called if you have the `Distribution' header in
248 `gnus-required-headers'.")
250 (defvar gnus-check-before-posting
251 '(subject-cmsg multiple-headers sendsys message-id from
252 long-lines control-chars size new-text
253 redirected-followup signature approved sender empty)
254 "In non-nil, Gnus will attempt to run some checks on outgoing posts.
255 If this variable is t, Gnus will check everything it can. If it is a
256 list, then those elements in that list will be checked.")
258 (defvar gnus-delete-supersedes-headers
259 "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Supersedes:\\|^Xref:\\|^Lines:"
260 "*Header lines matching this regexp will be deleted before posting.
261 It's best to delete old Path and Date headers before posting to avoid
264 (defvar gnus-auto-mail-to-author nil
265 "*If non-nil, mail the authors of articles a copy of your follow-ups.
266 If this variable is `ask', the user will be prompted for whether to
267 mail a copy. The string given by `gnus-mail-courtesy-message' will be
268 inserted at the beginning of the mail copy.")
270 ;; Added by Ethan Bradford <ethanb@ptolemy.astro.washington.edu>.
271 (defvar gnus-mail-courtesy-message
272 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
273 "*This is inserted at the start of a mailed copy of a posted message.
274 If this variable is nil, no such courtesy message will be added.")
276 (defvar gnus-mail-method 'sendmail
277 "*Method to use for composing mail.
278 There are three legal values: `sendmail' (which is the default), `mh',
281 (defvar gnus-mail-reply-method (function gnus-mail-reply-using-mail)
282 "*Function to compose a reply.
283 Three pre-made functions are `gnus-mail-reply-using-mail' (sendmail);
284 `gnus-mail-reply-using-mhe' (MH-E); and `gnus-mail-reply-using-vm'.")
286 (defvar gnus-mail-forward-method (function gnus-mail-forward-using-mail)
287 "*Function to forward the current message to another user.
288 Three pre-made functions are `gnus-mail-forward-using-mail' (sendmail);
289 `gnus-mail-forward-using-mhe' (MH-E); and `gnus-mail-forward-using-vm'.")
291 (defvar gnus-mail-other-window-method 'gnus-mail-other-window-using-mail
292 "*Function to compose mail in the other window.
293 Three pre-made functions are `gnus-mail-other-window-using-mail'
294 (sendmail); `gnus-mail-other-window-using-mhe' (MH-E); and
295 `gnus-mail-other-window-using-vm'.")
297 (defvar gnus-inews-article-function 'gnus-inews-article
298 "*Function to post an article.")
300 (defvar gnus-bounced-headers-junk "^\\(Received\\):"
301 "*Regexp that matches headers to be removed in resent bounced mail.")
303 (defvar gnus-inews-article-hook (list 'gnus-inews-do-fcc)
304 "*A hook called before finally posting an article.
305 The default hook (`gnus-inews-do-fcc') does FCC processing (ie. saves
306 the article to a file).")
308 (defvar gnus-inews-article-header-hook nil
309 "*A hook called after inserting the headers in an article to be posted.
310 The hook is called from the *post-news* buffer, narrowed to the
313 (defvar gnus-mail-hook nil
314 "*A hook called as the last thing after setting up a mail buffer.")
316 (defvar gnus-message-sent-hook nil
317 "*A hook run after an article has been sent (or attempted sent).")
319 ;;; Internal variables.
321 (defvar gnus-post-news-buffer "*post-news*")
322 (defvar gnus-mail-buffer "*mail*")
323 (defvar gnus-article-copy nil)
324 (defvar gnus-reply-subject nil)
325 (defvar gnus-newsgroup-followup nil)
326 (defvar gnus-add-to-address nil)
327 (defvar gnus-in-reply-to nil)
328 (defvar gnus-last-posting-server nil)
332 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
333 (autoload 'news-setup "rnewspost")
334 (autoload 'news-reply-mode "rnewspost")
335 (autoload 'rmail-output "rmailout"))
339 ;;; Gnus Posting Functions
343 (gnus-summary-send-map "S" gnus-summary-mode-map)
344 "p" gnus-summary-post-news
345 "f" gnus-summary-followup
346 "F" gnus-summary-followup-with-original
347 "b" gnus-summary-followup-and-reply
348 "B" gnus-summary-followup-and-reply-with-original
349 "c" gnus-summary-cancel-article
350 "s" gnus-summary-supersede-article
351 "r" gnus-summary-reply
352 "R" gnus-summary-reply-with-original
353 "m" gnus-summary-mail-other-window
354 "u" gnus-uu-post-news
355 "om" gnus-summary-mail-forward
356 "op" gnus-summary-post-forward
357 "Om" gnus-uu-digest-mail-forward
358 "Op" gnus-uu-digest-post-forward)
361 (gnus-send-bounce-map "D" gnus-summary-send-map)
362 "b" gnus-summary-resend-bounced-mail
363 "c" gnus-summary-send-draft
364 "r" gnus-summary-resend-message)
366 ;;; Internal functions.
368 (defun gnus-number-base36 (num len)
369 (if (if (< len 0) (<= num 0) (= len 0))
371 (concat (gnus-number-base36 (/ num 36) (1- len))
372 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
375 ;;; Post news commands of Gnus group mode and summary mode
377 (defun gnus-group-mail ()
378 "Start composing a mail."
381 ;; We might want to prompt here.
382 (when (and gnus-interactive-post
383 (not gnus-expert-user))
384 (read-string "To: "))))
386 (defun gnus-group-post-news (&optional arg)
388 The newsgroup under the cursor is used as the group to post to.
390 If you wish to get an empty post buffer, use a prefix ARG. You can
391 also do this by calling this function from the bottom of the Group
394 (let ((gnus-newsgroup-name nil)
395 (group (unless arg (gnus-group-group-name)))
397 ;; We might want to prompt here.
398 (when (and gnus-interactive-post
399 (not gnus-expert-user))
400 (setq gnus-newsgroup-name
402 (completing-read "Group: " gnus-active-hashtb nil nil
403 (cons (or group "") 0)))))
404 (gnus-post-news 'post group nil gnus-article-buffer)))
406 (defun gnus-summary-post-news ()
409 (gnus-set-global-variables)
410 (gnus-post-news 'post gnus-newsgroup-name))
412 (defun gnus-summary-followup (yank &optional yank-articles)
413 "Compose a followup to an article.
414 If prefix argument YANK is non-nil, original article is yanked automatically."
416 (gnus-set-global-variables)
417 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
418 (save-window-excursion
419 (gnus-summary-select-article))
420 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
421 (gnus-newsgroup-name gnus-newsgroup-name))
422 ;; Check Followup-To: poster.
423 (set-buffer gnus-article-buffer)
424 (if (and gnus-use-followup-to
425 (string-equal "poster" (gnus-fetch-field "followup-to"))
426 (or (not (memq gnus-use-followup-to '(t ask)))
428 "Do you want to ignore `Followup-To: poster'? "))))
429 ;; Mail to the poster.
430 (gnus-summary-reply yank)
432 (gnus-post-news nil gnus-newsgroup-name
433 headers gnus-article-buffer
434 (or yank-articles (not (not yank)))))))
436 (defun gnus-summary-followup-with-original (n)
437 "Compose a followup to an article and include the original article."
439 (gnus-summary-followup t (gnus-summary-work-articles n)))
441 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
442 (defun gnus-summary-followup-and-reply (yank &optional yank-articles)
443 "Compose a followup and do an auto mail to author."
445 (gnus-set-global-variables)
446 (let ((gnus-auto-mail-to-author 'force))
447 (gnus-summary-followup yank yank-articles)))
449 (defun gnus-summary-followup-and-reply-with-original (n)
450 "Compose a followup, include the original, and do an auto mail to author."
452 (gnus-summary-followup-and-reply t (gnus-summary-work-articles n)))
454 (defun gnus-summary-cancel-article (n)
455 "Cancel an article you posted."
457 (gnus-set-global-variables)
458 (let ((articles (gnus-summary-work-articles n))
460 (while (setq article (pop articles))
461 (when (gnus-summary-select-article t nil nil article)
462 (when (gnus-eval-in-buffer-window
463 gnus-original-article-buffer (gnus-cancel-news))
464 (gnus-summary-mark-as-read article gnus-canceled-mark))
465 (gnus-article-hide-headers-if-wanted))
466 (gnus-summary-remove-process-mark article))))
468 (defun gnus-summary-supersede-article ()
469 "Compose an article that will supersede a previous article.
470 This is done simply by taking the old article and adding a Supersedes
471 header line with the old Message-ID."
473 (gnus-set-global-variables)
474 (gnus-summary-select-article t)
475 ;; Check whether the user owns the article that is to be superseded.
476 (unless (string-equal
477 (downcase (mail-strip-quoted-names
478 (mail-header-from gnus-current-headers)))
479 (downcase (mail-strip-quoted-names (gnus-inews-user-name))))
480 (error "This article is not yours."))
481 ;; Get a normal *post-news* buffer.
482 (gnus-new-news gnus-newsgroup-name t)
484 (insert-buffer-substring gnus-original-article-buffer)
485 (nnheader-narrow-to-headers)
486 ;; Remove unwanted headers.
487 (when gnus-delete-supersedes-headers
488 (nnheader-remove-header gnus-delete-supersedes-headers t))
489 (goto-char (point-min))
490 (if (not (re-search-forward "^Message-ID: " nil t))
491 (error "No Message-ID in this article")
492 (replace-match "Supersedes: " t t))
493 (goto-char (point-max))
494 (insert mail-header-separator)
500 (defalias 'sendnews 'gnus-post-news)
503 (defalias 'postnews 'gnus-post-news)
505 (defun gnus-copy-article-buffer (&optional article-buffer)
506 ;; make a copy of the article buffer with all text properties removed
507 ;; this copy is in the buffer gnus-article-copy.
508 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
509 ;; this buffer should be passed to all mail/news reply/post routines.
510 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
511 (buffer-disable-undo gnus-article-copy)
512 (or (memq gnus-article-copy gnus-buffer-list)
513 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
514 (let ((article-buffer (or article-buffer gnus-article-buffer)))
515 (if (and (get-buffer article-buffer)
516 (buffer-name (get-buffer article-buffer)))
518 (set-buffer article-buffer)
520 (copy-to-buffer gnus-article-copy (point-min) (point-max))
521 (set-text-properties (point-min) (point-max)
522 nil gnus-article-copy)))))
524 (defun gnus-post-news (post &optional group header article-buffer yank subject)
525 "Begin editing a new USENET news article to be posted.
526 Type \\[describe-mode] in the buffer to get a list of commands."
527 (interactive (list t))
528 (let* ((group (or group gnus-newsgroup-name))
530 to-address to-group mailing-list to-list)
532 (setq to-address (gnus-group-get-parameter group 'to-address)
533 to-group (gnus-group-get-parameter group 'to-group)
534 to-list (gnus-group-get-parameter group 'to-list)
535 mailing-list (when gnus-mailing-list-groups
536 (string-match gnus-mailing-list-groups group))
537 group (gnus-group-real-name group)))
539 (and (gnus-news-group-p
540 (or pgroup gnus-newsgroup-name)
541 (if header (mail-header-number header) gnus-current-article))
547 (gnus-new-news (or to-group group))
548 (gnus-news-followup yank (or to-group group)))
552 (gnus-new-mail (or to-address to-list))
553 ;; Arrange for mail groups that have no `to-address' to
554 ;; get that when the user sends off the mail.
556 (make-local-variable 'gnus-add-to-address)
557 (setq gnus-add-to-address group)))
558 (gnus-mail-reply yank to-address 'followup)))))
560 (defun gnus-post-method (group query-method &optional silent)
561 "Return the posting method based on GROUP and query-method.
562 If SILENT, don't prompt the user."
563 (let ((group-method (if (stringp group)
564 (gnus-find-method-for-group group)
567 ;; If the group-method is nil (which shouldn't happen) we use
568 ;; the default method.
571 ;; We want this group's method.
572 ((and query-method (not (eq query-method 0)))
574 ;; We query the user for a post method.
576 (and gnus-post-method
577 (listp (car gnus-post-method))))
579 ;; Collect all methods we know about.
581 (when gnus-post-method
582 (if (listp (car gnus-post-method))
584 (listp gnus-post-method)))
585 gnus-secondary-select-methods
586 (list gnus-select-method)
587 (list group-method)))
588 method-alist post-methods method)
589 ;; Weed out all mail methods.
591 (setq method (gnus-server-get-method "" (pop methods)))
592 (when (or (gnus-method-option-p method 'post)
593 (gnus-method-option-p method 'post-mail))
594 (push method post-methods)))
595 ;; Create a name-method alist.
599 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
604 (setq gnus-last-posting-server
606 gnus-last-posting-server)
607 ;; Just use the last value.
608 gnus-last-posting-server
610 "Posting method: " method-alist nil t
611 (cons (or gnus-last-posting-server "") 0))))
613 ;; Override normal method.
614 ((and gnus-post-method
615 (or (gnus-method-option-p group-method 'post)
616 (gnus-method-option-p group-method 'post-mail)))
618 ;; Perhaps this is a mail group?
619 ((and (not (gnus-member-of-valid 'post group))
620 (not (gnus-method-option-p group-method 'post-mail)))
622 ;; Use the normal select method.
623 (t gnus-select-method))))
625 (defun gnus-news-group-p (group &optional article)
626 "Return non-nil if GROUP (and ARTICLE) come from a news server."
627 (or (gnus-member-of-valid 'post group) ; Ordinary news group.
628 (and (gnus-member-of-valid 'post-mail group) ; Combined group.
629 (eq (gnus-request-type group article) 'news))))
631 (defun gnus-inews-news (&optional use-group-method)
632 "Send a news message.
634 If given a non-zero prefix and the group is a foreign group, this
635 function will attempt to use the foreign server to post the article.
637 If given an zero prefix, the user will be prompted for a posting
640 (or gnus-current-select-method
641 (setq gnus-current-select-method gnus-select-method))
642 (let* ((case-fold-search nil)
643 (reply gnus-article-reply)
646 (gnus-start-news-server) ;Use default server.
648 (goto-char (point-min))
649 (run-hooks 'news-inews-hook)
652 (gnus-message 5 "Posting to USENET...")
653 (setq post-result (funcall gnus-inews-article-function use-group-method))
655 ((eq post-result 'illegal)
659 (gnus-message 5 "Posting to USENET...done")
660 (set-buffer-modified-p nil)
661 ;; We mark the article as replied.
662 (when (gnus-buffer-exists-p (car-safe reply))
664 (set-buffer gnus-summary-buffer)
665 (gnus-summary-mark-article-as-replied (cdr reply)))))
667 ;; We cannot signal an error.
671 1 "Article rejected: %s"
673 (gnus-post-method gnus-newsgroup-name use-group-method t))))))
675 (let ((conf gnus-prev-winconf))
678 ;; Restore last window configuration.
679 (and conf (set-window-configuration conf))))))
681 (defun gnus-inews-narrow-to-headers ()
684 (goto-char (point-min))
685 (or (and (re-search-forward
686 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
689 (goto-char (point-min)))
691 (defun gnus-inews-send-mail-copy ()
692 ;; Mail the message if To, Bcc or Cc exists.
693 (let* ((types '("to" "bcc" "cc"))
695 (buffer (current-buffer))
699 (gnus-inews-narrow-to-headers)
702 (or (mail-fetch-field (car ty) nil t)
703 (setq types (delete (car ty) types)))
707 ;; We do not want to send mail.
709 (gnus-message 5 "Sending via mail...")
712 ;; We copy the article over to a temp buffer since we are
713 ;; going to modify it a little.
714 (nnheader-set-temp-buffer " *Gnus-mailing*")
715 (insert-buffer-substring buffer)
716 ;; We remove Fcc, because we don't want the mailer to see
718 (gnus-inews-narrow-to-headers)
719 (nnheader-remove-header "fcc")
721 ;; Insert the X-Courtesy-Message header.
722 (and (or (member "to" types)
725 (goto-char (point-max))
726 (insert "Posted-To: "
727 (mail-fetch-field "newsgroups") "\n")))
731 (if (and gnus-mail-courtesy-message
732 (or (member "to" types)
733 (member "cc" types)))
734 ;; We only want to insert the courtesy mail message if
735 ;; we use To or Cc; Bcc should not have one. Well, if
736 ;; both Bcc and To are present, it will get one
739 ;; Insert "courtesy" mail message.
740 (goto-char (point-min))
742 (concat "^" (regexp-quote mail-header-separator) "$"))
744 (insert gnus-mail-courtesy-message)))
747 (kill-buffer (current-buffer))
748 (gnus-message 5 "Sending via mail...done"))))))
750 (defun gnus-inews-remove-headers-after-mail ()
753 (let ((case-fold-search t))
754 (gnus-inews-narrow-to-headers)
755 ;; Remove Bcc completely.
756 (nnheader-remove-header "bcc")
757 ;; We transform To and Cc headers to avoid re-mailing if the user
758 ;; accidentally (or purposefully) leans on the `C-c C-c' keys
759 ;; and the news server rejects the posting.
760 (while (re-search-forward "^\\(to\\|[bcf]cc\\|cc\\):" nil t)
765 (defun gnus-inews-dex-headers ()
766 "Remove \"X-\" prefixes from To and Cc headers."
769 (let ((case-fold-search t))
770 (nnheader-narrow-to-headers)
771 (while (re-search-forward "^X-\\(to\\|[bcf]cc\\|cc\\):" nil t)
776 (defun gnus-inews-remove-empty-headers ()
777 "Remove empty headers from news and mail.
778 The buffer should be narrowed to the headers before this function is
781 (goto-char (point-min))
782 (while (re-search-forward "^[^ \t:]+:\\([ \t]*\n\\)+[^ \t]" nil t)
783 (delete-region (match-beginning 0) (1- (match-end 0)))
784 (beginning-of-line))))
786 (defun gnus-inews-check-post ()
787 "Check whether the post looks ok."
789 (not gnus-check-before-posting)
791 ;; We narrow to the headers and check them first.
794 (goto-char (point-min))
799 (concat "^" (regexp-quote mail-header-separator) "$"))
800 (match-beginning 0)))
801 (goto-char (point-min))
803 ;; Check for commands in Subject.
805 (gnus-check-before-posting 'subject-cmsg)
807 (if (string-match "^cmsg " (mail-fetch-field "subject"))
809 "The control code \"cmsg \" is in the subject. Really post? ")
811 ;; Check for multiple identical headers.
812 (or (gnus-check-before-posting 'multiple-headers)
815 (while (and (not found) (re-search-forward "^[^ \t:]+: "
818 (or (re-search-forward
819 (concat "^" (setq found
822 (- (match-end 0) 2))))
827 (format "Multiple %s headers. Really post? " found))
829 ;; Check for Version and Sendsys.
830 (or (gnus-check-before-posting 'sendsys)
832 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
834 (format "The article contains a %s command. Really post? "
835 (buffer-substring (match-beginning 0)
836 (1- (match-end 0)))))
838 ;; Check for Approved.
839 (or (gnus-check-before-posting 'approved)
841 (if (re-search-forward "^Approved:" nil t)
843 "The article contains an Approved header. Really post? ")
845 ;; Check whether a Followup-To has redirected the newsgroup.
847 (gnus-check-before-posting 'redirected-followup)
848 (not gnus-newsgroup-followup)
850 (let ((followups (gnus-tokenize-header
851 (mail-fetch-field "Newsgroups")))
852 (newsgroups (gnus-tokenize-header
853 (car gnus-newsgroup-followup)))
855 (while (and followups
856 (not (member followups newsgroups)))
857 (setq followups (cdr followups)))
861 "Followup redirected from original newsgroups. Really post? "
863 ;; Check the Message-ID header.
864 (or (gnus-check-before-posting 'message-id)
866 (let* ((case-fold-search t)
867 (message-id (mail-fetch-field "message-id")))
869 (and (string-match "@" message-id)
870 (string-match "@[^\\.]*\\." message-id))
873 "The Message-ID looks strange: \"%s\". Really post? "
875 ;; Check the From header.
877 (gnus-check-before-posting 'from)
879 (let* ((case-fold-search t)
880 (from (mail-fetch-field "from")))
883 (gnus-y-or-n-p "There is no From line. Really post? "))
884 ((not (string-match "@[^\\.]*\\." from))
887 "The address looks strange: \"%s\". Really post? " from)))
888 ((string-match "(.*).*(.*)" from)
891 "The From header looks strange: \"%s\". Really post? "
893 ((string-match "<[^>]+> *$" from)
894 (let ((name (substring from 0 (match-beginning 0))))
896 (string-match "^ *\"[^\"]*\" *$" name)
897 (not (string-match "[][.!()<>@,;:\\]" name))
900 "The From header name has bogus characters. Really post? "
904 ;; Check for long lines.
905 (or (gnus-check-before-posting 'long-lines)
907 (goto-char (point-min))
909 (concat "^" (regexp-quote mail-header-separator) "$"))
913 (< (current-column) 80))
914 (zerop (forward-line 1))))
918 "You have lines longer than 79 characters. Really post? "))))
919 ;; Check whether the article is empty.
920 (or (gnus-check-before-posting 'empty)
922 (goto-char (point-min))
924 (concat "^" (regexp-quote mail-header-separator) "$"))
926 (or (re-search-forward "[^ \n\t]" nil t)
927 (gnus-y-or-n-p "Empty article. Really post?"))))
928 ;; Check for control characters.
929 (or (gnus-check-before-posting 'control-chars)
931 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
933 "The article contains control characters. Really post? ")
935 ;; Check excessive size.
936 (or (gnus-check-before-posting 'size)
937 (if (> (buffer-size) 60000)
939 (format "The article is %d octets long. Really post? "
942 ;; Use the (size . checksum) variable to see whether the
943 ;; article is empty or has only quoted text.
945 (gnus-check-before-posting 'new-text)
946 (if (and (= (buffer-size) (car gnus-article-check-size))
947 (= (gnus-article-checksum) (cdr gnus-article-check-size)))
949 "It looks like there's no new text in your article. Really post? ")
951 ;; Check the length of the signature.
952 (or (gnus-check-before-posting 'signature)
954 (goto-char (point-max))
955 (if (not (re-search-backward gnus-signature-separator nil t))
957 (if (> (count-lines (point) (point-max)) 5)
960 "Your .sig is %d lines; it should be max 4. Really post? "
961 (count-lines (point) (point-max))))
964 (defun gnus-tokenize-header (header &optional separator)
965 "Split HEADER into a list of header elements.
966 \",\" is used as the separator."
968 (separator (or separator ","))
970 (format "[ \t]*\\([^%s]+\\)?\\(%s\\|\\'\\)" separator separator))
972 (while (and (string-match regexp header beg)
973 (< beg (length header)))
974 (when (match-beginning 1)
975 (push (match-string 1 header) elems))
976 (setq beg (match-end 0)))
979 (defun gnus-article-checksum ()
983 (setq sum (logxor sum (following-char)))
987 ;; Returns non-nil if this type is not to be checked.
988 (defun gnus-check-before-posting (type)
990 (or (not gnus-check-before-posting)
991 (if (listp gnus-check-before-posting)
992 (memq type gnus-check-before-posting)
995 (defun gnus-cancel-news ()
996 "Cancel an article you posted."
998 (if (or gnus-expert-user
999 (gnus-yes-or-no-p "Do you really want to cancel this article? "))
1004 (or (gnus-news-group-p gnus-newsgroup-name)
1005 (error "This backend does not support canceling"))
1007 ;; Get header info. from original article.
1009 (gnus-article-show-all-headers)
1010 (goto-char (point-min))
1011 (search-forward "\n\n" nil 'move)
1012 (narrow-to-region (point-min) (point))
1013 (setq from (mail-fetch-field "from"))
1014 (setq newsgroups (mail-fetch-field "newsgroups"))
1015 (setq message-id (mail-fetch-field "message-id"))
1016 (setq distribution (mail-fetch-field "distribution")))
1017 ;; Verify if the article is absolutely user's by comparing
1018 ;; user id with value of its From: field.
1021 (downcase (mail-strip-quoted-names from))
1022 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
1024 (ding) (gnus-message 3 "This article is not yours.")
1026 ;; Make control article.
1027 (set-buffer (get-buffer-create " *Gnus-canceling*"))
1028 (buffer-disable-undo (current-buffer))
1030 (insert "Newsgroups: " newsgroups "\n"
1031 "From: " (gnus-inews-user-name) "\n"
1032 "Subject: cancel " message-id "\n"
1033 "Control: cancel " message-id "\n"
1035 (concat "Distribution: " distribution "\n")
1037 mail-header-separator "\n"
1038 "This is a cancel message from " from ".\n")
1039 ;; Send the control article to NNTP server.
1040 (gnus-message 5 "Canceling your article...")
1042 (if (funcall gnus-inews-article-function)
1043 (gnus-message 5 "Canceling your article...done")
1046 (gnus-message 1 "Cancel failed; %s"
1047 (gnus-status-message gnus-newsgroup-name))
1050 ;; Kill the article buffer.
1051 (kill-buffer (current-buffer))))))))
1054 ;;; Lowlevel inews interface.
1056 ;; Dummy to avoid byte-compile warning.
1057 (defvar nnspool-rejected-article-hook)
1059 (defun gnus-inews-article (&optional use-group-method)
1060 "Post an article in current buffer using NNTP protocol."
1061 (let ((artbuf (current-buffer))
1064 (goto-char (point-max))
1065 ;; Require a newline at the end of the buffer since inews may
1066 ;; append a .signature.
1067 (or (= (preceding-char) ?\n)
1069 ;; Prepare article headers. All message body such as signature
1070 ;; must be inserted before Lines: field is prepared.
1072 (gnus-inews-narrow-to-headers)
1073 ;; Fix some headers.
1074 (gnus-inews-cleanup-headers)
1075 ;; Remove some headers.
1076 (gnus-inews-remove-headers)
1077 ;; Insert some headers.
1078 (gnus-inews-insert-headers)
1079 ;; Let the user do all of the above.
1080 (run-hooks 'gnus-inews-article-header-hook)
1081 ;; Copy the Gcc header, if any.
1082 (setq gcc (mail-fetch-field "gcc"))
1084 ;; Check whether the article is a good Net Citizen.
1085 (if (and gnus-article-check-size
1086 (not (gnus-inews-check-post)))
1089 ;; We fudge a hook for nnspool.
1090 (setq nnspool-rejected-article-hook
1096 (set-buffer (, (buffer-name)))
1097 (gnus-put-in-draft-group nil 'silent))
1101 1 "Couldn't enter rejected article into draft group")))))))
1103 ;; Looks ok, so we do the nasty.
1105 ;; This hook may insert a signature.
1107 (goto-char (point-min))
1108 (let ((gnus-newsgroup-name (or (mail-fetch-field "newsgroups")
1109 gnus-newsgroup-name)))
1110 (run-hooks 'gnus-prepare-article-hook)))
1111 ;; Send off copies using mail, if that is wanted.
1112 (gnus-inews-send-mail-copy)
1113 ;; Remove more headers.
1114 (gnus-inews-remove-headers-after-mail)
1115 ;; Copy the article over to a temp buffer.
1116 (nnheader-set-temp-buffer " *Gnus-posting*")
1117 (insert-buffer-substring artbuf)
1118 ;; Remove the header separator.
1119 (goto-char (point-min))
1121 (concat "^" (regexp-quote mail-header-separator) "$"))
1122 (replace-match "" t t)
1123 ;; Remove X- prefixes to headers.
1124 (gnus-inews-dex-headers)
1125 ;; Run final inews hooks. This hook may do FCC.
1126 ;; The article must be saved before being posted because
1127 ;; `gnus-request-post' modifies the buffer.
1128 (run-hooks 'gnus-inews-article-hook)
1129 ;; Copy the article over to some group, possibly.
1130 (and gcc (gnus-inews-do-gcc gcc))
1131 ;; Post the article.
1132 (setq result (gnus-request-post
1133 (gnus-post-method gnus-newsgroup-name use-group-method)))
1134 (kill-buffer (current-buffer)))
1135 (run-hooks 'gnus-message-sent-hook)
1136 ;; If the posting was unsuccessful (that it, it was rejected) we
1137 ;; put it into the draft group.
1138 (or result (gnus-put-in-draft-group))
1141 (defun gnus-inews-cleanup-headers ()
1142 ;; Correct newsgroups field: change sequence of spaces to comma and
1143 ;; eliminate spaces around commas. Eliminate imbedded line breaks.
1144 (goto-char (point-min))
1145 (if (re-search-forward "^Newsgroups: +" nil t)
1149 (if (re-search-forward "^[^ \t]" nil t)
1153 (goto-char (point-min))
1154 (while (re-search-forward "\n[ \t]+" nil t)
1155 (replace-match " " t t)) ;No line breaks (too confusing)
1156 (goto-char (point-min))
1157 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
1158 (replace-match "," t t))
1159 (goto-char (point-min))
1160 ;; Remove a trailing comma.
1161 (if (re-search-forward ",$" nil t)
1162 (replace-match "" t t))))
1164 ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
1165 ;; Help save the the world!
1168 (let ((newsgroups (mail-fetch-field "newsgroups"))
1169 (followup-to (mail-fetch-field "followup-to"))
1172 (string-match "," newsgroups) (not followup-to))
1174 (while (string-match "," newsgroups)
1176 (cons (list (substring newsgroups 0 (match-beginning 0)))
1178 (setq newsgroups (substring newsgroups (match-end 0))))
1179 (setq groups (nreverse (cons (list newsgroups) groups)))
1181 (setq to (completing-read
1182 "Followups to: (default all groups) " groups))
1183 (if (> (length to) 0)
1185 (goto-char (point-min))
1186 (insert "Followup-To: " to "\n")))))))
1188 ;; Cleanup Followup-To.
1189 (goto-char (point-min))
1190 (if (search-forward-regexp "^Followup-To: +" nil t)
1194 (if (re-search-forward "^[^ \t]" nil 'end)
1197 (goto-char (point-min))
1198 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
1199 (goto-char (point-min))
1200 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ","))))
1203 (defun gnus-inews-remove-headers ()
1204 (let ((case-fold-search t)
1205 (headers gnus-removable-headers))
1206 ;; Remove toxic headers.
1208 (goto-char (point-min))
1209 (and (re-search-forward
1210 (concat "^" (downcase (format "%s" (car headers))))
1212 (delete-region (progn (beginning-of-line) (point))
1213 (progn (forward-line 1) (point))))
1214 (setq headers (cdr headers)))))
1216 ;;; Since the X-Newsreader/X-Mailer are ``vanity'' headers, they might
1217 ;;; as well include the Emacs version as well.
1218 ;;; The following function works with later GNU Emacs, and XEmacs.
1219 (defun gnus-extended-version ()
1220 "Stringified Gnus version and Emacs version"
1226 ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
1227 (concat "Emacs " (substring emacs-version
1230 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)" emacs-version)
1231 (concat (substring emacs-version
1234 (format " %d.%d" emacs-major-version emacs-minor-version)))
1235 (t emacs-version))))
1237 (defun gnus-inews-insert-headers (&optional headers)
1238 "Prepare article headers.
1239 Headers already prepared in the buffer are not modified.
1240 Headers in `gnus-required-headers' will be generated."
1241 (let* ((Date (gnus-inews-date))
1242 (Message-ID (gnus-inews-message-id))
1243 (Organization (gnus-inews-organization))
1244 (From (gnus-inews-user-name))
1245 (Path (gnus-inews-path))
1248 (In-Reply-To (gnus-inews-in-reply-to))
1250 (Distribution (gnus-inews-distribution))
1251 (Lines (gnus-inews-lines))
1252 (X-Newsreader (gnus-extended-version))
1253 (X-Mailer X-Newsreader)
1254 (Expires (gnus-inews-expires))
1255 (headers (or headers gnus-required-headers))
1256 (case-fold-search t)
1258 ;; First we remove any old generated headers.
1259 (let ((headers gnus-deletable-headers))
1261 (goto-char (point-min))
1262 (and (re-search-forward
1263 (concat "^" (symbol-name (car headers)) ": *") nil t)
1264 (get-text-property (1+ (match-beginning 0)) 'gnus-deletable)
1266 (setq headers (cdr headers))))
1267 ;; If there are References, and no "Re: ", then the thread has
1268 ;; changed name. See Son-of-1036.
1269 (if (and (mail-fetch-field "references")
1270 (get-buffer gnus-article-buffer))
1271 (let ((psubject (gnus-simplify-subject-re
1272 (mail-fetch-field "subject"))))
1273 (or (and psubject gnus-reply-subject
1274 (string= (gnus-simplify-subject-re gnus-reply-subject)
1277 (string-match "@" Message-ID)
1279 (concat (substring Message-ID 0 (match-beginning 0))
1281 (substring Message-ID (match-beginning 0))))))))
1282 ;; Go through all the required headers and see if they are in the
1283 ;; articles already. If they are not, or are empty, they are
1284 ;; inserted automatically - except for Subject, Newsgroups and
1287 (goto-char (point-min))
1288 (setq elem (pop headers))
1290 (setq header (car elem))
1292 (when (or (not (re-search-forward
1293 (concat "^" (downcase (symbol-name header)) ":") nil t))
1295 ;; The header was found. We insert a space after the
1296 ;; colon, if there is none.
1297 (if (/= (following-char) ? ) (insert " "))
1298 ;; Find out whether the header is empty...
1299 (looking-at "[ \t]*$")))
1300 ;; So we find out what value we should insert.
1303 ((and (consp elem) (eq (car elem) 'optional))
1304 ;; This is an optional header. If the cdr of this
1305 ;; is something that is nil, then we do not insert
1307 (setq header (cdr elem))
1308 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
1309 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
1311 ;; The element is a cons. Either the cdr is a
1312 ;; string to be inserted verbatim, or it is a
1313 ;; function, and we insert the value returned from
1315 (or (and (stringp (cdr elem)) (cdr elem))
1316 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
1317 ((and (boundp header) (symbol-value header))
1318 ;; The element is a symbol. We insert the value
1319 ;; of this symbol, if any.
1320 (symbol-value header))
1322 ;; We couldn't generate a value for this header,
1323 ;; so we just ask the user.
1324 (read-from-minibuffer
1325 (format "Empty header for %s; enter value: " header)))))
1326 ;; Finally insert the header.
1328 (not (equal value "")))
1332 ;; This header didn't exist, so we insert it.
1333 (goto-char (point-max))
1334 (insert (symbol-name header) ": " value "\n")
1336 ;; The value of this header was empty, so we clear
1337 ;; totally and insert the new value.
1338 (delete-region (point) (gnus-point-at-eol))
1340 ;; Add the deletable property to the headers that require it.
1341 (and (memq header gnus-deletable-headers)
1342 (progn (beginning-of-line) (looking-at "[^:]+: "))
1343 (add-text-properties
1344 (point) (match-end 0)
1345 '(gnus-deletable t face italic) (current-buffer)))))))
1346 ;; Insert new Sender if the From is strange.
1347 (let ((from (mail-fetch-field "from"))
1348 (sender (mail-fetch-field "sender"))
1349 (secure-sender (gnus-inews-real-user-address)))
1351 (not (gnus-check-before-posting 'sender))
1353 (downcase (car (cdr (gnus-extract-address-components
1355 (downcase (gnus-inews-real-user-address))))
1359 (downcase (car (cdr (gnus-extract-address-components
1361 (downcase secure-sender)))))
1362 (goto-char (point-min))
1363 ;; Rename any old Sender headers to Original-Sender.
1364 (when (re-search-forward "^Sender:" nil t)
1366 (insert "Original-")
1367 (beginning-of-line))
1368 (insert "Sender: " secure-sender "\n")))))
1370 (defun gnus-inews-insert-signature ()
1371 "Insert a signature file.
1372 If `gnus-signature-function' is bound and returns a string, this
1373 string is used instead of the variable `gnus-signature-file'.
1374 In either case, if the string is a file name, this file is
1375 inserted. If the string is not a file name, the string itself is
1378 If you never want any signature inserted, set both of these variables to
1382 (or (and gnus-signature-function
1383 (funcall gnus-signature-function gnus-newsgroup-name))
1384 gnus-signature-file)))
1386 (or (file-exists-p signature)
1387 (string-match " " signature)
1389 "^/[^/]+/" (expand-file-name signature)))))
1391 (goto-char (point-max))
1392 (if (and mail-signature (search-backward "\n-- \n" nil t))
1394 ;; Delete any previous signatures.
1395 (if (search-backward "\n-- \n" nil t)
1396 (delete-region (point) (point-max)))
1397 (or (eolp) (insert "\n"))
1399 (if (file-exists-p signature)
1400 (insert-file-contents signature)
1402 (goto-char (point-max))
1403 (or (bolp) (insert "\n"))))))))
1405 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1406 (defun gnus-inews-insert-mime-headers ()
1407 (goto-char (point-min))
1408 (let ((mail-header-separator
1410 (goto-char (point-min))
1411 (if (and (search-forward (concat "\n" mail-header-separator "\n")
1413 (not (search-backward "\n\n" nil t)))
1414 mail-header-separator
1416 (or (mail-position-on-field "Mime-Version")
1419 (goto-char (point-min))
1420 (re-search-forward "[\200-\377]" nil t))
1421 (or (mail-position-on-field "Content-Type")
1422 (insert "text/plain; charset=ISO-8859-1"))
1423 (or (mail-position-on-field "Content-Transfer-Encoding")
1425 (t (or (mail-position-on-field "Content-Type")
1426 (insert "text/plain; charset=US-ASCII"))
1427 (or (mail-position-on-field "Content-Transfer-Encoding")
1428 (insert "7bit")))))))
1430 (defun gnus-inews-do-fcc ()
1431 "Process Fcc headers in the current buffer.
1432 Unless the first character of the field is `|', the article is saved
1433 to the specified file using the function specified by the variable
1434 gnus-author-copy-saver. The default function rmail-output saves in
1435 Unix mailbox format.
1437 If the first character is `|', the contents of the article is sent to
1438 a program specified by the rest of the value."
1439 (let ((case-fold-search t) ;Should ignore case.
1443 (nnheader-narrow-to-headers)
1444 (while (setq file (mail-fetch-field "fcc"))
1446 (nnheader-remove-header "fcc" nil t))
1447 ;; Process FCC operations.
1450 (setq file (pop list))
1451 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
1452 ;; Pipe the article to the program in question.
1453 (call-process-region (point-min) (point-max) shell-file-name
1454 nil nil nil "-c" (match-string 1 file))
1455 ;; Save the article.
1456 (setq file (expand-file-name file))
1457 (gnus-make-directory (file-name-directory file))
1458 (if (and gnus-author-copy-saver
1459 (not (eq gnus-author-copy-saver 'rmail-output)))
1460 (funcall gnus-author-copy-saver file)
1461 (if (and (file-readable-p file) (mail-file-babyl-p file))
1462 (gnus-output-to-rmail file)
1463 (let ((mail-use-rfc822 t))
1464 (rmail-output file 1 t t))))))))))
1466 (defun gnus-inews-path ()
1468 (let ((login-name (gnus-inews-login-name)))
1469 (cond ((null gnus-use-generic-path)
1470 (concat (nth 1 gnus-select-method) "!" login-name))
1471 ((stringp gnus-use-generic-path)
1472 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1473 (concat gnus-use-generic-path "!" login-name))
1476 (defun gnus-inews-user-name ()
1477 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1478 (let ((full-name (gnus-inews-full-name))
1479 (address (if (or gnus-user-login-name gnus-use-generic-from
1480 gnus-local-domain (getenv "DOMAINNAME"))
1481 (concat (gnus-inews-login-name) "@"
1482 (gnus-inews-domain-name gnus-use-generic-from))
1483 user-mail-address)))
1484 (or gnus-user-from-line
1486 ;; User's full name.
1487 (cond ((string-equal full-name "&") ;Unix hack.
1488 (concat " (" (user-login-name) ")"))
1489 ((string-match "[^ ]+@[^ ]+ +(.*)" address)
1492 (concat " (" full-name ")")))))))
1494 (defun gnus-inews-real-user-address ()
1495 "Return the \"real\" user address.
1496 This function tries to ignore all user modifications, and
1497 give as trustworthy answer as possible."
1498 (concat (user-login-name) "@" (gnus-inews-full-address)))
1500 (defun gnus-inews-login-name ()
1501 "Return login name."
1502 (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1504 (defun gnus-inews-full-name ()
1505 "Return full user name."
1506 (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1508 (defun gnus-inews-domain-name (&optional genericfrom)
1509 "Return user's domain name.
1510 If optional argument GENERICFROM is a string, use it as the domain
1511 name; if it is non-nil, strip off local host name from the domain name.
1512 If the function `system-name' returns full internet name and the
1513 domain is undefined, the domain name is got from it."
1514 (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1515 (let* ((system-name (system-name))
1517 (or (if (stringp genericfrom) genericfrom)
1518 (getenv "DOMAINNAME")
1519 (and (boundp 'mail-host-address)
1522 ;; Function `system-name' may return full internet name.
1523 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1524 (if (string-match "\\.." system-name)
1525 ;; Some machines return "name.", and that's not
1527 (substring system-name (1- (match-end 0))))
1528 (read-string "Domain name (no host): ")))
1529 (host (or (if (string-match "\\." system-name)
1530 (substring system-name 0 (match-beginning 0)))
1532 (if (string-equal "." (substring domain 0 1))
1533 (setq domain (substring domain 1)))
1534 ;; Support GENERICFROM as same as standard Bnews system.
1535 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1536 (cond ((null genericfrom)
1537 (concat host "." domain))
1538 ;;((stringp genericfrom) genericfrom)
1540 (if (string-match "\\." (system-name))
1542 (if (string-match "@\\([^ ]+\\)\\($\\| \\)" user-mail-address)
1543 (substring user-mail-address
1544 (match-beginning 1) (match-end 1))
1547 (defun gnus-inews-full-address ()
1548 (let ((domain (gnus-inews-domain-name))
1549 (system (system-name))
1550 (case-fold-search t))
1551 (if (string-match "\\." system) system
1552 (if (string-match (concat "^" (regexp-quote system)) domain) domain
1553 (concat system "." domain)))))
1555 (defun gnus-inews-expires ()
1556 "Return an Expires header based on `gnus-article-expires'."
1557 (let ((current (current-time))
1558 (future (* 1.0 gnus-article-expires 60 60 24)))
1559 ;; Add the future to current.
1560 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
1561 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
1562 ;; Return the date in the future in UT.
1563 (timezone-make-date-arpa-standard
1564 (current-time-string current) (current-time-zone) '(0 "UT"))))
1566 (defun gnus-inews-distribution ()
1567 "Return the current Distribution header, if any."
1568 (when (and gnus-distribution-function
1569 (fboundp gnus-distribution-function))
1570 (funcall gnus-distribution-function (or gnus-newsgroup-name ""))))
1572 (defun gnus-inews-message-id ()
1573 "Generate unique Message-ID for user."
1574 ;; Message-ID should not contain a slash and should be terminated by
1575 ;; a number. I don't know the reason why it is so.
1576 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1578 (defvar gnus-unique-id-char nil)
1580 ;; If you ever change this function, make sure the new version
1581 ;; cannot generate IDs that the old version could.
1582 ;; You might for example insert a "." somewhere (not next to another dot
1583 ;; or string boundary), or modify the newsreader name to "Ding".
1584 (defun gnus-inews-unique-id ()
1585 ;; Don't use microseconds from (current-time), they may be unsupported.
1586 ;; Instead we use this randomly inited counter.
1587 (setq gnus-unique-id-char
1588 (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1589 ;; (current-time) returns 16-bit ints,
1590 ;; and 2^16*25 just fits into 4 digits i base 36.
1592 (let ((tm (if (fboundp 'current-time)
1593 (current-time) '(12191 46742 287898))))
1595 (if (memq system-type '(ms-dos emx vax-vms))
1596 (let ((user (downcase (gnus-inews-login-name))))
1597 (while (string-match "[^a-z0-9_]" user)
1598 (aset user (match-beginning 0) ?_))
1600 (gnus-number-base36 (user-uid) -1))
1601 (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1602 (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1603 ;; Append the newsreader name, because while the generated
1604 ;; ID is unique to this newsreader, other newsreaders might
1605 ;; otherwise generate the same ID via another algorithm.
1609 (defun gnus-inews-date ()
1610 "Current time string."
1611 (let ((now (current-time)))
1612 (timezone-make-date-arpa-standard
1613 (current-time-string now) (current-time-zone now))))
1615 (defun gnus-inews-organization ()
1616 "Return user's organization.
1617 The ORGANIZATION environment variable is used if defined.
1618 If not, the variable `gnus-local-organization' is used instead.
1619 If it is a function, the function will be called with the current
1620 newsgroup name as the argument.
1621 If this is a file name, the contents of this file will be used as the
1623 (let* ((organization
1624 (or (getenv "ORGANIZATION")
1625 (if gnus-local-organization
1626 (if (gnus-functionp gnus-local-organization)
1627 (funcall gnus-local-organization gnus-newsgroup-name)
1628 gnus-local-organization))
1629 gnus-organization-file
1630 "~/.organization")))
1631 (and (stringp organization)
1632 (> (length organization) 0)
1633 (or (file-exists-p organization)
1634 (string-match " " organization)
1635 (not (string-match "^/usr/lib/\\|^~/" organization)))
1637 (gnus-set-work-buffer)
1638 (if (file-exists-p organization)
1639 (insert-file-contents organization)
1640 (insert organization))
1641 (goto-char (point-min))
1642 (while (re-search-forward " *\n *" nil t)
1643 (replace-match " " t t))
1644 (buffer-substring (point-min) (point-max))))))
1646 (defun gnus-inews-lines ()
1647 "Count the number of lines and return numeric string."
1651 (goto-char (point-min))
1653 (concat "^" (regexp-quote mail-header-separator) "$"))
1655 (int-to-string (count-lines (point) (point-max))))))
1657 (defun gnus-inews-in-reply-to ()
1658 "Return the In-Reply-To header for this message."
1663 ;;; Gnus Mail Functions
1666 ;;; Mail reply commands of Gnus summary mode
1668 (defun gnus-summary-reply (yank &optional yank-articles)
1669 "Reply mail to news author.
1670 If prefix argument YANK is non-nil, original article is yanked automatically.
1671 Customize the variable gnus-mail-reply-method to use another mailer."
1673 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1674 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1675 (gnus-set-global-variables)
1676 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1677 (gnus-summary-select-article)
1678 (bury-buffer gnus-article-buffer)
1679 (gnus-mail-reply (or yank-articles (not (not yank)))))
1681 (defun gnus-summary-reply-with-original (n)
1682 "Reply mail to news author with original article.
1683 Customize the variable gnus-mail-reply-method to use another mailer."
1685 (gnus-summary-reply t (gnus-summary-work-articles n)))
1687 (defun gnus-summary-mail-forward (post)
1688 "Forward the current message to another user.
1689 Customize the variable gnus-mail-forward-method to use another mailer."
1691 (gnus-set-global-variables)
1692 (gnus-summary-select-article)
1693 (gnus-copy-article-buffer)
1695 (gnus-forward-using-post gnus-article-copy)
1696 (gnus-mail-forward gnus-article-copy)))
1698 (defun gnus-summary-resend-message (address)
1699 "Resend the current article to ADDRESS."
1700 (interactive "sResend message to: ")
1701 (gnus-summary-select-article)
1704 ;; We first set up a normal mail buffer.
1705 (nnheader-set-temp-buffer " *Gnus resend*")
1706 ;; This code from sendmail.el
1708 (let ((fill-prefix "\t")
1709 (address-start (point)))
1710 (insert address "\n")
1711 (fill-region-as-paragraph address-start (point-max)))
1712 (insert mail-header-separator "\n")
1713 ;; Insert our usual headers.
1714 (gnus-inews-narrow-to-headers)
1715 (gnus-inews-insert-headers '(From Date To))
1716 (goto-char (point-min))
1717 ;; Rename them all to "Resent-*".
1718 (while (re-search-forward "^[A-Za-z]" nil t)
1723 (delete-region (point) (point-max))
1725 ;; Insert the message to be resent.
1726 (insert-buffer-substring gnus-original-article-buffer)
1727 (goto-char (point-min))
1728 (search-forward "\n\n")
1730 (insert mail-header-separator)
1731 ;; Rename all old ("Also-")Resent headers.
1732 (while (re-search-backward "^\\(Also-\\)?Resent-" beg t)
1737 (kill-buffer (current-buffer)))))
1739 (defun gnus-summary-post-forward ()
1740 "Forward the current article to a newsgroup."
1742 (gnus-summary-mail-forward t))
1744 (defvar gnus-nastygram-message
1745 "The following article was inappropriately posted to %s.\n"
1746 "Format string to insert in nastygrams.
1747 The current group name will be inserted at \"%s\".")
1749 (defun gnus-summary-mail-nastygram (n)
1750 "Send a nastygram to the author of the current article."
1752 (if (or gnus-expert-user
1754 "Really send a nastygram to the author of the current article? "))
1755 (let ((group gnus-newsgroup-name))
1756 (gnus-summary-reply-with-original n)
1757 (set-buffer gnus-mail-buffer)
1758 (insert (format gnus-nastygram-message group))
1759 (gnus-mail-send-and-exit))))
1761 (defun gnus-summary-mail-other-window ()
1762 "Compose mail in other window.
1763 Customize the variable `gnus-mail-other-window-method' to use another
1766 (gnus-set-global-variables)
1768 ;; We might want to prompt here.
1769 (when (and gnus-interactive-post
1770 (not gnus-expert-user))
1771 (read-string "To: ")))
1772 (gnus-configure-windows 'summary-mail 'force))
1774 (defun gnus-new-mail (&optional to)
1776 (when (and gnus-interactive-post
1777 (not gnus-expert-user))
1778 (setq subject (read-string "Subject: ")))
1779 (pop-to-buffer gnus-mail-buffer)
1781 (gnus-mail-setup 'new to subject)
1782 (gnus-inews-insert-gcc)
1783 (gnus-inews-insert-archive-gcc)
1784 (run-hooks 'gnus-mail-hook)))
1786 (defun gnus-mail-reply (&optional yank to-address followup)
1788 (set-buffer gnus-summary-buffer)
1789 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1790 (cur (cons (current-buffer) (cdr gnus-article-current)))
1791 (winconf (current-window-configuration))
1792 from subject date reply-to message-of to cc
1793 references message-id sender follow-to sendto elt new-cc new-to
1795 (set-buffer (get-buffer-create gnus-mail-buffer))
1797 (if (and (buffer-modified-p)
1800 "Unsent message being composed; erase it? ")))
1804 (gnus-copy-article-buffer)
1806 (set-buffer gnus-article-copy)
1807 (nnheader-narrow-to-headers)
1809 ;; This is a regular reply.
1810 (if (gnus-functionp gnus-reply-to-function)
1811 (setq follow-to (funcall gnus-reply-to-function group)))
1812 ;; This is a followup.
1813 (if (gnus-functionp gnus-followup-to-function)
1816 (funcall gnus-followup-to-function group)))))
1817 (setq from (mail-fetch-field "from"))
1818 (setq date (or (mail-fetch-field "date")
1819 (mail-header-date gnus-current-headers)))
1820 (setq message-of (gnus-message-of from date))
1821 (setq sender (mail-fetch-field "sender"))
1822 (setq subject (or (mail-fetch-field "subject") "none"))
1823 ;; Remove any (buggy) Re:'s that are present and make a
1825 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1826 (setq subject (substring subject (match-end 0))))
1827 (setq subject (concat "Re: " subject))
1828 (setq to (mail-fetch-field "to"))
1829 (setq cc (mail-fetch-field "cc"))
1830 (setq mct (mail-fetch-field "mail-copies-to"))
1832 (unless (gnus-group-get-parameter group 'broken-reply-to)
1833 (mail-fetch-field "reply-to")))
1834 (setq references (mail-fetch-field "references"))
1835 (setq message-id (mail-fetch-field "message-id"))
1837 (setq mctdo (not (equal mct "never")))
1839 (if (not (and followup (not to-address)))
1840 (setq new-to (or reply-to from))
1843 (gnus-set-work-buffer)
1844 (unless (equal mct "never")
1845 (insert (or reply-to from "")))
1846 (insert (if (bolp) "" ", ")
1848 (if (or (not mct) (not mctdo)) ""
1849 (concat (if (bolp) "" ", ") mct))
1850 (if cc (concat (if (bolp) "" ", ") cc) ""))
1851 (goto-char (point-min))
1855 (cons (mail-strip-quoted-names addr) addr))
1856 (nreverse (mail-parse-comma-list))))
1859 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
1860 (setq new-to (cdr (pop ccalist)))
1863 (lambda (addr) (cdr addr))
1867 (setq news-reply-yank-from (or from "(nobody)"))
1868 (setq news-reply-yank-message-id
1869 (or message-id "(unknown Message-ID)"))
1871 ;; Gather the "to" addresses out of the follow-to list and remove
1873 (if (and follow-to (listp follow-to))
1874 (while (setq elt (assoc "To" follow-to))
1875 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1876 (setq follow-to (delq elt follow-to))))
1879 (if followup 'followup 'reply)
1881 (if (and follow-to (not (stringp follow-to))) sendto
1882 (or follow-to new-to sender "")))
1884 (if (zerop (length new-cc)) nil new-cc)
1887 (make-local-variable 'gnus-article-reply)
1888 (setq gnus-article-reply cur)
1889 (make-local-variable 'gnus-prev-winconf)
1890 (setq gnus-prev-winconf winconf)
1891 (make-local-variable 'gnus-reply-subject)
1892 (setq gnus-reply-subject subject)
1893 (make-local-variable 'gnus-in-reply-to)
1894 (setq gnus-in-reply-to message-of)
1896 (auto-save-mode auto-save-default)
1897 (gnus-inews-insert-gcc)
1898 (gnus-inews-insert-archive-gcc)
1900 (if (and follow-to (listp follow-to))
1902 (goto-char (point-min))
1903 (re-search-forward "^To:" nil t)
1907 (insert (car (car follow-to)) ": " (cdr (car follow-to)) "\n")
1908 (setq follow-to (cdr follow-to)))))
1909 (nnheader-insert-references references message-id)
1911 ;; Now the headers should be ok, so we do the yanking.
1912 (goto-char (point-min))
1914 (concat "^" (regexp-quote mail-header-separator) "$"))
1917 (gnus-configure-windows 'reply 'force)
1918 (let ((last (point))
1920 (if (not (listp yank))
1922 ;; Just a single article being yanked.
1924 (mail-yank-original nil))
1925 (or mail-yank-hooks mail-citation-hook
1926 (run-hooks 'news-reply-header-hook)))
1928 (save-window-excursion
1929 (set-buffer gnus-summary-buffer)
1930 (gnus-summary-select-article nil nil nil (car yank))
1931 (gnus-summary-remove-process-mark (car yank)))
1934 (gnus-copy-article-buffer)
1935 (mail-yank-original nil)
1937 (narrow-to-region (point-min) (point))
1938 (goto-char (mark t))
1939 (let ((news-reply-yank-from
1941 (set-buffer gnus-article-buffer)
1942 (or (mail-fetch-field "from") "(nobody)")))
1943 (news-reply-yank-message-id
1945 (set-buffer gnus-article-buffer)
1946 (or (mail-fetch-field "message-id")
1947 "(unknown Message-ID)"))))
1948 (or mail-yank-hooks mail-citation-hook
1949 (run-hooks 'news-reply-header-hook))
1950 (setq end (point-max)))))
1952 (setq yank (cdr yank))))
1955 (gnus-configure-windows 'reply-yank 'force))
1956 (run-hooks 'gnus-mail-hook)
1957 ;; Mark this buffer as unchanged.
1958 (set-buffer-modified-p nil)))))
1960 (defun gnus-new-news (&optional group inhibit-prompt)
1961 "Set up a *post-news* buffer that points to GROUP.
1962 If INHIBIT-PROMPT, never prompt for a Subject."
1963 (let ((winconf (current-window-configuration))
1965 (when (and gnus-interactive-post
1966 (not inhibit-prompt)
1967 (not gnus-expert-user))
1968 (setq subject (read-string "Subject: ")))
1969 (pop-to-buffer gnus-post-news-buffer)
1972 ;; Let posting styles be configured.
1973 (gnus-configure-posting-styles)
1974 (news-setup nil subject nil (and group (gnus-group-real-name group)) nil)
1975 ;; Associate this buffer with the draft group.
1976 (gnus-associate-buffer-with-draft)
1977 (goto-char (point-min))
1979 (unless (re-search-forward
1980 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1981 (goto-char (point-max)))
1984 (gnus-inews-insert-bfcc)
1985 (gnus-inews-insert-gcc)
1986 (gnus-inews-insert-archive-gcc)
1987 (gnus-inews-insert-signature)
1988 (and gnus-post-prepare-function
1989 (gnus-functionp gnus-post-prepare-function)
1990 (funcall gnus-post-prepare-function group))
1991 (run-hooks 'gnus-post-prepare-hook)
1992 (gnus-inews-set-point)
1993 (make-local-variable 'gnus-prev-winconf)
1994 (setq gnus-prev-winconf winconf)
1995 (gnus-inews-modify-mail-mode-map)
1996 (local-set-key "\C-c\C-c" 'gnus-inews-news)))
1998 (defun gnus-news-followup (&optional yank group)
2000 (set-buffer gnus-summary-buffer)
2001 (if (not (or (not gnus-novice-user)
2004 "Are you sure you want to post to all of USENET? ")))
2006 (let ((group (gnus-group-real-name (or group gnus-newsgroup-name)))
2007 (cur (cons (current-buffer) (cdr gnus-article-current)))
2008 (winconf (current-window-configuration))
2009 from subject date reply-to message-of
2010 references message-id sender follow-to sendto elt
2011 followup-to distribution newsgroups)
2012 (set-buffer (get-buffer-create gnus-post-news-buffer))
2014 ;; Associate this buffer with the draft group.
2015 (gnus-associate-buffer-with-draft)
2016 (if (and (buffer-modified-p)
2019 "Unsent message being composed; erase it? ")))
2023 (gnus-copy-article-buffer)
2025 (set-buffer gnus-article-copy)
2026 (nnheader-narrow-to-headers)
2027 (if (gnus-functionp gnus-followup-to-function)
2030 (funcall gnus-followup-to-function group))))
2031 (setq from (mail-fetch-field "from"))
2032 (setq date (or (mail-fetch-field "date")
2033 (mail-header-date gnus-current-headers)))
2034 (setq message-of (gnus-message-of from date))
2035 (setq subject (or (mail-fetch-field "subject") "none"))
2036 ;; Remove any (buggy) Re:'s that are present and make a
2038 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
2039 (setq subject (substring subject (match-end 0))))
2040 (setq subject (concat "Re: " subject))
2041 (setq references (mail-fetch-field "references"))
2042 (setq message-id (mail-fetch-field "message-id"))
2043 (setq followup-to (mail-fetch-field "followup-to"))
2044 (setq newsgroups (mail-fetch-field "newsgroups"))
2045 (setq distribution (mail-fetch-field "distribution"))
2046 ;; Remove bogus distribution.
2047 (and (stringp distribution)
2048 (string-match "world" distribution)
2049 (setq distribution nil))
2052 (setq news-reply-yank-from (or from "(nobody)"))
2053 (setq news-reply-yank-message-id
2054 (or message-id "(unknown Message-ID)"))
2056 ;; Gather the "to" addresses out of the follow-to list and remove
2058 (if (and follow-to (listp follow-to))
2059 (while (setq elt (assoc "Newsgroups" follow-to))
2060 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
2061 (setq follow-to (delq elt follow-to))))
2063 ;; Let posting styles be configured.
2064 (gnus-configure-posting-styles)
2066 (news-setup nil subject nil
2069 gnus-use-followup-to
2070 (or (not (eq gnus-use-followup-to 'ask))
2073 "Use Followup-To %s? " followup-to)))
2075 newsgroups group "")
2078 (make-local-variable 'gnus-article-reply)
2079 (setq gnus-article-reply cur)
2080 (make-local-variable 'gnus-prev-winconf)
2081 (setq gnus-prev-winconf winconf)
2082 (make-local-variable 'gnus-reply-subject)
2083 (setq gnus-reply-subject (mail-header-subject gnus-current-headers))
2084 (make-local-variable 'gnus-in-reply-to)
2085 (setq gnus-in-reply-to message-of)
2086 (when (and followup-to newsgroups)
2087 (make-local-variable 'gnus-newsgroup-followup)
2088 (setq gnus-newsgroup-followup
2089 (cons newsgroups followup-to)))
2091 (gnus-inews-insert-signature)
2093 (and gnus-post-prepare-function
2094 (gnus-functionp gnus-post-prepare-function)
2095 (funcall gnus-post-prepare-function group))
2096 (run-hooks 'gnus-post-prepare-hook)
2098 (auto-save-mode auto-save-default)
2099 (gnus-inews-modify-mail-mode-map)
2100 (local-set-key "\C-c\C-c" 'gnus-inews-news)
2102 (if (and follow-to (listp follow-to))
2104 (goto-char (point-min))
2105 (and (re-search-forward "^Newsgroups:" nil t)
2108 (insert (car (car follow-to)) ": "
2109 (cdr (car follow-to)) "\n")
2110 (setq follow-to (cdr follow-to)))))
2112 ;; If a distribution existed, we use it.
2115 (mail-position-on-field "Distribution")
2116 (insert distribution)))
2118 (nnheader-insert-references references message-id)
2120 ;; Handle `gnus-auto-mail-to-author'.
2121 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
2122 ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
2123 (let ((to (if (if (eq gnus-auto-mail-to-author 'ask)
2124 (y-or-n-p "Also send mail to author? ")
2125 gnus-auto-mail-to-author)
2127 (set-buffer gnus-article-copy)
2128 (unless (gnus-group-get-parameter
2129 group 'broken-reply-to)
2130 (gnus-fetch-field "reply-to")))
2132 (x-mail (save-excursion
2133 (set-buffer gnus-article-copy)
2134 (gnus-fetch-field "x-mail-copy-to"))))
2135 ;; Deny sending copy if there's a negative X-Mail-Copy-To
2138 (if (and (string= x-mail "never")
2139 (not (eq gnus-auto-mail-to-author 'force)))
2142 ;; Insert a To or Cc header.
2144 (if (mail-fetch-field "To")
2147 (insert "Cc: " to "\n"))
2148 (mail-position-on-field "To")
2151 (gnus-inews-insert-bfcc)
2152 (gnus-inews-insert-gcc)
2153 (gnus-inews-insert-archive-gcc)
2155 ;; Now the headers should be ok, so we do the yanking.
2156 (goto-char (point-min))
2158 (concat "^" (regexp-quote mail-header-separator) "$"))
2162 (gnus-configure-windows 'followup 'force)
2165 (let ((last (point))
2167 (if (not (listp yank))
2170 (mail-yank-original nil))
2171 (or mail-yank-hooks mail-citation-hook
2172 (run-hooks 'news-reply-header-hook)))
2174 (save-window-excursion
2175 (set-buffer gnus-summary-buffer)
2176 (gnus-summary-select-article nil nil nil (car yank))
2177 (gnus-summary-remove-process-mark (car yank)))
2179 (gnus-copy-article-buffer)
2180 (mail-yank-original nil)
2182 (or mail-yank-hooks mail-citation-hook
2183 (run-hooks 'news-reply-header-hook))
2185 (setq yank (cdr yank))))
2187 (gnus-configure-windows 'followup-yank 'force))
2189 (make-local-variable 'gnus-article-check-size)
2190 (setq gnus-article-check-size
2191 (cons (buffer-size) (gnus-article-checksum)))
2192 (gnus-inews-set-point))))))
2194 (defun gnus-message-of (from date)
2195 "Take a FROM and a DATE and return an IN-REPLY-TO."
2198 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2199 (concat (if stop-pos (substring from 0 stop-pos) from)
2201 (if (or (not date) (string= date ""))
2202 "(unknown date)" date)))))
2204 (defun gnus-mail-yank-original ()
2207 (mail-yank-original nil))
2208 (or mail-yank-hooks mail-citation-hook
2209 (run-hooks 'news-reply-header-hook)))
2211 (defun gnus-mail-send-and-exit (&optional dont-send)
2212 "Send the current mail and return to Gnus."
2214 (let* ((reply gnus-article-reply)
2215 (winconf gnus-prev-winconf)
2216 (address-group gnus-add-to-address)
2217 (to-address (and address-group
2218 (mail-fetch-field "to"))))
2219 (setq gnus-add-to-address nil)
2220 (let ((buffer-file-name nil))
2221 (or dont-send (gnus-mail-send)))
2223 ;; This mail group doesn't have a `to-list', so we add one
2226 (gnus-group-add-parameter
2227 address-group (cons 'to-list to-address)))
2228 (if (get-buffer gnus-group-buffer)
2230 (if (gnus-buffer-exists-p (car-safe reply))
2232 (set-buffer (car reply))
2234 (gnus-summary-mark-article-as-replied
2236 (and winconf (set-window-configuration winconf))))))
2238 (defun gnus-put-message ()
2239 "Put the current message in some group and return to Gnus."
2241 (let ((reply gnus-article-reply)
2242 (winconf gnus-prev-winconf)
2243 (group gnus-newsgroup-name)
2246 (or (and group (not (gnus-group-read-only-p group)))
2247 (setq group (read-string "Put in group: " nil
2248 (gnus-writable-groups))))
2249 (and (gnus-gethash group gnus-newsrc-hashtb)
2250 (error "No such group: %s" group))
2255 (gnus-inews-narrow-to-headers)
2256 (let (gnus-deletable-headers)
2257 (if (eq major-mode 'mail-mode)
2258 (gnus-inews-insert-headers gnus-required-mail-headers)
2259 (gnus-inews-insert-headers)))
2260 (goto-char (point-max))
2261 (insert "Gcc: " group "\n")
2266 (if (get-buffer gnus-group-buffer)
2268 (if (gnus-buffer-exists-p (car-safe reply))
2270 (set-buffer (car reply))
2272 (gnus-summary-mark-article-as-replied
2274 (and winconf (set-window-configuration winconf))))))
2276 (defun gnus-forward-make-subject (buffer)
2279 (concat "[" (if (memq 'mail (assoc (symbol-name
2280 (car (gnus-find-method-for-group
2281 gnus-newsgroup-name)))
2282 gnus-valid-select-methods))
2283 (gnus-fetch-field "From")
2284 gnus-newsgroup-name)
2285 "] " (or (gnus-fetch-field "Subject") ""))))
2287 (defun gnus-forward-insert-buffer (buffer)
2290 ;; Put point where we want it before inserting the forwarded
2292 (if gnus-signature-before-forwarded-message
2293 (goto-char (point-max))
2294 (goto-char (point-min))
2296 (concat "^" (regexp-quote mail-header-separator) "$"))
2298 ;; Narrow to the area we are to insert.
2299 (narrow-to-region (point) (point))
2300 ;; Insert the separators and the forwarded buffer.
2301 (insert gnus-forward-start-separator)
2302 (insert-buffer-substring buffer)
2303 (goto-char (point-max))
2304 (insert gnus-forward-end-separator)
2305 ;; Remove all unwanted headers.
2306 (goto-char (point-min))
2308 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
2311 (delete-non-matching-lines gnus-forward-included-headers))
2312 ;; Delete any invisible text.
2313 (goto-char (point-min))
2315 (while (setq beg (next-single-property-change (point) 'invisible))
2317 (delete-region beg (or (next-single-property-change
2321 (defun gnus-mail-forward (&optional buffer)
2322 "Forward the current message to another user using mail."
2323 (let* ((forward-buffer (or buffer (current-buffer)))
2324 (winconf (current-window-configuration))
2325 (subject (gnus-forward-make-subject forward-buffer)))
2326 (set-buffer (get-buffer-create gnus-mail-buffer))
2327 (if (and (buffer-modified-p)
2330 "Unsent message being composed; erase it? ")))
2333 (gnus-mail-setup 'forward nil subject)
2334 (make-local-variable 'gnus-prev-winconf)
2335 (setq gnus-prev-winconf winconf)
2336 (gnus-forward-insert-buffer forward-buffer)
2337 (goto-char (point-min))
2338 (re-search-forward "^To: ?" nil t)
2339 (gnus-configure-windows 'mail-forward 'force)
2340 ;; You have a chance to arrange the message.
2341 (run-hooks 'gnus-mail-forward-hook)
2342 (run-hooks 'gnus-mail-hook))))
2344 (defun gnus-forward-using-post (&optional buffer)
2346 (let* ((forward-buffer (or buffer (current-buffer)))
2347 (subject (gnus-forward-make-subject forward-buffer))
2348 (gnus-newsgroup-name nil))
2349 (gnus-post-news 'post nil nil nil nil subject)
2351 (gnus-forward-insert-buffer forward-buffer)
2352 ;; You have a chance to arrange the message.
2353 (run-hooks 'gnus-mail-forward-hook)))))
2355 (defun gnus-mail-other-window-using-mail ()
2356 "Compose mail other window using mail."
2357 (let ((winconf (current-window-configuration)))
2358 (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
2359 (gnus-inews-modify-mail-mode-map)
2360 (make-local-variable 'gnus-prev-winconf)
2361 (setq gnus-prev-winconf winconf)
2362 (run-hooks 'gnus-mail-hook)
2363 (gnus-configure-windows 'summary-mail 'force)))
2365 (defun gnus-article-mail (yank)
2366 "Send a reply to the address near point.
2367 If YANK is non-nil, include the original article."
2371 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
2372 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
2375 (switch-to-buffer gnus-summary-buffer)
2376 (gnus-mail-reply yank address)))))
2379 "Send a bug report to the Gnus maintainers."
2381 (let ((winconf (current-window-configuration)))
2382 (delete-other-windows)
2383 (switch-to-buffer "*Gnus Help Bug*")
2385 (insert gnus-bug-message)
2386 (goto-char (point-min))
2387 (pop-to-buffer "*Gnus Bug*")
2390 (mail-setup gnus-maintainer nil nil nil nil nil)
2391 (auto-save-mode auto-save-default)
2392 (make-local-variable 'gnus-prev-winconf)
2393 (setq gnus-prev-winconf winconf)
2394 (gnus-inews-modify-mail-mode-map)
2395 (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
2396 (goto-char (point-min))
2397 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2399 (insert (gnus-version) "\n")
2400 (insert (emacs-version))
2401 (insert "\n\n\n\n\n")
2403 (goto-char (point-min))
2404 (search-forward "Subject: " nil t)
2407 (defun gnus-bug-mail-send-and-exit ()
2408 "Send the bug message and exit."
2410 (and (get-buffer "*Gnus Help Bug*")
2411 (kill-buffer "*Gnus Help Bug*"))
2412 (gnus-mail-send-and-exit))
2414 (defun gnus-debug ()
2415 "Attemps to go through the Gnus source file and report what variables have been changed.
2416 The source file has to be in the Emacs load path."
2418 (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el" "nnmail.el"))
2419 file dirs expr olist sym)
2420 (message "Please wait while we snoop your variables...")
2423 (set-buffer (get-buffer-create " *gnus bug info*"))
2424 (buffer-disable-undo (current-buffer))
2427 (setq dirs load-path)
2429 (if (or (not (car dirs))
2430 (not (stringp (car dirs)))
2432 (setq file (concat (file-name-as-directory
2433 (car dirs)) (car files))))))
2434 (setq dirs (cdr dirs))
2436 (insert-file-contents file)
2437 (goto-char (point-min))
2438 (if (not (re-search-forward "^;;* *Internal variables" nil t))
2439 (message "Malformed sources in file %s" file)
2440 (narrow-to-region (point-min) (point))
2441 (goto-char (point-min))
2442 (while (setq expr (condition-case ()
2443 (read (current-buffer)) (error nil)))
2445 (and (eq (car expr) 'defvar)
2446 (stringp (nth 3 expr))
2447 (or (not (boundp (nth 1 expr)))
2448 (not (equal (eval (nth 2 expr))
2449 (symbol-value (nth 1 expr)))))
2450 (setq olist (cons (nth 1 expr) olist)))
2452 (setq files (cdr files)))
2453 (kill-buffer (current-buffer)))
2454 (when (setq olist (nreverse olist))
2455 (insert "------------------ Environment follows ------------------\n\n"))
2457 (if (boundp (car olist))
2458 (insert "(setq " (symbol-name (car olist))
2459 (if (or (consp (setq sym (symbol-value (car olist))))
2461 (not (or (eq sym nil)
2464 (prin1-to-string (symbol-value (car olist))) ")\n")
2465 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
2466 (setq olist (cdr olist)))
2468 ;; Remove any null chars - they seem to cause trouble for some
2469 ;; mailers. (Byte-compiled output from the stuff above.)
2470 (goto-char (point-min))
2471 (while (re-search-forward "[\000\200]" nil t)
2472 (replace-match "" t t))))
2475 ;;; Treatment of rejected articles.
2480 (defun gnus-summary-resend-bounced-mail (fetch)
2481 "Re-mail the current message.
2482 This only makes sense if the current message is a bounce message than
2483 contains some mail you have written which has been bounced back to
2485 If FETCH, try to fetch the article that this is a reply to, if indeed
2488 (gnus-summary-select-article t)
2489 ;; Create a mail buffer.
2492 (insert-buffer-substring gnus-article-buffer)
2493 (goto-char (point-min))
2494 (search-forward "\n\n")
2495 ;; We remove everything before the bounced mail.
2498 (if (re-search-forward "[^ \t]*:" nil t)
2504 (nnheader-narrow-to-headers)
2505 (nnheader-remove-header gnus-bounced-headers-junk t)
2506 (setq references (mail-fetch-field "references"))
2507 (goto-char (point-max))
2508 (insert mail-header-separator)))
2509 ;; If there are references, we fetch the article we answered to.
2512 (string-match "\\(<[^]+>\\)[ \t]*$" references)
2513 (gnus-summary-refer-article
2514 (substring references (match-beginning 1) (match-end 1)))
2516 (gnus-summary-show-all-headers)
2517 (gnus-configure-windows 'compose-bounce))))
2518 (goto-char (point-min)))
2522 (defun gnus-mail-send ()
2523 "Send the current buffer as mail.
2524 Headers will be generated before sending."
2529 (gnus-inews-narrow-to-headers)
2530 (gnus-inews-insert-headers gnus-required-mail-headers)
2531 (gnus-inews-remove-empty-headers)))
2533 ;; Remove the header separator.
2534 (goto-char (point-min))
2535 (and (re-search-forward
2536 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2537 (replace-match "" t t))
2538 ;; Run final inews hooks. This hook may do FCC.
2539 (run-hooks 'gnus-inews-article-hook)
2541 (nnheader-narrow-to-headers)
2542 (nnheader-remove-header "^[gf]cc:" t)
2544 (goto-char (point-min))
2545 (search-forward "\n\n")
2547 (insert mail-header-separator)
2549 (run-hooks 'gnus-message-sent-hook))
2551 (defun gnus-inews-modify-mail-mode-map ()
2552 (use-local-map (copy-keymap (current-local-map)))
2553 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
2554 (local-set-key "\C-c\C-p" 'gnus-put-message)
2555 (local-set-key "\C-c\C-d" 'gnus-put-in-draft-group))
2557 (defun gnus-mail-setup (type &optional to subject in-reply-to cc
2558 replybuffer actions)
2559 ;; Let posting styles be configured.
2560 (gnus-configure-posting-styles)
2564 (eq gnus-mail-method 'mh)
2565 (and (or (eq type 'reply) (eq type 'followup))
2566 (eq gnus-mail-reply-method 'gnus-mail-reply-using-mhe))
2567 (and (eq type 'forward)
2568 (eq gnus-mail-forward-method 'gnus-mail-forward-using-mhe))
2570 (eq gnus-mail-other-window-method
2571 'gnus-mail-other-window-using-mhe)))
2572 'gnus-mh-mail-setup)
2574 (eq gnus-mail-method 'vm)
2575 (and (or (eq type 'reply) (eq type 'followup))
2576 (eq gnus-mail-reply-method 'gnus-mail-reply-using-vm))
2577 (and (eq type 'forward)
2578 (eq gnus-mail-forward-method 'gnus-mail-forward-using-vm))
2580 (eq gnus-mail-other-window-method
2581 'gnus-mail-other-window-using-vm)))
2582 'gnus-vm-mail-setup)
2583 (t 'gnus-sendmail-mail-setup))
2584 to subject in-reply-to cc replybuffer actions)
2585 ;; Associate this mail buffer with the draft group.
2586 (gnus-associate-buffer-with-draft))
2588 (defun gnus-sendmail-mail-setup (to subject in-reply-to cc replybuffer actions)
2590 (mail-setup to subject nil cc replybuffer actions)
2591 (gnus-inews-set-point)
2592 (gnus-inews-modify-mail-mode-map))
2596 ;; Do Gcc handling, which copied the message over to some group.
2597 (defun gnus-inews-do-gcc (&optional gcc)
2600 (nnheader-narrow-to-headers)
2601 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
2602 (cur (current-buffer))
2603 end groups group method)
2605 (nnheader-remove-header "gcc")
2607 (setq groups (gnus-tokenize-header gcc " "))
2608 ;; Copy the article over to some group(s).
2609 (while (setq group (pop groups))
2612 (cond ((and (null (gnus-get-info group))
2613 (eq (car gnus-message-archive-method)
2614 (car (gnus-group-method-name group))))
2615 ;; If the group doesn't exist, we assume
2616 ;; it's an archive group...
2617 gnus-message-archive-method)
2618 (t (gnus-find-method-for-group group)))))
2619 (unless (gnus-request-group group t method)
2620 (gnus-request-create-group group method))
2621 (gnus-check-server method)
2623 (nnheader-set-temp-buffer " *acc*")
2624 (insert-buffer-substring cur)
2625 (unless (condition-case ()
2626 (gnus-request-accept-article group t method)
2628 (gnus-message 1 "Couldn't store article in group %s: %s"
2629 group (gnus-status-message method))
2631 (kill-buffer (current-buffer)))))))))
2633 (defun gnus-inews-insert-bfcc ()
2634 "Insert Bcc and Fcc headers."
2636 ;; Handle author copy using BCC field.
2637 (when (and gnus-mail-self-blind
2638 (not (mail-fetch-field "bcc")))
2639 (mail-position-on-field "Bcc")
2640 (insert (if (stringp gnus-mail-self-blind)
2641 gnus-mail-self-blind
2642 (user-login-name))))
2643 ;; Handle author copy using FCC field.
2644 (when gnus-author-copy
2645 (mail-position-on-field "Fcc")
2646 (insert gnus-author-copy))))
2648 (defun gnus-inews-insert-gcc ()
2649 "Insert Gcc headers based on `gnus-outgoing-message-group'."
2652 (gnus-inews-narrow-to-headers)
2653 (let* ((group gnus-outgoing-message-group)
2655 ((gnus-functionp group)
2657 ((or (stringp group) (list group))
2661 (if (stringp gcc) gcc
2662 (mapconcat 'identity gcc " "))
2665 (defun gnus-inews-insert-archive-gcc ()
2666 "Insert the Gcc to say where the article is to be archived."
2667 (let* ((var gnus-message-archive-group)
2672 ;; Just a single group.
2674 ((and (listp var) (stringp (car var)))
2675 ;; A list of groups.
2678 ;; An alist of regexps/functions/forms.
2683 ((stringp (caar var))
2685 (when (string-match (caar var)
2686 gnus-newsgroup-name)
2688 ((gnus-functionp (car var))
2690 (funcall (car var) gnus-newsgroup-name))
2692 (eval (car var)))))))
2693 (setq var (cdr var)))
2696 (when (stringp groups)
2697 (setq groups (list groups)))
2700 (gnus-inews-narrow-to-headers)
2701 (goto-char (point-max))
2704 (insert (gnus-group-prefixed-name
2705 (pop groups) gnus-message-archive-method))
2709 ;;; Handling rejected (and postponed) news.
2711 (defun gnus-draft-group ()
2712 "Return the name of the draft group."
2713 (gnus-group-prefixed-name
2714 (file-name-nondirectory gnus-draft-group-directory)
2715 (list 'nndraft gnus-draft-group-directory)))
2717 (defun gnus-make-draft-group ()
2718 "Make the draft group or die trying."
2719 (let* ((method (` (nndraft "private"
2721 (, gnus-draft-group-directory)))))
2722 (group (gnus-draft-group)))
2723 (or (gnus-gethash group gnus-newsrc-hashtb)
2724 (gnus-group-make-group (gnus-group-real-name group) method)
2725 (error "Can't create the draft group"))
2726 (gnus-check-server method)
2729 (defun gnus-put-in-draft-group (&optional generate silent)
2730 "Enter the current buffer into the draft group."
2732 (when (gnus-request-accept-article (gnus-make-draft-group) t)
2734 ;; This function does the proper marking of articles.
2735 (gnus-mail-send-and-exit 'dont-send))
2736 (set-buffer-modified-p nil)))
2738 (defun gnus-associate-buffer-with-draft ()
2740 ;; Make sure the draft group exists.
2741 (gnus-make-draft-group)
2742 ;; Associate the buffer with the draft group.
2743 (let ((article (gnus-request-associate-buffer (gnus-draft-group))))
2744 ;; Arrange for deletion of the draft after successful sending.
2745 (make-local-variable 'gnus-message-sent-hook)
2746 (setq gnus-message-sent-hook
2749 (let ((gnus-verbose-backends nil))
2750 (gnus-request-expire-articles
2751 (quote ,(list article))
2752 ,(gnus-draft-group) t))))))))
2754 (defun gnus-summary-send-draft ()
2755 "Enter a mail/post buffer to edit and send the draft."
2757 (gnus-set-global-variables)
2758 (unless (equal gnus-newsgroup-name (gnus-draft-group))
2759 (error "This function can only be used in the draft buffer"))
2761 (if (not (setq buf (gnus-request-restore-buffer
2762 (gnus-summary-article-number) gnus-newsgroup-name)))
2763 (error "Couldn't restore the article")
2764 (setq point (point))
2765 (switch-to-buffer buf)
2766 (gnus-inews-modify-mail-mode-map)
2767 (when (eq major-mode 'news-reply-mode)
2768 (local-set-key "\C-c\C-c" 'gnus-inews-news))
2769 (gnus-associate-buffer-with-draft)
2770 ;; Insert the separator.
2771 (goto-char (point-min))
2772 (search-forward "\n\n")
2774 (insert mail-header-separator)
2775 ;; Configure windows.
2776 (let ((gnus-draft-buffer (current-buffer)))
2777 (gnus-configure-windows 'draft)
2778 (goto-char (point))))))
2780 (defun gnus-configure-posting-styles ()
2781 "Configure posting styles according to `gnus-posting-styles'."
2782 (let ((styles gnus-posting-styles)
2783 (gnus-newsgroup-name (or gnus-newsgroup-name ""))
2784 style match variable attribute value value-value)
2785 ;; Go through all styles and look for matches.
2787 (setq style (pop styles)
2789 (when (cond ((stringp match)
2790 ;; Regexp string match on the group name.
2791 (string-match match gnus-newsgroup-name))
2792 ((or (symbolp match)
2793 (gnus-functionp match))
2794 (cond ((gnus-functionp match)
2795 ;; Function to be called.
2798 ;; Variable to be checked.
2799 (symbol-value match))))
2801 ;; This is a form to be evaled.
2803 ;; We have a match, so we set the variables.
2805 (setq attribute (pop style)
2806 value (cdr attribute))
2807 ;; We find the variable that is to be modified.
2808 (if (and (not (stringp (car attribute)))
2809 (not (setq variable (cdr (assq (car attribute)
2810 gnus-posting-style-alist)))))
2811 (message "Couldn't find attribute %s" (car attribute))
2812 ;; We set the variable.
2814 (cond ((stringp value)
2816 ((or (symbolp value)
2817 (gnus-functionp value))
2818 (cond ((gnus-functionp value)
2821 (symbol-value value))))
2826 ;; This is an ordinary variable.
2827 (make-local-variable variable)
2828 (set variable value-value))
2829 ;; This is a header to be added to the headers when
2832 (make-local-variable gnus-required-headers)
2833 (make-local-variable gnus-required-mail-headers)
2834 (push (cons (car attribute) value-value)
2835 gnus-required-headers)
2836 (push (cons (car attribute) value-value)
2837 gnus-required-mail-headers)))))))))
2839 (defun gnus-inews-set-point ()
2840 "Move point to where the user probably wants to find it."
2841 (gnus-inews-narrow-to-headers)
2843 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
2844 (search-backward ":" )
2848 (goto-char (point-max))
2851 (unless (looking-at "$")
2852 (forward-line 2)))))
2854 ;;; Allow redefinition of functions.
2860 ;;; gnus-msg.el ends here