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-article-copy nil)
281 (defvar gnus-reply-subject nil)
282 (defvar gnus-add-to-address nil)
283 (defvar gnus-in-reply-to nil)
286 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
287 (autoload 'news-setup "rnewspost")
288 (autoload 'news-reply-mode "rnewspost")
289 (autoload 'rmail-output "rmailout"))
293 ;;; Gnus Posting Functions
296 (define-prefix-command 'gnus-summary-send-map)
297 (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
298 (define-key gnus-summary-send-map "p" 'gnus-summary-post-news)
299 (define-key gnus-summary-send-map "f" 'gnus-summary-followup)
300 (define-key gnus-summary-send-map "F" 'gnus-summary-followup-with-original)
301 (define-key gnus-summary-send-map "b" 'gnus-summary-followup-and-reply)
302 (define-key gnus-summary-send-map "B" 'gnus-summary-followup-and-reply-with-original)
303 (define-key gnus-summary-send-map "c" 'gnus-summary-cancel-article)
304 (define-key gnus-summary-send-map "s" 'gnus-summary-supersede-article)
305 (define-key gnus-summary-send-map "r" 'gnus-summary-reply)
306 (define-key gnus-summary-send-map "R" 'gnus-summary-reply-with-original)
307 (define-key gnus-summary-send-map "m" 'gnus-summary-mail-other-window)
308 (define-key gnus-summary-send-map "Db" 'gnus-summary-resend-bounced-mail)
309 (define-key gnus-summary-send-map "Dc" 'gnus-summary-send-draft)
310 (define-key gnus-summary-send-map "u" 'gnus-uu-post-news)
311 (define-key gnus-summary-send-map "om" 'gnus-summary-mail-forward)
312 (define-key gnus-summary-send-map "op" 'gnus-summary-post-forward)
313 (define-key gnus-summary-send-map "Om" 'gnus-uu-digest-mail-forward)
314 (define-key gnus-summary-send-map "Op" 'gnus-uu-digest-post-forward)
316 ;;; Internal functions.
318 (defun gnus-number-base36 (num len)
319 (if (if (< len 0) (<= num 0) (= len 0))
321 (concat (gnus-number-base36 (/ num 36) (1- len))
322 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
325 ;;; Post news commands of Gnus group mode and summary mode
327 (defun gnus-group-mail ()
328 "Start composing a mail."
331 ;; We might want to prompt here.
332 (when (and gnus-interactive-post
333 (not gnus-expert-user))
334 (read-string "To: "))))
336 (defun gnus-group-post-news (&optional arg)
338 The newsgroup under the cursor is used as the group to post to.
340 If you wish to get an empty post buffer, use a prefix ARG. You can
341 also do this by calling this function from the bottom of the Group
344 (let ((gnus-newsgroup-name nil)
345 (group (unless arg (gnus-group-group-name)))
347 ;; We might want to prompt here.
348 (when (and gnus-interactive-post
349 (not gnus-expert-user))
350 (setq gnus-newsgroup-name
352 (completing-read "Group: " gnus-active-hashtb nil nil
354 (gnus-post-news 'post group nil gnus-article-buffer)))
356 (defun gnus-summary-post-news ()
359 (gnus-set-global-variables)
360 (gnus-post-news 'post gnus-newsgroup-name))
362 (defun gnus-summary-followup (yank &optional yank-articles)
363 "Compose a followup to an article.
364 If prefix argument YANK is non-nil, original article is yanked automatically."
366 (gnus-set-global-variables)
367 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
368 (save-window-excursion
369 (gnus-summary-select-article))
370 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
371 (gnus-newsgroup-name gnus-newsgroup-name))
372 ;; Check Followup-To: poster.
373 (set-buffer gnus-article-buffer)
374 (if (and gnus-use-followup-to
375 (string-equal "poster" (gnus-fetch-field "followup-to"))
376 (or (not (memq gnus-use-followup-to '(t ask)))
378 "Do you want to ignore `Followup-To: poster'? "))))
379 ;; Mail to the poster.
380 (gnus-summary-reply yank)
382 (gnus-post-news nil gnus-newsgroup-name
383 headers gnus-article-buffer
384 (or yank-articles (not (not yank)))))))
386 (defun gnus-summary-followup-with-original (n)
387 "Compose a followup to an article and include the original article."
389 (gnus-summary-followup t (gnus-summary-work-articles n)))
391 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
392 (defun gnus-summary-followup-and-reply (yank &optional yank-articles)
393 "Compose a followup and do an auto mail to author."
395 (gnus-set-global-variables)
396 (let ((gnus-auto-mail-to-author 'force))
397 (gnus-summary-followup yank yank-articles)))
399 (defun gnus-summary-followup-and-reply-with-original (n)
400 "Compose a followup, include the original, and do an auto mail to author."
402 (gnus-summary-followup-and-reply t (gnus-summary-work-articles n)))
404 (defun gnus-summary-cancel-article (n)
405 "Cancel an article you posted."
407 (gnus-set-global-variables)
408 (let ((articles (gnus-summary-work-articles n)))
410 (gnus-summary-select-article t nil nil (car articles))
411 (and (gnus-eval-in-buffer-window gnus-article-buffer (gnus-cancel-news))
412 (gnus-summary-mark-as-read (car articles) gnus-canceled-mark))
413 (gnus-summary-remove-process-mark (car articles))
414 (gnus-article-hide-headers-if-wanted)
415 (setq articles (cdr articles)))))
417 (defun gnus-summary-supersede-article ()
418 "Compose an article that will supersede a previous article.
419 This is done simply by taking the old article and adding a Supersedes
420 header line with the old Message-ID."
422 (gnus-set-global-variables)
423 (gnus-summary-select-article t)
424 ;; Check whether the user owns the article that is to be superseded.
425 (unless (string-equal
426 (downcase (mail-strip-quoted-names
427 (mail-header-from gnus-current-headers)))
428 (downcase (mail-strip-quoted-names (gnus-inews-user-name))))
429 (error "This article is not yours."))
430 ;; Get a normal *post-news* buffer.
431 (gnus-new-news gnus-newsgroup-name t)
433 (insert-buffer-substring gnus-original-article-buffer)
434 (gnus-narrow-to-headers)
435 ;; Remove unwanted headers.
436 (when gnus-delete-supersedes-headers
437 (nnheader-remove-header gnus-delete-supersedes-headers t))
438 (goto-char (point-min))
439 (if (not (re-search-forward "^Message-ID: " nil t))
440 (error "No Message-ID in this article")
441 (replace-match "Supersedes: " t t))
442 (goto-char (point-max))
443 (insert mail-header-separator)
449 (defalias 'sendnews 'gnus-post-news)
452 (defalias 'postnews 'gnus-post-news)
454 (defun gnus-copy-article-buffer (&optional article-buffer)
455 ;; make a copy of the article buffer with all text properties removed
456 ;; this copy is in the buffer gnus-article-copy.
457 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
458 ;; this buffer should be passed to all mail/news reply/post routines.
459 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
460 (buffer-disable-undo gnus-article-copy)
461 (or (memq gnus-article-copy gnus-buffer-list)
462 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
463 (let ((article-buffer (or article-buffer gnus-article-buffer)))
464 (if (and (get-buffer article-buffer)
465 (buffer-name (get-buffer article-buffer)))
467 (set-buffer article-buffer)
469 (copy-to-buffer gnus-article-copy (point-min) (point-max))
470 (set-text-properties (point-min) (point-max)
471 nil gnus-article-copy)))))
473 (defun gnus-post-news (post &optional group header article-buffer yank subject)
474 "Begin editing a new USENET news article to be posted.
475 Type \\[describe-mode] in the buffer to get a list of commands."
476 (interactive (list t))
477 (let* ((group (or group gnus-newsgroup-name))
479 to-address to-group mailing-list to-list)
481 (setq to-address (gnus-group-get-parameter group 'to-address)
482 to-group (gnus-group-get-parameter group 'to-group)
483 to-list (gnus-group-get-parameter group 'to-list)
484 mailing-list (when gnus-mailing-list-groups
485 (string-match gnus-mailing-list-groups group))
486 group (gnus-group-real-name group)))
488 (and (gnus-member-of-valid 'post (or pgroup gnus-newsgroup-name))
494 (gnus-new-news (or to-group group))
495 (gnus-news-followup yank (or to-group group)))
499 (gnus-new-mail (or to-address to-list))
500 ;; Arrange for mail groups that have no `to-address' to
501 ;; get that when the user sends off the mail.
503 (make-local-variable 'gnus-add-to-address)
504 (setq gnus-add-to-address group)))
505 (gnus-mail-reply yank to-address 'followup)))))
507 (defun gnus-inews-news (&optional use-group-method)
508 "Send a news message.
509 If given a prefix, and the group is a foreign group, this function
510 will attempt to use the foreign server to post the article."
512 (or gnus-current-select-method
513 (setq gnus-current-select-method gnus-select-method))
514 (let* ((case-fold-search nil)
515 (reply gnus-article-reply)
518 (gnus-start-news-server) ;Use default server.
520 (goto-char (point-min))
521 (run-hooks 'news-inews-hook)
524 (gnus-message 5 "Posting to USENET...")
525 (setq post-result (funcall gnus-inews-article-function use-group-method))
526 (cond ((eq post-result 'illegal)
530 (gnus-message 5 "Posting to USENET...done")
531 (if (gnus-buffer-exists-p (car-safe reply))
534 (set-buffer gnus-summary-buffer)
535 (gnus-summary-mark-article-as-replied
537 (set-buffer-modified-p nil))
539 ;; We cannot signal an error.
543 1 "Article rejected: %s"
545 (gnus-post-method gnus-newsgroup-name use-group-method))))))
547 (let ((conf gnus-prev-winconf))
550 ;; Restore last window configuration.
551 (and conf (set-window-configuration conf))))))
553 (defun gnus-inews-narrow-to-headers ()
556 (goto-char (point-min))
557 (or (and (re-search-forward
558 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
562 (defun gnus-inews-send-mail-copy ()
563 ;; Mail the message if To, Bcc or Cc exists.
564 (let* ((types '("to" "bcc" "cc"))
566 (buffer (current-buffer))
570 (gnus-inews-narrow-to-headers)
573 (or (mail-fetch-field (car ty) nil t)
574 (setq types (delete (car ty) types)))
578 ;; We do not want to send mail.
580 (gnus-message 5 "Sending via mail...")
583 ;; We copy the article over to a temp buffer since we are
584 ;; going to modify it a little.
585 (nnheader-set-temp-buffer " *Gnus-mailing*")
586 (insert-buffer-substring buffer)
587 ;; We remove Fcc, because we don't want the mailer to see
589 (gnus-inews-narrow-to-headers)
590 (nnheader-remove-header "fcc")
592 ;; Insert the X-Courtesy-Message header.
593 (and (or (member "to" types)
596 (goto-char (point-max))
597 (insert "Posted-To: "
598 (mail-fetch-field "newsgroups") "\n")))
602 (if (and gnus-mail-courtesy-message
603 (or (member "to" types)
604 (member "cc" types)))
605 ;; We only want to insert the courtesy mail message if
606 ;; we use To or Cc; Bcc should not have one. Well, if
607 ;; both Bcc and To are present, it will get one
610 ;; Insert "courtesy" mail message.
611 (goto-char (point-min))
613 (concat "^" (regexp-quote mail-header-separator) "$"))
615 (insert gnus-mail-courtesy-message)))
618 (kill-buffer (current-buffer))
619 (gnus-message 5 "Sending via mail...done"))))))
621 (defun gnus-inews-remove-headers-after-mail ()
624 (let ((case-fold-search t))
625 (gnus-inews-narrow-to-headers)
626 ;; Remove Bcc completely.
627 (nnheader-remove-header "bcc")
628 ;; We transform To and Cc headers to avoid re-mailing if the user
629 ;; accidentally (or purposefully) leans on the `C-c C-c' keys
630 ;; and the news server rejects the posting.
631 (while (re-search-forward "^\\(to\\|[bcf]cc\\|cc\\):" nil t)
636 (defun gnus-inews-dex-headers ()
637 "Remove \"X-\" prefixes from To and Cc headers."
640 (let ((case-fold-search t))
641 (gnus-narrow-to-headers)
642 (while (re-search-forward "^X-\\(to\\|[bcf]cc\\|cc\\):" nil t)
647 (defun gnus-inews-remove-empty-headers ()
648 "Remove empty headers from news and mail.
649 The buffer should be narrowed to the headers before this function is
652 (goto-char (point-min))
653 (while (re-search-forward "^[^ \t:]+:\\([ \t]*\n\\)+[^ \t]" nil t)
654 (delete-region (match-beginning 0) (1- (match-end 0)))
655 (beginning-of-line))))
657 (defun gnus-inews-check-post ()
658 "Check whether the post looks ok."
660 (not gnus-check-before-posting)
662 ;; We narrow to the headers and check them first.
665 (goto-char (point-min))
670 (concat "^" (regexp-quote mail-header-separator) "$"))
671 (match-beginning 0)))
672 (goto-char (point-min))
674 ;; Check for commands in Subject.
676 (gnus-check-before-posting 'subject-cmsg)
678 (if (string-match "^cmsg " (mail-fetch-field "subject"))
680 "The control code \"cmsg \" is in the subject. Really post? ")
682 ;; Check for multiple identical headers.
683 (or (gnus-check-before-posting 'multiple-headers)
686 (while (and (not found) (re-search-forward "^[^ \t:]+: "
689 (or (re-search-forward
690 (concat "^" (setq found
693 (- (match-end 0) 2))))
698 (format "Multiple %s headers. Really post? " found))
700 ;; Check for Version and Sendsys.
701 (or (gnus-check-before-posting 'sendsys)
703 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
705 (format "The article contains a %s command. Really post? "
706 (buffer-substring (match-beginning 0)
707 (1- (match-end 0)))))
709 ;; Check for Approved.
710 (or (gnus-check-before-posting 'approved)
712 (if (re-search-forward "^Approved:" nil t)
714 "The article contains an Approved header. Really post? ")
716 ;; Check the Message-ID header.
717 (or (gnus-check-before-posting 'message-id)
719 (let* ((case-fold-search t)
720 (message-id (mail-fetch-field "message-id")))
722 (and (string-match "@" message-id)
723 (string-match "@[^\\.]*\\." message-id))
726 "The Message-ID looks strange: \"%s\". Really post? "
728 ;; Check the From header.
729 (or (gnus-check-before-posting 'from)
731 (let* ((case-fold-search t)
732 (from (mail-fetch-field "from")))
735 (gnus-y-or-n-p "There is no From line. Really post? "))
736 ((not (string-match "@[^\\.]*\\." from))
739 "The address looks strange: \"%s\". Really post? " from)))
740 ((string-match "(.*).*(.*)" from)
743 "The From header looks strange: \"%s\". Really post? "
745 ((string-match "<[^>]+> *$" from)
746 (let ((name (substring from 0 (match-beginning 0))))
748 (string-match "^ *\"[^\"]*\" *$" name)
749 (not (string-match "[][.!()<>@,;:\\]" name))
752 "The From header name has bogus characters. Really post? "
756 ;; Check for long lines.
757 (or (gnus-check-before-posting 'long-lines)
759 (goto-char (point-min))
761 (concat "^" (regexp-quote mail-header-separator) "$"))
765 (< (current-column) 80))
766 (zerop (forward-line 1))))
771 "You have lines longer than 79 characters. Really post? ")))))
772 ;; Check for control characters.
773 (or (gnus-check-before-posting 'control-chars)
775 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
777 "The article contains control characters. Really post? ")
779 ;; Check excessive size.
780 (or (gnus-check-before-posting 'size)
781 (if (> (buffer-size) 60000)
783 (format "The article is %d octets long. Really post? "
786 ;; Use the (size . checksum) variable to see whether the
787 ;; article is empty or has only quoted text.
789 (gnus-check-before-posting 'new-text)
790 (if (and (= (buffer-size) (car gnus-article-check-size))
791 (= (gnus-article-checksum) (cdr gnus-article-check-size)))
793 "It looks like there's no new text in your article. Really post? ")
795 ;; Check the length of the signature.
796 (or (gnus-check-before-posting 'signature)
798 (goto-char (point-max))
799 (if (not (re-search-backward gnus-signature-separator nil t))
801 (if (> (count-lines (point) (point-max)) 5)
804 "Your .sig is %d lines; it should be max 4. Really post? "
805 (count-lines (point) (point-max))))
808 (defun gnus-article-checksum ()
812 (setq sum (logxor sum (following-char)))
816 ;; Returns non-nil if this type is not to be checked.
817 (defun gnus-check-before-posting (type)
819 (or (not gnus-check-before-posting)
820 (if (listp gnus-check-before-posting)
821 (memq type gnus-check-before-posting)
824 (defun gnus-cancel-news ()
825 "Cancel an article you posted."
827 (if (or gnus-expert-user
828 (gnus-yes-or-no-p "Do you really want to cancel this article? "))
833 (or (gnus-member-of-valid 'post gnus-newsgroup-name)
834 (error "This backend does not support canceling"))
836 ;; Get header info. from original article.
838 (gnus-article-show-all-headers)
839 (goto-char (point-min))
840 (search-forward "\n\n" nil 'move)
841 (narrow-to-region (point-min) (point))
842 (setq from (mail-fetch-field "from"))
843 (setq newsgroups (mail-fetch-field "newsgroups"))
844 (setq message-id (mail-fetch-field "message-id"))
845 (setq distribution (mail-fetch-field "distribution")))
846 ;; Verify if the article is absolutely user's by comparing
847 ;; user id with value of its From: field.
850 (downcase (mail-strip-quoted-names from))
851 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
853 (ding) (gnus-message 3 "This article is not yours.")
855 ;; Make control article.
856 (set-buffer (get-buffer-create " *Gnus-canceling*"))
857 (buffer-disable-undo (current-buffer))
859 (insert "Newsgroups: " newsgroups "\n"
860 "From: " (gnus-inews-real-user-address) "\n"
861 "Subject: cancel " message-id "\n"
862 "Control: cancel " message-id "\n"
864 (concat "Distribution: " distribution "\n")
866 mail-header-separator "\n"
867 "This is a cancel message from " from ".\n")
868 ;; Send the control article to NNTP server.
869 (gnus-message 5 "Canceling your article...")
871 (if (funcall gnus-inews-article-function)
872 (gnus-message 5 "Canceling your article...done")
875 (gnus-message 1 "Cancel failed; %s"
876 (gnus-status-message gnus-newsgroup-name))
879 ;; Kill the article buffer.
880 (kill-buffer (current-buffer))))))))
883 ;;; Lowlevel inews interface.
885 ;; Dummy to avoid byte-compile warning.
886 (defvar nnspool-rejected-article-hook)
888 (defun gnus-inews-article (&optional use-group-method)
889 "Post an article in current buffer using NNTP protocol."
890 (let ((artbuf (current-buffer))
893 (goto-char (point-max))
894 ;; Require a newline at the end of the buffer since inews may
895 ;; append a .signature.
896 (or (= (preceding-char) ?\n)
898 ;; Prepare article headers. All message body such as signature
899 ;; must be inserted before Lines: field is prepared.
901 (gnus-inews-narrow-to-headers)
903 (gnus-inews-cleanup-headers)
904 ;; Remove some headers.
905 (gnus-inews-remove-headers)
906 ;; Insert some headers.
907 (gnus-inews-insert-headers)
908 ;; Let the user do all of the above.
909 (run-hooks 'gnus-inews-article-header-hook)
910 ;; Copy the Gcc header, if any.
911 (setq gcc (mail-fetch-field "gcc"))
913 ;; Check whether the article is a good Net Citizen.
914 (if (and gnus-article-check-size
915 (not (gnus-inews-check-post)))
918 ;; We fudge a hook for nnspool.
919 (setq nnspool-rejected-article-hook
925 (set-buffer (, (buffer-name)))
926 (gnus-put-in-draft-group nil 'silent))
930 1 "Couldn't enter rejected article into draft group")))))))
932 ;; Looks ok, so we do the nasty.
934 ;; This hook may insert a signature.
936 (goto-char (point-min))
937 (let ((gnus-newsgroup-name (or (mail-fetch-field "newsgroups")
938 gnus-newsgroup-name)))
939 (run-hooks 'gnus-prepare-article-hook)))
940 ;; Send off copies using mail, if that is wanted.
941 (gnus-inews-send-mail-copy)
942 ;; Remove more headers.
943 (gnus-inews-remove-headers-after-mail)
944 ;; Copy the article over to a temp buffer.
945 (nnheader-set-temp-buffer " *Gnus-posting*")
946 (insert-buffer-substring artbuf)
947 ;; Remove the header separator.
948 (goto-char (point-min))
950 (concat "^" (regexp-quote mail-header-separator) "$"))
951 (replace-match "" t t)
952 ;; Remove X- prefixes to headers.
953 (gnus-inews-dex-headers)
954 ;; Run final inews hooks. This hook may do FCC.
955 ;; The article must be saved before being posted because
956 ;; `gnus-request-post' modifies the buffer.
957 (run-hooks 'gnus-inews-article-hook)
958 ;; Copy the article over to some group, possibly.
959 (and gcc (gnus-inews-do-gcc gcc))
961 (let ((method (gnus-post-method gnus-newsgroup-name use-group-method)))
962 (setq result (gnus-request-post method)))
963 (kill-buffer (current-buffer)))
964 (run-hooks 'gnus-message-sent-hook)
965 ;; If the posting was unsuccessful (that it, it was rejected) we
966 ;; put it into the draft group.
967 (or result (gnus-put-in-draft-group))
970 (defun gnus-inews-cleanup-headers ()
971 ;; Correct newsgroups field: change sequence of spaces to comma and
972 ;; eliminate spaces around commas. Eliminate imbedded line breaks.
973 (goto-char (point-min))
974 (if (re-search-forward "^Newsgroups: +" nil t)
978 (if (re-search-forward "^[^ \t]" nil t)
982 (goto-char (point-min))
983 (while (re-search-forward "\n[ \t]+" nil t)
984 (replace-match " " t t)) ;No line breaks (too confusing)
985 (goto-char (point-min))
986 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
987 (replace-match "," t t))
988 (goto-char (point-min))
989 ;; Remove a trailing comma.
990 (if (re-search-forward ",$" nil t)
991 (replace-match "" t t))))
993 ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
994 ;; Help save the the world!
997 (let ((newsgroups (mail-fetch-field "newsgroups"))
998 (followup-to (mail-fetch-field "followup-to"))
1001 (string-match "," newsgroups) (not followup-to))
1003 (while (string-match "," newsgroups)
1005 (cons (list (substring newsgroups 0 (match-beginning 0)))
1007 (setq newsgroups (substring newsgroups (match-end 0))))
1008 (setq groups (nreverse (cons (list newsgroups) groups)))
1010 (setq to (completing-read
1011 "Followups to: (default all groups) " groups))
1012 (if (> (length to) 0)
1014 (goto-char (point-min))
1015 (insert "Followup-To: " to "\n")))))))
1017 ;; Cleanup Followup-To.
1018 (goto-char (point-min))
1019 (if (search-forward-regexp "^Followup-To: +" nil t)
1023 (if (re-search-forward "^[^ \t]" nil 'end)
1026 (goto-char (point-min))
1027 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
1028 (goto-char (point-min))
1029 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ","))))
1032 (defun gnus-inews-remove-headers ()
1033 (let ((case-fold-search t)
1034 (headers gnus-removable-headers))
1035 ;; Remove toxic headers.
1037 (goto-char (point-min))
1038 (and (re-search-forward
1039 (concat "^" (downcase (format "%s" (car headers))))
1041 (delete-region (progn (beginning-of-line) (point))
1042 (progn (forward-line 1) (point))))
1043 (setq headers (cdr headers)))))
1045 (defun gnus-inews-insert-headers (&optional headers)
1046 "Prepare article headers.
1047 Headers already prepared in the buffer are not modified.
1048 Headers in `gnus-required-headers' will be generated."
1049 (let ((Date (gnus-inews-date))
1050 (Message-ID (gnus-inews-message-id))
1051 (Organization (gnus-inews-organization))
1052 (From (gnus-inews-user-name))
1053 (Path (gnus-inews-path))
1056 (In-Reply-To (gnus-inews-in-reply-to))
1059 (Lines (gnus-inews-lines))
1060 (X-Newsreader gnus-version)
1061 (X-Mailer gnus-version)
1062 (headers (or headers gnus-required-headers))
1063 (case-fold-search t)
1065 ;; First we remove any old generated headers.
1066 (let ((headers gnus-deletable-headers))
1068 (goto-char (point-min))
1069 (and (re-search-forward
1070 (concat "^" (symbol-name (car headers)) ": *") nil t)
1071 (get-text-property (1+ (match-beginning 0)) 'gnus-deletable)
1073 (setq headers (cdr headers))))
1074 ;; If there are References, and no "Re: ", then the thread has
1075 ;; changed name. See Son-of-1036.
1076 (if (and (mail-fetch-field "references")
1077 (get-buffer gnus-article-buffer))
1078 (let ((psubject (gnus-simplify-subject-re
1079 (mail-fetch-field "subject"))))
1080 (or (and psubject gnus-reply-subject
1081 (string= (gnus-simplify-subject-re gnus-reply-subject)
1084 (string-match "@" Message-ID)
1086 (concat (substring Message-ID 0 (match-beginning 0))
1088 (substring Message-ID (match-beginning 0))))))))
1089 ;; Go through all the required headers and see if they are in the
1090 ;; articles already. If they are not, or are empty, they are
1091 ;; inserted automatically - except for Subject, Newsgroups and
1094 (goto-char (point-min))
1095 (setq elem (pop headers))
1097 (setq header (car elem))
1099 (when (or (not (re-search-forward
1100 (concat "^" (downcase (symbol-name header)) ":") nil t))
1102 ;; The header was found. We insert a space after the
1103 ;; colon, if there is none.
1104 (if (/= (following-char) ? ) (insert " "))
1105 ;; Find out whether the header is empty...
1106 (looking-at "[ \t]*$")))
1107 ;; So we find out what value we should insert.
1110 ((and (consp elem) (eq (car elem) 'optional))
1111 ;; This is an optional header. If the cdr of this
1112 ;; is something that is nil, then we do not insert
1114 (setq header (cdr elem))
1115 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
1116 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
1118 ;; The element is a cons. Either the cdr is a
1119 ;; string to be inserted verbatim, or it is a
1120 ;; function, and we insert the value returned from
1122 (or (and (stringp (cdr elem)) (cdr elem))
1123 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
1124 ((and (boundp header) (symbol-value header))
1125 ;; The element is a symbol. We insert the value
1126 ;; of this symbol, if any.
1127 (symbol-value header))
1129 ;; We couldn't generate a value for this header,
1130 ;; so we just ask the user.
1131 (read-from-minibuffer
1132 (format "Empty header for %s; enter value: " header)))))
1133 ;; Finally insert the header.
1135 (not (equal value "")))
1139 ;; This header didn't exist, so we insert it.
1140 (goto-char (point-max))
1141 (insert (symbol-name header) ": " value "\n")
1143 ;; The value of this header was empty, so we clear
1144 ;; totally and insert the new value.
1145 (delete-region (point) (gnus-point-at-bol))
1147 ;; Add the deletable property to the headers that require it.
1148 (and (memq header gnus-deletable-headers)
1149 (progn (beginning-of-line) (looking-at "[^:]+: "))
1150 (add-text-properties
1151 (point) (match-end 0)
1152 '(gnus-deletable t face italic) (current-buffer)))))))
1153 ;; Insert new Sender if the From is strange.
1154 (let ((from (mail-fetch-field "from"))
1155 (sender (mail-fetch-field "sender")))
1157 (not (gnus-check-before-posting 'sender))
1159 (downcase (car (gnus-extract-address-components from)))
1160 (downcase (gnus-inews-real-user-address))))
1164 (downcase (car (gnus-extract-address-components sender)))
1165 (downcase (gnus-inews-real-user-address))))))
1167 (goto-char (point-min))
1168 (and (re-search-forward "^Sender:" nil t)
1171 (insert "Original-")
1172 (beginning-of-line)))
1173 (insert "Sender: " (gnus-inews-real-user-address) "\n"))))))
1176 (defun gnus-inews-insert-signature ()
1177 "Insert a signature file.
1178 If `gnus-signature-function' is bound and returns a string, this
1179 string is used instead of the variable `gnus-signature-file'.
1180 In either case, if the string is a file name, this file is
1181 inserted. If the string is not a file name, the string itself is
1184 If you never want any signature inserted, set both of these variables to
1188 (or (and gnus-signature-function
1189 (funcall gnus-signature-function gnus-newsgroup-name))
1190 gnus-signature-file)))
1192 (or (file-exists-p signature)
1193 (string-match " " signature)
1195 "^/[^/]+/" (expand-file-name signature)))))
1197 (goto-char (point-max))
1198 (if (and mail-signature (search-backward "\n-- \n" nil t))
1200 ;; Delete any previous signatures.
1201 (if (search-backward "\n-- \n" nil t)
1202 (delete-region (point) (point-max)))
1203 (or (eolp) (insert "\n"))
1205 (if (file-exists-p signature)
1206 (insert-file-contents signature)
1208 (goto-char (point-max))
1209 (or (bolp) (insert "\n"))))))))
1211 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1212 (defun gnus-inews-insert-mime-headers ()
1213 (goto-char (point-min))
1214 (let ((mail-header-separator
1216 (goto-char (point-min))
1217 (if (and (search-forward (concat "\n" mail-header-separator "\n")
1219 (not (search-backward "\n\n" nil t)))
1220 mail-header-separator
1222 (or (mail-position-on-field "Mime-Version")
1225 (goto-char (point-min))
1226 (re-search-forward "[\200-\377]" nil t))
1227 (or (mail-position-on-field "Content-Type")
1228 (insert "text/plain; charset=ISO-8859-1"))
1229 (or (mail-position-on-field "Content-Transfer-Encoding")
1231 (t (or (mail-position-on-field "Content-Type")
1232 (insert "text/plain; charset=US-ASCII"))
1233 (or (mail-position-on-field "Content-Transfer-Encoding")
1234 (insert "7bit")))))))
1236 (defun gnus-inews-do-fcc ()
1237 "Process Fcc headers in the current buffer.
1238 Unless the first character of the field is `|', the article is saved
1239 to the specified file using the function specified by the variable
1240 gnus-author-copy-saver. The default function rmail-output saves in
1241 Unix mailbox format.
1243 If the first character is `|', the contents of the article is sent to
1244 a program specified by the rest of the value."
1245 (let ((case-fold-search t) ;Should ignore case.
1249 (gnus-narrow-to-headers)
1250 (while (setq file (mail-fetch-field "fcc"))
1252 (nnheader-remove-header "fcc" nil t))
1253 ;; Process FCC operations.
1256 (setq file (pop list))
1257 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
1258 ;; Pipe the article to the program in question.
1259 (call-process-region (point-min) (point-max) shell-file-name
1260 nil nil nil "-c" (match-string 1 file))
1261 ;; Save the article.
1262 (setq file (expand-file-name file))
1263 (gnus-make-directory (file-name-directory file))
1264 (if (and gnus-author-copy-saver
1265 (not (eq gnus-author-copy-saver 'rmail-output)))
1266 (funcall gnus-author-copy-saver file)
1267 (if (and (file-readable-p file) (mail-file-babyl-p file))
1268 (gnus-output-to-rmail file)
1269 (rmail-output file 1 t t)))))))))
1271 (defun gnus-inews-path ()
1273 (let ((login-name (gnus-inews-login-name)))
1274 (cond ((null gnus-use-generic-path)
1275 (concat (nth 1 gnus-select-method) "!" login-name))
1276 ((stringp gnus-use-generic-path)
1277 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1278 (concat gnus-use-generic-path "!" login-name))
1281 (defun gnus-inews-user-name ()
1282 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1283 (let ((full-name (gnus-inews-full-name))
1284 (address (if (or gnus-user-login-name gnus-use-generic-from
1285 gnus-local-domain (getenv "DOMAINNAME"))
1286 (concat (gnus-inews-login-name) "@"
1287 (gnus-inews-domain-name gnus-use-generic-from))
1288 user-mail-address)))
1289 (or gnus-user-from-line
1291 ;; User's full name.
1292 (cond ((string-equal full-name "&") ;Unix hack.
1293 (concat " (" (user-login-name) ")"))
1294 ((string-match "[^ ]+@[^ ]+ +(.*)" address)
1297 (concat " (" full-name ")")))))))
1299 (defun gnus-inews-real-user-address ()
1300 "Return the \"real\" user address.
1301 This function tries to ignore all user modifications, and
1302 give as trustworthy answer as possible."
1303 (concat (user-login-name) "@" (gnus-inews-full-address)))
1305 (defun gnus-inews-login-name ()
1306 "Return login name."
1307 (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1309 (defun gnus-inews-full-name ()
1310 "Return full user name."
1311 (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1313 (defun gnus-inews-domain-name (&optional genericfrom)
1314 "Return user's domain name.
1315 If optional argument GENERICFROM is a string, use it as the domain
1316 name; if it is non-nil, strip off local host name from the domain name.
1317 If the function `system-name' returns full internet name and the
1318 domain is undefined, the domain name is got from it."
1319 (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1320 (let* ((system-name (system-name))
1322 (or (if (stringp genericfrom) genericfrom)
1323 (getenv "DOMAINNAME")
1325 ;; Function `system-name' may return full internet name.
1326 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1327 (if (string-match "\\.." system-name)
1328 ;; Some machines return "name.", and that's not
1330 (substring system-name (1- (match-end 0))))
1331 (read-string "Domain name (no host): ")))
1332 (host (or (if (string-match "\\." system-name)
1333 (substring system-name 0 (match-beginning 0)))
1335 (if (string-equal "." (substring domain 0 1))
1336 (setq domain (substring domain 1)))
1337 ;; Support GENERICFROM as same as standard Bnews system.
1338 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1339 (cond ((null genericfrom)
1340 (concat host "." domain))
1341 ;;((stringp genericfrom) genericfrom)
1343 (if (string-match "\\." (system-name))
1345 (substring user-mail-address
1346 (1+ (string-match "@" user-mail-address))))))
1348 (defun gnus-inews-full-address ()
1349 (let ((domain (gnus-inews-domain-name))
1350 (system (system-name))
1351 (case-fold-search t))
1352 (if (string-match "\\." system) system
1353 (if (string-match (concat "^" (regexp-quote system)) domain) domain
1354 (concat system "." domain)))))
1356 (defun gnus-inews-message-id ()
1357 "Generate unique Message-ID for user."
1358 ;; Message-ID should not contain a slash and should be terminated by
1359 ;; a number. I don't know the reason why it is so.
1360 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1362 (defvar gnus-unique-id-char nil)
1364 ;; If you ever change this function, make sure the new version
1365 ;; cannot generate IDs that the old version could.
1366 ;; You might for example insert a "." somewhere (not next to another dot
1367 ;; or string boundary), or modify the newsreader name to "Ding".
1368 (defun gnus-inews-unique-id ()
1369 ;; Dont use microseconds from (current-time), they may be unsupported.
1370 ;; Instead we use this randomly inited counter.
1371 (setq gnus-unique-id-char
1372 (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1373 ;; (current-time) returns 16-bit ints,
1374 ;; and 2^16*25 just fits into 4 digits i base 36.
1376 (let ((tm (if (fboundp 'current-time)
1377 (current-time) '(12191 46742 287898))))
1379 (if (memq system-type '(ms-dos emx vax-vms))
1380 (let ((user (downcase (gnus-inews-login-name))))
1381 (while (string-match "[^a-z0-9_]" user)
1382 (aset user (match-beginning 0) ?_))
1384 (gnus-number-base36 (user-uid) -1))
1385 (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1386 (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1387 ;; Append the newsreader name, because while the generated
1388 ;; ID is unique to this newsreader, other newsreaders might
1389 ;; otherwise generate the same ID via another algorithm.
1393 (defun gnus-inews-date ()
1394 "Current time string."
1395 (timezone-make-date-arpa-standard
1396 (current-time-string) (current-time-zone)))
1398 (defun gnus-inews-organization ()
1399 "Return user's organization.
1400 The ORGANIZATION environment variable is used if defined.
1401 If not, the variable `gnus-local-organization' is used instead.
1402 If it is a function, the function will be called with the current
1403 newsgroup name as the argument.
1404 If this is a file name, the contents of this file will be used as the
1406 (let* ((organization
1407 (or (getenv "ORGANIZATION")
1408 (if gnus-local-organization
1409 (if (gnus-functionp gnus-local-organization)
1410 (funcall gnus-local-organization gnus-newsgroup-name)
1411 gnus-local-organization))
1412 gnus-organization-file
1413 "~/.organization")))
1414 (and (stringp organization)
1415 (> (length organization) 0)
1416 (or (file-exists-p organization)
1417 (string-match " " organization)
1418 (not (string-match "^/usr/lib/\\|^~/" organization)))
1420 (gnus-set-work-buffer)
1421 (if (file-exists-p organization)
1422 (insert-file-contents organization)
1423 (insert organization))
1424 (goto-char (point-min))
1425 (while (re-search-forward " *\n *" nil t)
1426 (replace-match " " t t))
1427 (buffer-substring (point-min) (point-max))))))
1429 (defun gnus-inews-lines ()
1430 "Count the number of lines and return numeric string."
1434 (goto-char (point-min))
1436 (concat "^" (regexp-quote mail-header-separator) "$"))
1438 (int-to-string (count-lines (point) (point-max))))))
1440 (defun gnus-inews-in-reply-to ()
1441 "Return the In-Reply-To header for this message."
1446 ;;; Gnus Mail Functions
1449 ;;; Mail reply commands of Gnus summary mode
1451 (defun gnus-summary-reply (yank &optional yank-articles)
1452 "Reply mail to news author.
1453 If prefix argument YANK is non-nil, original article is yanked automatically.
1454 Customize the variable gnus-mail-reply-method to use another mailer."
1456 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1457 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1458 (gnus-set-global-variables)
1459 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1460 (gnus-summary-select-article)
1461 (bury-buffer gnus-article-buffer)
1462 (gnus-mail-reply (or yank-articles (not (not yank)))))
1464 (defun gnus-summary-reply-with-original (n)
1465 "Reply mail to news author with original article.
1466 Customize the variable gnus-mail-reply-method to use another mailer."
1468 (gnus-summary-reply t (gnus-summary-work-articles n)))
1470 (defun gnus-summary-mail-forward (post)
1471 "Forward the current message to another user.
1472 Customize the variable gnus-mail-forward-method to use another mailer."
1474 (gnus-set-global-variables)
1475 (gnus-summary-select-article)
1476 (gnus-copy-article-buffer)
1478 (gnus-forward-using-post gnus-article-copy)
1479 (gnus-mail-forward gnus-article-copy)))
1481 (defun gnus-summary-post-forward ()
1482 "Forward the current article to a newsgroup."
1484 (gnus-summary-mail-forward t))
1486 (defvar gnus-nastygram-message
1487 "The following article was inappropriately posted to %s.\n"
1488 "Format string to insert in nastygrams.
1489 The current group name will be inserted at \"%s\".")
1491 (defun gnus-summary-mail-nastygram (n)
1492 "Send a nastygram to the author of the current article."
1494 (if (or gnus-expert-user
1496 "Really send a nastygram to the author of the current article? "))
1497 (let ((group gnus-newsgroup-name))
1498 (gnus-summary-reply-with-original n)
1499 (set-buffer gnus-mail-buffer)
1500 (insert (format gnus-nastygram-message group))
1501 (gnus-mail-send-and-exit))))
1503 (defun gnus-summary-mail-other-window ()
1504 "Compose mail in other window.
1505 Customize the variable `gnus-mail-other-window-method' to use another
1508 (gnus-set-global-variables)
1511 (defun gnus-new-mail (&optional to)
1513 (when (and gnus-interactive-post
1514 (not gnus-expert-user))
1515 (setq subject (read-string "Subject: ")))
1516 (pop-to-buffer gnus-mail-buffer)
1518 (gnus-mail-setup 'new to subject)
1519 (run-hooks 'gnus-mail-hook)))
1521 (defun gnus-mail-reply (&optional yank to-address followup)
1523 (set-buffer gnus-summary-buffer)
1524 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1525 (cur (cons (current-buffer) (cdr gnus-article-current)))
1526 (winconf (current-window-configuration))
1527 from subject date reply-to message-of to cc
1528 references message-id sender follow-to sendto elt new-cc new-to
1530 (set-buffer (get-buffer-create gnus-mail-buffer))
1532 (if (and (buffer-modified-p)
1535 "Unsent message being composed; erase it? ")))
1539 (gnus-copy-article-buffer)
1541 (set-buffer gnus-article-copy)
1542 (gnus-narrow-to-headers)
1544 ;; This is a regular reply.
1545 (if (gnus-functionp gnus-reply-to-function)
1546 (setq follow-to (funcall gnus-reply-to-function group)))
1547 ;; This is a followup.
1548 (if (gnus-functionp gnus-followup-to-function)
1551 (funcall gnus-followup-to-function group)))))
1552 (setq from (mail-fetch-field "from"))
1553 (setq date (or (mail-fetch-field "date")
1554 (mail-header-date gnus-current-headers)))
1555 (setq message-of (gnus-message-of from date))
1556 (setq sender (mail-fetch-field "sender"))
1557 (setq subject (or (mail-fetch-field "subject") "none"))
1558 ;; Remove any (buggy) Re:'s that are present and make a
1560 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1561 (setq subject (substring subject (match-end 0))))
1562 (setq subject (concat "Re: " subject))
1563 (setq to (mail-fetch-field "to"))
1564 (setq cc (mail-fetch-field "cc"))
1565 (setq mct (mail-fetch-field "mail-copies-to"))
1566 (setq reply-to (mail-fetch-field "reply-to"))
1567 (setq references (mail-fetch-field "references"))
1568 (setq message-id (mail-fetch-field "message-id"))
1570 (setq mctdo (not (equal mct "never")))
1572 (if (not (and followup (not to-address)))
1573 (setq new-to (or reply-to from))
1576 (gnus-set-work-buffer)
1577 (unless (equal mct "never")
1578 (insert (or reply-to from "")))
1579 (insert (if (bolp) "" ", ")
1581 (if (or (not mct) (not mctdo)) ""
1582 (concat (if (bolp) "" ", ") mct))
1583 (if cc (concat (if (bolp) "" ", ") cc) ""))
1584 (goto-char (point-min))
1588 (cons (mail-strip-quoted-names addr) addr))
1589 (nreverse (mail-parse-comma-list))))
1592 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
1593 (setq new-to (cdr (pop ccalist)))
1596 (lambda (addr) (cdr addr))
1600 (setq news-reply-yank-from (or from "(nobody)"))
1601 (setq news-reply-yank-message-id
1602 (or message-id "(unknown Message-ID)"))
1604 ;; Gather the "to" addresses out of the follow-to list and remove
1606 (if (and follow-to (listp follow-to))
1607 (while (setq elt (assoc "To" follow-to))
1608 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1609 (setq follow-to (delq elt follow-to))))
1612 (if followup 'followup 'reply)
1614 (if (and follow-to (not (stringp follow-to))) sendto
1615 (or follow-to new-to sender "")))
1617 (if (zerop (length new-cc)) nil new-cc)
1620 (make-local-variable 'gnus-article-reply)
1621 (setq gnus-article-reply cur)
1622 (make-local-variable 'gnus-prev-winconf)
1623 (setq gnus-prev-winconf winconf)
1624 (make-local-variable 'gnus-reply-subject)
1625 (setq gnus-reply-subject subject)
1626 (make-local-variable 'gnus-in-reply-to)
1627 (setq gnus-in-reply-to message-of)
1629 (auto-save-mode auto-save-default)
1631 (if (and follow-to (listp follow-to))
1633 (goto-char (point-min))
1634 (re-search-forward "^To:" nil t)
1638 (insert (car (car follow-to)) ": " (cdr (car follow-to)) "\n")
1639 (setq follow-to (cdr follow-to)))))
1640 (nnheader-insert-references references message-id)
1642 ;; Now the headers should be ok, so we do the yanking.
1643 (goto-char (point-min))
1645 (concat "^" (regexp-quote mail-header-separator) "$"))
1648 (gnus-configure-windows 'reply 'force)
1649 (let ((last (point))
1651 (if (not (listp yank))
1653 ;; Just a single article being yanked.
1655 (mail-yank-original nil))
1656 (or mail-yank-hooks mail-citation-hook
1657 (run-hooks 'news-reply-header-hook)))
1659 (save-window-excursion
1660 (set-buffer gnus-summary-buffer)
1661 (gnus-summary-select-article nil nil nil (car yank))
1662 (gnus-summary-remove-process-mark (car yank)))
1664 (gnus-copy-article-buffer)
1665 (mail-yank-original nil)
1667 (narrow-to-region (point-min) (point))
1669 (let ((news-reply-yank-from
1671 (set-buffer gnus-article-buffer)
1672 (or (mail-fetch-field "from") "(nobody)")))
1673 (news-reply-yank-message-id
1675 (set-buffer gnus-article-buffer)
1676 (or (mail-fetch-field "message-id")
1677 "(unknown Message-ID)"))))
1678 (or mail-yank-hooks mail-citation-hook
1679 (run-hooks 'news-reply-header-hook))
1680 (setq end (point-max)))))
1682 (setq yank (cdr yank))))
1685 (gnus-configure-windows 'reply-yank 'force))
1686 (run-hooks 'gnus-mail-hook)))))
1688 (defun gnus-new-news (&optional group inhibit-prompt)
1689 "Set up a *post-news* buffer that points to GROUP.
1690 If INHIBIT-PROMPT, never prompt for a Subject."
1691 (let ((winconf (current-window-configuration))
1693 (when (and gnus-interactive-post
1694 (not inhibit-prompt)
1695 (not gnus-expert-user))
1696 (setq subject (read-string "Subject: ")))
1697 (pop-to-buffer gnus-post-news-buffer)
1700 ;; Let posting styles be configured.
1701 (gnus-configure-posting-styles)
1702 (news-setup nil subject nil (and group (gnus-group-real-name group)) nil)
1703 (goto-char (point-min))
1705 (unless (re-search-forward
1706 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1707 (goto-char (point-max)))
1710 (gnus-inews-insert-bfcc)
1711 (gnus-inews-insert-signature)
1712 (and gnus-post-prepare-function
1713 (gnus-functionp gnus-post-prepare-function)
1714 (funcall gnus-post-prepare-function group))
1715 (goto-char (point-min))
1717 (re-search-forward "^Subject: " nil t)
1718 (re-search-forward "^Newsgroups: " nil t))
1719 (run-hooks 'gnus-post-prepare-hook)
1720 (make-local-variable 'gnus-prev-winconf)
1721 (setq gnus-prev-winconf winconf)
1722 (gnus-inews-modify-mail-mode-map)
1723 (local-set-key "\C-c\C-c" 'gnus-inews-news)))
1725 (defun gnus-news-followup (&optional yank group)
1727 (set-buffer gnus-summary-buffer)
1728 (if (not (or (not gnus-novice-user)
1731 "Are you sure you want to post to all of USENET? ")))
1733 (let ((group (gnus-group-real-name (or group gnus-newsgroup-name)))
1734 (cur (cons (current-buffer) (cdr gnus-article-current)))
1735 (winconf (current-window-configuration))
1736 from subject date reply-to message-of
1737 references message-id sender follow-to sendto elt
1738 followup-to distribution newsgroups)
1739 (set-buffer (get-buffer-create gnus-post-news-buffer))
1741 (if (and (buffer-modified-p)
1744 "Unsent message being composed; erase it? ")))
1748 (gnus-copy-article-buffer)
1750 (set-buffer gnus-article-copy)
1751 (gnus-narrow-to-headers)
1752 (if (gnus-functionp gnus-followup-to-function)
1755 (funcall gnus-followup-to-function group))))
1756 (setq from (mail-fetch-field "from"))
1757 (setq date (or (mail-fetch-field "date")
1758 (mail-header-date gnus-current-headers)))
1759 (setq message-of (gnus-message-of from date))
1760 (setq subject (or (mail-fetch-field "subject") "none"))
1761 ;; Remove any (buggy) Re:'s that are present and make a
1763 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1764 (setq subject (substring subject (match-end 0))))
1765 (setq subject (concat "Re: " subject))
1766 (setq references (mail-fetch-field "references"))
1767 (setq message-id (mail-fetch-field "message-id"))
1768 (setq followup-to (mail-fetch-field "followup-to"))
1769 (setq newsgroups (mail-fetch-field "newsgroups"))
1770 (setq distribution (mail-fetch-field "distribution"))
1771 ;; Remove bogus distribution.
1772 (and (stringp distribution)
1773 (string-match "world" distribution)
1774 (setq distribution nil))
1777 (setq news-reply-yank-from (or from "(nobody)"))
1778 (setq news-reply-yank-message-id
1779 (or message-id "(unknown Message-ID)"))
1781 ;; Gather the "to" addresses out of the follow-to list and remove
1783 (if (and follow-to (listp follow-to))
1784 (while (setq elt (assoc "Newsgroups" follow-to))
1785 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1786 (setq follow-to (delq elt follow-to))))
1788 ;; Let posting styles be configured.
1789 (gnus-configure-posting-styles)
1791 (news-setup nil subject nil
1794 gnus-use-followup-to
1795 (or (not (eq gnus-use-followup-to 'ask))
1798 "Use Followup-To %s? " followup-to)))
1800 newsgroups group "")
1803 (make-local-variable 'gnus-article-reply)
1804 (setq gnus-article-reply cur)
1805 (make-local-variable 'gnus-prev-winconf)
1806 (setq gnus-prev-winconf winconf)
1807 (make-local-variable 'gnus-reply-subject)
1808 (setq gnus-reply-subject (mail-header-subject gnus-current-headers))
1809 (make-local-variable 'gnus-in-reply-to)
1810 (setq gnus-in-reply-to message-of)
1812 (gnus-inews-insert-signature)
1814 (and gnus-post-prepare-function
1815 (gnus-functionp gnus-post-prepare-function)
1816 (funcall gnus-post-prepare-function group))
1817 (run-hooks 'gnus-post-prepare-hook)
1819 (auto-save-mode auto-save-default)
1820 (gnus-inews-modify-mail-mode-map)
1821 (local-set-key "\C-c\C-c" 'gnus-inews-news)
1823 (if (and follow-to (listp follow-to))
1825 (goto-char (point-min))
1826 (and (re-search-forward "^Newsgroups:" nil t)
1829 (insert (car (car follow-to)) ": "
1830 (cdr (car follow-to)) "\n")
1831 (setq follow-to (cdr follow-to)))))
1833 ;; If a distribution existed, we use it.
1836 (mail-position-on-field "Distribution")
1837 (insert distribution)))
1839 (nnheader-insert-references references message-id)
1841 ;; Handle `gnus-auto-mail-to-author'.
1842 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
1843 ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
1844 (let ((to (if (if (eq gnus-auto-mail-to-author 'ask)
1845 (y-or-n-p "Also send mail to author? ")
1846 gnus-auto-mail-to-author)
1848 (set-buffer gnus-article-copy)
1849 (gnus-fetch-field "reply-to"))
1851 (x-mail (save-excursion
1852 (set-buffer gnus-article-copy)
1853 (gnus-fetch-field "x-mail-copy-to"))))
1854 ;; Deny sending copy if there's a negative X-Mail-Copy-To
1857 (if (and (string= x-mail "never")
1858 (not (eq gnus-auto-mail-to-author 'force)))
1861 ;; Insert a To or Cc header.
1863 (if (mail-fetch-field "To")
1866 (insert "Cc: " to "\n"))
1867 (mail-position-on-field "To")
1870 (gnus-inews-insert-bfcc)
1872 ;; Now the headers should be ok, so we do the yanking.
1873 (goto-char (point-min))
1875 (concat "^" (regexp-quote mail-header-separator) "$"))
1879 (gnus-configure-windows 'followup 'force)
1882 (let ((last (point))
1884 (if (not (listp yank))
1887 (mail-yank-original nil))
1888 (or mail-yank-hooks mail-citation-hook
1889 (run-hooks 'news-reply-header-hook)))
1891 (save-window-excursion
1892 (set-buffer gnus-summary-buffer)
1893 (gnus-summary-select-article nil nil nil (car yank))
1894 (gnus-summary-remove-process-mark (car yank)))
1896 (gnus-copy-article-buffer)
1897 (mail-yank-original nil)
1899 (or mail-yank-hooks mail-citation-hook
1900 (run-hooks 'news-reply-header-hook))
1902 (setq yank (cdr yank))))
1904 (gnus-configure-windows 'followup-yank 'force))
1906 (make-local-variable 'gnus-article-check-size)
1907 (setq gnus-article-check-size
1908 (cons (buffer-size) (gnus-article-checksum))))))))
1910 (defun gnus-message-of (from date)
1911 "Take a FROM and a DATE and create an IN-REPLY-TO."
1917 (string-match " *at \\| *@ \\| *(\\| *<" from)))
1918 (concat (if stop-pos (substring from 0 stop-pos) from)
1920 (if (or (not date) (string= date ""))
1921 "(unknown date)" date))))))
1923 (defun gnus-mail-yank-original ()
1926 (mail-yank-original nil))
1927 (or mail-yank-hooks mail-citation-hook
1928 (run-hooks 'news-reply-header-hook)))
1930 (defun gnus-mail-send-and-exit (&optional dont-send)
1931 "Send the current mail and return to Gnus."
1933 (let* ((reply gnus-article-reply)
1934 (winconf gnus-prev-winconf)
1935 (address-group gnus-add-to-address)
1936 (to-address (and address-group
1937 (mail-fetch-field "to"))))
1938 (setq gnus-add-to-address nil)
1939 (or dont-send (gnus-mail-send))
1941 ;; This mail group doesn't have a `to-address', so we add one
1944 (gnus-group-add-parameter
1945 address-group (cons 'to-address to-address)))
1946 (if (get-buffer gnus-group-buffer)
1948 (if (gnus-buffer-exists-p (car-safe reply))
1950 (set-buffer (car reply))
1952 (gnus-summary-mark-article-as-replied
1954 (and winconf (set-window-configuration winconf))))))
1956 (defun gnus-put-message ()
1957 "Put the current message in some group and return to Gnus."
1959 (let ((reply gnus-article-reply)
1960 (winconf gnus-prev-winconf)
1961 (group gnus-newsgroup-name)
1964 (or (and group (not (gnus-group-read-only-p group)))
1965 (setq group (read-string "Put in group: " nil
1966 (gnus-writable-groups))))
1967 (and (gnus-gethash group gnus-newsrc-hashtb)
1968 (error "No such group: %s" group))
1973 (gnus-inews-narrow-to-headers)
1974 (let (gnus-deletable-headers)
1975 (if (eq major-mode 'mail-mode)
1976 (gnus-inews-insert-headers gnus-required-mail-headers)
1977 (gnus-inews-insert-headers)))
1978 (goto-char (point-max))
1979 (insert "Gcc: " group "\n")
1984 (if (get-buffer gnus-group-buffer)
1986 (if (gnus-buffer-exists-p (car-safe reply))
1988 (set-buffer (car reply))
1990 (gnus-summary-mark-article-as-replied
1992 (and winconf (set-window-configuration winconf))))))
1994 (defun gnus-forward-make-subject (buffer)
1997 (concat "[" (if (memq 'mail (assoc (symbol-name
1998 (car (gnus-find-method-for-group
1999 gnus-newsgroup-name)))
2000 gnus-valid-select-methods))
2001 (gnus-fetch-field "From")
2002 gnus-newsgroup-name)
2003 "] " (or (gnus-fetch-field "Subject") ""))))
2005 (defun gnus-forward-insert-buffer (buffer)
2008 (if gnus-signature-before-forwarded-message
2009 (goto-char (point-max))
2010 (goto-char (point-min))
2012 (concat "^" (regexp-quote mail-header-separator) "$"))
2014 ;; Narrow to the area we are to insert.
2015 (narrow-to-region (point) (point))
2016 ;; Insert the separators and the forwarded buffer.
2017 (insert gnus-forward-start-separator)
2018 (insert-buffer-substring buffer)
2019 (goto-char (point-max))
2020 (insert gnus-forward-end-separator)
2021 ;; Delete any invisible text.
2022 (goto-char (point-min))
2024 (while (setq beg (next-single-property-change (point) 'invisible))
2026 (delete-region beg (or (next-single-property-change
2030 (defun gnus-mail-forward (&optional buffer)
2031 "Forward the current message to another user using mail."
2032 (let* ((forward-buffer (or buffer (current-buffer)))
2033 (winconf (current-window-configuration))
2034 (subject (gnus-forward-make-subject forward-buffer)))
2035 (set-buffer (get-buffer-create gnus-mail-buffer))
2036 (if (and (buffer-modified-p)
2039 "Unsent message being composed; erase it? ")))
2042 (gnus-mail-setup 'forward nil subject)
2043 (make-local-variable 'gnus-prev-winconf)
2044 (setq gnus-prev-winconf winconf)
2045 (gnus-forward-insert-buffer forward-buffer)
2046 (goto-char (point-min))
2047 (re-search-forward "^To: ?" nil t)
2048 (gnus-configure-windows 'mail-forward 'force)
2049 ;; You have a chance to arrange the message.
2050 (run-hooks 'gnus-mail-forward-hook)
2051 (run-hooks 'gnus-mail-hook))))
2053 (defun gnus-forward-using-post (&optional buffer)
2055 (let* ((forward-buffer (or buffer (current-buffer)))
2056 (subject (gnus-forward-make-subject forward-buffer))
2057 (gnus-newsgroup-name nil))
2058 (gnus-post-news 'post nil nil nil nil subject)
2060 (gnus-forward-insert-buffer forward-buffer)
2061 ;; You have a chance to arrange the message.
2062 (run-hooks 'gnus-mail-forward-hook)))))
2064 (defun gnus-mail-other-window-using-mail ()
2065 "Compose mail other window using mail."
2066 (let ((winconf (current-window-configuration)))
2067 (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
2068 (gnus-inews-modify-mail-mode-map)
2069 (make-local-variable 'gnus-prev-winconf)
2070 (setq gnus-prev-winconf winconf)
2071 (run-hooks 'gnus-mail-hook)
2072 (gnus-configure-windows 'summary-mail 'force)))
2074 (defun gnus-article-mail (yank)
2075 "Send a reply to the address near point.
2076 If YANK is non-nil, include the original article."
2080 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
2081 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
2084 (switch-to-buffer gnus-summary-buffer)
2085 (gnus-mail-reply yank address)))))
2088 "Send a bug report to the Gnus maintainers."
2090 (let ((winconf (current-window-configuration)))
2091 (delete-other-windows)
2092 (switch-to-buffer "*Gnus Help Bug*")
2094 (insert gnus-bug-message)
2095 (goto-char (point-min))
2096 (pop-to-buffer "*Gnus Bug*")
2099 (mail-setup gnus-maintainer nil nil nil nil nil)
2100 (auto-save-mode auto-save-default)
2101 (make-local-variable 'gnus-prev-winconf)
2102 (setq gnus-prev-winconf winconf)
2103 (gnus-inews-modify-mail-mode-map)
2104 (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
2105 (goto-char (point-min))
2106 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2108 (insert (format "%s\n%s\n\n\n\n\n" (gnus-version) (emacs-version)))
2110 (goto-char (point-min))
2111 (search-forward "Subject: " nil t)
2114 (defun gnus-bug-mail-send-and-exit ()
2115 "Send the bug message and exit."
2117 (and (get-buffer "*Gnus Help Bug*")
2118 (kill-buffer "*Gnus Help Bug*"))
2119 (gnus-mail-send-and-exit))
2121 (defun gnus-debug ()
2122 "Attemps to go through the Gnus source file and report what variables have been changed.
2123 The source file has to be in the Emacs load path."
2125 (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el"))
2126 file dirs expr olist sym)
2127 (message "Please wait while we snoop your variables...")
2130 (set-buffer (get-buffer-create " *gnus bug info*"))
2131 (buffer-disable-undo (current-buffer))
2134 (setq dirs load-path)
2136 (if (or (not (car dirs))
2137 (not (stringp (car dirs)))
2139 (setq file (concat (file-name-as-directory
2140 (car dirs)) (car files))))))
2141 (setq dirs (cdr dirs))
2143 (insert-file-contents file)
2144 (goto-char (point-min))
2145 (or (re-search-forward "^;;* *Internal variables" nil t)
2146 (error "Malformed sources in file %s" file))
2147 (narrow-to-region (point-min) (point))
2148 (goto-char (point-min))
2149 (while (setq expr (condition-case ()
2150 (read (current-buffer)) (error nil)))
2152 (and (eq (car expr) 'defvar)
2153 (stringp (nth 3 expr))
2154 (or (not (boundp (nth 1 expr)))
2155 (not (equal (eval (nth 2 expr))
2156 (symbol-value (nth 1 expr)))))
2157 (setq olist (cons (nth 1 expr) olist)))
2159 (setq files (cdr files)))
2160 (kill-buffer (current-buffer)))
2161 (insert "------------------- Environment follows -------------------\n\n")
2163 (if (boundp (car olist))
2164 (insert "(setq " (symbol-name (car olist))
2165 (if (or (consp (setq sym (symbol-value (car olist))))
2167 (not (or (eq sym nil)
2170 (prin1-to-string (symbol-value (car olist))) ")\n")
2171 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
2172 (setq olist (cdr olist)))
2174 ;; Remove any null chars - they seem to cause trouble for some
2175 ;; mailers. (Byte-compiled output from the stuff above.)
2176 (goto-char (point-min))
2177 (while (re-search-forward "[\000\200]" nil t)
2178 (replace-match "" t t))))
2181 ;;; Treatment of rejected articles.
2186 (defun gnus-summary-resend-bounced-mail (fetch)
2187 "Re-mail the current message.
2188 This only makes sense if the current message is a bounce message than
2189 contains some mail you have written which has been bounced back to
2191 If FETCH, try to fetch the article that this is a reply to, if indeed
2194 (gnus-summary-select-article t)
2195 ;; Create a mail buffer.
2198 (insert-buffer-substring gnus-article-buffer)
2199 (goto-char (point-min))
2200 (search-forward "\n\n")
2201 ;; We remove everything before the bounced mail.
2204 (if (re-search-forward "[^ \t]*:" nil t)
2210 (gnus-narrow-to-headers)
2211 (nnheader-remove-header gnus-bounced-headers-junk t)
2212 (setq references (mail-fetch-field "references"))
2213 (goto-char (point-max))
2214 (insert mail-header-separator)))
2215 ;; If there are references, we fetch the article we answered to.
2218 (string-match "\\(<[^]+>\\)[ \t]*$" references)
2219 (gnus-summary-refer-article
2220 (substring references (match-beginning 1) (match-end 1)))
2222 (gnus-summary-show-all-headers)
2223 (gnus-configure-windows 'compose-bounce))))
2224 (goto-char (point-min)))
2228 (defun gnus-mail-send ()
2229 "Send the current buffer as mail.
2230 Headers will be generated before sending."
2235 (gnus-inews-narrow-to-headers)
2236 (gnus-inews-insert-headers gnus-required-mail-headers)
2237 (gnus-inews-remove-empty-headers)))
2239 ;; Remove the header separator.
2240 (goto-char (point-min))
2241 (and (re-search-forward
2242 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2243 (replace-match "" t t))
2244 ;; Run final inews hooks. This hook may do FCC.
2245 (run-hooks 'gnus-inews-article-hook)
2247 (gnus-narrow-to-headers)
2248 (nnheader-remove-header "^[gf]cc:" t)
2250 (goto-char (point-min))
2251 (search-forward "\n\n")
2253 (insert mail-header-separator)
2255 (run-hooks 'gnus-message-sent-hook))
2257 (defun gnus-inews-modify-mail-mode-map ()
2258 (use-local-map (copy-keymap (current-local-map)))
2259 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
2260 (local-set-key "\C-c\C-p" 'gnus-put-message)
2261 (local-set-key "\C-c\C-d" 'gnus-enter-into-draft-group))
2263 (defun gnus-mail-setup (type &optional to subject in-reply-to cc
2264 replybuffer actions)
2265 ;; Let posting styles be configured.
2266 (gnus-configure-posting-styles)
2270 (and (or (eq type 'reply) (eq type 'followup))
2271 (eq gnus-mail-reply-method 'gnus-mail-reply-using-mhe))
2272 (and (eq type 'forward)
2273 (eq gnus-mail-forward-method 'gnus-mail-forward-using-mhe))
2275 (eq gnus-mail-other-window-method
2276 'gnus-mail-other-window-using-mhe)))
2277 'gnus-mh-mail-setup)
2279 (and (or (eq type 'reply) (eq type 'followup))
2280 (eq gnus-mail-reply-method 'gnus-mail-reply-using-vm))
2281 (and (eq type 'forward)
2282 (eq gnus-mail-forward-method 'gnus-mail-forward-using-vm))
2284 (eq gnus-mail-other-window-method
2285 'gnus-mail-other-window-using-vm)))
2286 'gnus-vm-mail-setup)
2287 (t 'gnus-sendmail-mail-setup))
2288 to subject in-reply-to cc replybuffer actions))
2290 (defun gnus-sendmail-mail-setup (to subject in-reply-to cc replybuffer actions)
2292 (mail-setup to subject nil cc replybuffer actions)
2293 (goto-char (point-min))
2294 (if (re-search-forward
2295 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2297 (goto-char (point-max)))
2299 (gnus-inews-modify-mail-mode-map))
2303 ;; Do Gcc handling, which copied the message over to some group.
2304 (defun gnus-inews-do-gcc (&optional gcc)
2307 (gnus-narrow-to-headers)
2308 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
2311 () ; Nothing to be done.
2312 (nnheader-remove-header "gcc")
2313 ;; Copy the article over to some group(s).
2314 (while (string-match
2315 "^[ \t]*\\([^ \t]+\\)\\([ \t]+\\|$\\)" gcc)
2316 (setq end (match-end 0))
2318 (gnus-request-accept-article
2319 (substring gcc (match-beginning 1) (match-end 1)) t)
2321 (setq gcc (substring gcc end))))))))
2323 (defun gnus-inews-insert-bfcc ()
2324 "Insert Bcc and Fcc headers."
2326 ;; Handle author copy using BCC field.
2327 (when (and gnus-mail-self-blind
2328 (not (mail-fetch-field "bcc")))
2329 (mail-position-on-field "Bcc")
2330 (insert (if (stringp gnus-mail-self-blind)
2331 gnus-mail-self-blind
2332 (user-login-name))))
2333 ;; Handle author copy using FCC field.
2334 (when gnus-author-copy
2335 (mail-position-on-field "Fcc")
2336 (insert gnus-author-copy))))
2338 (defun gnus-inews-insert-gcc ()
2339 (let* ((group gnus-outgoing-message-group)
2341 ((gnus-functionp group)
2343 ((or (stringp group) (list group))
2347 (if (stringp group) group
2348 (mapconcat 'identity group " "))
2351 ;;; Handling rejected (and postponed) news.
2353 (defun gnus-draft-group ()
2354 "Return the name of the draft group."
2355 (gnus-group-prefixed-name
2356 (file-name-nondirectory gnus-draft-group-directory)
2357 (list 'nndir gnus-draft-group-directory)))
2359 (defun gnus-make-draft-group ()
2360 "Make the draft group or die trying."
2361 (let* ((method (` (nndir "private"
2362 (nndir-directory (, gnus-draft-group-directory)))))
2363 (group (gnus-group-prefixed-name
2364 (file-name-nondirectory gnus-draft-group-directory)
2366 (or (gnus-gethash group gnus-newsrc-hashtb)
2367 (gnus-group-make-group (gnus-group-real-name group) method)
2368 (error "Can't create the draft group"))
2371 (defun gnus-enter-into-draft-group ()
2372 "Enter the current buffer into the draft group."
2374 (gnus-put-in-draft-group t))
2376 (defun gnus-put-in-draft-group (&optional generate silent)
2377 "Does the actual putting."
2378 (let ((group (gnus-make-draft-group))
2379 (type (list major-mode (buffer-name) gnus-newsgroup-name
2382 (buf (current-buffer)))
2385 (nnheader-set-temp-buffer " *enter-draft*")
2386 (insert-buffer-substring buf)
2389 (gnus-inews-narrow-to-headers)
2390 (let (gnus-deletable-headers)
2391 (if (eq mode 'mail-mode)
2392 (gnus-inews-insert-headers gnus-required-mail-headers)
2393 (gnus-inews-insert-headers)))
2396 (goto-char (point-min))
2397 ;; We have to store whether we are in a mail group or news group.
2398 (insert (format "X-Gnus-Draft-Type: %S\n" type))
2399 (and (re-search-forward
2400 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2401 (replace-match "" t t))
2403 (gnus-request-accept-article group t)
2404 (kill-buffer (current-buffer)))
2406 (gnus-mail-send-and-exit 'dont-send))))
2407 (set-buffer-modified-p nil)))
2409 (defun gnus-summary-send-draft ()
2410 "Enter a mail/post buffer to edit and send the draft."
2412 (gnus-set-global-variables)
2413 (gnus-summary-select-article t)
2414 ;; First we find the draft type.
2417 (set-buffer gnus-article-buffer)
2419 (gnus-narrow-to-headers)
2420 (setq type (condition-case ()
2421 (read (mail-fetch-field "x-gnus-draft-type"))
2425 (error "Unknown draft type"))
2426 ;; Get to the proper buffer.
2427 (set-buffer (get-buffer-create (nth 1 type)))
2428 ;; It might be modified.
2429 (and (buffer-modified-p)
2430 (or (gnus-yes-or-no-p "Unsent message being composed; discard it? ")
2432 (setq buffer-read-only nil)
2433 (buffer-enable-undo (current-buffer))
2436 (funcall (car type))
2437 (and (eq major-mode 'mail-mode)
2438 (gnus-inews-modify-mail-mode-map))
2439 ;; Arrange for deletion of the draft after successful sending.
2440 (make-local-variable 'gnus-message-sent-hook)
2441 (setq gnus-message-sent-hook
2445 (gnus-request-expire-articles
2446 (quote (, (list (cdr gnus-article-current))))
2447 (, gnus-newsgroup-name) t)))))
2448 ;; Insert the draft.
2449 (insert-buffer-substring gnus-article-buffer)
2450 ;; Insert the separator.
2451 (goto-char (point-min))
2452 (search-forward "\n\n")
2454 (insert mail-header-separator)
2455 ;; Remove the draft header.
2456 (gnus-inews-narrow-to-headers)
2457 (nnheader-remove-header "x-gnus-draft-type")
2459 ;; Configure windows.
2460 (let ((gnus-draft-buffer (current-buffer)))
2461 (gnus-configure-windows 'draft))
2462 ;; Put point where you left it.
2463 (goto-char (nth 3 type))))
2465 (defun gnus-configure-posting-styles ()
2466 "Configure posting styles according to `gnus-posting-styles'."
2467 (let ((styles gnus-posting-styles)
2468 (gnus-newsgroup-name (or gnus-newsgroup-name ""))
2469 style match variable attribute value value-value)
2470 ;; Go through all styles and look for matches.
2472 (setq style (pop styles)
2474 (when (cond ((stringp match)
2475 ;; Regexp string match on the group name.
2476 (string-match match gnus-newsgroup-name))
2477 ((or (symbolp match)
2478 (gnus-functionp match))
2479 (cond ((gnus-functionp match)
2480 ;; Function to be called.
2483 ;; Variable to be checked.
2484 (symbol-value match))))
2486 ;; This is a form to be evaled.
2488 ;; We have a match, so we set the variables.
2490 (setq attribute (pop style)
2491 value (cdr attribute))
2492 ;; We find the variable that is to be modified.
2493 (if (and (not (stringp (car attribute)))
2494 (not (setq variable (cdr (assq (car attribute)
2495 gnus-posting-style-alist)))))
2496 (message "Couldn't find attribute %s" (car attribute))
2497 ;; We set the variable.
2499 (cond ((stringp value)
2501 ((or (symbolp value)
2502 (gnus-functionp value))
2503 (cond ((gnus-functionp value)
2506 (symbol-value value))))
2511 ;; This is an ordinary variable.
2512 (make-local-variable variable)
2513 (set variable value-value))
2514 ;; This is a header to be added to the headers when
2517 (make-local-variable gnus-required-headers)
2518 (make-local-variable gnus-required-mail-headers)
2519 (push (cons (car attribute) value-value)
2520 gnus-required-headers)
2521 (push (cons (car attribute) value-value)
2522 gnus-required-mail-headers)))))))))
2524 ;;; Allow redefinition of functions.
2530 ;;; gnus-msg.el ends here