1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
5 ;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
31 (eval-when-compile (require 'cl))
33 (defvar gnus-organization-file "/usr/lib/news/organization"
34 "*Local news organization file.")
36 (defvar gnus-prepare-article-hook nil
37 "*A hook called after preparing body, but before preparing header headers.")
39 (defvar gnus-post-prepare-function nil
40 "*Function that is run after a post buffer has been prepared.
41 It is called with the name of the newsgroup that is posted to. It
42 might be used, for instance, for inserting signatures based on the
43 newsgroup name. (In that case, `gnus-signature-file' and
44 `mail-signature' should both be set to nil).")
46 (defvar gnus-post-prepare-hook nil
47 "*Hook that is run after a post buffer has been prepared.
48 If you want to insert the signature, you might put
49 `gnus-inews-insert-signature' in this hook.")
51 (defvar gnus-use-followup-to t
52 "*Specifies what to do with Followup-To header.
53 If nil, ignore the header. If it is t, use its value, but ignore
54 `poster'. If it is the symbol `ask', query the user before posting.
55 If it is the symbol `use', always use the value.")
57 (defvar gnus-followup-to-function nil
58 "*A variable that contains a function that returns a followup address.
59 The function will be called in the buffer of the article that is being
60 followed up. The buffer will be narrowed to the headers of the
61 article. To pick header headers, one might use `mail-fetch-field'. The
62 function will be called with the name of the current newsgroup as the
65 Here's an example `gnus-followup-to-function':
67 (setq gnus-followup-to-function
69 (cond ((string= group \"mail.list\")
70 (or (mail-fetch-field \"sender\")
71 (mail-fetch-field \"from\")))
73 (or (mail-fetch-field \"reply-to\")
74 (mail-fetch-field \"from\"))))))")
76 (defvar gnus-reply-to-function nil
77 "*A variable that contains a function that returns a reply address.
78 See the `gnus-followup-to-function' variable for an explanation of how
79 this variable is used.
81 This function should return a string that will be used to fill in the
82 header. This function may also return a list. In that case, every
83 list element should be a cons where the first car should be a string
84 with the header name, and the cdr should be a string with the header
87 (defvar gnus-author-copy (getenv "AUTHORCOPY")
88 "*Save outgoing articles in this file.
89 Initialized from the AUTHORCOPY environment variable.
91 If this variable begins with the character \"|\", outgoing articles
92 will be piped to the named program. It is possible to save an article
93 in an MH folder as follows:
95 \(setq gnus-author-copy \"|/usr/local/lib/mh/rcvstore +Article\")
97 If the first character is not a pipe, articles are saved using the
98 function specified by the `gnus-author-copy-saver' variable.")
100 (defvar gnus-mail-self-blind nil
101 "*Non-nil means insert a BCC header in all outgoing articles.
102 This will result in having a copy of the article mailed to yourself.
103 The BCC header is inserted when the post buffer is initialized, so you
104 can remove or alter the BCC header to override the default.")
106 (defvar gnus-author-copy-saver (function rmail-output)
107 "*A function called to save outgoing articles.
108 This function will be called with the same of the file to store the
109 article in. The default function is `rmail-output' which saves in Unix
112 (defvar gnus-outgoing-message-group nil
113 "*All outgoing messages will be put in this group.
114 If you want to store all your outgoing mail and articles in the group
115 \"nnml:archive\", you set this variable to that value. This variable
116 can also be a list of group names.
118 If you want to have greater control over what group to put each
119 message in, you can set this variable to a function that checks the
120 current newsgroup name and then returns a suitable group name (or list
123 (defvar gnus-mailing-list-groups nil
124 "*Regexp matching groups that are really mailing lists.
125 This is useful when you're reading a mailing list that has been
126 gatewayed to a newsgroup, and you want to followup to an article in
129 (defvar gnus-draft-group-directory
131 (concat (file-name-as-directory gnus-article-save-directory)
133 "*The directory where draft messages will be stored.")
135 (defvar gnus-posting-styles nil
136 "*Alist of styles to use when posting.")
138 (defvar gnus-posting-style-alist
139 '((organization . gnus-organization-file)
140 (signature . gnus-signature-file)
141 (from . gnus-user-from-line)))
143 (defvar gnus-user-login-name nil
144 "*The login name of the user.
145 Got from the function `user-login-name' if undefined.")
147 (defvar gnus-user-full-name nil
148 "*The full name of the user.
149 Got from the NAME environment variable if undefined.")
151 (defvar gnus-user-from-line nil
152 "*Your full, complete e-mail address.
153 Overrides the other Gnus variables if it is non-nil.
155 Here are two example values of this variable:
157 \"Lars Magne Ingebrigtsen <larsi@ifi.uio.no>\"
161 \"larsi@ifi.uio.no (Lars Magne Ingebrigtsen)\"
163 The first version is recommended, but the name has to be quoted if it
164 contains non-alphanumerical characters.")
166 (defvar gnus-signature-file "~/.signature"
167 "*Your signature file.
168 If the variable is a string that doesn't correspond to a file, the
169 string itself is inserted.")
171 (defvar gnus-signature-function nil
172 "*A function that should return a signature file name.
173 The function will be called with the name of the newsgroup being
175 If the function returns a string that doesn't correspond to a file, the
176 string itself is inserted.
177 If the function returns nil, the `gnus-signature-file' variable will
180 (defvar gnus-forward-start-separator
181 "------- Start of forwarded message -------\n"
182 "*Delimiter inserted before forwarded messages.")
184 (defvar gnus-forward-end-separator
185 "------- End of forwarded message -------\n"
186 "*Delimiter inserted after forwarded messages.")
188 (defvar gnus-signature-before-forwarded-message t
189 "*If non-nil, put the signature before any included forwarded message.")
191 (defvar gnus-required-headers
192 '(From Date Newsgroups Subject Message-ID Organization Lines X-Newsreader)
193 "*Headers to be generated or prompted for when posting an article.
194 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
195 Message-ID. Organization, Lines, In-Reply-To and X-Newsreader are
196 optional. If you want Gnus not to insert some header, remove it from
199 (defvar gnus-required-mail-headers
200 '(From Date To Subject (optional . In-Reply-To) Message-ID Organization Lines)
201 "*Headers to be generated or prompted for when mailing a message.
202 RFC822 required that From, Date, To, Subject and Message-ID be
203 included. Organization, Lines and X-Mailer are optional.")
205 (defvar gnus-deletable-headers '(Message-ID Date)
206 "*Headers to be deleted if they already exists and were generated by Gnus previously.")
208 (defvar gnus-removable-headers '(NNTP-Posting-Host Bcc Xref)
209 "*Headers to be removed unconditionally before posting.")
211 (defvar gnus-check-before-posting
212 '(subject-cmsg multiple-headers sendsys message-id from
213 long-lines control-chars size new-text
214 signature approved sender)
215 "In non-nil, Gnus will attempt to run some checks on outgoing posts.
216 If this variable is t, Gnus will check everything it can. If it is a
217 list, then those elements in that list will be checked.")
219 (defvar gnus-delete-supersedes-headers
220 "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Supersedes:\\|^Xref:\\|^Lines:"
221 "*Header lines matching this regexp will be deleted before posting.
222 It's best to delete old Path and Date headers before posting to avoid
225 (defvar gnus-auto-mail-to-author nil
226 "*If non-nil, mail the authors of articles a copy of your follow-ups.
227 If this variable is `ask', the user will be prompted for whether to
228 mail a copy. The string given by `gnus-mail-courtesy-message' will be
229 inserted at the beginning of the mail copy.")
231 ;; Added by Ethan Bradford <ethanb@ptolemy.astro.washington.edu>.
232 (defvar gnus-mail-courtesy-message
233 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
234 "*This is inserted at the start of a mailed copy of a posted message.
235 If this variable is nil, no such courtesy message will be added.")
237 (defvar gnus-mail-reply-method (function gnus-mail-reply-using-mail)
238 "*Function to compose a reply.
239 Three pre-made functions are `gnus-mail-reply-using-mail' (sendmail);
240 `gnus-mail-reply-using-mhe' (MH-E); and `gnus-mail-reply-using-vm'.")
242 (defvar gnus-mail-forward-method (function gnus-mail-forward-using-mail)
243 "*Function to forward the current message to another user.
244 Three pre-made functions are `gnus-mail-forward-using-mail' (sendmail);
245 `gnus-mail-forward-using-mhe' (MH-E); and `gnus-mail-forward-using-vm'.")
247 (defvar gnus-mail-other-window-method 'gnus-mail-other-window-using-mail
248 "*Function to compose mail in the other window.
249 Three pre-made functions are `gnus-mail-other-window-using-mail'
250 (sendmail); `gnus-mail-other-window-using-mhe' (MH-E); and
251 `gnus-mail-other-window-using-vm'.")
253 (defvar gnus-inews-article-function 'gnus-inews-article
254 "*Function to post an article.")
256 (defvar gnus-bounced-headers-junk "^\\(Received\\):"
257 "*Regexp that matches headers to be removed in resent bounced mail.")
259 (defvar gnus-inews-article-hook (list 'gnus-inews-do-fcc)
260 "*A hook called before finally posting an article.
261 The default hook (`gnus-inews-do-fcc') does FCC processing (ie. saves
262 the article to a file).")
264 (defvar gnus-inews-article-header-hook nil
265 "*A hook called after inserting the headers in an article to be posted.
266 The hook is called from the *post-news* buffer, narrowed to the
269 (defvar gnus-mail-hook nil
270 "*A hook called as the last thing after setting up a mail buffer.")
272 (defvar gnus-message-sent-hook nil
273 "*A hook run after an article has been sent (or attempted sent).")
275 ;;; Internal variables.
277 (defvar gnus-post-news-buffer "*post-news*")
278 (defvar gnus-mail-buffer "*mail*")
279 (defvar gnus-summary-send-map nil)
280 (defvar gnus-send-bounce-map nil)
281 (defvar gnus-article-copy nil)
282 (defvar gnus-reply-subject nil)
283 (defvar gnus-add-to-address nil)
284 (defvar gnus-in-reply-to nil)
287 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
288 (autoload 'news-setup "rnewspost")
289 (autoload 'news-reply-mode "rnewspost")
290 (autoload 'rmail-output "rmailout"))
294 ;;; Gnus Posting Functions
297 (define-prefix-command 'gnus-summary-send-map)
298 (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
299 (define-key gnus-summary-send-map "p" 'gnus-summary-post-news)
300 (define-key gnus-summary-send-map "f" 'gnus-summary-followup)
301 (define-key gnus-summary-send-map "F" 'gnus-summary-followup-with-original)
302 (define-key gnus-summary-send-map "b" 'gnus-summary-followup-and-reply)
303 (define-key gnus-summary-send-map "B" 'gnus-summary-followup-and-reply-with-original)
304 (define-key gnus-summary-send-map "c" 'gnus-summary-cancel-article)
305 (define-key gnus-summary-send-map "s" 'gnus-summary-supersede-article)
306 (define-key gnus-summary-send-map "r" 'gnus-summary-reply)
307 (define-key gnus-summary-send-map "R" 'gnus-summary-reply-with-original)
308 (define-key gnus-summary-send-map "m" 'gnus-summary-mail-other-window)
309 (define-key gnus-summary-send-map "u" 'gnus-uu-post-news)
310 (define-key gnus-summary-send-map "om" 'gnus-summary-mail-forward)
311 (define-key gnus-summary-send-map "op" 'gnus-summary-post-forward)
312 (define-key gnus-summary-send-map "Om" 'gnus-uu-digest-mail-forward)
313 (define-key gnus-summary-send-map "Op" 'gnus-uu-digest-post-forward)
315 (define-prefix-command 'gnus-send-bounce-map)
316 (define-key gnus-summary-send-map "D" 'gnus-send-bounce-map)
317 (define-key gnus-send-bounce-map "b" 'gnus-summary-resend-bounced-mail)
318 (define-key gnus-send-bounce-map "c" 'gnus-summary-send-draft)
319 (define-key gnus-send-bounce-map "r" 'gnus-summary-resend-message)
321 ;;; Internal functions.
323 (defun gnus-number-base36 (num len)
324 (if (if (< len 0) (<= num 0) (= len 0))
326 (concat (gnus-number-base36 (/ num 36) (1- len))
327 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
330 ;;; Post news commands of Gnus group mode and summary mode
332 (defun gnus-group-mail ()
333 "Start composing a mail."
336 ;; We might want to prompt here.
337 (when (and gnus-interactive-post
338 (not gnus-expert-user))
339 (read-string "To: "))))
341 (defun gnus-group-post-news (&optional arg)
343 The newsgroup under the cursor is used as the group to post to.
345 If you wish to get an empty post buffer, use a prefix ARG. You can
346 also do this by calling this function from the bottom of the Group
349 (let ((gnus-newsgroup-name nil)
350 (group (unless arg (gnus-group-group-name)))
352 ;; We might want to prompt here.
353 (when (and gnus-interactive-post
354 (not gnus-expert-user))
355 (setq gnus-newsgroup-name
357 (completing-read "Group: " gnus-active-hashtb nil nil
359 (gnus-post-news 'post group nil gnus-article-buffer)))
361 (defun gnus-summary-post-news ()
364 (gnus-set-global-variables)
365 (gnus-post-news 'post gnus-newsgroup-name))
367 (defun gnus-summary-followup (yank &optional yank-articles)
368 "Compose a followup to an article.
369 If prefix argument YANK is non-nil, original article is yanked automatically."
371 (gnus-set-global-variables)
372 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
373 (save-window-excursion
374 (gnus-summary-select-article))
375 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
376 (gnus-newsgroup-name gnus-newsgroup-name))
377 ;; Check Followup-To: poster.
378 (set-buffer gnus-article-buffer)
379 (if (and gnus-use-followup-to
380 (string-equal "poster" (gnus-fetch-field "followup-to"))
381 (or (not (memq gnus-use-followup-to '(t ask)))
383 "Do you want to ignore `Followup-To: poster'? "))))
384 ;; Mail to the poster.
385 (gnus-summary-reply yank)
387 (gnus-post-news nil gnus-newsgroup-name
388 headers gnus-article-buffer
389 (or yank-articles (not (not yank)))))))
391 (defun gnus-summary-followup-with-original (n)
392 "Compose a followup to an article and include the original article."
394 (gnus-summary-followup t (gnus-summary-work-articles n)))
396 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
397 (defun gnus-summary-followup-and-reply (yank &optional yank-articles)
398 "Compose a followup and do an auto mail to author."
400 (gnus-set-global-variables)
401 (let ((gnus-auto-mail-to-author 'force))
402 (gnus-summary-followup yank yank-articles)))
404 (defun gnus-summary-followup-and-reply-with-original (n)
405 "Compose a followup, include the original, and do an auto mail to author."
407 (gnus-summary-followup-and-reply t (gnus-summary-work-articles n)))
409 (defun gnus-summary-cancel-article (n)
410 "Cancel an article you posted."
412 (gnus-set-global-variables)
413 (let ((articles (gnus-summary-work-articles n)))
415 (gnus-summary-select-article t nil nil (car articles))
416 (and (gnus-eval-in-buffer-window gnus-article-buffer (gnus-cancel-news))
417 (gnus-summary-mark-as-read (car articles) gnus-canceled-mark))
418 (gnus-summary-remove-process-mark (car articles))
419 (gnus-article-hide-headers-if-wanted)
420 (setq articles (cdr articles)))))
422 (defun gnus-summary-supersede-article ()
423 "Compose an article that will supersede a previous article.
424 This is done simply by taking the old article and adding a Supersedes
425 header line with the old Message-ID."
427 (gnus-set-global-variables)
428 (gnus-summary-select-article t)
429 ;; Check whether the user owns the article that is to be superseded.
430 (unless (string-equal
431 (downcase (mail-strip-quoted-names
432 (mail-header-from gnus-current-headers)))
433 (downcase (mail-strip-quoted-names (gnus-inews-user-name))))
434 (error "This article is not yours."))
435 ;; Get a normal *post-news* buffer.
436 (gnus-new-news gnus-newsgroup-name t)
438 (insert-buffer-substring gnus-original-article-buffer)
439 (gnus-narrow-to-headers)
440 ;; Remove unwanted headers.
441 (when gnus-delete-supersedes-headers
442 (nnheader-remove-header gnus-delete-supersedes-headers t))
443 (goto-char (point-min))
444 (if (not (re-search-forward "^Message-ID: " nil t))
445 (error "No Message-ID in this article")
446 (replace-match "Supersedes: " t t))
447 (goto-char (point-max))
448 (insert mail-header-separator)
454 (defalias 'sendnews 'gnus-post-news)
457 (defalias 'postnews 'gnus-post-news)
459 (defun gnus-copy-article-buffer (&optional article-buffer)
460 ;; make a copy of the article buffer with all text properties removed
461 ;; this copy is in the buffer gnus-article-copy.
462 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
463 ;; this buffer should be passed to all mail/news reply/post routines.
464 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
465 (buffer-disable-undo gnus-article-copy)
466 (or (memq gnus-article-copy gnus-buffer-list)
467 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
468 (let ((article-buffer (or article-buffer gnus-article-buffer)))
469 (if (and (get-buffer article-buffer)
470 (buffer-name (get-buffer article-buffer)))
472 (set-buffer article-buffer)
474 (copy-to-buffer gnus-article-copy (point-min) (point-max))
475 (set-text-properties (point-min) (point-max)
476 nil gnus-article-copy)))))
478 (defun gnus-post-news (post &optional group header article-buffer yank subject)
479 "Begin editing a new USENET news article to be posted.
480 Type \\[describe-mode] in the buffer to get a list of commands."
481 (interactive (list t))
482 (let* ((group (or group gnus-newsgroup-name))
484 to-address to-group mailing-list to-list)
486 (setq to-address (gnus-group-get-parameter group 'to-address)
487 to-group (gnus-group-get-parameter group 'to-group)
488 to-list (gnus-group-get-parameter group 'to-list)
489 mailing-list (when gnus-mailing-list-groups
490 (string-match gnus-mailing-list-groups group))
491 group (gnus-group-real-name group)))
493 (and (gnus-member-of-valid 'post (or pgroup gnus-newsgroup-name))
499 (gnus-new-news (or to-group group))
500 (gnus-news-followup yank (or to-group group)))
504 (gnus-new-mail (or to-address to-list))
505 ;; Arrange for mail groups that have no `to-address' to
506 ;; get that when the user sends off the mail.
508 (make-local-variable 'gnus-add-to-address)
509 (setq gnus-add-to-address group)))
510 (gnus-mail-reply yank to-address 'followup)))))
512 (defun gnus-inews-news (&optional use-group-method)
513 "Send a news message.
514 If given a prefix, and the group is a foreign group, this function
515 will attempt to use the foreign server to post the article."
517 (or gnus-current-select-method
518 (setq gnus-current-select-method gnus-select-method))
519 (let* ((case-fold-search nil)
520 (reply gnus-article-reply)
523 (gnus-start-news-server) ;Use default server.
525 (goto-char (point-min))
526 (run-hooks 'news-inews-hook)
529 (gnus-message 5 "Posting to USENET...")
530 (setq post-result (funcall gnus-inews-article-function use-group-method))
531 (cond ((eq post-result 'illegal)
535 (gnus-message 5 "Posting to USENET...done")
536 (if (gnus-buffer-exists-p (car-safe reply))
539 (set-buffer gnus-summary-buffer)
540 (gnus-summary-mark-article-as-replied
542 (set-buffer-modified-p nil))
544 ;; We cannot signal an error.
548 1 "Article rejected: %s"
550 (gnus-post-method gnus-newsgroup-name use-group-method))))))
552 (let ((conf gnus-prev-winconf))
555 ;; Restore last window configuration.
556 (and conf (set-window-configuration conf))))))
558 (defun gnus-inews-narrow-to-headers ()
561 (goto-char (point-min))
562 (or (and (re-search-forward
563 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
567 (defun gnus-inews-send-mail-copy ()
568 ;; Mail the message if To, Bcc or Cc exists.
569 (let* ((types '("to" "bcc" "cc"))
571 (buffer (current-buffer))
575 (gnus-inews-narrow-to-headers)
578 (or (mail-fetch-field (car ty) nil t)
579 (setq types (delete (car ty) types)))
583 ;; We do not want to send mail.
585 (gnus-message 5 "Sending via mail...")
588 ;; We copy the article over to a temp buffer since we are
589 ;; going to modify it a little.
590 (nnheader-set-temp-buffer " *Gnus-mailing*")
591 (insert-buffer-substring buffer)
592 ;; We remove Fcc, because we don't want the mailer to see
594 (gnus-inews-narrow-to-headers)
595 (nnheader-remove-header "fcc")
597 ;; Insert the X-Courtesy-Message header.
598 (and (or (member "to" types)
601 (goto-char (point-max))
602 (insert "Posted-To: "
603 (mail-fetch-field "newsgroups") "\n")))
607 (if (and gnus-mail-courtesy-message
608 (or (member "to" types)
609 (member "cc" types)))
610 ;; We only want to insert the courtesy mail message if
611 ;; we use To or Cc; Bcc should not have one. Well, if
612 ;; both Bcc and To are present, it will get one
615 ;; Insert "courtesy" mail message.
616 (goto-char (point-min))
618 (concat "^" (regexp-quote mail-header-separator) "$"))
620 (insert gnus-mail-courtesy-message)))
623 (kill-buffer (current-buffer))
624 (gnus-message 5 "Sending via mail...done"))))))
626 (defun gnus-inews-remove-headers-after-mail ()
629 (let ((case-fold-search t))
630 (gnus-inews-narrow-to-headers)
631 ;; Remove Bcc completely.
632 (nnheader-remove-header "bcc")
633 ;; We transform To and Cc headers to avoid re-mailing if the user
634 ;; accidentally (or purposefully) leans on the `C-c C-c' keys
635 ;; and the news server rejects the posting.
636 (while (re-search-forward "^\\(to\\|[bcf]cc\\|cc\\):" nil t)
641 (defun gnus-inews-dex-headers ()
642 "Remove \"X-\" prefixes from To and Cc headers."
645 (let ((case-fold-search t))
646 (gnus-narrow-to-headers)
647 (while (re-search-forward "^X-\\(to\\|[bcf]cc\\|cc\\):" nil t)
652 (defun gnus-inews-remove-empty-headers ()
653 "Remove empty headers from news and mail.
654 The buffer should be narrowed to the headers before this function is
657 (goto-char (point-min))
658 (while (re-search-forward "^[^ \t:]+:\\([ \t]*\n\\)+[^ \t]" nil t)
659 (delete-region (match-beginning 0) (1- (match-end 0)))
660 (beginning-of-line))))
662 (defun gnus-inews-check-post ()
663 "Check whether the post looks ok."
665 (not gnus-check-before-posting)
667 ;; We narrow to the headers and check them first.
670 (goto-char (point-min))
675 (concat "^" (regexp-quote mail-header-separator) "$"))
676 (match-beginning 0)))
677 (goto-char (point-min))
679 ;; Check for commands in Subject.
681 (gnus-check-before-posting 'subject-cmsg)
683 (if (string-match "^cmsg " (mail-fetch-field "subject"))
685 "The control code \"cmsg \" is in the subject. Really post? ")
687 ;; Check for multiple identical headers.
688 (or (gnus-check-before-posting 'multiple-headers)
691 (while (and (not found) (re-search-forward "^[^ \t:]+: "
694 (or (re-search-forward
695 (concat "^" (setq found
698 (- (match-end 0) 2))))
703 (format "Multiple %s headers. Really post? " found))
705 ;; Check for Version and Sendsys.
706 (or (gnus-check-before-posting 'sendsys)
708 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
710 (format "The article contains a %s command. Really post? "
711 (buffer-substring (match-beginning 0)
712 (1- (match-end 0)))))
714 ;; Check for Approved.
715 (or (gnus-check-before-posting 'approved)
717 (if (re-search-forward "^Approved:" nil t)
719 "The article contains an Approved header. Really post? ")
721 ;; Check the Message-ID header.
722 (or (gnus-check-before-posting 'message-id)
724 (let* ((case-fold-search t)
725 (message-id (mail-fetch-field "message-id")))
727 (and (string-match "@" message-id)
728 (string-match "@[^\\.]*\\." message-id))
731 "The Message-ID looks strange: \"%s\". Really post? "
733 ;; Check the From header.
734 (or (gnus-check-before-posting 'from)
736 (let* ((case-fold-search t)
737 (from (mail-fetch-field "from")))
740 (gnus-y-or-n-p "There is no From line. Really post? "))
741 ((not (string-match "@[^\\.]*\\." from))
744 "The address looks strange: \"%s\". Really post? " from)))
745 ((string-match "(.*).*(.*)" from)
748 "The From header looks strange: \"%s\". Really post? "
750 ((string-match "<[^>]+> *$" from)
751 (let ((name (substring from 0 (match-beginning 0))))
753 (string-match "^ *\"[^\"]*\" *$" name)
754 (not (string-match "[][.!()<>@,;:\\]" name))
757 "The From header name has bogus characters. Really post? "
761 ;; Check for long lines.
762 (or (gnus-check-before-posting 'long-lines)
764 (goto-char (point-min))
766 (concat "^" (regexp-quote mail-header-separator) "$"))
770 (< (current-column) 80))
771 (zerop (forward-line 1))))
776 "You have lines longer than 79 characters. Really post? ")))))
777 ;; Check for control characters.
778 (or (gnus-check-before-posting 'control-chars)
780 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
782 "The article contains control characters. Really post? ")
784 ;; Check excessive size.
785 (or (gnus-check-before-posting 'size)
786 (if (> (buffer-size) 60000)
788 (format "The article is %d octets long. Really post? "
791 ;; Use the (size . checksum) variable to see whether the
792 ;; article is empty or has only quoted text.
794 (gnus-check-before-posting 'new-text)
795 (if (and (= (buffer-size) (car gnus-article-check-size))
796 (= (gnus-article-checksum) (cdr gnus-article-check-size)))
798 "It looks like there's no new text in your article. Really post? ")
800 ;; Check the length of the signature.
801 (or (gnus-check-before-posting 'signature)
803 (goto-char (point-max))
804 (if (not (re-search-backward gnus-signature-separator nil t))
806 (if (> (count-lines (point) (point-max)) 5)
809 "Your .sig is %d lines; it should be max 4. Really post? "
810 (count-lines (point) (point-max))))
813 (defun gnus-article-checksum ()
817 (setq sum (logxor sum (following-char)))
821 ;; Returns non-nil if this type is not to be checked.
822 (defun gnus-check-before-posting (type)
824 (or (not gnus-check-before-posting)
825 (if (listp gnus-check-before-posting)
826 (memq type gnus-check-before-posting)
829 (defun gnus-cancel-news ()
830 "Cancel an article you posted."
832 (if (or gnus-expert-user
833 (gnus-yes-or-no-p "Do you really want to cancel this article? "))
838 (or (gnus-member-of-valid 'post gnus-newsgroup-name)
839 (error "This backend does not support canceling"))
841 ;; Get header info. from original article.
843 (gnus-article-show-all-headers)
844 (goto-char (point-min))
845 (search-forward "\n\n" nil 'move)
846 (narrow-to-region (point-min) (point))
847 (setq from (mail-fetch-field "from"))
848 (setq newsgroups (mail-fetch-field "newsgroups"))
849 (setq message-id (mail-fetch-field "message-id"))
850 (setq distribution (mail-fetch-field "distribution")))
851 ;; Verify if the article is absolutely user's by comparing
852 ;; user id with value of its From: field.
855 (downcase (mail-strip-quoted-names from))
856 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
858 (ding) (gnus-message 3 "This article is not yours.")
860 ;; Make control article.
861 (set-buffer (get-buffer-create " *Gnus-canceling*"))
862 (buffer-disable-undo (current-buffer))
864 (insert "Newsgroups: " newsgroups "\n"
865 "From: " (gnus-inews-real-user-address) "\n"
866 "Subject: cancel " message-id "\n"
867 "Control: cancel " message-id "\n"
869 (concat "Distribution: " distribution "\n")
871 mail-header-separator "\n"
872 "This is a cancel message from " from ".\n")
873 ;; Send the control article to NNTP server.
874 (gnus-message 5 "Canceling your article...")
876 (if (funcall gnus-inews-article-function)
877 (gnus-message 5 "Canceling your article...done")
880 (gnus-message 1 "Cancel failed; %s"
881 (gnus-status-message gnus-newsgroup-name))
884 ;; Kill the article buffer.
885 (kill-buffer (current-buffer))))))))
888 ;;; Lowlevel inews interface.
890 ;; Dummy to avoid byte-compile warning.
891 (defvar nnspool-rejected-article-hook)
893 (defun gnus-inews-article (&optional use-group-method)
894 "Post an article in current buffer using NNTP protocol."
895 (let ((artbuf (current-buffer))
898 (goto-char (point-max))
899 ;; Require a newline at the end of the buffer since inews may
900 ;; append a .signature.
901 (or (= (preceding-char) ?\n)
903 ;; Prepare article headers. All message body such as signature
904 ;; must be inserted before Lines: field is prepared.
906 (gnus-inews-narrow-to-headers)
908 (gnus-inews-cleanup-headers)
909 ;; Remove some headers.
910 (gnus-inews-remove-headers)
911 ;; Insert some headers.
912 (gnus-inews-insert-headers)
913 ;; Let the user do all of the above.
914 (run-hooks 'gnus-inews-article-header-hook)
915 ;; Copy the Gcc header, if any.
916 (setq gcc (mail-fetch-field "gcc"))
918 ;; Check whether the article is a good Net Citizen.
919 (if (and gnus-article-check-size
920 (not (gnus-inews-check-post)))
923 ;; We fudge a hook for nnspool.
924 (setq nnspool-rejected-article-hook
930 (set-buffer (, (buffer-name)))
931 (gnus-put-in-draft-group nil 'silent))
935 1 "Couldn't enter rejected article into draft group")))))))
937 ;; Looks ok, so we do the nasty.
939 ;; This hook may insert a signature.
941 (goto-char (point-min))
942 (let ((gnus-newsgroup-name (or (mail-fetch-field "newsgroups")
943 gnus-newsgroup-name)))
944 (run-hooks 'gnus-prepare-article-hook)))
945 ;; Send off copies using mail, if that is wanted.
946 (gnus-inews-send-mail-copy)
947 ;; Remove more headers.
948 (gnus-inews-remove-headers-after-mail)
949 ;; Copy the article over to a temp buffer.
950 (nnheader-set-temp-buffer " *Gnus-posting*")
951 (insert-buffer-substring artbuf)
952 ;; Remove the header separator.
953 (goto-char (point-min))
955 (concat "^" (regexp-quote mail-header-separator) "$"))
956 (replace-match "" t t)
957 ;; Remove X- prefixes to headers.
958 (gnus-inews-dex-headers)
959 ;; Run final inews hooks. This hook may do FCC.
960 ;; The article must be saved before being posted because
961 ;; `gnus-request-post' modifies the buffer.
962 (run-hooks 'gnus-inews-article-hook)
963 ;; Copy the article over to some group, possibly.
964 (and gcc (gnus-inews-do-gcc gcc))
966 (let ((method (gnus-post-method gnus-newsgroup-name use-group-method)))
967 (setq result (gnus-request-post method)))
968 (kill-buffer (current-buffer)))
969 (run-hooks 'gnus-message-sent-hook)
970 ;; If the posting was unsuccessful (that it, it was rejected) we
971 ;; put it into the draft group.
972 (or result (gnus-put-in-draft-group))
975 (defun gnus-inews-cleanup-headers ()
976 ;; Correct newsgroups field: change sequence of spaces to comma and
977 ;; eliminate spaces around commas. Eliminate imbedded line breaks.
978 (goto-char (point-min))
979 (if (re-search-forward "^Newsgroups: +" nil t)
983 (if (re-search-forward "^[^ \t]" nil t)
987 (goto-char (point-min))
988 (while (re-search-forward "\n[ \t]+" nil t)
989 (replace-match " " t t)) ;No line breaks (too confusing)
990 (goto-char (point-min))
991 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
992 (replace-match "," t t))
993 (goto-char (point-min))
994 ;; Remove a trailing comma.
995 (if (re-search-forward ",$" nil t)
996 (replace-match "" t t))))
998 ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
999 ;; Help save the the world!
1002 (let ((newsgroups (mail-fetch-field "newsgroups"))
1003 (followup-to (mail-fetch-field "followup-to"))
1006 (string-match "," newsgroups) (not followup-to))
1008 (while (string-match "," newsgroups)
1010 (cons (list (substring newsgroups 0 (match-beginning 0)))
1012 (setq newsgroups (substring newsgroups (match-end 0))))
1013 (setq groups (nreverse (cons (list newsgroups) groups)))
1015 (setq to (completing-read
1016 "Followups to: (default all groups) " groups))
1017 (if (> (length to) 0)
1019 (goto-char (point-min))
1020 (insert "Followup-To: " to "\n")))))))
1022 ;; Cleanup Followup-To.
1023 (goto-char (point-min))
1024 (if (search-forward-regexp "^Followup-To: +" nil t)
1028 (if (re-search-forward "^[^ \t]" nil 'end)
1031 (goto-char (point-min))
1032 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
1033 (goto-char (point-min))
1034 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ","))))
1037 (defun gnus-inews-remove-headers ()
1038 (let ((case-fold-search t)
1039 (headers gnus-removable-headers))
1040 ;; Remove toxic headers.
1042 (goto-char (point-min))
1043 (and (re-search-forward
1044 (concat "^" (downcase (format "%s" (car headers))))
1046 (delete-region (progn (beginning-of-line) (point))
1047 (progn (forward-line 1) (point))))
1048 (setq headers (cdr headers)))))
1050 ;;; Since the X-Newsreader/X-Mailer are ``vanity'' headers, they might
1051 ;;; as well include the Emacs version as well.
1052 ;;; The following function works with later GNU Emacs, and XEmacs.
1053 (defun gnus-extended-version ()
1054 "Stringified Gnus version and Emacs version"
1060 ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
1061 (concat "Emacs " (substring emacs-version
1064 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)" emacs-version)
1065 (concat (substring emacs-version
1068 (format " %d.%d" emacs-major-version emacs-minor-version)))
1069 (t emacs-version))))
1071 (defun gnus-inews-insert-headers (&optional headers)
1072 "Prepare article headers.
1073 Headers already prepared in the buffer are not modified.
1074 Headers in `gnus-required-headers' will be generated."
1075 (let ((Date (gnus-inews-date))
1076 (Message-ID (gnus-inews-message-id))
1077 (Organization (gnus-inews-organization))
1078 (From (gnus-inews-user-name))
1079 (Path (gnus-inews-path))
1082 (In-Reply-To (gnus-inews-in-reply-to))
1085 (Lines (gnus-inews-lines))
1086 (X-Newsreader (gnus-extended-version))
1087 (X-Mailer (gnus-extended-version))
1088 (headers (or headers gnus-required-headers))
1089 (case-fold-search t)
1091 ;; First we remove any old generated headers.
1092 (let ((headers gnus-deletable-headers))
1094 (goto-char (point-min))
1095 (and (re-search-forward
1096 (concat "^" (symbol-name (car headers)) ": *") nil t)
1097 (get-text-property (1+ (match-beginning 0)) 'gnus-deletable)
1099 (setq headers (cdr headers))))
1100 ;; If there are References, and no "Re: ", then the thread has
1101 ;; changed name. See Son-of-1036.
1102 (if (and (mail-fetch-field "references")
1103 (get-buffer gnus-article-buffer))
1104 (let ((psubject (gnus-simplify-subject-re
1105 (mail-fetch-field "subject"))))
1106 (or (and psubject gnus-reply-subject
1107 (string= (gnus-simplify-subject-re gnus-reply-subject)
1110 (string-match "@" Message-ID)
1112 (concat (substring Message-ID 0 (match-beginning 0))
1114 (substring Message-ID (match-beginning 0))))))))
1115 ;; Go through all the required headers and see if they are in the
1116 ;; articles already. If they are not, or are empty, they are
1117 ;; inserted automatically - except for Subject, Newsgroups and
1120 (goto-char (point-min))
1121 (setq elem (pop headers))
1123 (setq header (car elem))
1125 (when (or (not (re-search-forward
1126 (concat "^" (downcase (symbol-name header)) ":") nil t))
1128 ;; The header was found. We insert a space after the
1129 ;; colon, if there is none.
1130 (if (/= (following-char) ? ) (insert " "))
1131 ;; Find out whether the header is empty...
1132 (looking-at "[ \t]*$")))
1133 ;; So we find out what value we should insert.
1136 ((and (consp elem) (eq (car elem) 'optional))
1137 ;; This is an optional header. If the cdr of this
1138 ;; is something that is nil, then we do not insert
1140 (setq header (cdr elem))
1141 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
1142 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
1144 ;; The element is a cons. Either the cdr is a
1145 ;; string to be inserted verbatim, or it is a
1146 ;; function, and we insert the value returned from
1148 (or (and (stringp (cdr elem)) (cdr elem))
1149 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
1150 ((and (boundp header) (symbol-value header))
1151 ;; The element is a symbol. We insert the value
1152 ;; of this symbol, if any.
1153 (symbol-value header))
1155 ;; We couldn't generate a value for this header,
1156 ;; so we just ask the user.
1157 (read-from-minibuffer
1158 (format "Empty header for %s; enter value: " header)))))
1159 ;; Finally insert the header.
1161 (not (equal value "")))
1165 ;; This header didn't exist, so we insert it.
1166 (goto-char (point-max))
1167 (insert (symbol-name header) ": " value "\n")
1169 ;; The value of this header was empty, so we clear
1170 ;; totally and insert the new value.
1171 (delete-region (point) (gnus-point-at-eol))
1173 ;; Add the deletable property to the headers that require it.
1174 (and (memq header gnus-deletable-headers)
1175 (progn (beginning-of-line) (looking-at "[^:]+: "))
1176 (add-text-properties
1177 (point) (match-end 0)
1178 '(gnus-deletable t face italic) (current-buffer)))))))
1179 ;; Insert new Sender if the From is strange.
1180 (let ((from (mail-fetch-field "from"))
1181 (sender (mail-fetch-field "sender")))
1183 (not (gnus-check-before-posting 'sender))
1185 (downcase (car (gnus-extract-address-components from)))
1186 (downcase (gnus-inews-real-user-address))))
1190 (downcase (car (gnus-extract-address-components sender)))
1191 (downcase (gnus-inews-real-user-address))))))
1193 (goto-char (point-min))
1194 (and (re-search-forward "^Sender:" nil t)
1197 (insert "Original-")
1198 (beginning-of-line)))
1199 (insert "Sender: " (gnus-inews-real-user-address) "\n"))))))
1202 (defun gnus-inews-insert-signature ()
1203 "Insert a signature file.
1204 If `gnus-signature-function' is bound and returns a string, this
1205 string is used instead of the variable `gnus-signature-file'.
1206 In either case, if the string is a file name, this file is
1207 inserted. If the string is not a file name, the string itself is
1210 If you never want any signature inserted, set both of these variables to
1214 (or (and gnus-signature-function
1215 (funcall gnus-signature-function gnus-newsgroup-name))
1216 gnus-signature-file)))
1218 (or (file-exists-p signature)
1219 (string-match " " signature)
1221 "^/[^/]+/" (expand-file-name signature)))))
1223 (goto-char (point-max))
1224 (if (and mail-signature (search-backward "\n-- \n" nil t))
1226 ;; Delete any previous signatures.
1227 (if (search-backward "\n-- \n" nil t)
1228 (delete-region (point) (point-max)))
1229 (or (eolp) (insert "\n"))
1231 (if (file-exists-p signature)
1232 (insert-file-contents signature)
1234 (goto-char (point-max))
1235 (or (bolp) (insert "\n"))))))))
1237 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1238 (defun gnus-inews-insert-mime-headers ()
1239 (goto-char (point-min))
1240 (let ((mail-header-separator
1242 (goto-char (point-min))
1243 (if (and (search-forward (concat "\n" mail-header-separator "\n")
1245 (not (search-backward "\n\n" nil t)))
1246 mail-header-separator
1248 (or (mail-position-on-field "Mime-Version")
1251 (goto-char (point-min))
1252 (re-search-forward "[\200-\377]" nil t))
1253 (or (mail-position-on-field "Content-Type")
1254 (insert "text/plain; charset=ISO-8859-1"))
1255 (or (mail-position-on-field "Content-Transfer-Encoding")
1257 (t (or (mail-position-on-field "Content-Type")
1258 (insert "text/plain; charset=US-ASCII"))
1259 (or (mail-position-on-field "Content-Transfer-Encoding")
1260 (insert "7bit")))))))
1262 (defun gnus-inews-do-fcc ()
1263 "Process Fcc headers in the current buffer.
1264 Unless the first character of the field is `|', the article is saved
1265 to the specified file using the function specified by the variable
1266 gnus-author-copy-saver. The default function rmail-output saves in
1267 Unix mailbox format.
1269 If the first character is `|', the contents of the article is sent to
1270 a program specified by the rest of the value."
1271 (let ((case-fold-search t) ;Should ignore case.
1275 (gnus-narrow-to-headers)
1276 (while (setq file (mail-fetch-field "fcc"))
1278 (nnheader-remove-header "fcc" nil t))
1279 ;; Process FCC operations.
1282 (setq file (pop list))
1283 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
1284 ;; Pipe the article to the program in question.
1285 (call-process-region (point-min) (point-max) shell-file-name
1286 nil nil nil "-c" (match-string 1 file))
1287 ;; Save the article.
1288 (setq file (expand-file-name file))
1289 (gnus-make-directory (file-name-directory file))
1290 (if (and gnus-author-copy-saver
1291 (not (eq gnus-author-copy-saver 'rmail-output)))
1292 (funcall gnus-author-copy-saver file)
1293 (if (and (file-readable-p file) (mail-file-babyl-p file))
1294 (gnus-output-to-rmail file)
1295 (rmail-output file 1 t t)))))))))
1297 (defun gnus-inews-path ()
1299 (let ((login-name (gnus-inews-login-name)))
1300 (cond ((null gnus-use-generic-path)
1301 (concat (nth 1 gnus-select-method) "!" login-name))
1302 ((stringp gnus-use-generic-path)
1303 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1304 (concat gnus-use-generic-path "!" login-name))
1307 (defun gnus-inews-user-name ()
1308 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1309 (let ((full-name (gnus-inews-full-name))
1310 (address (if (or gnus-user-login-name gnus-use-generic-from
1311 gnus-local-domain (getenv "DOMAINNAME"))
1312 (concat (gnus-inews-login-name) "@"
1313 (gnus-inews-domain-name gnus-use-generic-from))
1314 user-mail-address)))
1315 (or gnus-user-from-line
1317 ;; User's full name.
1318 (cond ((string-equal full-name "&") ;Unix hack.
1319 (concat " (" (user-login-name) ")"))
1320 ((string-match "[^ ]+@[^ ]+ +(.*)" address)
1323 (concat " (" full-name ")")))))))
1325 (defun gnus-inews-real-user-address ()
1326 "Return the \"real\" user address.
1327 This function tries to ignore all user modifications, and
1328 give as trustworthy answer as possible."
1329 (concat (user-login-name) "@" (gnus-inews-full-address)))
1331 (defun gnus-inews-login-name ()
1332 "Return login name."
1333 (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1335 (defun gnus-inews-full-name ()
1336 "Return full user name."
1337 (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1339 (defun gnus-inews-domain-name (&optional genericfrom)
1340 "Return user's domain name.
1341 If optional argument GENERICFROM is a string, use it as the domain
1342 name; if it is non-nil, strip off local host name from the domain name.
1343 If the function `system-name' returns full internet name and the
1344 domain is undefined, the domain name is got from it."
1345 (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1346 (let* ((system-name (system-name))
1348 (or (if (stringp genericfrom) genericfrom)
1349 (getenv "DOMAINNAME")
1351 ;; Function `system-name' may return full internet name.
1352 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1353 (if (string-match "\\.." system-name)
1354 ;; Some machines return "name.", and that's not
1356 (substring system-name (1- (match-end 0))))
1357 (read-string "Domain name (no host): ")))
1358 (host (or (if (string-match "\\." system-name)
1359 (substring system-name 0 (match-beginning 0)))
1361 (if (string-equal "." (substring domain 0 1))
1362 (setq domain (substring domain 1)))
1363 ;; Support GENERICFROM as same as standard Bnews system.
1364 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1365 (cond ((null genericfrom)
1366 (concat host "." domain))
1367 ;;((stringp genericfrom) genericfrom)
1369 (if (string-match "\\." (system-name))
1371 (substring user-mail-address
1372 (1+ (string-match "@" user-mail-address))))))
1374 (defun gnus-inews-full-address ()
1375 (let ((domain (gnus-inews-domain-name))
1376 (system (system-name))
1377 (case-fold-search t))
1378 (if (string-match "\\." system) system
1379 (if (string-match (concat "^" (regexp-quote system)) domain) domain
1380 (concat system "." domain)))))
1382 (defun gnus-inews-message-id ()
1383 "Generate unique Message-ID for user."
1384 ;; Message-ID should not contain a slash and should be terminated by
1385 ;; a number. I don't know the reason why it is so.
1386 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1388 (defvar gnus-unique-id-char nil)
1390 ;; If you ever change this function, make sure the new version
1391 ;; cannot generate IDs that the old version could.
1392 ;; You might for example insert a "." somewhere (not next to another dot
1393 ;; or string boundary), or modify the newsreader name to "Ding".
1394 (defun gnus-inews-unique-id ()
1395 ;; Dont use microseconds from (current-time), they may be unsupported.
1396 ;; Instead we use this randomly inited counter.
1397 (setq gnus-unique-id-char
1398 (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1399 ;; (current-time) returns 16-bit ints,
1400 ;; and 2^16*25 just fits into 4 digits i base 36.
1402 (let ((tm (if (fboundp 'current-time)
1403 (current-time) '(12191 46742 287898))))
1405 (if (memq system-type '(ms-dos emx vax-vms))
1406 (let ((user (downcase (gnus-inews-login-name))))
1407 (while (string-match "[^a-z0-9_]" user)
1408 (aset user (match-beginning 0) ?_))
1410 (gnus-number-base36 (user-uid) -1))
1411 (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1412 (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1413 ;; Append the newsreader name, because while the generated
1414 ;; ID is unique to this newsreader, other newsreaders might
1415 ;; otherwise generate the same ID via another algorithm.
1419 (defun gnus-inews-date ()
1420 "Current time string."
1421 (timezone-make-date-arpa-standard
1422 (current-time-string) (current-time-zone)))
1424 (defun gnus-inews-organization ()
1425 "Return user's organization.
1426 The ORGANIZATION environment variable is used if defined.
1427 If not, the variable `gnus-local-organization' is used instead.
1428 If it is a function, the function will be called with the current
1429 newsgroup name as the argument.
1430 If this is a file name, the contents of this file will be used as the
1432 (let* ((organization
1433 (or (getenv "ORGANIZATION")
1434 (if gnus-local-organization
1435 (if (gnus-functionp gnus-local-organization)
1436 (funcall gnus-local-organization gnus-newsgroup-name)
1437 gnus-local-organization))
1438 gnus-organization-file
1439 "~/.organization")))
1440 (and (stringp organization)
1441 (> (length organization) 0)
1442 (or (file-exists-p organization)
1443 (string-match " " organization)
1444 (not (string-match "^/usr/lib/\\|^~/" organization)))
1446 (gnus-set-work-buffer)
1447 (if (file-exists-p organization)
1448 (insert-file-contents organization)
1449 (insert organization))
1450 (goto-char (point-min))
1451 (while (re-search-forward " *\n *" nil t)
1452 (replace-match " " t t))
1453 (buffer-substring (point-min) (point-max))))))
1455 (defun gnus-inews-lines ()
1456 "Count the number of lines and return numeric string."
1460 (goto-char (point-min))
1462 (concat "^" (regexp-quote mail-header-separator) "$"))
1464 (int-to-string (count-lines (point) (point-max))))))
1466 (defun gnus-inews-in-reply-to ()
1467 "Return the In-Reply-To header for this message."
1472 ;;; Gnus Mail Functions
1475 ;;; Mail reply commands of Gnus summary mode
1477 (defun gnus-summary-reply (yank &optional yank-articles)
1478 "Reply mail to news author.
1479 If prefix argument YANK is non-nil, original article is yanked automatically.
1480 Customize the variable gnus-mail-reply-method to use another mailer."
1482 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1483 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1484 (gnus-set-global-variables)
1485 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1486 (gnus-summary-select-article)
1487 (bury-buffer gnus-article-buffer)
1488 (gnus-mail-reply (or yank-articles (not (not yank)))))
1490 (defun gnus-summary-reply-with-original (n)
1491 "Reply mail to news author with original article.
1492 Customize the variable gnus-mail-reply-method to use another mailer."
1494 (gnus-summary-reply t (gnus-summary-work-articles n)))
1496 (defun gnus-summary-mail-forward (post)
1497 "Forward the current message to another user.
1498 Customize the variable gnus-mail-forward-method to use another mailer."
1500 (gnus-set-global-variables)
1501 (gnus-summary-select-article)
1502 (gnus-copy-article-buffer)
1504 (gnus-forward-using-post gnus-article-copy)
1505 (gnus-mail-forward gnus-article-copy)))
1507 (defun gnus-summary-resend-message (address)
1508 "Resend the current article to ADDRESS."
1509 (interactive "sResend message to: ")
1510 (gnus-summary-select-article)
1513 ;; We first set up a normal mail buffer.
1514 (nnheader-set-temp-buffer " *Gnus resend*")
1515 (gnus-mail-setup 'new address)
1516 ;; Insert our usual headers.
1517 (gnus-inews-narrow-to-headers)
1518 (let ((headers '(From Date To Message-ID Organization)))
1519 (gnus-inews-insert-headers headers))
1520 (goto-char (point-min))
1521 ;; Rename them all to "Resent-*".
1522 (while (re-search-forward "^" nil t)
1525 (delete-region (point) (point-max))
1526 ;; Insert the message to be resent.
1527 (insert-buffer-substring gnus-original-article-buffer)
1528 (goto-char (point-min))
1529 (search-forward "\n\n")
1531 (insert mail-header-separator)
1534 (kill-buffer (current-buffer)))))
1536 (defun gnus-summary-post-forward ()
1537 "Forward the current article to a newsgroup."
1539 (gnus-summary-mail-forward t))
1541 (defvar gnus-nastygram-message
1542 "The following article was inappropriately posted to %s.\n"
1543 "Format string to insert in nastygrams.
1544 The current group name will be inserted at \"%s\".")
1546 (defun gnus-summary-mail-nastygram (n)
1547 "Send a nastygram to the author of the current article."
1549 (if (or gnus-expert-user
1551 "Really send a nastygram to the author of the current article? "))
1552 (let ((group gnus-newsgroup-name))
1553 (gnus-summary-reply-with-original n)
1554 (set-buffer gnus-mail-buffer)
1555 (insert (format gnus-nastygram-message group))
1556 (gnus-mail-send-and-exit))))
1558 (defun gnus-summary-mail-other-window ()
1559 "Compose mail in other window.
1560 Customize the variable `gnus-mail-other-window-method' to use another
1563 (gnus-set-global-variables)
1565 ;; We might want to prompt here.
1566 (when (and gnus-interactive-post
1567 (not gnus-expert-user))
1568 (read-string "To: ")))
1569 (gnus-configure-windows 'summary-mail 'force))
1571 (defun gnus-new-mail (&optional to)
1573 (when (and gnus-interactive-post
1574 (not gnus-expert-user))
1575 (setq subject (read-string "Subject: ")))
1576 (pop-to-buffer gnus-mail-buffer)
1578 (gnus-mail-setup 'new to subject)
1579 (run-hooks 'gnus-mail-hook)))
1581 (defun gnus-mail-reply (&optional yank to-address followup)
1583 (set-buffer gnus-summary-buffer)
1584 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1585 (cur (cons (current-buffer) (cdr gnus-article-current)))
1586 (winconf (current-window-configuration))
1587 from subject date reply-to message-of to cc
1588 references message-id sender follow-to sendto elt new-cc new-to
1590 (set-buffer (get-buffer-create gnus-mail-buffer))
1592 (if (and (buffer-modified-p)
1595 "Unsent message being composed; erase it? ")))
1599 (gnus-copy-article-buffer)
1601 (set-buffer gnus-article-copy)
1602 (gnus-narrow-to-headers)
1604 ;; This is a regular reply.
1605 (if (gnus-functionp gnus-reply-to-function)
1606 (setq follow-to (funcall gnus-reply-to-function group)))
1607 ;; This is a followup.
1608 (if (gnus-functionp gnus-followup-to-function)
1611 (funcall gnus-followup-to-function group)))))
1612 (setq from (mail-fetch-field "from"))
1613 (setq date (or (mail-fetch-field "date")
1614 (mail-header-date gnus-current-headers)))
1615 (setq message-of (gnus-message-of from date))
1616 (setq sender (mail-fetch-field "sender"))
1617 (setq subject (or (mail-fetch-field "subject") "none"))
1618 ;; Remove any (buggy) Re:'s that are present and make a
1620 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1621 (setq subject (substring subject (match-end 0))))
1622 (setq subject (concat "Re: " subject))
1623 (setq to (mail-fetch-field "to"))
1624 (setq cc (mail-fetch-field "cc"))
1625 (setq mct (mail-fetch-field "mail-copies-to"))
1626 (setq reply-to (mail-fetch-field "reply-to"))
1627 (setq references (mail-fetch-field "references"))
1628 (setq message-id (mail-fetch-field "message-id"))
1630 (setq mctdo (not (equal mct "never")))
1632 (if (not (and followup (not to-address)))
1633 (setq new-to (or reply-to from))
1636 (gnus-set-work-buffer)
1637 (unless (equal mct "never")
1638 (insert (or reply-to from "")))
1639 (insert (if (bolp) "" ", ")
1641 (if (or (not mct) (not mctdo)) ""
1642 (concat (if (bolp) "" ", ") mct))
1643 (if cc (concat (if (bolp) "" ", ") cc) ""))
1644 (goto-char (point-min))
1648 (cons (mail-strip-quoted-names addr) addr))
1649 (nreverse (mail-parse-comma-list))))
1652 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
1653 (setq new-to (cdr (pop ccalist)))
1656 (lambda (addr) (cdr addr))
1660 (setq news-reply-yank-from (or from "(nobody)"))
1661 (setq news-reply-yank-message-id
1662 (or message-id "(unknown Message-ID)"))
1664 ;; Gather the "to" addresses out of the follow-to list and remove
1666 (if (and follow-to (listp follow-to))
1667 (while (setq elt (assoc "To" follow-to))
1668 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1669 (setq follow-to (delq elt follow-to))))
1672 (if followup 'followup 'reply)
1674 (if (and follow-to (not (stringp follow-to))) sendto
1675 (or follow-to new-to sender "")))
1677 (if (zerop (length new-cc)) nil new-cc)
1680 (make-local-variable 'gnus-article-reply)
1681 (setq gnus-article-reply cur)
1682 (make-local-variable 'gnus-prev-winconf)
1683 (setq gnus-prev-winconf winconf)
1684 (make-local-variable 'gnus-reply-subject)
1685 (setq gnus-reply-subject subject)
1686 (make-local-variable 'gnus-in-reply-to)
1687 (setq gnus-in-reply-to message-of)
1689 (auto-save-mode auto-save-default)
1691 (if (and follow-to (listp follow-to))
1693 (goto-char (point-min))
1694 (re-search-forward "^To:" nil t)
1698 (insert (car (car follow-to)) ": " (cdr (car follow-to)) "\n")
1699 (setq follow-to (cdr follow-to)))))
1700 (nnheader-insert-references references message-id)
1702 ;; Now the headers should be ok, so we do the yanking.
1703 (goto-char (point-min))
1705 (concat "^" (regexp-quote mail-header-separator) "$"))
1708 (gnus-configure-windows 'reply 'force)
1709 (let ((last (point))
1711 (if (not (listp yank))
1713 ;; Just a single article being yanked.
1715 (mail-yank-original nil))
1716 (or mail-yank-hooks mail-citation-hook
1717 (run-hooks 'news-reply-header-hook)))
1719 (save-window-excursion
1720 (set-buffer gnus-summary-buffer)
1721 (gnus-summary-select-article nil nil nil (car yank))
1722 (gnus-summary-remove-process-mark (car yank)))
1724 (gnus-copy-article-buffer)
1725 (mail-yank-original nil)
1727 (narrow-to-region (point-min) (point))
1729 (let ((news-reply-yank-from
1731 (set-buffer gnus-article-buffer)
1732 (or (mail-fetch-field "from") "(nobody)")))
1733 (news-reply-yank-message-id
1735 (set-buffer gnus-article-buffer)
1736 (or (mail-fetch-field "message-id")
1737 "(unknown Message-ID)"))))
1738 (or mail-yank-hooks mail-citation-hook
1739 (run-hooks 'news-reply-header-hook))
1740 (setq end (point-max)))))
1742 (setq yank (cdr yank))))
1745 (gnus-configure-windows 'reply-yank 'force))
1746 (run-hooks 'gnus-mail-hook)))))
1748 (defun gnus-new-news (&optional group inhibit-prompt)
1749 "Set up a *post-news* buffer that points to GROUP.
1750 If INHIBIT-PROMPT, never prompt for a Subject."
1751 (let ((winconf (current-window-configuration))
1753 (when (and gnus-interactive-post
1754 (not inhibit-prompt)
1755 (not gnus-expert-user))
1756 (setq subject (read-string "Subject: ")))
1757 (pop-to-buffer gnus-post-news-buffer)
1760 ;; Let posting styles be configured.
1761 (gnus-configure-posting-styles)
1762 (news-setup nil subject nil (and group (gnus-group-real-name group)) nil)
1763 (goto-char (point-min))
1765 (unless (re-search-forward
1766 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1767 (goto-char (point-max)))
1770 (gnus-inews-insert-bfcc)
1771 (gnus-inews-insert-signature)
1772 (and gnus-post-prepare-function
1773 (gnus-functionp gnus-post-prepare-function)
1774 (funcall gnus-post-prepare-function group))
1775 (goto-char (point-min))
1777 (re-search-forward "^Subject: " nil t)
1778 (re-search-forward "^Newsgroups: " nil t))
1779 (run-hooks 'gnus-post-prepare-hook)
1780 (make-local-variable 'gnus-prev-winconf)
1781 (setq gnus-prev-winconf winconf)
1782 (gnus-inews-modify-mail-mode-map)
1783 (local-set-key "\C-c\C-c" 'gnus-inews-news)))
1785 (defun gnus-news-followup (&optional yank group)
1787 (set-buffer gnus-summary-buffer)
1788 (if (not (or (not gnus-novice-user)
1791 "Are you sure you want to post to all of USENET? ")))
1793 (let ((group (gnus-group-real-name (or group gnus-newsgroup-name)))
1794 (cur (cons (current-buffer) (cdr gnus-article-current)))
1795 (winconf (current-window-configuration))
1796 from subject date reply-to message-of
1797 references message-id sender follow-to sendto elt
1798 followup-to distribution newsgroups)
1799 (set-buffer (get-buffer-create gnus-post-news-buffer))
1801 (if (and (buffer-modified-p)
1804 "Unsent message being composed; erase it? ")))
1808 (gnus-copy-article-buffer)
1810 (set-buffer gnus-article-copy)
1811 (gnus-narrow-to-headers)
1812 (if (gnus-functionp gnus-followup-to-function)
1815 (funcall gnus-followup-to-function group))))
1816 (setq from (mail-fetch-field "from"))
1817 (setq date (or (mail-fetch-field "date")
1818 (mail-header-date gnus-current-headers)))
1819 (setq message-of (gnus-message-of from date))
1820 (setq subject (or (mail-fetch-field "subject") "none"))
1821 ;; Remove any (buggy) Re:'s that are present and make a
1823 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1824 (setq subject (substring subject (match-end 0))))
1825 (setq subject (concat "Re: " subject))
1826 (setq references (mail-fetch-field "references"))
1827 (setq message-id (mail-fetch-field "message-id"))
1828 (setq followup-to (mail-fetch-field "followup-to"))
1829 (setq newsgroups (mail-fetch-field "newsgroups"))
1830 (setq distribution (mail-fetch-field "distribution"))
1831 ;; Remove bogus distribution.
1832 (and (stringp distribution)
1833 (string-match "world" distribution)
1834 (setq distribution nil))
1837 (setq news-reply-yank-from (or from "(nobody)"))
1838 (setq news-reply-yank-message-id
1839 (or message-id "(unknown Message-ID)"))
1841 ;; Gather the "to" addresses out of the follow-to list and remove
1843 (if (and follow-to (listp follow-to))
1844 (while (setq elt (assoc "Newsgroups" follow-to))
1845 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1846 (setq follow-to (delq elt follow-to))))
1848 ;; Let posting styles be configured.
1849 (gnus-configure-posting-styles)
1851 (news-setup nil subject nil
1854 gnus-use-followup-to
1855 (or (not (eq gnus-use-followup-to 'ask))
1858 "Use Followup-To %s? " followup-to)))
1860 newsgroups group "")
1863 (make-local-variable 'gnus-article-reply)
1864 (setq gnus-article-reply cur)
1865 (make-local-variable 'gnus-prev-winconf)
1866 (setq gnus-prev-winconf winconf)
1867 (make-local-variable 'gnus-reply-subject)
1868 (setq gnus-reply-subject (mail-header-subject gnus-current-headers))
1869 (make-local-variable 'gnus-in-reply-to)
1870 (setq gnus-in-reply-to message-of)
1872 (gnus-inews-insert-signature)
1874 (and gnus-post-prepare-function
1875 (gnus-functionp gnus-post-prepare-function)
1876 (funcall gnus-post-prepare-function group))
1877 (run-hooks 'gnus-post-prepare-hook)
1879 (auto-save-mode auto-save-default)
1880 (gnus-inews-modify-mail-mode-map)
1881 (local-set-key "\C-c\C-c" 'gnus-inews-news)
1883 (if (and follow-to (listp follow-to))
1885 (goto-char (point-min))
1886 (and (re-search-forward "^Newsgroups:" nil t)
1889 (insert (car (car follow-to)) ": "
1890 (cdr (car follow-to)) "\n")
1891 (setq follow-to (cdr follow-to)))))
1893 ;; If a distribution existed, we use it.
1896 (mail-position-on-field "Distribution")
1897 (insert distribution)))
1899 (nnheader-insert-references references message-id)
1901 ;; Handle `gnus-auto-mail-to-author'.
1902 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
1903 ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
1904 (let ((to (if (if (eq gnus-auto-mail-to-author 'ask)
1905 (y-or-n-p "Also send mail to author? ")
1906 gnus-auto-mail-to-author)
1908 (set-buffer gnus-article-copy)
1909 (gnus-fetch-field "reply-to"))
1911 (x-mail (save-excursion
1912 (set-buffer gnus-article-copy)
1913 (gnus-fetch-field "x-mail-copy-to"))))
1914 ;; Deny sending copy if there's a negative X-Mail-Copy-To
1917 (if (and (string= x-mail "never")
1918 (not (eq gnus-auto-mail-to-author 'force)))
1921 ;; Insert a To or Cc header.
1923 (if (mail-fetch-field "To")
1926 (insert "Cc: " to "\n"))
1927 (mail-position-on-field "To")
1930 (gnus-inews-insert-bfcc)
1932 ;; Now the headers should be ok, so we do the yanking.
1933 (goto-char (point-min))
1935 (concat "^" (regexp-quote mail-header-separator) "$"))
1939 (gnus-configure-windows 'followup 'force)
1942 (let ((last (point))
1944 (if (not (listp yank))
1947 (mail-yank-original nil))
1948 (or mail-yank-hooks mail-citation-hook
1949 (run-hooks 'news-reply-header-hook)))
1951 (save-window-excursion
1952 (set-buffer gnus-summary-buffer)
1953 (gnus-summary-select-article nil nil nil (car yank))
1954 (gnus-summary-remove-process-mark (car yank)))
1956 (gnus-copy-article-buffer)
1957 (mail-yank-original nil)
1959 (or mail-yank-hooks mail-citation-hook
1960 (run-hooks 'news-reply-header-hook))
1962 (setq yank (cdr yank))))
1964 (gnus-configure-windows 'followup-yank 'force))
1966 (make-local-variable 'gnus-article-check-size)
1967 (setq gnus-article-check-size
1968 (cons (buffer-size) (gnus-article-checksum))))))))
1970 (defun gnus-message-of (from date)
1971 "Take a FROM and a DATE and create an IN-REPLY-TO."
1977 (string-match " *at \\| *@ \\| *(\\| *<" from)))
1978 (concat (if stop-pos (substring from 0 stop-pos) from)
1980 (if (or (not date) (string= date ""))
1981 "(unknown date)" date))))))
1983 (defun gnus-mail-yank-original ()
1986 (mail-yank-original nil))
1987 (or mail-yank-hooks mail-citation-hook
1988 (run-hooks 'news-reply-header-hook)))
1990 (defun gnus-mail-send-and-exit (&optional dont-send)
1991 "Send the current mail and return to Gnus."
1993 (let* ((reply gnus-article-reply)
1994 (winconf gnus-prev-winconf)
1995 (address-group gnus-add-to-address)
1996 (to-address (and address-group
1997 (mail-fetch-field "to"))))
1998 (setq gnus-add-to-address nil)
1999 (or dont-send (gnus-mail-send))
2001 ;; This mail group doesn't have a `to-address', so we add one
2004 (gnus-group-add-parameter
2005 address-group (cons 'to-address to-address)))
2006 (if (get-buffer gnus-group-buffer)
2008 (if (gnus-buffer-exists-p (car-safe reply))
2010 (set-buffer (car reply))
2012 (gnus-summary-mark-article-as-replied
2014 (and winconf (set-window-configuration winconf))))))
2016 (defun gnus-put-message ()
2017 "Put the current message in some group and return to Gnus."
2019 (let ((reply gnus-article-reply)
2020 (winconf gnus-prev-winconf)
2021 (group gnus-newsgroup-name)
2024 (or (and group (not (gnus-group-read-only-p group)))
2025 (setq group (read-string "Put in group: " nil
2026 (gnus-writable-groups))))
2027 (and (gnus-gethash group gnus-newsrc-hashtb)
2028 (error "No such group: %s" group))
2033 (gnus-inews-narrow-to-headers)
2034 (let (gnus-deletable-headers)
2035 (if (eq major-mode 'mail-mode)
2036 (gnus-inews-insert-headers gnus-required-mail-headers)
2037 (gnus-inews-insert-headers)))
2038 (goto-char (point-max))
2039 (insert "Gcc: " group "\n")
2044 (if (get-buffer gnus-group-buffer)
2046 (if (gnus-buffer-exists-p (car-safe reply))
2048 (set-buffer (car reply))
2050 (gnus-summary-mark-article-as-replied
2052 (and winconf (set-window-configuration winconf))))))
2054 (defun gnus-forward-make-subject (buffer)
2057 (concat "[" (if (memq 'mail (assoc (symbol-name
2058 (car (gnus-find-method-for-group
2059 gnus-newsgroup-name)))
2060 gnus-valid-select-methods))
2061 (gnus-fetch-field "From")
2062 gnus-newsgroup-name)
2063 "] " (or (gnus-fetch-field "Subject") ""))))
2065 (defun gnus-forward-insert-buffer (buffer)
2068 (if gnus-signature-before-forwarded-message
2069 (goto-char (point-max))
2070 (goto-char (point-min))
2072 (concat "^" (regexp-quote mail-header-separator) "$"))
2074 ;; Narrow to the area we are to insert.
2075 (narrow-to-region (point) (point))
2076 ;; Insert the separators and the forwarded buffer.
2077 (insert gnus-forward-start-separator)
2078 (insert-buffer-substring buffer)
2079 (goto-char (point-max))
2080 (insert gnus-forward-end-separator)
2081 ;; Delete any invisible text.
2082 (goto-char (point-min))
2084 (while (setq beg (next-single-property-change (point) 'invisible))
2086 (delete-region beg (or (next-single-property-change
2090 (defun gnus-mail-forward (&optional buffer)
2091 "Forward the current message to another user using mail."
2092 (let* ((forward-buffer (or buffer (current-buffer)))
2093 (winconf (current-window-configuration))
2094 (subject (gnus-forward-make-subject forward-buffer)))
2095 (set-buffer (get-buffer-create gnus-mail-buffer))
2096 (if (and (buffer-modified-p)
2099 "Unsent message being composed; erase it? ")))
2102 (gnus-mail-setup 'forward nil subject)
2103 (make-local-variable 'gnus-prev-winconf)
2104 (setq gnus-prev-winconf winconf)
2105 (gnus-forward-insert-buffer forward-buffer)
2106 (goto-char (point-min))
2107 (re-search-forward "^To: ?" nil t)
2108 (gnus-configure-windows 'mail-forward 'force)
2109 ;; You have a chance to arrange the message.
2110 (run-hooks 'gnus-mail-forward-hook)
2111 (run-hooks 'gnus-mail-hook))))
2113 (defun gnus-forward-using-post (&optional buffer)
2115 (let* ((forward-buffer (or buffer (current-buffer)))
2116 (subject (gnus-forward-make-subject forward-buffer))
2117 (gnus-newsgroup-name nil))
2118 (gnus-post-news 'post nil nil nil nil subject)
2120 (gnus-forward-insert-buffer forward-buffer)
2121 ;; You have a chance to arrange the message.
2122 (run-hooks 'gnus-mail-forward-hook)))))
2124 (defun gnus-mail-other-window-using-mail ()
2125 "Compose mail other window using mail."
2126 (let ((winconf (current-window-configuration)))
2127 (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
2128 (gnus-inews-modify-mail-mode-map)
2129 (make-local-variable 'gnus-prev-winconf)
2130 (setq gnus-prev-winconf winconf)
2131 (run-hooks 'gnus-mail-hook)
2132 (gnus-configure-windows 'summary-mail 'force)))
2134 (defun gnus-article-mail (yank)
2135 "Send a reply to the address near point.
2136 If YANK is non-nil, include the original article."
2140 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
2141 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
2144 (switch-to-buffer gnus-summary-buffer)
2145 (gnus-mail-reply yank address)))))
2148 "Send a bug report to the Gnus maintainers."
2150 (let ((winconf (current-window-configuration)))
2151 (delete-other-windows)
2152 (switch-to-buffer "*Gnus Help Bug*")
2154 (insert gnus-bug-message)
2155 (goto-char (point-min))
2156 (pop-to-buffer "*Gnus Bug*")
2159 (mail-setup gnus-maintainer nil nil nil nil nil)
2160 (auto-save-mode auto-save-default)
2161 (make-local-variable 'gnus-prev-winconf)
2162 (setq gnus-prev-winconf winconf)
2163 (gnus-inews-modify-mail-mode-map)
2164 (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
2165 (goto-char (point-min))
2166 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2168 (insert (format "%s\n%s\n\n\n\n\n" (gnus-version) (emacs-version)))
2170 (goto-char (point-min))
2171 (search-forward "Subject: " nil t)
2174 (defun gnus-bug-mail-send-and-exit ()
2175 "Send the bug message and exit."
2177 (and (get-buffer "*Gnus Help Bug*")
2178 (kill-buffer "*Gnus Help Bug*"))
2179 (gnus-mail-send-and-exit))
2181 (defun gnus-debug ()
2182 "Attemps to go through the Gnus source file and report what variables have been changed.
2183 The source file has to be in the Emacs load path."
2185 (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el"))
2186 file dirs expr olist sym)
2187 (message "Please wait while we snoop your variables...")
2190 (set-buffer (get-buffer-create " *gnus bug info*"))
2191 (buffer-disable-undo (current-buffer))
2194 (setq dirs load-path)
2196 (if (or (not (car dirs))
2197 (not (stringp (car dirs)))
2199 (setq file (concat (file-name-as-directory
2200 (car dirs)) (car files))))))
2201 (setq dirs (cdr dirs))
2203 (insert-file-contents file)
2204 (goto-char (point-min))
2205 (or (re-search-forward "^;;* *Internal variables" nil t)
2206 (error "Malformed sources in file %s" file))
2207 (narrow-to-region (point-min) (point))
2208 (goto-char (point-min))
2209 (while (setq expr (condition-case ()
2210 (read (current-buffer)) (error nil)))
2212 (and (eq (car expr) 'defvar)
2213 (stringp (nth 3 expr))
2214 (or (not (boundp (nth 1 expr)))
2215 (not (equal (eval (nth 2 expr))
2216 (symbol-value (nth 1 expr)))))
2217 (setq olist (cons (nth 1 expr) olist)))
2219 (setq files (cdr files)))
2220 (kill-buffer (current-buffer)))
2221 (insert "------------------- Environment follows -------------------\n\n")
2223 (if (boundp (car olist))
2224 (insert "(setq " (symbol-name (car olist))
2225 (if (or (consp (setq sym (symbol-value (car olist))))
2227 (not (or (eq sym nil)
2230 (prin1-to-string (symbol-value (car olist))) ")\n")
2231 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
2232 (setq olist (cdr olist)))
2234 ;; Remove any null chars - they seem to cause trouble for some
2235 ;; mailers. (Byte-compiled output from the stuff above.)
2236 (goto-char (point-min))
2237 (while (re-search-forward "[\000\200]" nil t)
2238 (replace-match "" t t))))
2241 ;;; Treatment of rejected articles.
2246 (defun gnus-summary-resend-bounced-mail (fetch)
2247 "Re-mail the current message.
2248 This only makes sense if the current message is a bounce message than
2249 contains some mail you have written which has been bounced back to
2251 If FETCH, try to fetch the article that this is a reply to, if indeed
2254 (gnus-summary-select-article t)
2255 ;; Create a mail buffer.
2258 (insert-buffer-substring gnus-article-buffer)
2259 (goto-char (point-min))
2260 (search-forward "\n\n")
2261 ;; We remove everything before the bounced mail.
2264 (if (re-search-forward "[^ \t]*:" nil t)
2270 (gnus-narrow-to-headers)
2271 (nnheader-remove-header gnus-bounced-headers-junk t)
2272 (setq references (mail-fetch-field "references"))
2273 (goto-char (point-max))
2274 (insert mail-header-separator)))
2275 ;; If there are references, we fetch the article we answered to.
2278 (string-match "\\(<[^]+>\\)[ \t]*$" references)
2279 (gnus-summary-refer-article
2280 (substring references (match-beginning 1) (match-end 1)))
2282 (gnus-summary-show-all-headers)
2283 (gnus-configure-windows 'compose-bounce))))
2284 (goto-char (point-min)))
2288 (defun gnus-mail-send ()
2289 "Send the current buffer as mail.
2290 Headers will be generated before sending."
2295 (gnus-inews-narrow-to-headers)
2296 (gnus-inews-insert-headers gnus-required-mail-headers)
2297 (gnus-inews-remove-empty-headers)))
2299 ;; Remove the header separator.
2300 (goto-char (point-min))
2301 (and (re-search-forward
2302 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2303 (replace-match "" t t))
2304 ;; Run final inews hooks. This hook may do FCC.
2305 (run-hooks 'gnus-inews-article-hook)
2307 (gnus-narrow-to-headers)
2308 (nnheader-remove-header "^[gf]cc:" t)
2310 (goto-char (point-min))
2311 (search-forward "\n\n")
2313 (insert mail-header-separator)
2315 (run-hooks 'gnus-message-sent-hook))
2317 (defun gnus-inews-modify-mail-mode-map ()
2318 (use-local-map (copy-keymap (current-local-map)))
2319 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
2320 (local-set-key "\C-c\C-p" 'gnus-put-message)
2321 (local-set-key "\C-c\C-d" 'gnus-enter-into-draft-group))
2323 (defun gnus-mail-setup (type &optional to subject in-reply-to cc
2324 replybuffer actions)
2325 ;; Let posting styles be configured.
2326 (gnus-configure-posting-styles)
2330 (and (or (eq type 'reply) (eq type 'followup))
2331 (eq gnus-mail-reply-method 'gnus-mail-reply-using-mhe))
2332 (and (eq type 'forward)
2333 (eq gnus-mail-forward-method 'gnus-mail-forward-using-mhe))
2335 (eq gnus-mail-other-window-method
2336 'gnus-mail-other-window-using-mhe)))
2337 'gnus-mh-mail-setup)
2339 (and (or (eq type 'reply) (eq type 'followup))
2340 (eq gnus-mail-reply-method 'gnus-mail-reply-using-vm))
2341 (and (eq type 'forward)
2342 (eq gnus-mail-forward-method 'gnus-mail-forward-using-vm))
2344 (eq gnus-mail-other-window-method
2345 'gnus-mail-other-window-using-vm)))
2346 'gnus-vm-mail-setup)
2347 (t 'gnus-sendmail-mail-setup))
2348 to subject in-reply-to cc replybuffer actions))
2350 (defun gnus-sendmail-mail-setup (to subject in-reply-to cc replybuffer actions)
2352 (mail-setup to subject nil cc replybuffer actions)
2353 (goto-char (point-min))
2354 (if (re-search-forward
2355 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2357 (goto-char (point-max)))
2359 (gnus-inews-modify-mail-mode-map))
2363 ;; Do Gcc handling, which copied the message over to some group.
2364 (defun gnus-inews-do-gcc (&optional gcc)
2367 (gnus-narrow-to-headers)
2368 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
2371 () ; Nothing to be done.
2372 (nnheader-remove-header "gcc")
2373 ;; Copy the article over to some group(s).
2374 (while (string-match
2375 "^[ \t]*\\([^ \t]+\\)\\([ \t]+\\|$\\)" gcc)
2376 (setq end (match-end 0))
2378 (gnus-request-accept-article
2379 (substring gcc (match-beginning 1) (match-end 1)) t)
2381 (setq gcc (substring gcc end))))))))
2383 (defun gnus-inews-insert-bfcc ()
2384 "Insert Bcc and Fcc headers."
2386 ;; Handle author copy using BCC field.
2387 (when (and gnus-mail-self-blind
2388 (not (mail-fetch-field "bcc")))
2389 (mail-position-on-field "Bcc")
2390 (insert (if (stringp gnus-mail-self-blind)
2391 gnus-mail-self-blind
2392 (user-login-name))))
2393 ;; Handle author copy using FCC field.
2394 (when gnus-author-copy
2395 (mail-position-on-field "Fcc")
2396 (insert gnus-author-copy))))
2398 (defun gnus-inews-insert-gcc ()
2399 (let* ((group gnus-outgoing-message-group)
2401 ((gnus-functionp group)
2403 ((or (stringp group) (list group))
2407 (if (stringp group) group
2408 (mapconcat 'identity group " "))
2411 ;;; Handling rejected (and postponed) news.
2413 (defun gnus-draft-group ()
2414 "Return the name of the draft group."
2415 (gnus-group-prefixed-name
2416 (file-name-nondirectory gnus-draft-group-directory)
2417 (list 'nndir gnus-draft-group-directory)))
2419 (defun gnus-make-draft-group ()
2420 "Make the draft group or die trying."
2421 (let* ((method (` (nndir "private"
2422 (nndir-directory (, gnus-draft-group-directory)))))
2423 (group (gnus-group-prefixed-name
2424 (file-name-nondirectory gnus-draft-group-directory)
2426 (or (gnus-gethash group gnus-newsrc-hashtb)
2427 (gnus-group-make-group (gnus-group-real-name group) method)
2428 (error "Can't create the draft group"))
2431 (defun gnus-enter-into-draft-group ()
2432 "Enter the current buffer into the draft group."
2434 (gnus-put-in-draft-group t))
2436 (defun gnus-put-in-draft-group (&optional generate silent)
2437 "Does the actual putting."
2438 (let ((group (gnus-make-draft-group))
2439 (type (list major-mode (buffer-name) gnus-newsgroup-name
2442 (buf (current-buffer)))
2445 (nnheader-set-temp-buffer " *enter-draft*")
2446 (insert-buffer-substring buf)
2449 (gnus-inews-narrow-to-headers)
2450 (let (gnus-deletable-headers)
2451 (if (eq mode 'mail-mode)
2452 (gnus-inews-insert-headers gnus-required-mail-headers)
2453 (gnus-inews-insert-headers)))
2456 (goto-char (point-min))
2457 ;; We have to store whether we are in a mail group or news group.
2458 (insert (format "X-Gnus-Draft-Type: %S\n" type))
2459 (and (re-search-forward
2460 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2461 (replace-match "" t t))
2463 (gnus-request-accept-article group t)
2464 (kill-buffer (current-buffer)))
2466 (gnus-mail-send-and-exit 'dont-send))))
2467 (set-buffer-modified-p nil)))
2469 (defun gnus-summary-send-draft ()
2470 "Enter a mail/post buffer to edit and send the draft."
2472 (gnus-set-global-variables)
2473 (gnus-summary-select-article t)
2474 ;; First we find the draft type.
2477 (set-buffer gnus-article-buffer)
2479 (gnus-narrow-to-headers)
2480 (setq type (condition-case ()
2481 (read (mail-fetch-field "x-gnus-draft-type"))
2485 (error "Unknown draft type"))
2486 ;; Get to the proper buffer.
2487 (set-buffer (get-buffer-create (nth 1 type)))
2488 ;; It might be modified.
2489 (and (buffer-modified-p)
2490 (or (gnus-yes-or-no-p "Unsent message being composed; discard it? ")
2492 (setq buffer-read-only nil)
2493 (buffer-enable-undo (current-buffer))
2496 (funcall (car type))
2497 (and (eq major-mode 'mail-mode)
2498 (gnus-inews-modify-mail-mode-map))
2499 ;; Arrange for deletion of the draft after successful sending.
2500 (make-local-variable 'gnus-message-sent-hook)
2501 (setq gnus-message-sent-hook
2505 (gnus-request-expire-articles
2506 (quote (, (list (cdr gnus-article-current))))
2507 (, gnus-newsgroup-name) t)))))
2508 ;; Insert the draft.
2509 (insert-buffer-substring gnus-article-buffer)
2510 ;; Insert the separator.
2511 (goto-char (point-min))
2512 (search-forward "\n\n")
2514 (insert mail-header-separator)
2515 ;; Remove the draft header.
2516 (gnus-inews-narrow-to-headers)
2517 (nnheader-remove-header "x-gnus-draft-type")
2519 ;; Configure windows.
2520 (let ((gnus-draft-buffer (current-buffer)))
2521 (gnus-configure-windows 'draft))
2522 ;; Put point where you left it.
2523 (goto-char (nth 3 type))))
2525 (defun gnus-configure-posting-styles ()
2526 "Configure posting styles according to `gnus-posting-styles'."
2527 (let ((styles gnus-posting-styles)
2528 (gnus-newsgroup-name (or gnus-newsgroup-name ""))
2529 style match variable attribute value value-value)
2530 ;; Go through all styles and look for matches.
2532 (setq style (pop styles)
2534 (when (cond ((stringp match)
2535 ;; Regexp string match on the group name.
2536 (string-match match gnus-newsgroup-name))
2537 ((or (symbolp match)
2538 (gnus-functionp match))
2539 (cond ((gnus-functionp match)
2540 ;; Function to be called.
2543 ;; Variable to be checked.
2544 (symbol-value match))))
2546 ;; This is a form to be evaled.
2548 ;; We have a match, so we set the variables.
2550 (setq attribute (pop style)
2551 value (cdr attribute))
2552 ;; We find the variable that is to be modified.
2553 (if (and (not (stringp (car attribute)))
2554 (not (setq variable (cdr (assq (car attribute)
2555 gnus-posting-style-alist)))))
2556 (message "Couldn't find attribute %s" (car attribute))
2557 ;; We set the variable.
2559 (cond ((stringp value)
2561 ((or (symbolp value)
2562 (gnus-functionp value))
2563 (cond ((gnus-functionp value)
2566 (symbol-value value))))
2571 ;; This is an ordinary variable.
2572 (make-local-variable variable)
2573 (set variable value-value))
2574 ;; This is a header to be added to the headers when
2577 (make-local-variable gnus-required-headers)
2578 (make-local-variable gnus-required-mail-headers)
2579 (push (cons (car attribute) value-value)
2580 gnus-required-headers)
2581 (push (cons (car attribute) value-value)
2582 gnus-required-mail-headers)))))))))
2584 ;;; Allow redefinition of functions.
2590 ;;; gnus-msg.el ends here