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 (mail-strip-quoted-names
485 (mail-header-from gnus-current-headers)))
486 (downcase (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 (mail-strip-quoted-names from))
1039 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
1041 (ding) (gnus-message 3 "This article is not yours.")
1043 ;; Make control article.
1044 (set-buffer (get-buffer-create " *Gnus-canceling*"))
1045 (buffer-disable-undo (current-buffer))
1047 (insert "Newsgroups: " newsgroups "\n"
1048 "From: " (gnus-inews-user-name) "\n"
1049 "Subject: cancel " message-id "\n"
1050 "Control: cancel " message-id "\n"
1052 (concat "Distribution: " distribution "\n")
1054 mail-header-separator "\n"
1055 "This is a cancel message from " from ".\n")
1056 ;; Send the control article to NNTP server.
1057 (gnus-message 5 "Canceling your article...")
1059 (if (funcall gnus-inews-article-function)
1060 (gnus-message 5 "Canceling your article...done")
1063 (gnus-message 1 "Cancel failed; %s"
1064 (gnus-status-message gnus-newsgroup-name))
1067 ;; Kill the article buffer.
1068 (kill-buffer (current-buffer))))))))
1070 (defun gnus-inews-remove-signature ()
1071 "Remove the signature from the text between point and mark.
1072 The text will also be indented the normal way.
1073 This function can be used in `mail-citation-hook', for instance."
1075 (let ((start (point))
1077 (if (not (re-search-forward gnus-signature-separator (mark t) t))
1078 ;; No signature here, so we just indent the cited text.
1079 (mail-indent-citation)
1080 ;; Find the last non-empty line.
1082 (while (looking-at "[ \t]*$")
1085 (setq mark (set-marker (make-marker) (point)))
1087 (mail-indent-citation)
1088 ;; Enable undoing the deletion.
1090 (delete-region mark (mark t))
1091 (set-marker mark nil)))))
1095 ;; Dummy to avoid byte-compile warning.
1096 (defvar nnspool-rejected-article-hook)
1098 (defun gnus-inews-article (&optional use-group-method)
1099 "Post an article in current buffer using NNTP protocol."
1100 (let ((artbuf (current-buffer))
1103 (goto-char (point-max))
1104 ;; Require a newline at the end of the buffer since inews may
1105 ;; append a .signature.
1106 (or (= (preceding-char) ?\n)
1108 ;; Prepare article headers. All message body such as signature
1109 ;; must be inserted before Lines: field is prepared.
1111 (gnus-inews-narrow-to-headers)
1112 ;; Fix some headers.
1113 (gnus-inews-cleanup-headers)
1114 ;; Remove some headers.
1115 (gnus-inews-remove-headers)
1116 ;; Insert some headers.
1117 (gnus-inews-insert-headers)
1118 ;; Let the user do all of the above.
1119 (run-hooks 'gnus-inews-article-header-hook)
1120 ;; Copy the Gcc header, if any.
1121 (setq gcc (mail-fetch-field "gcc"))
1123 ;; Check whether the article is a good Net Citizen.
1124 (if (not (gnus-inews-check-post))
1127 ;; We fudge a hook for nnspool.
1128 (setq nnspool-rejected-article-hook
1132 (set-buffer ,(buffer-name))
1133 (gnus-associate-buffer-with-draft nil 'silent))
1137 1 "Couldn't enter rejected article into draft group"))))))
1139 ;; Looks ok, so we do the nasty.
1141 ;; This hook may insert a signature.
1143 (goto-char (point-min))
1144 (let ((gnus-newsgroup-name (or (mail-fetch-field "newsgroups")
1145 gnus-newsgroup-name)))
1146 (run-hooks 'gnus-prepare-article-hook)))
1147 ;; Send off copies using mail, if that is wanted.
1148 (gnus-inews-send-mail-copy)
1149 ;; Remove more headers.
1150 (gnus-inews-remove-headers-after-mail)
1151 ;; Copy the article over to a temp buffer.
1152 (nnheader-set-temp-buffer " *Gnus-posting*")
1153 (insert-buffer-substring artbuf)
1154 ;; Remove the header separator.
1155 (goto-char (point-min))
1157 (concat "^" (regexp-quote mail-header-separator) "$"))
1158 (replace-match "" t t)
1159 ;; Remove X- prefixes to headers.
1160 (gnus-inews-dex-headers)
1161 ;; Run final inews hooks. This hook may do FCC.
1162 ;; The article must be saved before being posted because
1163 ;; `gnus-request-post' modifies the buffer.
1164 (run-hooks 'gnus-inews-article-hook)
1165 ;; Copy the article over to some group, possibly.
1166 (and gcc (gnus-inews-do-gcc gcc))
1167 ;; Post the article.
1168 (setq result (gnus-request-post
1169 (gnus-post-method gnus-newsgroup-name use-group-method)))
1170 (kill-buffer (current-buffer)))
1171 (run-hooks 'gnus-message-sent-hook)
1172 ;; If the posting was unsuccessful (that it, it was rejected) we
1173 ;; put it into the draft group.
1174 (or result (gnus-associate-buffer-with-draft))
1177 (defun gnus-inews-cleanup-headers ()
1178 ;; Remove empty lines in the header.
1180 (gnus-inews-narrow-to-headers)
1181 (while (re-search-forward "^[ \t]*\n" nil t)
1182 (replace-match "" t t)))
1184 ;; Correct newsgroups field: change sequence of spaces to comma and
1185 ;; eliminate spaces around commas. Eliminate imbedded line breaks.
1186 (goto-char (point-min))
1187 (if (re-search-forward "^Newsgroups: +" nil t)
1191 (if (re-search-forward "^[^ \t]" nil t)
1195 (goto-char (point-min))
1196 (while (re-search-forward "\n[ \t]+" nil t)
1197 (replace-match " " t t)) ;No line breaks (too confusing)
1198 (goto-char (point-min))
1199 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
1200 (replace-match "," t t))
1201 (goto-char (point-min))
1202 ;; Remove a trailing comma.
1203 (if (re-search-forward ",$" nil t)
1204 (replace-match "" t t))))
1206 ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
1207 ;; Help save the the world!
1210 (let ((newsgroups (mail-fetch-field "newsgroups"))
1211 (followup-to (mail-fetch-field "followup-to"))
1214 (string-match "," newsgroups) (not followup-to))
1216 (while (string-match "," newsgroups)
1218 (cons (list (substring newsgroups 0 (match-beginning 0)))
1220 (setq newsgroups (substring newsgroups (match-end 0))))
1221 (setq groups (nreverse (cons (list newsgroups) groups)))
1223 (setq to (completing-read
1224 "Followups to: (default all groups) " groups))
1225 (if (> (length to) 0)
1227 (goto-char (point-min))
1228 (insert "Followup-To: " to "\n")))))))
1230 ;; Cleanup Followup-To.
1231 (goto-char (point-min))
1232 (if (search-forward-regexp "^Followup-To: +" nil t)
1236 (if (re-search-forward "^[^ \t]" nil 'end)
1239 (goto-char (point-min))
1240 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
1241 (goto-char (point-min))
1242 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ","))))
1244 (defun gnus-inews-remove-headers ()
1245 (let ((case-fold-search t)
1246 (headers gnus-removable-headers))
1247 ;; Remove toxic headers.
1249 (goto-char (point-min))
1250 (and (re-search-forward
1251 (concat "^" (downcase (format "%s" (car headers))))
1253 (delete-region (progn (beginning-of-line) (point))
1254 (progn (forward-line 1) (point))))
1255 (setq headers (cdr headers)))))
1257 ;;; Since the X-Newsreader/X-Mailer are ``vanity'' headers, they might
1258 ;;; as well include the Emacs version as well.
1259 ;;; The following function works with later GNU Emacs, and XEmacs.
1260 (defun gnus-extended-version ()
1261 "Stringified Gnus version and Emacs version"
1267 ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
1268 (concat "Emacs " (substring emacs-version
1271 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)" emacs-version)
1272 (concat (substring emacs-version
1275 (format " %d.%d" emacs-major-version emacs-minor-version)))
1276 (t emacs-version))))
1278 (defun gnus-inews-insert-headers (&optional headers)
1279 "Prepare article headers.
1280 Headers already prepared in the buffer are not modified.
1281 Headers in `gnus-required-headers' will be generated."
1282 (let* ((Date (gnus-inews-date))
1283 (Message-ID (gnus-inews-message-id))
1284 (Organization (gnus-inews-organization))
1285 (From (gnus-inews-user-name))
1286 (Path (gnus-inews-path))
1289 (In-Reply-To (gnus-inews-in-reply-to))
1291 (Distribution (gnus-inews-distribution))
1292 (Lines (gnus-inews-lines))
1293 (X-Newsreader (gnus-extended-version))
1294 (X-Mailer X-Newsreader)
1295 (Expires (gnus-inews-expires))
1296 (headers (or headers gnus-required-headers))
1297 (case-fold-search t)
1299 ;; First we remove any old generated headers.
1300 (let ((headers gnus-deletable-headers))
1302 (goto-char (point-min))
1303 (and (re-search-forward
1304 (concat "^" (symbol-name (car headers)) ": *") nil t)
1305 (get-text-property (1+ (match-beginning 0)) 'gnus-deletable)
1307 (setq headers (cdr headers))))
1308 ;; If there are References, and no "Re: ", then the thread has
1309 ;; changed name. See Son-of-1036.
1310 (if (and (mail-fetch-field "references")
1311 (get-buffer gnus-article-buffer))
1312 (let ((psubject (gnus-simplify-subject-re
1313 (mail-fetch-field "subject"))))
1314 (or (and psubject gnus-reply-subject
1315 (string= (gnus-simplify-subject-re gnus-reply-subject)
1318 (string-match "@" Message-ID)
1320 (concat (substring Message-ID 0 (match-beginning 0))
1322 (substring Message-ID (match-beginning 0))))))))
1323 ;; Go through all the required headers and see if they are in the
1324 ;; articles already. If they are not, or are empty, they are
1325 ;; inserted automatically - except for Subject, Newsgroups and
1328 (goto-char (point-min))
1329 (setq elem (pop headers))
1331 (setq header (car elem))
1333 (when (or (not (re-search-forward
1334 (concat "^" (downcase (symbol-name header)) ":") nil t))
1336 ;; The header was found. We insert a space after the
1337 ;; colon, if there is none.
1338 (if (/= (following-char) ? ) (insert " "))
1339 ;; Find out whether the header is empty...
1340 (looking-at "[ \t]*$")))
1341 ;; So we find out what value we should insert.
1344 ((and (consp elem) (eq (car elem) 'optional))
1345 ;; This is an optional header. If the cdr of this
1346 ;; is something that is nil, then we do not insert
1348 (setq header (cdr elem))
1349 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
1350 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
1352 ;; The element is a cons. Either the cdr is a
1353 ;; string to be inserted verbatim, or it is a
1354 ;; function, and we insert the value returned from
1356 (or (and (stringp (cdr elem)) (cdr elem))
1357 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
1358 ((and (boundp header) (symbol-value header))
1359 ;; The element is a symbol. We insert the value
1360 ;; of this symbol, if any.
1361 (symbol-value header))
1363 ;; We couldn't generate a value for this header,
1364 ;; so we just ask the user.
1365 (read-from-minibuffer
1366 (format "Empty header for %s; enter value: " header)))))
1367 ;; Finally insert the header.
1369 (not (equal value "")))
1373 ;; This header didn't exist, so we insert it.
1374 (goto-char (point-max))
1375 (insert (symbol-name header) ": " value "\n")
1377 ;; The value of this header was empty, so we clear
1378 ;; totally and insert the new value.
1379 (delete-region (point) (gnus-point-at-eol))
1381 ;; Add the deletable property to the headers that require it.
1382 (and (memq header gnus-deletable-headers)
1383 (progn (beginning-of-line) (looking-at "[^:]+: "))
1384 (add-text-properties
1385 (point) (match-end 0)
1386 '(gnus-deletable t face italic) (current-buffer)))))))
1387 ;; Insert new Sender if the From is strange.
1388 (let ((from (mail-fetch-field "from"))
1389 (sender (mail-fetch-field "sender"))
1390 (secure-sender (gnus-inews-real-user-address)))
1392 (not (gnus-check-before-posting 'sender))
1394 (downcase (cadr (gnus-extract-address-components from)))
1395 (downcase (gnus-inews-real-user-address))))
1400 (cadr (gnus-extract-address-components sender)))
1401 (downcase secure-sender)))))
1402 (goto-char (point-min))
1403 ;; Rename any old Sender headers to Original-Sender.
1404 (when (re-search-forward "^Sender:" nil t)
1406 (insert "Original-")
1407 (beginning-of-line))
1408 (insert "Sender: " secure-sender "\n")))))
1410 (defun gnus-inews-insert-signature ()
1411 "Insert a signature file.
1412 If `gnus-signature-function' is bound and returns a string, this
1413 string is used instead of the variable `gnus-signature-file'.
1414 In either case, if the string is a file name, this file is
1415 inserted. If the string is not a file name, the string itself is
1418 If you never want any signature inserted, set both of these variables to
1422 (or (and gnus-signature-function
1423 (funcall gnus-signature-function gnus-newsgroup-name))
1424 gnus-signature-file)))
1426 (or (file-exists-p signature)
1427 (string-match " " signature)
1429 "^/[^/]+/" (expand-file-name signature)))))
1431 (goto-char (point-max))
1432 (if (and mail-signature (search-backward "\n-- \n" nil t))
1434 ;; Delete any previous signatures.
1435 (if (search-backward "\n-- \n" nil t)
1436 (delete-region (point) (point-max)))
1437 (or (eolp) (insert "\n"))
1439 (if (file-exists-p signature)
1440 (insert-file-contents signature)
1442 (goto-char (point-max))
1443 (or (bolp) (insert "\n"))))))))
1445 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1446 (defun gnus-inews-insert-mime-headers ()
1447 (goto-char (point-min))
1448 (let ((mail-header-separator
1450 (goto-char (point-min))
1451 (if (and (search-forward (concat "\n" mail-header-separator "\n")
1453 (not (search-backward "\n\n" nil t)))
1454 mail-header-separator
1456 (or (mail-position-on-field "Mime-Version")
1458 (cond ((save-restriction
1460 (goto-char (point-min))
1461 (re-search-forward "[\200-\377]" nil t))
1462 (or (mail-position-on-field "Content-Type")
1463 (insert "text/plain; charset=ISO-8859-1"))
1464 (or (mail-position-on-field "Content-Transfer-Encoding")
1466 (t (or (mail-position-on-field "Content-Type")
1467 (insert "text/plain; charset=US-ASCII"))
1468 (or (mail-position-on-field "Content-Transfer-Encoding")
1469 (insert "7bit")))))))
1471 (defun gnus-inews-do-fcc ()
1472 "Process Fcc headers in the current buffer.
1473 Unless the first character of the field is `|', the article is saved
1474 to the specified file using the function specified by the variable
1475 gnus-author-copy-saver. The default function rmail-output saves in
1476 Unix mailbox format.
1478 If the first character is `|', the contents of the article is sent to
1479 a program specified by the rest of the value."
1480 (let ((case-fold-search t) ;Should ignore case.
1484 (nnheader-narrow-to-headers)
1485 (while (setq file (mail-fetch-field "fcc"))
1487 (nnheader-remove-header "fcc" nil t))
1488 ;; Process FCC operations.
1491 (setq file (pop list))
1492 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
1493 ;; Pipe the article to the program in question.
1494 (call-process-region (point-min) (point-max) shell-file-name
1495 nil nil nil "-c" (match-string 1 file))
1496 ;; Save the article.
1497 (setq file (expand-file-name file))
1498 (gnus-make-directory (file-name-directory file))
1499 (if (and gnus-author-copy-saver
1500 (not (eq gnus-author-copy-saver 'rmail-output)))
1501 (funcall gnus-author-copy-saver file)
1502 (if (and (file-readable-p file) (mail-file-babyl-p file))
1503 (gnus-output-to-rmail file)
1504 (let ((mail-use-rfc822 t))
1505 (rmail-output file 1 t t))))))))))
1507 (defun gnus-inews-path ()
1509 (let ((login-name (gnus-inews-login-name)))
1510 (cond ((null gnus-use-generic-path)
1511 (concat (nth 1 gnus-select-method) "!" login-name))
1512 ((stringp gnus-use-generic-path)
1513 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1514 (concat gnus-use-generic-path "!" login-name))
1517 (defun gnus-inews-user-name ()
1518 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1519 (let ((full-name (gnus-inews-full-name))
1520 (address (if (or gnus-user-login-name gnus-use-generic-from
1521 gnus-local-domain (getenv "DOMAINNAME"))
1522 (concat (gnus-inews-login-name) "@"
1523 (gnus-inews-domain-name gnus-use-generic-from))
1524 user-mail-address)))
1525 (or gnus-user-from-line
1527 ;; User's full name.
1528 (cond ((string-equal full-name "&") ;Unix hack.
1529 (concat " (" (user-login-name) ")"))
1530 ((string-match "[^ ]+@[^ ]+ +(.*)" address)
1533 (concat " (" full-name ")")))))))
1535 (defun gnus-inews-real-user-address ()
1536 "Return the \"real\" user address.
1537 This function tries to ignore all user modifications, and
1538 give as trustworthy answer as possible."
1539 (concat (user-login-name) "@" (system-name)))
1541 (defun gnus-inews-login-name ()
1542 "Return login name."
1543 (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1545 (defun gnus-inews-full-name ()
1546 "Return full user name."
1547 (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1549 (defun gnus-inews-domain-name (&optional genericfrom)
1550 "Return user's domain name.
1551 If optional argument GENERICFROM is a string, use it as the domain
1552 name; if it is non-nil, strip off local host name from the domain name.
1553 If the function `system-name' returns full internet name and the
1554 domain is undefined, the domain name is got from it."
1555 (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1556 (let* ((system-name (system-name))
1558 (or (if (stringp genericfrom) genericfrom)
1559 (getenv "DOMAINNAME")
1560 (and (boundp 'mail-host-address)
1563 ;; Function `system-name' may return full internet name.
1564 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1565 (if (string-match "\\.." system-name)
1566 ;; Some machines return "name.", and that's not
1568 (substring system-name (1- (match-end 0))))
1569 (read-string "Domain name (no host): ")))
1570 (host (or (if (string-match "\\." system-name)
1571 (substring system-name 0 (match-beginning 0)))
1573 (if (string-equal "." (substring domain 0 1))
1574 (setq domain (substring domain 1)))
1575 ;; Support GENERICFROM as same as standard Bnews system.
1576 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1577 (cond ((null genericfrom)
1578 (concat host "." domain))
1579 ;;((stringp genericfrom) genericfrom)
1581 (if (string-match "\\." (system-name))
1583 (if (string-match "@\\([^ ]+\\)\\($\\| \\)" user-mail-address)
1584 (substring user-mail-address
1585 (match-beginning 1) (match-end 1))
1588 (defun gnus-inews-full-address ()
1589 (let ((domain (gnus-inews-domain-name))
1590 (system (system-name))
1591 (case-fold-search t))
1592 (if (string-match "\\." system) system
1593 (if (string-match (concat "^" (regexp-quote system)) domain) domain
1594 (concat system "." domain)))))
1596 (defun gnus-inews-expires ()
1597 "Return an Expires header based on `gnus-article-expires'."
1598 (let ((current (current-time))
1599 (future (* 1.0 gnus-article-expires 60 60 24)))
1600 ;; Add the future to current.
1601 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
1602 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
1603 ;; Return the date in the future in UT.
1604 (timezone-make-date-arpa-standard
1605 (current-time-string current) (current-time-zone) '(0 "UT"))))
1607 (defun gnus-inews-distribution ()
1608 "Return the current Distribution header, if any."
1609 (when (and gnus-distribution-function
1610 (fboundp gnus-distribution-function))
1611 (funcall gnus-distribution-function (or gnus-newsgroup-name ""))))
1613 (defun gnus-inews-message-id ()
1614 "Generate unique Message-ID for user."
1615 ;; Message-ID should not contain a slash and should be terminated by
1616 ;; a number. I don't know the reason why it is so.
1617 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1619 (defvar gnus-unique-id-char nil)
1621 ;; If you ever change this function, make sure the new version
1622 ;; cannot generate IDs that the old version could.
1623 ;; You might for example insert a "." somewhere (not next to another dot
1624 ;; or string boundary), or modify the newsreader name to "Ding".
1625 (defun gnus-inews-unique-id ()
1626 ;; Don't use microseconds from (current-time), they may be unsupported.
1627 ;; Instead we use this randomly inited counter.
1628 (setq gnus-unique-id-char
1629 (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1630 ;; (current-time) returns 16-bit ints,
1631 ;; and 2^16*25 just fits into 4 digits i base 36.
1633 (let ((tm (if (fboundp 'current-time)
1634 (current-time) '(12191 46742 287898))))
1636 (if (memq system-type '(ms-dos emx vax-vms))
1637 (let ((user (downcase (gnus-inews-login-name))))
1638 (while (string-match "[^a-z0-9_]" user)
1639 (aset user (match-beginning 0) ?_))
1641 (gnus-number-base36 (user-uid) -1))
1642 (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1643 (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1644 ;; Append the newsreader name, because while the generated
1645 ;; ID is unique to this newsreader, other newsreaders might
1646 ;; otherwise generate the same ID via another algorithm.
1649 (defun gnus-inews-date ()
1650 "Current time string."
1651 (let ((now (current-time)))
1652 (timezone-make-date-arpa-standard
1653 (current-time-string now) (current-time-zone now))))
1655 (defun gnus-inews-organization ()
1656 "Return user's organization.
1657 The ORGANIZATION environment variable is used if defined.
1658 If not, the variable `gnus-local-organization' is used instead.
1659 If it is a function, the function will be called with the current
1660 newsgroup name as the argument.
1661 If this is a file name, the contents of this file will be used as the
1663 (let* ((organization
1664 (or (getenv "ORGANIZATION")
1665 (if gnus-local-organization
1666 (if (gnus-functionp gnus-local-organization)
1667 (funcall gnus-local-organization gnus-newsgroup-name)
1668 gnus-local-organization))
1669 gnus-organization-file
1670 "~/.organization")))
1671 (and (stringp organization)
1672 (> (length organization) 0)
1673 (or (file-exists-p organization)
1674 (string-match " " organization)
1675 (not (string-match "^/usr/lib/\\|^~/" organization)))
1677 (gnus-set-work-buffer)
1678 (if (file-exists-p organization)
1679 (insert-file-contents organization)
1680 (insert organization))
1681 (goto-char (point-min))
1682 (while (re-search-forward " *\n *" nil t)
1683 (replace-match " " t t))
1684 (buffer-substring (point-min) (point-max))))))
1686 (defun gnus-inews-lines ()
1687 "Count the number of lines and return numeric string."
1691 (goto-char (point-min))
1693 (concat "^" (regexp-quote mail-header-separator) "$"))
1695 (int-to-string (count-lines (point) (point-max))))))
1697 (defun gnus-inews-in-reply-to ()
1698 "Return the In-Reply-To header for this message."
1703 ;;; Gnus Mail Functions
1706 ;;; Mail reply commands of Gnus summary mode
1708 (defun gnus-summary-reply (yank &optional yank-articles)
1709 "Reply mail to news author.
1710 If prefix argument YANK is non-nil, original article is yanked automatically.
1711 Customize the variable gnus-mail-reply-method to use another mailer."
1713 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1714 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1715 (gnus-set-global-variables)
1716 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1717 (gnus-summary-select-article)
1718 (bury-buffer gnus-article-buffer)
1719 (gnus-mail-reply (or yank-articles (not (not yank)))))
1721 (defun gnus-summary-reply-with-original (n)
1722 "Reply mail to news author with original article.
1723 Customize the variable gnus-mail-reply-method to use another mailer."
1725 (gnus-summary-reply t (gnus-summary-work-articles n)))
1727 (defun gnus-summary-mail-forward (post)
1728 "Forward the current message to another user.
1729 Customize the variable gnus-mail-forward-method to use another mailer."
1731 (gnus-set-global-variables)
1732 (gnus-summary-select-article)
1733 (gnus-copy-article-buffer)
1735 (gnus-forward-using-post gnus-original-article-buffer)
1736 (gnus-mail-forward gnus-original-article-buffer)))
1738 (defun gnus-summary-resend-message (address)
1739 "Resend the current article to ADDRESS."
1740 (interactive "sResend message to: ")
1741 (gnus-summary-select-article)
1744 ;; We first set up a normal mail buffer.
1745 (nnheader-set-temp-buffer " *Gnus resend*")
1746 ;; This code from sendmail.el
1748 (let ((fill-prefix "\t")
1749 (address-start (point)))
1750 (insert address "\n")
1751 (fill-region-as-paragraph address-start (point-max)))
1752 (insert mail-header-separator "\n")
1753 ;; Insert our usual headers.
1754 (gnus-inews-narrow-to-headers)
1755 (gnus-inews-insert-headers '(From Date To))
1756 (goto-char (point-min))
1757 ;; Rename them all to "Resent-*".
1758 (while (re-search-forward "^[A-Za-z]" nil t)
1763 (delete-region (point) (point-max))
1765 ;; Insert the message to be resent.
1766 (insert-buffer-substring gnus-original-article-buffer)
1767 (goto-char (point-min))
1768 (search-forward "\n\n")
1770 (insert mail-header-separator)
1771 ;; Rename all old ("Also-")Resent headers.
1772 (while (re-search-backward "^\\(Also-\\)?Resent-" beg t)
1777 (kill-buffer (current-buffer)))))
1779 (defun gnus-summary-post-forward ()
1780 "Forward the current article to a newsgroup."
1782 (gnus-summary-mail-forward t))
1784 (defvar gnus-nastygram-message
1785 "The following article was inappropriately posted to %s.\n"
1786 "Format string to insert in nastygrams.
1787 The current group name will be inserted at \"%s\".")
1789 (defun gnus-summary-mail-nastygram (n)
1790 "Send a nastygram to the author of the current article."
1792 (if (or gnus-expert-user
1794 "Really send a nastygram to the author of the current article? "))
1795 (let ((group gnus-newsgroup-name))
1796 (gnus-summary-reply-with-original n)
1797 (set-buffer gnus-mail-buffer)
1798 (insert (format gnus-nastygram-message group))
1799 (gnus-mail-send-and-exit))))
1801 (defun gnus-summary-mail-other-window ()
1802 "Compose mail in other window.
1803 Customize the variable `gnus-mail-other-window-method' to use another
1806 (gnus-set-global-variables)
1808 ;; We might want to prompt here.
1809 (when (and gnus-interactive-post
1810 (not gnus-expert-user))
1811 (read-string "To: ")))
1812 (gnus-configure-windows 'summary-mail 'force))
1814 (defun gnus-new-mail (&optional to)
1816 (when (and gnus-interactive-post
1817 (not gnus-expert-user))
1818 (setq subject (read-string "Subject: ")))
1819 (pop-to-buffer gnus-mail-buffer)
1821 (gnus-mail-setup 'new to subject)
1822 (gnus-inews-insert-gcc)
1823 (gnus-inews-insert-archive-gcc)
1824 (run-hooks 'gnus-mail-hook)))
1826 (defun gnus-new-empty-mail ()
1827 "Create a new, virtually empty mail mode buffer."
1828 (pop-to-buffer gnus-mail-buffer)
1829 (gnus-mail-setup 'new "" ""))
1831 (defun gnus-mail-reply (&optional yank to-address followup)
1833 (set-buffer gnus-summary-buffer)
1834 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1835 (cur (cons (current-buffer) (cdr gnus-article-current)))
1836 (winconf (current-window-configuration))
1837 from subject date reply-to message-of to cc
1838 references message-id sender follow-to sendto elt new-cc new-to
1839 mct mctdo gnus-warning)
1840 (set-buffer (get-buffer-create gnus-mail-buffer))
1842 (if (and (buffer-modified-p)
1845 "Unsent message being composed; erase it? ")))
1849 (gnus-copy-article-buffer)
1851 (set-buffer gnus-article-copy)
1852 (nnheader-narrow-to-headers)
1854 ;; This is a regular reply.
1855 (if (gnus-functionp gnus-reply-to-function)
1856 (setq follow-to (funcall gnus-reply-to-function group)))
1857 ;; This is a followup.
1858 (if (gnus-functionp gnus-followup-to-function)
1861 (funcall gnus-followup-to-function group)))))
1862 (setq from (mail-fetch-field "from"))
1863 (setq date (or (mail-fetch-field "date")
1864 (mail-header-date gnus-current-headers)))
1865 (setq message-of (gnus-message-of from date))
1866 (setq sender (mail-fetch-field "sender"))
1867 (setq subject (or (mail-fetch-field "subject") "none"))
1868 ;; Remove any (buggy) Re:'s that are present and make a
1870 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1871 (setq subject (substring subject (match-end 0))))
1872 (setq subject (concat "Re: " subject))
1873 (setq to (mail-fetch-field "to"))
1874 (setq cc (mail-fetch-field "cc"))
1875 (setq mct (mail-fetch-field "mail-copies-to"))
1877 (unless (gnus-group-get-parameter group 'broken-reply-to)
1878 (mail-fetch-field "reply-to")))
1879 (setq references (mail-fetch-field "references"))
1880 (setq message-id (mail-fetch-field "message-id"))
1881 (when (and (setq gnus-warning (mail-fetch-field "gnus-warning"))
1882 (string-match "<[^>]+>" gnus-warning))
1883 (setq message-id (match-string 0 gnus-warning)))
1885 (setq mctdo (not (equal mct "never")))
1886 (when (and mct (string= (downcase mct) "always"))
1887 (setq mct (or reply-to from)))
1889 (if (not (and followup (not to-address)))
1890 (setq new-to (or reply-to from)
1894 (mail-strip-quoted-names mct)
1895 (mail-strip-quoted-names
1898 (not (stringp follow-to)))
1900 (or follow-to new-to
1905 (gnus-set-work-buffer)
1906 (unless (equal mct "never")
1907 (insert (or reply-to from "")))
1909 (if (bolp) "" ", ") (or to "")
1910 (if (or (not mct) (not mctdo)) ""
1911 (concat (if (bolp) "" ", ") mct))
1912 (if cc (concat (if (bolp) "" ", ") cc) ""))
1913 ;; Remove addresses that match `rmail-dont-reply-to-names'.
1914 (insert (prog1 (rmail-dont-reply-to (buffer-string))
1916 (goto-char (point-min))
1920 (cons (mail-strip-quoted-names addr) addr))
1921 (nreverse (gnus-mail-parse-comma-list))))
1924 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
1925 (setq new-to (cdr (pop ccalist)))
1928 (lambda (addr) (cdr addr))
1932 (setq news-reply-yank-from (or from "(nobody)"))
1933 (setq news-reply-yank-message-id
1934 (or message-id "(unknown Message-ID)"))
1936 ;; Gather the "to" addresses out of the follow-to list and remove
1938 (if (and follow-to (listp follow-to))
1939 (while (setq elt (assoc "To" follow-to))
1940 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1941 (setq follow-to (delq elt follow-to))))
1944 (if followup 'followup 'reply)
1946 (if (and follow-to (not (stringp follow-to))) sendto
1947 (or follow-to new-to sender "")))
1949 (if (zerop (length new-cc)) nil new-cc)
1952 (make-local-variable 'gnus-article-reply)
1953 (setq gnus-article-reply cur)
1954 (make-local-variable 'gnus-prev-winconf)
1955 (setq gnus-prev-winconf winconf)
1956 (make-local-variable 'gnus-reply-subject)
1957 (setq gnus-reply-subject subject)
1958 (make-local-variable 'gnus-in-reply-to)
1959 (setq gnus-in-reply-to message-of)
1961 (auto-save-mode auto-save-default)
1962 (gnus-inews-insert-gcc)
1963 (gnus-inews-insert-archive-gcc group)
1965 (when (and follow-to (listp follow-to))
1967 (gnus-inews-narrow-to-headers)
1968 (re-search-forward "^To:" nil t)
1972 ;; Insert the rest of the Follow-To headers.
1974 (goto-char (point-min))
1975 (if (not (re-search-forward
1976 (concat "^" (caar follow-to) ": *") nil t))
1979 (insert (caar follow-to) ": " (cdar follow-to) "\n"))
1982 (insert (cdar follow-to)))
1983 (setq follow-to (cdr follow-to)))
1985 (nnheader-insert-references references message-id)
1987 ;; Now the headers should be ok, so we do the yanking.
1988 (goto-char (point-min))
1990 (concat "^" (regexp-quote mail-header-separator) "$"))
1993 (gnus-configure-windows 'reply 'force)
1994 (let ((last (point))
1996 (if (not (listp yank))
1998 ;; Just a single article being yanked.
2000 (mail-yank-original nil))
2001 (or mail-yank-hooks mail-citation-hook
2002 (run-hooks 'news-reply-header-hook)))
2004 (save-window-excursion
2005 (set-buffer gnus-summary-buffer)
2006 (gnus-summary-select-article nil nil nil (car yank))
2007 (gnus-summary-remove-process-mark (car yank)))
2010 (gnus-copy-article-buffer)
2011 (mail-yank-original nil)
2013 (narrow-to-region (point-min) (point))
2014 (goto-char (mark t))
2015 (let ((news-reply-yank-from
2017 (set-buffer gnus-article-buffer)
2018 (or (mail-fetch-field "from") "(nobody)")))
2019 (news-reply-yank-message-id
2021 (set-buffer gnus-article-buffer)
2022 (or (mail-fetch-field "message-id")
2023 "(unknown Message-ID)"))))
2024 (or mail-yank-hooks mail-citation-hook
2025 (run-hooks 'news-reply-header-hook))
2026 (setq end (point-max)))))
2028 (setq yank (cdr yank))))
2031 (gnus-configure-windows 'reply-yank 'force))
2032 (run-hooks 'gnus-mail-hook)
2033 ;; Mark this buffer as unchanged.
2034 (set-buffer-modified-p nil)))))
2036 (defun gnus-mail-parse-comma-list ()
2039 (skip-chars-forward " ")
2042 (skip-chars-forward "^,")
2047 (narrow-to-region beg (point))
2050 (while (search-forward "\"" nil t)
2052 (if (zerop i) 2 i)) 2)))))
2053 (skip-chars-forward ",")
2054 (skip-chars-forward "^,"))
2055 (skip-chars-backward " ")
2057 (cons (buffer-substring beg (point))
2059 (skip-chars-forward "^,")
2060 (skip-chars-forward ", "))
2063 (defun gnus-new-news (&optional group inhibit-prompt)
2064 "Set up a *Post Gnus* buffer that points to GROUP.
2065 If INHIBIT-PROMPT, never prompt for a Subject."
2066 (let ((winconf (current-window-configuration))
2068 (when (and gnus-interactive-post
2069 (not inhibit-prompt)
2070 (not gnus-expert-user))
2071 (setq subject (read-string "Subject: ")))
2072 (pop-to-buffer gnus-post-news-buffer)
2075 ;; Let posting styles be configured.
2076 (gnus-configure-posting-styles)
2077 (news-setup nil subject nil (and group (gnus-group-real-name group)) nil)
2078 ;; Associate this buffer with the draft group.
2079 (gnus-enter-buffer-into-draft)
2080 (goto-char (point-min))
2082 (unless (re-search-forward
2083 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2084 (goto-char (point-max)))
2087 (gnus-inews-insert-bfcc)
2088 (gnus-inews-insert-gcc)
2089 (gnus-inews-insert-archive-gcc group)
2090 (gnus-inews-insert-signature)
2091 (and gnus-post-prepare-function
2092 (gnus-functionp gnus-post-prepare-function)
2093 (funcall gnus-post-prepare-function group))
2094 (run-hooks 'gnus-post-prepare-hook)
2095 (gnus-inews-set-point)
2096 (make-local-variable 'gnus-prev-winconf)
2097 (setq gnus-prev-winconf winconf)
2098 (gnus-inews-modify-mail-mode-map)
2099 (local-set-key "\C-c\C-c" 'gnus-inews-news)))
2101 (defun gnus-news-followup (&optional yank group)
2103 (set-buffer gnus-summary-buffer)
2104 (if (not (or (not gnus-novice-user)
2107 "Are you sure you want to post to all of USENET? ")))
2109 (let ((group (gnus-group-real-name (or group gnus-newsgroup-name)))
2110 (cur (cons (current-buffer) (cdr gnus-article-current)))
2111 (winconf (current-window-configuration))
2112 from subject date reply-to message-of
2113 references message-id sender follow-to sendto elt
2114 followup-to distribution newsgroups gnus-warning)
2115 (set-buffer (get-buffer-create gnus-post-news-buffer))
2117 ;; Associate this buffer with the draft group.
2118 (gnus-enter-buffer-into-draft)
2119 (if (and (buffer-modified-p)
2122 "Unsent message being composed; erase it? ")))
2126 (gnus-copy-article-buffer)
2128 (set-buffer gnus-article-copy)
2129 (nnheader-narrow-to-headers)
2130 (if (gnus-functionp gnus-followup-to-function)
2133 (funcall gnus-followup-to-function group))))
2134 (setq from (mail-fetch-field "from"))
2135 (setq date (or (mail-fetch-field "date")
2136 (mail-header-date gnus-current-headers)))
2137 (setq message-of (gnus-message-of from date))
2138 (setq subject (or (mail-fetch-field "subject") "none"))
2139 ;; Remove any (buggy) Re:'s that are present and make a
2141 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
2142 (setq subject (substring subject (match-end 0))))
2143 (setq subject (concat "Re: " subject))
2144 (setq references (mail-fetch-field "references"))
2145 (setq message-id (mail-fetch-field "message-id"))
2146 (when (and (setq gnus-warning (mail-fetch-field "gnus-warning"))
2147 (string-match "<[^>]+>" gnus-warning))
2148 (setq message-id (match-string 0 gnus-warning)))
2149 (setq followup-to (mail-fetch-field "followup-to"))
2150 (setq newsgroups (mail-fetch-field "newsgroups"))
2151 (setq distribution (mail-fetch-field "distribution"))
2152 ;; Remove bogus distribution.
2153 (and (stringp distribution)
2154 (string-match "world" distribution)
2155 (setq distribution nil))
2158 (setq news-reply-yank-from (or from "(nobody)"))
2159 (setq news-reply-yank-message-id
2160 (or message-id "(unknown Message-ID)"))
2162 ;; Gather the "to" addresses out of the follow-to list and remove
2164 (if (and follow-to (listp follow-to))
2165 (while (setq elt (assoc "Newsgroups" follow-to))
2166 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
2167 (setq follow-to (delq elt follow-to))))
2169 ;; Let posting styles be configured.
2170 (gnus-configure-posting-styles)
2176 gnus-use-followup-to
2177 (or (not (eq gnus-use-followup-to 'ask))
2178 (equal followup-to newsgroups)
2180 (format "Use Followup-To %s? " followup-to)))
2182 newsgroups group "")
2185 (make-local-variable 'gnus-article-reply)
2186 (setq gnus-article-reply cur)
2187 (make-local-variable 'gnus-prev-winconf)
2188 (setq gnus-prev-winconf winconf)
2189 (make-local-variable 'gnus-reply-subject)
2190 (setq gnus-reply-subject (mail-header-subject gnus-current-headers))
2191 (make-local-variable 'gnus-in-reply-to)
2192 (setq gnus-in-reply-to message-of)
2193 (when (and followup-to newsgroups)
2194 (make-local-variable 'gnus-newsgroup-followup)
2195 (setq gnus-newsgroup-followup
2196 (cons newsgroups followup-to)))
2198 (gnus-inews-insert-signature)
2200 (and gnus-post-prepare-function
2201 (gnus-functionp gnus-post-prepare-function)
2202 (funcall gnus-post-prepare-function group))
2203 (run-hooks 'gnus-post-prepare-hook)
2205 (auto-save-mode auto-save-default)
2206 (gnus-inews-modify-mail-mode-map)
2207 (local-set-key "\C-c\C-c" 'gnus-inews-news)
2209 (if (and follow-to (listp follow-to))
2211 (goto-char (point-min))
2212 (and (re-search-forward "^Newsgroups:" nil t)
2215 (insert (caar follow-to) ": " (cdar follow-to) "\n")
2216 (setq follow-to (cdr follow-to)))))
2218 ;; If a distribution existed, we use it.
2221 (mail-position-on-field "Distribution")
2222 (insert distribution)))
2224 (nnheader-insert-references references message-id)
2226 ;; Handle `gnus-auto-mail-to-author'.
2227 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
2228 ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
2229 (let ((to (if (if (eq gnus-auto-mail-to-author 'ask)
2230 (y-or-n-p "Also send mail to author? ")
2231 gnus-auto-mail-to-author)
2233 (set-buffer gnus-article-copy)
2234 (unless (gnus-group-get-parameter
2235 group 'broken-reply-to)
2236 (gnus-fetch-field "reply-to")))
2238 (x-mail (save-excursion
2239 (set-buffer gnus-article-copy)
2240 (gnus-fetch-field "x-mail-copy-to"))))
2241 ;; Deny sending copy if there's a negative X-Mail-Copy-To
2244 (if (and (string= x-mail "never")
2245 (not (eq gnus-auto-mail-to-author 'force)))
2248 ;; Insert a To or Cc header.
2250 (if (mail-fetch-field "To")
2253 (insert "Cc: " to "\n"))
2254 (mail-position-on-field "To")
2257 (gnus-inews-insert-bfcc)
2258 (gnus-inews-insert-gcc)
2259 (gnus-inews-insert-archive-gcc group)
2261 ;; Now the headers should be ok, so we do the yanking.
2262 (goto-char (point-min))
2264 (concat "^" (regexp-quote mail-header-separator) "$"))
2268 (gnus-configure-windows 'followup 'force)
2271 (let ((last (point))
2273 (if (not (listp yank))
2276 (mail-yank-original nil))
2277 (or mail-yank-hooks mail-citation-hook
2278 (run-hooks 'news-reply-header-hook)))
2280 (save-window-excursion
2281 (set-buffer gnus-summary-buffer)
2282 (gnus-summary-select-article nil nil nil (car yank))
2283 (gnus-summary-remove-process-mark (car yank)))
2285 (gnus-copy-article-buffer)
2286 (mail-yank-original nil)
2288 (or mail-yank-hooks mail-citation-hook
2289 (run-hooks 'news-reply-header-hook))
2291 (setq yank (cdr yank))))
2293 (gnus-configure-windows 'followup-yank 'force))
2295 (make-local-variable 'gnus-article-check-size)
2296 (setq gnus-article-check-size
2297 (cons (buffer-size) (gnus-article-checksum)))
2298 (gnus-inews-set-point))))))
2300 (defun gnus-message-of (from date)
2301 "Take a FROM and a DATE and return an IN-REPLY-TO."
2304 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2305 (concat (if stop-pos (substring from 0 stop-pos) from)
2307 (if (or (not date) (string= date ""))
2308 "(unknown date)" date)))))
2310 (defun gnus-mail-yank-original ()
2313 (mail-yank-original nil))
2314 (or mail-yank-hooks mail-citation-hook
2315 (run-hooks 'news-reply-header-hook)))
2317 (defun gnus-mail-send-and-exit (&optional dont-send)
2318 "Send the current mail and return to Gnus."
2320 (let* ((reply gnus-article-reply)
2321 (winconf gnus-prev-winconf)
2322 (address-group gnus-add-to-address)
2323 (to-address (and address-group
2324 (mail-fetch-field "to"))))
2325 (setq gnus-add-to-address nil)
2326 (let ((buffer-file-name nil))
2327 (or dont-send (gnus-mail-send)))
2329 (when (gnus-alive-p)
2330 ;; This mail group doesn't have a `to-list', so we add one
2333 (gnus-group-add-parameter address-group (cons 'to-list to-address)))
2334 (when (and (gnus-buffer-exists-p (car reply))
2337 (set-buffer (car reply))
2338 (gnus-summary-mark-article-as-replied (cdr reply))))
2339 (and winconf (set-window-configuration winconf)))))
2341 (defun gnus-kill-message-buffer ()
2342 "Kill the current buffer after dissociating it from the draft group."
2344 (when (gnus-y-or-n-p "Dissociate and kill the current buffer? ")
2345 (gnus-dissociate-buffer-from-draft)
2346 (let ((winconf gnus-prev-winconf))
2347 (kill-buffer (current-buffer))
2349 (set-window-configuration winconf)))))
2351 (defun gnus-put-message ()
2352 "Put the current message in some group and return to Gnus."
2354 (let ((reply gnus-article-reply)
2355 (winconf gnus-prev-winconf)
2356 (group gnus-newsgroup-name)
2359 (or (and group (not (gnus-group-read-only-p group)))
2360 (setq group (read-string "Put in group: " nil
2361 (gnus-writable-groups))))
2362 (and (gnus-gethash group gnus-newsrc-hashtb)
2363 (error "No such group: %s" group))
2368 (gnus-inews-narrow-to-headers)
2369 (let (gnus-deletable-headers)
2370 (if (eq major-mode 'mail-mode)
2371 (gnus-inews-insert-headers gnus-required-mail-headers)
2372 (gnus-inews-insert-headers)))
2373 (goto-char (point-max))
2374 (insert "Gcc: " group "\n")
2379 (if (get-buffer gnus-group-buffer)
2381 (if (gnus-buffer-exists-p (car-safe reply))
2383 (set-buffer (car reply))
2385 (gnus-summary-mark-article-as-replied
2387 (and winconf (set-window-configuration winconf))))))
2389 (defun gnus-forward-make-subject (buffer)
2392 (concat "[" (if (memq 'mail (assoc (symbol-name
2393 (car (gnus-find-method-for-group
2394 gnus-newsgroup-name)))
2395 gnus-valid-select-methods))
2396 (gnus-fetch-field "From")
2397 gnus-newsgroup-name)
2398 "] " (or (gnus-fetch-field "Subject") ""))))
2400 (defun gnus-forward-insert-buffer (buffer)
2403 ;; Put point where we want it before inserting the forwarded
2405 (if gnus-signature-before-forwarded-message
2406 (goto-char (point-max))
2407 (goto-char (point-min))
2409 (concat "^" (regexp-quote mail-header-separator) "$"))
2411 ;; Narrow to the area we are to insert.
2412 (narrow-to-region (point) (point))
2413 ;; Insert the separators and the forwarded buffer.
2414 (insert gnus-forward-start-separator)
2415 (insert-buffer-substring buffer)
2416 (goto-char (point-max))
2417 (insert gnus-forward-end-separator)
2418 (gnus-set-text-properties (point-min) (point-max) nil)
2419 ;; Remove all unwanted headers.
2420 (goto-char (point-min))
2423 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
2426 (goto-char (point-min))
2427 (let ((case-fold-search t))
2428 (delete-non-matching-lines gnus-forward-included-headers))))))
2430 (defun gnus-mail-forward (&optional buffer)
2431 "Forward the current message to another user using mail."
2432 (let* ((forward-buffer (or buffer (current-buffer)))
2433 (winconf (current-window-configuration))
2434 (subject (gnus-forward-make-subject forward-buffer)))
2435 (set-buffer (get-buffer-create gnus-mail-buffer))
2436 (if (and (buffer-modified-p)
2439 "Unsent message being composed; erase it? ")))
2442 (gnus-mail-setup 'forward nil subject)
2443 (make-local-variable 'gnus-prev-winconf)
2444 (setq gnus-prev-winconf winconf)
2445 (gnus-forward-insert-buffer forward-buffer)
2446 (goto-char (point-min))
2447 (re-search-forward "^To: ?" nil t)
2448 (gnus-configure-windows 'mail-forward 'force)
2449 ;; You have a chance to arrange the message.
2450 (run-hooks 'gnus-mail-forward-hook)
2451 (run-hooks 'gnus-mail-hook))))
2453 (defun gnus-forward-using-post (&optional buffer)
2455 (let* ((forward-buffer (or buffer (current-buffer)))
2456 (subject (gnus-forward-make-subject forward-buffer))
2457 (gnus-newsgroup-name nil))
2458 (gnus-post-news 'post nil nil nil nil subject)
2460 (gnus-forward-insert-buffer forward-buffer)
2461 ;; You have a chance to arrange the message.
2462 (run-hooks 'gnus-mail-forward-hook)))))
2464 (defun gnus-mail-other-window-using-mail ()
2465 "Compose mail other window using mail."
2466 (let ((winconf (current-window-configuration)))
2467 (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
2468 (gnus-inews-modify-mail-mode-map)
2469 (make-local-variable 'gnus-prev-winconf)
2470 (setq gnus-prev-winconf winconf)
2471 (run-hooks 'gnus-mail-hook)
2472 (gnus-configure-windows 'summary-mail 'force)))
2474 (defun gnus-article-mail (yank)
2475 "Send a reply to the address near point.
2476 If YANK is non-nil, include the original article."
2480 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
2481 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
2484 (switch-to-buffer gnus-summary-buffer)
2485 (gnus-mail-reply yank address)))))
2488 "Send a bug report to the Gnus maintainers."
2490 (let ((winconf (current-window-configuration)))
2491 (delete-other-windows)
2492 (switch-to-buffer "*Gnus Help Bug*")
2494 (insert gnus-bug-message)
2495 (goto-char (point-min))
2496 (pop-to-buffer "*Gnus Bug*")
2499 (mail-setup gnus-maintainer nil nil nil nil nil)
2500 (auto-save-mode auto-save-default)
2501 (make-local-variable 'gnus-prev-winconf)
2502 (setq gnus-prev-winconf winconf)
2503 (gnus-inews-modify-mail-mode-map)
2504 (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
2505 (goto-char (point-min))
2506 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2508 (insert (gnus-version) "\n")
2509 (insert (emacs-version))
2510 (insert "\n\n\n\n\n")
2512 (goto-char (point-min))
2513 (search-forward "Subject: " nil t)
2516 (defun gnus-bug-mail-send-and-exit ()
2517 "Send the bug message and exit."
2519 (let ((cur (current-buffer)))
2520 (and (get-buffer "*Gnus Help Bug*")
2521 (kill-buffer "*Gnus Help Bug*"))
2522 (gnus-mail-send-and-exit)
2523 (when (buffer-name cur)
2524 (kill-buffer cur))))
2526 (defun gnus-debug ()
2527 "Attemps to go through the Gnus source file and report what variables have been changed.
2528 The source file has to be in the Emacs load path."
2530 (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el" "nnmail.el"))
2531 file dirs expr olist sym)
2532 (message "Please wait while we snoop your variables...")
2535 (set-buffer (get-buffer-create " *gnus bug info*"))
2536 (buffer-disable-undo (current-buffer))
2539 (setq dirs load-path)
2541 (if (or (not (car dirs))
2542 (not (stringp (car dirs)))
2544 (setq file (concat (file-name-as-directory
2545 (car dirs)) (car files))))))
2546 (setq dirs (cdr dirs))
2548 (insert-file-contents file)
2549 (goto-char (point-min))
2550 (if (not (re-search-forward "^;;* *Internal variables" nil t))
2551 (message "Malformed sources in file %s" file)
2552 (narrow-to-region (point-min) (point))
2553 (goto-char (point-min))
2554 (while (setq expr (condition-case ()
2555 (read (current-buffer)) (error nil)))
2557 (and (eq (car expr) 'defvar)
2558 (stringp (nth 3 expr))
2559 (or (not (boundp (nth 1 expr)))
2560 (not (equal (eval (nth 2 expr))
2561 (symbol-value (nth 1 expr)))))
2562 (setq olist (cons (nth 1 expr) olist)))
2564 (setq files (cdr files)))
2565 (kill-buffer (current-buffer)))
2566 (when (setq olist (nreverse olist))
2567 (insert "------------------ Environment follows ------------------\n\n"))
2569 (if (boundp (car olist))
2574 ,(if (or (consp (setq sym (symbol-value (car olist))))
2576 (not (or (eq sym nil)
2578 (list 'quote (symbol-value (car olist)))
2579 (symbol-value (car olist)))))
2581 (format "(setq %s 'whatever)\n" (car olist)))))
2582 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
2583 (setq olist (cdr olist)))
2585 ;; Remove any null chars - they seem to cause trouble for some
2586 ;; mailers. (Byte-compiled output from the stuff above.)
2587 (goto-char (point-min))
2588 (while (re-search-forward "[\000\200]" nil t)
2589 (replace-match "" t t))))
2591 ;;; Treatment of rejected articles.
2594 (defun gnus-summary-resend-bounced-mail (fetch)
2595 "Re-mail the current message.
2596 This only makes sense if the current message is a bounce message than
2597 contains some mail you have written which has been bounced back to
2599 If FETCH, try to fetch the article that this is a reply to, if indeed
2602 (gnus-summary-select-article t)
2603 ;; Create a mail buffer.
2604 (gnus-new-empty-mail)
2606 (insert-buffer-substring gnus-article-buffer)
2607 (goto-char (point-min))
2608 (or (re-search-forward "--- *Original message.*\n" nil t)
2609 (and (search-forward "\n\n" nil t)
2610 (re-search-forward "^Return-Path:.*\n" nil t)))
2611 ;; We remove everything before the bounced mail.
2614 (if (re-search-forward "[^ \t]*:" nil t)
2620 (nnheader-narrow-to-headers)
2621 (nnheader-remove-header gnus-bounced-headers-junk t)
2622 (setq references (mail-fetch-field "references"))
2623 (goto-char (point-max))
2624 (insert mail-header-separator)))
2625 ;; If there are references, we fetch the article we answered to.
2628 (string-match "\\(<[^]+>\\)[ \t]*$" references)
2629 (gnus-summary-refer-article
2630 (substring references (match-beginning 1) (match-end 1)))
2632 (gnus-summary-show-all-headers)
2633 (gnus-configure-windows 'compose-bounce))))
2634 (goto-char (point-min)))
2638 (defun gnus-mail-send (&optional no-generated-headers)
2639 "Send the current buffer as mail.
2640 Headers will be generated before sending."
2642 (unless no-generated-headers
2646 (gnus-inews-narrow-to-headers)
2647 (gnus-inews-insert-headers gnus-required-mail-headers)
2648 (gnus-inews-remove-empty-headers))))
2650 ;; Remove the header separator.
2651 (goto-char (point-min))
2652 (and (re-search-forward
2653 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2654 (replace-match "" t t))
2655 ;; Run final inews hooks. This hook may do FCC.
2656 (run-hooks 'gnus-inews-article-hook)
2658 (nnheader-narrow-to-headers)
2659 (nnheader-remove-header "^[gf]cc:" t)
2661 (goto-char (point-min))
2662 (search-forward "\n\n")
2664 (insert mail-header-separator)
2666 (run-hooks 'gnus-message-sent-hook))
2668 (defun gnus-inews-modify-mail-mode-map ()
2669 (use-local-map (copy-keymap (current-local-map)))
2670 (gnus-local-set-keys
2671 "\C-c\C-c" gnus-mail-send-and-exit
2672 "\C-c\M-\C-p" gnus-put-message
2673 "\C-c\C-q" gnus-kill-message-buffer
2674 "\C-c\M-d" gnus-dissociate-buffer-from-draft
2675 "\C-c\C-d" gnus-associate-buffer-with-draft))
2677 (defun gnus-mail-setup (type &optional to subject in-reply-to cc
2678 replybuffer actions)
2679 ;; Let posting styles be configured.
2680 (gnus-configure-posting-styles)
2684 (eq gnus-mail-method 'mh)
2685 (and (or (eq type 'reply) (eq type 'followup))
2686 (eq gnus-mail-reply-method 'gnus-mail-reply-using-mhe))
2687 (and (eq type 'forward)
2688 (eq gnus-mail-forward-method 'gnus-mail-forward-using-mhe))
2690 (eq gnus-mail-other-window-method
2691 'gnus-mail-other-window-using-mhe)))
2692 'gnus-mh-mail-setup)
2694 (eq gnus-mail-method 'vm)
2695 (and (or (eq type 'reply) (eq type 'followup))
2696 (eq gnus-mail-reply-method 'gnus-mail-reply-using-vm))
2697 (and (eq type 'forward)
2698 (eq gnus-mail-forward-method 'gnus-mail-forward-using-vm))
2700 (eq gnus-mail-other-window-method
2701 'gnus-mail-other-window-using-vm)))
2702 'gnus-vm-mail-setup)
2704 (eq gnus-mail-method 'sendmail)
2705 (and (or (eq type 'reply) (eq type 'followup))
2706 (eq gnus-mail-reply-method 'gnus-mail-reply-using-mail))
2707 (and (eq type 'forward)
2708 (eq gnus-mail-forward-method 'gnus-mail-forward-using-mail))
2710 (eq gnus-mail-other-window-method
2711 'gnus-mail-other-window-using-mail)))
2712 'gnus-sendmail-mail-setup)
2714 (cond ((or (eq type 'reply) (eq type 'followup))
2715 gnus-mail-reply-method)
2717 gnus-mail-forward-method)
2719 gnus-mail-other-window-method))))
2720 to subject in-reply-to cc replybuffer actions)
2721 ;; Associate this mail buffer with the draft group.
2722 (gnus-enter-buffer-into-draft))
2724 (defun gnus-sendmail-mail-setup (to subject in-reply-to cc replybuffer actions)
2726 (mail-setup to subject nil cc replybuffer actions)
2727 (gnus-inews-set-point)
2728 (gnus-inews-modify-mail-mode-map))
2732 ;; Do Gcc handling, which copied the message over to some group.
2733 (defun gnus-inews-do-gcc (&optional gcc)
2736 (nnheader-narrow-to-headers)
2737 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
2738 (cur (current-buffer))
2739 end groups group method)
2741 (nnheader-remove-header "gcc")
2743 (setq groups (gnus-tokenize-header gcc " ,"))
2744 ;; Copy the article over to some group(s).
2745 (while (setq group (pop groups))
2748 (cond ((and (null (gnus-get-info group))
2749 (eq (car gnus-message-archive-method)
2751 (gnus-server-to-method
2752 (gnus-group-method group)))))
2753 ;; If the group doesn't exist, we assume
2754 ;; it's an archive group...
2755 gnus-message-archive-method)
2756 (t (gnus-find-method-for-group group)))))
2757 (unless (gnus-request-group group t method)
2758 (gnus-request-create-group group method))
2759 (gnus-check-server method)
2761 (nnheader-set-temp-buffer " *acc*")
2762 (insert-buffer-substring cur)
2763 (unless (condition-case ()
2764 (gnus-request-accept-article group t method)
2766 (gnus-message 1 "Couldn't store article in group %s: %s"
2767 group (gnus-status-message method))
2769 (kill-buffer (current-buffer)))))))))
2771 (defun gnus-inews-insert-bfcc ()
2772 "Insert Bcc and Fcc headers."
2774 ;; Handle author copy using BCC field.
2775 (when (and gnus-mail-self-blind
2776 (not (mail-fetch-field "bcc")))
2777 (mail-position-on-field "Bcc")
2778 (insert (if (stringp gnus-mail-self-blind)
2779 gnus-mail-self-blind
2780 (user-login-name))))
2781 ;; Handle author copy using FCC field.
2782 (when gnus-author-copy
2783 (mail-position-on-field "Fcc")
2784 (insert gnus-author-copy))))
2786 (defun gnus-inews-insert-gcc ()
2787 "Insert Gcc headers based on `gnus-outgoing-message-group'."
2790 (gnus-inews-narrow-to-headers)
2791 (let* ((group gnus-outgoing-message-group)
2793 ((gnus-functionp group)
2795 ((or (stringp group) (list group))
2799 (if (stringp gcc) gcc
2800 (mapconcat 'identity gcc " "))
2803 (defun gnus-inews-insert-archive-gcc (&optional group)
2804 "Insert the Gcc to say where the article is to be archived."
2805 (let* ((var gnus-message-archive-group)
2806 (group (or group gnus-newsgroup-name ""))
2810 ((null gnus-message-archive-method)
2814 ;; Just a single group.
2817 ;; We don't want this.
2819 ((and (listp var) (stringp (car var)))
2820 ;; A list of groups.
2822 ((gnus-functionp var)
2824 (funcall var group))
2826 ;; An alist of regexps/functions/forms.
2831 ((stringp (caar var))
2833 (when (string-match (caar var) group)
2835 ((gnus-functionp (car var))
2837 (funcall (car var) group))
2839 (eval (car var)))))))
2840 (setq var (cdr var)))
2843 (when (stringp groups)
2844 (setq groups (list groups)))
2847 (gnus-inews-narrow-to-headers)
2848 (goto-char (point-max))
2851 (insert (gnus-group-prefixed-name
2852 (pop groups) gnus-message-archive-method))
2856 ;;; Handling rejected (and postponed) news.
2858 (defun gnus-draft-group ()
2859 "Return the name of the draft group."
2860 (gnus-group-prefixed-name
2861 (file-name-nondirectory (directory-file-name gnus-draft-group-directory))
2862 (list 'nndraft gnus-draft-group-directory)))
2864 (defun gnus-make-draft-group ()
2865 "Make the draft group or die trying."
2866 (let* ((method `(nndraft "private"
2868 ,gnus-draft-group-directory)))
2869 (group (gnus-draft-group)))
2870 (or (gnus-gethash group gnus-newsrc-hashtb)
2871 (gnus-group-make-group (gnus-group-real-name group) method)
2872 (error "Can't create the draft group"))
2873 (gnus-check-server method)
2876 (defun gnus-associate-buffer-with-draft (&optional generate silent)
2877 "Enter the current buffer into the draft group."
2879 (when (gnus-request-accept-article (gnus-make-draft-group) t)
2881 ;; This function does the proper marking of articles.
2882 (gnus-mail-send-and-exit 'dont-send))
2883 (set-buffer-modified-p nil)))
2885 (defun gnus-enter-buffer-into-draft ()
2886 (when gnus-use-draft
2888 ;; Make sure the draft group exists.
2889 (gnus-make-draft-group)
2890 ;; Associate the buffer with the draft group.
2891 (let ((article (gnus-request-associate-buffer (gnus-draft-group))))
2892 ;; Arrange for deletion of the draft after successful sending.
2893 (make-local-variable 'gnus-message-sent-hook)
2894 (setq gnus-message-sent-hook
2897 (let ((gnus-verbose-backends nil))
2898 (gnus-request-expire-articles
2899 (quote ,(list article))
2900 ,(gnus-draft-group) t)))))))))
2902 (defun gnus-dissociate-buffer-from-draft ()
2903 "Disable auto-saving and association to the draft group of the current buffer."
2905 (run-hooks 'gnus-message-sent-hook)
2906 (setq buffer-file-name nil)
2907 (setq buffer-auto-save-file-name nil))
2909 (defun gnus-summary-send-draft ()
2910 "Enter a mail/post buffer to edit and send the draft."
2912 (gnus-set-global-variables)
2913 (unless (equal gnus-newsgroup-name (gnus-draft-group))
2914 (error "This function can only be used in the draft buffer"))
2916 (if (not (setq buf (gnus-request-restore-buffer
2917 (gnus-summary-article-number) gnus-newsgroup-name)))
2918 (error "Couldn't restore the article")
2919 (setq point (point))
2920 (switch-to-buffer buf)
2921 (gnus-inews-modify-mail-mode-map)
2922 (when (eq major-mode 'news-reply-mode)
2923 (local-set-key "\C-c\C-c" 'gnus-inews-news))
2924 (gnus-enter-buffer-into-draft)
2925 ;; Insert the separator.
2926 (goto-char (point-min))
2927 (search-forward "\n\n")
2929 (insert mail-header-separator)
2930 ;; Configure windows.
2931 (let ((gnus-draft-buffer (current-buffer)))
2932 (gnus-configure-windows 'draft t)
2933 (goto-char (point))))))
2935 (defun gnus-configure-posting-styles ()
2936 "Configure posting styles according to `gnus-posting-styles'."
2937 (let ((styles gnus-posting-styles)
2938 (gnus-newsgroup-name (or gnus-newsgroup-name ""))
2939 style match variable attribute value value-value)
2940 ;; Go through all styles and look for matches.
2942 (setq style (pop styles)
2944 (when (cond ((stringp match)
2945 ;; Regexp string match on the group name.
2946 (string-match match gnus-newsgroup-name))
2947 ((or (symbolp match)
2948 (gnus-functionp match))
2949 (cond ((gnus-functionp match)
2950 ;; Function to be called.
2953 ;; Variable to be checked.
2954 (symbol-value match))))
2956 ;; This is a form to be evaled.
2958 ;; We have a match, so we set the variables.
2960 (setq attribute (pop style)
2961 value (cdr attribute))
2962 ;; We find the variable that is to be modified.
2963 (if (and (not (stringp (car attribute)))
2964 (not (setq variable (cdr (assq (car attribute)
2965 gnus-posting-style-alist)))))
2966 (message "Couldn't find attribute %s" (car attribute))
2967 ;; We set the variable.
2969 (cond ((stringp value)
2971 ((or (symbolp value)
2972 (gnus-functionp value))
2973 (cond ((gnus-functionp value)
2976 (symbol-value value))))
2981 ;; This is an ordinary variable.
2982 (make-local-variable variable)
2983 (set variable value-value))
2984 ;; This is a header to be added to the headers when
2987 (make-local-variable gnus-required-headers)
2988 (make-local-variable gnus-required-mail-headers)
2989 (push (cons (car attribute) value-value)
2990 gnus-required-headers)
2991 (push (cons (car attribute) value-value)
2992 gnus-required-mail-headers)))))))))
2994 (defun gnus-inews-set-point ()
2995 "Move point to where the user probably wants to find it."
2996 (gnus-inews-narrow-to-headers)
2998 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
2999 (search-backward ":" )
3003 (goto-char (point-max))
3006 (unless (looking-at "$")
3007 (forward-line 2)))))
3009 ;;; Allow redefinition of functions.
3015 ;;; gnus-msg.el ends here