1 ;;; gnus-msg.el --- mail and post interface for Gnus
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
34 (defvar gnus-organization-file
"/usr/lib/news/organization"
35 "*Local news organization file.")
37 (defvar gnus-prepare-article-hook
(list 'gnus-inews-insert-signature
)
38 "*A hook called after preparing body, but before preparing header headers.
39 The default hook (`gnus-inews-insert-signature') inserts a signature
40 file specified by the variable `gnus-signature-file'.")
42 (defvar gnus-post-prepare-function nil
43 "*Function that is run after a post buffer has been prepared.
44 It is called with the name of the newsgroup that is posted to. It
45 might be used, for instance, for inserting signatures based on the
46 newsgroup name. (In that case, `gnus-signature-file' and
47 `mail-signature' should both be set to nil).")
49 (defvar gnus-post-prepare-hook nil
50 "*Hook that is run after a post buffer has been prepared.
51 If you want to insert the signature, you might put
52 `gnus-inews-insert-signature' in this hook.")
54 (defvar gnus-use-followup-to t
55 "*Specifies what to do with Followup-To header.
56 If nil, ignore the header. If it is t, use its value, but ignore
57 `poster'. If it is the symbol `ask', query the user before posting.
58 If it is the symbol `use', always use the value.")
60 (defvar gnus-followup-to-function nil
61 "*A variable that contains a function that returns a followup address.
62 The function will be called in the buffer of the article that is being
63 followed up. The buffer will be narrowed to the headers of the
64 article. To pick header headers, one might use `mail-fetch-field'. The
65 function will be called with the name of the current newsgroup as the
68 Here's an example `gnus-followup-to-function':
70 (setq gnus-followup-to-function
72 (cond ((string= group \"mail.list\")
73 (or (mail-fetch-field \"sender\")
74 (mail-fetch-field \"from\")))
76 (or (mail-fetch-field \"reply-to\")
77 (mail-fetch-field \"from\"))))))")
79 (defvar gnus-reply-to-function nil
80 "*A variable that contains a function that returns a reply address.
81 See the `gnus-followup-to-function' variable for an explanation of how
82 this variable is used.
84 This function should return a string that will be used to fill in the
85 header. This function may also return a list. In that case, every
86 list element should be a cons where the first car should be a string
87 with the header name, and the cdr should be a string with the header
90 (defvar gnus-author-copy
(getenv "AUTHORCOPY")
91 "*Save outgoing articles in this file.
92 Initialized from the AUTHORCOPY environment variable.
94 If this variable begins with the character \"|\", outgoing articles
95 will be piped to the named program. It is possible to save an article
96 in an MH folder as follows:
98 \(setq gnus-author-copy \"|/usr/local/lib/mh/rcvstore +Article\")
100 If the first character is not a pipe, articles are saved using the
101 function specified by the `gnus-author-copy-saver' variable.")
103 (defvar gnus-mail-self-blind nil
104 "*Non-nil means insert a BCC header in all outgoing articles.
105 This will result in having a copy of the article mailed to yourself.
106 The BCC header is inserted when the post buffer is initialized, so you
107 can remove or alter the BCC header to override the default.")
109 (defvar gnus-author-copy-saver
(function rmail-output
)
110 "*A function called to save outgoing articles.
111 This function will be called with the same of the file to store the
112 article in. The default function is `rmail-output' which saves in Unix
115 (defvar gnus-user-login-name nil
116 "*The login name of the user.
117 Got from the function `user-login-name' if undefined.")
119 (defvar gnus-user-full-name nil
120 "*The full name of the user.
121 Got from the NAME environment variable if undefined.")
123 (defvar gnus-user-from-line nil
124 "*Your full, complete e-mail address.
125 Overrides the other Gnus variables if it is non-nil.
127 Here are two example values of this variable:
129 \"Lars Magne Ingebrigtsen <larsi@ifi.uio.no>\"
133 \"larsi@ifi.uio.no (Lars Magne Ingebrigtsen)\"
135 The first version is recommended, but the name has to be quoted if it
136 contains non-alphanumerical characters.")
138 (defvar gnus-signature-file
"~/.signature"
139 "*Your signature file.
140 If the variable is a string that doesn't correspond to a file, the
141 string itself is inserted.")
143 (defvar gnus-signature-function nil
144 "*A function that should return a signature file name.
145 The function will be called with the name of the newsgroup being
147 If the function returns a string that doesn't correspond to a file, the
148 string itself is inserted.
149 If the function returns nil, the `gnus-signature-file' variable will
152 (defvar gnus-required-headers
153 '(From Date Newsgroups Subject Message-ID Organization Lines X-Newsreader
)
154 "*Headers to be generated or prompted for when posting an article.
155 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
156 Message-ID. Organization, Lines and X-Newsreader are optional. If
157 you want Gnus not to insert some header, remove it from this list.")
159 (defvar gnus-deletable-headers
'(Message-ID Date
)
160 "*Headers to be deleted if they already exists and were generated by Gnus previously.")
162 (defvar gnus-removable-headers
'(NNTP-Posting-Host Bcc Xref
)
163 "*Headers to be removed unconditionally before posting.")
165 (defvar gnus-check-before-posting
166 '(subject-cmsg multiple-headers sendsys message-id from
167 long-lines control-chars size new-text
169 "In non-nil, Gnus will attempt to run some checks on outgoing posts.
170 If this variable is t, Gnus will check everything it can. If it is a
171 list, then those elements in that list will be checked.")
173 (defvar gnus-delete-supersedes-headers
174 "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Supersedes:"
175 "*Header lines matching this regexp will be deleted before posting.
176 It's best to delete old Path and Date headers before posting to avoid
179 (defvar gnus-auto-mail-to-author nil
180 "*If non-nil, mail the authors of articles a copy of your follow-ups.
181 If this variable is `ask', the user will be prompted for whether to
182 mail a copy. The string given by `gnus-mail-courtesy-message' will be
183 inserted at the beginning of the mail copy.
185 Mail is sent using the function specified by the
186 `gnus-mail-send-method' variable.")
188 ;; Added by Ethan Bradford <ethanb@ptolemy.astro.washington.edu>.
189 (defvar gnus-mail-courtesy-message
190 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
191 "*This is inserted at the start of a mailed copy of a posted message.
192 If this variable is nil, no such courtesy message will be added.")
194 (defvar gnus-mail-reply-method
(function gnus-mail-reply-using-mail
)
195 "*Function to compose a reply.
196 Three pre-made functions are `gnus-mail-reply-using-mail' (sendmail);
197 `gnus-mail-reply-using-mhe' (MH-E); and `gnus-mail-reply-using-vm'.")
199 (defvar gnus-mail-forward-method
(function gnus-mail-forward-using-mail
)
200 "*Function to forward the current message to another user.
201 Three pre-made functions are `gnus-mail-forward-using-mail' (sendmail);
202 `gnus-mail-forward-using-mhe' (MH-E); and `gnus-mail-forward-using-vm'.")
204 (defvar gnus-mail-other-window-method
'gnus-mail-other-window-using-mail
205 "*Function to compose mail in the other window.
206 Three pre-made functions are `gnus-mail-other-window-using-mail'
207 (sendmail); `gnus-mail-other-window-using-mhe' (MH-E); and
208 `gnus-mail-other-window-using-vm'.")
210 (defvar gnus-mail-send-method send-mail-function
211 "*Function to mail a message which is also being posted as an article.
212 The message must have To or Cc header. The default is copied from
213 the variable `send-mail-function'.")
215 (defvar gnus-inews-article-function
'gnus-inews-article
216 "*Function to post an article.")
218 (defvar gnus-inews-article-hook
(list 'gnus-inews-do-fcc
)
219 "*A hook called before finally posting an article.
220 The default hook (`gnus-inews-do-fcc') does FCC processing (ie. saves
221 the article to a file).")
223 (defvar gnus-inews-article-header-hook nil
224 "*A hook called after inserting the headers in an article to be posted.
225 The hook is called from the *post-news* buffer, narrowed to the
228 (defvar gnus-mail-hook nil
229 "*A hook called as the last thing after setting up a mail buffer.")
231 ;;; Internal variables.
233 (defvar gnus-post-news-buffer
"*post-news*")
234 (defvar gnus-mail-buffer
"*mail*")
235 (defvar gnus-summary-send-map nil
)
236 (defvar gnus-article-copy nil
)
237 (defvar gnus-reply-subject nil
)
240 (autoload 'gnus-uu-post-news
"gnus-uu" nil t
)
241 (autoload 'rmail-output
"rmailout"))
245 ;;; Gnus Posting Functions
248 (define-prefix-command 'gnus-summary-send-map
)
249 (define-key gnus-summary-mode-map
"S" 'gnus-summary-send-map
)
250 (define-key gnus-summary-send-map
"p" 'gnus-summary-post-news
)
251 (define-key gnus-summary-send-map
"f" 'gnus-summary-followup
)
252 (define-key gnus-summary-send-map
"F" 'gnus-summary-followup-with-original
)
253 (define-key gnus-summary-send-map
"b" 'gnus-summary-followup-and-reply
)
254 (define-key gnus-summary-send-map
"B" 'gnus-summary-followup-and-reply-with-original
)
255 (define-key gnus-summary-send-map
"c" 'gnus-summary-cancel-article
)
256 (define-key gnus-summary-send-map
"s" 'gnus-summary-supersede-article
)
257 (define-key gnus-summary-send-map
"r" 'gnus-summary-reply
)
258 (define-key gnus-summary-send-map
"R" 'gnus-summary-reply-with-original
)
259 (define-key gnus-summary-send-map
"m" 'gnus-summary-mail-other-window
)
260 (define-key gnus-summary-send-map
"u" 'gnus-uu-post-news
)
261 (define-key gnus-summary-send-map
"om" 'gnus-summary-mail-forward
)
262 (define-key gnus-summary-send-map
"op" 'gnus-summary-post-forward
)
263 (define-key gnus-summary-send-map
"Om" 'gnus-uu-digest-mail-forward
)
264 (define-key gnus-summary-send-map
"Op" 'gnus-uu-digest-post-forward
)
266 ;;; Internal functions.
268 (defun gnus-number-base36 (num len
)
269 (if (if (< len
0) (<= num
0) (= len
0))
271 (concat (gnus-number-base36 (/ num
36) (1- len
))
272 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
275 ;;; Post news commands of Gnus group mode and summary mode
277 (defun gnus-group-mail ()
278 "Start composing a mail."
280 (funcall gnus-mail-other-window-method
))
282 (defun gnus-group-post-news ()
285 (let ((gnus-newsgroup-name nil
))
286 (gnus-post-news 'post nil nil gnus-article-buffer
)))
288 (defun gnus-summary-post-news ()
291 (gnus-set-global-variables)
292 (gnus-post-news 'post gnus-newsgroup-name
))
294 (defun gnus-summary-followup (yank &optional yank-articles
)
295 "Compose a followup to an article.
296 If prefix argument YANK is non-nil, original article is yanked automatically."
298 (gnus-set-global-variables)
299 (if yank-articles
(gnus-summary-goto-subject (car yank-articles
)))
300 (save-window-excursion
301 (gnus-summary-select-article))
302 (let ((headers (gnus-get-header-by-number (gnus-summary-article-number)))
303 (gnus-newsgroup-name gnus-newsgroup-name
))
304 ;; Check Followup-To: poster.
305 (set-buffer gnus-article-buffer
)
306 (if (and gnus-use-followup-to
307 (string-equal "poster" (gnus-fetch-field "followup-to"))
308 (or (not (memq gnus-use-followup-to
'(t ask
)))
310 "Do you want to ignore `Followup-To: poster'? "))))
311 ;; Mail to the poster.
312 (gnus-summary-reply yank
)
313 (gnus-post-news nil gnus-newsgroup-name
314 headers gnus-article-buffer
315 (or yank-articles
(not (not yank
)))))))
317 (defun gnus-summary-followup-with-original (n)
318 "Compose a followup to an article and include the original article."
320 (gnus-summary-followup t
(gnus-summary-work-articles n
)))
322 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
323 (defun gnus-summary-followup-and-reply (yank &optional yank-articles
)
324 "Compose a followup and do an auto mail to author."
326 (gnus-set-global-variables)
327 (let ((gnus-auto-mail-to-author t
))
328 (gnus-summary-followup yank yank-articles
)))
330 (defun gnus-summary-followup-and-reply-with-original (n)
331 "Compose a followup, include the original, and do an auto mail to author."
333 (gnus-summary-followup-and-reply t
(gnus-summary-work-articles n
)))
335 (defun gnus-summary-cancel-article (n)
336 "Cancel an article you posted."
338 (gnus-set-global-variables)
339 (let ((articles (gnus-summary-work-articles n
)))
341 (gnus-summary-select-article t nil nil
(car articles
))
342 (and (gnus-eval-in-buffer-window gnus-article-buffer
(gnus-cancel-news))
343 (gnus-summary-mark-as-read (car articles
) gnus-canceled-mark
))
344 (gnus-summary-remove-process-mark (car articles
))
345 (gnus-article-hide-headers-if-wanted)
346 (setq articles
(cdr articles
)))))
348 (defun gnus-summary-supersede-article ()
349 "Compose an article that will supersede a previous article.
350 This is done simply by taking the old article and adding a Supersedes
351 header line with the old Message-ID."
353 (gnus-set-global-variables)
354 (gnus-summary-select-article t
)
357 (downcase (mail-strip-quoted-names
358 (mail-header-from gnus-current-headers
)))
359 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
360 (error "This article is not yours."))
362 (set-buffer gnus-article-buffer
)
363 (let ((buffer-read-only nil
))
364 (goto-char (point-min))
365 (search-forward "\n\n" nil t
)
366 (if (not (re-search-backward "^Message-ID: " nil t
))
367 (error "No Message-ID in this article"))))
368 (if (gnus-post-news 'post gnus-newsgroup-name
)
371 (insert-buffer gnus-article-buffer
)
372 (if (search-forward "\n\n" nil t
)
374 (goto-char (point-max)))
375 (narrow-to-region (point-min) (point))
376 (goto-char (point-min))
377 (and gnus-delete-supersedes-headers
378 (delete-matching-lines gnus-delete-supersedes-headers
))
379 (goto-char (point-min))
380 (if (not (re-search-forward "^Message-ID: " nil t
))
381 (error "No Message-ID in this article")
382 (replace-match "Supersedes: " t t
))
383 (goto-char (point-max))
384 (insert mail-header-separator
)
390 (defalias 'sendnews
'gnus-post-news
)
393 (defalias 'postnews
'gnus-post-news
)
395 (defun gnus-copy-article-buffer (&optional article-buffer
)
396 ;; make a copy of the article buffer with all text properties removed
397 ;; this copy is in the buffer gnus-article-copy.
398 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
399 ;; this buffer should be passed to all mail/news reply/post routines.
400 (setq gnus-article-copy
(get-buffer-create " *gnus article copy*"))
401 (buffer-disable-undo gnus-article-copy
)
402 (or (memq gnus-article-copy gnus-buffer-list
)
403 (setq gnus-buffer-list
(cons gnus-article-copy gnus-buffer-list
)))
404 (let ((article-buffer (or article-buffer gnus-article-buffer
)))
405 (if (and (get-buffer article-buffer
)
406 (buffer-name (get-buffer article-buffer
)))
408 (set-buffer article-buffer
)
410 (copy-to-buffer gnus-article-copy
(point-min) (point-max))
411 (set-text-properties (point-min) (point-max)
412 nil gnus-article-copy
)))))
415 (defun gnus-post-news (post &optional group header article-buffer yank subject
)
416 "Begin editing a new USENET news article to be posted.
417 Type \\[describe-mode] in the buffer to get a list of commands."
418 (interactive (list t
))
419 (gnus-copy-article-buffer article-buffer
)
420 (if (or (not gnus-novice-user
)
424 (format "%s" (car (gnus-find-method-for-group
425 gnus-newsgroup-name
)))
426 gnus-valid-select-methods
))))
429 (nth 5 (nth 2 (gnus-gethash group gnus-newsrc-hashtb
)))))
430 (gnus-y-or-n-p "Are you sure you want to post to all of USENET? "))
431 (let ((sumart (if (not post
)
433 (set-buffer gnus-summary-buffer
)
434 (cons (current-buffer) gnus-current-article
))))
435 (from (and header
(mail-header-from header
)))
436 (winconf (current-window-configuration))
438 (and gnus-interactive-post
439 (not gnus-expert-user
)
442 (setq gnus-newsgroup-name
444 (completing-read "Group: " gnus-active-hashtb
)))
446 (setq subject
(read-string "Subject: ")))))
447 (setq mail-reply-buffer gnus-article-copy
)
449 (let ((newsgroup-name (or group gnus-newsgroup-name
"")))
450 (setq real-group
(and group
(gnus-group-real-name group
)))
451 (setq gnus-post-news-buffer
452 (gnus-request-post-buffer
453 post real-group subject header gnus-article-copy
454 (nth 2 (and group
(gnus-gethash group gnus-newsrc-hashtb
)))
455 (or (cdr (assq 'to-group
456 (nth 5 (nth 2 (gnus-gethash
458 gnus-newsrc-hashtb
)))))
459 (if (and (boundp 'gnus-followup-to-function
)
460 gnus-followup-to-function
463 (set-buffer gnus-article-copy
)
464 (funcall gnus-followup-to-function group
))))
465 gnus-use-followup-to
))
467 (gnus-configure-windows 'post
'force
)
469 (gnus-configure-windows 'followup-yank
'force
)
470 (gnus-configure-windows 'followup
'force
)))
471 (gnus-overload-functions)
472 (make-local-variable 'gnus-article-reply
)
473 (make-local-variable 'gnus-article-check-size
)
474 (make-local-variable 'gnus-reply-subject
)
475 (setq gnus-reply-subject
(and header
(mail-header-subject header
)))
476 (setq gnus-article-reply sumart
)
477 ;; Handle `gnus-auto-mail-to-author'.
478 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
479 ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
480 (let ((to (and (not post
)
481 (if (if (eq gnus-auto-mail-to-author
'ask
)
482 (y-or-n-p "Also send mail to author? ")
483 gnus-auto-mail-to-author
)
485 (set-buffer gnus-article-copy
)
486 (gnus-fetch-field "reply-to"))
489 (if (mail-fetch-field "To")
492 (insert "Cc: " to
"\n"))
493 (mail-position-on-field "To")
495 ;; Handle author copy using BCC field.
496 (if (and gnus-mail-self-blind
497 (not (mail-fetch-field "bcc")))
499 (mail-position-on-field "Bcc")
500 (insert (if (stringp gnus-mail-self-blind
)
502 (user-login-name)))))
503 ;; Handle author copy using FCC field.
506 (mail-position-on-field "Fcc")
507 (insert gnus-author-copy
)))
508 (goto-char (point-min))
511 (re-search-forward "^Newsgroup:" nil t
)
514 (re-search-forward "^Subject:" nil t
)
518 (concat "^" (regexp-quote mail-header-separator
) "$"))
521 (concat "^" (regexp-quote mail-header-separator
) "$"))
526 (if (not (listp yank
))
527 (news-reply-yank-original nil
)
528 (setq yank
(reverse yank
))
531 (save-window-excursion
532 (set-buffer gnus-summary-buffer
)
533 (gnus-summary-select-article nil nil nil
(car yank
))
534 (gnus-summary-remove-process-mark (car yank
)))
535 (let ((mail-reply-buffer gnus-article-copy
))
536 (gnus-copy-article-buffer)
537 (let ((news-reply-yank-message-id
539 (set-buffer gnus-article-copy
)
540 (mail-fetch-field "message-id")))
541 (news-reply-yank-from
543 (set-buffer gnus-article-copy
)
544 (mail-fetch-field "from"))))
545 (news-reply-yank-original nil
))
546 (setq yank
(cdr yank
)))))))))
547 (if gnus-post-prepare-function
548 (funcall gnus-post-prepare-function group
))
549 (run-hooks 'gnus-post-prepare-hook
)
550 (make-local-variable 'gnus-prev-winconf
)
551 (setq gnus-prev-winconf winconf
))))
552 (setq gnus-article-check-size
(cons (buffer-size) (gnus-article-checksum)))
556 (defun gnus-inews-news (&optional use-group-method
)
557 "Send a news message.
558 If given a prefix, and the group is a foreign group, this function
559 will attempt to use the foreign server to post the article."
561 (or gnus-current-select-method
562 (setq gnus-current-select-method gnus-select-method
))
563 (let* ((case-fold-search nil
)
564 (server-running (gnus-server-opened gnus-current-select-method
))
565 (reply gnus-article-reply
)
568 ;; Connect to default NNTP server if necessary.
569 ;; Suggested by yuki@flab.fujitsu.junet.
570 (gnus-start-news-server) ;Use default server.
571 ;; NNTP server must be opened before current buffer is modified.
573 (goto-char (point-min))
574 (run-hooks 'news-inews-hook
)
579 (goto-char (point-min))
581 (concat "^" (regexp-quote mail-header-separator
) "$"))
582 (match-beginning 0)))
584 ;; Correct newsgroups field: change sequence of spaces to comma and
585 ;; eliminate spaces around commas. Eliminate embedded line breaks.
586 (goto-char (point-min))
587 (if (re-search-forward "^Newsgroups: +" nil t
)
591 (if (re-search-forward "^[^ \t]" nil t
)
595 (goto-char (point-min))
596 (while (re-search-forward "\n[ \t]+" nil t
)
597 (replace-match " " t t
)) ;No line breaks (too confusing)
598 (goto-char (point-min))
599 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
600 (replace-match "," t t
))
601 (goto-char (point-min))
602 ;; Remove a trailing comma.
603 (if (re-search-forward ",$" nil t
)
604 (replace-match "" t t
))))
606 ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
607 ;; Help save the the world!
610 (let ((newsgroups (mail-fetch-field "newsgroups"))
611 (followup-to (mail-fetch-field "followup-to"))
614 (string-match "," newsgroups
) (not followup-to
))
616 (while (string-match "," newsgroups
)
618 (cons (list (substring newsgroups
619 0 (match-beginning 0)))
621 (setq newsgroups
(substring newsgroups
(match-end 0))))
622 (setq groups
(nreverse (cons (list newsgroups
) groups
)))
625 (completing-read "Followups to: (default all groups) "
627 (if (> (length to
) 0)
629 (goto-char (point-min))
630 (insert "Followup-To: " to
"\n")))))))
632 ;; Cleanup Followup-To.
633 (goto-char (point-min))
634 (if (search-forward-regexp "^Followup-To: +" nil t
)
638 (if (re-search-forward "^[^ \t]" nil
'end
)
641 (goto-char (point-min))
642 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
643 (goto-char (point-min))
644 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ",")))
646 ;; Mail the message too if To:, Bcc:. or Cc: exists.
647 (let* ((types '("to" "bcc" "cc"))
651 (or (mail-fetch-field (car ty
) nil t
)
652 (setq types
(delete (car ty
) types
)))
656 ;; We do not want to send mail.
658 (if (not gnus-mail-send-method
)
662 1 "No mailer defined. To: and/or Cc: fields ignored.")
665 ;; We want to remove Fcc, because we want to handle
666 ;; that one ourselves...
668 (goto-char (point-min))
669 (if (re-search-forward "^Fcc: " nil t
)
673 (progn (beginning-of-line) (point))
674 (progn (forward-line 1) (point))))
678 ;; We generate a Message-ID so that the mail and the
679 ;; news copy of the message both get the same ID.
680 (or (mail-fetch-field "message-id")
681 (not (memq 'Message-ID gnus-required-headers
))
683 (goto-char (point-max))
684 (insert "Message-ID: " (gnus-inews-message-id) "\n")))
688 (gnus-message 5 "Sending via mail...")
690 (if (and gnus-mail-courtesy-message
691 (or (member "to" types
)
692 (member "cc" types
)))
693 ;; We only want to insert the courtesy mail
694 ;; message if we use to or cc; bcc should not
695 ;; have one. Well, if both bcc and to are
696 ;; present, it will get one anyway.
698 ;; Insert "courtesy" mail message.
699 (goto-char (point-min))
701 (concat "^" (regexp-quote
702 mail-header-separator
) "$"))
704 (insert gnus-mail-courtesy-message
)
705 (funcall gnus-mail-send-method
)
706 (goto-char (point-min))
707 (search-forward gnus-mail-courtesy-message
)
708 (replace-match "" t t
))
709 (funcall gnus-mail-send-method
))
711 (gnus-message 5 "Sending via mail...done")
713 (goto-char (point-min))
717 (concat "^" (regexp-quote mail-header-separator
) "$")))
718 (goto-char (point-min))
719 (while (re-search-forward "^BCC:" nil t
)
720 (delete-region (match-beginning 0)
721 ;; There might be continuation headers.
722 (if (re-search-forward "^[^ \t]" nil t
)
724 ;; Uhm... or something like this.
729 (goto-char (point-max))
730 (insert fcc-line
))))))))
733 (gnus-message 5 "Posting to USENET...")
734 (setq post-result
(funcall gnus-inews-article-function use-group-method
))
735 (cond ((eq post-result
'illegal
)
739 (gnus-message 5 "Posting to USENET...done")
740 (if (gnus-buffer-exists-p (car-safe reply
))
743 (set-buffer gnus-summary-buffer
)
744 (gnus-summary-mark-article-as-replied
746 (set-buffer-modified-p nil
))
748 ;; We cannot signal an error.
751 (gnus-message 1 "Article rejected: %s"
752 (gnus-status-message gnus-select-method
)))))
753 ;; If NNTP server is opened by gnus-inews-news, close it by myself.
755 (gnus-close-server (gnus-find-method-for-group gnus-newsgroup-name
)))
756 (let ((conf gnus-prev-winconf
))
760 ;; Restore last window configuration.
761 (and conf
(set-window-configuration conf
)))))))
763 (defun gnus-inews-check-post ()
764 "Check whether the post looks ok."
766 (not gnus-check-before-posting
)
768 ;; We narrow to the headers and check them first.
771 (goto-char (point-min))
776 (concat "^" (regexp-quote mail-header-separator
) "$"))
777 (match-beginning 0)))
778 (goto-char (point-min))
780 ;; Check for commands in Subject.
782 (gnus-check-before-posting 'subject-cmsg
)
784 (if (string-match "^cmsg " (mail-fetch-field "subject"))
786 "The control code \"cmsg \" is in the subject. Really post? ")
788 ;; Check for multiple identical headers.
789 (or (gnus-check-before-posting 'multiple-headers
)
792 (while (and (not found
) (re-search-forward "^[^ \t:]+: "
795 (or (re-search-forward
796 (concat "^" (setq found
799 (- (match-end 0) 2))))
804 (format "Multiple %s headers. Really post? " found
))
806 ;; Check for version and sendsys.
807 (or (gnus-check-before-posting 'sendsys
)
809 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
811 (format "The article contains a %s command. Really post? "
812 (buffer-substring (match-beginning 0)
813 (1- (match-end 0)))))
815 ;; Check the Message-Id header.
816 (or (gnus-check-before-posting 'message-id
)
818 (let* ((case-fold-search t
)
819 (message-id (mail-fetch-field "message-id")))
821 (and (string-match "@" message-id
)
822 (string-match "@[^\\.]*\\." message-id
))
825 "The Message-ID looks strange: \"%s\". Really post? "
827 ;; Check the From header.
828 (or (gnus-check-before-posting 'from
)
830 (let* ((case-fold-search t
)
831 (from (mail-fetch-field "from")))
834 (gnus-y-or-n-p "There is no From line. Really post? "))
835 ((not (string-match "@[^\\.]*\\." from
))
838 "The address looks strange: \"%s\". Really post? " from
)))
839 ((string-match "(.*).*(.*)" from
)
842 "The From header looks strange: \"%s\". Really post? "
846 ;; Check for long lines.
847 (or (gnus-check-before-posting 'long-lines
)
849 (goto-char (point-min))
851 (concat "^" (regexp-quote mail-header-separator
) "$"))
855 (< (current-column) 80))
856 (zerop (forward-line 1))))
861 "You have lines longer than 79 characters. Really post? ")))))
862 ;; Check for control characters.
863 (or (gnus-check-before-posting 'control-chars
)
865 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t
)
867 "The article contains control characters. Really post? ")
869 ;; Check excessive size.
870 (or (gnus-check-before-posting 'size
)
871 (if (> (buffer-size) 60000)
873 (format "The article is %d octets long. Really post? "
876 ;; Use the (size . checksum) variable to see whether the
877 ;; article is empty or has only quoted text.
879 (gnus-check-before-posting 'new-text
)
880 (if (and (= (buffer-size) (car gnus-article-check-size
))
881 (= (gnus-article-checksum) (cdr gnus-article-check-size
)))
883 "It looks like there's no new text in your article. Really post? ")
885 ;; Check the length of the signature.
886 (or (gnus-check-before-posting 'signature
)
888 (goto-char (point-max))
889 (if (not (re-search-backward gnus-signature-separator nil t
))
891 (if (> (count-lines (point) (point-max)) 5)
894 "Your .sig is %d lines; it should be max 4. Really post? "
895 (count-lines (point) (point-max))))
898 (defun gnus-article-checksum ()
902 (setq sum
(logxor sum
(following-char)))
906 ;; Returns non-nil if this type is not to be checked.
907 (defun gnus-check-before-posting (type)
909 (or (not gnus-check-before-posting
)
910 (if (listp gnus-check-before-posting
)
911 (memq type gnus-check-before-posting
)
914 (defun gnus-cancel-news ()
915 "Cancel an article you posted."
917 (if (or gnus-expert-user
918 (gnus-yes-or-no-p "Do you really want to cancel this article? "))
923 (or (gnus-member-of-valid 'post gnus-newsgroup-name
)
924 (error "This backend does not support canceling"))
926 ;; Get header info. from original article.
928 (gnus-article-show-all-headers)
929 (goto-char (point-min))
930 (search-forward "\n\n" nil
'move
)
931 (narrow-to-region (point-min) (point))
932 (setq from
(mail-fetch-field "from"))
933 (setq newsgroups
(mail-fetch-field "newsgroups"))
934 (setq message-id
(mail-fetch-field "message-id"))
935 (setq distribution
(mail-fetch-field "distribution")))
936 ;; Verify if the article is absolutely user's by comparing
937 ;; user id with value of its From: field.
940 (downcase (mail-strip-quoted-names from
))
941 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
943 (ding) (gnus-message 3 "This article is not yours.")
945 ;; Make control article.
946 (set-buffer (get-buffer-create " *Gnus-canceling*"))
947 (buffer-disable-undo (current-buffer))
949 (insert "Newsgroups: " newsgroups
"\n"
950 "Subject: cancel " message-id
"\n"
951 "Control: cancel " message-id
"\n"
953 (concat "Distribution: " distribution
"\n")
955 mail-header-separator
"\n"
956 "This is a cancel message from " from
".\n")
957 ;; Send the control article to NNTP server.
958 (gnus-message 5 "Canceling your article...")
960 (if (funcall gnus-inews-article-function
)
961 (gnus-message 5 "Canceling your article...done")
964 (gnus-message 1 "Cancel failed; %s"
965 (gnus-status-message gnus-newsgroup-name
))
968 ;; Kill the article buffer.
969 (kill-buffer (current-buffer))))))))
972 ;;; Lowlevel inews interface
974 (defun gnus-inews-article (&optional use-group-method
)
975 "Post an article in current buffer using NNTP protocol."
976 (let ((artbuf (current-buffer))
977 (tmpbuf (get-buffer-create " *Gnus-posting*")))
979 (goto-char (point-max))
980 ;; require a newline at the end for inews to append .signature to
981 (or (= (preceding-char) ?
\n)
983 ;; Prepare article headers. All message body such as signature
984 ;; must be inserted before Lines: field is prepared.
986 (goto-char (point-min))
991 (concat "^" (regexp-quote mail-header-separator
) "$"))
992 (match-beginning 0)))
993 (gnus-inews-remove-headers)
994 (gnus-inews-insert-headers)
995 (run-hooks 'gnus-inews-article-header-hook
)
997 ;; Check whether the article is a good Net Citizen.
998 (if (and gnus-article-check-size
999 (not (gnus-inews-check-post)))
1002 ;; Looks ok, so we do the nasty.
1005 (buffer-disable-undo (current-buffer))
1007 (insert-buffer-substring artbuf
)
1008 ;; Remove the header separator.
1009 (goto-char (point-min))
1011 (concat "^" (regexp-quote mail-header-separator
) "$"))
1012 (replace-match "" t t
)
1013 ;; This hook may insert a signature.
1015 (goto-char (point-min))
1016 (let ((gnus-newsgroup-name (or (mail-fetch-field "newsgroups")
1017 gnus-newsgroup-name
)))
1018 (run-hooks 'gnus-prepare-article-hook
)))
1019 ;; Run final inews hooks. This hook may do FCC.
1020 ;; The article must be saved before being posted because
1021 ;; `gnus-request-post' modifies the buffer.
1022 (run-hooks 'gnus-inews-article-hook
)
1023 ;; Post an article to NNTP server.
1024 ;; Return NIL if post failed.
1027 (if use-group-method
1028 (gnus-find-method-for-group gnus-newsgroup-name
)
1029 gnus-select-method
) use-group-method
)
1030 (kill-buffer (current-buffer)))))))
1032 (defun gnus-inews-remove-headers ()
1033 (let ((case-fold-search t
)
1034 (headers gnus-removable-headers
))
1035 ;; Remove toxic headers.
1037 (goto-char (point-min))
1038 (and (re-search-forward
1039 (concat "^" (downcase (format "%s" (car headers
))))
1041 (delete-region (progn (beginning-of-line) (point))
1042 (progn (forward-line 1) (point))))
1043 (setq headers
(cdr headers
)))))
1045 (defun gnus-inews-insert-headers ()
1046 "Prepare article headers.
1047 Headers already prepared in the buffer are not modified.
1048 Headers in `gnus-required-headers' will be generated."
1049 (let ((Date (gnus-inews-date))
1050 (Message-ID (gnus-inews-message-id))
1051 (Organization (gnus-inews-organization))
1052 (From (gnus-inews-user-name))
1053 (Path (gnus-inews-path))
1057 (Lines (gnus-inews-lines))
1058 (X-Newsreader gnus-version
)
1059 (headers gnus-required-headers
)
1060 (case-fold-search t
)
1062 ;; First we remove any old generated headers.
1063 (let ((headers gnus-deletable-headers
))
1065 (goto-char (point-min))
1066 (and (re-search-forward
1067 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
1068 (get-text-property (1+ (match-beginning 0)) 'gnus-deletable
)
1070 (setq headers
(cdr headers
))))
1071 ;; If there are References, and no "Re: ", then the thread has
1072 ;; changed name. See Son-of-1036.
1073 (if (and (mail-fetch-field "references")
1074 (get-buffer gnus-article-buffer
))
1075 (let ((psubject (gnus-simplify-subject-re
1076 (mail-fetch-field "subject"))))
1077 (or (and psubject gnus-reply-subject
1078 (string= (gnus-simplify-subject-re gnus-reply-subject
)
1081 (string-match "@" Message-ID
)
1083 (concat (substring Message-ID
0 (match-beginning 0))
1085 (substring Message-ID
(match-beginning 0))))))))
1086 ;; Go through all the required headers and see if they are in the
1087 ;; articles already. If they are not, or are empty, they are
1088 ;; inserted automatically - except for Subject, Newsgroups and
1091 (goto-char (point-min))
1092 (setq elem
(car headers
))
1094 (setq header
(car elem
))
1096 (if (or (not (re-search-forward
1097 (concat "^" (downcase (symbol-name header
)) ":") nil t
))
1099 ;; The header was found. We insert a space after the
1100 ;; colon, if there is none.
1101 (if (/= (following-char) ?
) (insert " "))
1102 ;; Find out whether the header is empty...
1103 (looking-at "[ \t]*$")))
1104 ;; So we find out what value we should insert.
1107 (or (if (consp elem
)
1108 ;; The element is a cons. Either the cdr is
1109 ;; a string to be inserted verbatim, or it
1110 ;; is a function, and we insert the value
1111 ;; returned from this function.
1112 (or (and (stringp (cdr elem
)) (cdr elem
))
1113 (and (fboundp (cdr elem
)) (funcall (cdr elem
))))
1114 ;; The element is a symbol. We insert the
1115 ;; value of this symbol, if any.
1116 (and (boundp header
) (symbol-value header
)))
1117 ;; We couldn't generate a value for this header,
1118 ;; so we just ask the user.
1119 (read-from-minibuffer
1120 (format "Empty header for %s; enter value: " header
))))
1121 ;; Finally insert the header.
1125 (goto-char (point-max))
1126 (insert (symbol-name header
) ": " value
"\n")
1128 (replace-match value t t
))
1129 ;; Add the deletable property to the headers that require it.
1130 (and (memq header gnus-deletable-headers
)
1131 (progn (beginning-of-line) (looking-at "[^:]+: "))
1132 (add-text-properties
1133 (point) (match-end 0)
1134 '(gnus-deletable t face italic
) (current-buffer))))))
1135 (setq headers
(cdr headers
)))
1136 ;; Insert new Sender if the From is strange.
1137 (let ((from (mail-fetch-field "from"))
1138 (sender (mail-fetch-field "sender")))
1142 (car (cdr (gnus-extract-address-components from
))))
1143 (downcase (gnus-inews-real-user-address))))
1148 (car (cdr (gnus-extract-address-components sender
))))
1149 (downcase (gnus-inews-real-user-address))))))
1151 (goto-char (point-min))
1152 (and (re-search-forward "^Sender:" nil t
)
1155 (insert "Original-")
1156 (beginning-of-line)))
1157 (insert "Sender: " (gnus-inews-real-user-address) "\n"))))))
1160 (defun gnus-inews-insert-signature ()
1161 "Insert a signature file.
1162 If `gnus-signature-function' is bound and returns a string, this
1163 string is used instead of the variable `gnus-signature-file'.
1164 In either case, if the string is a file name, this file is
1165 inserted. If the string is not a file name, the string itself is
1168 If you never want any signature inserted, set both of these variables to
1172 (or (and gnus-signature-function
1173 (funcall gnus-signature-function gnus-newsgroup-name
))
1174 gnus-signature-file
)))
1176 (or (file-exists-p signature
)
1177 (string-match " " signature
)
1179 "^/[^/]+/" (expand-file-name signature
)))))
1181 (goto-char (point-max))
1182 (if (and mail-signature
(search-backward "\n-- \n" nil t
))
1184 ;; Delete any previous signatures.
1185 (if (search-backward "\n-- \n" nil t
)
1186 (delete-region (point) (point-max)))
1187 (or (eolp) (insert "\n"))
1189 (if (file-exists-p signature
)
1190 (insert-file-contents signature
)
1192 (goto-char (point-max))
1193 (or (bolp) (insert "\n"))))))))
1195 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1196 (defun gnus-inews-insert-mime-headers ()
1197 (let ((mail-header-separator ""))
1198 (or (mail-position-on-field "Mime-Version")
1200 (cond ((save-excursion
1201 (beginning-of-buffer)
1202 (re-search-forward "[\200-\377]" nil t
))
1203 (or (mail-position-on-field "Content-Type")
1204 (insert "text/plain; charset=ISO-8859-1"))
1205 (or (mail-position-on-field "Content-Transfer-Encoding")
1207 (t (or (mail-position-on-field "Content-Type")
1208 (insert "text/plain; charset=US-ASCII"))
1209 (or (mail-position-on-field "Content-Transfer-Encoding")
1210 (insert "7bit")))))))
1212 (defun gnus-inews-do-fcc ()
1213 "Process FCC: fields in current article buffer.
1214 Unless the first character of the field is `|', the article is saved
1215 to the specified file using the function specified by the variable
1216 gnus-author-copy-saver. The default function rmail-output saves in
1217 Unix mailbox format.
1218 If the first character is `|', the contents of the article is send to
1219 a program specified by the rest of the value."
1220 (let ((fcc-list nil
)
1222 (case-fold-search t
)) ;Should ignore case.
1225 (goto-char (point-min))
1226 (search-forward "\n\n")
1227 (narrow-to-region (point-min) (point))
1228 (goto-char (point-min))
1229 (while (re-search-forward "^FCC:[ \t]*" nil t
)
1231 (cons (buffer-substring
1235 (skip-chars-backward " \t")
1238 (delete-region (match-beginning 0)
1239 (progn (forward-line 1) (point))))
1240 ;; Process FCC operations.
1243 (setq fcc-file
(car fcc-list
))
1244 (setq fcc-list
(cdr fcc-list
))
1245 (cond ((string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" fcc-file
)
1246 (let ((program (substring fcc-file
1247 (match-beginning 1) (match-end 1))))
1248 ;; Suggested by yuki@flab.fujitsu.junet.
1249 ;; Send article to named program.
1250 (call-process-region (point-min) (point-max) shell-file-name
1251 nil nil nil
"-c" program
)))
1253 ;; Suggested by hyoko@flab.fujitsu.junet.
1254 ;; Save article in Unix mail format by default.
1255 (gnus-make-directory (file-name-directory fcc-file
))
1256 (if (and gnus-author-copy-saver
1257 (not (eq gnus-author-copy-saver
'rmail-output
)))
1258 (funcall gnus-author-copy-saver fcc-file
)
1259 (if (and (file-readable-p fcc-file
)
1260 (mail-file-babyl-p fcc-file
))
1261 (gnus-output-to-rmail fcc-file
)
1262 (rmail-output fcc-file
1 t t
))))))))))
1264 (defun gnus-inews-path ()
1266 (let ((login-name (gnus-inews-login-name)))
1267 (cond ((null gnus-use-generic-path
)
1268 (concat (nth 1 gnus-select-method
) "!" login-name
))
1269 ((stringp gnus-use-generic-path
)
1270 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1271 (concat gnus-use-generic-path
"!" login-name
))
1274 (defun gnus-inews-user-name ()
1275 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1276 (let ((full-name (gnus-inews-full-name))
1277 (address (if (or gnus-user-login-name gnus-use-generic-from
1278 gnus-local-domain
(getenv "DOMAINNAME"))
1279 (concat (gnus-inews-login-name) "@"
1280 (gnus-inews-domain-name gnus-use-generic-from
))
1281 user-mail-address
)))
1282 (or gnus-user-from-line
1284 ;; User's full name.
1285 (cond ((string-equal full-name
"&") ;Unix hack.
1286 (concat " (" (user-login-name) ")"))
1287 ((string-match "[^ ]+@[^ ]+ +(.*)" address
)
1290 (concat " (" full-name
")")))))))
1292 (defun gnus-inews-real-user-address ()
1293 "Return the \"real\" user address.
1294 This function tries to ignore all user modifications, and
1295 give as trustworthy answer as possible."
1296 (concat (user-login-name) "@" (gnus-inews-full-address)))
1298 (defun gnus-inews-login-name ()
1299 "Return login name."
1300 (or gnus-user-login-name
(getenv "LOGNAME") (user-login-name)))
1302 (defun gnus-inews-full-name ()
1303 "Return full user name."
1304 (or gnus-user-full-name
(getenv "NAME") (user-full-name)))
1306 (defun gnus-inews-domain-name (&optional genericfrom
)
1307 "Return user's domain name.
1308 If optional argument GENERICFROM is a string, use it as the domain
1309 name; if it is non-nil, strip off local host name from the domain name.
1310 If the function `system-name' returns full internet name and the
1311 domain is undefined, the domain name is got from it."
1312 (if (or genericfrom gnus-local-domain
(getenv "DOMAINNAME"))
1313 (let* ((system-name (system-name))
1315 (or (if (stringp genericfrom
) genericfrom
)
1316 (getenv "DOMAINNAME")
1318 ;; Function `system-name' may return full internet name.
1319 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1320 (if (string-match "\\." system-name
)
1321 (substring system-name
(match-end 0)))
1322 (read-string "Domain name (no host): ")))
1323 (host (or (if (string-match "\\." system-name
)
1324 (substring system-name
0 (match-beginning 0)))
1326 (if (string-equal "." (substring domain
0 1))
1327 (setq domain
(substring domain
1)))
1328 ;; Support GENERICFROM as same as standard Bnews system.
1329 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1330 (cond ((null genericfrom
)
1331 (concat host
"." domain
))
1332 ;;((stringp genericfrom) genericfrom)
1334 (if (string-match "\\." (system-name))
1336 (substring user-mail-address
1337 (1+ (string-match "@" user-mail-address
))))))
1339 (defun gnus-inews-full-address ()
1340 (let ((domain (gnus-inews-domain-name))
1341 (system (system-name))
1342 (case-fold-search t
))
1343 (if (string-match "\\." system
) system
1344 (if (string-match (concat "^" (regexp-quote system
)) domain
) domain
1345 (concat system
"." domain
)))))
1347 (defun gnus-inews-message-id ()
1348 "Generate unique Message-ID for user."
1349 ;; Message-ID should not contain a slash and should be terminated by
1350 ;; a number. I don't know the reason why it is so.
1351 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1353 (defvar gnus-unique-id-char nil
)
1355 ;; If you ever change this function, make sure the new version
1356 ;; cannot generate IDs that the old version could.
1357 ;; You might for example insert a "." somewhere (not next to another dot
1358 ;; or string boundary), or modify the newsreader name to "Ding".
1359 (defun gnus-inews-unique-id ()
1360 ;; Don't use microseconds from (current-time), they may be unsupported.
1361 ;; Instead we use this randomly inited counter.
1362 (setq gnus-unique-id-char
1363 (%
(1+ (or gnus-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
1364 ;; (current-time) returns 16-bit ints,
1365 ;; and 2^16*25 just fits into 4 digits i base 36.
1367 (let ((tm (if (fboundp 'current-time
)
1368 (current-time) '(12191 46742 287898))))
1370 (if (memq system-type
'(ms-dos emx vax-vms
))
1371 (let ((user (downcase (gnus-inews-login-name))))
1372 (while (string-match "[^a-z0-9_]" user
)
1373 (aset user
(match-beginning 0) ?_
))
1375 (gnus-number-base36 (user-uid) -
1))
1376 (gnus-number-base36 (+ (car tm
) (lsh (% gnus-unique-id-char
25) 16)) 4)
1377 (gnus-number-base36 (+ (nth 1 tm
) (lsh (/ gnus-unique-id-char
25) 16)) 4)
1378 ;; Append the newsreader name, because while the generated
1379 ;; ID is unique to this newsreader, other newsreaders might
1380 ;; otherwise generate the same ID via another algorithm.
1384 (defun gnus-inews-date ()
1385 "Current time string."
1386 (timezone-make-date-arpa-standard
1387 (current-time-string) (current-time-zone)))
1389 (defun gnus-inews-organization ()
1390 "Return user's organization.
1391 The ORGANIZATION environment variable is used if defined.
1392 If not, the variable `gnus-local-organization' is used instead.
1393 If it is a function, the function will be called with the current
1394 newsgroup name as the argument.
1395 If this is a file name, the contents of this file will be used as the
1397 (let* ((organization
1398 (or (getenv "ORGANIZATION")
1399 (if gnus-local-organization
1400 (if (and (symbolp gnus-local-organization
)
1401 (fboundp gnus-local-organization
))
1402 (funcall gnus-local-organization gnus-newsgroup-name
)
1403 gnus-local-organization
))
1404 gnus-organization-file
1405 "~/.organization")))
1406 (and (stringp organization
)
1407 (> (length organization
) 0)
1408 (or (file-exists-p organization
)
1409 (string-match " " organization
)
1410 (not (string-match "^/usr/lib/" organization
)))
1412 (gnus-set-work-buffer)
1413 (if (file-exists-p organization
)
1414 (insert-file-contents organization
)
1415 (insert organization
))
1416 (goto-char (point-min))
1417 (while (re-search-forward " *\n *" nil t
)
1418 (replace-match " " t t
))
1419 (buffer-substring (point-min) (point-max))))))
1421 (defun gnus-inews-lines ()
1422 "Count the number of lines and return numeric string."
1426 (goto-char (point-min))
1428 (concat "^" (regexp-quote mail-header-separator
) "$"))
1430 (int-to-string (count-lines (point) (point-max))))))
1434 ;;; Gnus Mail Functions
1437 ;;; Mail reply commands of Gnus summary mode
1439 (defun gnus-summary-reply (yank &optional yank-articles
)
1440 "Reply mail to news author.
1441 If prefix argument YANK is non-nil, original article is yanked automatically.
1442 Customize the variable gnus-mail-reply-method to use another mailer."
1444 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1445 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1446 (gnus-set-global-variables)
1447 (if yank-articles
(gnus-summary-goto-subject (car yank-articles
)))
1448 (gnus-summary-select-article)
1449 (let ((gnus-newsgroup-name gnus-newsgroup-name
))
1450 (bury-buffer gnus-article-buffer
)
1451 (funcall gnus-mail-reply-method
(or yank-articles
(not (not yank
))))))
1453 (defun gnus-summary-reply-with-original (n)
1454 "Reply mail to news author with original article.
1455 Customize the variable gnus-mail-reply-method to use another mailer."
1457 (gnus-summary-reply t
(gnus-summary-work-articles n
)))
1459 (defun gnus-summary-mail-forward (post)
1460 "Forward the current message to another user.
1461 Customize the variable gnus-mail-forward-method to use another mailer."
1463 (gnus-set-global-variables)
1464 (gnus-summary-select-article)
1465 (gnus-copy-article-buffer)
1466 (let ((gnus-newsgroup-name gnus-newsgroup-name
))
1468 (gnus-forward-using-post gnus-article-copy
)
1469 (funcall gnus-mail-forward-method 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)
1499 (let ((gnus-newsgroup-name gnus-newsgroup-name
))
1500 (funcall gnus-mail-other-window-method
)))
1502 (defun gnus-mail-reply-using-mail (&optional yank to-address
)
1504 (set-buffer gnus-summary-buffer
)
1505 (let ((group (gnus-group-real-name gnus-newsgroup-name
))
1506 (cur (cons (current-buffer) (cdr gnus-article-current
)))
1507 (winconf (current-window-configuration))
1508 from subject date reply-to message-of
1509 references message-id sender follow-to sendto elt
)
1510 (set-buffer (get-buffer-create gnus-mail-buffer
))
1512 (make-local-variable 'gnus-article-reply
)
1513 (setq gnus-article-reply cur
)
1514 (make-local-variable 'gnus-prev-winconf
)
1515 (setq gnus-prev-winconf winconf
)
1516 (if (and (buffer-modified-p)
1519 "Unsent article being composed; erase it? ")))
1523 (gnus-copy-article-buffer)
1525 (set-buffer gnus-article-copy
)
1526 (gnus-narrow-to-headers)
1527 (if (and (boundp 'gnus-reply-to-function
)
1528 gnus-reply-to-function
)
1529 (setq follow-to
(funcall gnus-reply-to-function group
)))
1530 (setq from
(mail-fetch-field "from"))
1531 (setq date
(or (mail-fetch-field "date")
1532 (mail-header-date gnus-current-headers
)))
1535 (string-match " *at \\| *@ \\| *(\\| *<" from
)))
1537 (concat (if stop-pos
(substring from
0 stop-pos
) from
)
1538 "'s message of " date
))))
1539 (setq sender
(mail-fetch-field "sender"))
1540 (setq subject
(or (mail-fetch-field "subject")
1542 (or (string-match "^[Rr][Ee]:" subject
)
1543 (setq subject
(concat "Re: " subject
)))
1544 (setq reply-to
(mail-fetch-field "reply-to"))
1545 (setq references
(mail-fetch-field "references"))
1546 (setq message-id
(mail-fetch-field "message-id"))
1548 (setq news-reply-yank-from
(or from
"(nobody)")))
1549 (setq news-reply-yank-message-id
1550 (or message-id
"(unknown Message-ID)"))
1552 ;; Gather the "to" addresses out of the follow-to list and remove
1554 (if (and follow-to
(listp follow-to
))
1555 (while (setq elt
(assoc "To" follow-to
))
1556 (setq sendto
(concat sendto
(and sendto
", ") (cdr elt
)))
1557 (setq follow-to
(delq elt follow-to
))))
1559 (mail-setup (or to-address
1560 (if (and follow-to
(not (stringp follow-to
))) sendto
1561 (or follow-to reply-to from sender
"")))
1562 subject message-of nil gnus-article-copy nil
)
1564 (auto-save-mode auto-save-default
)
1565 (use-local-map (copy-keymap (current-local-map)))
1566 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit
)
1568 (if (and follow-to
(listp follow-to
))
1570 (goto-char (point-min))
1571 (re-search-forward "^To:" nil t
)
1575 (insert (car (car follow-to
)) ": " (cdr (car follow-to
)) "\n")
1576 (setq follow-to
(cdr follow-to
)))))
1577 (nnheader-insert-references references message-id
)
1578 (goto-char (point-min))
1580 (concat "^" (regexp-quote mail-header-separator
) "$"))
1583 (gnus-configure-windows 'reply
'force
)
1584 (let ((last (point))
1586 (if (not (listp yank
))
1589 (mail-yank-original nil
))
1590 (or mail-yank-hooks mail-citation-hook
1591 (run-hooks 'news-reply-header-hook
)))
1593 (save-window-excursion
1594 (set-buffer gnus-summary-buffer
)
1595 (gnus-summary-select-article nil nil nil
(car yank
))
1596 (gnus-summary-remove-process-mark (car yank
)))
1598 (gnus-copy-article-buffer)
1599 (mail-yank-original nil
)
1601 (or mail-yank-hooks mail-citation-hook
1602 (run-hooks 'news-reply-header-hook
))
1604 (setq yank
(cdr yank
))))
1606 (gnus-configure-windows 'reply-yank
'force
))
1607 (run-hooks 'gnus-mail-hook
)))))
1609 (defun gnus-mail-yank-original ()
1612 (mail-yank-original nil
))
1613 (or mail-yank-hooks mail-citation-hook
1614 (run-hooks 'news-reply-header-hook
)))
1616 (defun gnus-mail-send-and-exit ()
1618 (let ((reply gnus-article-reply
)
1619 (winconf gnus-prev-winconf
))
1620 (mail-send-and-exit nil
)
1621 (if (get-buffer gnus-group-buffer
)
1623 (if (gnus-buffer-exists-p (car-safe reply
))
1625 (set-buffer (car reply
))
1627 (gnus-summary-mark-article-as-replied
1629 (and winconf
(set-window-configuration winconf
))))))
1631 (defun gnus-forward-make-subject (buffer)
1634 (concat "[" (if (memq 'mail
(assoc (symbol-name
1635 (car (gnus-find-method-for-group
1636 gnus-newsgroup-name
)))
1637 gnus-valid-select-methods
))
1638 (gnus-fetch-field "From")
1639 gnus-newsgroup-name
)
1640 "] " (or (gnus-fetch-field "Subject") ""))))
1642 (defun gnus-forward-insert-buffer (buffer)
1643 (let ((beg (goto-char (point-max))))
1644 (insert "------- Start of forwarded message -------\n")
1645 (insert-buffer buffer
)
1646 (goto-char (point-max))
1647 (insert "------- End of forwarded message -------\n")
1648 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
1650 (while (setq beg
(next-single-property-change (point) 'invisible
))
1652 (delete-region beg
(or (next-single-property-change
1656 (defun gnus-mail-forward-using-mail (&optional buffer
)
1657 "Forward the current message to another user using mail."
1658 ;; This is almost a carbon copy of rmail-forward in rmail.el.
1659 (let* ((forward-buffer (or buffer
(current-buffer)))
1660 (winconf (current-window-configuration))
1661 (subject (gnus-forward-make-subject forward-buffer
)))
1662 (set-buffer forward-buffer
)
1663 (mail nil nil subject
)
1664 (use-local-map (copy-keymap (current-local-map)))
1665 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit
)
1666 (make-local-variable 'gnus-prev-winconf
)
1667 (setq gnus-prev-winconf winconf
)
1668 (gnus-forward-insert-buffer forward-buffer
)
1669 (goto-char (point-min))
1670 (re-search-forward "^To: " nil t
)
1671 (gnus-configure-windows 'mail-forward
'force
)
1672 ;; You have a chance to arrange the message.
1673 (run-hooks 'gnus-mail-forward-hook
)
1674 (run-hooks 'gnus-mail-hook
)))
1676 (defun gnus-forward-using-post (&optional buffer
)
1678 (let* ((forward-buffer (or buffer
(current-buffer)))
1679 (subject (gnus-forward-make-subject forward-buffer
))
1680 (gnus-newsgroup-name nil
))
1681 (gnus-post-news 'post nil nil nil nil subject
)
1683 (gnus-forward-insert-buffer forward-buffer
)
1684 ;; You have a chance to arrange the message.
1685 (run-hooks 'gnus-mail-forward-hook
)))))
1687 (defun gnus-mail-other-window-using-mail ()
1688 "Compose mail other window using mail."
1689 (let ((winconf (current-window-configuration)))
1690 (mail-other-window nil nil nil nil nil
(get-buffer gnus-article-buffer
))
1691 (use-local-map (copy-keymap (current-local-map)))
1692 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit
)
1693 (make-local-variable 'gnus-prev-winconf
)
1694 (setq gnus-prev-winconf winconf
)
1695 (run-hooks 'gnus-mail-hook
)
1696 (gnus-configure-windows 'summary-mail
'force
)))
1698 (defun gnus-article-mail (yank)
1699 "Send a reply to the address near point.
1700 If YANK is non-nil, include the original article."
1704 (save-excursion (re-search-backward "[ \t\n]" nil t
) (1+ (point)))
1705 (save-excursion (re-search-forward "[ \t\n]" nil t
) (1- (point))))))
1708 (switch-to-buffer gnus-summary-buffer
)
1709 (funcall gnus-mail-reply-method yank address
)))))
1712 "Send a bug report to the Gnus maintainers."
1714 (let ((winconf (current-window-configuration)))
1715 (delete-other-windows)
1716 (switch-to-buffer "*Gnus Help Bug*")
1718 (insert gnus-bug-message
)
1719 (goto-char (point-min))
1720 (pop-to-buffer "*Gnus Bug*")
1723 (mail-setup gnus-maintainer nil nil nil nil nil
)
1724 (auto-save-mode auto-save-default
)
1725 (make-local-variable 'gnus-prev-winconf
)
1726 (setq gnus-prev-winconf winconf
)
1727 (use-local-map (copy-keymap mail-mode-map
))
1728 (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit
)
1729 (goto-char (point-min))
1730 (re-search-forward (concat "^" (regexp-quote mail-header-separator
) "$"))
1732 (insert (format "%s\n%s\n\n\n\n\n" (gnus-version) (emacs-version)))
1734 (goto-char (point-min))
1735 (search-forward "Subject: " nil t
)
1738 (defun gnus-bug-mail-send-and-exit ()
1739 "Send the bug message and exit."
1741 (and (get-buffer "*Gnus Help Bug*")
1742 (kill-buffer "*Gnus Help Bug*"))
1743 (gnus-mail-send-and-exit))
1745 (defun gnus-debug ()
1746 "Attemps to go through the Gnus source file and report what variables have been changed.
1747 The source file has to be in the Emacs load path."
1749 (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el"))
1750 file dirs expr olist sym
)
1751 (message "Please wait while we snoop your variables...")
1754 (set-buffer (get-buffer-create " *gnus bug info*"))
1755 (buffer-disable-undo (current-buffer))
1758 (setq dirs load-path
)
1760 (if (or (not (car dirs
))
1761 (not (stringp (car dirs
)))
1763 (setq file
(concat (file-name-as-directory
1764 (car dirs
)) (car files
))))))
1765 (setq dirs
(cdr dirs
))
1767 (insert-file-contents file
)
1768 (goto-char (point-min))
1769 (or (re-search-forward "^;;* *Internal variables" nil t
)
1770 (error "Malformed sources in file %s" file
))
1771 (narrow-to-region (point-min) (point))
1772 (goto-char (point-min))
1773 (while (setq expr
(condition-case ()
1774 (read (current-buffer)) (error nil
)))
1776 (and (eq (car expr
) 'defvar
)
1777 (stringp (nth 3 expr
))
1778 (or (not (boundp (nth 1 expr
)))
1779 (not (equal (eval (nth 2 expr
))
1780 (symbol-value (nth 1 expr
)))))
1781 (setq olist
(cons (nth 1 expr
) olist
)))
1783 (setq files
(cdr files
)))
1784 (kill-buffer (current-buffer)))
1785 (insert "------------------- Environment follows -------------------\n\n")
1787 (if (boundp (car olist
))
1788 (insert "(setq " (symbol-name (car olist
))
1789 (if (or (consp (setq sym
(symbol-value (car olist
))))
1791 (not (or (eq sym nil
)
1794 (prin1-to-string (symbol-value (car olist
))) ")\n")
1795 (insert ";; (makeunbound '" (symbol-name (car olist
)) ")\n"))
1796 (setq olist
(cdr olist
)))
1798 ;; Remove any null chars - they seem to cause trouble for some
1799 ;; mailers. (Byte-compiled output from the stuff above.)
1800 (goto-char (point-min))
1801 (while (re-search-forward "[\000\200]" nil t
)
1802 (replace-match "" t t
))))
1808 ;;; gnus-msg.el ends here