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-required-headers
181 '(From Date Newsgroups Subject Message-ID Organization Lines X-Newsreader)
182 "*Headers to be generated or prompted for when posting an article.
183 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
184 Message-ID. Organization, Lines, In-Reply-To and X-Newsreader are
185 optional. If you want Gnus not to insert some header, remove it from
188 (defvar gnus-required-mail-headers
189 '(From Date To Subject (optional . In-Reply-To) Message-ID Organization Lines)
190 "*Headers to be generated or prompted for when mailing a message.
191 RFC822 required that From, Date, To, Subject and Message-ID be
192 included. Organization, Lines and X-Mailer are optional.")
194 (defvar gnus-deletable-headers '(Message-ID Date)
195 "*Headers to be deleted if they already exists and were generated by Gnus previously.")
197 (defvar gnus-removable-headers '(NNTP-Posting-Host Bcc Xref)
198 "*Headers to be removed unconditionally before posting.")
200 (defvar gnus-check-before-posting
201 '(subject-cmsg multiple-headers sendsys message-id from
202 long-lines control-chars size new-text
203 signature approved sender)
204 "In non-nil, Gnus will attempt to run some checks on outgoing posts.
205 If this variable is t, Gnus will check everything it can. If it is a
206 list, then those elements in that list will be checked.")
208 (defvar gnus-delete-supersedes-headers
209 "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Supersedes:\\|^Xref:\\|^Lines:"
210 "*Header lines matching this regexp will be deleted before posting.
211 It's best to delete old Path and Date headers before posting to avoid
214 (defvar gnus-auto-mail-to-author nil
215 "*If non-nil, mail the authors of articles a copy of your follow-ups.
216 If this variable is `ask', the user will be prompted for whether to
217 mail a copy. The string given by `gnus-mail-courtesy-message' will be
218 inserted at the beginning of the mail copy.")
220 ;; Added by Ethan Bradford <ethanb@ptolemy.astro.washington.edu>.
221 (defvar gnus-mail-courtesy-message
222 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
223 "*This is inserted at the start of a mailed copy of a posted message.
224 If this variable is nil, no such courtesy message will be added.")
226 (defvar gnus-mail-reply-method (function gnus-mail-reply-using-mail)
227 "*Function to compose a reply.
228 Three pre-made functions are `gnus-mail-reply-using-mail' (sendmail);
229 `gnus-mail-reply-using-mhe' (MH-E); and `gnus-mail-reply-using-vm'.")
231 (defvar gnus-mail-forward-method (function gnus-mail-forward-using-mail)
232 "*Function to forward the current message to another user.
233 Three pre-made functions are `gnus-mail-forward-using-mail' (sendmail);
234 `gnus-mail-forward-using-mhe' (MH-E); and `gnus-mail-forward-using-vm'.")
236 (defvar gnus-mail-other-window-method 'gnus-mail-other-window-using-mail
237 "*Function to compose mail in the other window.
238 Three pre-made functions are `gnus-mail-other-window-using-mail'
239 (sendmail); `gnus-mail-other-window-using-mhe' (MH-E); and
240 `gnus-mail-other-window-using-vm'.")
242 (defvar gnus-inews-article-function 'gnus-inews-article
243 "*Function to post an article.")
245 (defvar gnus-bounced-headers-junk "^\\(Received\\):"
246 "*Regexp that matches headers to be removed in resent bounced mail.")
248 (defvar gnus-inews-article-hook (list 'gnus-inews-do-fcc)
249 "*A hook called before finally posting an article.
250 The default hook (`gnus-inews-do-fcc') does FCC processing (ie. saves
251 the article to a file).")
253 (defvar gnus-inews-article-header-hook nil
254 "*A hook called after inserting the headers in an article to be posted.
255 The hook is called from the *post-news* buffer, narrowed to the
258 (defvar gnus-mail-hook nil
259 "*A hook called as the last thing after setting up a mail buffer.")
261 (defvar gnus-message-sent-hook nil
262 "*A hook run after an article has been sent (or attempted sent).")
264 ;;; Internal variables.
266 (defvar gnus-post-news-buffer "*post-news*")
267 (defvar gnus-mail-buffer "*mail*")
268 (defvar gnus-summary-send-map nil)
269 (defvar gnus-article-copy nil)
270 (defvar gnus-reply-subject nil)
271 (defvar gnus-add-to-address nil)
272 (defvar gnus-in-reply-to nil)
275 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
276 (autoload 'news-setup "rnewspost")
277 (autoload 'news-reply-mode "rnewspost")
278 (autoload 'rmail-output "rmailout"))
282 ;;; Gnus Posting Functions
285 (define-prefix-command 'gnus-summary-send-map)
286 (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
287 (define-key gnus-summary-send-map "p" 'gnus-summary-post-news)
288 (define-key gnus-summary-send-map "f" 'gnus-summary-followup)
289 (define-key gnus-summary-send-map "F" 'gnus-summary-followup-with-original)
290 (define-key gnus-summary-send-map "b" 'gnus-summary-followup-and-reply)
291 (define-key gnus-summary-send-map "B" 'gnus-summary-followup-and-reply-with-original)
292 (define-key gnus-summary-send-map "c" 'gnus-summary-cancel-article)
293 (define-key gnus-summary-send-map "s" 'gnus-summary-supersede-article)
294 (define-key gnus-summary-send-map "r" 'gnus-summary-reply)
295 (define-key gnus-summary-send-map "R" 'gnus-summary-reply-with-original)
296 (define-key gnus-summary-send-map "m" 'gnus-summary-mail-other-window)
297 (define-key gnus-summary-send-map "Db" 'gnus-summary-resend-bounced-mail)
298 (define-key gnus-summary-send-map "Dc" 'gnus-summary-send-draft)
299 (define-key gnus-summary-send-map "u" 'gnus-uu-post-news)
300 (define-key gnus-summary-send-map "om" 'gnus-summary-mail-forward)
301 (define-key gnus-summary-send-map "op" 'gnus-summary-post-forward)
302 (define-key gnus-summary-send-map "Om" 'gnus-uu-digest-mail-forward)
303 (define-key gnus-summary-send-map "Op" 'gnus-uu-digest-post-forward)
305 ;;; Internal functions.
307 (defun gnus-number-base36 (num len)
308 (if (if (< len 0) (<= num 0) (= len 0))
310 (concat (gnus-number-base36 (/ num 36) (1- len))
311 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
314 ;;; Post news commands of Gnus group mode and summary mode
316 (defun gnus-group-mail ()
317 "Start composing a mail."
320 ;; We might want to prompt here.
321 (when (and gnus-interactive-post
322 (not gnus-expert-user))
323 (read-string "To: "))))
325 (defun gnus-group-post-news (&optional arg)
327 The newsgroup under the cursor is used as the group to post to.
329 If you wish to get an empty post buffer, use a prefix ARG. You can
330 also do this by calling this function from the bottom of the Group
333 (let ((gnus-newsgroup-name nil)
334 (group (unless arg (gnus-group-group-name)))
336 ;; We might want to prompt here.
337 (when (and gnus-interactive-post
338 (not gnus-expert-user))
339 (setq gnus-newsgroup-name
341 (completing-read "Group: " gnus-active-hashtb nil nil
343 (gnus-post-news 'post group nil gnus-article-buffer)))
345 (defun gnus-summary-post-news ()
348 (gnus-set-global-variables)
349 (gnus-post-news 'post gnus-newsgroup-name))
351 (defun gnus-summary-followup (yank &optional yank-articles)
352 "Compose a followup to an article.
353 If prefix argument YANK is non-nil, original article is yanked automatically."
355 (gnus-set-global-variables)
356 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
357 (save-window-excursion
358 (gnus-summary-select-article))
359 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
360 (gnus-newsgroup-name gnus-newsgroup-name))
361 ;; Check Followup-To: poster.
362 (set-buffer gnus-article-buffer)
363 (if (and gnus-use-followup-to
364 (string-equal "poster" (gnus-fetch-field "followup-to"))
365 (or (not (memq gnus-use-followup-to '(t ask)))
367 "Do you want to ignore `Followup-To: poster'? "))))
368 ;; Mail to the poster.
369 (gnus-summary-reply yank)
371 (gnus-post-news nil gnus-newsgroup-name
372 headers gnus-article-buffer
373 (or yank-articles (not (not yank)))))))
375 (defun gnus-summary-followup-with-original (n)
376 "Compose a followup to an article and include the original article."
378 (gnus-summary-followup t (gnus-summary-work-articles n)))
380 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
381 (defun gnus-summary-followup-and-reply (yank &optional yank-articles)
382 "Compose a followup and do an auto mail to author."
384 (gnus-set-global-variables)
385 (let ((gnus-auto-mail-to-author 'force))
386 (gnus-summary-followup yank yank-articles)))
388 (defun gnus-summary-followup-and-reply-with-original (n)
389 "Compose a followup, include the original, and do an auto mail to author."
391 (gnus-summary-followup-and-reply t (gnus-summary-work-articles n)))
393 (defun gnus-summary-cancel-article (n)
394 "Cancel an article you posted."
396 (gnus-set-global-variables)
397 (let ((articles (gnus-summary-work-articles n)))
399 (gnus-summary-select-article t nil nil (car articles))
400 (and (gnus-eval-in-buffer-window gnus-article-buffer (gnus-cancel-news))
401 (gnus-summary-mark-as-read (car articles) gnus-canceled-mark))
402 (gnus-summary-remove-process-mark (car articles))
403 (gnus-article-hide-headers-if-wanted)
404 (setq articles (cdr articles)))))
406 (defun gnus-summary-supersede-article ()
407 "Compose an article that will supersede a previous article.
408 This is done simply by taking the old article and adding a Supersedes
409 header line with the old Message-ID."
411 (gnus-set-global-variables)
412 (gnus-summary-select-article t)
413 ;; Check whether the user owns the article that is to be superseded.
414 (unless (string-equal
415 (downcase (mail-strip-quoted-names
416 (mail-header-from gnus-current-headers)))
417 (downcase (mail-strip-quoted-names (gnus-inews-user-name))))
418 (error "This article is not yours."))
419 ;; Get a normal *post-news* buffer.
420 (gnus-new-news gnus-newsgroup-name t)
422 (insert-buffer-substring gnus-original-article-buffer)
423 (gnus-narrow-to-headers)
424 ;; Remove unwanted headers.
425 (when gnus-delete-supersedes-headers
426 (nnheader-remove-header gnus-delete-supersedes-headers t))
427 (goto-char (point-min))
428 (if (not (re-search-forward "^Message-ID: " nil t))
429 (error "No Message-ID in this article")
430 (replace-match "Supersedes: " t t))
431 (goto-char (point-max))
432 (insert mail-header-separator)
438 (defalias 'sendnews 'gnus-post-news)
441 (defalias 'postnews 'gnus-post-news)
443 (defun gnus-copy-article-buffer (&optional article-buffer)
444 ;; make a copy of the article buffer with all text properties removed
445 ;; this copy is in the buffer gnus-article-copy.
446 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
447 ;; this buffer should be passed to all mail/news reply/post routines.
448 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
449 (buffer-disable-undo gnus-article-copy)
450 (or (memq gnus-article-copy gnus-buffer-list)
451 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
452 (let ((article-buffer (or article-buffer gnus-article-buffer)))
453 (if (and (get-buffer article-buffer)
454 (buffer-name (get-buffer article-buffer)))
456 (set-buffer article-buffer)
458 (copy-to-buffer gnus-article-copy (point-min) (point-max))
459 (set-text-properties (point-min) (point-max)
460 nil gnus-article-copy)))))
462 (defun gnus-post-news (post &optional group header article-buffer yank subject)
463 "Begin editing a new USENET news article to be posted.
464 Type \\[describe-mode] in the buffer to get a list of commands."
465 (interactive (list t))
466 (let* ((group (or group gnus-newsgroup-name))
470 (gnus-group-get-parameter group 'to-address)))
473 (gnus-group-get-parameter group 'to-group)))
475 (and group gnus-mailing-list-groups
476 (string-match gnus-mailing-list-groups group))))
478 (setq group (gnus-group-real-name group)))
480 (and (gnus-member-of-valid 'post (or pgroup gnus-newsgroup-name))
485 (gnus-new-news (or to-group group))
486 (gnus-news-followup yank (or to-group group)))
490 (gnus-new-mail to-address)
491 ;; Arrange for mail groups that have no `to-address' to
492 ;; get that when the user sends off the mail.
495 (make-local-variable 'gnus-add-to-address)
496 (setq gnus-add-to-address group))))
497 (gnus-mail-reply yank to-address 'followup)))))
499 (defun gnus-inews-news (&optional use-group-method)
500 "Send a news message.
501 If given a prefix, and the group is a foreign group, this function
502 will attempt to use the foreign server to post the article."
504 (or gnus-current-select-method
505 (setq gnus-current-select-method gnus-select-method))
506 (let* ((case-fold-search nil)
507 (reply gnus-article-reply)
510 (gnus-start-news-server) ;Use default server.
512 (goto-char (point-min))
513 (run-hooks 'news-inews-hook)
516 (gnus-message 5 "Posting to USENET...")
517 (setq post-result (funcall gnus-inews-article-function use-group-method))
518 (cond ((eq post-result 'illegal)
522 (gnus-message 5 "Posting to USENET...done")
523 (if (gnus-buffer-exists-p (car-safe reply))
526 (set-buffer gnus-summary-buffer)
527 (gnus-summary-mark-article-as-replied
529 (set-buffer-modified-p nil))
531 ;; We cannot signal an error.
535 1 "Article rejected: %s"
537 (gnus-post-method gnus-newsgroup-name use-group-method))))))
539 (let ((conf gnus-prev-winconf))
542 ;; Restore last window configuration.
543 (and conf (set-window-configuration conf))))))
545 (defun gnus-inews-narrow-to-headers ()
548 (goto-char (point-min))
549 (or (and (re-search-forward
550 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
554 (defun gnus-inews-send-mail-copy ()
555 ;; Mail the message if To, Bcc or Cc exists.
556 (let* ((types '("to" "bcc" "cc"))
558 (buffer (current-buffer))
562 (gnus-inews-narrow-to-headers)
565 (or (mail-fetch-field (car ty) nil t)
566 (setq types (delete (car ty) types)))
570 ;; We do not want to send mail.
572 (gnus-message 5 "Sending via mail...")
575 ;; We copy the article over to a temp buffer since we are
576 ;; going to modify it a little.
577 (nnheader-set-temp-buffer " *Gnus-mailing*")
578 (insert-buffer-substring buffer)
579 ;; We remove Fcc, because we don't want the mailer to see
581 (gnus-inews-narrow-to-headers)
582 (nnheader-remove-header "fcc")
584 ;; Insert the X-Courtesy-Message header.
585 (and (or (member "to" types)
588 (goto-char (point-max))
589 (insert "Posted-To: "
590 (mail-fetch-field "newsgroups") "\n")))
594 (if (and gnus-mail-courtesy-message
595 (or (member "to" types)
596 (member "cc" types)))
597 ;; We only want to insert the courtesy mail message if
598 ;; we use To or Cc; Bcc should not have one. Well, if
599 ;; both Bcc and To are present, it will get one
602 ;; Insert "courtesy" mail message.
603 (goto-char (point-min))
605 (concat "^" (regexp-quote mail-header-separator) "$"))
607 (insert gnus-mail-courtesy-message)))
610 (kill-buffer (current-buffer))
611 (gnus-message 5 "Sending via mail...done"))))))
613 (defun gnus-inews-remove-headers-after-mail ()
616 (let ((case-fold-search t))
617 (gnus-inews-narrow-to-headers)
618 ;; Remove Bcc completely.
619 (nnheader-remove-header "bcc")
620 ;; We transform To and Cc headers to avoid re-mailing if the user
621 ;; accidentally (or purposefully) leans on the `C-c C-c' keys
622 ;; and the news server rejects the posting.
623 (while (re-search-forward "^\\(to\\|[bcf]cc\\|cc\\):" nil t)
628 (defun gnus-inews-dex-headers ()
629 "Remove \"X-\" prefixes from To and Cc headers."
632 (let ((case-fold-search t))
633 (gnus-narrow-to-headers)
634 (while (re-search-forward "^X-\\(to\\|[bcf]cc\\|cc\\):" nil t)
639 (defun gnus-inews-remove-empty-headers ()
640 "Remove empty headers from news and mail.
641 The buffer should be narrowed to the headers before this function is
644 (goto-char (point-min))
645 (while (re-search-forward "^[^ \t:]+:\\([ \t]*\n\\)+[^ \t]" nil t)
646 (delete-region (match-beginning 0) (1- (match-end 0)))
647 (beginning-of-line))))
649 (defun gnus-inews-check-post ()
650 "Check whether the post looks ok."
652 (not gnus-check-before-posting)
654 ;; We narrow to the headers and check them first.
657 (goto-char (point-min))
662 (concat "^" (regexp-quote mail-header-separator) "$"))
663 (match-beginning 0)))
664 (goto-char (point-min))
666 ;; Check for commands in Subject.
668 (gnus-check-before-posting 'subject-cmsg)
670 (if (string-match "^cmsg " (mail-fetch-field "subject"))
672 "The control code \"cmsg \" is in the subject. Really post? ")
674 ;; Check for multiple identical headers.
675 (or (gnus-check-before-posting 'multiple-headers)
678 (while (and (not found) (re-search-forward "^[^ \t:]+: "
681 (or (re-search-forward
682 (concat "^" (setq found
685 (- (match-end 0) 2))))
690 (format "Multiple %s headers. Really post? " found))
692 ;; Check for Version and Sendsys.
693 (or (gnus-check-before-posting 'sendsys)
695 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
697 (format "The article contains a %s command. Really post? "
698 (buffer-substring (match-beginning 0)
699 (1- (match-end 0)))))
701 ;; Check for Approved.
702 (or (gnus-check-before-posting 'approved)
704 (if (re-search-forward "^Approved:" nil t)
706 "The article contains an Approved header. Really post? ")
708 ;; Check the Message-ID header.
709 (or (gnus-check-before-posting 'message-id)
711 (let* ((case-fold-search t)
712 (message-id (mail-fetch-field "message-id")))
714 (and (string-match "@" message-id)
715 (string-match "@[^\\.]*\\." message-id))
718 "The Message-ID looks strange: \"%s\". Really post? "
720 ;; Check the From header.
721 (or (gnus-check-before-posting 'from)
723 (let* ((case-fold-search t)
724 (from (mail-fetch-field "from")))
727 (gnus-y-or-n-p "There is no From line. Really post? "))
728 ((not (string-match "@[^\\.]*\\." from))
731 "The address looks strange: \"%s\". Really post? " from)))
732 ((string-match "(.*).*(.*)" from)
735 "The From header looks strange: \"%s\". Really post? "
737 ((string-match "<[^>]+> *$" from)
738 (let ((name (substring from 0 (match-beginning 0))))
740 (string-match "^ *\"[^\"]*\" *$" name)
741 (not (string-match "[][.!()<>@,;:\\]" name))
744 "The From header name has bogus characters. Really post? "
748 ;; Check for long lines.
749 (or (gnus-check-before-posting 'long-lines)
751 (goto-char (point-min))
753 (concat "^" (regexp-quote mail-header-separator) "$"))
757 (< (current-column) 80))
758 (zerop (forward-line 1))))
763 "You have lines longer than 79 characters. Really post? ")))))
764 ;; Check for control characters.
765 (or (gnus-check-before-posting 'control-chars)
767 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
769 "The article contains control characters. Really post? ")
771 ;; Check excessive size.
772 (or (gnus-check-before-posting 'size)
773 (if (> (buffer-size) 60000)
775 (format "The article is %d octets long. Really post? "
778 ;; Use the (size . checksum) variable to see whether the
779 ;; article is empty or has only quoted text.
781 (gnus-check-before-posting 'new-text)
782 (if (and (= (buffer-size) (car gnus-article-check-size))
783 (= (gnus-article-checksum) (cdr gnus-article-check-size)))
785 "It looks like there's no new text in your article. Really post? ")
787 ;; Check the length of the signature.
788 (or (gnus-check-before-posting 'signature)
790 (goto-char (point-max))
791 (if (not (re-search-backward gnus-signature-separator nil t))
793 (if (> (count-lines (point) (point-max)) 5)
796 "Your .sig is %d lines; it should be max 4. Really post? "
797 (count-lines (point) (point-max))))
800 (defun gnus-article-checksum ()
804 (setq sum (logxor sum (following-char)))
808 ;; Returns non-nil if this type is not to be checked.
809 (defun gnus-check-before-posting (type)
811 (or (not gnus-check-before-posting)
812 (if (listp gnus-check-before-posting)
813 (memq type gnus-check-before-posting)
816 (defun gnus-cancel-news ()
817 "Cancel an article you posted."
819 (if (or gnus-expert-user
820 (gnus-yes-or-no-p "Do you really want to cancel this article? "))
825 (or (gnus-member-of-valid 'post gnus-newsgroup-name)
826 (error "This backend does not support canceling"))
828 ;; Get header info. from original article.
830 (gnus-article-show-all-headers)
831 (goto-char (point-min))
832 (search-forward "\n\n" nil 'move)
833 (narrow-to-region (point-min) (point))
834 (setq from (mail-fetch-field "from"))
835 (setq newsgroups (mail-fetch-field "newsgroups"))
836 (setq message-id (mail-fetch-field "message-id"))
837 (setq distribution (mail-fetch-field "distribution")))
838 ;; Verify if the article is absolutely user's by comparing
839 ;; user id with value of its From: field.
842 (downcase (mail-strip-quoted-names from))
843 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
845 (ding) (gnus-message 3 "This article is not yours.")
847 ;; Make control article.
848 (set-buffer (get-buffer-create " *Gnus-canceling*"))
849 (buffer-disable-undo (current-buffer))
851 (insert "Newsgroups: " newsgroups "\n"
852 "From: " (gnus-inews-real-user-address) "\n"
853 "Subject: cancel " message-id "\n"
854 "Control: cancel " message-id "\n"
856 (concat "Distribution: " distribution "\n")
858 mail-header-separator "\n"
859 "This is a cancel message from " from ".\n")
860 ;; Send the control article to NNTP server.
861 (gnus-message 5 "Canceling your article...")
863 (if (funcall gnus-inews-article-function)
864 (gnus-message 5 "Canceling your article...done")
867 (gnus-message 1 "Cancel failed; %s"
868 (gnus-status-message gnus-newsgroup-name))
871 ;; Kill the article buffer.
872 (kill-buffer (current-buffer))))))))
875 ;;; Lowlevel inews interface.
877 ;; Dummy to avoid byte-compile warning.
878 (defvar nnspool-rejected-article-hook)
880 (defun gnus-inews-article (&optional use-group-method)
881 "Post an article in current buffer using NNTP protocol."
882 (let ((artbuf (current-buffer))
885 (goto-char (point-max))
886 ;; Require a newline at the end of the buffer since inews may
887 ;; append a .signature.
888 (or (= (preceding-char) ?\n)
890 ;; Prepare article headers. All message body such as signature
891 ;; must be inserted before Lines: field is prepared.
893 (gnus-inews-narrow-to-headers)
895 (gnus-inews-cleanup-headers)
896 ;; Remove some headers.
897 (gnus-inews-remove-headers)
898 ;; Insert some headers.
899 (gnus-inews-insert-headers)
900 ;; Let the user do all of the above.
901 (run-hooks 'gnus-inews-article-header-hook)
902 ;; Copy the Gcc header, if any.
903 (setq gcc (mail-fetch-field "gcc"))
905 ;; Check whether the article is a good Net Citizen.
906 (if (and gnus-article-check-size
907 (not (gnus-inews-check-post)))
910 ;; We fudge a hook for nnspool.
911 (setq nnspool-rejected-article-hook
917 (set-buffer (, (buffer-name)))
918 (gnus-put-in-draft-group nil 'silent))
922 1 "Couldn't enter rejected article into draft group")))))))
924 ;; Looks ok, so we do the nasty.
926 ;; This hook may insert a signature.
928 (goto-char (point-min))
929 (let ((gnus-newsgroup-name (or (mail-fetch-field "newsgroups")
930 gnus-newsgroup-name)))
931 (run-hooks 'gnus-prepare-article-hook)))
932 ;; Send off copies using mail, if that is wanted.
933 (gnus-inews-send-mail-copy)
934 ;; Remove more headers.
935 (gnus-inews-remove-headers-after-mail)
936 ;; Copy the article over to a temp buffer.
937 (nnheader-set-temp-buffer " *Gnus-posting*")
938 (insert-buffer-substring artbuf)
939 ;; Remove the header separator.
940 (goto-char (point-min))
942 (concat "^" (regexp-quote mail-header-separator) "$"))
943 (replace-match "" t t)
944 ;; Run final inews hooks. This hook may do FCC.
945 ;; The article must be saved before being posted because
946 ;; `gnus-request-post' modifies the buffer.
947 (run-hooks 'gnus-inews-article-hook)
948 ;; Remove X- prefixes to headers.
949 (gnus-inews-dex-headers)
950 ;; Copy the article over to some group, possibly.
951 (and gcc (gnus-inews-do-gcc gcc))
953 (let ((method (gnus-post-method gnus-newsgroup-name use-group-method)))
954 (setq result (gnus-request-post method)))
955 (kill-buffer (current-buffer)))
956 (run-hooks 'gnus-message-sent-hook)
957 ;; If the posting was unsuccessful (that it, it was rejected) we
958 ;; put it into the draft group.
959 (or result (gnus-put-in-draft-group))
962 (defun gnus-inews-cleanup-headers ()
963 ;; Correct newsgroups field: change sequence of spaces to comma and
964 ;; eliminate spaces around commas. Eliminate imbedded line breaks.
965 (goto-char (point-min))
966 (if (re-search-forward "^Newsgroups: +" nil t)
970 (if (re-search-forward "^[^ \t]" nil t)
974 (goto-char (point-min))
975 (while (re-search-forward "\n[ \t]+" nil t)
976 (replace-match " " t t)) ;No line breaks (too confusing)
977 (goto-char (point-min))
978 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
979 (replace-match "," t t))
980 (goto-char (point-min))
981 ;; Remove a trailing comma.
982 (if (re-search-forward ",$" nil t)
983 (replace-match "" t t))))
985 ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
986 ;; Help save the the world!
989 (let ((newsgroups (mail-fetch-field "newsgroups"))
990 (followup-to (mail-fetch-field "followup-to"))
993 (string-match "," newsgroups) (not followup-to))
995 (while (string-match "," newsgroups)
997 (cons (list (substring newsgroups 0 (match-beginning 0)))
999 (setq newsgroups (substring newsgroups (match-end 0))))
1000 (setq groups (nreverse (cons (list newsgroups) groups)))
1002 (setq to (completing-read
1003 "Followups to: (default all groups) " groups))
1004 (if (> (length to) 0)
1006 (goto-char (point-min))
1007 (insert "Followup-To: " to "\n")))))))
1009 ;; Cleanup Followup-To.
1010 (goto-char (point-min))
1011 (if (search-forward-regexp "^Followup-To: +" nil t)
1015 (if (re-search-forward "^[^ \t]" nil 'end)
1018 (goto-char (point-min))
1019 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
1020 (goto-char (point-min))
1021 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ","))))
1024 (defun gnus-inews-remove-headers ()
1025 (let ((case-fold-search t)
1026 (headers gnus-removable-headers))
1027 ;; Remove toxic headers.
1029 (goto-char (point-min))
1030 (and (re-search-forward
1031 (concat "^" (downcase (format "%s" (car headers))))
1033 (delete-region (progn (beginning-of-line) (point))
1034 (progn (forward-line 1) (point))))
1035 (setq headers (cdr headers)))))
1037 (defun gnus-inews-insert-headers (&optional headers)
1038 "Prepare article headers.
1039 Headers already prepared in the buffer are not modified.
1040 Headers in `gnus-required-headers' will be generated."
1041 (let ((Date (gnus-inews-date))
1042 (Message-ID (gnus-inews-message-id))
1043 (Organization (gnus-inews-organization))
1044 (From (gnus-inews-user-name))
1045 (Path (gnus-inews-path))
1048 (In-Reply-To (gnus-inews-in-reply-to))
1051 (Lines (gnus-inews-lines))
1052 (X-Newsreader gnus-version)
1053 (X-Mailer gnus-version)
1054 (headers (or headers gnus-required-headers))
1055 (case-fold-search t)
1057 ;; First we remove any old generated headers.
1058 (let ((headers gnus-deletable-headers))
1060 (goto-char (point-min))
1061 (and (re-search-forward
1062 (concat "^" (symbol-name (car headers)) ": *") nil t)
1063 (get-text-property (1+ (match-beginning 0)) 'gnus-deletable)
1065 (setq headers (cdr headers))))
1066 ;; If there are References, and no "Re: ", then the thread has
1067 ;; changed name. See Son-of-1036.
1068 (if (and (mail-fetch-field "references")
1069 (get-buffer gnus-article-buffer))
1070 (let ((psubject (gnus-simplify-subject-re
1071 (mail-fetch-field "subject"))))
1072 (or (and psubject gnus-reply-subject
1073 (string= (gnus-simplify-subject-re gnus-reply-subject)
1076 (string-match "@" Message-ID)
1078 (concat (substring Message-ID 0 (match-beginning 0))
1080 (substring Message-ID (match-beginning 0))))))))
1081 ;; Go through all the required headers and see if they are in the
1082 ;; articles already. If they are not, or are empty, they are
1083 ;; inserted automatically - except for Subject, Newsgroups and
1086 (goto-char (point-min))
1087 (setq elem (pop headers))
1089 (setq header (car elem))
1091 (when (or (not (re-search-forward
1092 (concat "^" (downcase (symbol-name header)) ":") nil t))
1094 ;; The header was found. We insert a space after the
1095 ;; colon, if there is none.
1096 (if (/= (following-char) ? ) (insert " "))
1097 ;; Find out whether the header is empty...
1098 (looking-at "[ \t]*$")))
1099 ;; So we find out what value we should insert.
1102 ((and (consp elem) (eq (car elem) 'optional))
1103 ;; This is an optional header. If the cdr of this
1104 ;; is something that is nil, then we do not insert
1106 (setq header (cdr elem))
1107 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
1108 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
1110 ;; The element is a cons. Either the cdr is a
1111 ;; string to be inserted verbatim, or it is a
1112 ;; function, and we insert the value returned from
1114 (or (and (stringp (cdr elem)) (cdr elem))
1115 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
1116 ((and (boundp header) (symbol-value header))
1117 ;; The element is a symbol. We insert the value
1118 ;; of this symbol, if any.
1119 (symbol-value header))
1121 ;; We couldn't generate a value for this header,
1122 ;; so we just ask the user.
1123 (read-from-minibuffer
1124 (format "Empty header for %s; enter value: " header)))))
1125 ;; Finally insert the header.
1127 (not (equal value "")))
1131 ;; This header didn't exist, so we insert it.
1132 (goto-char (point-max))
1133 (insert (symbol-name header) ": " value "\n")
1135 ;; The value of this header was empty, so we clear
1136 ;; totally and insert the new value.
1137 (delete-region (point) (gnus-point-at-bol))
1139 ;; Add the deletable property to the headers that require it.
1140 (and (memq header gnus-deletable-headers)
1141 (progn (beginning-of-line) (looking-at "[^:]+: "))
1142 (add-text-properties
1143 (point) (match-end 0)
1144 '(gnus-deletable t face italic) (current-buffer)))))))
1145 ;; Insert new Sender if the From is strange.
1146 (let ((from (mail-fetch-field "from"))
1147 (sender (mail-fetch-field "sender")))
1149 (not (gnus-check-before-posting 'sender))
1151 (downcase (car (gnus-extract-address-components from)))
1152 (downcase (gnus-inews-real-user-address))))
1156 (downcase (car (gnus-extract-address-components sender)))
1157 (downcase (gnus-inews-real-user-address))))))
1159 (goto-char (point-min))
1160 (and (re-search-forward "^Sender:" nil t)
1163 (insert "Original-")
1164 (beginning-of-line)))
1165 (insert "Sender: " (gnus-inews-real-user-address) "\n"))))))
1168 (defun gnus-inews-insert-signature ()
1169 "Insert a signature file.
1170 If `gnus-signature-function' is bound and returns a string, this
1171 string is used instead of the variable `gnus-signature-file'.
1172 In either case, if the string is a file name, this file is
1173 inserted. If the string is not a file name, the string itself is
1176 If you never want any signature inserted, set both of these variables to
1180 (or (and gnus-signature-function
1181 (funcall gnus-signature-function gnus-newsgroup-name))
1182 gnus-signature-file)))
1184 (or (file-exists-p signature)
1185 (string-match " " signature)
1187 "^/[^/]+/" (expand-file-name signature)))))
1189 (goto-char (point-max))
1190 (if (and mail-signature (search-backward "\n-- \n" nil t))
1192 ;; Delete any previous signatures.
1193 (if (search-backward "\n-- \n" nil t)
1194 (delete-region (point) (point-max)))
1195 (or (eolp) (insert "\n"))
1197 (if (file-exists-p signature)
1198 (insert-file-contents signature)
1200 (goto-char (point-max))
1201 (or (bolp) (insert "\n"))))))))
1203 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1204 (defun gnus-inews-insert-mime-headers ()
1205 (goto-char (point-min))
1206 (let ((mail-header-separator
1208 (goto-char (point-min))
1209 (if (and (search-forward (concat "\n" mail-header-separator "\n")
1211 (not (search-backward "\n\n" nil t)))
1212 mail-header-separator
1214 (or (mail-position-on-field "Mime-Version")
1217 (goto-char (point-min))
1218 (re-search-forward "[\200-\377]" nil t))
1219 (or (mail-position-on-field "Content-Type")
1220 (insert "text/plain; charset=ISO-8859-1"))
1221 (or (mail-position-on-field "Content-Transfer-Encoding")
1223 (t (or (mail-position-on-field "Content-Type")
1224 (insert "text/plain; charset=US-ASCII"))
1225 (or (mail-position-on-field "Content-Transfer-Encoding")
1226 (insert "7bit")))))))
1228 (defun gnus-inews-do-fcc ()
1229 "Process Fcc headers in the current buffer.
1230 Unless the first character of the field is `|', the article is saved
1231 to the specified file using the function specified by the variable
1232 gnus-author-copy-saver. The default function rmail-output saves in
1233 Unix mailbox format.
1235 If the first character is `|', the contents of the article is sent to
1236 a program specified by the rest of the value."
1237 (let ((case-fold-search t) ;Should ignore case.
1241 (gnus-narrow-to-headers)
1242 (while (setq file (mail-fetch-field "fcc"))
1244 (nnheader-remove-header "fcc" nil t))
1245 ;; Process FCC operations.
1248 (setq file (pop list))
1249 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
1250 ;; Pipe the article to the program in question.
1251 (call-process-region (point-min) (point-max) shell-file-name
1252 nil nil nil "-c" (match-string 1 file))
1253 ;; Save the article.
1254 (setq file (expand-file-name file))
1255 (gnus-make-directory (file-name-directory file))
1256 (if (and gnus-author-copy-saver
1257 (not (eq gnus-author-copy-saver 'rmail-output)))
1258 (funcall gnus-author-copy-saver file)
1259 (if (and (file-readable-p file) (mail-file-babyl-p file))
1260 (gnus-output-to-rmail file)
1261 (rmail-output file 1 t t)))))))))
1263 (defun gnus-inews-path ()
1265 (let ((login-name (gnus-inews-login-name)))
1266 (cond ((null gnus-use-generic-path)
1267 (concat (nth 1 gnus-select-method) "!" login-name))
1268 ((stringp gnus-use-generic-path)
1269 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1270 (concat gnus-use-generic-path "!" login-name))
1273 (defun gnus-inews-user-name ()
1274 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1275 (let ((full-name (gnus-inews-full-name))
1276 (address (if (or gnus-user-login-name gnus-use-generic-from
1277 gnus-local-domain (getenv "DOMAINNAME"))
1278 (concat (gnus-inews-login-name) "@"
1279 (gnus-inews-domain-name gnus-use-generic-from))
1280 user-mail-address)))
1281 (or gnus-user-from-line
1283 ;; User's full name.
1284 (cond ((string-equal full-name "&") ;Unix hack.
1285 (concat " (" (user-login-name) ")"))
1286 ((string-match "[^ ]+@[^ ]+ +(.*)" address)
1289 (concat " (" full-name ")")))))))
1291 (defun gnus-inews-real-user-address ()
1292 "Return the \"real\" user address.
1293 This function tries to ignore all user modifications, and
1294 give as trustworthy answer as possible."
1295 (concat (user-login-name) "@" (gnus-inews-full-address)))
1297 (defun gnus-inews-login-name ()
1298 "Return login name."
1299 (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1301 (defun gnus-inews-full-name ()
1302 "Return full user name."
1303 (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1305 (defun gnus-inews-domain-name (&optional genericfrom)
1306 "Return user's domain name.
1307 If optional argument GENERICFROM is a string, use it as the domain
1308 name; if it is non-nil, strip off local host name from the domain name.
1309 If the function `system-name' returns full internet name and the
1310 domain is undefined, the domain name is got from it."
1311 (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1312 (let* ((system-name (system-name))
1314 (or (if (stringp genericfrom) genericfrom)
1315 (getenv "DOMAINNAME")
1317 ;; Function `system-name' may return full internet name.
1318 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1319 (if (string-match "\\.." system-name)
1320 ;; Some machines return "name.", and that's not
1322 (substring system-name (1- (match-end 0))))
1323 (read-string "Domain name (no host): ")))
1324 (host (or (if (string-match "\\." system-name)
1325 (substring system-name 0 (match-beginning 0)))
1327 (if (string-equal "." (substring domain 0 1))
1328 (setq domain (substring domain 1)))
1329 ;; Support GENERICFROM as same as standard Bnews system.
1330 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1331 (cond ((null genericfrom)
1332 (concat host "." domain))
1333 ;;((stringp genericfrom) genericfrom)
1335 (if (string-match "\\." (system-name))
1337 (substring user-mail-address
1338 (1+ (string-match "@" user-mail-address))))))
1340 (defun gnus-inews-full-address ()
1341 (let ((domain (gnus-inews-domain-name))
1342 (system (system-name))
1343 (case-fold-search t))
1344 (if (string-match "\\." system) system
1345 (if (string-match (concat "^" (regexp-quote system)) domain) domain
1346 (concat system "." domain)))))
1348 (defun gnus-inews-message-id ()
1349 "Generate unique Message-ID for user."
1350 ;; Message-ID should not contain a slash and should be terminated by
1351 ;; a number. I don't know the reason why it is so.
1352 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1354 (defvar gnus-unique-id-char nil)
1356 ;; If you ever change this function, make sure the new version
1357 ;; cannot generate IDs that the old version could.
1358 ;; You might for example insert a "." somewhere (not next to another dot
1359 ;; or string boundary), or modify the newsreader name to "Ding".
1360 (defun gnus-inews-unique-id ()
1361 ;; Dont use microseconds from (current-time), they may be unsupported.
1362 ;; Instead we use this randomly inited counter.
1363 (setq gnus-unique-id-char
1364 (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1365 ;; (current-time) returns 16-bit ints,
1366 ;; and 2^16*25 just fits into 4 digits i base 36.
1368 (let ((tm (if (fboundp 'current-time)
1369 (current-time) '(12191 46742 287898))))
1371 (if (memq system-type '(ms-dos emx vax-vms))
1372 (let ((user (downcase (gnus-inews-login-name))))
1373 (while (string-match "[^a-z0-9_]" user)
1374 (aset user (match-beginning 0) ?_))
1376 (gnus-number-base36 (user-uid) -1))
1377 (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1378 (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1379 ;; Append the newsreader name, because while the generated
1380 ;; ID is unique to this newsreader, other newsreaders might
1381 ;; otherwise generate the same ID via another algorithm.
1385 (defun gnus-inews-date ()
1386 "Current time string."
1387 (timezone-make-date-arpa-standard
1388 (current-time-string) (current-time-zone)))
1390 (defun gnus-inews-organization ()
1391 "Return user's organization.
1392 The ORGANIZATION environment variable is used if defined.
1393 If not, the variable `gnus-local-organization' is used instead.
1394 If it is a function, the function will be called with the current
1395 newsgroup name as the argument.
1396 If this is a file name, the contents of this file will be used as the
1398 (let* ((organization
1399 (or (getenv "ORGANIZATION")
1400 (if gnus-local-organization
1401 (if (and (symbolp gnus-local-organization)
1402 (fboundp gnus-local-organization))
1403 (funcall gnus-local-organization gnus-newsgroup-name)
1404 gnus-local-organization))
1405 gnus-organization-file
1406 "~/.organization")))
1407 (and (stringp organization)
1408 (> (length organization) 0)
1409 (or (file-exists-p organization)
1410 (string-match " " organization)
1411 (not (string-match "^/usr/lib/\\|^~/" organization)))
1413 (gnus-set-work-buffer)
1414 (if (file-exists-p organization)
1415 (insert-file-contents organization)
1416 (insert organization))
1417 (goto-char (point-min))
1418 (while (re-search-forward " *\n *" nil t)
1419 (replace-match " " t t))
1420 (buffer-substring (point-min) (point-max))))))
1422 (defun gnus-inews-lines ()
1423 "Count the number of lines and return numeric string."
1427 (goto-char (point-min))
1429 (concat "^" (regexp-quote mail-header-separator) "$"))
1431 (int-to-string (count-lines (point) (point-max))))))
1433 (defun gnus-inews-in-reply-to ()
1434 "Return the In-Reply-To header for this message."
1439 ;;; Gnus Mail Functions
1442 ;;; Mail reply commands of Gnus summary mode
1444 (defun gnus-summary-reply (yank &optional yank-articles)
1445 "Reply mail to news author.
1446 If prefix argument YANK is non-nil, original article is yanked automatically.
1447 Customize the variable gnus-mail-reply-method to use another mailer."
1449 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1450 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1451 (gnus-set-global-variables)
1452 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1453 (gnus-summary-select-article)
1454 (bury-buffer gnus-article-buffer)
1455 (gnus-mail-reply (or yank-articles (not (not yank)))))
1457 (defun gnus-summary-reply-with-original (n)
1458 "Reply mail to news author with original article.
1459 Customize the variable gnus-mail-reply-method to use another mailer."
1461 (gnus-summary-reply t (gnus-summary-work-articles n)))
1463 (defun gnus-summary-mail-forward (post)
1464 "Forward the current message to another user.
1465 Customize the variable gnus-mail-forward-method to use another mailer."
1467 (gnus-set-global-variables)
1468 (gnus-summary-select-article)
1469 (gnus-copy-article-buffer)
1471 (gnus-forward-using-post gnus-article-copy)
1472 (gnus-mail-forward gnus-article-copy)))
1474 (defun gnus-summary-post-forward ()
1475 "Forward the current article to a newsgroup."
1477 (gnus-summary-mail-forward t))
1479 (defvar gnus-nastygram-message
1480 "The following article was inappropriately posted to %s.\n"
1481 "Format string to insert in nastygrams.
1482 The current group name will be inserted at \"%s\".")
1484 (defun gnus-summary-mail-nastygram (n)
1485 "Send a nastygram to the author of the current article."
1487 (if (or gnus-expert-user
1489 "Really send a nastygram to the author of the current article? "))
1490 (let ((group gnus-newsgroup-name))
1491 (gnus-summary-reply-with-original n)
1492 (set-buffer gnus-mail-buffer)
1493 (insert (format gnus-nastygram-message group))
1494 (gnus-mail-send-and-exit))))
1496 (defun gnus-summary-mail-other-window ()
1497 "Compose mail in other window.
1498 Customize the variable `gnus-mail-other-window-method' to use another
1501 (gnus-set-global-variables)
1504 (defun gnus-new-mail (&optional to)
1506 (when (and gnus-interactive-post
1507 (not gnus-expert-user))
1508 (setq subject (read-string "Subject: ")))
1509 (pop-to-buffer gnus-mail-buffer)
1511 (gnus-mail-setup 'new to subject)
1512 (run-hooks 'gnus-mail-hook)))
1514 (defun gnus-mail-reply (&optional yank to-address followup)
1516 (set-buffer gnus-summary-buffer)
1517 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1518 (cur (cons (current-buffer) (cdr gnus-article-current)))
1519 (winconf (current-window-configuration))
1520 from subject date reply-to message-of to cc
1521 references message-id sender follow-to sendto elt new-cc)
1522 (set-buffer (get-buffer-create gnus-mail-buffer))
1524 (if (and (buffer-modified-p)
1527 "Unsent message being composed; erase it? ")))
1531 (gnus-copy-article-buffer)
1533 (set-buffer gnus-article-copy)
1534 (gnus-narrow-to-headers)
1536 ;; This is a regular reply.
1537 (if (and (symbolp gnus-reply-to-function)
1538 (fboundp gnus-reply-to-function))
1539 (setq follow-to (funcall gnus-reply-to-function group)))
1540 ;; This is a followup.
1541 (if (and (symbolp gnus-followup-to-function)
1542 (fboundp gnus-followup-to-function))
1545 (funcall gnus-followup-to-function group)))))
1546 (setq from (mail-fetch-field "from"))
1547 (setq date (or (mail-fetch-field "date")
1548 (mail-header-date gnus-current-headers)))
1549 (setq message-of (gnus-message-of from date))
1550 (setq sender (mail-fetch-field "sender"))
1551 (setq subject (or (mail-fetch-field "subject") "none"))
1552 ;; Remove any (buggy) Re:'s that are present and make a
1554 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1555 (setq subject (substring subject (match-end 0))))
1556 (setq subject (concat "Re: " subject))
1557 (setq to (mail-fetch-field "to"))
1558 (setq cc (mail-fetch-field "cc"))
1559 (setq reply-to (mail-fetch-field "reply-to"))
1560 (setq references (mail-fetch-field "references"))
1561 (setq message-id (mail-fetch-field "message-id"))
1565 ;; When we followup, we want all the headers, I would think.
1566 (setq new-cc (rmail-dont-reply-to
1568 (if cc (concat (if to ", " "") cc) ""))))
1569 (let ((rmail-dont-reply-to-names
1570 (regexp-quote (mail-strip-quoted-names
1571 (or to-address reply-to from "")))))
1572 (setq new-cc (rmail-dont-reply-to new-cc))))
1576 (setq news-reply-yank-from (or from "(nobody)"))
1577 (setq news-reply-yank-message-id
1578 (or message-id "(unknown Message-ID)"))
1580 ;; Gather the "to" addresses out of the follow-to list and remove
1582 (if (and follow-to (listp follow-to))
1583 (while (setq elt (assoc "To" follow-to))
1584 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1585 (setq follow-to (delq elt follow-to))))
1588 (if followup 'followup 'reply)
1590 (if (and follow-to (not (stringp follow-to))) sendto
1591 (or follow-to reply-to from sender "")))
1593 (if (zerop (length new-cc)) nil new-cc)
1596 (make-local-variable 'gnus-article-reply)
1597 (setq gnus-article-reply cur)
1598 (make-local-variable 'gnus-prev-winconf)
1599 (setq gnus-prev-winconf winconf)
1600 (make-local-variable 'gnus-reply-subject)
1601 (setq gnus-reply-subject subject)
1602 (make-local-variable 'gnus-in-reply-to)
1603 (setq gnus-in-reply-to message-of)
1605 (auto-save-mode auto-save-default)
1607 (if (and follow-to (listp follow-to))
1609 (goto-char (point-min))
1610 (re-search-forward "^To:" nil t)
1614 (insert (car (car follow-to)) ": " (cdr (car follow-to)) "\n")
1615 (setq follow-to (cdr follow-to)))))
1616 (nnheader-insert-references references message-id)
1618 ;; Now the headers should be ok, so we do the yanking.
1619 (goto-char (point-min))
1621 (concat "^" (regexp-quote mail-header-separator) "$"))
1624 (gnus-configure-windows 'reply 'force)
1625 (let ((last (point))
1627 (if (not (listp yank))
1630 (mail-yank-original nil))
1631 (or mail-yank-hooks mail-citation-hook
1632 (run-hooks 'news-reply-header-hook)))
1634 (save-window-excursion
1635 (set-buffer gnus-summary-buffer)
1636 (gnus-summary-select-article nil nil nil (car yank))
1637 (gnus-summary-remove-process-mark (car yank)))
1639 (gnus-copy-article-buffer)
1640 (mail-yank-original nil)
1642 (or mail-yank-hooks mail-citation-hook
1643 (run-hooks 'news-reply-header-hook))
1645 (setq yank (cdr yank))))
1648 (gnus-configure-windows 'reply-yank 'force))
1649 (run-hooks 'gnus-mail-hook)))))
1651 (defun gnus-new-news (&optional group inhibit-prompt)
1652 "Set up a *post-news* buffer that points to GROUP.
1653 If INHIBIT-PROMPT, never prompt for a Subject."
1654 (let ((winconf (current-window-configuration))
1656 (when (and gnus-interactive-post
1657 (not inhibit-prompt)
1658 (not gnus-expert-user))
1659 (setq subject (read-string "Subject: ")))
1660 (pop-to-buffer gnus-post-news-buffer)
1663 ;; Let posting styles be configured.
1664 (gnus-configure-posting-styles)
1665 (news-setup nil subject nil (and group (gnus-group-real-name group)) nil)
1666 (goto-char (point-min))
1668 (unless (re-search-forward
1669 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1670 (goto-char (point-max)))
1673 (gnus-inews-insert-bfcc)
1674 (gnus-inews-insert-signature)
1675 (and gnus-post-prepare-function
1676 (symbolp gnus-post-prepare-function)
1677 (fboundp gnus-post-prepare-function)
1678 (funcall gnus-post-prepare-function group))
1679 (goto-char (point-min))
1681 (re-search-forward "^Subject: " nil t)
1682 (re-search-forward "^Newsgroups: " nil t))
1683 (run-hooks 'gnus-post-prepare-hook)
1684 (make-local-variable 'gnus-prev-winconf)
1685 (setq gnus-prev-winconf winconf)
1686 (gnus-inews-modify-mail-mode-map)
1687 (local-set-key "\C-c\C-c" 'gnus-inews-news)))
1689 (defun gnus-news-followup (&optional yank group)
1691 (set-buffer gnus-summary-buffer)
1692 (if (not (or (not gnus-novice-user)
1695 "Are you sure you want to post to all of USENET? ")))
1697 (let ((group (gnus-group-real-name (or group gnus-newsgroup-name)))
1698 (cur (cons (current-buffer) (cdr gnus-article-current)))
1699 (winconf (current-window-configuration))
1700 from subject date reply-to message-of
1701 references message-id sender follow-to sendto elt
1702 followup-to distribution newsgroups)
1703 (set-buffer (get-buffer-create gnus-post-news-buffer))
1705 (if (and (buffer-modified-p)
1708 "Unsent message being composed; erase it? ")))
1712 (gnus-copy-article-buffer)
1714 (set-buffer gnus-article-copy)
1715 (gnus-narrow-to-headers)
1716 (if (and (symbolp gnus-followup-to-function)
1717 (fboundp gnus-followup-to-function))
1720 (funcall gnus-followup-to-function group))))
1721 (setq from (mail-fetch-field "from"))
1722 (setq date (or (mail-fetch-field "date")
1723 (mail-header-date gnus-current-headers)))
1724 (setq message-of (gnus-message-of from date))
1725 (setq subject (or (mail-fetch-field "subject") "none"))
1726 ;; Remove any (buggy) Re:'s that are present and make a
1728 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1729 (setq subject (substring subject (match-end 0))))
1730 (setq subject (concat "Re: " subject))
1731 (setq references (mail-fetch-field "references"))
1732 (setq message-id (mail-fetch-field "message-id"))
1733 (setq followup-to (mail-fetch-field "followup-to"))
1734 (setq newsgroups (mail-fetch-field "newsgroups"))
1735 (setq distribution (mail-fetch-field "distribution"))
1736 ;; Remove bogus distribution.
1737 (and (stringp distribution)
1738 (string-match "world" distribution)
1739 (setq distribution nil))
1742 (setq news-reply-yank-from (or from "(nobody)"))
1743 (setq news-reply-yank-message-id
1744 (or message-id "(unknown Message-ID)"))
1746 ;; Gather the "to" addresses out of the follow-to list and remove
1748 (if (and follow-to (listp follow-to))
1749 (while (setq elt (assoc "Newsgroups" follow-to))
1750 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1751 (setq follow-to (delq elt follow-to))))
1753 ;; Let posting styles be configured.
1754 (gnus-configure-posting-styles)
1756 (news-setup nil subject nil
1759 gnus-use-followup-to
1760 (or (not (eq gnus-use-followup-to 'ask))
1763 "Use Followup-To %s? " followup-to)))
1765 newsgroups group "")
1768 (make-local-variable 'gnus-article-reply)
1769 (setq gnus-article-reply cur)
1770 (make-local-variable 'gnus-prev-winconf)
1771 (setq gnus-prev-winconf winconf)
1772 (make-local-variable 'gnus-reply-subject)
1773 (setq gnus-reply-subject (mail-header-subject gnus-current-headers))
1774 (make-local-variable 'gnus-in-reply-to)
1775 (setq gnus-in-reply-to message-of)
1777 (gnus-inews-insert-signature)
1779 (and gnus-post-prepare-function
1780 (symbolp gnus-post-prepare-function)
1781 (fboundp gnus-post-prepare-function)
1782 (funcall gnus-post-prepare-function group))
1783 (run-hooks 'gnus-post-prepare-hook)
1785 (auto-save-mode auto-save-default)
1786 (gnus-inews-modify-mail-mode-map)
1787 (local-set-key "\C-c\C-c" 'gnus-inews-news)
1789 (if (and follow-to (listp follow-to))
1791 (goto-char (point-min))
1792 (and (re-search-forward "^Newsgroups:" nil t)
1795 (insert (car (car follow-to)) ": "
1796 (cdr (car follow-to)) "\n")
1797 (setq follow-to (cdr follow-to)))))
1799 ;; If a distribution existed, we use it.
1802 (mail-position-on-field "Distribution")
1803 (insert distribution)))
1805 (nnheader-insert-references references message-id)
1807 ;; Handle `gnus-auto-mail-to-author'.
1808 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
1809 ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
1810 (let ((to (if (if (eq gnus-auto-mail-to-author 'ask)
1811 (y-or-n-p "Also send mail to author? ")
1812 gnus-auto-mail-to-author)
1814 (set-buffer gnus-article-copy)
1815 (gnus-fetch-field "reply-to"))
1817 (x-mail (save-excursion
1818 (set-buffer gnus-article-copy)
1819 (gnus-fetch-field "x-mail-copy-to"))))
1820 ;; Deny sending copy if there's a negative X-Mail-Copy-To
1823 (if (and (string= x-mail "never")
1824 (not (eq gnus-auto-mail-to-author 'force)))
1827 ;; Insert a To or Cc header.
1829 (if (mail-fetch-field "To")
1832 (insert "Cc: " to "\n"))
1833 (mail-position-on-field "To")
1836 (gnus-inews-insert-bfcc)
1838 ;; Now the headers should be ok, so we do the yanking.
1839 (goto-char (point-min))
1841 (concat "^" (regexp-quote mail-header-separator) "$"))
1845 (gnus-configure-windows 'followup 'force)
1848 (let ((last (point))
1850 (if (not (listp yank))
1853 (mail-yank-original nil))
1854 (or mail-yank-hooks mail-citation-hook
1855 (run-hooks 'news-reply-header-hook)))
1857 (save-window-excursion
1858 (set-buffer gnus-summary-buffer)
1859 (gnus-summary-select-article nil nil nil (car yank))
1860 (gnus-summary-remove-process-mark (car yank)))
1862 (gnus-copy-article-buffer)
1863 (mail-yank-original nil)
1865 (or mail-yank-hooks mail-citation-hook
1866 (run-hooks 'news-reply-header-hook))
1868 (setq yank (cdr yank))))
1870 (gnus-configure-windows 'followup-yank 'force))
1872 (make-local-variable 'gnus-article-check-size)
1873 (setq gnus-article-check-size
1874 (cons (buffer-size) (gnus-article-checksum))))))))
1876 (defun gnus-message-of (from date)
1877 "Take a FROM and a DATE and create an IN-REPLY-TO."
1883 (string-match " *at \\| *@ \\| *(\\| *<" from)))
1884 (concat (if stop-pos (substring from 0 stop-pos) from)
1886 (if (or (not date) (string= date ""))
1887 "(unknown date)" date))))))
1889 (defun gnus-mail-yank-original ()
1892 (mail-yank-original nil))
1893 (or mail-yank-hooks mail-citation-hook
1894 (run-hooks 'news-reply-header-hook)))
1896 (defun gnus-mail-send-and-exit (&optional dont-send)
1897 "Send the current mail and return to Gnus."
1899 (let* ((reply gnus-article-reply)
1900 (winconf gnus-prev-winconf)
1901 (address-group gnus-add-to-address)
1902 (to-address (and address-group
1903 (mail-fetch-field "to"))))
1904 (setq gnus-add-to-address nil)
1905 (or dont-send (gnus-mail-send))
1907 ;; This mail group doesn't have a `to-address', so we add one
1910 (gnus-group-add-parameter
1911 address-group (cons 'to-address to-address)))
1912 (if (get-buffer gnus-group-buffer)
1914 (if (gnus-buffer-exists-p (car-safe reply))
1916 (set-buffer (car reply))
1918 (gnus-summary-mark-article-as-replied
1920 (and winconf (set-window-configuration winconf))))))
1922 (defun gnus-put-message ()
1923 "Put the current message in some group and return to Gnus."
1925 (let ((reply gnus-article-reply)
1926 (winconf gnus-prev-winconf)
1927 (group gnus-newsgroup-name)
1930 (or (and group (not (gnus-group-read-only-p group)))
1931 (setq group (read-string "Put in group: " nil
1932 (gnus-writable-groups))))
1933 (and (gnus-gethash group gnus-newsrc-hashtb)
1934 (error "No such group: %s" group))
1939 (gnus-inews-narrow-to-headers)
1940 (let (gnus-deletable-headers)
1941 (if (eq major-mode 'mail-mode)
1942 (gnus-inews-insert-headers gnus-required-mail-headers)
1943 (gnus-inews-insert-headers)))
1944 (goto-char (point-max))
1945 (insert "Gcc: " group "\n")
1950 (if (get-buffer gnus-group-buffer)
1952 (if (gnus-buffer-exists-p (car-safe reply))
1954 (set-buffer (car reply))
1956 (gnus-summary-mark-article-as-replied
1958 (and winconf (set-window-configuration winconf))))))
1961 (defun gnus-forward-make-subject (buffer)
1964 (concat "[" (if (memq 'mail (assoc (symbol-name
1965 (car (gnus-find-method-for-group
1966 gnus-newsgroup-name)))
1967 gnus-valid-select-methods))
1968 (gnus-fetch-field "From")
1969 gnus-newsgroup-name)
1970 "] " (or (gnus-fetch-field "Subject") ""))))
1972 (defun gnus-forward-insert-buffer (buffer)
1973 (let ((beg (goto-char (point-max))))
1974 (insert "------- Start of forwarded message -------\n")
1975 (insert-buffer-substring buffer)
1976 (goto-char (point-max))
1977 (insert "------- End of forwarded message -------\n")
1978 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
1980 (while (setq beg (next-single-property-change (point) 'invisible))
1982 (delete-region beg (or (next-single-property-change
1986 (defun gnus-mail-forward (&optional buffer)
1987 "Forward the current message to another user using mail."
1988 (let* ((forward-buffer (or buffer (current-buffer)))
1989 (winconf (current-window-configuration))
1990 (subject (gnus-forward-make-subject forward-buffer)))
1991 (set-buffer (get-buffer-create gnus-mail-buffer))
1992 (if (and (buffer-modified-p)
1995 "Unsent message being composed; erase it? ")))
1998 (gnus-mail-setup 'forward nil subject)
1999 (make-local-variable 'gnus-prev-winconf)
2000 (setq gnus-prev-winconf winconf)
2001 (gnus-forward-insert-buffer forward-buffer)
2002 (goto-char (point-min))
2003 (re-search-forward "^To: ?" nil t)
2004 (gnus-configure-windows 'mail-forward 'force)
2005 ;; You have a chance to arrange the message.
2006 (run-hooks 'gnus-mail-forward-hook)
2007 (run-hooks 'gnus-mail-hook))))
2009 (defun gnus-forward-using-post (&optional buffer)
2011 (let* ((forward-buffer (or buffer (current-buffer)))
2012 (subject (gnus-forward-make-subject forward-buffer))
2013 (gnus-newsgroup-name nil))
2014 (gnus-post-news 'post nil nil nil nil subject)
2016 (gnus-forward-insert-buffer forward-buffer)
2017 ;; You have a chance to arrange the message.
2018 (run-hooks 'gnus-mail-forward-hook)))))
2020 (defun gnus-mail-other-window-using-mail ()
2021 "Compose mail other window using mail."
2022 (let ((winconf (current-window-configuration)))
2023 (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
2024 (gnus-inews-modify-mail-mode-map)
2025 (make-local-variable 'gnus-prev-winconf)
2026 (setq gnus-prev-winconf winconf)
2027 (run-hooks 'gnus-mail-hook)
2028 (gnus-configure-windows 'summary-mail 'force)))
2030 (defun gnus-article-mail (yank)
2031 "Send a reply to the address near point.
2032 If YANK is non-nil, include the original article."
2036 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
2037 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
2040 (switch-to-buffer gnus-summary-buffer)
2041 (gnus-mail-reply yank address)))))
2044 "Send a bug report to the Gnus maintainers."
2046 (let ((winconf (current-window-configuration)))
2047 (delete-other-windows)
2048 (switch-to-buffer "*Gnus Help Bug*")
2050 (insert gnus-bug-message)
2051 (goto-char (point-min))
2052 (pop-to-buffer "*Gnus Bug*")
2055 (mail-setup gnus-maintainer nil nil nil nil nil)
2056 (auto-save-mode auto-save-default)
2057 (make-local-variable 'gnus-prev-winconf)
2058 (setq gnus-prev-winconf winconf)
2059 (gnus-inews-modify-mail-mode-map)
2060 (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
2061 (goto-char (point-min))
2062 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2064 (insert (format "%s\n%s\n\n\n\n\n" (gnus-version) (emacs-version)))
2066 (goto-char (point-min))
2067 (search-forward "Subject: " nil t)
2070 (defun gnus-bug-mail-send-and-exit ()
2071 "Send the bug message and exit."
2073 (and (get-buffer "*Gnus Help Bug*")
2074 (kill-buffer "*Gnus Help Bug*"))
2075 (gnus-mail-send-and-exit))
2077 (defun gnus-debug ()
2078 "Attemps to go through the Gnus source file and report what variables have been changed.
2079 The source file has to be in the Emacs load path."
2081 (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el"))
2082 file dirs expr olist sym)
2083 (message "Please wait while we snoop your variables...")
2086 (set-buffer (get-buffer-create " *gnus bug info*"))
2087 (buffer-disable-undo (current-buffer))
2090 (setq dirs load-path)
2092 (if (or (not (car dirs))
2093 (not (stringp (car dirs)))
2095 (setq file (concat (file-name-as-directory
2096 (car dirs)) (car files))))))
2097 (setq dirs (cdr dirs))
2099 (insert-file-contents file)
2100 (goto-char (point-min))
2101 (or (re-search-forward "^;;* *Internal variables" nil t)
2102 (error "Malformed sources in file %s" file))
2103 (narrow-to-region (point-min) (point))
2104 (goto-char (point-min))
2105 (while (setq expr (condition-case ()
2106 (read (current-buffer)) (error nil)))
2108 (and (eq (car expr) 'defvar)
2109 (stringp (nth 3 expr))
2110 (or (not (boundp (nth 1 expr)))
2111 (not (equal (eval (nth 2 expr))
2112 (symbol-value (nth 1 expr)))))
2113 (setq olist (cons (nth 1 expr) olist)))
2115 (setq files (cdr files)))
2116 (kill-buffer (current-buffer)))
2117 (insert "------------------- Environment follows -------------------\n\n")
2119 (if (boundp (car olist))
2120 (insert "(setq " (symbol-name (car olist))
2121 (if (or (consp (setq sym (symbol-value (car olist))))
2123 (not (or (eq sym nil)
2126 (prin1-to-string (symbol-value (car olist))) ")\n")
2127 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
2128 (setq olist (cdr olist)))
2130 ;; Remove any null chars - they seem to cause trouble for some
2131 ;; mailers. (Byte-compiled output from the stuff above.)
2132 (goto-char (point-min))
2133 (while (re-search-forward "[\000\200]" nil t)
2134 (replace-match "" t t))))
2137 ;;; Treatment of rejected articles.
2142 (defun gnus-summary-resend-bounced-mail (fetch)
2143 "Re-mail the current message.
2144 This only makes sense if the current message is a bounce message than
2145 contains some mail you have written which has been bounced back to
2147 If FETCH, try to fetch the article that this is a reply to, if indeed
2150 (gnus-summary-select-article t)
2151 ;; Create a mail buffer.
2154 (insert-buffer-substring gnus-article-buffer)
2155 (goto-char (point-min))
2156 (search-forward "\n\n")
2157 ;; We remove everything before the bounced mail.
2160 (if (re-search-forward "[^ \t]*:" nil t)
2166 (gnus-narrow-to-headers)
2167 (nnheader-remove-header gnus-bounced-headers-junk t)
2168 (setq references (mail-fetch-field "references"))
2169 (goto-char (point-max))
2170 (insert mail-header-separator)))
2171 ;; If there are references, we fetch the article we answered to.
2174 (string-match "\\(<[^]+>\\)[ \t]*$" references)
2175 (gnus-summary-refer-article
2176 (substring references (match-beginning 1) (match-end 1)))
2178 (gnus-summary-show-all-headers)
2179 (gnus-configure-windows 'compose-bounce))))
2180 (goto-char (point-min)))
2184 (defun gnus-mail-send ()
2185 "Send the current buffer as mail.
2186 Headers will be generated before sending."
2191 (gnus-inews-narrow-to-headers)
2192 (gnus-inews-insert-headers gnus-required-mail-headers)
2193 (gnus-inews-remove-empty-headers)))
2195 ;; Remove the header separator.
2196 (goto-char (point-min))
2197 (and (re-search-forward
2198 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2199 (replace-match "" t t))
2200 ;; Run final inews hooks. This hook may do FCC.
2201 (run-hooks 'gnus-inews-article-hook)
2203 (gnus-narrow-to-headers)
2204 (nnheader-remove-header "^[gf]cc:" t)
2206 (goto-char (point-min))
2207 (search-forward "\n\n")
2209 (insert mail-header-separator)
2211 (run-hooks 'gnus-message-sent-hook))
2213 (defun gnus-inews-modify-mail-mode-map ()
2214 (use-local-map (copy-keymap (current-local-map)))
2215 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
2216 (local-set-key "\C-c\C-p" 'gnus-put-message)
2217 (local-set-key "\C-c\C-d" 'gnus-enter-into-draft-group))
2219 (defun gnus-mail-setup (type &optional to subject in-reply-to cc
2220 replybuffer actions)
2221 ;; Let posting styles be configured.
2222 (gnus-configure-posting-styles)
2226 (and (or (eq type 'reply) (eq type 'followup))
2227 (eq gnus-mail-reply-method 'gnus-mail-reply-using-mhe))
2228 (and (eq type 'forward)
2229 (eq gnus-mail-forward-method 'gnus-mail-forward-using-mhe))
2231 (eq gnus-mail-other-window-method
2232 'gnus-mail-other-window-using-mhe)))
2233 'gnus-mh-mail-setup)
2235 (and (or (eq type 'reply) (eq type 'followup))
2236 (eq gnus-mail-reply-method 'gnus-mail-reply-using-vm))
2237 (and (eq type 'forward)
2238 (eq gnus-mail-forward-method 'gnus-mail-forward-using-vm))
2240 (eq gnus-mail-other-window-method
2241 'gnus-mail-other-window-using-vm)))
2242 'gnus-vm-mail-setup)
2243 (t 'gnus-sendmail-mail-setup))
2244 to subject in-reply-to cc replybuffer actions))
2246 (defun gnus-sendmail-mail-setup (to subject in-reply-to cc replybuffer actions)
2248 (mail-setup to subject nil cc replybuffer actions)
2249 (goto-char (point-min))
2250 (if (re-search-forward
2251 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2253 (goto-char (point-max)))
2255 (gnus-inews-modify-mail-mode-map))
2259 ;; Do Gcc handling, which copied the message over to some group.
2260 (defun gnus-inews-do-gcc (&optional gcc)
2263 (gnus-narrow-to-headers)
2264 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
2267 () ; Nothing to be done.
2268 (nnheader-remove-header "gcc")
2269 ;; Copy the article over to some group(s).
2270 (while (string-match
2271 "^[ \t]*\\([^ \t]+\\)\\([ \t]+\\|$\\)" gcc)
2272 (setq end (match-end 0))
2274 (gnus-request-accept-article
2275 (substring gcc (match-beginning 1) (match-end 1)) t)
2277 (setq gcc (substring gcc end))))))))
2279 (defun gnus-inews-insert-bfcc ()
2280 "Insert Bcc and Fcc headers."
2282 ;; Handle author copy using BCC field.
2283 (when (and gnus-mail-self-blind
2284 (not (mail-fetch-field "bcc")))
2285 (mail-position-on-field "Bcc")
2286 (insert (if (stringp gnus-mail-self-blind)
2287 gnus-mail-self-blind
2288 (user-login-name))))
2289 ;; Handle author copy using FCC field.
2290 (when gnus-author-copy
2291 (mail-position-on-field "Fcc")
2292 (insert gnus-author-copy))))
2294 (defun gnus-inews-insert-gcc ()
2295 (let* ((group gnus-outgoing-message-group)
2297 ((and (symbolp group) (fboundp group))
2299 ((or (stringp group) (list group))
2303 (if (stringp group) group
2304 (mapconcat 'identity group " "))
2307 ;;; Handling rejected (and postponed) news.
2309 (defun gnus-draft-group ()
2310 "Return the name of the draft group."
2311 (gnus-group-prefixed-name
2312 (file-name-nondirectory gnus-draft-group-directory)
2313 (list 'nndir gnus-draft-group-directory)))
2315 (defun gnus-make-draft-group ()
2316 "Make the draft group or die trying."
2317 (let* ((method (` (nndir "private"
2318 (nndir-directory (, gnus-draft-group-directory)))))
2319 (group (gnus-group-prefixed-name
2320 (file-name-nondirectory gnus-draft-group-directory)
2322 (or (gnus-gethash group gnus-newsrc-hashtb)
2323 (gnus-group-make-group (gnus-group-real-name group) method)
2324 (error "Can't create the draft group"))
2327 (defun gnus-enter-into-draft-group ()
2328 "Enter the current buffer into the draft group."
2330 (gnus-put-in-draft-group t))
2332 (defun gnus-put-in-draft-group (&optional generate silent)
2333 "Does the actual putting."
2334 (let ((group (gnus-make-draft-group))
2335 (type (list major-mode (buffer-name) gnus-newsgroup-name
2338 (buf (current-buffer)))
2341 (nnheader-set-temp-buffer " *enter-draft*")
2342 (insert-buffer-substring buf)
2345 (gnus-inews-narrow-to-headers)
2346 (let (gnus-deletable-headers)
2347 (if (eq mode 'mail-mode)
2348 (gnus-inews-insert-headers gnus-required-mail-headers)
2349 (gnus-inews-insert-headers)))
2352 (goto-char (point-min))
2353 ;; We have to store whether we are in a mail group or news group.
2354 (insert (format "X-Gnus-Draft-Type: %S\n" type))
2355 (and (re-search-forward
2356 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2357 (replace-match "" t t))
2359 (gnus-request-accept-article group t)
2360 (kill-buffer (current-buffer)))
2362 (gnus-mail-send-and-exit 'dont-send))))
2363 (set-buffer-modified-p nil)))
2365 (defun gnus-summary-send-draft ()
2366 "Enter a mail/post buffer to edit and send the draft."
2368 (gnus-set-global-variables)
2369 (gnus-summary-select-article t)
2370 ;; First we find the draft type.
2373 (set-buffer gnus-article-buffer)
2375 (gnus-narrow-to-headers)
2376 (setq type (condition-case ()
2377 (read (mail-fetch-field "x-gnus-draft-type"))
2381 (error "Unknown draft type"))
2382 ;; Get to the proper buffer.
2383 (set-buffer (get-buffer-create (nth 1 type)))
2384 ;; It might be modified.
2385 (and (buffer-modified-p)
2386 (or (gnus-yes-or-no-p "Unsent message being composed; discard it? ")
2388 (setq buffer-read-only nil)
2389 (buffer-enable-undo (current-buffer))
2392 (funcall (car type))
2393 (and (eq major-mode 'mail-mode)
2394 (gnus-inews-modify-mail-mode-map))
2395 ;; Arrange for deletion of the draft after successful sending.
2396 (make-local-variable 'gnus-message-sent-hook)
2397 (setq gnus-message-sent-hook
2401 (gnus-request-expire-articles
2402 (quote (, (list (cdr gnus-article-current))))
2403 (, gnus-newsgroup-name) t)))))
2404 ;; Insert the draft.
2405 (insert-buffer-substring gnus-article-buffer)
2406 ;; Insert the separator.
2407 (goto-char (point-min))
2408 (search-forward "\n\n")
2410 (insert mail-header-separator)
2411 ;; Remove the draft header.
2412 (gnus-inews-narrow-to-headers)
2413 (nnheader-remove-header "x-gnus-draft-type")
2415 ;; Configure windows.
2416 (let ((gnus-draft-buffer (current-buffer)))
2417 (gnus-configure-windows 'draft))
2418 ;; Put point where you left it.
2419 (goto-char (nth 3 type))))
2421 (defun gnus-configure-posting-styles ()
2422 "Configure posting styles according to `gnus-posting-styles'."
2423 (let ((styles gnus-posting-styles)
2424 (gnus-newsgroup-name (or gnus-newsgroup-name ""))
2425 style match variable attribute value value-value)
2426 ;; Go through all styles and look for matches.
2428 (setq style (pop styles)
2430 (when (cond ((stringp match)
2431 ;; Regexp string match on the group name.
2432 (string-match match gnus-newsgroup-name))
2434 (cond ((fboundp match)
2435 ;; Function to be called.
2438 ;; Variable to be checked.
2439 (symbol-value match))))
2441 ;; This is a form to be evaled.
2443 ;; We have a match, so we set the variables.
2445 (setq attribute (pop style)
2446 value (cdr attribute))
2447 ;; We find the variable that is to be modified.
2448 (if (and (not (stringp (car attribute)))
2449 (not (setq variable (cdr (assq (car attribute)
2450 gnus-posting-style-alist)))))
2451 (message "Couldn't find attribute %s" (car attribute))
2452 ;; We set the variable.
2454 (cond ((stringp value)
2457 (cond ((fboundp value)
2460 (symbol-value value))))
2465 ;; This is an ordinary variable.
2466 (make-local-variable variable)
2467 (set variable value-value))
2468 ;; This is a header to be added to the headers when
2471 (make-local-variable gnus-required-headers)
2472 (make-local-variable gnus-required-mail-headers)
2473 (push (cons (car attribute) value-value)
2474 gnus-required-headers)
2475 (push (cons (car attribute) value-value)
2476 gnus-required-mail-headers)))))))))
2478 ;;; Allow redefinition of functions.
2484 ;;; gnus-msg.el ends here