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))
468 to-address to-group mailing-list to-list)
470 (setq to-address (gnus-group-get-parameter group 'to-address)
471 to-group (gnus-group-get-parameter group 'to-group)
472 to-list (gnus-group-get-parameter group 'to-list)
473 mailing-list (when gnus-mailing-list-groups
474 (string-match gnus-mailing-list-groups group))
475 group (gnus-group-real-name group)))
477 (and (gnus-member-of-valid 'post (or pgroup gnus-newsgroup-name))
483 (gnus-new-news (or to-group group))
484 (gnus-news-followup yank (or to-group group)))
488 (gnus-new-mail (or to-address to-list))
489 ;; Arrange for mail groups that have no `to-address' to
490 ;; get that when the user sends off the mail.
492 (make-local-variable 'gnus-add-to-address)
493 (setq gnus-add-to-address group)))
494 (gnus-mail-reply yank to-address 'followup)))))
496 (defun gnus-inews-news (&optional use-group-method)
497 "Send a news message.
498 If given a prefix, and the group is a foreign group, this function
499 will attempt to use the foreign server to post the article."
501 (or gnus-current-select-method
502 (setq gnus-current-select-method gnus-select-method))
503 (let* ((case-fold-search nil)
504 (reply gnus-article-reply)
507 (gnus-start-news-server) ;Use default server.
509 (goto-char (point-min))
510 (run-hooks 'news-inews-hook)
513 (gnus-message 5 "Posting to USENET...")
514 (setq post-result (funcall gnus-inews-article-function use-group-method))
515 (cond ((eq post-result 'illegal)
519 (gnus-message 5 "Posting to USENET...done")
520 (if (gnus-buffer-exists-p (car-safe reply))
523 (set-buffer gnus-summary-buffer)
524 (gnus-summary-mark-article-as-replied
526 (set-buffer-modified-p nil))
528 ;; We cannot signal an error.
532 1 "Article rejected: %s"
534 (gnus-post-method gnus-newsgroup-name use-group-method))))))
536 (let ((conf gnus-prev-winconf))
539 ;; Restore last window configuration.
540 (and conf (set-window-configuration conf))))))
542 (defun gnus-inews-narrow-to-headers ()
545 (goto-char (point-min))
546 (or (and (re-search-forward
547 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
551 (defun gnus-inews-send-mail-copy ()
552 ;; Mail the message if To, Bcc or Cc exists.
553 (let* ((types '("to" "bcc" "cc"))
555 (buffer (current-buffer))
559 (gnus-inews-narrow-to-headers)
562 (or (mail-fetch-field (car ty) nil t)
563 (setq types (delete (car ty) types)))
567 ;; We do not want to send mail.
569 (gnus-message 5 "Sending via mail...")
572 ;; We copy the article over to a temp buffer since we are
573 ;; going to modify it a little.
574 (nnheader-set-temp-buffer " *Gnus-mailing*")
575 (insert-buffer-substring buffer)
576 ;; We remove Fcc, because we don't want the mailer to see
578 (gnus-inews-narrow-to-headers)
579 (nnheader-remove-header "fcc")
581 ;; Insert the X-Courtesy-Message header.
582 (and (or (member "to" types)
585 (goto-char (point-max))
586 (insert "Posted-To: "
587 (mail-fetch-field "newsgroups") "\n")))
591 (if (and gnus-mail-courtesy-message
592 (or (member "to" types)
593 (member "cc" types)))
594 ;; We only want to insert the courtesy mail message if
595 ;; we use To or Cc; Bcc should not have one. Well, if
596 ;; both Bcc and To are present, it will get one
599 ;; Insert "courtesy" mail message.
600 (goto-char (point-min))
602 (concat "^" (regexp-quote mail-header-separator) "$"))
604 (insert gnus-mail-courtesy-message)))
607 (kill-buffer (current-buffer))
608 (gnus-message 5 "Sending via mail...done"))))))
610 (defun gnus-inews-remove-headers-after-mail ()
613 (let ((case-fold-search t))
614 (gnus-inews-narrow-to-headers)
615 ;; Remove Bcc completely.
616 (nnheader-remove-header "bcc")
617 ;; We transform To and Cc headers to avoid re-mailing if the user
618 ;; accidentally (or purposefully) leans on the `C-c C-c' keys
619 ;; and the news server rejects the posting.
620 (while (re-search-forward "^\\(to\\|[bcf]cc\\|cc\\):" nil t)
625 (defun gnus-inews-dex-headers ()
626 "Remove \"X-\" prefixes from To and Cc headers."
629 (let ((case-fold-search t))
630 (gnus-narrow-to-headers)
631 (while (re-search-forward "^X-\\(to\\|[bcf]cc\\|cc\\):" nil t)
636 (defun gnus-inews-remove-empty-headers ()
637 "Remove empty headers from news and mail.
638 The buffer should be narrowed to the headers before this function is
641 (goto-char (point-min))
642 (while (re-search-forward "^[^ \t:]+:\\([ \t]*\n\\)+[^ \t]" nil t)
643 (delete-region (match-beginning 0) (1- (match-end 0)))
644 (beginning-of-line))))
646 (defun gnus-inews-check-post ()
647 "Check whether the post looks ok."
649 (not gnus-check-before-posting)
651 ;; We narrow to the headers and check them first.
654 (goto-char (point-min))
659 (concat "^" (regexp-quote mail-header-separator) "$"))
660 (match-beginning 0)))
661 (goto-char (point-min))
663 ;; Check for commands in Subject.
665 (gnus-check-before-posting 'subject-cmsg)
667 (if (string-match "^cmsg " (mail-fetch-field "subject"))
669 "The control code \"cmsg \" is in the subject. Really post? ")
671 ;; Check for multiple identical headers.
672 (or (gnus-check-before-posting 'multiple-headers)
675 (while (and (not found) (re-search-forward "^[^ \t:]+: "
678 (or (re-search-forward
679 (concat "^" (setq found
682 (- (match-end 0) 2))))
687 (format "Multiple %s headers. Really post? " found))
689 ;; Check for Version and Sendsys.
690 (or (gnus-check-before-posting 'sendsys)
692 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
694 (format "The article contains a %s command. Really post? "
695 (buffer-substring (match-beginning 0)
696 (1- (match-end 0)))))
698 ;; Check for Approved.
699 (or (gnus-check-before-posting 'approved)
701 (if (re-search-forward "^Approved:" nil t)
703 "The article contains an Approved header. Really post? ")
705 ;; Check the Message-ID header.
706 (or (gnus-check-before-posting 'message-id)
708 (let* ((case-fold-search t)
709 (message-id (mail-fetch-field "message-id")))
711 (and (string-match "@" message-id)
712 (string-match "@[^\\.]*\\." message-id))
715 "The Message-ID looks strange: \"%s\". Really post? "
717 ;; Check the From header.
718 (or (gnus-check-before-posting 'from)
720 (let* ((case-fold-search t)
721 (from (mail-fetch-field "from")))
724 (gnus-y-or-n-p "There is no From line. Really post? "))
725 ((not (string-match "@[^\\.]*\\." from))
728 "The address looks strange: \"%s\". Really post? " from)))
729 ((string-match "(.*).*(.*)" from)
732 "The From header looks strange: \"%s\". Really post? "
734 ((string-match "<[^>]+> *$" from)
735 (let ((name (substring from 0 (match-beginning 0))))
737 (string-match "^ *\"[^\"]*\" *$" name)
738 (not (string-match "[][.!()<>@,;:\\]" name))
741 "The From header name has bogus characters. Really post? "
745 ;; Check for long lines.
746 (or (gnus-check-before-posting 'long-lines)
748 (goto-char (point-min))
750 (concat "^" (regexp-quote mail-header-separator) "$"))
754 (< (current-column) 80))
755 (zerop (forward-line 1))))
760 "You have lines longer than 79 characters. Really post? ")))))
761 ;; Check for control characters.
762 (or (gnus-check-before-posting 'control-chars)
764 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
766 "The article contains control characters. Really post? ")
768 ;; Check excessive size.
769 (or (gnus-check-before-posting 'size)
770 (if (> (buffer-size) 60000)
772 (format "The article is %d octets long. Really post? "
775 ;; Use the (size . checksum) variable to see whether the
776 ;; article is empty or has only quoted text.
778 (gnus-check-before-posting 'new-text)
779 (if (and (= (buffer-size) (car gnus-article-check-size))
780 (= (gnus-article-checksum) (cdr gnus-article-check-size)))
782 "It looks like there's no new text in your article. Really post? ")
784 ;; Check the length of the signature.
785 (or (gnus-check-before-posting 'signature)
787 (goto-char (point-max))
788 (if (not (re-search-backward gnus-signature-separator nil t))
790 (if (> (count-lines (point) (point-max)) 5)
793 "Your .sig is %d lines; it should be max 4. Really post? "
794 (count-lines (point) (point-max))))
797 (defun gnus-article-checksum ()
801 (setq sum (logxor sum (following-char)))
805 ;; Returns non-nil if this type is not to be checked.
806 (defun gnus-check-before-posting (type)
808 (or (not gnus-check-before-posting)
809 (if (listp gnus-check-before-posting)
810 (memq type gnus-check-before-posting)
813 (defun gnus-cancel-news ()
814 "Cancel an article you posted."
816 (if (or gnus-expert-user
817 (gnus-yes-or-no-p "Do you really want to cancel this article? "))
822 (or (gnus-member-of-valid 'post gnus-newsgroup-name)
823 (error "This backend does not support canceling"))
825 ;; Get header info. from original article.
827 (gnus-article-show-all-headers)
828 (goto-char (point-min))
829 (search-forward "\n\n" nil 'move)
830 (narrow-to-region (point-min) (point))
831 (setq from (mail-fetch-field "from"))
832 (setq newsgroups (mail-fetch-field "newsgroups"))
833 (setq message-id (mail-fetch-field "message-id"))
834 (setq distribution (mail-fetch-field "distribution")))
835 ;; Verify if the article is absolutely user's by comparing
836 ;; user id with value of its From: field.
839 (downcase (mail-strip-quoted-names from))
840 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
842 (ding) (gnus-message 3 "This article is not yours.")
844 ;; Make control article.
845 (set-buffer (get-buffer-create " *Gnus-canceling*"))
846 (buffer-disable-undo (current-buffer))
848 (insert "Newsgroups: " newsgroups "\n"
849 "From: " (gnus-inews-real-user-address) "\n"
850 "Subject: cancel " message-id "\n"
851 "Control: cancel " message-id "\n"
853 (concat "Distribution: " distribution "\n")
855 mail-header-separator "\n"
856 "This is a cancel message from " from ".\n")
857 ;; Send the control article to NNTP server.
858 (gnus-message 5 "Canceling your article...")
860 (if (funcall gnus-inews-article-function)
861 (gnus-message 5 "Canceling your article...done")
864 (gnus-message 1 "Cancel failed; %s"
865 (gnus-status-message gnus-newsgroup-name))
868 ;; Kill the article buffer.
869 (kill-buffer (current-buffer))))))))
872 ;;; Lowlevel inews interface.
874 ;; Dummy to avoid byte-compile warning.
875 (defvar nnspool-rejected-article-hook)
877 (defun gnus-inews-article (&optional use-group-method)
878 "Post an article in current buffer using NNTP protocol."
879 (let ((artbuf (current-buffer))
882 (goto-char (point-max))
883 ;; Require a newline at the end of the buffer since inews may
884 ;; append a .signature.
885 (or (= (preceding-char) ?\n)
887 ;; Prepare article headers. All message body such as signature
888 ;; must be inserted before Lines: field is prepared.
890 (gnus-inews-narrow-to-headers)
892 (gnus-inews-cleanup-headers)
893 ;; Remove some headers.
894 (gnus-inews-remove-headers)
895 ;; Insert some headers.
896 (gnus-inews-insert-headers)
897 ;; Let the user do all of the above.
898 (run-hooks 'gnus-inews-article-header-hook)
899 ;; Copy the Gcc header, if any.
900 (setq gcc (mail-fetch-field "gcc"))
902 ;; Check whether the article is a good Net Citizen.
903 (if (and gnus-article-check-size
904 (not (gnus-inews-check-post)))
907 ;; We fudge a hook for nnspool.
908 (setq nnspool-rejected-article-hook
914 (set-buffer (, (buffer-name)))
915 (gnus-put-in-draft-group nil 'silent))
919 1 "Couldn't enter rejected article into draft group")))))))
921 ;; Looks ok, so we do the nasty.
923 ;; This hook may insert a signature.
925 (goto-char (point-min))
926 (let ((gnus-newsgroup-name (or (mail-fetch-field "newsgroups")
927 gnus-newsgroup-name)))
928 (run-hooks 'gnus-prepare-article-hook)))
929 ;; Send off copies using mail, if that is wanted.
930 (gnus-inews-send-mail-copy)
931 ;; Remove more headers.
932 (gnus-inews-remove-headers-after-mail)
933 ;; Copy the article over to a temp buffer.
934 (nnheader-set-temp-buffer " *Gnus-posting*")
935 (insert-buffer-substring artbuf)
936 ;; Remove the header separator.
937 (goto-char (point-min))
939 (concat "^" (regexp-quote mail-header-separator) "$"))
940 (replace-match "" t t)
941 ;; Remove X- prefixes to headers.
942 (gnus-inews-dex-headers)
943 ;; Run final inews hooks. This hook may do FCC.
944 ;; The article must be saved before being posted because
945 ;; `gnus-request-post' modifies the buffer.
946 (run-hooks 'gnus-inews-article-hook)
947 ;; Copy the article over to some group, possibly.
948 (and gcc (gnus-inews-do-gcc gcc))
950 (let ((method (gnus-post-method gnus-newsgroup-name use-group-method)))
951 (setq result (gnus-request-post method)))
952 (kill-buffer (current-buffer)))
953 (run-hooks 'gnus-message-sent-hook)
954 ;; If the posting was unsuccessful (that it, it was rejected) we
955 ;; put it into the draft group.
956 (or result (gnus-put-in-draft-group))
959 (defun gnus-inews-cleanup-headers ()
960 ;; Correct newsgroups field: change sequence of spaces to comma and
961 ;; eliminate spaces around commas. Eliminate imbedded line breaks.
962 (goto-char (point-min))
963 (if (re-search-forward "^Newsgroups: +" nil t)
967 (if (re-search-forward "^[^ \t]" nil t)
971 (goto-char (point-min))
972 (while (re-search-forward "\n[ \t]+" nil t)
973 (replace-match " " t t)) ;No line breaks (too confusing)
974 (goto-char (point-min))
975 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
976 (replace-match "," t t))
977 (goto-char (point-min))
978 ;; Remove a trailing comma.
979 (if (re-search-forward ",$" nil t)
980 (replace-match "" t t))))
982 ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
983 ;; Help save the the world!
986 (let ((newsgroups (mail-fetch-field "newsgroups"))
987 (followup-to (mail-fetch-field "followup-to"))
990 (string-match "," newsgroups) (not followup-to))
992 (while (string-match "," newsgroups)
994 (cons (list (substring newsgroups 0 (match-beginning 0)))
996 (setq newsgroups (substring newsgroups (match-end 0))))
997 (setq groups (nreverse (cons (list newsgroups) groups)))
999 (setq to (completing-read
1000 "Followups to: (default all groups) " groups))
1001 (if (> (length to) 0)
1003 (goto-char (point-min))
1004 (insert "Followup-To: " to "\n")))))))
1006 ;; Cleanup Followup-To.
1007 (goto-char (point-min))
1008 (if (search-forward-regexp "^Followup-To: +" nil t)
1012 (if (re-search-forward "^[^ \t]" nil 'end)
1015 (goto-char (point-min))
1016 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
1017 (goto-char (point-min))
1018 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ","))))
1021 (defun gnus-inews-remove-headers ()
1022 (let ((case-fold-search t)
1023 (headers gnus-removable-headers))
1024 ;; Remove toxic headers.
1026 (goto-char (point-min))
1027 (and (re-search-forward
1028 (concat "^" (downcase (format "%s" (car headers))))
1030 (delete-region (progn (beginning-of-line) (point))
1031 (progn (forward-line 1) (point))))
1032 (setq headers (cdr headers)))))
1034 (defun gnus-inews-insert-headers (&optional headers)
1035 "Prepare article headers.
1036 Headers already prepared in the buffer are not modified.
1037 Headers in `gnus-required-headers' will be generated."
1038 (let ((Date (gnus-inews-date))
1039 (Message-ID (gnus-inews-message-id))
1040 (Organization (gnus-inews-organization))
1041 (From (gnus-inews-user-name))
1042 (Path (gnus-inews-path))
1045 (In-Reply-To (gnus-inews-in-reply-to))
1048 (Lines (gnus-inews-lines))
1049 (X-Newsreader gnus-version)
1050 (X-Mailer gnus-version)
1051 (headers (or headers gnus-required-headers))
1052 (case-fold-search t)
1054 ;; First we remove any old generated headers.
1055 (let ((headers gnus-deletable-headers))
1057 (goto-char (point-min))
1058 (and (re-search-forward
1059 (concat "^" (symbol-name (car headers)) ": *") nil t)
1060 (get-text-property (1+ (match-beginning 0)) 'gnus-deletable)
1062 (setq headers (cdr headers))))
1063 ;; If there are References, and no "Re: ", then the thread has
1064 ;; changed name. See Son-of-1036.
1065 (if (and (mail-fetch-field "references")
1066 (get-buffer gnus-article-buffer))
1067 (let ((psubject (gnus-simplify-subject-re
1068 (mail-fetch-field "subject"))))
1069 (or (and psubject gnus-reply-subject
1070 (string= (gnus-simplify-subject-re gnus-reply-subject)
1073 (string-match "@" Message-ID)
1075 (concat (substring Message-ID 0 (match-beginning 0))
1077 (substring Message-ID (match-beginning 0))))))))
1078 ;; Go through all the required headers and see if they are in the
1079 ;; articles already. If they are not, or are empty, they are
1080 ;; inserted automatically - except for Subject, Newsgroups and
1083 (goto-char (point-min))
1084 (setq elem (pop headers))
1086 (setq header (car elem))
1088 (when (or (not (re-search-forward
1089 (concat "^" (downcase (symbol-name header)) ":") nil t))
1091 ;; The header was found. We insert a space after the
1092 ;; colon, if there is none.
1093 (if (/= (following-char) ? ) (insert " "))
1094 ;; Find out whether the header is empty...
1095 (looking-at "[ \t]*$")))
1096 ;; So we find out what value we should insert.
1099 ((and (consp elem) (eq (car elem) 'optional))
1100 ;; This is an optional header. If the cdr of this
1101 ;; is something that is nil, then we do not insert
1103 (setq header (cdr elem))
1104 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
1105 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
1107 ;; The element is a cons. Either the cdr is a
1108 ;; string to be inserted verbatim, or it is a
1109 ;; function, and we insert the value returned from
1111 (or (and (stringp (cdr elem)) (cdr elem))
1112 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
1113 ((and (boundp header) (symbol-value header))
1114 ;; The element is a symbol. We insert the value
1115 ;; of this symbol, if any.
1116 (symbol-value header))
1118 ;; We couldn't generate a value for this header,
1119 ;; so we just ask the user.
1120 (read-from-minibuffer
1121 (format "Empty header for %s; enter value: " header)))))
1122 ;; Finally insert the header.
1124 (not (equal value "")))
1128 ;; This header didn't exist, so we insert it.
1129 (goto-char (point-max))
1130 (insert (symbol-name header) ": " value "\n")
1132 ;; The value of this header was empty, so we clear
1133 ;; totally and insert the new value.
1134 (delete-region (point) (gnus-point-at-bol))
1136 ;; Add the deletable property to the headers that require it.
1137 (and (memq header gnus-deletable-headers)
1138 (progn (beginning-of-line) (looking-at "[^:]+: "))
1139 (add-text-properties
1140 (point) (match-end 0)
1141 '(gnus-deletable t face italic) (current-buffer)))))))
1142 ;; Insert new Sender if the From is strange.
1143 (let ((from (mail-fetch-field "from"))
1144 (sender (mail-fetch-field "sender")))
1146 (not (gnus-check-before-posting 'sender))
1148 (downcase (car (gnus-extract-address-components from)))
1149 (downcase (gnus-inews-real-user-address))))
1153 (downcase (car (gnus-extract-address-components sender)))
1154 (downcase (gnus-inews-real-user-address))))))
1156 (goto-char (point-min))
1157 (and (re-search-forward "^Sender:" nil t)
1160 (insert "Original-")
1161 (beginning-of-line)))
1162 (insert "Sender: " (gnus-inews-real-user-address) "\n"))))))
1165 (defun gnus-inews-insert-signature ()
1166 "Insert a signature file.
1167 If `gnus-signature-function' is bound and returns a string, this
1168 string is used instead of the variable `gnus-signature-file'.
1169 In either case, if the string is a file name, this file is
1170 inserted. If the string is not a file name, the string itself is
1173 If you never want any signature inserted, set both of these variables to
1177 (or (and gnus-signature-function
1178 (funcall gnus-signature-function gnus-newsgroup-name))
1179 gnus-signature-file)))
1181 (or (file-exists-p signature)
1182 (string-match " " signature)
1184 "^/[^/]+/" (expand-file-name signature)))))
1186 (goto-char (point-max))
1187 (if (and mail-signature (search-backward "\n-- \n" nil t))
1189 ;; Delete any previous signatures.
1190 (if (search-backward "\n-- \n" nil t)
1191 (delete-region (point) (point-max)))
1192 (or (eolp) (insert "\n"))
1194 (if (file-exists-p signature)
1195 (insert-file-contents signature)
1197 (goto-char (point-max))
1198 (or (bolp) (insert "\n"))))))))
1200 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1201 (defun gnus-inews-insert-mime-headers ()
1202 (goto-char (point-min))
1203 (let ((mail-header-separator
1205 (goto-char (point-min))
1206 (if (and (search-forward (concat "\n" mail-header-separator "\n")
1208 (not (search-backward "\n\n" nil t)))
1209 mail-header-separator
1211 (or (mail-position-on-field "Mime-Version")
1214 (goto-char (point-min))
1215 (re-search-forward "[\200-\377]" nil t))
1216 (or (mail-position-on-field "Content-Type")
1217 (insert "text/plain; charset=ISO-8859-1"))
1218 (or (mail-position-on-field "Content-Transfer-Encoding")
1220 (t (or (mail-position-on-field "Content-Type")
1221 (insert "text/plain; charset=US-ASCII"))
1222 (or (mail-position-on-field "Content-Transfer-Encoding")
1223 (insert "7bit")))))))
1225 (defun gnus-inews-do-fcc ()
1226 "Process Fcc headers in the current buffer.
1227 Unless the first character of the field is `|', the article is saved
1228 to the specified file using the function specified by the variable
1229 gnus-author-copy-saver. The default function rmail-output saves in
1230 Unix mailbox format.
1232 If the first character is `|', the contents of the article is sent to
1233 a program specified by the rest of the value."
1234 (let ((case-fold-search t) ;Should ignore case.
1238 (gnus-narrow-to-headers)
1239 (while (setq file (mail-fetch-field "fcc"))
1241 (nnheader-remove-header "fcc" nil t))
1242 ;; Process FCC operations.
1245 (setq file (pop list))
1246 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
1247 ;; Pipe the article to the program in question.
1248 (call-process-region (point-min) (point-max) shell-file-name
1249 nil nil nil "-c" (match-string 1 file))
1250 ;; Save the article.
1251 (setq file (expand-file-name file))
1252 (gnus-make-directory (file-name-directory file))
1253 (if (and gnus-author-copy-saver
1254 (not (eq gnus-author-copy-saver 'rmail-output)))
1255 (funcall gnus-author-copy-saver file)
1256 (if (and (file-readable-p file) (mail-file-babyl-p file))
1257 (gnus-output-to-rmail file)
1258 (rmail-output file 1 t t)))))))))
1260 (defun gnus-inews-path ()
1262 (let ((login-name (gnus-inews-login-name)))
1263 (cond ((null gnus-use-generic-path)
1264 (concat (nth 1 gnus-select-method) "!" login-name))
1265 ((stringp gnus-use-generic-path)
1266 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1267 (concat gnus-use-generic-path "!" login-name))
1270 (defun gnus-inews-user-name ()
1271 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1272 (let ((full-name (gnus-inews-full-name))
1273 (address (if (or gnus-user-login-name gnus-use-generic-from
1274 gnus-local-domain (getenv "DOMAINNAME"))
1275 (concat (gnus-inews-login-name) "@"
1276 (gnus-inews-domain-name gnus-use-generic-from))
1277 user-mail-address)))
1278 (or gnus-user-from-line
1280 ;; User's full name.
1281 (cond ((string-equal full-name "&") ;Unix hack.
1282 (concat " (" (user-login-name) ")"))
1283 ((string-match "[^ ]+@[^ ]+ +(.*)" address)
1286 (concat " (" full-name ")")))))))
1288 (defun gnus-inews-real-user-address ()
1289 "Return the \"real\" user address.
1290 This function tries to ignore all user modifications, and
1291 give as trustworthy answer as possible."
1292 (concat (user-login-name) "@" (gnus-inews-full-address)))
1294 (defun gnus-inews-login-name ()
1295 "Return login name."
1296 (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1298 (defun gnus-inews-full-name ()
1299 "Return full user name."
1300 (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1302 (defun gnus-inews-domain-name (&optional genericfrom)
1303 "Return user's domain name.
1304 If optional argument GENERICFROM is a string, use it as the domain
1305 name; if it is non-nil, strip off local host name from the domain name.
1306 If the function `system-name' returns full internet name and the
1307 domain is undefined, the domain name is got from it."
1308 (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1309 (let* ((system-name (system-name))
1311 (or (if (stringp genericfrom) genericfrom)
1312 (getenv "DOMAINNAME")
1314 ;; Function `system-name' may return full internet name.
1315 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1316 (if (string-match "\\.." system-name)
1317 ;; Some machines return "name.", and that's not
1319 (substring system-name (1- (match-end 0))))
1320 (read-string "Domain name (no host): ")))
1321 (host (or (if (string-match "\\." system-name)
1322 (substring system-name 0 (match-beginning 0)))
1324 (if (string-equal "." (substring domain 0 1))
1325 (setq domain (substring domain 1)))
1326 ;; Support GENERICFROM as same as standard Bnews system.
1327 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1328 (cond ((null genericfrom)
1329 (concat host "." domain))
1330 ;;((stringp genericfrom) genericfrom)
1332 (if (string-match "\\." (system-name))
1334 (substring user-mail-address
1335 (1+ (string-match "@" user-mail-address))))))
1337 (defun gnus-inews-full-address ()
1338 (let ((domain (gnus-inews-domain-name))
1339 (system (system-name))
1340 (case-fold-search t))
1341 (if (string-match "\\." system) system
1342 (if (string-match (concat "^" (regexp-quote system)) domain) domain
1343 (concat system "." domain)))))
1345 (defun gnus-inews-message-id ()
1346 "Generate unique Message-ID for user."
1347 ;; Message-ID should not contain a slash and should be terminated by
1348 ;; a number. I don't know the reason why it is so.
1349 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1351 (defvar gnus-unique-id-char nil)
1353 ;; If you ever change this function, make sure the new version
1354 ;; cannot generate IDs that the old version could.
1355 ;; You might for example insert a "." somewhere (not next to another dot
1356 ;; or string boundary), or modify the newsreader name to "Ding".
1357 (defun gnus-inews-unique-id ()
1358 ;; Dont use microseconds from (current-time), they may be unsupported.
1359 ;; Instead we use this randomly inited counter.
1360 (setq gnus-unique-id-char
1361 (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1362 ;; (current-time) returns 16-bit ints,
1363 ;; and 2^16*25 just fits into 4 digits i base 36.
1365 (let ((tm (if (fboundp 'current-time)
1366 (current-time) '(12191 46742 287898))))
1368 (if (memq system-type '(ms-dos emx vax-vms))
1369 (let ((user (downcase (gnus-inews-login-name))))
1370 (while (string-match "[^a-z0-9_]" user)
1371 (aset user (match-beginning 0) ?_))
1373 (gnus-number-base36 (user-uid) -1))
1374 (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1375 (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1376 ;; Append the newsreader name, because while the generated
1377 ;; ID is unique to this newsreader, other newsreaders might
1378 ;; otherwise generate the same ID via another algorithm.
1382 (defun gnus-inews-date ()
1383 "Current time string."
1384 (timezone-make-date-arpa-standard
1385 (current-time-string) (current-time-zone)))
1387 (defun gnus-inews-organization ()
1388 "Return user's organization.
1389 The ORGANIZATION environment variable is used if defined.
1390 If not, the variable `gnus-local-organization' is used instead.
1391 If it is a function, the function will be called with the current
1392 newsgroup name as the argument.
1393 If this is a file name, the contents of this file will be used as the
1395 (let* ((organization
1396 (or (getenv "ORGANIZATION")
1397 (if gnus-local-organization
1398 (if (and (symbolp gnus-local-organization)
1399 (fboundp gnus-local-organization))
1400 (funcall gnus-local-organization gnus-newsgroup-name)
1401 gnus-local-organization))
1402 gnus-organization-file
1403 "~/.organization")))
1404 (and (stringp organization)
1405 (> (length organization) 0)
1406 (or (file-exists-p organization)
1407 (string-match " " organization)
1408 (not (string-match "^/usr/lib/\\|^~/" organization)))
1410 (gnus-set-work-buffer)
1411 (if (file-exists-p organization)
1412 (insert-file-contents organization)
1413 (insert organization))
1414 (goto-char (point-min))
1415 (while (re-search-forward " *\n *" nil t)
1416 (replace-match " " t t))
1417 (buffer-substring (point-min) (point-max))))))
1419 (defun gnus-inews-lines ()
1420 "Count the number of lines and return numeric string."
1424 (goto-char (point-min))
1426 (concat "^" (regexp-quote mail-header-separator) "$"))
1428 (int-to-string (count-lines (point) (point-max))))))
1430 (defun gnus-inews-in-reply-to ()
1431 "Return the In-Reply-To header for this message."
1436 ;;; Gnus Mail Functions
1439 ;;; Mail reply commands of Gnus summary mode
1441 (defun gnus-summary-reply (yank &optional yank-articles)
1442 "Reply mail to news author.
1443 If prefix argument YANK is non-nil, original article is yanked automatically.
1444 Customize the variable gnus-mail-reply-method to use another mailer."
1446 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1447 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1448 (gnus-set-global-variables)
1449 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1450 (gnus-summary-select-article)
1451 (bury-buffer gnus-article-buffer)
1452 (gnus-mail-reply (or yank-articles (not (not yank)))))
1454 (defun gnus-summary-reply-with-original (n)
1455 "Reply mail to news author with original article.
1456 Customize the variable gnus-mail-reply-method to use another mailer."
1458 (gnus-summary-reply t (gnus-summary-work-articles n)))
1460 (defun gnus-summary-mail-forward (post)
1461 "Forward the current message to another user.
1462 Customize the variable gnus-mail-forward-method to use another mailer."
1464 (gnus-set-global-variables)
1465 (gnus-summary-select-article)
1466 (gnus-copy-article-buffer)
1468 (gnus-forward-using-post gnus-article-copy)
1469 (gnus-mail-forward gnus-article-copy)))
1471 (defun gnus-summary-post-forward ()
1472 "Forward the current article to a newsgroup."
1474 (gnus-summary-mail-forward t))
1476 (defvar gnus-nastygram-message
1477 "The following article was inappropriately posted to %s.\n"
1478 "Format string to insert in nastygrams.
1479 The current group name will be inserted at \"%s\".")
1481 (defun gnus-summary-mail-nastygram (n)
1482 "Send a nastygram to the author of the current article."
1484 (if (or gnus-expert-user
1486 "Really send a nastygram to the author of the current article? "))
1487 (let ((group gnus-newsgroup-name))
1488 (gnus-summary-reply-with-original n)
1489 (set-buffer gnus-mail-buffer)
1490 (insert (format gnus-nastygram-message group))
1491 (gnus-mail-send-and-exit))))
1493 (defun gnus-summary-mail-other-window ()
1494 "Compose mail in other window.
1495 Customize the variable `gnus-mail-other-window-method' to use another
1498 (gnus-set-global-variables)
1501 (defun gnus-new-mail (&optional to)
1503 (when (and gnus-interactive-post
1504 (not gnus-expert-user))
1505 (setq subject (read-string "Subject: ")))
1506 (pop-to-buffer gnus-mail-buffer)
1508 (gnus-mail-setup 'new to subject)
1509 (run-hooks 'gnus-mail-hook)))
1511 (defun gnus-mail-reply (&optional yank to-address followup)
1513 (set-buffer gnus-summary-buffer)
1514 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1515 (cur (cons (current-buffer) (cdr gnus-article-current)))
1516 (winconf (current-window-configuration))
1517 from subject date reply-to message-of to cc
1518 references message-id sender follow-to sendto elt new-cc new-to
1520 (set-buffer (get-buffer-create gnus-mail-buffer))
1522 (if (and (buffer-modified-p)
1525 "Unsent message being composed; erase it? ")))
1529 (gnus-copy-article-buffer)
1531 (set-buffer gnus-article-copy)
1532 (gnus-narrow-to-headers)
1534 ;; This is a regular reply.
1535 (if (and (symbolp gnus-reply-to-function)
1536 (fboundp gnus-reply-to-function))
1537 (setq follow-to (funcall gnus-reply-to-function group)))
1538 ;; This is a followup.
1539 (if (and (symbolp gnus-followup-to-function)
1540 (fboundp gnus-followup-to-function))
1543 (funcall gnus-followup-to-function group)))))
1544 (setq from (mail-fetch-field "from"))
1545 (setq date (or (mail-fetch-field "date")
1546 (mail-header-date gnus-current-headers)))
1547 (setq message-of (gnus-message-of from date))
1548 (setq sender (mail-fetch-field "sender"))
1549 (setq subject (or (mail-fetch-field "subject") "none"))
1550 ;; Remove any (buggy) Re:'s that are present and make a
1552 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1553 (setq subject (substring subject (match-end 0))))
1554 (setq subject (concat "Re: " subject))
1555 (setq to (mail-fetch-field "to"))
1556 (setq cc (mail-fetch-field "cc"))
1557 (setq mct (mail-fetch-field "mail-copies-to"))
1558 (setq reply-to (mail-fetch-field "reply-to"))
1559 (setq references (mail-fetch-field "references"))
1560 (setq message-id (mail-fetch-field "message-id"))
1562 (setq mctdo (not (equal mct "never")))
1564 (if (not (and followup (not to-address)))
1565 (setq new-to (or reply-to from))
1568 (gnus-set-work-buffer)
1569 (unless (equal mct "never")
1570 (insert (or reply-to from "")))
1571 (insert (if (bolp) "" ", ")
1573 (if (or (not mct) (not mctdo)) ""
1574 (concat (if (bolp) "" ", ") mct))
1575 (if cc (concat (if (bolp) "" ", ") cc) ""))
1576 (goto-char (point-min))
1580 (cons (mail-strip-quoted-names addr) addr))
1581 (nreverse (mail-parse-comma-list))))
1584 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
1585 (setq new-to (cdr (pop ccalist)))
1588 (lambda (addr) (cdr addr))
1592 (setq news-reply-yank-from (or from "(nobody)"))
1593 (setq news-reply-yank-message-id
1594 (or message-id "(unknown Message-ID)"))
1596 ;; Gather the "to" addresses out of the follow-to list and remove
1598 (if (and follow-to (listp follow-to))
1599 (while (setq elt (assoc "To" follow-to))
1600 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1601 (setq follow-to (delq elt follow-to))))
1604 (if followup 'followup 'reply)
1606 (if (and follow-to (not (stringp follow-to))) sendto
1607 (or follow-to new-to sender "")))
1609 (if (zerop (length new-cc)) nil new-cc)
1612 (make-local-variable 'gnus-article-reply)
1613 (setq gnus-article-reply cur)
1614 (make-local-variable 'gnus-prev-winconf)
1615 (setq gnus-prev-winconf winconf)
1616 (make-local-variable 'gnus-reply-subject)
1617 (setq gnus-reply-subject subject)
1618 (make-local-variable 'gnus-in-reply-to)
1619 (setq gnus-in-reply-to message-of)
1621 (auto-save-mode auto-save-default)
1623 (if (and follow-to (listp follow-to))
1625 (goto-char (point-min))
1626 (re-search-forward "^To:" nil t)
1630 (insert (car (car follow-to)) ": " (cdr (car follow-to)) "\n")
1631 (setq follow-to (cdr follow-to)))))
1632 (nnheader-insert-references references message-id)
1634 ;; Now the headers should be ok, so we do the yanking.
1635 (goto-char (point-min))
1637 (concat "^" (regexp-quote mail-header-separator) "$"))
1640 (gnus-configure-windows 'reply 'force)
1641 (let ((last (point))
1643 (if (not (listp yank))
1646 (mail-yank-original nil))
1647 (or mail-yank-hooks mail-citation-hook
1648 (run-hooks 'news-reply-header-hook)))
1650 (save-window-excursion
1651 (set-buffer gnus-summary-buffer)
1652 (gnus-summary-select-article nil nil nil (car yank))
1653 (gnus-summary-remove-process-mark (car yank)))
1655 (gnus-copy-article-buffer)
1656 (mail-yank-original nil)
1658 (or mail-yank-hooks mail-citation-hook
1659 (run-hooks 'news-reply-header-hook))
1661 (setq yank (cdr yank))))
1664 (gnus-configure-windows 'reply-yank 'force))
1665 (run-hooks 'gnus-mail-hook)))))
1667 (defun gnus-new-news (&optional group inhibit-prompt)
1668 "Set up a *post-news* buffer that points to GROUP.
1669 If INHIBIT-PROMPT, never prompt for a Subject."
1670 (let ((winconf (current-window-configuration))
1672 (when (and gnus-interactive-post
1673 (not inhibit-prompt)
1674 (not gnus-expert-user))
1675 (setq subject (read-string "Subject: ")))
1676 (pop-to-buffer gnus-post-news-buffer)
1679 ;; Let posting styles be configured.
1680 (gnus-configure-posting-styles)
1681 (news-setup nil subject nil (and group (gnus-group-real-name group)) nil)
1682 (goto-char (point-min))
1684 (unless (re-search-forward
1685 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1686 (goto-char (point-max)))
1689 (gnus-inews-insert-bfcc)
1690 (gnus-inews-insert-signature)
1691 (and gnus-post-prepare-function
1692 (symbolp gnus-post-prepare-function)
1693 (fboundp gnus-post-prepare-function)
1694 (funcall gnus-post-prepare-function group))
1695 (goto-char (point-min))
1697 (re-search-forward "^Subject: " nil t)
1698 (re-search-forward "^Newsgroups: " nil t))
1699 (run-hooks 'gnus-post-prepare-hook)
1700 (make-local-variable 'gnus-prev-winconf)
1701 (setq gnus-prev-winconf winconf)
1702 (gnus-inews-modify-mail-mode-map)
1703 (local-set-key "\C-c\C-c" 'gnus-inews-news)))
1705 (defun gnus-news-followup (&optional yank group)
1707 (set-buffer gnus-summary-buffer)
1708 (if (not (or (not gnus-novice-user)
1711 "Are you sure you want to post to all of USENET? ")))
1713 (let ((group (gnus-group-real-name (or group gnus-newsgroup-name)))
1714 (cur (cons (current-buffer) (cdr gnus-article-current)))
1715 (winconf (current-window-configuration))
1716 from subject date reply-to message-of
1717 references message-id sender follow-to sendto elt
1718 followup-to distribution newsgroups)
1719 (set-buffer (get-buffer-create gnus-post-news-buffer))
1721 (if (and (buffer-modified-p)
1724 "Unsent message being composed; erase it? ")))
1728 (gnus-copy-article-buffer)
1730 (set-buffer gnus-article-copy)
1731 (gnus-narrow-to-headers)
1732 (if (and (symbolp gnus-followup-to-function)
1733 (fboundp gnus-followup-to-function))
1736 (funcall gnus-followup-to-function group))))
1737 (setq from (mail-fetch-field "from"))
1738 (setq date (or (mail-fetch-field "date")
1739 (mail-header-date gnus-current-headers)))
1740 (setq message-of (gnus-message-of from date))
1741 (setq subject (or (mail-fetch-field "subject") "none"))
1742 ;; Remove any (buggy) Re:'s that are present and make a
1744 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1745 (setq subject (substring subject (match-end 0))))
1746 (setq subject (concat "Re: " subject))
1747 (setq references (mail-fetch-field "references"))
1748 (setq message-id (mail-fetch-field "message-id"))
1749 (setq followup-to (mail-fetch-field "followup-to"))
1750 (setq newsgroups (mail-fetch-field "newsgroups"))
1751 (setq distribution (mail-fetch-field "distribution"))
1752 ;; Remove bogus distribution.
1753 (and (stringp distribution)
1754 (string-match "world" distribution)
1755 (setq distribution nil))
1758 (setq news-reply-yank-from (or from "(nobody)"))
1759 (setq news-reply-yank-message-id
1760 (or message-id "(unknown Message-ID)"))
1762 ;; Gather the "to" addresses out of the follow-to list and remove
1764 (if (and follow-to (listp follow-to))
1765 (while (setq elt (assoc "Newsgroups" follow-to))
1766 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1767 (setq follow-to (delq elt follow-to))))
1769 ;; Let posting styles be configured.
1770 (gnus-configure-posting-styles)
1772 (news-setup nil subject nil
1775 gnus-use-followup-to
1776 (or (not (eq gnus-use-followup-to 'ask))
1779 "Use Followup-To %s? " followup-to)))
1781 newsgroups group "")
1784 (make-local-variable 'gnus-article-reply)
1785 (setq gnus-article-reply cur)
1786 (make-local-variable 'gnus-prev-winconf)
1787 (setq gnus-prev-winconf winconf)
1788 (make-local-variable 'gnus-reply-subject)
1789 (setq gnus-reply-subject (mail-header-subject gnus-current-headers))
1790 (make-local-variable 'gnus-in-reply-to)
1791 (setq gnus-in-reply-to message-of)
1793 (gnus-inews-insert-signature)
1795 (and gnus-post-prepare-function
1796 (symbolp gnus-post-prepare-function)
1797 (fboundp gnus-post-prepare-function)
1798 (funcall gnus-post-prepare-function group))
1799 (run-hooks 'gnus-post-prepare-hook)
1801 (auto-save-mode auto-save-default)
1802 (gnus-inews-modify-mail-mode-map)
1803 (local-set-key "\C-c\C-c" 'gnus-inews-news)
1805 (if (and follow-to (listp follow-to))
1807 (goto-char (point-min))
1808 (and (re-search-forward "^Newsgroups:" nil t)
1811 (insert (car (car follow-to)) ": "
1812 (cdr (car follow-to)) "\n")
1813 (setq follow-to (cdr follow-to)))))
1815 ;; If a distribution existed, we use it.
1818 (mail-position-on-field "Distribution")
1819 (insert distribution)))
1821 (nnheader-insert-references references message-id)
1823 ;; Handle `gnus-auto-mail-to-author'.
1824 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
1825 ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
1826 (let ((to (if (if (eq gnus-auto-mail-to-author 'ask)
1827 (y-or-n-p "Also send mail to author? ")
1828 gnus-auto-mail-to-author)
1830 (set-buffer gnus-article-copy)
1831 (gnus-fetch-field "reply-to"))
1833 (x-mail (save-excursion
1834 (set-buffer gnus-article-copy)
1835 (gnus-fetch-field "x-mail-copy-to"))))
1836 ;; Deny sending copy if there's a negative X-Mail-Copy-To
1839 (if (and (string= x-mail "never")
1840 (not (eq gnus-auto-mail-to-author 'force)))
1843 ;; Insert a To or Cc header.
1845 (if (mail-fetch-field "To")
1848 (insert "Cc: " to "\n"))
1849 (mail-position-on-field "To")
1852 (gnus-inews-insert-bfcc)
1854 ;; Now the headers should be ok, so we do the yanking.
1855 (goto-char (point-min))
1857 (concat "^" (regexp-quote mail-header-separator) "$"))
1861 (gnus-configure-windows 'followup 'force)
1864 (let ((last (point))
1866 (if (not (listp yank))
1869 (mail-yank-original nil))
1870 (or mail-yank-hooks mail-citation-hook
1871 (run-hooks 'news-reply-header-hook)))
1873 (save-window-excursion
1874 (set-buffer gnus-summary-buffer)
1875 (gnus-summary-select-article nil nil nil (car yank))
1876 (gnus-summary-remove-process-mark (car yank)))
1878 (gnus-copy-article-buffer)
1879 (mail-yank-original nil)
1881 (or mail-yank-hooks mail-citation-hook
1882 (run-hooks 'news-reply-header-hook))
1884 (setq yank (cdr yank))))
1886 (gnus-configure-windows 'followup-yank 'force))
1888 (make-local-variable 'gnus-article-check-size)
1889 (setq gnus-article-check-size
1890 (cons (buffer-size) (gnus-article-checksum))))))))
1892 (defun gnus-message-of (from date)
1893 "Take a FROM and a DATE and create an IN-REPLY-TO."
1899 (string-match " *at \\| *@ \\| *(\\| *<" from)))
1900 (concat (if stop-pos (substring from 0 stop-pos) from)
1902 (if (or (not date) (string= date ""))
1903 "(unknown date)" date))))))
1905 (defun gnus-mail-yank-original ()
1908 (mail-yank-original nil))
1909 (or mail-yank-hooks mail-citation-hook
1910 (run-hooks 'news-reply-header-hook)))
1912 (defun gnus-mail-send-and-exit (&optional dont-send)
1913 "Send the current mail and return to Gnus."
1915 (let* ((reply gnus-article-reply)
1916 (winconf gnus-prev-winconf)
1917 (address-group gnus-add-to-address)
1918 (to-address (and address-group
1919 (mail-fetch-field "to"))))
1920 (setq gnus-add-to-address nil)
1921 (or dont-send (gnus-mail-send))
1923 ;; This mail group doesn't have a `to-address', so we add one
1926 (gnus-group-add-parameter
1927 address-group (cons 'to-address to-address)))
1928 (if (get-buffer gnus-group-buffer)
1930 (if (gnus-buffer-exists-p (car-safe reply))
1932 (set-buffer (car reply))
1934 (gnus-summary-mark-article-as-replied
1936 (and winconf (set-window-configuration winconf))))))
1938 (defun gnus-put-message ()
1939 "Put the current message in some group and return to Gnus."
1941 (let ((reply gnus-article-reply)
1942 (winconf gnus-prev-winconf)
1943 (group gnus-newsgroup-name)
1946 (or (and group (not (gnus-group-read-only-p group)))
1947 (setq group (read-string "Put in group: " nil
1948 (gnus-writable-groups))))
1949 (and (gnus-gethash group gnus-newsrc-hashtb)
1950 (error "No such group: %s" group))
1955 (gnus-inews-narrow-to-headers)
1956 (let (gnus-deletable-headers)
1957 (if (eq major-mode 'mail-mode)
1958 (gnus-inews-insert-headers gnus-required-mail-headers)
1959 (gnus-inews-insert-headers)))
1960 (goto-char (point-max))
1961 (insert "Gcc: " group "\n")
1966 (if (get-buffer gnus-group-buffer)
1968 (if (gnus-buffer-exists-p (car-safe reply))
1970 (set-buffer (car reply))
1972 (gnus-summary-mark-article-as-replied
1974 (and winconf (set-window-configuration winconf))))))
1977 (defun gnus-forward-make-subject (buffer)
1980 (concat "[" (if (memq 'mail (assoc (symbol-name
1981 (car (gnus-find-method-for-group
1982 gnus-newsgroup-name)))
1983 gnus-valid-select-methods))
1984 (gnus-fetch-field "From")
1985 gnus-newsgroup-name)
1986 "] " (or (gnus-fetch-field "Subject") ""))))
1988 (defun gnus-forward-insert-buffer (buffer)
1989 (let ((beg (goto-char (point-max))))
1990 (insert "------- Start of forwarded message -------\n")
1991 (insert-buffer-substring buffer)
1992 (goto-char (point-max))
1993 (insert "------- End of forwarded message -------\n")
1994 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
1996 (while (setq beg (next-single-property-change (point) 'invisible))
1998 (delete-region beg (or (next-single-property-change
2002 (defun gnus-mail-forward (&optional buffer)
2003 "Forward the current message to another user using mail."
2004 (let* ((forward-buffer (or buffer (current-buffer)))
2005 (winconf (current-window-configuration))
2006 (subject (gnus-forward-make-subject forward-buffer)))
2007 (set-buffer (get-buffer-create gnus-mail-buffer))
2008 (if (and (buffer-modified-p)
2011 "Unsent message being composed; erase it? ")))
2014 (gnus-mail-setup 'forward nil subject)
2015 (make-local-variable 'gnus-prev-winconf)
2016 (setq gnus-prev-winconf winconf)
2017 (gnus-forward-insert-buffer forward-buffer)
2018 (goto-char (point-min))
2019 (re-search-forward "^To: ?" nil t)
2020 (gnus-configure-windows 'mail-forward 'force)
2021 ;; You have a chance to arrange the message.
2022 (run-hooks 'gnus-mail-forward-hook)
2023 (run-hooks 'gnus-mail-hook))))
2025 (defun gnus-forward-using-post (&optional buffer)
2027 (let* ((forward-buffer (or buffer (current-buffer)))
2028 (subject (gnus-forward-make-subject forward-buffer))
2029 (gnus-newsgroup-name nil))
2030 (gnus-post-news 'post nil nil nil nil subject)
2032 (gnus-forward-insert-buffer forward-buffer)
2033 ;; You have a chance to arrange the message.
2034 (run-hooks 'gnus-mail-forward-hook)))))
2036 (defun gnus-mail-other-window-using-mail ()
2037 "Compose mail other window using mail."
2038 (let ((winconf (current-window-configuration)))
2039 (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
2040 (gnus-inews-modify-mail-mode-map)
2041 (make-local-variable 'gnus-prev-winconf)
2042 (setq gnus-prev-winconf winconf)
2043 (run-hooks 'gnus-mail-hook)
2044 (gnus-configure-windows 'summary-mail 'force)))
2046 (defun gnus-article-mail (yank)
2047 "Send a reply to the address near point.
2048 If YANK is non-nil, include the original article."
2052 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
2053 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
2056 (switch-to-buffer gnus-summary-buffer)
2057 (gnus-mail-reply yank address)))))
2060 "Send a bug report to the Gnus maintainers."
2062 (let ((winconf (current-window-configuration)))
2063 (delete-other-windows)
2064 (switch-to-buffer "*Gnus Help Bug*")
2066 (insert gnus-bug-message)
2067 (goto-char (point-min))
2068 (pop-to-buffer "*Gnus Bug*")
2071 (mail-setup gnus-maintainer nil nil nil nil nil)
2072 (auto-save-mode auto-save-default)
2073 (make-local-variable 'gnus-prev-winconf)
2074 (setq gnus-prev-winconf winconf)
2075 (gnus-inews-modify-mail-mode-map)
2076 (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
2077 (goto-char (point-min))
2078 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2080 (insert (format "%s\n%s\n\n\n\n\n" (gnus-version) (emacs-version)))
2082 (goto-char (point-min))
2083 (search-forward "Subject: " nil t)
2086 (defun gnus-bug-mail-send-and-exit ()
2087 "Send the bug message and exit."
2089 (and (get-buffer "*Gnus Help Bug*")
2090 (kill-buffer "*Gnus Help Bug*"))
2091 (gnus-mail-send-and-exit))
2093 (defun gnus-debug ()
2094 "Attemps to go through the Gnus source file and report what variables have been changed.
2095 The source file has to be in the Emacs load path."
2097 (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el"))
2098 file dirs expr olist sym)
2099 (message "Please wait while we snoop your variables...")
2102 (set-buffer (get-buffer-create " *gnus bug info*"))
2103 (buffer-disable-undo (current-buffer))
2106 (setq dirs load-path)
2108 (if (or (not (car dirs))
2109 (not (stringp (car dirs)))
2111 (setq file (concat (file-name-as-directory
2112 (car dirs)) (car files))))))
2113 (setq dirs (cdr dirs))
2115 (insert-file-contents file)
2116 (goto-char (point-min))
2117 (or (re-search-forward "^;;* *Internal variables" nil t)
2118 (error "Malformed sources in file %s" file))
2119 (narrow-to-region (point-min) (point))
2120 (goto-char (point-min))
2121 (while (setq expr (condition-case ()
2122 (read (current-buffer)) (error nil)))
2124 (and (eq (car expr) 'defvar)
2125 (stringp (nth 3 expr))
2126 (or (not (boundp (nth 1 expr)))
2127 (not (equal (eval (nth 2 expr))
2128 (symbol-value (nth 1 expr)))))
2129 (setq olist (cons (nth 1 expr) olist)))
2131 (setq files (cdr files)))
2132 (kill-buffer (current-buffer)))
2133 (insert "------------------- Environment follows -------------------\n\n")
2135 (if (boundp (car olist))
2136 (insert "(setq " (symbol-name (car olist))
2137 (if (or (consp (setq sym (symbol-value (car olist))))
2139 (not (or (eq sym nil)
2142 (prin1-to-string (symbol-value (car olist))) ")\n")
2143 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
2144 (setq olist (cdr olist)))
2146 ;; Remove any null chars - they seem to cause trouble for some
2147 ;; mailers. (Byte-compiled output from the stuff above.)
2148 (goto-char (point-min))
2149 (while (re-search-forward "[\000\200]" nil t)
2150 (replace-match "" t t))))
2153 ;;; Treatment of rejected articles.
2158 (defun gnus-summary-resend-bounced-mail (fetch)
2159 "Re-mail the current message.
2160 This only makes sense if the current message is a bounce message than
2161 contains some mail you have written which has been bounced back to
2163 If FETCH, try to fetch the article that this is a reply to, if indeed
2166 (gnus-summary-select-article t)
2167 ;; Create a mail buffer.
2170 (insert-buffer-substring gnus-article-buffer)
2171 (goto-char (point-min))
2172 (search-forward "\n\n")
2173 ;; We remove everything before the bounced mail.
2176 (if (re-search-forward "[^ \t]*:" nil t)
2182 (gnus-narrow-to-headers)
2183 (nnheader-remove-header gnus-bounced-headers-junk t)
2184 (setq references (mail-fetch-field "references"))
2185 (goto-char (point-max))
2186 (insert mail-header-separator)))
2187 ;; If there are references, we fetch the article we answered to.
2190 (string-match "\\(<[^]+>\\)[ \t]*$" references)
2191 (gnus-summary-refer-article
2192 (substring references (match-beginning 1) (match-end 1)))
2194 (gnus-summary-show-all-headers)
2195 (gnus-configure-windows 'compose-bounce))))
2196 (goto-char (point-min)))
2200 (defun gnus-mail-send ()
2201 "Send the current buffer as mail.
2202 Headers will be generated before sending."
2207 (gnus-inews-narrow-to-headers)
2208 (gnus-inews-insert-headers gnus-required-mail-headers)
2209 (gnus-inews-remove-empty-headers)))
2211 ;; Remove the header separator.
2212 (goto-char (point-min))
2213 (and (re-search-forward
2214 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2215 (replace-match "" t t))
2216 ;; Run final inews hooks. This hook may do FCC.
2217 (run-hooks 'gnus-inews-article-hook)
2219 (gnus-narrow-to-headers)
2220 (nnheader-remove-header "^[gf]cc:" t)
2222 (goto-char (point-min))
2223 (search-forward "\n\n")
2225 (insert mail-header-separator)
2227 (run-hooks 'gnus-message-sent-hook))
2229 (defun gnus-inews-modify-mail-mode-map ()
2230 (use-local-map (copy-keymap (current-local-map)))
2231 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
2232 (local-set-key "\C-c\C-p" 'gnus-put-message)
2233 (local-set-key "\C-c\C-d" 'gnus-enter-into-draft-group))
2235 (defun gnus-mail-setup (type &optional to subject in-reply-to cc
2236 replybuffer actions)
2237 ;; Let posting styles be configured.
2238 (gnus-configure-posting-styles)
2242 (and (or (eq type 'reply) (eq type 'followup))
2243 (eq gnus-mail-reply-method 'gnus-mail-reply-using-mhe))
2244 (and (eq type 'forward)
2245 (eq gnus-mail-forward-method 'gnus-mail-forward-using-mhe))
2247 (eq gnus-mail-other-window-method
2248 'gnus-mail-other-window-using-mhe)))
2249 'gnus-mh-mail-setup)
2251 (and (or (eq type 'reply) (eq type 'followup))
2252 (eq gnus-mail-reply-method 'gnus-mail-reply-using-vm))
2253 (and (eq type 'forward)
2254 (eq gnus-mail-forward-method 'gnus-mail-forward-using-vm))
2256 (eq gnus-mail-other-window-method
2257 'gnus-mail-other-window-using-vm)))
2258 'gnus-vm-mail-setup)
2259 (t 'gnus-sendmail-mail-setup))
2260 to subject in-reply-to cc replybuffer actions))
2262 (defun gnus-sendmail-mail-setup (to subject in-reply-to cc replybuffer actions)
2264 (mail-setup to subject nil cc replybuffer actions)
2265 (goto-char (point-min))
2266 (if (re-search-forward
2267 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2269 (goto-char (point-max)))
2271 (gnus-inews-modify-mail-mode-map))
2275 ;; Do Gcc handling, which copied the message over to some group.
2276 (defun gnus-inews-do-gcc (&optional gcc)
2279 (gnus-narrow-to-headers)
2280 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
2283 () ; Nothing to be done.
2284 (nnheader-remove-header "gcc")
2285 ;; Copy the article over to some group(s).
2286 (while (string-match
2287 "^[ \t]*\\([^ \t]+\\)\\([ \t]+\\|$\\)" gcc)
2288 (setq end (match-end 0))
2290 (gnus-request-accept-article
2291 (substring gcc (match-beginning 1) (match-end 1)) t)
2293 (setq gcc (substring gcc end))))))))
2295 (defun gnus-inews-insert-bfcc ()
2296 "Insert Bcc and Fcc headers."
2298 ;; Handle author copy using BCC field.
2299 (when (and gnus-mail-self-blind
2300 (not (mail-fetch-field "bcc")))
2301 (mail-position-on-field "Bcc")
2302 (insert (if (stringp gnus-mail-self-blind)
2303 gnus-mail-self-blind
2304 (user-login-name))))
2305 ;; Handle author copy using FCC field.
2306 (when gnus-author-copy
2307 (mail-position-on-field "Fcc")
2308 (insert gnus-author-copy))))
2310 (defun gnus-inews-insert-gcc ()
2311 (let* ((group gnus-outgoing-message-group)
2313 ((and (symbolp group) (fboundp group))
2315 ((or (stringp group) (list group))
2319 (if (stringp group) group
2320 (mapconcat 'identity group " "))
2323 ;;; Handling rejected (and postponed) news.
2325 (defun gnus-draft-group ()
2326 "Return the name of the draft group."
2327 (gnus-group-prefixed-name
2328 (file-name-nondirectory gnus-draft-group-directory)
2329 (list 'nndir gnus-draft-group-directory)))
2331 (defun gnus-make-draft-group ()
2332 "Make the draft group or die trying."
2333 (let* ((method (` (nndir "private"
2334 (nndir-directory (, gnus-draft-group-directory)))))
2335 (group (gnus-group-prefixed-name
2336 (file-name-nondirectory gnus-draft-group-directory)
2338 (or (gnus-gethash group gnus-newsrc-hashtb)
2339 (gnus-group-make-group (gnus-group-real-name group) method)
2340 (error "Can't create the draft group"))
2343 (defun gnus-enter-into-draft-group ()
2344 "Enter the current buffer into the draft group."
2346 (gnus-put-in-draft-group t))
2348 (defun gnus-put-in-draft-group (&optional generate silent)
2349 "Does the actual putting."
2350 (let ((group (gnus-make-draft-group))
2351 (type (list major-mode (buffer-name) gnus-newsgroup-name
2354 (buf (current-buffer)))
2357 (nnheader-set-temp-buffer " *enter-draft*")
2358 (insert-buffer-substring buf)
2361 (gnus-inews-narrow-to-headers)
2362 (let (gnus-deletable-headers)
2363 (if (eq mode 'mail-mode)
2364 (gnus-inews-insert-headers gnus-required-mail-headers)
2365 (gnus-inews-insert-headers)))
2368 (goto-char (point-min))
2369 ;; We have to store whether we are in a mail group or news group.
2370 (insert (format "X-Gnus-Draft-Type: %S\n" type))
2371 (and (re-search-forward
2372 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2373 (replace-match "" t t))
2375 (gnus-request-accept-article group t)
2376 (kill-buffer (current-buffer)))
2378 (gnus-mail-send-and-exit 'dont-send))))
2379 (set-buffer-modified-p nil)))
2381 (defun gnus-summary-send-draft ()
2382 "Enter a mail/post buffer to edit and send the draft."
2384 (gnus-set-global-variables)
2385 (gnus-summary-select-article t)
2386 ;; First we find the draft type.
2389 (set-buffer gnus-article-buffer)
2391 (gnus-narrow-to-headers)
2392 (setq type (condition-case ()
2393 (read (mail-fetch-field "x-gnus-draft-type"))
2397 (error "Unknown draft type"))
2398 ;; Get to the proper buffer.
2399 (set-buffer (get-buffer-create (nth 1 type)))
2400 ;; It might be modified.
2401 (and (buffer-modified-p)
2402 (or (gnus-yes-or-no-p "Unsent message being composed; discard it? ")
2404 (setq buffer-read-only nil)
2405 (buffer-enable-undo (current-buffer))
2408 (funcall (car type))
2409 (and (eq major-mode 'mail-mode)
2410 (gnus-inews-modify-mail-mode-map))
2411 ;; Arrange for deletion of the draft after successful sending.
2412 (make-local-variable 'gnus-message-sent-hook)
2413 (setq gnus-message-sent-hook
2417 (gnus-request-expire-articles
2418 (quote (, (list (cdr gnus-article-current))))
2419 (, gnus-newsgroup-name) t)))))
2420 ;; Insert the draft.
2421 (insert-buffer-substring gnus-article-buffer)
2422 ;; Insert the separator.
2423 (goto-char (point-min))
2424 (search-forward "\n\n")
2426 (insert mail-header-separator)
2427 ;; Remove the draft header.
2428 (gnus-inews-narrow-to-headers)
2429 (nnheader-remove-header "x-gnus-draft-type")
2431 ;; Configure windows.
2432 (let ((gnus-draft-buffer (current-buffer)))
2433 (gnus-configure-windows 'draft))
2434 ;; Put point where you left it.
2435 (goto-char (nth 3 type))))
2437 (defun gnus-configure-posting-styles ()
2438 "Configure posting styles according to `gnus-posting-styles'."
2439 (let ((styles gnus-posting-styles)
2440 (gnus-newsgroup-name (or gnus-newsgroup-name ""))
2441 style match variable attribute value value-value)
2442 ;; Go through all styles and look for matches.
2444 (setq style (pop styles)
2446 (when (cond ((stringp match)
2447 ;; Regexp string match on the group name.
2448 (string-match match gnus-newsgroup-name))
2450 (cond ((fboundp match)
2451 ;; Function to be called.
2454 ;; Variable to be checked.
2455 (symbol-value match))))
2457 ;; This is a form to be evaled.
2459 ;; We have a match, so we set the variables.
2461 (setq attribute (pop style)
2462 value (cdr attribute))
2463 ;; We find the variable that is to be modified.
2464 (if (and (not (stringp (car attribute)))
2465 (not (setq variable (cdr (assq (car attribute)
2466 gnus-posting-style-alist)))))
2467 (message "Couldn't find attribute %s" (car attribute))
2468 ;; We set the variable.
2470 (cond ((stringp value)
2473 (cond ((fboundp value)
2476 (symbol-value value))))
2481 ;; This is an ordinary variable.
2482 (make-local-variable variable)
2483 (set variable value-value))
2484 ;; This is a header to be added to the headers when
2487 (make-local-variable gnus-required-headers)
2488 (make-local-variable gnus-required-mail-headers)
2489 (push (cons (car attribute) value-value)
2490 gnus-required-headers)
2491 (push (cons (car attribute) value-value)
2492 gnus-required-mail-headers)))))))))
2494 ;;; Allow redefinition of functions.
2500 ;;; gnus-msg.el ends here