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 the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
32 (eval-when-compile (require 'cl))
34 ;; Added by Sudish Joseph <joseph@cis.ohio-state.edu>.
35 (defvar gnus-post-method nil
36 "*Preferred method for posting USENET news.
37 If this variable is nil, Gnus will use the current method to decide
38 which method to use when posting. If it is non-nil, it will override
39 the current method. This method will not be used in mail groups and
40 the like, only in \"real\" newsgroups.
42 The value must be a valid method as discussed in the documentation of
43 `gnus-select-method'. It can also be a list of methods. If that is
44 the case, the user will be queried for what select method to use when
47 (defvar gnus-organization-file "/usr/lib/news/organization"
48 "*Local news organization file.")
50 (defvar gnus-prepare-article-hook nil
51 "*A hook called after preparing body, but before preparing header headers.")
53 (defvar gnus-post-prepare-function nil
54 "*Function that is run after a post buffer has been prepared.
55 It is called with the name of the newsgroup that is posted to. It
56 might be used, for instance, for inserting signatures based on the
57 newsgroup name. (In that case, `gnus-signature-file' and
58 `mail-signature' should both be set to nil).")
60 (defvar gnus-post-prepare-hook nil
61 "*Hook that is run after a post buffer has been prepared.
62 If you want to insert the signature, you might put
63 `gnus-inews-insert-signature' in this hook.")
65 (defvar gnus-use-followup-to 'ask
66 "*Specifies what to do with Followup-To header.
67 If nil, ignore the header. If it is t, use its value, but ignore
68 \"poster\". If it is the symbol `ask', query the user whether to
69 ignore the \"poster\" value. If it is the symbol `use', always use
72 (defvar gnus-followup-to-function nil
73 "*A variable that contains a function that returns a followup address.
74 The function will be called in the buffer of the article that is being
75 followed up. The buffer will be narrowed to the headers of the
76 article. To pick header headers, one might use `mail-fetch-field'. The
77 function will be called with the name of the current newsgroup as the
80 Here's an example `gnus-followup-to-function':
82 (setq gnus-followup-to-function
84 (cond ((string= group \"mail.list\")
85 (or (mail-fetch-field \"sender\")
86 (mail-fetch-field \"from\")))
88 (or (mail-fetch-field \"reply-to\")
89 (mail-fetch-field \"from\"))))))")
91 (defvar gnus-reply-to-function nil
92 "*A variable that contains a function that returns a reply address.
93 See the `gnus-followup-to-function' variable for an explanation of how
94 this variable is used.
96 This function should return a string that will be used to fill in the
97 header. This function may also return a list. In that case, every
98 list element should be a cons where the first car should be a string
99 with the header name, and the cdr should be a string with the header
102 (defvar gnus-author-copy (getenv "AUTHORCOPY")
103 "*Save outgoing articles in this file.
104 Initialized from the AUTHORCOPY environment variable.
106 If this variable begins with the character \"|\", outgoing articles
107 will be piped to the named program. It is possible to save an article
108 in an MH folder as follows:
110 \(setq gnus-author-copy \"|/usr/local/lib/mh/rcvstore +Article\")
112 If the first character is not a pipe, articles are saved using the
113 function specified by the `gnus-author-copy-saver' variable.")
115 (defvar gnus-mail-self-blind nil
116 "*Non-nil means insert a BCC header in all outgoing articles.
117 This will result in having a copy of the article mailed to yourself.
118 The BCC header is inserted when the post buffer is initialized, so you
119 can remove or alter the BCC header to override the default.")
121 (defvar gnus-author-copy-saver (function rmail-output)
122 "*A function called to save outgoing articles.
123 This function will be called with the same of the file to store the
124 article in. The default function is `rmail-output' which saves in Unix
127 (defvar gnus-outgoing-message-group nil
128 "*All outgoing messages will be put in this group.
129 If you want to store all your outgoing mail and articles in the group
130 \"nnml:archive\", you set this variable to that value. This variable
131 can also be a list of group names.
133 If you want to have greater control over what group to put each
134 message in, you can set this variable to a function that checks the
135 current newsgroup name and then returns a suitable group name (or list
138 (defvar gnus-message-archive-group
139 '((if (eq major-mode 'news-reply-mode) "misc-news" "misc-mail"))
140 "*Name of the group in which to save the messages you've written.
141 This can either be a string, a list of strings; or an alist
142 of regexps/functions/forms to be evaluated to return a string (or a list
143 of strings). The functions are called with the name of the current
144 group (or nil) as a parameter.")
146 (defvar gnus-mailing-list-groups nil
147 "*Regexp matching groups that are really mailing lists.
148 This is useful when you're reading a mailing list that has been
149 gatewayed to a newsgroup, and you want to followup to an article in
152 (defvar gnus-draft-group-directory
154 (concat (file-name-as-directory gnus-article-save-directory)
156 "*The directory where draft messages will be stored.")
158 (defvar gnus-use-draft t
159 "*Whether Gnus should use the draft group.")
161 (defvar gnus-posting-styles nil
162 "*Alist of styles to use when posting.")
164 (defvar gnus-posting-style-alist
165 '((organization . gnus-organization-file)
166 (signature . gnus-signature-file)
167 (from . gnus-user-from-line))
168 "*Mapping from style parameters to Gnus variables.")
170 (defvar gnus-user-login-name nil
171 "*The login name of the user.
172 Got from the function `user-login-name' if undefined.")
174 (defvar gnus-user-full-name nil
175 "*The full name of the user.
176 Got from the NAME environment variable if undefined.")
178 (defvar gnus-user-from-line nil
179 "*Your full, complete e-mail address.
180 Overrides the other Gnus variables if it is non-nil.
182 Here are two example values of this variable:
184 \"Lars Magne Ingebrigtsen <larsi@ifi.uio.no>\"
188 \"larsi@ifi.uio.no (Lars Magne Ingebrigtsen)\"
190 The first version is recommended, but the name has to be quoted if it
191 contains non-alphanumerical characters.")
193 (defvar gnus-signature-file "~/.signature"
194 "*Your signature file.
195 If the variable is a string that doesn't correspond to a file, the
196 string itself is inserted.")
198 (defvar gnus-signature-function nil
199 "*A function that should return a signature file name.
200 The function will be called with the name of the newsgroup being
202 If the function returns a string that doesn't correspond to a file, the
203 string itself is inserted.
204 If the function returns nil, the `gnus-signature-file' variable will
207 (defvar gnus-forward-start-separator
208 "------- Start of forwarded message -------\n"
209 "*Delimiter inserted before forwarded messages.")
211 (defvar gnus-forward-end-separator
212 "------- End of forwarded message -------\n"
213 "*Delimiter inserted after forwarded messages.")
215 (defvar gnus-signature-before-forwarded-message t
216 "*If non-nil, put the signature before any included forwarded message.")
218 (defvar gnus-forward-included-headers
219 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-\\|^Message-ID:\\|^References:"
220 "*Regexp matching headers to be included in forwarded messages.")
222 (defvar gnus-required-headers
223 '(From Date Newsgroups Subject Message-ID Organization Lines X-Newsreader)
224 "*Headers to be generated or prompted for when posting an article.
225 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
226 Message-ID. Organization, Lines, In-Reply-To, Expires, and
227 X-Newsreader are optional. If you want Gnus not to insert some
228 header, remove it from this list.")
230 (defvar gnus-required-mail-headers
231 '(From Date To Subject (optional . In-Reply-To) Message-ID Organization Lines)
232 "*Headers to be generated or prompted for when mailing a message.
233 RFC822 required that From, Date, To, Subject and Message-ID be
234 included. Organization, Lines and X-Mailer are optional.")
236 (defvar gnus-deletable-headers '(Message-ID Date)
237 "*Headers to be deleted if they already exists and were generated by Gnus previously.")
239 (defvar gnus-removable-headers '(NNTP-Posting-Host Xref)
240 "*Headers to be removed unconditionally before posting.")
242 (defvar gnus-ignored-resent-headers "^Return-receipt"
243 "*All headers that match this regexp will be deleted when resending a message.")
245 (defvar gnus-article-expires 14
246 "*Number of days before your article expires.
247 This variable isn't used unless you have the `Expires' element in
248 `gnus-required-headers'.")
250 (defvar gnus-distribution-function nil
251 "*Function that should return the Distribution header for outgoing articles.
252 It will be called from the buffer where the outgoing article
253 is being prepared with the group name as the only parameter.
254 It should return a valid distribution.
256 The function will only be called if you have the `Distribution' header in
257 `gnus-required-headers'.")
259 (defvar gnus-check-before-posting
260 '(subject-cmsg multiple-headers sendsys message-id from
261 long-lines control-chars size new-text
262 redirected-followup signature approved sender
264 "In non-nil, Gnus will attempt to run some checks on outgoing posts.
265 If this variable is t, Gnus will check everything it can. If it is a
266 list, then those elements in that list will be checked.")
268 (defvar gnus-delete-supersedes-headers
269 "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Supersedes:\\|^Xref:\\|^Lines:"
270 "*Header lines matching this regexp will be deleted before posting.
271 It's best to delete old Path and Date headers before posting to avoid
274 (defvar gnus-auto-mail-to-author nil
275 "*If non-nil, mail the authors of articles a copy of your follow-ups.
276 If this variable is `ask', the user will be prompted for whether to
277 mail a copy. The string given by `gnus-mail-courtesy-message' will be
278 inserted at the beginning of the mail copy.")
280 ;; Added by Ethan Bradford <ethanb@ptolemy.astro.washington.edu>.
281 (defvar gnus-mail-courtesy-message
282 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
283 "*This is inserted at the start of a mailed copy of a posted message.
284 If this variable is nil, no such courtesy message will be added.")
286 (defvar gnus-mail-method 'sendmail
287 "*Method to use for composing mail.
288 There are three legal values: `sendmail' (which is the default), `mh',
291 (defvar gnus-mail-reply-method (function gnus-mail-reply-using-mail)
292 "*Function to compose a reply.
293 Three pre-made functions are `gnus-mail-reply-using-mail' (sendmail);
294 `gnus-mail-reply-using-mhe' (MH-E); and `gnus-mail-reply-using-vm'.")
296 (defvar gnus-mail-forward-method (function gnus-mail-forward-using-mail)
297 "*Function to forward the current message to another user.
298 Three pre-made functions are `gnus-mail-forward-using-mail' (sendmail);
299 `gnus-mail-forward-using-mhe' (MH-E); and `gnus-mail-forward-using-vm'.")
301 (defvar gnus-mail-other-window-method 'gnus-mail-other-window-using-mail
302 "*Function to compose mail in the other window.
303 Three pre-made functions are `gnus-mail-other-window-using-mail'
304 (sendmail); `gnus-mail-other-window-using-mhe' (MH-E); and
305 `gnus-mail-other-window-using-vm'.")
307 (defvar gnus-inews-article-function 'gnus-inews-article
308 "*Function to post an article.")
310 (defvar gnus-bounced-headers-junk "^\\(Received\\):"
311 "*Regexp that matches headers to be removed in resent bounced mail.")
313 (defvar gnus-sent-message-ids-file
314 (concat (file-name-as-directory gnus-article-save-directory)
316 "File where Gnus saves a cache of sent message ids.")
318 (defvar gnus-sent-message-ids-length 1000
319 "The number of sent Message-IDs to save.")
321 (defvar gnus-inews-article-hook (list 'gnus-inews-do-fcc)
322 "*A hook called before finally posting an article.
323 The default hook (`gnus-inews-do-fcc') does FCC processing (ie. saves
324 the article to a file).")
326 (defvar gnus-inews-article-header-hook nil
327 "*A hook called after inserting the headers in an article to be posted.
328 The hook is called from the *post-news* buffer, narrowed to the
331 (defvar gnus-mail-hook nil
332 "*A hook called as the last thing after setting up a mail buffer.")
334 (defvar gnus-message-sent-hook nil
335 "*A hook run after an article has been sent (or attempted sent).")
337 ;;; Internal variables.
339 (defvar gnus-post-news-buffer "*Post Gnus*")
340 (defvar gnus-mail-buffer "*Mail Gnus*")
341 (defvar gnus-article-copy nil)
342 (defvar gnus-reply-subject nil)
343 (defvar gnus-newsgroup-followup nil)
344 (defvar gnus-add-to-address nil)
345 (defvar gnus-in-reply-to nil)
346 (defvar gnus-last-posting-server nil)
349 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
350 (autoload 'news-setup "rnewspost")
351 (autoload 'news-reply-mode "rnewspost")
352 (autoload 'rmail-dont-reply-to "mail-utils")
353 (autoload 'rmail-output "rmailout"))
357 ;;; Gnus Posting Functions
361 (gnus-summary-send-map "S" gnus-summary-mode-map)
362 "p" gnus-summary-post-news
363 "f" gnus-summary-followup
364 "F" gnus-summary-followup-with-original
365 "b" gnus-summary-followup-and-reply
366 "B" gnus-summary-followup-and-reply-with-original
367 "c" gnus-summary-cancel-article
368 "s" gnus-summary-supersede-article
369 "r" gnus-summary-reply
370 "R" gnus-summary-reply-with-original
371 "m" gnus-summary-mail-other-window
372 "u" gnus-uu-post-news
373 "om" gnus-summary-mail-forward
374 "op" gnus-summary-post-forward
375 "Om" gnus-uu-digest-mail-forward
376 "Op" gnus-uu-digest-post-forward)
379 (gnus-send-bounce-map "D" gnus-summary-send-map)
380 "b" gnus-summary-resend-bounced-mail
381 "c" gnus-summary-send-draft
382 "r" gnus-summary-resend-message)
384 ;;; Internal functions.
386 (defun gnus-number-base36 (num len)
387 (if (if (< len 0) (<= num 0) (= len 0))
389 (concat (gnus-number-base36 (/ num 36) (1- len))
390 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
393 ;;; Post news commands of Gnus group mode and summary mode
395 (defun gnus-group-mail ()
396 "Start composing a mail."
399 ;; We might want to prompt here.
400 (when (and gnus-interactive-post
401 (not gnus-expert-user))
402 (read-string "To: ")))
403 (gnus-configure-windows 'group-mail 'force))
405 (defun gnus-group-post-news (&optional arg)
407 The newsgroup under the cursor is used as the group to post to.
409 If you wish to get an empty post buffer, use a prefix ARG. You can
410 also do this by calling this function from the bottom of the Group
413 (let ((gnus-newsgroup-name nil)
414 (group (unless arg (gnus-group-group-name))))
415 ;; We might want to prompt here.
416 (when (and gnus-interactive-post
417 (not gnus-expert-user))
418 (setq gnus-newsgroup-name
420 (completing-read "Group: " gnus-active-hashtb nil nil
421 (cons (or group "") 0)))))
422 (gnus-post-news 'post group nil gnus-article-buffer)
423 (if (eq major-mode 'news-reply-mode)
424 (gnus-configure-windows 'group-post t)
425 (gnus-configure-windows 'group-mail t))))
427 (defun gnus-summary-post-news ()
430 (gnus-set-global-variables)
431 (gnus-post-news 'post gnus-newsgroup-name))
433 (defun gnus-summary-followup (yank &optional yank-articles)
434 "Compose a followup to an article.
435 If prefix argument YANK is non-nil, original article is yanked automatically."
437 (gnus-set-global-variables)
438 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
439 (save-window-excursion
440 (gnus-summary-select-article))
441 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
442 (gnus-newsgroup-name gnus-newsgroup-name))
443 ;; Check Followup-To: poster.
444 (set-buffer gnus-article-buffer)
445 (if (and gnus-use-followup-to
446 (string-equal "poster" (gnus-fetch-field "followup-to"))
447 (or (not (memq gnus-use-followup-to '(t ask)))
449 "Do you want to ignore `Followup-To: poster'? "))))
450 ;; Mail to the poster.
452 (set-buffer gnus-summary-buffer)
453 (gnus-summary-reply yank))
455 (gnus-post-news nil gnus-newsgroup-name
456 headers gnus-article-buffer
457 (or yank-articles (not (not yank)))))))
459 (defun gnus-summary-followup-with-original (n)
460 "Compose a followup to an article and include the original article."
462 (gnus-summary-followup t (gnus-summary-work-articles n)))
464 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
465 (defun gnus-summary-followup-and-reply (yank &optional yank-articles)
466 "Compose a followup and do an auto mail to author."
468 (gnus-set-global-variables)
469 (let ((gnus-auto-mail-to-author 'force))
470 (gnus-summary-followup yank yank-articles)))
472 (defun gnus-summary-followup-and-reply-with-original (n)
473 "Compose a followup, include the original, and do an auto mail to author."
475 (gnus-summary-followup-and-reply t (gnus-summary-work-articles n)))
477 (defun gnus-summary-cancel-article (n)
478 "Cancel an article you posted."
480 (gnus-set-global-variables)
481 (let ((articles (gnus-summary-work-articles n))
483 (while (setq article (pop articles))
484 (when (gnus-summary-select-article t nil nil article)
485 (when (gnus-eval-in-buffer-window
486 gnus-original-article-buffer (gnus-cancel-news))
487 (gnus-summary-mark-as-read article gnus-canceled-mark))
488 (gnus-article-hide-headers-if-wanted))
489 (gnus-summary-remove-process-mark article))))
491 (defun gnus-summary-supersede-article ()
492 "Compose an article that will supersede a previous article.
493 This is done simply by taking the old article and adding a Supersedes
494 header line with the old Message-ID."
496 (gnus-set-global-variables)
497 (gnus-summary-select-article t)
498 ;; Check whether the user owns the article that is to be superseded.
499 (unless (string-equal
500 (downcase (gnus-mail-strip-quoted-names
501 (mail-header-from gnus-current-headers)))
502 (downcase (gnus-mail-strip-quoted-names (gnus-inews-user-name))))
503 (error "This article is not yours."))
504 ;; Get a normal *Post News* buffer.
505 (gnus-new-news gnus-newsgroup-name t)
507 (insert-buffer-substring gnus-original-article-buffer)
508 (nnheader-narrow-to-headers)
509 ;; Remove unwanted headers.
510 (when gnus-delete-supersedes-headers
511 (nnheader-remove-header gnus-delete-supersedes-headers t))
512 (goto-char (point-min))
513 (if (not (re-search-forward "^Message-ID: " nil t))
514 (error "No Message-ID in this article")
515 (replace-match "Supersedes: " t t))
516 (goto-char (point-max))
517 (insert mail-header-separator)
523 (defalias 'sendnews 'gnus-post-news)
526 (defalias 'postnews 'gnus-post-news)
528 (defun gnus-copy-article-buffer (&optional article-buffer)
529 ;; make a copy of the article buffer with all text properties removed
530 ;; this copy is in the buffer gnus-article-copy.
531 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
532 ;; this buffer should be passed to all mail/news reply/post routines.
533 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
534 (buffer-disable-undo gnus-article-copy)
535 (or (memq gnus-article-copy gnus-buffer-list)
536 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
537 (let ((article-buffer (or article-buffer gnus-article-buffer)))
538 (if (and (get-buffer article-buffer)
539 (buffer-name (get-buffer article-buffer)))
541 (set-buffer article-buffer)
543 (copy-to-buffer gnus-article-copy (point-min) (point-max))
544 (gnus-set-text-properties (point-min) (point-max)
545 nil gnus-article-copy)))))
547 (defun gnus-post-news (post &optional group header article-buffer yank subject)
548 "Begin editing a new USENET news article to be posted.
549 Type \\[describe-mode] in the buffer to get a list of commands."
550 (interactive (list t))
551 (let* ((group (or group gnus-newsgroup-name))
553 to-address to-group mailing-list to-list)
555 (setq to-address (gnus-group-get-parameter group 'to-address)
556 to-group (gnus-group-get-parameter group 'to-group)
557 to-list (gnus-group-get-parameter group 'to-list)
558 mailing-list (when gnus-mailing-list-groups
559 (string-match gnus-mailing-list-groups group))
560 group (gnus-group-real-name group)))
561 (if (or (and to-group
562 (gnus-news-group-p to-group))
563 (and (gnus-news-group-p
564 (or pgroup gnus-newsgroup-name)
565 (if header (mail-header-number header) gnus-current-article))
571 (gnus-new-news (or to-group group))
572 (gnus-news-followup yank (or to-group group)))
576 (gnus-new-mail (or to-address to-list))
577 ;; Arrange for mail groups that have no `to-address' to
578 ;; get that when the user sends off the mail.
580 (make-local-variable 'gnus-add-to-address)
581 (setq gnus-add-to-address group)))
582 (gnus-mail-reply yank to-address 'followup)))))
584 (defun gnus-post-method (group query-method &optional silent)
585 "Return the posting method based on GROUP and query-method.
586 If SILENT, don't prompt the user."
587 (let ((group-method (if (stringp group)
588 (gnus-find-method-for-group group)
591 ;; If the group-method is nil (which shouldn't happen) we use
592 ;; the default method.
594 (or gnus-post-method gnus-select-method))
595 ;; We want this group's method.
596 ((and query-method (not (eq query-method 0)))
598 ;; We query the user for a post method.
600 (and gnus-post-method
601 (listp (car gnus-post-method))))
603 ;; Collect all methods we know about.
605 (when gnus-post-method
606 (if (listp (car gnus-post-method))
608 (listp gnus-post-method)))
609 gnus-secondary-select-methods
610 (list gnus-select-method)
611 (list group-method)))
612 method-alist post-methods method)
613 ;; Weed out all mail methods.
615 (setq method (gnus-server-get-method "" (pop methods)))
616 (when (or (gnus-method-option-p method 'post)
617 (gnus-method-option-p method 'post-mail))
618 (push method post-methods)))
619 ;; Create a name-method alist.
623 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
628 (setq gnus-last-posting-server
630 gnus-last-posting-server)
631 ;; Just use the last value.
632 gnus-last-posting-server
634 "Posting method: " method-alist nil t
635 (cons (or gnus-last-posting-server "") 0))))
637 ;; Override normal method.
638 ((and gnus-post-method
639 (or (gnus-method-option-p group-method 'post)
640 (gnus-method-option-p group-method 'post-mail)))
642 ;; Perhaps this is a mail group?
643 ((and (not (gnus-member-of-valid 'post group))
644 (not (gnus-method-option-p group-method 'post-mail)))
646 ;; Use the normal select method.
647 (t gnus-select-method))))
649 (defun gnus-news-group-p (group &optional article)
650 "Return non-nil if GROUP (and ARTICLE) come from a news server."
651 (or (gnus-member-of-valid 'post group) ; Ordinary news group.
652 (and (gnus-member-of-valid 'post-mail group) ; Combined group.
653 (eq (gnus-request-type group article) 'news))))
655 (defun gnus-inews-news (&optional use-group-method)
656 "Send a news message.
658 If given a non-zero prefix and the group is a foreign group, this
659 function will attempt to use the foreign server to post the article.
661 If given an zero prefix, the user will be prompted for a posting
664 (unless (gnus-alive-p)
665 (error "Gnus is dead; you can't post anything."))
666 (or gnus-current-select-method
667 (setq gnus-current-select-method gnus-select-method))
668 (let* ((case-fold-search nil)
669 (reply gnus-article-reply)
672 (gnus-start-news-server) ;Use default server.
674 (goto-char (point-min))
675 (run-hooks 'news-inews-hook)
678 (gnus-message 5 "Posting to USENET...")
679 (setq post-result (funcall gnus-inews-article-function use-group-method))
681 ((eq post-result 'illegal)
685 (gnus-message 5 "Posting to USENET...done")
686 (set-buffer-modified-p nil)
687 ;; We mark the article as replied.
688 (when (gnus-buffer-exists-p (car-safe reply))
690 (set-buffer gnus-summary-buffer)
691 (gnus-summary-mark-article-as-replied (cdr reply)))))
693 ;; We cannot signal an error.
697 1 "Article rejected: %s"
699 (gnus-post-method gnus-newsgroup-name use-group-method t))))))
701 (let ((conf gnus-prev-winconf))
704 ;; Restore last window configuration.
705 (and conf (set-window-configuration conf))))))
707 (defun gnus-inews-narrow-to-headers ()
710 (goto-char (point-min))
711 (or (and (re-search-forward
712 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
715 (goto-char (point-min)))
717 (defun gnus-inews-send-mail-copy ()
718 ;; Mail the message if To, Bcc or Cc exists.
719 (let* ((types '("to" "bcc" "cc"))
721 (buffer (current-buffer)))
724 (gnus-inews-narrow-to-headers)
727 (or (mail-fetch-field (car ty) nil t)
728 (setq types (delete (car ty) types)))
732 ;; We do not want to send mail.
734 (gnus-message 5 "Sending via mail...")
737 ;; We copy the article over to a temp buffer since we are
738 ;; going to modify it a little.
739 (nnheader-set-temp-buffer " *Gnus-mailing*")
740 (insert-buffer-substring buffer)
741 ;; We remove Fcc, because we don't want the mailer to see
743 (gnus-inews-narrow-to-headers)
744 (nnheader-remove-header "fcc")
746 ;; Insert the X-Courtesy-Message header.
747 (and (or (member "to" types)
750 (goto-char (point-max))
751 (insert "Posted-To: "
752 (mail-fetch-field "newsgroups") "\n")))
756 (if (and gnus-mail-courtesy-message
757 (or (member "to" types)
758 (member "cc" types)))
759 ;; We only want to insert the courtesy mail message if
760 ;; we use To or Cc; Bcc should not have one. Well, if
761 ;; both Bcc and To are present, it will get one
764 ;; Insert "courtesy" mail message.
765 (goto-char (point-min))
767 (concat "^" (regexp-quote mail-header-separator) "$"))
769 (insert gnus-mail-courtesy-message)))
772 (kill-buffer (current-buffer))
773 (gnus-message 5 "Sending via mail...done"))))))
775 (defun gnus-inews-remove-headers-after-mail ()
778 (let ((case-fold-search t))
779 (gnus-inews-narrow-to-headers)
780 ;; Remove Bcc completely.
781 (nnheader-remove-header "bcc")
782 ;; We transform To and Cc headers to avoid re-mailing if the user
783 ;; accidentally (or purposefully) leans on the `C-c C-c' keys
784 ;; and the news server rejects the posting.
785 (while (re-search-forward "^\\(to\\|[bcf]cc\\|cc\\):" nil t)
790 (defun gnus-inews-dex-headers ()
791 "Remove \"X-\" prefixes from To and Cc headers."
794 (let ((case-fold-search t))
795 (nnheader-narrow-to-headers)
796 (while (re-search-forward "^X-\\(to\\|[bcf]cc\\|cc\\):" nil t)
801 (defun gnus-inews-remove-empty-headers ()
802 "Remove empty headers from news and mail.
803 The buffer should be narrowed to the headers before this function is
806 (goto-char (point-min))
807 (while (re-search-forward "^[^ \t:]+:\\([ \t]*\n\\)+[^ \t]" nil t)
808 (delete-region (match-beginning 0) (1- (match-end 0)))
809 (beginning-of-line))))
811 (defun gnus-inews-check-post ()
812 "Check whether the post looks ok."
814 (not gnus-check-before-posting)
816 ;; We narrow to the headers and check them first.
819 (gnus-inews-narrow-to-headers)
821 ;; Check for commands in Subject.
823 (gnus-check-before-posting 'subject-cmsg)
825 (if (string-match "^cmsg " (mail-fetch-field "subject"))
827 "The control code \"cmsg \" is in the subject. Really post? ")
829 ;; Check for multiple identical headers.
830 (or (gnus-check-before-posting 'multiple-headers)
833 (while (and (not found)
834 (re-search-forward "^[^ \t:]+: " nil t))
836 (or (re-search-forward
837 (concat "^" (setq found
840 (- (match-end 0) 2))))
845 (format "Multiple %s headers. Really post? " found))
847 ;; Check for Version and Sendsys.
848 (or (gnus-check-before-posting 'sendsys)
850 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
852 (format "The article contains a %s command. Really post? "
853 (buffer-substring (match-beginning 0)
854 (1- (match-end 0)))))
856 ;; Check for Approved.
857 (or (gnus-check-before-posting 'approved)
859 (if (re-search-forward "^Approved:" nil t)
861 "The article contains an Approved header. Really post? ")
863 ;; Check whether a Followup-To has redirected the newsgroup.
865 (gnus-check-before-posting 'redirected-followup)
866 (not gnus-newsgroup-followup)
868 (let ((followups (gnus-tokenize-header
869 (mail-fetch-field "Newsgroups")))
870 (newsgroups (gnus-tokenize-header
871 (car gnus-newsgroup-followup))))
872 (while (and followups
873 (member (car followups) newsgroups))
874 (setq followups (cdr followups)))
878 "Followup redirected from original newsgroups. Really post? "
880 ;; Check the Message-ID header.
881 (or (gnus-check-before-posting 'message-id)
883 (let* ((case-fold-search t)
884 (message-id (mail-fetch-field "message-id")))
886 (and (string-match "@" message-id)
887 (string-match "@[^\\.]*\\." message-id))
890 "The Message-ID looks strange: \"%s\". Really post? "
892 ;; Check whether any headers are empty.
893 (or (gnus-check-before-posting 'empty-headers)
896 (goto-char (point-min))
897 (while (and post (not (eobp)))
898 (when (looking-at "\\([^ :]+\\):[ \t]\n[^ \t]")
902 "The %s header is empty. Really post? "
906 ;; Check the From header.
908 (gnus-check-before-posting 'from)
910 (let* ((case-fold-search t)
911 (from (mail-fetch-field "from")))
914 (gnus-y-or-n-p "There is no From line. Really post? "))
915 ((not (string-match "@[^\\.]*\\." from))
918 "The address looks strange: \"%s\". Really post? " from)))
919 ((string-match "(.*).*(.*)" from)
922 "The From header looks strange: \"%s\". Really post? "
924 ((string-match "<[^>]+> *$" from)
925 (let ((name (substring from 0 (match-beginning 0))))
927 (string-match "^ *\"[^\"]*\" *$" name)
928 (not (string-match "[][.!()<>@,;:\\]" name))
931 "The From header name has bogus characters. Really post? "
935 ;; Check for long lines.
936 (or (gnus-check-before-posting 'long-lines)
938 (goto-char (point-min))
940 (concat "^" (regexp-quote mail-header-separator) "$"))
944 (< (current-column) 80))
945 (zerop (forward-line 1))))
949 "You have lines longer than 79 characters. Really post? "))))
950 ;; Check whether the article is empty.
951 (or (gnus-check-before-posting 'empty)
953 (goto-char (point-min))
955 (concat "^" (regexp-quote mail-header-separator) "$"))
957 (or (re-search-forward "[^ \n\t]" nil t)
958 (gnus-y-or-n-p "Empty article. Really post?"))))
959 ;; Check for control characters.
960 (or (gnus-check-before-posting 'control-chars)
962 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
964 "The article contains control characters. Really post? ")
966 ;; Check excessive size.
967 (or (gnus-check-before-posting 'size)
968 (if (> (buffer-size) 60000)
970 (format "The article is %d octets long. Really post? "
973 ;; Use the (size . checksum) variable to see whether the
974 ;; article is empty or has only quoted text.
976 (gnus-check-before-posting 'new-text)
977 (not gnus-article-check-size)
978 (if (and (= (buffer-size) (car gnus-article-check-size))
979 (= (gnus-article-checksum) (cdr gnus-article-check-size)))
981 "It looks like there's no new text in your article. Really post? ")
983 ;; Check the length of the signature.
984 (or (gnus-check-before-posting 'signature)
986 (goto-char (point-max))
987 (if (not (re-search-backward gnus-signature-separator nil t))
989 (if (> (count-lines (point) (point-max)) 5)
992 "Your .sig is %d lines; it should be max 4. Really post? "
993 (count-lines (point) (point-max))))
996 (defvar gnus-inews-sent-ids nil)
998 (defun gnus-inews-reject-message ()
999 "Check whether this message has already been sent."
1000 (when gnus-sent-message-ids-file
1001 (let ((message-id (save-restriction (gnus-inews-narrow-to-headers)
1002 (mail-fetch-field "message-id")))
1005 (unless gnus-inews-sent-ids
1009 (if (member message-id gnus-inews-sent-ids)
1010 ;; Reject this message.
1011 (not (gnus-yes-or-no-p
1012 (format "Message %s already sent. Send anyway? "
1014 (push message-id gnus-inews-sent-ids)
1015 ;; Chop off the last Message-IDs.
1016 (when (setq end (nthcdr gnus-sent-message-ids-length
1017 gnus-inews-sent-ids))
1019 (nnheader-temp-write gnus-sent-message-ids-file
1020 (prin1 `(setq gnus-inews-sent-ids ',gnus-inews-sent-ids)
1024 (defun gnus-tokenize-header (header &optional separator)
1025 "Split HEADER into a list of header elements.
1026 \",\" is used as the separator."
1028 (separator (or separator ","))
1030 (format "[ \t]*\\([^%s]+\\)?\\([%s]+\\|\\'\\)" separator separator))
1032 (while (and (string-match regexp header beg)
1033 (< beg (length header)))
1034 (when (match-beginning 1)
1035 (push (match-string 1 header) elems))
1036 (setq beg (match-end 0)))
1039 (defun gnus-article-checksum ()
1043 (setq sum (logxor sum (following-char)))
1047 ;; Returns non-nil if this type is not to be checked.
1048 (defun gnus-check-before-posting (type)
1050 (or (not gnus-check-before-posting)
1051 (if (listp gnus-check-before-posting)
1052 (memq type gnus-check-before-posting)
1055 (defun gnus-cancel-news ()
1056 "Cancel an article you posted."
1058 (if (or gnus-expert-user
1059 (gnus-yes-or-no-p "Do you really want to cancel this article? "))
1064 (or (gnus-news-group-p gnus-newsgroup-name)
1065 (error "This backend does not support canceling"))
1067 ;; Get header info. from original article.
1069 (gnus-article-show-all-headers)
1070 (goto-char (point-min))
1071 (search-forward "\n\n" nil 'move)
1072 (narrow-to-region (point-min) (point))
1073 (setq from (mail-fetch-field "from"))
1074 (setq newsgroups (mail-fetch-field "newsgroups"))
1075 (setq message-id (mail-fetch-field "message-id"))
1076 (setq distribution (mail-fetch-field "distribution")))
1077 ;; Verify if the article is absolutely user's by comparing
1078 ;; user id with value of its From: field.
1081 (downcase (gnus-mail-strip-quoted-names from))
1082 (downcase (gnus-mail-strip-quoted-names
1083 (gnus-inews-user-name)))))
1085 (ding) (gnus-message 3 "This article is not yours.")
1087 ;; Make control article.
1088 (set-buffer (get-buffer-create " *Gnus-canceling*"))
1089 (buffer-disable-undo (current-buffer))
1091 (insert "Newsgroups: " newsgroups "\n"
1092 "From: " (gnus-inews-user-name) "\n"
1093 "Subject: cancel " message-id "\n"
1094 "Control: cancel " message-id "\n"
1096 (concat "Distribution: " distribution "\n")
1098 mail-header-separator "\n"
1099 "This is a cancel message from " from ".\n")
1100 ;; Send the control article to NNTP server.
1101 (gnus-message 5 "Canceling your article...")
1103 (if (funcall gnus-inews-article-function)
1104 (gnus-message 5 "Canceling your article...done")
1107 (gnus-message 1 "Cancel failed; %s"
1108 (gnus-status-message gnus-newsgroup-name))
1111 ;; Kill the article buffer.
1112 (kill-buffer (current-buffer))))))))
1114 (defun gnus-inews-remove-signature ()
1115 "Remove the signature from the text between point and mark.
1116 The text will also be indented the normal way.
1117 This function can be used in `mail-citation-hook', for instance."
1119 (let ((start (point))
1121 (if (not (re-search-forward gnus-signature-separator (mark t) t))
1122 ;; No signature here, so we just indent the cited text.
1123 (mail-indent-citation)
1124 ;; Find the last non-empty line.
1126 (while (looking-at "[ \t]*$")
1129 (setq mark (set-marker (make-marker) (point)))
1131 (mail-indent-citation)
1132 ;; Enable undoing the deletion.
1134 (delete-region mark (mark t))
1135 (set-marker mark nil)))))
1139 ;; Dummy to avoid byte-compile warning.
1140 (defvar nnspool-rejected-article-hook)
1142 (defun gnus-inews-article (&optional use-group-method)
1143 "Post an article in current buffer using NNTP protocol."
1144 (let ((artbuf (current-buffer))
1147 (goto-char (point-max))
1148 ;; Require a newline at the end of the buffer since inews may
1149 ;; append a .signature.
1150 (or (= (preceding-char) ?\n)
1152 ;; Prepare article headers. All message body such as signature
1153 ;; must be inserted before Lines: field is prepared.
1155 (gnus-inews-narrow-to-headers)
1156 ;; Fix some headers.
1157 (gnus-inews-cleanup-headers)
1158 ;; Remove some headers.
1159 (gnus-inews-remove-headers)
1160 ;; Insert some headers.
1161 (gnus-inews-insert-headers)
1162 ;; Let the user do all of the above.
1163 (run-hooks 'gnus-inews-article-header-hook)
1164 ;; Copy the Gcc header, if any.
1165 (setq gcc (mail-fetch-field "gcc"))
1167 ;; Check whether the article is a good Net Citizen.
1168 (if (not (gnus-inews-check-post))
1171 ;; We fudge a hook for nnspool.
1172 (setq nnspool-rejected-article-hook
1176 (set-buffer ,(buffer-name))
1177 (gnus-associate-buffer-with-draft nil 'silent))
1181 1 "Couldn't enter rejected article into draft group"))))))
1183 ;; Looks ok, so we do the nasty.
1185 ;; This hook may insert a signature.
1187 (goto-char (point-min))
1188 (let ((gnus-newsgroup-name (or (mail-fetch-field "newsgroups")
1189 gnus-newsgroup-name)))
1190 (run-hooks 'gnus-prepare-article-hook)))
1191 ;; Send off copies using mail, if that is wanted.
1192 (gnus-inews-send-mail-copy)
1193 ;; Remove more headers.
1194 (gnus-inews-remove-headers-after-mail)
1195 ;; Copy the article over to a temp buffer.
1196 (nnheader-set-temp-buffer " *Gnus-posting*")
1197 (insert-buffer-substring artbuf)
1198 ;; Remove the header separator.
1199 (goto-char (point-min))
1201 (concat "^" (regexp-quote mail-header-separator) "$"))
1202 (replace-match "" t t)
1203 ;; Remove X- prefixes to headers.
1204 (gnus-inews-dex-headers)
1205 ;; Run final inews hooks. This hook may do FCC.
1206 ;; The article must be saved before being posted because
1207 ;; `gnus-request-post' modifies the buffer.
1208 (run-hooks 'gnus-inews-article-hook)
1209 ;; Copy the article over to some group, possibly.
1210 (and gcc (gnus-inews-do-gcc gcc))
1211 ;; Post the article.
1212 (setq result (gnus-request-post
1213 (gnus-post-method gnus-newsgroup-name use-group-method)))
1214 (kill-buffer (current-buffer)))
1215 (run-hooks 'gnus-message-sent-hook)
1216 ;; If the posting was unsuccessful (that it, it was rejected) we
1217 ;; put it into the draft group.
1218 (or result (gnus-associate-buffer-with-draft))
1221 (defun gnus-inews-cleanup-headers ()
1222 ;; Remove empty lines in the header.
1224 (gnus-inews-narrow-to-headers)
1225 (while (re-search-forward "^[ \t]*\n" nil t)
1226 (replace-match "" t t)))
1228 ;; Correct newsgroups field: change sequence of spaces to comma and
1229 ;; eliminate spaces around commas. Eliminate imbedded line breaks.
1230 (goto-char (point-min))
1231 (when (re-search-forward "^Newsgroups: +" nil t)
1235 (if (re-search-forward "^[^ \t]" nil t)
1239 (goto-char (point-min))
1240 (while (re-search-forward "\n[ \t]+" nil t)
1241 (replace-match " " t t)) ;No line breaks (too confusing)
1242 (goto-char (point-min))
1243 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
1244 (replace-match "," t t))
1245 (goto-char (point-min))
1246 ;; Remove trailing commas.
1247 (when (re-search-forward ",+$" nil t)
1248 (replace-match "" t t))))
1250 ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
1251 ;; Help save the the world!
1252 (unless gnus-expert-user
1253 (let ((newsgroups (mail-fetch-field "newsgroups"))
1254 (followup-to (mail-fetch-field "followup-to"))
1256 (when (and newsgroups (string-match "," newsgroups)
1261 (setq to (completing-read
1262 "Followups to: (default all groups) "
1263 (mapcar (lambda (g) (list g))
1265 (gnus-tokenize-header
1267 (goto-char (point-min))
1268 (insert "Followup-To: " to "\n"))))
1270 ;; Cleanup Followup-To.
1271 (goto-char (point-min))
1272 (when (search-forward-regexp "^Followup-To: +" nil t)
1276 (if (re-search-forward "^[^ \t]" nil 'end)
1279 (goto-char (point-min))
1280 ;; No line breaks (too confusing)
1281 (while (re-search-forward "\n[ \t]+" nil t )
1282 (replace-match " " t ))
1283 (goto-char (point-min))
1284 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
1285 (replace-match "," t t)))))
1287 (defun gnus-inews-remove-headers ()
1288 (let ((case-fold-search t)
1289 (headers gnus-removable-headers))
1290 ;; Remove toxic headers.
1292 (goto-char (point-min))
1293 (and (re-search-forward
1294 (concat "^" (downcase (format "%s" (car headers))))
1296 (delete-region (progn (beginning-of-line) (point))
1297 (progn (forward-line 1) (point))))
1298 (setq headers (cdr headers)))))
1300 ;;; Since the X-Newsreader/X-Mailer are ``vanity'' headers, they might
1301 ;;; as well include the Emacs version as well.
1302 ;;; The following function works with later GNU Emacs, and XEmacs.
1303 (defun gnus-extended-version ()
1304 "Stringified Gnus version and Emacs version"
1310 ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
1311 (concat "Emacs " (substring emacs-version
1314 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)" emacs-version)
1315 (concat (substring emacs-version
1318 (format " %d.%d" emacs-major-version emacs-minor-version)))
1319 (t emacs-version))))
1321 (defun gnus-inews-insert-headers (&optional headers)
1322 "Prepare article headers.
1323 Headers already prepared in the buffer are not modified.
1324 Headers in `gnus-required-headers' will be generated."
1325 (let* ((Date (gnus-inews-date))
1326 (Message-ID (gnus-inews-message-id))
1327 (Organization (gnus-inews-organization))
1328 (From (gnus-inews-user-name))
1329 (Path (gnus-inews-path))
1332 (In-Reply-To (gnus-inews-in-reply-to))
1334 (Distribution (gnus-inews-distribution))
1335 (Lines (gnus-inews-lines))
1336 (X-Newsreader (gnus-extended-version))
1337 (X-Mailer X-Newsreader)
1338 (Expires (gnus-inews-expires))
1339 (headers (or headers gnus-required-headers))
1340 (case-fold-search t)
1342 ;; First we remove any old generated headers.
1343 (let ((headers gnus-deletable-headers))
1345 (goto-char (point-min))
1346 (and (re-search-forward
1347 (concat "^" (symbol-name (car headers)) ": *") nil t)
1348 (get-text-property (1+ (match-beginning 0)) 'gnus-deletable)
1350 (setq headers (cdr headers))))
1351 ;; If there are References, and no "Re: ", then the thread has
1352 ;; changed name. See Son-of-1036.
1353 (if (and (mail-fetch-field "references")
1354 (get-buffer gnus-article-buffer))
1355 (let ((psubject (gnus-simplify-subject-re
1356 (mail-fetch-field "subject"))))
1357 (or (and psubject gnus-reply-subject
1358 (string= (gnus-simplify-subject-re gnus-reply-subject)
1361 (string-match "@" Message-ID)
1363 (concat (substring Message-ID 0 (match-beginning 0))
1365 (substring Message-ID (match-beginning 0))))))))
1366 ;; Go through all the required headers and see if they are in the
1367 ;; articles already. If they are not, or are empty, they are
1368 ;; inserted automatically - except for Subject, Newsgroups and
1371 (goto-char (point-min))
1372 (setq elem (pop headers))
1374 (setq header (car elem))
1376 (when (or (not (re-search-forward
1377 (concat "^" (downcase (symbol-name header)) ":") nil t))
1379 ;; The header was found. We insert a space after the
1380 ;; colon, if there is none.
1381 (if (/= (following-char) ? ) (insert " "))
1382 ;; Find out whether the header is empty...
1383 (looking-at "[ \t]*$")))
1384 ;; So we find out what value we should insert.
1387 ((and (consp elem) (eq (car elem) 'optional))
1388 ;; This is an optional header. If the cdr of this
1389 ;; is something that is nil, then we do not insert
1391 (setq header (cdr elem))
1392 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
1393 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
1395 ;; The element is a cons. Either the cdr is a
1396 ;; string to be inserted verbatim, or it is a
1397 ;; function, and we insert the value returned from
1399 (or (and (stringp (cdr elem)) (cdr elem))
1400 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
1401 ((and (boundp header) (symbol-value header))
1402 ;; The element is a symbol. We insert the value
1403 ;; of this symbol, if any.
1404 (symbol-value header))
1406 ;; We couldn't generate a value for this header,
1407 ;; so we just ask the user.
1408 (read-from-minibuffer
1409 (format "Empty header for %s; enter value: " header)))))
1410 ;; Finally insert the header.
1412 (not (equal value "")))
1416 ;; This header didn't exist, so we insert it.
1417 (goto-char (point-max))
1418 (insert (symbol-name header) ": " value "\n")
1420 ;; The value of this header was empty, so we clear
1421 ;; totally and insert the new value.
1422 (delete-region (point) (gnus-point-at-eol))
1424 ;; Add the deletable property to the headers that require it.
1425 (and (memq header gnus-deletable-headers)
1426 (progn (beginning-of-line) (looking-at "[^:]+: "))
1427 (add-text-properties
1428 (point) (match-end 0)
1429 '(gnus-deletable t face italic) (current-buffer)))))))
1430 ;; Insert new Sender if the From is strange.
1431 (let ((from (mail-fetch-field "from"))
1432 (sender (mail-fetch-field "sender"))
1433 (secure-sender (gnus-inews-real-user-address)))
1435 (not (gnus-check-before-posting 'sender))
1437 (downcase (cadr (gnus-extract-address-components from)))
1438 (downcase (gnus-inews-real-user-address))))
1443 (cadr (gnus-extract-address-components sender)))
1444 (downcase secure-sender)))))
1445 (goto-char (point-min))
1446 ;; Rename any old Sender headers to Original-Sender.
1447 (when (re-search-forward "^Sender:" nil t)
1449 (insert "Original-")
1450 (beginning-of-line))
1451 (insert "Sender: " secure-sender "\n")))))
1453 (defun gnus-inews-insert-signature ()
1454 "Insert a signature file.
1455 If `gnus-signature-function' is bound and returns a string, this
1456 string is used instead of the variable `gnus-signature-file'.
1457 In either case, if the string is a file name, this file is
1458 inserted. If the string is not a file name, the string itself is
1461 If you never want any signature inserted, set both of these variables to
1465 (or (and gnus-signature-function
1466 (funcall gnus-signature-function gnus-newsgroup-name))
1467 gnus-signature-file)))
1469 (or (file-exists-p signature)
1470 (string-match " " signature)
1472 "^/[^/]+/" (expand-file-name signature)))))
1474 (goto-char (point-max))
1475 (if (and mail-signature (search-backward "\n-- \n" nil t))
1477 ;; Delete any previous signatures.
1478 (if (search-backward "\n-- \n" nil t)
1479 (delete-region (point) (point-max)))
1480 (or (eolp) (insert "\n"))
1482 (if (file-exists-p signature)
1483 (insert-file-contents signature)
1485 (goto-char (point-max))
1486 (or (bolp) (insert "\n"))))))))
1488 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1489 (defun gnus-inews-insert-mime-headers ()
1490 (goto-char (point-min))
1491 (let ((mail-header-separator
1493 (goto-char (point-min))
1494 (if (and (search-forward (concat "\n" mail-header-separator "\n")
1496 (not (search-backward "\n\n" nil t)))
1497 mail-header-separator
1499 (or (mail-position-on-field "Mime-Version")
1501 (cond ((save-restriction
1503 (goto-char (point-min))
1504 (re-search-forward "[\200-\377]" nil t))
1505 (or (mail-position-on-field "Content-Type")
1506 (insert "text/plain; charset=ISO-8859-1"))
1507 (or (mail-position-on-field "Content-Transfer-Encoding")
1509 (t (or (mail-position-on-field "Content-Type")
1510 (insert "text/plain; charset=US-ASCII"))
1511 (or (mail-position-on-field "Content-Transfer-Encoding")
1512 (insert "7bit")))))))
1514 (defun gnus-inews-do-fcc ()
1515 "Process Fcc headers in the current buffer.
1516 Unless the first character of the field is `|', the article is saved
1517 to the specified file using the function specified by the variable
1518 gnus-author-copy-saver. The default function rmail-output saves in
1519 Unix mailbox format.
1521 If the first character is `|', the contents of the article is sent to
1522 a program specified by the rest of the value."
1523 (let ((case-fold-search t) ;Should ignore case.
1527 (nnheader-narrow-to-headers)
1528 (while (setq file (mail-fetch-field "fcc"))
1530 (nnheader-remove-header "fcc" nil t))
1531 ;; Process FCC operations.
1534 (setq file (pop list))
1535 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
1536 ;; Pipe the article to the program in question.
1537 (call-process-region (point-min) (point-max) shell-file-name
1538 nil nil nil "-c" (match-string 1 file))
1539 ;; Save the article.
1540 (setq file (expand-file-name file))
1541 (gnus-make-directory (file-name-directory file))
1542 (if (and gnus-author-copy-saver
1543 (not (eq gnus-author-copy-saver 'rmail-output)))
1544 (funcall gnus-author-copy-saver file)
1545 (if (and (file-readable-p file) (mail-file-babyl-p file))
1546 (gnus-output-to-rmail file)
1547 (let ((mail-use-rfc822 t))
1548 (rmail-output file 1 t t))))))))))
1550 (defun gnus-inews-path ()
1552 (let ((login-name (gnus-inews-login-name)))
1553 (cond ((null gnus-use-generic-path)
1554 (concat (nth 1 gnus-select-method) "!" login-name))
1555 ((stringp gnus-use-generic-path)
1556 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1557 (concat gnus-use-generic-path "!" login-name))
1560 (defun gnus-inews-user-name ()
1561 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1562 (let ((full-name (gnus-inews-full-name))
1563 (address (if (or gnus-user-login-name gnus-use-generic-from
1564 gnus-local-domain (getenv "DOMAINNAME"))
1565 (concat (gnus-inews-login-name) "@"
1566 (gnus-inews-domain-name gnus-use-generic-from))
1567 user-mail-address)))
1568 (or gnus-user-from-line
1570 ;; User's full name.
1571 (cond ((string-equal full-name "&") ;Unix hack.
1572 (concat " (" (user-login-name) ")"))
1573 ((string-match "[^ ]+@[^ ]+ +(.*)" address)
1576 (concat " (" full-name ")")))))))
1578 (defun gnus-inews-real-user-address ()
1579 "Return the \"real\" user address.
1580 This function tries to ignore all user modifications, and
1581 give as trustworthy answer as possible."
1582 (concat (user-login-name) "@" (system-name)))
1584 (defun gnus-inews-login-name ()
1585 "Return login name."
1586 (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1588 (defun gnus-inews-full-name ()
1589 "Return full user name."
1590 (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1592 (defun gnus-inews-domain-name (&optional genericfrom)
1593 "Return user's domain name.
1594 If optional argument GENERICFROM is a string, use it as the domain
1595 name; if it is non-nil, strip off local host name from the domain name.
1596 If the function `system-name' returns full internet name and the
1597 domain is undefined, the domain name is got from it."
1598 (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1599 (let* ((system-name (system-name))
1601 (or (if (stringp genericfrom) genericfrom)
1602 (getenv "DOMAINNAME")
1603 (and (boundp 'mail-host-address)
1606 ;; Function `system-name' may return full internet name.
1607 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1608 (if (string-match "\\.." system-name)
1609 ;; Some machines return "name.", and that's not
1611 (substring system-name (1- (match-end 0))))
1612 (read-string "Domain name (no host): ")))
1613 (host (or (if (string-match "\\." system-name)
1614 (substring system-name 0 (match-beginning 0)))
1616 (if (string-equal "." (substring domain 0 1))
1617 (setq domain (substring domain 1)))
1618 ;; Support GENERICFROM as same as standard Bnews system.
1619 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1620 (cond ((null genericfrom)
1621 (concat host "." domain))
1622 ;;((stringp genericfrom) genericfrom)
1624 (if (string-match "\\." (system-name))
1626 (if (string-match "@\\([^ ]+\\)\\($\\| \\)" user-mail-address)
1627 (substring user-mail-address
1628 (match-beginning 1) (match-end 1))
1631 (defun gnus-inews-full-address ()
1632 (let ((domain (gnus-inews-domain-name))
1633 (system (system-name))
1634 (case-fold-search t))
1635 (if (string-match "\\." system) system
1636 (if (string-match (concat "^" (regexp-quote system)) domain) domain
1637 (concat system "." domain)))))
1639 (defun gnus-inews-expires ()
1640 "Return an Expires header based on `gnus-article-expires'."
1641 (let ((current (current-time))
1642 (future (* 1.0 gnus-article-expires 60 60 24)))
1643 ;; Add the future to current.
1644 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
1645 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
1646 ;; Return the date in the future in UT.
1647 (timezone-make-date-arpa-standard
1648 (current-time-string current) (current-time-zone) '(0 "UT"))))
1650 (defun gnus-inews-distribution ()
1651 "Return the current Distribution header, if any."
1652 (when (and gnus-distribution-function
1653 (fboundp gnus-distribution-function))
1654 (funcall gnus-distribution-function (or gnus-newsgroup-name ""))))
1656 (defun gnus-inews-message-id ()
1657 "Generate unique Message-ID for user."
1658 ;; Message-ID should not contain a slash and should be terminated by
1659 ;; a number. I don't know the reason why it is so.
1660 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1662 (defvar gnus-unique-id-char nil)
1664 ;; If you ever change this function, make sure the new version
1665 ;; cannot generate IDs that the old version could.
1666 ;; You might for example insert a "." somewhere (not next to another dot
1667 ;; or string boundary), or modify the newsreader name to "Ding".
1668 (defun gnus-inews-unique-id ()
1669 ;; Don't use microseconds from (current-time), they may be unsupported.
1670 ;; Instead we use this randomly inited counter.
1671 (setq gnus-unique-id-char
1672 (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1673 ;; (current-time) returns 16-bit ints,
1674 ;; and 2^16*25 just fits into 4 digits i base 36.
1676 (let ((tm (if (fboundp 'current-time)
1677 (current-time) '(12191 46742 287898))))
1679 (if (memq system-type '(ms-dos emx vax-vms))
1680 (let ((user (downcase (gnus-inews-login-name))))
1681 (while (string-match "[^a-z0-9_]" user)
1682 (aset user (match-beginning 0) ?_))
1684 (gnus-number-base36 (user-uid) -1))
1685 (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1686 (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1687 ;; Append the newsreader name, because while the generated
1688 ;; ID is unique to this newsreader, other newsreaders might
1689 ;; otherwise generate the same ID via another algorithm.
1692 (defun gnus-inews-date ()
1693 "Current time string."
1694 (let ((now (current-time)))
1695 (timezone-make-date-arpa-standard
1696 (current-time-string now) (current-time-zone now))))
1698 (defun gnus-inews-organization ()
1699 "Return user's organization.
1700 The ORGANIZATION environment variable is used if defined.
1701 If not, the variable `gnus-local-organization' is used instead.
1702 If it is a function, the function will be called with the current
1703 newsgroup name as the argument.
1704 If this is a file name, the contents of this file will be used as the
1706 (let* ((organization
1707 (or (getenv "ORGANIZATION")
1708 (if gnus-local-organization
1709 (if (gnus-functionp gnus-local-organization)
1710 (funcall gnus-local-organization gnus-newsgroup-name)
1711 gnus-local-organization))
1712 gnus-organization-file
1713 "~/.organization")))
1714 (and (stringp organization)
1715 (> (length organization) 0)
1716 (or (file-exists-p organization)
1717 (string-match " " organization)
1718 (not (string-match "^/usr/lib/\\|^~/" organization)))
1720 (gnus-set-work-buffer)
1721 (if (file-exists-p organization)
1722 (insert-file-contents organization)
1723 (insert organization))
1724 (goto-char (point-min))
1725 (while (re-search-forward " *\n *" nil t)
1726 (replace-match " " t t))
1727 (buffer-substring (point-min) (point-max))))))
1729 (defun gnus-inews-lines ()
1730 "Count the number of lines and return numeric string."
1734 (goto-char (point-min))
1736 (concat "^" (regexp-quote mail-header-separator) "$"))
1738 (int-to-string (count-lines (point) (point-max))))))
1740 (defun gnus-inews-in-reply-to ()
1741 "Return the In-Reply-To header for this message."
1746 ;;; Gnus Mail Functions
1749 ;;; Mail reply commands of Gnus summary mode
1751 (defun gnus-summary-reply (yank &optional yank-articles)
1752 "Reply mail to news author.
1753 If prefix argument YANK is non-nil, original article is yanked automatically.
1754 Customize the variable gnus-mail-reply-method to use another mailer."
1756 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1757 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1758 (gnus-set-global-variables)
1759 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1760 (gnus-summary-select-article)
1761 (bury-buffer gnus-article-buffer)
1762 (gnus-mail-reply (or yank-articles (not (not yank)))))
1764 (defun gnus-summary-reply-with-original (n)
1765 "Reply mail to news author with original article.
1766 Customize the variable gnus-mail-reply-method to use another mailer."
1768 (gnus-summary-reply t (gnus-summary-work-articles n)))
1770 (defun gnus-summary-mail-forward (post)
1771 "Forward the current message to another user.
1772 Customize the variable gnus-mail-forward-method to use another mailer."
1774 (gnus-set-global-variables)
1775 (gnus-summary-select-article)
1776 (gnus-copy-article-buffer)
1778 (gnus-forward-using-post gnus-original-article-buffer)
1779 (gnus-mail-forward gnus-original-article-buffer)))
1781 (defun gnus-summary-resend-message (address)
1782 "Resend the current article to ADDRESS."
1783 (interactive "sResend message to: ")
1784 (gnus-summary-select-article)
1787 ;; We first set up a normal mail buffer.
1788 (nnheader-set-temp-buffer " *Gnus resend*")
1789 ;; This code from sendmail.el
1791 (let ((fill-prefix "\t")
1792 (address-start (point)))
1793 (insert address "\n")
1794 (fill-region-as-paragraph address-start (point-max)))
1795 (insert mail-header-separator "\n")
1796 ;; Insert our usual headers.
1797 (gnus-inews-narrow-to-headers)
1798 (gnus-inews-insert-headers '(From Date To))
1799 (goto-char (point-min))
1800 ;; Rename them all to "Resent-*".
1801 (while (re-search-forward "^[A-Za-z]" nil t)
1806 (delete-region (point) (point-max))
1808 ;; Insert the message to be resent.
1809 (insert-buffer-substring gnus-original-article-buffer)
1810 (goto-char (point-min))
1811 (search-forward "\n\n")
1814 (narrow-to-region beg (point))
1815 (nnheader-remove-header gnus-ignored-resent-headers t)
1816 (goto-char (point-max)))
1817 (insert mail-header-separator)
1818 ;; Rename all old ("Also-")Resent headers.
1819 (while (re-search-backward "^\\(Also-\\)?Resent-" beg t)
1824 (kill-buffer (current-buffer)))))
1826 (defun gnus-summary-post-forward ()
1827 "Forward the current article to a newsgroup."
1829 (gnus-summary-mail-forward t))
1831 (defvar gnus-nastygram-message
1832 "The following article was inappropriately posted to %s.\n"
1833 "Format string to insert in nastygrams.
1834 The current group name will be inserted at \"%s\".")
1836 (defun gnus-summary-mail-nastygram (n)
1837 "Send a nastygram to the author of the current article."
1839 (if (or gnus-expert-user
1841 "Really send a nastygram to the author of the current article? "))
1842 (let ((group gnus-newsgroup-name))
1843 (gnus-summary-reply-with-original n)
1844 (set-buffer gnus-mail-buffer)
1845 (insert (format gnus-nastygram-message group))
1846 (gnus-mail-send-and-exit))))
1848 (defun gnus-summary-mail-other-window ()
1849 "Compose mail in other window.
1850 Customize the variable `gnus-mail-other-window-method' to use another
1853 (gnus-set-global-variables)
1855 ;; We might want to prompt here.
1856 (when (and gnus-interactive-post
1857 (not gnus-expert-user))
1858 (read-string "To: ")))
1859 (gnus-configure-windows 'summary-mail 'force))
1861 (defun gnus-new-mail (&optional to)
1863 (when (and gnus-interactive-post
1864 (not gnus-expert-user))
1865 (setq subject (read-string "Subject: ")))
1866 (pop-to-buffer gnus-mail-buffer)
1868 (gnus-mail-setup 'new to subject)
1869 (gnus-inews-insert-gcc)
1870 (gnus-inews-insert-archive-gcc)
1871 (run-hooks 'gnus-mail-hook)))
1873 (defun gnus-new-empty-mail ()
1874 "Create a new, virtually empty mail mode buffer."
1875 (pop-to-buffer gnus-mail-buffer)
1876 (gnus-mail-setup 'new "" ""))
1878 (defun gnus-mail-reply (&optional yank to-address followup)
1880 (set-buffer gnus-summary-buffer)
1881 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1882 (cur (cons (current-buffer) (cdr gnus-article-current)))
1883 (winconf (current-window-configuration))
1884 from subject date reply-to message-of to cc
1885 references message-id sender follow-to sendto elt new-cc new-to
1886 mct mctdo gnus-warning)
1887 (set-buffer (get-buffer-create gnus-mail-buffer))
1889 (if (and (buffer-modified-p)
1892 "Unsent message being composed; erase it? ")))
1896 (gnus-copy-article-buffer)
1898 (set-buffer gnus-article-copy)
1899 (nnheader-narrow-to-headers)
1901 ;; This is a regular reply.
1902 (if (gnus-functionp gnus-reply-to-function)
1903 (setq follow-to (funcall gnus-reply-to-function group)))
1904 ;; This is a followup.
1905 (if (gnus-functionp gnus-followup-to-function)
1908 (funcall gnus-followup-to-function group)))))
1909 (setq from (mail-fetch-field "from"))
1910 (setq date (or (mail-fetch-field "date")
1911 (mail-header-date gnus-current-headers)))
1912 (setq message-of (gnus-message-of from date))
1913 (setq sender (mail-fetch-field "sender"))
1914 (setq subject (or (mail-fetch-field "subject") "none"))
1915 ;; Remove any (buggy) Re:'s that are present and make a
1917 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1918 (setq subject (substring subject (match-end 0))))
1919 (setq subject (concat "Re: " subject))
1920 (setq to (mail-fetch-field "to"))
1921 (setq cc (mail-fetch-field "cc"))
1922 (setq mct (mail-fetch-field "mail-copies-to"))
1924 (unless (gnus-group-get-parameter group 'broken-reply-to)
1925 (mail-fetch-field "reply-to")))
1926 (setq references (mail-fetch-field "references"))
1927 (setq message-id (mail-fetch-field "message-id"))
1928 (when (and (setq gnus-warning (mail-fetch-field "gnus-warning"))
1929 (string-match "<[^>]+>" gnus-warning))
1930 (setq message-id (match-string 0 gnus-warning)))
1932 (setq mctdo (and mct (not (equal mct "never"))))
1933 (when (and mct (string= (downcase mct) "always"))
1934 (setq mct (or reply-to from)))
1936 (if (not (and followup (not to-address)))
1937 (setq new-to (or reply-to from)
1941 (gnus-mail-strip-quoted-names mct)
1942 (gnus-mail-strip-quoted-names
1945 (not (stringp follow-to)))
1947 (or follow-to new-to
1952 (gnus-set-work-buffer)
1953 (unless (equal mct "never")
1954 (insert (or reply-to from "")))
1956 (if (bolp) "" ", ") (or to "")
1957 (if (or (not mct) (not mctdo)) ""
1958 (concat (if (bolp) "" ", ") mct))
1959 (if cc (concat (if (bolp) "" ", ") cc) ""))
1960 ;; Remove addresses that match `rmail-dont-reply-to-names'.
1961 (insert (prog1 (rmail-dont-reply-to (buffer-string))
1963 (goto-char (point-min))
1967 (cons (gnus-mail-strip-quoted-names addr) addr))
1968 (nreverse (gnus-mail-parse-comma-list))))
1971 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
1972 (setq new-to (cdr (pop ccalist)))
1975 (lambda (addr) (cdr addr))
1979 (setq news-reply-yank-from (or from "(nobody)"))
1980 (setq news-reply-yank-message-id
1981 (or message-id "(unknown Message-ID)"))
1983 ;; Gather the "to" addresses out of the follow-to list and remove
1985 (if (and follow-to (listp follow-to))
1986 (while (setq elt (assoc "To" follow-to))
1987 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1988 (setq follow-to (delq elt follow-to))))
1991 (if followup 'followup 'reply)
1993 (if (and follow-to (not (stringp follow-to))) sendto
1994 (or follow-to new-to sender "")))
1996 (if (zerop (length new-cc)) nil new-cc)
1999 (make-local-variable 'gnus-article-reply)
2000 (setq gnus-article-reply cur)
2001 (make-local-variable 'gnus-prev-winconf)
2002 (setq gnus-prev-winconf winconf)
2003 (make-local-variable 'gnus-reply-subject)
2004 (setq gnus-reply-subject subject)
2005 (make-local-variable 'gnus-in-reply-to)
2006 (setq gnus-in-reply-to message-of)
2008 (auto-save-mode auto-save-default)
2009 (gnus-inews-insert-gcc)
2010 (gnus-inews-insert-archive-gcc group)
2012 (when (and follow-to (listp follow-to))
2014 (gnus-inews-narrow-to-headers)
2015 (re-search-forward "^To:" nil t)
2019 ;; Insert the rest of the Follow-To headers.
2021 (goto-char (point-min))
2022 (if (not (re-search-forward
2023 (concat "^" (caar follow-to) ": *") nil t))
2026 (insert (caar follow-to) ": " (cdar follow-to) "\n"))
2029 (insert (cdar follow-to)))
2030 (setq follow-to (cdr follow-to)))
2032 (nnheader-insert-references references message-id)
2034 ;; Now the headers should be ok, so we do the yanking.
2035 (goto-char (point-min))
2037 (concat "^" (regexp-quote mail-header-separator) "$"))
2040 (gnus-configure-windows 'reply 'force)
2041 (let ((last (point))
2043 (if (not (listp yank))
2045 ;; Just a single article being yanked.
2047 (mail-yank-original nil))
2048 (or mail-yank-hooks mail-citation-hook
2049 (run-hooks 'news-reply-header-hook)))
2051 (save-window-excursion
2052 (set-buffer gnus-summary-buffer)
2053 (gnus-summary-select-article nil nil nil (car yank))
2054 (gnus-summary-remove-process-mark (car yank)))
2057 (gnus-copy-article-buffer)
2058 (mail-yank-original nil)
2060 (narrow-to-region (point-min) (point))
2061 (goto-char (mark t))
2062 (let ((news-reply-yank-from
2064 (set-buffer gnus-article-buffer)
2065 (or (mail-fetch-field "from") "(nobody)")))
2066 (news-reply-yank-message-id
2068 (set-buffer gnus-article-buffer)
2069 (or (mail-fetch-field "message-id")
2070 "(unknown Message-ID)"))))
2071 (or mail-yank-hooks mail-citation-hook
2072 (run-hooks 'news-reply-header-hook))
2073 (setq end (point-max)))))
2075 (setq yank (cdr yank))))
2078 (gnus-configure-windows 'reply-yank 'force))
2079 (run-hooks 'gnus-mail-hook)
2080 ;; Mark this buffer as unchanged.
2081 (set-buffer-modified-p nil)))))
2083 (defun gnus-mail-parse-comma-list ()
2086 (skip-chars-forward " ")
2089 (skip-chars-forward "^,")
2094 (narrow-to-region beg (point))
2097 (while (search-forward "\"" nil t)
2099 (if (zerop i) 2 i)) 2)))))
2100 (skip-chars-forward ",")
2101 (skip-chars-forward "^,"))
2102 (skip-chars-backward " ")
2104 (cons (buffer-substring beg (point))
2106 (skip-chars-forward "^,")
2107 (skip-chars-forward ", "))
2110 (defun gnus-new-news (&optional group inhibit-prompt)
2111 "Set up a *Post Gnus* buffer that points to GROUP.
2112 If INHIBIT-PROMPT, never prompt for a Subject."
2113 (let ((winconf (current-window-configuration))
2115 (when (and gnus-interactive-post
2116 (not inhibit-prompt)
2117 (not gnus-expert-user))
2118 (setq subject (read-string "Subject: ")))
2119 (pop-to-buffer gnus-post-news-buffer)
2122 ;; Let posting styles be configured.
2123 (gnus-configure-posting-styles)
2124 (news-setup nil subject nil (and group (gnus-group-real-name group)) nil)
2125 ;; Associate this buffer with the draft group.
2126 (gnus-enter-buffer-into-draft)
2127 (goto-char (point-min))
2129 (unless (re-search-forward
2130 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2131 (goto-char (point-max)))
2134 (gnus-inews-insert-bfcc)
2135 (gnus-inews-insert-gcc)
2136 (gnus-inews-insert-archive-gcc group)
2137 (gnus-inews-insert-signature)
2138 (and gnus-post-prepare-function
2139 (gnus-functionp gnus-post-prepare-function)
2140 (funcall gnus-post-prepare-function group))
2141 (run-hooks 'gnus-post-prepare-hook)
2142 (gnus-inews-set-point)
2143 (make-local-variable 'gnus-prev-winconf)
2144 (setq gnus-prev-winconf winconf)
2145 (gnus-inews-modify-mail-mode-map)
2146 (local-set-key "\C-c\C-c" 'gnus-inews-news)))
2148 (defun gnus-news-followup (&optional yank group)
2150 (set-buffer gnus-summary-buffer)
2151 (if (not (or (not gnus-novice-user)
2154 "Are you sure you want to post to all of USENET? ")))
2156 (let ((group (gnus-group-real-name (or group gnus-newsgroup-name)))
2157 (cur (cons (current-buffer) (cdr gnus-article-current)))
2158 (winconf (current-window-configuration))
2159 from subject date message-of
2160 references message-id follow-to sendto elt
2161 followup-to distribution newsgroups gnus-warning)
2162 (set-buffer (get-buffer-create gnus-post-news-buffer))
2164 ;; Associate this buffer with the draft group.
2165 (gnus-enter-buffer-into-draft)
2166 (if (and (buffer-modified-p)
2169 "Unsent message being composed; erase it? ")))
2173 (gnus-copy-article-buffer)
2175 (set-buffer gnus-article-copy)
2176 (nnheader-narrow-to-headers)
2177 (if (gnus-functionp gnus-followup-to-function)
2180 (funcall gnus-followup-to-function group))))
2181 (setq from (mail-fetch-field "from"))
2182 (setq date (or (mail-fetch-field "date")
2183 (mail-header-date gnus-current-headers)))
2184 (setq message-of (gnus-message-of from date))
2185 (setq subject (or (mail-fetch-field "subject") "none"))
2186 ;; Remove any (buggy) Re:'s that are present and make a
2188 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
2189 (setq subject (substring subject (match-end 0))))
2190 (setq subject (concat "Re: " subject))
2191 (setq references (mail-fetch-field "references"))
2192 (setq message-id (mail-fetch-field "message-id"))
2193 (when (and (setq gnus-warning (mail-fetch-field "gnus-warning"))
2194 (string-match "<[^>]+>" gnus-warning))
2195 (setq message-id (match-string 0 gnus-warning)))
2196 (setq followup-to (mail-fetch-field "followup-to"))
2197 (setq newsgroups (mail-fetch-field "newsgroups"))
2198 (setq distribution (mail-fetch-field "distribution"))
2199 ;; Remove bogus distribution.
2200 (and (stringp distribution)
2201 (string-match "world" distribution)
2202 (setq distribution nil))
2205 (setq news-reply-yank-from (or from "(nobody)"))
2206 (setq news-reply-yank-message-id
2207 (or message-id "(unknown Message-ID)"))
2209 ;; Gather the "to" addresses out of the follow-to list and remove
2211 (if (and follow-to (listp follow-to))
2212 (while (setq elt (assoc "Newsgroups" follow-to))
2213 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
2214 (setq follow-to (delq elt follow-to))))
2216 ;; Let posting styles be configured.
2217 (gnus-configure-posting-styles)
2222 (if (equal followup-to "poster")
2223 (or newsgroups group "")
2225 gnus-use-followup-to
2226 (or (not (eq gnus-use-followup-to 'ask))
2227 (equal followup-to newsgroups)
2229 (format "Use Followup-To %s? " followup-to)))
2231 newsgroups group "")
2234 (make-local-variable 'gnus-article-reply)
2235 (setq gnus-article-reply cur)
2236 (make-local-variable 'gnus-prev-winconf)
2237 (setq gnus-prev-winconf winconf)
2238 (make-local-variable 'gnus-reply-subject)
2239 (setq gnus-reply-subject (mail-header-subject gnus-current-headers))
2240 (make-local-variable 'gnus-in-reply-to)
2241 (setq gnus-in-reply-to message-of)
2242 (when (and followup-to newsgroups)
2243 (make-local-variable 'gnus-newsgroup-followup)
2244 (setq gnus-newsgroup-followup
2245 (cons newsgroups followup-to)))
2247 (gnus-inews-insert-signature)
2249 (and gnus-post-prepare-function
2250 (gnus-functionp gnus-post-prepare-function)
2251 (funcall gnus-post-prepare-function group))
2252 (run-hooks 'gnus-post-prepare-hook)
2254 (auto-save-mode auto-save-default)
2255 (gnus-inews-modify-mail-mode-map)
2256 (local-set-key "\C-c\C-c" 'gnus-inews-news)
2258 (if (and follow-to (listp follow-to))
2260 (goto-char (point-min))
2261 (and (re-search-forward "^Newsgroups:" nil t)
2264 (insert (caar follow-to) ": " (cdar follow-to) "\n")
2265 (setq follow-to (cdr follow-to)))))
2267 ;; If a distribution existed, we use it.
2270 (mail-position-on-field "Distribution")
2271 (insert distribution)))
2273 (nnheader-insert-references references message-id)
2275 ;; Handle `gnus-auto-mail-to-author'.
2276 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
2277 ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
2278 (let ((to (if (if (eq gnus-auto-mail-to-author 'ask)
2279 (y-or-n-p "Also send mail to author? ")
2280 gnus-auto-mail-to-author)
2282 (set-buffer gnus-article-copy)
2283 (unless (gnus-group-get-parameter
2284 group 'broken-reply-to)
2285 (gnus-fetch-field "reply-to")))
2287 (x-mail (save-excursion
2288 (set-buffer gnus-article-copy)
2289 (gnus-fetch-field "x-mail-copy-to"))))
2290 ;; Deny sending copy if there's a negative X-Mail-Copy-To
2293 (if (and (string= x-mail "never")
2294 (not (eq gnus-auto-mail-to-author 'force)))
2297 ;; Insert a To or Cc header.
2299 (if (mail-fetch-field "To")
2302 (insert "Cc: " to "\n"))
2303 (mail-position-on-field "To")
2306 (gnus-inews-insert-bfcc)
2307 (gnus-inews-insert-gcc)
2308 (gnus-inews-insert-archive-gcc group)
2310 ;; Now the headers should be ok, so we do the yanking.
2311 (goto-char (point-min))
2313 (concat "^" (regexp-quote mail-header-separator) "$"))
2317 (gnus-configure-windows 'followup 'force)
2320 (let ((last (point))
2322 (if (not (listp yank))
2325 (mail-yank-original nil))
2326 (or mail-yank-hooks mail-citation-hook
2327 (run-hooks 'news-reply-header-hook)))
2329 (save-window-excursion
2330 (set-buffer gnus-summary-buffer)
2331 (gnus-summary-select-article nil nil nil (car yank))
2332 (gnus-summary-remove-process-mark (car yank)))
2334 (gnus-copy-article-buffer)
2335 (mail-yank-original nil)
2336 (setq end (set-marker (make-marker) (point))))
2337 (or mail-yank-hooks mail-citation-hook
2338 (run-hooks 'news-reply-header-hook))
2340 (set-marker end nil)
2341 (setq yank (cdr yank))))
2343 (gnus-configure-windows 'followup-yank 'force))
2345 (make-local-variable 'gnus-article-check-size)
2346 (setq gnus-article-check-size
2347 (cons (buffer-size) (gnus-article-checksum)))
2348 (gnus-inews-set-point))))))
2350 (defun gnus-message-of (from date)
2351 "Take a FROM and a DATE and return an IN-REPLY-TO."
2354 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2355 (concat (if stop-pos (substring from 0 stop-pos) from)
2357 (if (or (not date) (string= date ""))
2358 "(unknown date)" date)))))
2360 (defun gnus-mail-yank-original ()
2363 (mail-yank-original nil))
2364 (or mail-yank-hooks mail-citation-hook
2365 (run-hooks 'news-reply-header-hook)))
2367 (defun gnus-mail-send-and-exit (&optional dont-send)
2368 "Send the current mail and return to Gnus."
2370 (let* ((reply gnus-article-reply)
2371 (winconf gnus-prev-winconf)
2372 (address-group gnus-add-to-address)
2373 (to-address (and address-group
2374 (mail-fetch-field "to"))))
2375 (setq gnus-add-to-address nil)
2376 (let ((buffer-file-name nil))
2377 (or dont-send (gnus-mail-send)))
2379 (when (gnus-alive-p)
2380 ;; This mail group doesn't have a `to-list', so we add one
2383 (gnus-group-add-parameter address-group (cons 'to-list to-address)))
2384 (when (and (gnus-buffer-exists-p (car reply))
2387 (set-buffer (car reply))
2388 (gnus-summary-mark-article-as-replied (cdr reply))))
2389 (and winconf (set-window-configuration winconf)))))
2391 (defun gnus-kill-message-buffer ()
2392 "Kill the current buffer after dissociating it from the draft group."
2394 (when (gnus-y-or-n-p "Dissociate and kill the current buffer? ")
2395 (gnus-dissociate-buffer-from-draft)
2396 (let ((winconf gnus-prev-winconf))
2397 (kill-buffer (current-buffer))
2399 (set-window-configuration winconf)))))
2401 (defun gnus-put-message ()
2402 "Put the current message in some group and return to Gnus."
2404 (let ((reply gnus-article-reply)
2405 (winconf gnus-prev-winconf)
2406 (group gnus-newsgroup-name))
2408 (or (and group (not (gnus-group-read-only-p group)))
2409 (setq group (read-string "Put in group: " nil
2410 (gnus-writable-groups))))
2411 (and (gnus-gethash group gnus-newsrc-hashtb)
2412 (error "No such group: %s" group))
2417 (gnus-inews-narrow-to-headers)
2418 (let (gnus-deletable-headers)
2419 (if (eq major-mode 'mail-mode)
2420 (gnus-inews-insert-headers gnus-required-mail-headers)
2421 (gnus-inews-insert-headers)))
2422 (goto-char (point-max))
2423 (insert "Gcc: " group "\n")
2428 (if (get-buffer gnus-group-buffer)
2430 (if (gnus-buffer-exists-p (car-safe reply))
2432 (set-buffer (car reply))
2434 (gnus-summary-mark-article-as-replied
2436 (and winconf (set-window-configuration winconf))))))
2438 (defun gnus-forward-make-subject (buffer)
2441 (concat "[" (if (memq 'mail (assoc (symbol-name
2442 (car (gnus-find-method-for-group
2443 gnus-newsgroup-name)))
2444 gnus-valid-select-methods))
2445 (gnus-fetch-field "From")
2446 gnus-newsgroup-name)
2447 "] " (or (gnus-fetch-field "Subject") ""))))
2449 (defun gnus-forward-insert-buffer (buffer)
2452 ;; Put point where we want it before inserting the forwarded
2454 (if gnus-signature-before-forwarded-message
2455 (goto-char (point-max))
2456 (goto-char (point-min))
2458 (concat "^" (regexp-quote mail-header-separator) "$"))
2460 ;; Narrow to the area we are to insert.
2461 (narrow-to-region (point) (point))
2462 ;; Insert the separators and the forwarded buffer.
2463 (insert gnus-forward-start-separator)
2464 (insert-buffer-substring buffer)
2465 (goto-char (point-max))
2466 (insert gnus-forward-end-separator)
2467 (gnus-set-text-properties (point-min) (point-max) nil)
2468 ;; Remove all unwanted headers.
2469 (goto-char (point-min))
2472 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
2475 (goto-char (point-min))
2476 (let ((case-fold-search t))
2477 (delete-non-matching-lines gnus-forward-included-headers))))))
2479 (defun gnus-mail-forward (&optional buffer)
2480 "Forward the current message to another user using mail."
2481 (let* ((forward-buffer (or buffer (current-buffer)))
2482 (winconf (current-window-configuration))
2483 (subject (gnus-forward-make-subject forward-buffer)))
2484 (set-buffer (get-buffer-create gnus-mail-buffer))
2485 (if (and (buffer-modified-p)
2488 "Unsent message being composed; erase it? ")))
2491 (gnus-mail-setup 'forward nil subject)
2492 (make-local-variable 'gnus-prev-winconf)
2493 (setq gnus-prev-winconf winconf)
2494 (gnus-forward-insert-buffer forward-buffer)
2495 (goto-char (point-min))
2496 (re-search-forward "^To: ?" nil t)
2497 (gnus-configure-windows 'mail-forward 'force)
2498 ;; You have a chance to arrange the message.
2499 (run-hooks 'gnus-mail-forward-hook)
2500 (run-hooks 'gnus-mail-hook))))
2502 (defun gnus-forward-using-post (&optional buffer)
2504 (let* ((forward-buffer (or buffer (current-buffer)))
2505 (subject (gnus-forward-make-subject forward-buffer))
2506 (gnus-newsgroup-name nil))
2507 (gnus-post-news 'post nil nil nil nil subject)
2509 (gnus-forward-insert-buffer forward-buffer)
2510 ;; You have a chance to arrange the message.
2511 (run-hooks 'gnus-mail-forward-hook)))))
2513 (defun gnus-mail-other-window-using-mail ()
2514 "Compose mail other window using mail."
2515 (let ((winconf (current-window-configuration)))
2516 (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
2517 (gnus-inews-modify-mail-mode-map)
2518 (make-local-variable 'gnus-prev-winconf)
2519 (setq gnus-prev-winconf winconf)
2520 (run-hooks 'gnus-mail-hook)
2521 (gnus-configure-windows 'summary-mail 'force)))
2523 (defun gnus-article-mail (yank)
2524 "Send a reply to the address near point.
2525 If YANK is non-nil, include the original article."
2529 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
2530 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
2533 (switch-to-buffer gnus-summary-buffer)
2534 (gnus-mail-reply yank address)))))
2537 "Send a bug report to the Gnus maintainers."
2539 (let ((winconf (current-window-configuration)))
2540 (delete-other-windows)
2541 (switch-to-buffer "*Gnus Help Bug*")
2543 (insert gnus-bug-message)
2544 (goto-char (point-min))
2545 (pop-to-buffer "*Gnus Bug*")
2548 (mail-setup gnus-maintainer nil nil nil nil nil)
2549 (auto-save-mode auto-save-default)
2550 (make-local-variable 'gnus-prev-winconf)
2551 (setq gnus-prev-winconf winconf)
2552 (gnus-inews-modify-mail-mode-map)
2553 (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
2554 (goto-char (point-min))
2555 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2557 (insert (gnus-version) "\n")
2558 (insert (emacs-version))
2559 (insert "\n\n\n\n\n")
2561 (goto-char (point-min))
2562 (search-forward "Subject: " nil t)
2565 (defun gnus-bug-mail-send-and-exit ()
2566 "Send the bug message and exit."
2568 (let ((cur (current-buffer)))
2569 (and (get-buffer "*Gnus Help Bug*")
2570 (kill-buffer "*Gnus Help Bug*"))
2571 (gnus-mail-send-and-exit)
2572 (when (buffer-name cur)
2573 (kill-buffer cur))))
2575 (defun gnus-debug ()
2576 "Attemps to go through the Gnus source file and report what variables have been changed.
2577 The source file has to be in the Emacs load path."
2579 (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el" "nnmail.el"))
2580 file dirs expr olist sym)
2581 (message "Please wait while we snoop your variables...")
2584 (set-buffer (get-buffer-create " *gnus bug info*"))
2585 (buffer-disable-undo (current-buffer))
2588 (setq dirs load-path)
2590 (if (or (not (car dirs))
2591 (not (stringp (car dirs)))
2593 (setq file (concat (file-name-as-directory
2594 (car dirs)) (car files))))))
2595 (setq dirs (cdr dirs))
2597 (insert-file-contents file)
2598 (goto-char (point-min))
2599 (if (not (re-search-forward "^;;* *Internal variables" nil t))
2600 (message "Malformed sources in file %s" file)
2601 (narrow-to-region (point-min) (point))
2602 (goto-char (point-min))
2603 (while (setq expr (condition-case ()
2604 (read (current-buffer)) (error nil)))
2606 (and (eq (car expr) 'defvar)
2607 (stringp (nth 3 expr))
2608 (or (not (boundp (nth 1 expr)))
2609 (not (equal (eval (nth 2 expr))
2610 (symbol-value (nth 1 expr)))))
2611 (setq olist (cons (nth 1 expr) olist)))
2613 (setq files (cdr files)))
2614 (kill-buffer (current-buffer)))
2615 (when (setq olist (nreverse olist))
2616 (insert "------------------ Environment follows ------------------\n\n"))
2618 (if (boundp (car olist))
2620 (pp `(setq ,(car olist)
2621 ,(if (or (consp (setq sym (symbol-value (car olist))))
2623 (not (or (eq sym nil)
2625 (list 'quote (symbol-value (car olist)))
2626 (symbol-value (car olist))))
2629 (format "(setq %s 'whatever)\n" (car olist))))
2630 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
2631 (setq olist (cdr olist)))
2633 ;; Remove any null chars - they seem to cause trouble for some
2634 ;; mailers. (Byte-compiled output from the stuff above.)
2635 (goto-char (point-min))
2636 (while (re-search-forward "[\000\200]" nil t)
2637 (replace-match "" t t))))
2639 ;;; Treatment of rejected articles.
2642 (defvar mail-unsent-separator)
2644 (defun gnus-summary-resend-bounced-mail (fetch)
2645 "Re-mail the current message.
2646 This only makes sense if the current message is a bounce message than
2647 contains some mail you have written which has been bounced back to
2649 If FETCH, try to fetch the article that this is a reply to, if indeed
2653 (gnus-summary-select-article t)
2654 ;; Create a mail buffer.
2655 (gnus-new-empty-mail)
2657 (insert-buffer-substring gnus-article-buffer)
2658 (goto-char (point-min))
2659 (or (re-search-forward mail-unsent-separator nil t)
2660 (and (search-forward "\n\n" nil t)
2661 (re-search-forward "^Return-Path:.*\n" nil t)))
2662 ;; We remove everything before the bounced mail.
2665 (if (re-search-forward "[^ \t]*:" nil t)
2671 (nnheader-narrow-to-headers)
2672 (nnheader-remove-header gnus-bounced-headers-junk t)
2673 (setq references (mail-fetch-field "references"))
2674 (goto-char (point-max))
2675 (insert mail-header-separator)))
2676 ;; If there are references, we fetch the article we answered to.
2679 (string-match "\\(<[^]+>\\)[ \t]*$" references)
2680 (gnus-summary-refer-article
2681 (substring references (match-beginning 1) (match-end 1)))
2683 (gnus-summary-show-all-headers)
2684 (gnus-configure-windows 'compose-bounce))))
2685 (goto-char (point-min)))
2689 (defun gnus-mail-send (&optional no-generated-headers)
2690 "Send the current buffer as mail.
2691 Headers will be generated before sending."
2693 (unless no-generated-headers
2697 (gnus-inews-narrow-to-headers)
2698 (gnus-inews-insert-headers gnus-required-mail-headers)
2699 (gnus-inews-remove-empty-headers))))
2701 (when (not (gnus-inews-reject-message))
2702 ;; Remove the header separator.
2703 (goto-char (point-min))
2704 (and (re-search-forward
2705 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2706 (replace-match "" t t))
2707 ;; Run final inews hooks. This hook may do FCC.
2708 (run-hooks 'gnus-inews-article-hook)
2710 (nnheader-narrow-to-headers)
2711 (nnheader-remove-header "^[gf]cc:" t)
2713 (goto-char (point-min))
2714 (search-forward "\n\n")
2716 (insert mail-header-separator)
2718 (run-hooks 'gnus-message-sent-hook)))
2720 (defun gnus-inews-modify-mail-mode-map ()
2721 (use-local-map (copy-keymap (current-local-map)))
2722 (gnus-local-set-keys
2723 "\C-c\C-c" gnus-mail-send-and-exit
2724 "\C-c\M-\C-p" gnus-put-message
2725 "\C-c\C-q" gnus-kill-message-buffer
2726 "\C-c\M-d" gnus-dissociate-buffer-from-draft
2727 "\C-c\C-d" gnus-associate-buffer-with-draft))
2729 (defun gnus-mail-setup (type &optional to subject in-reply-to cc
2730 replybuffer actions)
2731 ;; Let posting styles be configured.
2732 (gnus-configure-posting-styles)
2736 (eq gnus-mail-method 'mh)
2737 (and (or (eq type 'reply) (eq type 'followup))
2738 (eq gnus-mail-reply-method 'gnus-mail-reply-using-mhe))
2739 (and (eq type 'forward)
2740 (eq gnus-mail-forward-method 'gnus-mail-forward-using-mhe))
2742 (eq gnus-mail-other-window-method
2743 'gnus-mail-other-window-using-mhe)))
2744 'gnus-mh-mail-setup)
2746 (eq gnus-mail-method 'vm)
2747 (and (or (eq type 'reply) (eq type 'followup))
2748 (eq gnus-mail-reply-method 'gnus-mail-reply-using-vm))
2749 (and (eq type 'forward)
2750 (eq gnus-mail-forward-method 'gnus-mail-forward-using-vm))
2752 (eq gnus-mail-other-window-method
2753 'gnus-mail-other-window-using-vm)))
2754 'gnus-vm-mail-setup)
2756 (eq gnus-mail-method 'sendmail)
2757 (and (or (eq type 'reply) (eq type 'followup))
2758 (eq gnus-mail-reply-method 'gnus-mail-reply-using-mail))
2759 (and (eq type 'forward)
2760 (eq gnus-mail-forward-method 'gnus-mail-forward-using-mail))
2762 (eq gnus-mail-other-window-method
2763 'gnus-mail-other-window-using-mail)))
2764 'gnus-sendmail-mail-setup)
2766 (cond ((or (eq type 'reply) (eq type 'followup))
2767 gnus-mail-reply-method)
2769 gnus-mail-forward-method)
2771 gnus-mail-other-window-method))))
2772 to subject in-reply-to cc replybuffer actions)
2773 ;; Associate this mail buffer with the draft group.
2774 (gnus-enter-buffer-into-draft))
2776 (defun gnus-sendmail-mail-setup (to subject in-reply-to cc replybuffer actions)
2778 (mail-setup to subject nil cc replybuffer actions)
2779 (gnus-inews-set-point)
2780 (gnus-inews-modify-mail-mode-map))
2784 ;; Do Gcc handling, which copied the message over to some group.
2785 (defun gnus-inews-do-gcc (&optional gcc)
2788 (nnheader-narrow-to-headers)
2789 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
2790 (cur (current-buffer))
2791 groups group method)
2793 (nnheader-remove-header "gcc")
2795 (setq groups (gnus-tokenize-header gcc " ,"))
2796 ;; Copy the article over to some group(s).
2797 (while (setq group (pop groups))
2800 (cond ((and (null (gnus-get-info group))
2801 (eq (car gnus-message-archive-method)
2803 (gnus-server-to-method
2804 (gnus-group-method group)))))
2805 ;; If the group doesn't exist, we assume
2806 ;; it's an archive group...
2807 gnus-message-archive-method)
2808 (t (gnus-group-method group)))))
2809 (unless (gnus-request-group group t method)
2810 (gnus-request-create-group group method))
2811 (gnus-check-server method)
2813 (nnheader-set-temp-buffer " *acc*")
2814 (insert-buffer-substring cur)
2815 (unless (condition-case ()
2816 (gnus-request-accept-article group t method)
2818 (gnus-message 1 "Couldn't store article in group %s: %s"
2819 group (gnus-status-message method))
2821 (kill-buffer (current-buffer)))))))))
2823 (defun gnus-inews-insert-bfcc ()
2824 "Insert Bcc and Fcc headers."
2826 ;; Handle author copy using BCC field.
2827 (when (and gnus-mail-self-blind
2828 (not (mail-fetch-field "bcc")))
2829 (mail-position-on-field "Bcc")
2830 (insert (if (stringp gnus-mail-self-blind)
2831 gnus-mail-self-blind
2832 (user-login-name))))
2833 ;; Handle author copy using FCC field.
2834 (when gnus-author-copy
2835 (mail-position-on-field "Fcc")
2836 (insert gnus-author-copy))))
2838 (defun gnus-inews-insert-gcc ()
2839 "Insert Gcc headers based on `gnus-outgoing-message-group'."
2842 (gnus-inews-narrow-to-headers)
2843 (let* ((group gnus-outgoing-message-group)
2845 ((gnus-functionp group)
2847 ((or (stringp group) (list group))
2851 (if (stringp gcc) gcc
2852 (mapconcat 'identity gcc " "))
2855 (defun gnus-inews-insert-archive-gcc (&optional group)
2856 "Insert the Gcc to say where the article is to be archived."
2857 (let* ((var gnus-message-archive-group)
2858 (group (or group gnus-newsgroup-name ""))
2862 ((null gnus-message-archive-method)
2866 ;; Just a single group.
2869 ;; We don't want this.
2871 ((and (listp var) (stringp (car var)))
2872 ;; A list of groups.
2874 ((gnus-functionp var)
2876 (funcall var group))
2878 ;; An alist of regexps/functions/forms.
2883 ((stringp (caar var))
2885 (when (string-match (caar var) group)
2887 ((gnus-functionp (car var))
2889 (funcall (car var) group))
2891 (eval (car var)))))))
2892 (setq var (cdr var)))
2895 (when (stringp groups)
2896 (setq groups (list groups)))
2899 (gnus-inews-narrow-to-headers)
2900 (goto-char (point-max))
2903 (insert (gnus-group-prefixed-name
2904 (pop groups) gnus-message-archive-method))
2908 ;;; Handling rejected (and postponed) news.
2910 (defun gnus-draft-group ()
2911 "Return the name of the draft group."
2912 (gnus-group-prefixed-name
2913 (file-name-nondirectory (directory-file-name gnus-draft-group-directory))
2914 (list 'nndraft gnus-draft-group-directory)))
2916 (defun gnus-make-draft-group ()
2917 "Make the draft group or die trying."
2918 (let* ((method `(nndraft "private"
2920 ,gnus-draft-group-directory)))
2921 (group (gnus-draft-group)))
2922 (or (gnus-gethash group gnus-newsrc-hashtb)
2923 (gnus-group-make-group (gnus-group-real-name group) method)
2924 (error "Can't create the draft group"))
2925 (gnus-check-server method)
2928 (defun gnus-associate-buffer-with-draft (&optional generate silent)
2929 "Enter the current buffer into the draft group."
2931 (when (gnus-request-accept-article (gnus-make-draft-group) t)
2933 ;; This function does the proper marking of articles.
2934 (gnus-mail-send-and-exit 'dont-send))
2935 (set-buffer-modified-p nil)))
2937 (defun gnus-enter-buffer-into-draft ()
2938 (when gnus-use-draft
2940 ;; Make sure the draft group exists.
2941 (gnus-make-draft-group)
2942 ;; Associate the buffer with the draft group.
2943 (let ((article (gnus-request-associate-buffer (gnus-draft-group))))
2944 ;; Arrange for deletion of the draft after successful sending.
2945 (make-local-variable 'gnus-message-sent-hook)
2946 (setq gnus-message-sent-hook
2949 (let ((gnus-verbose-backends nil))
2950 (gnus-request-expire-articles
2951 (quote ,(list article))
2952 ,(gnus-draft-group) t)))))))))
2954 (defun gnus-dissociate-buffer-from-draft ()
2955 "Disable auto-saving and association to the draft group of the current buffer."
2957 (run-hooks 'gnus-message-sent-hook)
2958 (setq buffer-file-name nil)
2959 (setq buffer-auto-save-file-name nil))
2961 (defun gnus-summary-send-draft ()
2962 "Enter a mail/post buffer to edit and send the draft."
2964 (gnus-set-global-variables)
2965 (unless (equal gnus-newsgroup-name (gnus-draft-group))
2966 (error "This function can only be used in the draft buffer"))
2968 (if (not (setq buf (gnus-request-restore-buffer
2969 (gnus-summary-article-number) gnus-newsgroup-name)))
2970 (error "Couldn't restore the article")
2971 (switch-to-buffer buf)
2972 (gnus-inews-modify-mail-mode-map)
2973 (when (eq major-mode 'news-reply-mode)
2974 (local-set-key "\C-c\C-c" 'gnus-inews-news))
2975 (gnus-enter-buffer-into-draft)
2976 ;; Insert the separator.
2977 (goto-char (point-min))
2978 (search-forward "\n\n")
2980 (insert mail-header-separator)
2981 ;; Configure windows.
2982 (let ((gnus-draft-buffer (current-buffer)))
2983 (gnus-configure-windows 'draft t)
2984 (goto-char (point))))))
2986 (defun gnus-configure-posting-styles ()
2987 "Configure posting styles according to `gnus-posting-styles'."
2988 (let ((styles gnus-posting-styles)
2989 (gnus-newsgroup-name (or gnus-newsgroup-name ""))
2990 style match variable attribute value value-value)
2991 ;; Go through all styles and look for matches.
2993 (setq style (pop styles)
2995 (when (cond ((stringp match)
2996 ;; Regexp string match on the group name.
2997 (string-match match gnus-newsgroup-name))
2998 ((or (symbolp match)
2999 (gnus-functionp match))
3000 (cond ((gnus-functionp match)
3001 ;; Function to be called.
3004 ;; Variable to be checked.
3005 (symbol-value match))))
3007 ;; This is a form to be evaled.
3009 ;; We have a match, so we set the variables.
3011 (setq attribute (pop style)
3012 value (cdr attribute))
3013 ;; We find the variable that is to be modified.
3014 (if (and (not (stringp (car attribute)))
3015 (not (setq variable (cdr (assq (car attribute)
3016 gnus-posting-style-alist)))))
3017 (message "Couldn't find attribute %s" (car attribute))
3018 ;; We set the variable.
3020 (cond ((stringp value)
3022 ((or (symbolp value)
3023 (gnus-functionp value))
3024 (cond ((gnus-functionp value)
3027 (symbol-value value))))
3032 ;; This is an ordinary variable.
3033 (make-local-variable variable)
3034 (set variable value-value))
3035 ;; This is a header to be added to the headers when
3038 (make-local-variable gnus-required-headers)
3039 (make-local-variable gnus-required-mail-headers)
3040 (push (cons (car attribute) value-value)
3041 gnus-required-headers)
3042 (push (cons (car attribute) value-value)
3043 gnus-required-mail-headers)))))))))
3045 (defun gnus-inews-set-point ()
3046 "Move point to where the user probably wants to find it."
3047 (gnus-inews-narrow-to-headers)
3049 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3050 (search-backward ":" )
3054 (goto-char (point-max))
3057 (unless (looking-at "$")
3061 (gnus-add-shutdown 'gnus-inews-close 'gnus)
3063 (defun gnus-inews-close ()
3064 (setq gnus-inews-sent-ids nil))
3066 ;;; Allow redefinition of functions.
3072 ;;; gnus-msg.el ends here