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-article-expires 14
243 "*Number of days before your article expires.
244 This variable isn't used unless you have the `Expires' element in
245 `gnus-required-headers'.")
247 (defvar gnus-distribution-function nil
248 "*Function that should return the Distribution header for outgoing articles.
249 It will be called from the buffer where the outgoing article
250 is being prepared with the group name as the only parameter.
251 It should return a valid distribution.
253 The function will only be called if you have the `Distribution' header in
254 `gnus-required-headers'.")
256 (defvar gnus-check-before-posting
257 '(subject-cmsg multiple-headers sendsys message-id from
258 long-lines control-chars size new-text
259 redirected-followup signature approved sender
261 "In non-nil, Gnus will attempt to run some checks on outgoing posts.
262 If this variable is t, Gnus will check everything it can. If it is a
263 list, then those elements in that list will be checked.")
265 (defvar gnus-delete-supersedes-headers
266 "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Supersedes:\\|^Xref:\\|^Lines:"
267 "*Header lines matching this regexp will be deleted before posting.
268 It's best to delete old Path and Date headers before posting to avoid
271 (defvar gnus-auto-mail-to-author nil
272 "*If non-nil, mail the authors of articles a copy of your follow-ups.
273 If this variable is `ask', the user will be prompted for whether to
274 mail a copy. The string given by `gnus-mail-courtesy-message' will be
275 inserted at the beginning of the mail copy.")
277 ;; Added by Ethan Bradford <ethanb@ptolemy.astro.washington.edu>.
278 (defvar gnus-mail-courtesy-message
279 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
280 "*This is inserted at the start of a mailed copy of a posted message.
281 If this variable is nil, no such courtesy message will be added.")
283 (defvar gnus-mail-method 'sendmail
284 "*Method to use for composing mail.
285 There are three legal values: `sendmail' (which is the default), `mh',
288 (defvar gnus-mail-reply-method (function gnus-mail-reply-using-mail)
289 "*Function to compose a reply.
290 Three pre-made functions are `gnus-mail-reply-using-mail' (sendmail);
291 `gnus-mail-reply-using-mhe' (MH-E); and `gnus-mail-reply-using-vm'.")
293 (defvar gnus-mail-forward-method (function gnus-mail-forward-using-mail)
294 "*Function to forward the current message to another user.
295 Three pre-made functions are `gnus-mail-forward-using-mail' (sendmail);
296 `gnus-mail-forward-using-mhe' (MH-E); and `gnus-mail-forward-using-vm'.")
298 (defvar gnus-mail-other-window-method 'gnus-mail-other-window-using-mail
299 "*Function to compose mail in the other window.
300 Three pre-made functions are `gnus-mail-other-window-using-mail'
301 (sendmail); `gnus-mail-other-window-using-mhe' (MH-E); and
302 `gnus-mail-other-window-using-vm'.")
304 (defvar gnus-inews-article-function 'gnus-inews-article
305 "*Function to post an article.")
307 (defvar gnus-bounced-headers-junk "^\\(Received\\):"
308 "*Regexp that matches headers to be removed in resent bounced mail.")
310 (defvar gnus-inews-article-hook (list 'gnus-inews-do-fcc)
311 "*A hook called before finally posting an article.
312 The default hook (`gnus-inews-do-fcc') does FCC processing (ie. saves
313 the article to a file).")
315 (defvar gnus-inews-article-header-hook nil
316 "*A hook called after inserting the headers in an article to be posted.
317 The hook is called from the *post-news* buffer, narrowed to the
320 (defvar gnus-mail-hook nil
321 "*A hook called as the last thing after setting up a mail buffer.")
323 (defvar gnus-message-sent-hook nil
324 "*A hook run after an article has been sent (or attempted sent).")
326 ;;; Internal variables.
328 (defvar gnus-post-news-buffer "*Post Gnus*")
329 (defvar gnus-mail-buffer "*Mail Gnus*")
330 (defvar gnus-article-copy nil)
331 (defvar gnus-reply-subject nil)
332 (defvar gnus-newsgroup-followup nil)
333 (defvar gnus-add-to-address nil)
334 (defvar gnus-in-reply-to nil)
335 (defvar gnus-last-posting-server nil)
338 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
339 (autoload 'news-setup "rnewspost")
340 (autoload 'news-reply-mode "rnewspost")
341 (autoload 'rmail-dont-reply-to "mail-utils")
342 (autoload 'rmail-output "rmailout"))
346 ;;; Gnus Posting Functions
350 (gnus-summary-send-map "S" gnus-summary-mode-map)
351 "p" gnus-summary-post-news
352 "f" gnus-summary-followup
353 "F" gnus-summary-followup-with-original
354 "b" gnus-summary-followup-and-reply
355 "B" gnus-summary-followup-and-reply-with-original
356 "c" gnus-summary-cancel-article
357 "s" gnus-summary-supersede-article
358 "r" gnus-summary-reply
359 "R" gnus-summary-reply-with-original
360 "m" gnus-summary-mail-other-window
361 "u" gnus-uu-post-news
362 "om" gnus-summary-mail-forward
363 "op" gnus-summary-post-forward
364 "Om" gnus-uu-digest-mail-forward
365 "Op" gnus-uu-digest-post-forward)
368 (gnus-send-bounce-map "D" gnus-summary-send-map)
369 "b" gnus-summary-resend-bounced-mail
370 "c" gnus-summary-send-draft
371 "r" gnus-summary-resend-message)
373 ;;; Internal functions.
375 (defun gnus-number-base36 (num len)
376 (if (if (< len 0) (<= num 0) (= len 0))
378 (concat (gnus-number-base36 (/ num 36) (1- len))
379 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
382 ;;; Post news commands of Gnus group mode and summary mode
384 (defun gnus-group-mail ()
385 "Start composing a mail."
388 ;; We might want to prompt here.
389 (when (and gnus-interactive-post
390 (not gnus-expert-user))
391 (read-string "To: "))))
393 (defun gnus-group-post-news (&optional arg)
395 The newsgroup under the cursor is used as the group to post to.
397 If you wish to get an empty post buffer, use a prefix ARG. You can
398 also do this by calling this function from the bottom of the Group
401 (let ((gnus-newsgroup-name nil)
402 (group (unless arg (gnus-group-group-name)))
404 ;; We might want to prompt here.
405 (when (and gnus-interactive-post
406 (not gnus-expert-user))
407 (setq gnus-newsgroup-name
409 (completing-read "Group: " gnus-active-hashtb nil nil
410 (cons (or group "") 0)))))
411 (gnus-post-news 'post group nil gnus-article-buffer)))
413 (defun gnus-summary-post-news ()
416 (gnus-set-global-variables)
417 (gnus-post-news 'post gnus-newsgroup-name))
419 (defun gnus-summary-followup (yank &optional yank-articles)
420 "Compose a followup to an article.
421 If prefix argument YANK is non-nil, original article is yanked automatically."
423 (gnus-set-global-variables)
424 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
425 (save-window-excursion
426 (gnus-summary-select-article))
427 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
428 (gnus-newsgroup-name gnus-newsgroup-name))
429 ;; Check Followup-To: poster.
430 (set-buffer gnus-article-buffer)
431 (if (and gnus-use-followup-to
432 (string-equal "poster" (gnus-fetch-field "followup-to"))
433 (or (not (memq gnus-use-followup-to '(t ask)))
435 "Do you want to ignore `Followup-To: poster'? "))))
436 ;; Mail to the poster.
437 (gnus-summary-reply yank)
439 (gnus-post-news nil gnus-newsgroup-name
440 headers gnus-article-buffer
441 (or yank-articles (not (not yank)))))))
443 (defun gnus-summary-followup-with-original (n)
444 "Compose a followup to an article and include the original article."
446 (gnus-summary-followup t (gnus-summary-work-articles n)))
448 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
449 (defun gnus-summary-followup-and-reply (yank &optional yank-articles)
450 "Compose a followup and do an auto mail to author."
452 (gnus-set-global-variables)
453 (let ((gnus-auto-mail-to-author 'force))
454 (gnus-summary-followup yank yank-articles)))
456 (defun gnus-summary-followup-and-reply-with-original (n)
457 "Compose a followup, include the original, and do an auto mail to author."
459 (gnus-summary-followup-and-reply t (gnus-summary-work-articles n)))
461 (defun gnus-summary-cancel-article (n)
462 "Cancel an article you posted."
464 (gnus-set-global-variables)
465 (let ((articles (gnus-summary-work-articles n))
467 (while (setq article (pop articles))
468 (when (gnus-summary-select-article t nil nil article)
469 (when (gnus-eval-in-buffer-window
470 gnus-original-article-buffer (gnus-cancel-news))
471 (gnus-summary-mark-as-read article gnus-canceled-mark))
472 (gnus-article-hide-headers-if-wanted))
473 (gnus-summary-remove-process-mark article))))
475 (defun gnus-summary-supersede-article ()
476 "Compose an article that will supersede a previous article.
477 This is done simply by taking the old article and adding a Supersedes
478 header line with the old Message-ID."
480 (gnus-set-global-variables)
481 (gnus-summary-select-article t)
482 ;; Check whether the user owns the article that is to be superseded.
483 (unless (string-equal
484 (downcase (gnus-mail-strip-quoted-names
485 (mail-header-from gnus-current-headers)))
486 (downcase (gnus-mail-strip-quoted-names (gnus-inews-user-name))))
487 (error "This article is not yours."))
488 ;; Get a normal *Post News* buffer.
489 (gnus-new-news gnus-newsgroup-name t)
491 (insert-buffer-substring gnus-original-article-buffer)
492 (nnheader-narrow-to-headers)
493 ;; Remove unwanted headers.
494 (when gnus-delete-supersedes-headers
495 (nnheader-remove-header gnus-delete-supersedes-headers t))
496 (goto-char (point-min))
497 (if (not (re-search-forward "^Message-ID: " nil t))
498 (error "No Message-ID in this article")
499 (replace-match "Supersedes: " t t))
500 (goto-char (point-max))
501 (insert mail-header-separator)
507 (defalias 'sendnews 'gnus-post-news)
510 (defalias 'postnews 'gnus-post-news)
512 (defun gnus-copy-article-buffer (&optional article-buffer)
513 ;; make a copy of the article buffer with all text properties removed
514 ;; this copy is in the buffer gnus-article-copy.
515 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
516 ;; this buffer should be passed to all mail/news reply/post routines.
517 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
518 (buffer-disable-undo gnus-article-copy)
519 (or (memq gnus-article-copy gnus-buffer-list)
520 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
521 (let ((article-buffer (or article-buffer gnus-article-buffer)))
522 (if (and (get-buffer article-buffer)
523 (buffer-name (get-buffer article-buffer)))
525 (set-buffer article-buffer)
527 (copy-to-buffer gnus-article-copy (point-min) (point-max))
528 (gnus-set-text-properties (point-min) (point-max)
529 nil gnus-article-copy)))))
531 (defun gnus-post-news (post &optional group header article-buffer yank subject)
532 "Begin editing a new USENET news article to be posted.
533 Type \\[describe-mode] in the buffer to get a list of commands."
534 (interactive (list t))
535 (let* ((group (or group gnus-newsgroup-name))
537 to-address to-group mailing-list to-list)
539 (setq to-address (gnus-group-get-parameter group 'to-address)
540 to-group (gnus-group-get-parameter group 'to-group)
541 to-list (gnus-group-get-parameter group 'to-list)
542 mailing-list (when gnus-mailing-list-groups
543 (string-match gnus-mailing-list-groups group))
544 group (gnus-group-real-name group)))
545 (if (or (and to-group
546 (gnus-news-group-p to-group))
547 (and (gnus-news-group-p
548 (or pgroup gnus-newsgroup-name)
549 (if header (mail-header-number header) gnus-current-article))
555 (gnus-new-news (or to-group group))
556 (gnus-news-followup yank (or to-group group)))
560 (gnus-new-mail (or to-address to-list))
561 ;; Arrange for mail groups that have no `to-address' to
562 ;; get that when the user sends off the mail.
564 (make-local-variable 'gnus-add-to-address)
565 (setq gnus-add-to-address group)))
566 (gnus-mail-reply yank to-address 'followup)))))
568 (defun gnus-post-method (group query-method &optional silent)
569 "Return the posting method based on GROUP and query-method.
570 If SILENT, don't prompt the user."
571 (let ((group-method (if (stringp group)
572 (gnus-find-method-for-group group)
575 ;; If the group-method is nil (which shouldn't happen) we use
576 ;; the default method.
578 (or gnus-post-method gnus-select-method))
579 ;; We want this group's method.
580 ((and query-method (not (eq query-method 0)))
582 ;; We query the user for a post method.
584 (and gnus-post-method
585 (listp (car gnus-post-method))))
587 ;; Collect all methods we know about.
589 (when gnus-post-method
590 (if (listp (car gnus-post-method))
592 (listp gnus-post-method)))
593 gnus-secondary-select-methods
594 (list gnus-select-method)
595 (list group-method)))
596 method-alist post-methods method)
597 ;; Weed out all mail methods.
599 (setq method (gnus-server-get-method "" (pop methods)))
600 (when (or (gnus-method-option-p method 'post)
601 (gnus-method-option-p method 'post-mail))
602 (push method post-methods)))
603 ;; Create a name-method alist.
607 (list (concat (cadr m) " (" (symbol-name (car m)) ")") m))
612 (setq gnus-last-posting-server
614 gnus-last-posting-server)
615 ;; Just use the last value.
616 gnus-last-posting-server
618 "Posting method: " method-alist nil t
619 (cons (or gnus-last-posting-server "") 0))))
621 ;; Override normal method.
622 ((and gnus-post-method
623 (or (gnus-method-option-p group-method 'post)
624 (gnus-method-option-p group-method 'post-mail)))
626 ;; Perhaps this is a mail group?
627 ((and (not (gnus-member-of-valid 'post group))
628 (not (gnus-method-option-p group-method 'post-mail)))
630 ;; Use the normal select method.
631 (t gnus-select-method))))
633 (defun gnus-news-group-p (group &optional article)
634 "Return non-nil if GROUP (and ARTICLE) come from a news server."
635 (or (gnus-member-of-valid 'post group) ; Ordinary news group.
636 (and (gnus-member-of-valid 'post-mail group) ; Combined group.
637 (eq (gnus-request-type group article) 'news))))
639 (defun gnus-inews-news (&optional use-group-method)
640 "Send a news message.
642 If given a non-zero prefix and the group is a foreign group, this
643 function will attempt to use the foreign server to post the article.
645 If given an zero prefix, the user will be prompted for a posting
648 (unless (gnus-alive-p)
649 (error "Gnus is dead; you can't post anything."))
650 (or gnus-current-select-method
651 (setq gnus-current-select-method gnus-select-method))
652 (let* ((case-fold-search nil)
653 (reply gnus-article-reply)
656 (gnus-start-news-server) ;Use default server.
658 (goto-char (point-min))
659 (run-hooks 'news-inews-hook)
662 (gnus-message 5 "Posting to USENET...")
663 (setq post-result (funcall gnus-inews-article-function use-group-method))
665 ((eq post-result 'illegal)
669 (gnus-message 5 "Posting to USENET...done")
670 (set-buffer-modified-p nil)
671 ;; We mark the article as replied.
672 (when (gnus-buffer-exists-p (car-safe reply))
674 (set-buffer gnus-summary-buffer)
675 (gnus-summary-mark-article-as-replied (cdr reply)))))
677 ;; We cannot signal an error.
681 1 "Article rejected: %s"
683 (gnus-post-method gnus-newsgroup-name use-group-method t))))))
685 (let ((conf gnus-prev-winconf))
688 ;; Restore last window configuration.
689 (and conf (set-window-configuration conf))))))
691 (defun gnus-inews-narrow-to-headers ()
694 (goto-char (point-min))
695 (or (and (re-search-forward
696 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
699 (goto-char (point-min)))
701 (defun gnus-inews-send-mail-copy ()
702 ;; Mail the message if To, Bcc or Cc exists.
703 (let* ((types '("to" "bcc" "cc"))
705 (buffer (current-buffer))
709 (gnus-inews-narrow-to-headers)
712 (or (mail-fetch-field (car ty) nil t)
713 (setq types (delete (car ty) types)))
717 ;; We do not want to send mail.
719 (gnus-message 5 "Sending via mail...")
722 ;; We copy the article over to a temp buffer since we are
723 ;; going to modify it a little.
724 (nnheader-set-temp-buffer " *Gnus-mailing*")
725 (insert-buffer-substring buffer)
726 ;; We remove Fcc, because we don't want the mailer to see
728 (gnus-inews-narrow-to-headers)
729 (nnheader-remove-header "fcc")
731 ;; Insert the X-Courtesy-Message header.
732 (and (or (member "to" types)
735 (goto-char (point-max))
736 (insert "Posted-To: "
737 (mail-fetch-field "newsgroups") "\n")))
741 (if (and gnus-mail-courtesy-message
742 (or (member "to" types)
743 (member "cc" types)))
744 ;; We only want to insert the courtesy mail message if
745 ;; we use To or Cc; Bcc should not have one. Well, if
746 ;; both Bcc and To are present, it will get one
749 ;; Insert "courtesy" mail message.
750 (goto-char (point-min))
752 (concat "^" (regexp-quote mail-header-separator) "$"))
754 (insert gnus-mail-courtesy-message)))
757 (kill-buffer (current-buffer))
758 (gnus-message 5 "Sending via mail...done"))))))
760 (defun gnus-inews-remove-headers-after-mail ()
763 (let ((case-fold-search t))
764 (gnus-inews-narrow-to-headers)
765 ;; Remove Bcc completely.
766 (nnheader-remove-header "bcc")
767 ;; We transform To and Cc headers to avoid re-mailing if the user
768 ;; accidentally (or purposefully) leans on the `C-c C-c' keys
769 ;; and the news server rejects the posting.
770 (while (re-search-forward "^\\(to\\|[bcf]cc\\|cc\\):" nil t)
775 (defun gnus-inews-dex-headers ()
776 "Remove \"X-\" prefixes from To and Cc headers."
779 (let ((case-fold-search t))
780 (nnheader-narrow-to-headers)
781 (while (re-search-forward "^X-\\(to\\|[bcf]cc\\|cc\\):" nil t)
786 (defun gnus-inews-remove-empty-headers ()
787 "Remove empty headers from news and mail.
788 The buffer should be narrowed to the headers before this function is
791 (goto-char (point-min))
792 (while (re-search-forward "^[^ \t:]+:\\([ \t]*\n\\)+[^ \t]" nil t)
793 (delete-region (match-beginning 0) (1- (match-end 0)))
794 (beginning-of-line))))
796 (defun gnus-inews-check-post ()
797 "Check whether the post looks ok."
799 (not gnus-check-before-posting)
801 ;; We narrow to the headers and check them first.
804 (gnus-inews-narrow-to-headers)
806 ;; Check for commands in Subject.
808 (gnus-check-before-posting 'subject-cmsg)
810 (if (string-match "^cmsg " (mail-fetch-field "subject"))
812 "The control code \"cmsg \" is in the subject. Really post? ")
814 ;; Check for multiple identical headers.
815 (or (gnus-check-before-posting 'multiple-headers)
818 (while (and (not found)
819 (re-search-forward "^[^ \t:]+: " nil t))
821 (or (re-search-forward
822 (concat "^" (setq found
825 (- (match-end 0) 2))))
830 (format "Multiple %s headers. Really post? " found))
832 ;; Check for Version and Sendsys.
833 (or (gnus-check-before-posting 'sendsys)
835 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
837 (format "The article contains a %s command. Really post? "
838 (buffer-substring (match-beginning 0)
839 (1- (match-end 0)))))
841 ;; Check for Approved.
842 (or (gnus-check-before-posting 'approved)
844 (if (re-search-forward "^Approved:" nil t)
846 "The article contains an Approved header. Really post? ")
848 ;; Check whether a Followup-To has redirected the newsgroup.
850 (gnus-check-before-posting 'redirected-followup)
851 (not gnus-newsgroup-followup)
853 (let ((followups (gnus-tokenize-header
854 (mail-fetch-field "Newsgroups")))
855 (newsgroups (gnus-tokenize-header
856 (car gnus-newsgroup-followup))))
857 (while (and followups
858 (member (car followups) newsgroups))
859 (setq followups (cdr followups)))
863 "Followup redirected from original newsgroups. Really post? "
865 ;; Check the Message-ID header.
866 (or (gnus-check-before-posting 'message-id)
868 (let* ((case-fold-search t)
869 (message-id (mail-fetch-field "message-id")))
871 (and (string-match "@" message-id)
872 (string-match "@[^\\.]*\\." message-id))
875 "The Message-ID looks strange: \"%s\". Really post? "
877 ;; Check whether any headers are empty.
878 (or (gnus-check-before-posting 'empty-headers)
881 (goto-char (point-min))
882 (while (and post (not (eobp)))
883 (when (looking-at "\\([^ :]+\\):[ \t]\n[^ \t]")
887 "The %s header is empty. Really post? "
891 ;; Check the From header.
893 (gnus-check-before-posting 'from)
895 (let* ((case-fold-search t)
896 (from (mail-fetch-field "from")))
899 (gnus-y-or-n-p "There is no From line. Really post? "))
900 ((not (string-match "@[^\\.]*\\." from))
903 "The address looks strange: \"%s\". Really post? " from)))
904 ((string-match "(.*).*(.*)" from)
907 "The From header looks strange: \"%s\". Really post? "
909 ((string-match "<[^>]+> *$" from)
910 (let ((name (substring from 0 (match-beginning 0))))
912 (string-match "^ *\"[^\"]*\" *$" name)
913 (not (string-match "[][.!()<>@,;:\\]" name))
916 "The From header name has bogus characters. Really post? "
920 ;; Check for long lines.
921 (or (gnus-check-before-posting 'long-lines)
923 (goto-char (point-min))
925 (concat "^" (regexp-quote mail-header-separator) "$"))
929 (< (current-column) 80))
930 (zerop (forward-line 1))))
934 "You have lines longer than 79 characters. Really post? "))))
935 ;; Check whether the article is empty.
936 (or (gnus-check-before-posting 'empty)
938 (goto-char (point-min))
940 (concat "^" (regexp-quote mail-header-separator) "$"))
942 (or (re-search-forward "[^ \n\t]" nil t)
943 (gnus-y-or-n-p "Empty article. Really post?"))))
944 ;; Check for control characters.
945 (or (gnus-check-before-posting 'control-chars)
947 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
949 "The article contains control characters. Really post? ")
951 ;; Check excessive size.
952 (or (gnus-check-before-posting 'size)
953 (if (> (buffer-size) 60000)
955 (format "The article is %d octets long. Really post? "
958 ;; Use the (size . checksum) variable to see whether the
959 ;; article is empty or has only quoted text.
961 (gnus-check-before-posting 'new-text)
962 (not gnus-article-check-size)
963 (if (and (= (buffer-size) (car gnus-article-check-size))
964 (= (gnus-article-checksum) (cdr gnus-article-check-size)))
966 "It looks like there's no new text in your article. Really post? ")
968 ;; Check the length of the signature.
969 (or (gnus-check-before-posting 'signature)
971 (goto-char (point-max))
972 (if (not (re-search-backward gnus-signature-separator nil t))
974 (if (> (count-lines (point) (point-max)) 5)
977 "Your .sig is %d lines; it should be max 4. Really post? "
978 (count-lines (point) (point-max))))
981 (defun gnus-tokenize-header (header &optional separator)
982 "Split HEADER into a list of header elements.
983 \",\" is used as the separator."
985 (separator (or separator ","))
987 (format "[ \t]*\\([^%s]+\\)?\\(%s\\|\\'\\)" separator separator))
989 (while (and (string-match regexp header beg)
990 (< beg (length header)))
991 (when (match-beginning 1)
992 (push (match-string 1 header) elems))
993 (setq beg (match-end 0)))
996 (defun gnus-article-checksum ()
1000 (setq sum (logxor sum (following-char)))
1004 ;; Returns non-nil if this type is not to be checked.
1005 (defun gnus-check-before-posting (type)
1007 (or (not gnus-check-before-posting)
1008 (if (listp gnus-check-before-posting)
1009 (memq type gnus-check-before-posting)
1012 (defun gnus-cancel-news ()
1013 "Cancel an article you posted."
1015 (if (or gnus-expert-user
1016 (gnus-yes-or-no-p "Do you really want to cancel this article? "))
1021 (or (gnus-news-group-p gnus-newsgroup-name)
1022 (error "This backend does not support canceling"))
1024 ;; Get header info. from original article.
1026 (gnus-article-show-all-headers)
1027 (goto-char (point-min))
1028 (search-forward "\n\n" nil 'move)
1029 (narrow-to-region (point-min) (point))
1030 (setq from (mail-fetch-field "from"))
1031 (setq newsgroups (mail-fetch-field "newsgroups"))
1032 (setq message-id (mail-fetch-field "message-id"))
1033 (setq distribution (mail-fetch-field "distribution")))
1034 ;; Verify if the article is absolutely user's by comparing
1035 ;; user id with value of its From: field.
1038 (downcase (gnus-mail-strip-quoted-names from))
1039 (downcase (gnus-mail-strip-quoted-names
1040 (gnus-inews-user-name)))))
1042 (ding) (gnus-message 3 "This article is not yours.")
1044 ;; Make control article.
1045 (set-buffer (get-buffer-create " *Gnus-canceling*"))
1046 (buffer-disable-undo (current-buffer))
1048 (insert "Newsgroups: " newsgroups "\n"
1049 "From: " (gnus-inews-user-name) "\n"
1050 "Subject: cancel " message-id "\n"
1051 "Control: cancel " message-id "\n"
1053 (concat "Distribution: " distribution "\n")
1055 mail-header-separator "\n"
1056 "This is a cancel message from " from ".\n")
1057 ;; Send the control article to NNTP server.
1058 (gnus-message 5 "Canceling your article...")
1060 (if (funcall gnus-inews-article-function)
1061 (gnus-message 5 "Canceling your article...done")
1064 (gnus-message 1 "Cancel failed; %s"
1065 (gnus-status-message gnus-newsgroup-name))
1068 ;; Kill the article buffer.
1069 (kill-buffer (current-buffer))))))))
1071 (defun gnus-inews-remove-signature ()
1072 "Remove the signature from the text between point and mark.
1073 The text will also be indented the normal way.
1074 This function can be used in `mail-citation-hook', for instance."
1076 (let ((start (point))
1078 (if (not (re-search-forward gnus-signature-separator (mark t) t))
1079 ;; No signature here, so we just indent the cited text.
1080 (mail-indent-citation)
1081 ;; Find the last non-empty line.
1083 (while (looking-at "[ \t]*$")
1086 (setq mark (set-marker (make-marker) (point)))
1088 (mail-indent-citation)
1089 ;; Enable undoing the deletion.
1091 (delete-region mark (mark t))
1092 (set-marker mark nil)))))
1096 ;; Dummy to avoid byte-compile warning.
1097 (defvar nnspool-rejected-article-hook)
1099 (defun gnus-inews-article (&optional use-group-method)
1100 "Post an article in current buffer using NNTP protocol."
1101 (let ((artbuf (current-buffer))
1104 (goto-char (point-max))
1105 ;; Require a newline at the end of the buffer since inews may
1106 ;; append a .signature.
1107 (or (= (preceding-char) ?\n)
1109 ;; Prepare article headers. All message body such as signature
1110 ;; must be inserted before Lines: field is prepared.
1112 (gnus-inews-narrow-to-headers)
1113 ;; Fix some headers.
1114 (gnus-inews-cleanup-headers)
1115 ;; Remove some headers.
1116 (gnus-inews-remove-headers)
1117 ;; Insert some headers.
1118 (gnus-inews-insert-headers)
1119 ;; Let the user do all of the above.
1120 (run-hooks 'gnus-inews-article-header-hook)
1121 ;; Copy the Gcc header, if any.
1122 (setq gcc (mail-fetch-field "gcc"))
1124 ;; Check whether the article is a good Net Citizen.
1125 (if (not (gnus-inews-check-post))
1128 ;; We fudge a hook for nnspool.
1129 (setq nnspool-rejected-article-hook
1133 (set-buffer ,(buffer-name))
1134 (gnus-associate-buffer-with-draft nil 'silent))
1138 1 "Couldn't enter rejected article into draft group"))))))
1140 ;; Looks ok, so we do the nasty.
1142 ;; This hook may insert a signature.
1144 (goto-char (point-min))
1145 (let ((gnus-newsgroup-name (or (mail-fetch-field "newsgroups")
1146 gnus-newsgroup-name)))
1147 (run-hooks 'gnus-prepare-article-hook)))
1148 ;; Send off copies using mail, if that is wanted.
1149 (gnus-inews-send-mail-copy)
1150 ;; Remove more headers.
1151 (gnus-inews-remove-headers-after-mail)
1152 ;; Copy the article over to a temp buffer.
1153 (nnheader-set-temp-buffer " *Gnus-posting*")
1154 (insert-buffer-substring artbuf)
1155 ;; Remove the header separator.
1156 (goto-char (point-min))
1158 (concat "^" (regexp-quote mail-header-separator) "$"))
1159 (replace-match "" t t)
1160 ;; Remove X- prefixes to headers.
1161 (gnus-inews-dex-headers)
1162 ;; Run final inews hooks. This hook may do FCC.
1163 ;; The article must be saved before being posted because
1164 ;; `gnus-request-post' modifies the buffer.
1165 (run-hooks 'gnus-inews-article-hook)
1166 ;; Copy the article over to some group, possibly.
1167 (and gcc (gnus-inews-do-gcc gcc))
1168 ;; Post the article.
1169 (setq result (gnus-request-post
1170 (gnus-post-method gnus-newsgroup-name use-group-method)))
1171 (kill-buffer (current-buffer)))
1172 (run-hooks 'gnus-message-sent-hook)
1173 ;; If the posting was unsuccessful (that it, it was rejected) we
1174 ;; put it into the draft group.
1175 (or result (gnus-associate-buffer-with-draft))
1178 (defun gnus-inews-cleanup-headers ()
1179 ;; Remove empty lines in the header.
1181 (gnus-inews-narrow-to-headers)
1182 (while (re-search-forward "^[ \t]*\n" nil t)
1183 (replace-match "" t t)))
1185 ;; Correct newsgroups field: change sequence of spaces to comma and
1186 ;; eliminate spaces around commas. Eliminate imbedded line breaks.
1187 (goto-char (point-min))
1188 (if (re-search-forward "^Newsgroups: +" nil t)
1192 (if (re-search-forward "^[^ \t]" nil t)
1196 (goto-char (point-min))
1197 (while (re-search-forward "\n[ \t]+" nil t)
1198 (replace-match " " t t)) ;No line breaks (too confusing)
1199 (goto-char (point-min))
1200 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
1201 (replace-match "," t t))
1202 (goto-char (point-min))
1203 ;; Remove a trailing comma.
1204 (if (re-search-forward ",$" nil t)
1205 (replace-match "" t t))))
1207 ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
1208 ;; Help save the the world!
1211 (let ((newsgroups (mail-fetch-field "newsgroups"))
1212 (followup-to (mail-fetch-field "followup-to"))
1215 (string-match "," newsgroups) (not followup-to))
1217 (while (string-match "," newsgroups)
1219 (cons (list (substring newsgroups 0 (match-beginning 0)))
1221 (setq newsgroups (substring newsgroups (match-end 0))))
1222 (setq groups (nreverse (cons (list newsgroups) groups)))
1224 (setq to (completing-read
1225 "Followups to: (default all groups) " groups))
1226 (if (> (length to) 0)
1228 (goto-char (point-min))
1229 (insert "Followup-To: " to "\n")))))))
1231 ;; Cleanup Followup-To.
1232 (goto-char (point-min))
1233 (if (search-forward-regexp "^Followup-To: +" nil t)
1237 (if (re-search-forward "^[^ \t]" nil 'end)
1240 (goto-char (point-min))
1241 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
1242 (goto-char (point-min))
1243 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ","))))
1245 (defun gnus-inews-remove-headers ()
1246 (let ((case-fold-search t)
1247 (headers gnus-removable-headers))
1248 ;; Remove toxic headers.
1250 (goto-char (point-min))
1251 (and (re-search-forward
1252 (concat "^" (downcase (format "%s" (car headers))))
1254 (delete-region (progn (beginning-of-line) (point))
1255 (progn (forward-line 1) (point))))
1256 (setq headers (cdr headers)))))
1258 ;;; Since the X-Newsreader/X-Mailer are ``vanity'' headers, they might
1259 ;;; as well include the Emacs version as well.
1260 ;;; The following function works with later GNU Emacs, and XEmacs.
1261 (defun gnus-extended-version ()
1262 "Stringified Gnus version and Emacs version"
1268 ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
1269 (concat "Emacs " (substring emacs-version
1272 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)" emacs-version)
1273 (concat (substring emacs-version
1276 (format " %d.%d" emacs-major-version emacs-minor-version)))
1277 (t emacs-version))))
1279 (defun gnus-inews-insert-headers (&optional headers)
1280 "Prepare article headers.
1281 Headers already prepared in the buffer are not modified.
1282 Headers in `gnus-required-headers' will be generated."
1283 (let* ((Date (gnus-inews-date))
1284 (Message-ID (gnus-inews-message-id))
1285 (Organization (gnus-inews-organization))
1286 (From (gnus-inews-user-name))
1287 (Path (gnus-inews-path))
1290 (In-Reply-To (gnus-inews-in-reply-to))
1292 (Distribution (gnus-inews-distribution))
1293 (Lines (gnus-inews-lines))
1294 (X-Newsreader (gnus-extended-version))
1295 (X-Mailer X-Newsreader)
1296 (Expires (gnus-inews-expires))
1297 (headers (or headers gnus-required-headers))
1298 (case-fold-search t)
1300 ;; First we remove any old generated headers.
1301 (let ((headers gnus-deletable-headers))
1303 (goto-char (point-min))
1304 (and (re-search-forward
1305 (concat "^" (symbol-name (car headers)) ": *") nil t)
1306 (get-text-property (1+ (match-beginning 0)) 'gnus-deletable)
1308 (setq headers (cdr headers))))
1309 ;; If there are References, and no "Re: ", then the thread has
1310 ;; changed name. See Son-of-1036.
1311 (if (and (mail-fetch-field "references")
1312 (get-buffer gnus-article-buffer))
1313 (let ((psubject (gnus-simplify-subject-re
1314 (mail-fetch-field "subject"))))
1315 (or (and psubject gnus-reply-subject
1316 (string= (gnus-simplify-subject-re gnus-reply-subject)
1319 (string-match "@" Message-ID)
1321 (concat (substring Message-ID 0 (match-beginning 0))
1323 (substring Message-ID (match-beginning 0))))))))
1324 ;; Go through all the required headers and see if they are in the
1325 ;; articles already. If they are not, or are empty, they are
1326 ;; inserted automatically - except for Subject, Newsgroups and
1329 (goto-char (point-min))
1330 (setq elem (pop headers))
1332 (setq header (car elem))
1334 (when (or (not (re-search-forward
1335 (concat "^" (downcase (symbol-name header)) ":") nil t))
1337 ;; The header was found. We insert a space after the
1338 ;; colon, if there is none.
1339 (if (/= (following-char) ? ) (insert " "))
1340 ;; Find out whether the header is empty...
1341 (looking-at "[ \t]*$")))
1342 ;; So we find out what value we should insert.
1345 ((and (consp elem) (eq (car elem) 'optional))
1346 ;; This is an optional header. If the cdr of this
1347 ;; is something that is nil, then we do not insert
1349 (setq header (cdr elem))
1350 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
1351 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
1353 ;; The element is a cons. Either the cdr is a
1354 ;; string to be inserted verbatim, or it is a
1355 ;; function, and we insert the value returned from
1357 (or (and (stringp (cdr elem)) (cdr elem))
1358 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
1359 ((and (boundp header) (symbol-value header))
1360 ;; The element is a symbol. We insert the value
1361 ;; of this symbol, if any.
1362 (symbol-value header))
1364 ;; We couldn't generate a value for this header,
1365 ;; so we just ask the user.
1366 (read-from-minibuffer
1367 (format "Empty header for %s; enter value: " header)))))
1368 ;; Finally insert the header.
1370 (not (equal value "")))
1374 ;; This header didn't exist, so we insert it.
1375 (goto-char (point-max))
1376 (insert (symbol-name header) ": " value "\n")
1378 ;; The value of this header was empty, so we clear
1379 ;; totally and insert the new value.
1380 (delete-region (point) (gnus-point-at-eol))
1382 ;; Add the deletable property to the headers that require it.
1383 (and (memq header gnus-deletable-headers)
1384 (progn (beginning-of-line) (looking-at "[^:]+: "))
1385 (add-text-properties
1386 (point) (match-end 0)
1387 '(gnus-deletable t face italic) (current-buffer)))))))
1388 ;; Insert new Sender if the From is strange.
1389 (let ((from (mail-fetch-field "from"))
1390 (sender (mail-fetch-field "sender"))
1391 (secure-sender (gnus-inews-real-user-address)))
1393 (not (gnus-check-before-posting 'sender))
1395 (downcase (cadr (gnus-extract-address-components from)))
1396 (downcase (gnus-inews-real-user-address))))
1401 (cadr (gnus-extract-address-components sender)))
1402 (downcase secure-sender)))))
1403 (goto-char (point-min))
1404 ;; Rename any old Sender headers to Original-Sender.
1405 (when (re-search-forward "^Sender:" nil t)
1407 (insert "Original-")
1408 (beginning-of-line))
1409 (insert "Sender: " secure-sender "\n")))))
1411 (defun gnus-inews-insert-signature ()
1412 "Insert a signature file.
1413 If `gnus-signature-function' is bound and returns a string, this
1414 string is used instead of the variable `gnus-signature-file'.
1415 In either case, if the string is a file name, this file is
1416 inserted. If the string is not a file name, the string itself is
1419 If you never want any signature inserted, set both of these variables to
1423 (or (and gnus-signature-function
1424 (funcall gnus-signature-function gnus-newsgroup-name))
1425 gnus-signature-file)))
1427 (or (file-exists-p signature)
1428 (string-match " " signature)
1430 "^/[^/]+/" (expand-file-name signature)))))
1432 (goto-char (point-max))
1433 (if (and mail-signature (search-backward "\n-- \n" nil t))
1435 ;; Delete any previous signatures.
1436 (if (search-backward "\n-- \n" nil t)
1437 (delete-region (point) (point-max)))
1438 (or (eolp) (insert "\n"))
1440 (if (file-exists-p signature)
1441 (insert-file-contents signature)
1443 (goto-char (point-max))
1444 (or (bolp) (insert "\n"))))))))
1446 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1447 (defun gnus-inews-insert-mime-headers ()
1448 (goto-char (point-min))
1449 (let ((mail-header-separator
1451 (goto-char (point-min))
1452 (if (and (search-forward (concat "\n" mail-header-separator "\n")
1454 (not (search-backward "\n\n" nil t)))
1455 mail-header-separator
1457 (or (mail-position-on-field "Mime-Version")
1459 (cond ((save-restriction
1461 (goto-char (point-min))
1462 (re-search-forward "[\200-\377]" nil t))
1463 (or (mail-position-on-field "Content-Type")
1464 (insert "text/plain; charset=ISO-8859-1"))
1465 (or (mail-position-on-field "Content-Transfer-Encoding")
1467 (t (or (mail-position-on-field "Content-Type")
1468 (insert "text/plain; charset=US-ASCII"))
1469 (or (mail-position-on-field "Content-Transfer-Encoding")
1470 (insert "7bit")))))))
1472 (defun gnus-inews-do-fcc ()
1473 "Process Fcc headers in the current buffer.
1474 Unless the first character of the field is `|', the article is saved
1475 to the specified file using the function specified by the variable
1476 gnus-author-copy-saver. The default function rmail-output saves in
1477 Unix mailbox format.
1479 If the first character is `|', the contents of the article is sent to
1480 a program specified by the rest of the value."
1481 (let ((case-fold-search t) ;Should ignore case.
1485 (nnheader-narrow-to-headers)
1486 (while (setq file (mail-fetch-field "fcc"))
1488 (nnheader-remove-header "fcc" nil t))
1489 ;; Process FCC operations.
1492 (setq file (pop list))
1493 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
1494 ;; Pipe the article to the program in question.
1495 (call-process-region (point-min) (point-max) shell-file-name
1496 nil nil nil "-c" (match-string 1 file))
1497 ;; Save the article.
1498 (setq file (expand-file-name file))
1499 (gnus-make-directory (file-name-directory file))
1500 (if (and gnus-author-copy-saver
1501 (not (eq gnus-author-copy-saver 'rmail-output)))
1502 (funcall gnus-author-copy-saver file)
1503 (if (and (file-readable-p file) (mail-file-babyl-p file))
1504 (gnus-output-to-rmail file)
1505 (let ((mail-use-rfc822 t))
1506 (rmail-output file 1 t t))))))))))
1508 (defun gnus-inews-path ()
1510 (let ((login-name (gnus-inews-login-name)))
1511 (cond ((null gnus-use-generic-path)
1512 (concat (nth 1 gnus-select-method) "!" login-name))
1513 ((stringp gnus-use-generic-path)
1514 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1515 (concat gnus-use-generic-path "!" login-name))
1518 (defun gnus-inews-user-name ()
1519 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1520 (let ((full-name (gnus-inews-full-name))
1521 (address (if (or gnus-user-login-name gnus-use-generic-from
1522 gnus-local-domain (getenv "DOMAINNAME"))
1523 (concat (gnus-inews-login-name) "@"
1524 (gnus-inews-domain-name gnus-use-generic-from))
1525 user-mail-address)))
1526 (or gnus-user-from-line
1528 ;; User's full name.
1529 (cond ((string-equal full-name "&") ;Unix hack.
1530 (concat " (" (user-login-name) ")"))
1531 ((string-match "[^ ]+@[^ ]+ +(.*)" address)
1534 (concat " (" full-name ")")))))))
1536 (defun gnus-inews-real-user-address ()
1537 "Return the \"real\" user address.
1538 This function tries to ignore all user modifications, and
1539 give as trustworthy answer as possible."
1540 (concat (user-login-name) "@" (system-name)))
1542 (defun gnus-inews-login-name ()
1543 "Return login name."
1544 (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1546 (defun gnus-inews-full-name ()
1547 "Return full user name."
1548 (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1550 (defun gnus-inews-domain-name (&optional genericfrom)
1551 "Return user's domain name.
1552 If optional argument GENERICFROM is a string, use it as the domain
1553 name; if it is non-nil, strip off local host name from the domain name.
1554 If the function `system-name' returns full internet name and the
1555 domain is undefined, the domain name is got from it."
1556 (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1557 (let* ((system-name (system-name))
1559 (or (if (stringp genericfrom) genericfrom)
1560 (getenv "DOMAINNAME")
1561 (and (boundp 'mail-host-address)
1564 ;; Function `system-name' may return full internet name.
1565 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1566 (if (string-match "\\.." system-name)
1567 ;; Some machines return "name.", and that's not
1569 (substring system-name (1- (match-end 0))))
1570 (read-string "Domain name (no host): ")))
1571 (host (or (if (string-match "\\." system-name)
1572 (substring system-name 0 (match-beginning 0)))
1574 (if (string-equal "." (substring domain 0 1))
1575 (setq domain (substring domain 1)))
1576 ;; Support GENERICFROM as same as standard Bnews system.
1577 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1578 (cond ((null genericfrom)
1579 (concat host "." domain))
1580 ;;((stringp genericfrom) genericfrom)
1582 (if (string-match "\\." (system-name))
1584 (if (string-match "@\\([^ ]+\\)\\($\\| \\)" user-mail-address)
1585 (substring user-mail-address
1586 (match-beginning 1) (match-end 1))
1589 (defun gnus-inews-full-address ()
1590 (let ((domain (gnus-inews-domain-name))
1591 (system (system-name))
1592 (case-fold-search t))
1593 (if (string-match "\\." system) system
1594 (if (string-match (concat "^" (regexp-quote system)) domain) domain
1595 (concat system "." domain)))))
1597 (defun gnus-inews-expires ()
1598 "Return an Expires header based on `gnus-article-expires'."
1599 (let ((current (current-time))
1600 (future (* 1.0 gnus-article-expires 60 60 24)))
1601 ;; Add the future to current.
1602 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
1603 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
1604 ;; Return the date in the future in UT.
1605 (timezone-make-date-arpa-standard
1606 (current-time-string current) (current-time-zone) '(0 "UT"))))
1608 (defun gnus-inews-distribution ()
1609 "Return the current Distribution header, if any."
1610 (when (and gnus-distribution-function
1611 (fboundp gnus-distribution-function))
1612 (funcall gnus-distribution-function (or gnus-newsgroup-name ""))))
1614 (defun gnus-inews-message-id ()
1615 "Generate unique Message-ID for user."
1616 ;; Message-ID should not contain a slash and should be terminated by
1617 ;; a number. I don't know the reason why it is so.
1618 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1620 (defvar gnus-unique-id-char nil)
1622 ;; If you ever change this function, make sure the new version
1623 ;; cannot generate IDs that the old version could.
1624 ;; You might for example insert a "." somewhere (not next to another dot
1625 ;; or string boundary), or modify the newsreader name to "Ding".
1626 (defun gnus-inews-unique-id ()
1627 ;; Don't use microseconds from (current-time), they may be unsupported.
1628 ;; Instead we use this randomly inited counter.
1629 (setq gnus-unique-id-char
1630 (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1631 ;; (current-time) returns 16-bit ints,
1632 ;; and 2^16*25 just fits into 4 digits i base 36.
1634 (let ((tm (if (fboundp 'current-time)
1635 (current-time) '(12191 46742 287898))))
1637 (if (memq system-type '(ms-dos emx vax-vms))
1638 (let ((user (downcase (gnus-inews-login-name))))
1639 (while (string-match "[^a-z0-9_]" user)
1640 (aset user (match-beginning 0) ?_))
1642 (gnus-number-base36 (user-uid) -1))
1643 (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1644 (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1645 ;; Append the newsreader name, because while the generated
1646 ;; ID is unique to this newsreader, other newsreaders might
1647 ;; otherwise generate the same ID via another algorithm.
1650 (defun gnus-inews-date ()
1651 "Current time string."
1652 (let ((now (current-time)))
1653 (timezone-make-date-arpa-standard
1654 (current-time-string now) (current-time-zone now))))
1656 (defun gnus-inews-organization ()
1657 "Return user's organization.
1658 The ORGANIZATION environment variable is used if defined.
1659 If not, the variable `gnus-local-organization' is used instead.
1660 If it is a function, the function will be called with the current
1661 newsgroup name as the argument.
1662 If this is a file name, the contents of this file will be used as the
1664 (let* ((organization
1665 (or (getenv "ORGANIZATION")
1666 (if gnus-local-organization
1667 (if (gnus-functionp gnus-local-organization)
1668 (funcall gnus-local-organization gnus-newsgroup-name)
1669 gnus-local-organization))
1670 gnus-organization-file
1671 "~/.organization")))
1672 (and (stringp organization)
1673 (> (length organization) 0)
1674 (or (file-exists-p organization)
1675 (string-match " " organization)
1676 (not (string-match "^/usr/lib/\\|^~/" organization)))
1678 (gnus-set-work-buffer)
1679 (if (file-exists-p organization)
1680 (insert-file-contents organization)
1681 (insert organization))
1682 (goto-char (point-min))
1683 (while (re-search-forward " *\n *" nil t)
1684 (replace-match " " t t))
1685 (buffer-substring (point-min) (point-max))))))
1687 (defun gnus-inews-lines ()
1688 "Count the number of lines and return numeric string."
1692 (goto-char (point-min))
1694 (concat "^" (regexp-quote mail-header-separator) "$"))
1696 (int-to-string (count-lines (point) (point-max))))))
1698 (defun gnus-inews-in-reply-to ()
1699 "Return the In-Reply-To header for this message."
1704 ;;; Gnus Mail Functions
1707 ;;; Mail reply commands of Gnus summary mode
1709 (defun gnus-summary-reply (yank &optional yank-articles)
1710 "Reply mail to news author.
1711 If prefix argument YANK is non-nil, original article is yanked automatically.
1712 Customize the variable gnus-mail-reply-method to use another mailer."
1714 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1715 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1716 (gnus-set-global-variables)
1717 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1718 (gnus-summary-select-article)
1719 (bury-buffer gnus-article-buffer)
1720 (gnus-mail-reply (or yank-articles (not (not yank)))))
1722 (defun gnus-summary-reply-with-original (n)
1723 "Reply mail to news author with original article.
1724 Customize the variable gnus-mail-reply-method to use another mailer."
1726 (gnus-summary-reply t (gnus-summary-work-articles n)))
1728 (defun gnus-summary-mail-forward (post)
1729 "Forward the current message to another user.
1730 Customize the variable gnus-mail-forward-method to use another mailer."
1732 (gnus-set-global-variables)
1733 (gnus-summary-select-article)
1734 (gnus-copy-article-buffer)
1736 (gnus-forward-using-post gnus-original-article-buffer)
1737 (gnus-mail-forward gnus-original-article-buffer)))
1739 (defun gnus-summary-resend-message (address)
1740 "Resend the current article to ADDRESS."
1741 (interactive "sResend message to: ")
1742 (gnus-summary-select-article)
1745 ;; We first set up a normal mail buffer.
1746 (nnheader-set-temp-buffer " *Gnus resend*")
1747 ;; This code from sendmail.el
1749 (let ((fill-prefix "\t")
1750 (address-start (point)))
1751 (insert address "\n")
1752 (fill-region-as-paragraph address-start (point-max)))
1753 (insert mail-header-separator "\n")
1754 ;; Insert our usual headers.
1755 (gnus-inews-narrow-to-headers)
1756 (gnus-inews-insert-headers '(From Date To))
1757 (goto-char (point-min))
1758 ;; Rename them all to "Resent-*".
1759 (while (re-search-forward "^[A-Za-z]" nil t)
1764 (delete-region (point) (point-max))
1766 ;; Insert the message to be resent.
1767 (insert-buffer-substring gnus-original-article-buffer)
1768 (goto-char (point-min))
1769 (search-forward "\n\n")
1771 (insert mail-header-separator)
1772 ;; Rename all old ("Also-")Resent headers.
1773 (while (re-search-backward "^\\(Also-\\)?Resent-" beg t)
1778 (kill-buffer (current-buffer)))))
1780 (defun gnus-summary-post-forward ()
1781 "Forward the current article to a newsgroup."
1783 (gnus-summary-mail-forward t))
1785 (defvar gnus-nastygram-message
1786 "The following article was inappropriately posted to %s.\n"
1787 "Format string to insert in nastygrams.
1788 The current group name will be inserted at \"%s\".")
1790 (defun gnus-summary-mail-nastygram (n)
1791 "Send a nastygram to the author of the current article."
1793 (if (or gnus-expert-user
1795 "Really send a nastygram to the author of the current article? "))
1796 (let ((group gnus-newsgroup-name))
1797 (gnus-summary-reply-with-original n)
1798 (set-buffer gnus-mail-buffer)
1799 (insert (format gnus-nastygram-message group))
1800 (gnus-mail-send-and-exit))))
1802 (defun gnus-summary-mail-other-window ()
1803 "Compose mail in other window.
1804 Customize the variable `gnus-mail-other-window-method' to use another
1807 (gnus-set-global-variables)
1809 ;; We might want to prompt here.
1810 (when (and gnus-interactive-post
1811 (not gnus-expert-user))
1812 (read-string "To: ")))
1813 (gnus-configure-windows 'summary-mail 'force))
1815 (defun gnus-new-mail (&optional to)
1817 (when (and gnus-interactive-post
1818 (not gnus-expert-user))
1819 (setq subject (read-string "Subject: ")))
1820 (pop-to-buffer gnus-mail-buffer)
1822 (gnus-mail-setup 'new to subject)
1823 (gnus-inews-insert-gcc)
1824 (gnus-inews-insert-archive-gcc)
1825 (run-hooks 'gnus-mail-hook)))
1827 (defun gnus-new-empty-mail ()
1828 "Create a new, virtually empty mail mode buffer."
1829 (pop-to-buffer gnus-mail-buffer)
1830 (gnus-mail-setup 'new "" ""))
1832 (defun gnus-mail-reply (&optional yank to-address followup)
1834 (set-buffer gnus-summary-buffer)
1835 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1836 (cur (cons (current-buffer) (cdr gnus-article-current)))
1837 (winconf (current-window-configuration))
1838 from subject date reply-to message-of to cc
1839 references message-id sender follow-to sendto elt new-cc new-to
1840 mct mctdo gnus-warning)
1841 (set-buffer (get-buffer-create gnus-mail-buffer))
1843 (if (and (buffer-modified-p)
1846 "Unsent message being composed; erase it? ")))
1850 (gnus-copy-article-buffer)
1852 (set-buffer gnus-article-copy)
1853 (nnheader-narrow-to-headers)
1855 ;; This is a regular reply.
1856 (if (gnus-functionp gnus-reply-to-function)
1857 (setq follow-to (funcall gnus-reply-to-function group)))
1858 ;; This is a followup.
1859 (if (gnus-functionp gnus-followup-to-function)
1862 (funcall gnus-followup-to-function group)))))
1863 (setq from (mail-fetch-field "from"))
1864 (setq date (or (mail-fetch-field "date")
1865 (mail-header-date gnus-current-headers)))
1866 (setq message-of (gnus-message-of from date))
1867 (setq sender (mail-fetch-field "sender"))
1868 (setq subject (or (mail-fetch-field "subject") "none"))
1869 ;; Remove any (buggy) Re:'s that are present and make a
1871 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1872 (setq subject (substring subject (match-end 0))))
1873 (setq subject (concat "Re: " subject))
1874 (setq to (mail-fetch-field "to"))
1875 (setq cc (mail-fetch-field "cc"))
1876 (setq mct (mail-fetch-field "mail-copies-to"))
1878 (unless (gnus-group-get-parameter group 'broken-reply-to)
1879 (mail-fetch-field "reply-to")))
1880 (setq references (mail-fetch-field "references"))
1881 (setq message-id (mail-fetch-field "message-id"))
1882 (when (and (setq gnus-warning (mail-fetch-field "gnus-warning"))
1883 (string-match "<[^>]+>" gnus-warning))
1884 (setq message-id (match-string 0 gnus-warning)))
1886 (setq mctdo (and mct (not (equal mct "never"))))
1887 (when (and mct (string= (downcase mct) "always"))
1888 (setq mct (or reply-to from)))
1890 (if (not (and followup (not to-address)))
1891 (setq new-to (or reply-to from)
1895 (gnus-mail-strip-quoted-names mct)
1896 (gnus-mail-strip-quoted-names
1899 (not (stringp follow-to)))
1901 (or follow-to new-to
1906 (gnus-set-work-buffer)
1907 (unless (equal mct "never")
1908 (insert (or reply-to from "")))
1910 (if (bolp) "" ", ") (or to "")
1911 (if (or (not mct) (not mctdo)) ""
1912 (concat (if (bolp) "" ", ") mct))
1913 (if cc (concat (if (bolp) "" ", ") cc) ""))
1914 ;; Remove addresses that match `rmail-dont-reply-to-names'.
1915 (insert (prog1 (rmail-dont-reply-to (buffer-string))
1917 (goto-char (point-min))
1921 (cons (gnus-mail-strip-quoted-names addr) addr))
1922 (nreverse (gnus-mail-parse-comma-list))))
1925 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
1926 (setq new-to (cdr (pop ccalist)))
1929 (lambda (addr) (cdr addr))
1933 (setq news-reply-yank-from (or from "(nobody)"))
1934 (setq news-reply-yank-message-id
1935 (or message-id "(unknown Message-ID)"))
1937 ;; Gather the "to" addresses out of the follow-to list and remove
1939 (if (and follow-to (listp follow-to))
1940 (while (setq elt (assoc "To" follow-to))
1941 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1942 (setq follow-to (delq elt follow-to))))
1945 (if followup 'followup 'reply)
1947 (if (and follow-to (not (stringp follow-to))) sendto
1948 (or follow-to new-to sender "")))
1950 (if (zerop (length new-cc)) nil new-cc)
1953 (make-local-variable 'gnus-article-reply)
1954 (setq gnus-article-reply cur)
1955 (make-local-variable 'gnus-prev-winconf)
1956 (setq gnus-prev-winconf winconf)
1957 (make-local-variable 'gnus-reply-subject)
1958 (setq gnus-reply-subject subject)
1959 (make-local-variable 'gnus-in-reply-to)
1960 (setq gnus-in-reply-to message-of)
1962 (auto-save-mode auto-save-default)
1963 (gnus-inews-insert-gcc)
1964 (gnus-inews-insert-archive-gcc group)
1966 (when (and follow-to (listp follow-to))
1968 (gnus-inews-narrow-to-headers)
1969 (re-search-forward "^To:" nil t)
1973 ;; Insert the rest of the Follow-To headers.
1975 (goto-char (point-min))
1976 (if (not (re-search-forward
1977 (concat "^" (caar follow-to) ": *") nil t))
1980 (insert (caar follow-to) ": " (cdar follow-to) "\n"))
1983 (insert (cdar follow-to)))
1984 (setq follow-to (cdr follow-to)))
1986 (nnheader-insert-references references message-id)
1988 ;; Now the headers should be ok, so we do the yanking.
1989 (goto-char (point-min))
1991 (concat "^" (regexp-quote mail-header-separator) "$"))
1994 (gnus-configure-windows 'reply 'force)
1995 (let ((last (point))
1997 (if (not (listp yank))
1999 ;; Just a single article being yanked.
2001 (mail-yank-original nil))
2002 (or mail-yank-hooks mail-citation-hook
2003 (run-hooks 'news-reply-header-hook)))
2005 (save-window-excursion
2006 (set-buffer gnus-summary-buffer)
2007 (gnus-summary-select-article nil nil nil (car yank))
2008 (gnus-summary-remove-process-mark (car yank)))
2011 (gnus-copy-article-buffer)
2012 (mail-yank-original nil)
2014 (narrow-to-region (point-min) (point))
2015 (goto-char (mark t))
2016 (let ((news-reply-yank-from
2018 (set-buffer gnus-article-buffer)
2019 (or (mail-fetch-field "from") "(nobody)")))
2020 (news-reply-yank-message-id
2022 (set-buffer gnus-article-buffer)
2023 (or (mail-fetch-field "message-id")
2024 "(unknown Message-ID)"))))
2025 (or mail-yank-hooks mail-citation-hook
2026 (run-hooks 'news-reply-header-hook))
2027 (setq end (point-max)))))
2029 (setq yank (cdr yank))))
2032 (gnus-configure-windows 'reply-yank 'force))
2033 (run-hooks 'gnus-mail-hook)
2034 ;; Mark this buffer as unchanged.
2035 (set-buffer-modified-p nil)))))
2037 (defun gnus-mail-parse-comma-list ()
2040 (skip-chars-forward " ")
2043 (skip-chars-forward "^,")
2048 (narrow-to-region beg (point))
2051 (while (search-forward "\"" nil t)
2053 (if (zerop i) 2 i)) 2)))))
2054 (skip-chars-forward ",")
2055 (skip-chars-forward "^,"))
2056 (skip-chars-backward " ")
2058 (cons (buffer-substring beg (point))
2060 (skip-chars-forward "^,")
2061 (skip-chars-forward ", "))
2064 (defun gnus-new-news (&optional group inhibit-prompt)
2065 "Set up a *Post Gnus* buffer that points to GROUP.
2066 If INHIBIT-PROMPT, never prompt for a Subject."
2067 (let ((winconf (current-window-configuration))
2069 (when (and gnus-interactive-post
2070 (not inhibit-prompt)
2071 (not gnus-expert-user))
2072 (setq subject (read-string "Subject: ")))
2073 (pop-to-buffer gnus-post-news-buffer)
2076 ;; Let posting styles be configured.
2077 (gnus-configure-posting-styles)
2078 (news-setup nil subject nil (and group (gnus-group-real-name group)) nil)
2079 ;; Associate this buffer with the draft group.
2080 (gnus-enter-buffer-into-draft)
2081 (goto-char (point-min))
2083 (unless (re-search-forward
2084 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2085 (goto-char (point-max)))
2088 (gnus-inews-insert-bfcc)
2089 (gnus-inews-insert-gcc)
2090 (gnus-inews-insert-archive-gcc group)
2091 (gnus-inews-insert-signature)
2092 (and gnus-post-prepare-function
2093 (gnus-functionp gnus-post-prepare-function)
2094 (funcall gnus-post-prepare-function group))
2095 (run-hooks 'gnus-post-prepare-hook)
2096 (gnus-inews-set-point)
2097 (make-local-variable 'gnus-prev-winconf)
2098 (setq gnus-prev-winconf winconf)
2099 (gnus-inews-modify-mail-mode-map)
2100 (local-set-key "\C-c\C-c" 'gnus-inews-news)))
2102 (defun gnus-news-followup (&optional yank group)
2104 (set-buffer gnus-summary-buffer)
2105 (if (not (or (not gnus-novice-user)
2108 "Are you sure you want to post to all of USENET? ")))
2110 (let ((group (gnus-group-real-name (or group gnus-newsgroup-name)))
2111 (cur (cons (current-buffer) (cdr gnus-article-current)))
2112 (winconf (current-window-configuration))
2113 from subject date reply-to message-of
2114 references message-id sender follow-to sendto elt
2115 followup-to distribution newsgroups gnus-warning)
2116 (set-buffer (get-buffer-create gnus-post-news-buffer))
2118 ;; Associate this buffer with the draft group.
2119 (gnus-enter-buffer-into-draft)
2120 (if (and (buffer-modified-p)
2123 "Unsent message being composed; erase it? ")))
2127 (gnus-copy-article-buffer)
2129 (set-buffer gnus-article-copy)
2130 (nnheader-narrow-to-headers)
2131 (if (gnus-functionp gnus-followup-to-function)
2134 (funcall gnus-followup-to-function group))))
2135 (setq from (mail-fetch-field "from"))
2136 (setq date (or (mail-fetch-field "date")
2137 (mail-header-date gnus-current-headers)))
2138 (setq message-of (gnus-message-of from date))
2139 (setq subject (or (mail-fetch-field "subject") "none"))
2140 ;; Remove any (buggy) Re:'s that are present and make a
2142 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
2143 (setq subject (substring subject (match-end 0))))
2144 (setq subject (concat "Re: " subject))
2145 (setq references (mail-fetch-field "references"))
2146 (setq message-id (mail-fetch-field "message-id"))
2147 (when (and (setq gnus-warning (mail-fetch-field "gnus-warning"))
2148 (string-match "<[^>]+>" gnus-warning))
2149 (setq message-id (match-string 0 gnus-warning)))
2150 (setq followup-to (mail-fetch-field "followup-to"))
2151 (setq newsgroups (mail-fetch-field "newsgroups"))
2152 (setq distribution (mail-fetch-field "distribution"))
2153 ;; Remove bogus distribution.
2154 (and (stringp distribution)
2155 (string-match "world" distribution)
2156 (setq distribution nil))
2159 (setq news-reply-yank-from (or from "(nobody)"))
2160 (setq news-reply-yank-message-id
2161 (or message-id "(unknown Message-ID)"))
2163 ;; Gather the "to" addresses out of the follow-to list and remove
2165 (if (and follow-to (listp follow-to))
2166 (while (setq elt (assoc "Newsgroups" follow-to))
2167 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
2168 (setq follow-to (delq elt follow-to))))
2170 ;; Let posting styles be configured.
2171 (gnus-configure-posting-styles)
2177 gnus-use-followup-to
2178 (or (not (eq gnus-use-followup-to 'ask))
2179 (equal followup-to newsgroups)
2181 (format "Use Followup-To %s? " followup-to)))
2183 newsgroups group "")
2186 (make-local-variable 'gnus-article-reply)
2187 (setq gnus-article-reply cur)
2188 (make-local-variable 'gnus-prev-winconf)
2189 (setq gnus-prev-winconf winconf)
2190 (make-local-variable 'gnus-reply-subject)
2191 (setq gnus-reply-subject (mail-header-subject gnus-current-headers))
2192 (make-local-variable 'gnus-in-reply-to)
2193 (setq gnus-in-reply-to message-of)
2194 (when (and followup-to newsgroups)
2195 (make-local-variable 'gnus-newsgroup-followup)
2196 (setq gnus-newsgroup-followup
2197 (cons newsgroups followup-to)))
2199 (gnus-inews-insert-signature)
2201 (and gnus-post-prepare-function
2202 (gnus-functionp gnus-post-prepare-function)
2203 (funcall gnus-post-prepare-function group))
2204 (run-hooks 'gnus-post-prepare-hook)
2206 (auto-save-mode auto-save-default)
2207 (gnus-inews-modify-mail-mode-map)
2208 (local-set-key "\C-c\C-c" 'gnus-inews-news)
2210 (if (and follow-to (listp follow-to))
2212 (goto-char (point-min))
2213 (and (re-search-forward "^Newsgroups:" nil t)
2216 (insert (caar follow-to) ": " (cdar follow-to) "\n")
2217 (setq follow-to (cdr follow-to)))))
2219 ;; If a distribution existed, we use it.
2222 (mail-position-on-field "Distribution")
2223 (insert distribution)))
2225 (nnheader-insert-references references message-id)
2227 ;; Handle `gnus-auto-mail-to-author'.
2228 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
2229 ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
2230 (let ((to (if (if (eq gnus-auto-mail-to-author 'ask)
2231 (y-or-n-p "Also send mail to author? ")
2232 gnus-auto-mail-to-author)
2234 (set-buffer gnus-article-copy)
2235 (unless (gnus-group-get-parameter
2236 group 'broken-reply-to)
2237 (gnus-fetch-field "reply-to")))
2239 (x-mail (save-excursion
2240 (set-buffer gnus-article-copy)
2241 (gnus-fetch-field "x-mail-copy-to"))))
2242 ;; Deny sending copy if there's a negative X-Mail-Copy-To
2245 (if (and (string= x-mail "never")
2246 (not (eq gnus-auto-mail-to-author 'force)))
2249 ;; Insert a To or Cc header.
2251 (if (mail-fetch-field "To")
2254 (insert "Cc: " to "\n"))
2255 (mail-position-on-field "To")
2258 (gnus-inews-insert-bfcc)
2259 (gnus-inews-insert-gcc)
2260 (gnus-inews-insert-archive-gcc group)
2262 ;; Now the headers should be ok, so we do the yanking.
2263 (goto-char (point-min))
2265 (concat "^" (regexp-quote mail-header-separator) "$"))
2269 (gnus-configure-windows 'followup 'force)
2272 (let ((last (point))
2274 (if (not (listp yank))
2277 (mail-yank-original nil))
2278 (or mail-yank-hooks mail-citation-hook
2279 (run-hooks 'news-reply-header-hook)))
2281 (save-window-excursion
2282 (set-buffer gnus-summary-buffer)
2283 (gnus-summary-select-article nil nil nil (car yank))
2284 (gnus-summary-remove-process-mark (car yank)))
2286 (gnus-copy-article-buffer)
2287 (mail-yank-original nil)
2289 (or mail-yank-hooks mail-citation-hook
2290 (run-hooks 'news-reply-header-hook))
2292 (setq yank (cdr yank))))
2294 (gnus-configure-windows 'followup-yank 'force))
2296 (make-local-variable 'gnus-article-check-size)
2297 (setq gnus-article-check-size
2298 (cons (buffer-size) (gnus-article-checksum)))
2299 (gnus-inews-set-point))))))
2301 (defun gnus-message-of (from date)
2302 "Take a FROM and a DATE and return an IN-REPLY-TO."
2305 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2306 (concat (if stop-pos (substring from 0 stop-pos) from)
2308 (if (or (not date) (string= date ""))
2309 "(unknown date)" date)))))
2311 (defun gnus-mail-yank-original ()
2314 (mail-yank-original nil))
2315 (or mail-yank-hooks mail-citation-hook
2316 (run-hooks 'news-reply-header-hook)))
2318 (defun gnus-mail-send-and-exit (&optional dont-send)
2319 "Send the current mail and return to Gnus."
2321 (let* ((reply gnus-article-reply)
2322 (winconf gnus-prev-winconf)
2323 (address-group gnus-add-to-address)
2324 (to-address (and address-group
2325 (mail-fetch-field "to"))))
2326 (setq gnus-add-to-address nil)
2327 (let ((buffer-file-name nil))
2328 (or dont-send (gnus-mail-send)))
2330 (when (gnus-alive-p)
2331 ;; This mail group doesn't have a `to-list', so we add one
2334 (gnus-group-add-parameter address-group (cons 'to-list to-address)))
2335 (when (and (gnus-buffer-exists-p (car reply))
2338 (set-buffer (car reply))
2339 (gnus-summary-mark-article-as-replied (cdr reply))))
2340 (and winconf (set-window-configuration winconf)))))
2342 (defun gnus-kill-message-buffer ()
2343 "Kill the current buffer after dissociating it from the draft group."
2345 (when (gnus-y-or-n-p "Dissociate and kill the current buffer? ")
2346 (gnus-dissociate-buffer-from-draft)
2347 (let ((winconf gnus-prev-winconf))
2348 (kill-buffer (current-buffer))
2350 (set-window-configuration winconf)))))
2352 (defun gnus-put-message ()
2353 "Put the current message in some group and return to Gnus."
2355 (let ((reply gnus-article-reply)
2356 (winconf gnus-prev-winconf)
2357 (group gnus-newsgroup-name)
2360 (or (and group (not (gnus-group-read-only-p group)))
2361 (setq group (read-string "Put in group: " nil
2362 (gnus-writable-groups))))
2363 (and (gnus-gethash group gnus-newsrc-hashtb)
2364 (error "No such group: %s" group))
2369 (gnus-inews-narrow-to-headers)
2370 (let (gnus-deletable-headers)
2371 (if (eq major-mode 'mail-mode)
2372 (gnus-inews-insert-headers gnus-required-mail-headers)
2373 (gnus-inews-insert-headers)))
2374 (goto-char (point-max))
2375 (insert "Gcc: " group "\n")
2380 (if (get-buffer gnus-group-buffer)
2382 (if (gnus-buffer-exists-p (car-safe reply))
2384 (set-buffer (car reply))
2386 (gnus-summary-mark-article-as-replied
2388 (and winconf (set-window-configuration winconf))))))
2390 (defun gnus-forward-make-subject (buffer)
2393 (concat "[" (if (memq 'mail (assoc (symbol-name
2394 (car (gnus-find-method-for-group
2395 gnus-newsgroup-name)))
2396 gnus-valid-select-methods))
2397 (gnus-fetch-field "From")
2398 gnus-newsgroup-name)
2399 "] " (or (gnus-fetch-field "Subject") ""))))
2401 (defun gnus-forward-insert-buffer (buffer)
2404 ;; Put point where we want it before inserting the forwarded
2406 (if gnus-signature-before-forwarded-message
2407 (goto-char (point-max))
2408 (goto-char (point-min))
2410 (concat "^" (regexp-quote mail-header-separator) "$"))
2412 ;; Narrow to the area we are to insert.
2413 (narrow-to-region (point) (point))
2414 ;; Insert the separators and the forwarded buffer.
2415 (insert gnus-forward-start-separator)
2416 (insert-buffer-substring buffer)
2417 (goto-char (point-max))
2418 (insert gnus-forward-end-separator)
2419 (gnus-set-text-properties (point-min) (point-max) nil)
2420 ;; Remove all unwanted headers.
2421 (goto-char (point-min))
2424 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
2427 (goto-char (point-min))
2428 (let ((case-fold-search t))
2429 (delete-non-matching-lines gnus-forward-included-headers))))))
2431 (defun gnus-mail-forward (&optional buffer)
2432 "Forward the current message to another user using mail."
2433 (let* ((forward-buffer (or buffer (current-buffer)))
2434 (winconf (current-window-configuration))
2435 (subject (gnus-forward-make-subject forward-buffer)))
2436 (set-buffer (get-buffer-create gnus-mail-buffer))
2437 (if (and (buffer-modified-p)
2440 "Unsent message being composed; erase it? ")))
2443 (gnus-mail-setup 'forward nil subject)
2444 (make-local-variable 'gnus-prev-winconf)
2445 (setq gnus-prev-winconf winconf)
2446 (gnus-forward-insert-buffer forward-buffer)
2447 (goto-char (point-min))
2448 (re-search-forward "^To: ?" nil t)
2449 (gnus-configure-windows 'mail-forward 'force)
2450 ;; You have a chance to arrange the message.
2451 (run-hooks 'gnus-mail-forward-hook)
2452 (run-hooks 'gnus-mail-hook))))
2454 (defun gnus-forward-using-post (&optional buffer)
2456 (let* ((forward-buffer (or buffer (current-buffer)))
2457 (subject (gnus-forward-make-subject forward-buffer))
2458 (gnus-newsgroup-name nil))
2459 (gnus-post-news 'post nil nil nil nil subject)
2461 (gnus-forward-insert-buffer forward-buffer)
2462 ;; You have a chance to arrange the message.
2463 (run-hooks 'gnus-mail-forward-hook)))))
2465 (defun gnus-mail-other-window-using-mail ()
2466 "Compose mail other window using mail."
2467 (let ((winconf (current-window-configuration)))
2468 (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
2469 (gnus-inews-modify-mail-mode-map)
2470 (make-local-variable 'gnus-prev-winconf)
2471 (setq gnus-prev-winconf winconf)
2472 (run-hooks 'gnus-mail-hook)
2473 (gnus-configure-windows 'summary-mail 'force)))
2475 (defun gnus-article-mail (yank)
2476 "Send a reply to the address near point.
2477 If YANK is non-nil, include the original article."
2481 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
2482 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
2485 (switch-to-buffer gnus-summary-buffer)
2486 (gnus-mail-reply yank address)))))
2489 "Send a bug report to the Gnus maintainers."
2491 (let ((winconf (current-window-configuration)))
2492 (delete-other-windows)
2493 (switch-to-buffer "*Gnus Help Bug*")
2495 (insert gnus-bug-message)
2496 (goto-char (point-min))
2497 (pop-to-buffer "*Gnus Bug*")
2500 (mail-setup gnus-maintainer nil nil nil nil nil)
2501 (auto-save-mode auto-save-default)
2502 (make-local-variable 'gnus-prev-winconf)
2503 (setq gnus-prev-winconf winconf)
2504 (gnus-inews-modify-mail-mode-map)
2505 (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
2506 (goto-char (point-min))
2507 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2509 (insert (gnus-version) "\n")
2510 (insert (emacs-version))
2511 (insert "\n\n\n\n\n")
2513 (goto-char (point-min))
2514 (search-forward "Subject: " nil t)
2517 (defun gnus-bug-mail-send-and-exit ()
2518 "Send the bug message and exit."
2520 (let ((cur (current-buffer)))
2521 (and (get-buffer "*Gnus Help Bug*")
2522 (kill-buffer "*Gnus Help Bug*"))
2523 (gnus-mail-send-and-exit)
2524 (when (buffer-name cur)
2525 (kill-buffer cur))))
2527 (defun gnus-debug ()
2528 "Attemps to go through the Gnus source file and report what variables have been changed.
2529 The source file has to be in the Emacs load path."
2531 (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el" "nnmail.el"))
2532 file dirs expr olist sym)
2533 (message "Please wait while we snoop your variables...")
2536 (set-buffer (get-buffer-create " *gnus bug info*"))
2537 (buffer-disable-undo (current-buffer))
2540 (setq dirs load-path)
2542 (if (or (not (car dirs))
2543 (not (stringp (car dirs)))
2545 (setq file (concat (file-name-as-directory
2546 (car dirs)) (car files))))))
2547 (setq dirs (cdr dirs))
2549 (insert-file-contents file)
2550 (goto-char (point-min))
2551 (if (not (re-search-forward "^;;* *Internal variables" nil t))
2552 (message "Malformed sources in file %s" file)
2553 (narrow-to-region (point-min) (point))
2554 (goto-char (point-min))
2555 (while (setq expr (condition-case ()
2556 (read (current-buffer)) (error nil)))
2558 (and (eq (car expr) 'defvar)
2559 (stringp (nth 3 expr))
2560 (or (not (boundp (nth 1 expr)))
2561 (not (equal (eval (nth 2 expr))
2562 (symbol-value (nth 1 expr)))))
2563 (setq olist (cons (nth 1 expr) olist)))
2565 (setq files (cdr files)))
2566 (kill-buffer (current-buffer)))
2567 (when (setq olist (nreverse olist))
2568 (insert "------------------ Environment follows ------------------\n\n"))
2570 (if (boundp (car olist))
2575 ,(if (or (consp (setq sym (symbol-value (car olist))))
2577 (not (or (eq sym nil)
2579 (list 'quote (symbol-value (car olist)))
2580 (symbol-value (car olist)))))
2582 (format "(setq %s 'whatever)\n" (car olist)))))
2583 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
2584 (setq olist (cdr olist)))
2586 ;; Remove any null chars - they seem to cause trouble for some
2587 ;; mailers. (Byte-compiled output from the stuff above.)
2588 (goto-char (point-min))
2589 (while (re-search-forward "[\000\200]" nil t)
2590 (replace-match "" t t))))
2592 ;;; Treatment of rejected articles.
2595 (defvar mail-unsent-separator)
2597 (defun gnus-summary-resend-bounced-mail (fetch)
2598 "Re-mail the current message.
2599 This only makes sense if the current message is a bounce message than
2600 contains some mail you have written which has been bounced back to
2602 If FETCH, try to fetch the article that this is a reply to, if indeed
2606 (gnus-summary-select-article t)
2607 ;; Create a mail buffer.
2608 (gnus-new-empty-mail)
2610 (insert-buffer-substring gnus-article-buffer)
2611 (goto-char (point-min))
2612 (or (re-search-forward mail-unsent-separator nil t)
2613 (and (search-forward "\n\n" nil t)
2614 (re-search-forward "^Return-Path:.*\n" nil t)))
2615 ;; We remove everything before the bounced mail.
2618 (if (re-search-forward "[^ \t]*:" nil t)
2624 (nnheader-narrow-to-headers)
2625 (nnheader-remove-header gnus-bounced-headers-junk t)
2626 (setq references (mail-fetch-field "references"))
2627 (goto-char (point-max))
2628 (insert mail-header-separator)))
2629 ;; If there are references, we fetch the article we answered to.
2632 (string-match "\\(<[^]+>\\)[ \t]*$" references)
2633 (gnus-summary-refer-article
2634 (substring references (match-beginning 1) (match-end 1)))
2636 (gnus-summary-show-all-headers)
2637 (gnus-configure-windows 'compose-bounce))))
2638 (goto-char (point-min)))
2642 (defun gnus-mail-send (&optional no-generated-headers)
2643 "Send the current buffer as mail.
2644 Headers will be generated before sending."
2646 (unless no-generated-headers
2650 (gnus-inews-narrow-to-headers)
2651 (gnus-inews-insert-headers gnus-required-mail-headers)
2652 (gnus-inews-remove-empty-headers))))
2654 ;; Remove the header separator.
2655 (goto-char (point-min))
2656 (and (re-search-forward
2657 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2658 (replace-match "" t t))
2659 ;; Run final inews hooks. This hook may do FCC.
2660 (run-hooks 'gnus-inews-article-hook)
2662 (nnheader-narrow-to-headers)
2663 (nnheader-remove-header "^[gf]cc:" t)
2665 (goto-char (point-min))
2666 (search-forward "\n\n")
2668 (insert mail-header-separator)
2670 (run-hooks 'gnus-message-sent-hook))
2672 (defun gnus-inews-modify-mail-mode-map ()
2673 (use-local-map (copy-keymap (current-local-map)))
2674 (gnus-local-set-keys
2675 "\C-c\C-c" gnus-mail-send-and-exit
2676 "\C-c\M-\C-p" gnus-put-message
2677 "\C-c\C-q" gnus-kill-message-buffer
2678 "\C-c\M-d" gnus-dissociate-buffer-from-draft
2679 "\C-c\C-d" gnus-associate-buffer-with-draft))
2681 (defun gnus-mail-setup (type &optional to subject in-reply-to cc
2682 replybuffer actions)
2683 ;; Let posting styles be configured.
2684 (gnus-configure-posting-styles)
2688 (eq gnus-mail-method 'mh)
2689 (and (or (eq type 'reply) (eq type 'followup))
2690 (eq gnus-mail-reply-method 'gnus-mail-reply-using-mhe))
2691 (and (eq type 'forward)
2692 (eq gnus-mail-forward-method 'gnus-mail-forward-using-mhe))
2694 (eq gnus-mail-other-window-method
2695 'gnus-mail-other-window-using-mhe)))
2696 'gnus-mh-mail-setup)
2698 (eq gnus-mail-method 'vm)
2699 (and (or (eq type 'reply) (eq type 'followup))
2700 (eq gnus-mail-reply-method 'gnus-mail-reply-using-vm))
2701 (and (eq type 'forward)
2702 (eq gnus-mail-forward-method 'gnus-mail-forward-using-vm))
2704 (eq gnus-mail-other-window-method
2705 'gnus-mail-other-window-using-vm)))
2706 'gnus-vm-mail-setup)
2708 (eq gnus-mail-method 'sendmail)
2709 (and (or (eq type 'reply) (eq type 'followup))
2710 (eq gnus-mail-reply-method 'gnus-mail-reply-using-mail))
2711 (and (eq type 'forward)
2712 (eq gnus-mail-forward-method 'gnus-mail-forward-using-mail))
2714 (eq gnus-mail-other-window-method
2715 'gnus-mail-other-window-using-mail)))
2716 'gnus-sendmail-mail-setup)
2718 (cond ((or (eq type 'reply) (eq type 'followup))
2719 gnus-mail-reply-method)
2721 gnus-mail-forward-method)
2723 gnus-mail-other-window-method))))
2724 to subject in-reply-to cc replybuffer actions)
2725 ;; Associate this mail buffer with the draft group.
2726 (gnus-enter-buffer-into-draft))
2728 (defun gnus-sendmail-mail-setup (to subject in-reply-to cc replybuffer actions)
2730 (mail-setup to subject nil cc replybuffer actions)
2731 (gnus-inews-set-point)
2732 (gnus-inews-modify-mail-mode-map))
2736 ;; Do Gcc handling, which copied the message over to some group.
2737 (defun gnus-inews-do-gcc (&optional gcc)
2740 (nnheader-narrow-to-headers)
2741 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
2742 (cur (current-buffer))
2743 end groups group method)
2745 (nnheader-remove-header "gcc")
2747 (setq groups (gnus-tokenize-header gcc " ,"))
2748 ;; Copy the article over to some group(s).
2749 (while (setq group (pop groups))
2752 (cond ((and (null (gnus-get-info group))
2753 (eq (car gnus-message-archive-method)
2755 (gnus-server-to-method
2756 (gnus-group-method group)))))
2757 ;; If the group doesn't exist, we assume
2758 ;; it's an archive group...
2759 gnus-message-archive-method)
2760 (t (gnus-find-method-for-group group)))))
2761 (unless (gnus-request-group group t method)
2762 (gnus-request-create-group group method))
2763 (gnus-check-server method)
2765 (nnheader-set-temp-buffer " *acc*")
2766 (insert-buffer-substring cur)
2767 (unless (condition-case ()
2768 (gnus-request-accept-article group t method)
2770 (gnus-message 1 "Couldn't store article in group %s: %s"
2771 group (gnus-status-message method))
2773 (kill-buffer (current-buffer)))))))))
2775 (defun gnus-inews-insert-bfcc ()
2776 "Insert Bcc and Fcc headers."
2778 ;; Handle author copy using BCC field.
2779 (when (and gnus-mail-self-blind
2780 (not (mail-fetch-field "bcc")))
2781 (mail-position-on-field "Bcc")
2782 (insert (if (stringp gnus-mail-self-blind)
2783 gnus-mail-self-blind
2784 (user-login-name))))
2785 ;; Handle author copy using FCC field.
2786 (when gnus-author-copy
2787 (mail-position-on-field "Fcc")
2788 (insert gnus-author-copy))))
2790 (defun gnus-inews-insert-gcc ()
2791 "Insert Gcc headers based on `gnus-outgoing-message-group'."
2794 (gnus-inews-narrow-to-headers)
2795 (let* ((group gnus-outgoing-message-group)
2797 ((gnus-functionp group)
2799 ((or (stringp group) (list group))
2803 (if (stringp gcc) gcc
2804 (mapconcat 'identity gcc " "))
2807 (defun gnus-inews-insert-archive-gcc (&optional group)
2808 "Insert the Gcc to say where the article is to be archived."
2809 (let* ((var gnus-message-archive-group)
2810 (group (or group gnus-newsgroup-name ""))
2814 ((null gnus-message-archive-method)
2818 ;; Just a single group.
2821 ;; We don't want this.
2823 ((and (listp var) (stringp (car var)))
2824 ;; A list of groups.
2826 ((gnus-functionp var)
2828 (funcall var group))
2830 ;; An alist of regexps/functions/forms.
2835 ((stringp (caar var))
2837 (when (string-match (caar var) group)
2839 ((gnus-functionp (car var))
2841 (funcall (car var) group))
2843 (eval (car var)))))))
2844 (setq var (cdr var)))
2847 (when (stringp groups)
2848 (setq groups (list groups)))
2851 (gnus-inews-narrow-to-headers)
2852 (goto-char (point-max))
2855 (insert (gnus-group-prefixed-name
2856 (pop groups) gnus-message-archive-method))
2860 ;;; Handling rejected (and postponed) news.
2862 (defun gnus-draft-group ()
2863 "Return the name of the draft group."
2864 (gnus-group-prefixed-name
2865 (file-name-nondirectory (directory-file-name gnus-draft-group-directory))
2866 (list 'nndraft gnus-draft-group-directory)))
2868 (defun gnus-make-draft-group ()
2869 "Make the draft group or die trying."
2870 (let* ((method `(nndraft "private"
2872 ,gnus-draft-group-directory)))
2873 (group (gnus-draft-group)))
2874 (or (gnus-gethash group gnus-newsrc-hashtb)
2875 (gnus-group-make-group (gnus-group-real-name group) method)
2876 (error "Can't create the draft group"))
2877 (gnus-check-server method)
2880 (defun gnus-associate-buffer-with-draft (&optional generate silent)
2881 "Enter the current buffer into the draft group."
2883 (when (gnus-request-accept-article (gnus-make-draft-group) t)
2885 ;; This function does the proper marking of articles.
2886 (gnus-mail-send-and-exit 'dont-send))
2887 (set-buffer-modified-p nil)))
2889 (defun gnus-enter-buffer-into-draft ()
2890 (when gnus-use-draft
2892 ;; Make sure the draft group exists.
2893 (gnus-make-draft-group)
2894 ;; Associate the buffer with the draft group.
2895 (let ((article (gnus-request-associate-buffer (gnus-draft-group))))
2896 ;; Arrange for deletion of the draft after successful sending.
2897 (make-local-variable 'gnus-message-sent-hook)
2898 (setq gnus-message-sent-hook
2901 (let ((gnus-verbose-backends nil))
2902 (gnus-request-expire-articles
2903 (quote ,(list article))
2904 ,(gnus-draft-group) t)))))))))
2906 (defun gnus-dissociate-buffer-from-draft ()
2907 "Disable auto-saving and association to the draft group of the current buffer."
2909 (run-hooks 'gnus-message-sent-hook)
2910 (setq buffer-file-name nil)
2911 (setq buffer-auto-save-file-name nil))
2913 (defun gnus-summary-send-draft ()
2914 "Enter a mail/post buffer to edit and send the draft."
2916 (gnus-set-global-variables)
2917 (unless (equal gnus-newsgroup-name (gnus-draft-group))
2918 (error "This function can only be used in the draft buffer"))
2920 (if (not (setq buf (gnus-request-restore-buffer
2921 (gnus-summary-article-number) gnus-newsgroup-name)))
2922 (error "Couldn't restore the article")
2923 (setq point (point))
2924 (switch-to-buffer buf)
2925 (gnus-inews-modify-mail-mode-map)
2926 (when (eq major-mode 'news-reply-mode)
2927 (local-set-key "\C-c\C-c" 'gnus-inews-news))
2928 (gnus-enter-buffer-into-draft)
2929 ;; Insert the separator.
2930 (goto-char (point-min))
2931 (search-forward "\n\n")
2933 (insert mail-header-separator)
2934 ;; Configure windows.
2935 (let ((gnus-draft-buffer (current-buffer)))
2936 (gnus-configure-windows 'draft t)
2937 (goto-char (point))))))
2939 (defun gnus-configure-posting-styles ()
2940 "Configure posting styles according to `gnus-posting-styles'."
2941 (let ((styles gnus-posting-styles)
2942 (gnus-newsgroup-name (or gnus-newsgroup-name ""))
2943 style match variable attribute value value-value)
2944 ;; Go through all styles and look for matches.
2946 (setq style (pop styles)
2948 (when (cond ((stringp match)
2949 ;; Regexp string match on the group name.
2950 (string-match match gnus-newsgroup-name))
2951 ((or (symbolp match)
2952 (gnus-functionp match))
2953 (cond ((gnus-functionp match)
2954 ;; Function to be called.
2957 ;; Variable to be checked.
2958 (symbol-value match))))
2960 ;; This is a form to be evaled.
2962 ;; We have a match, so we set the variables.
2964 (setq attribute (pop style)
2965 value (cdr attribute))
2966 ;; We find the variable that is to be modified.
2967 (if (and (not (stringp (car attribute)))
2968 (not (setq variable (cdr (assq (car attribute)
2969 gnus-posting-style-alist)))))
2970 (message "Couldn't find attribute %s" (car attribute))
2971 ;; We set the variable.
2973 (cond ((stringp value)
2975 ((or (symbolp value)
2976 (gnus-functionp value))
2977 (cond ((gnus-functionp value)
2980 (symbol-value value))))
2985 ;; This is an ordinary variable.
2986 (make-local-variable variable)
2987 (set variable value-value))
2988 ;; This is a header to be added to the headers when
2991 (make-local-variable gnus-required-headers)
2992 (make-local-variable gnus-required-mail-headers)
2993 (push (cons (car attribute) value-value)
2994 gnus-required-headers)
2995 (push (cons (car attribute) value-value)
2996 gnus-required-mail-headers)))))))))
2998 (defun gnus-inews-set-point ()
2999 "Move point to where the user probably wants to find it."
3000 (gnus-inews-narrow-to-headers)
3002 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3003 (search-backward ":" )
3007 (goto-char (point-max))
3010 (unless (looking-at "$")
3011 (forward-line 2)))))
3013 ;;; Allow redefinition of functions.
3019 ;;; gnus-msg.el ends here