1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
5 ;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
31 (eval-when-compile (require 'cl))
33 (defvar gnus-organization-file "/usr/lib/news/organization"
34 "*Local news organization file.")
36 (defvar gnus-prepare-article-hook nil
37 "*A hook called after preparing body, but before preparing header headers.")
39 (defvar gnus-post-prepare-function nil
40 "*Function that is run after a post buffer has been prepared.
41 It is called with the name of the newsgroup that is posted to. It
42 might be used, for instance, for inserting signatures based on the
43 newsgroup name. (In that case, `gnus-signature-file' and
44 `mail-signature' should both be set to nil).")
46 (defvar gnus-post-prepare-hook nil
47 "*Hook that is run after a post buffer has been prepared.
48 If you want to insert the signature, you might put
49 `gnus-inews-insert-signature' in this hook.")
51 (defvar gnus-use-followup-to t
52 "*Specifies what to do with Followup-To header.
53 If nil, ignore the header. If it is t, use its value, but ignore
54 `poster'. If it is the symbol `ask', query the user before posting.
55 If it is the symbol `use', always use the value.")
57 (defvar gnus-followup-to-function nil
58 "*A variable that contains a function that returns a followup address.
59 The function will be called in the buffer of the article that is being
60 followed up. The buffer will be narrowed to the headers of the
61 article. To pick header headers, one might use `mail-fetch-field'. The
62 function will be called with the name of the current newsgroup as the
65 Here's an example `gnus-followup-to-function':
67 (setq gnus-followup-to-function
69 (cond ((string= group \"mail.list\")
70 (or (mail-fetch-field \"sender\")
71 (mail-fetch-field \"from\")))
73 (or (mail-fetch-field \"reply-to\")
74 (mail-fetch-field \"from\"))))))")
76 (defvar gnus-reply-to-function nil
77 "*A variable that contains a function that returns a reply address.
78 See the `gnus-followup-to-function' variable for an explanation of how
79 this variable is used.
81 This function should return a string that will be used to fill in the
82 header. This function may also return a list. In that case, every
83 list element should be a cons where the first car should be a string
84 with the header name, and the cdr should be a string with the header
87 (defvar gnus-author-copy (getenv "AUTHORCOPY")
88 "*Save outgoing articles in this file.
89 Initialized from the AUTHORCOPY environment variable.
91 If this variable begins with the character \"|\", outgoing articles
92 will be piped to the named program. It is possible to save an article
93 in an MH folder as follows:
95 \(setq gnus-author-copy \"|/usr/local/lib/mh/rcvstore +Article\")
97 If the first character is not a pipe, articles are saved using the
98 function specified by the `gnus-author-copy-saver' variable.")
100 (defvar gnus-mail-self-blind nil
101 "*Non-nil means insert a BCC header in all outgoing articles.
102 This will result in having a copy of the article mailed to yourself.
103 The BCC header is inserted when the post buffer is initialized, so you
104 can remove or alter the BCC header to override the default.")
106 (defvar gnus-author-copy-saver (function rmail-output)
107 "*A function called to save outgoing articles.
108 This function will be called with the same of the file to store the
109 article in. The default function is `rmail-output' which saves in Unix
112 (defvar gnus-outgoing-message-group nil
113 "*All outgoing messages will be put in this group.
114 If you want to store all your outgoing mail and articles in the group
115 \"nnml:archive\", you set this variable to that value. This variable
116 can also be a list of group names.
118 If you want to have greater control over what group to put each
119 message in, you can set this variable to a function that checks the
120 current newsgroup name and then returns a suitable group name (or list
123 (defvar gnus-mailing-list-groups nil
124 "*Regexp matching groups that are really mailing lists.
125 This is useful when you're reading a mailing list that has been
126 gatewayed to a newsgroup, and you want to followup to an article in
129 (defvar gnus-draft-group-directory
131 (concat (file-name-as-directory gnus-article-save-directory)
133 "*The directory where draft messages will be stored.")
135 (defvar gnus-posting-styles nil
136 "*Alist of styles to use when posting.")
138 (defvar gnus-posting-style-alist
139 '((organization . gnus-organization-file)
140 (signature . gnus-signature-file)
141 (from . gnus-user-from-line)))
143 (defvar gnus-user-login-name nil
144 "*The login name of the user.
145 Got from the function `user-login-name' if undefined.")
147 (defvar gnus-user-full-name nil
148 "*The full name of the user.
149 Got from the NAME environment variable if undefined.")
151 (defvar gnus-user-from-line nil
152 "*Your full, complete e-mail address.
153 Overrides the other Gnus variables if it is non-nil.
155 Here are two example values of this variable:
157 \"Lars Magne Ingebrigtsen <larsi@ifi.uio.no>\"
161 \"larsi@ifi.uio.no (Lars Magne Ingebrigtsen)\"
163 The first version is recommended, but the name has to be quoted if it
164 contains non-alphanumerical characters.")
166 (defvar gnus-signature-file "~/.signature"
167 "*Your signature file.
168 If the variable is a string that doesn't correspond to a file, the
169 string itself is inserted.")
171 (defvar gnus-signature-function nil
172 "*A function that should return a signature file name.
173 The function will be called with the name of the newsgroup being
175 If the function returns a string that doesn't correspond to a file, the
176 string itself is inserted.
177 If the function returns nil, the `gnus-signature-file' variable will
180 (defvar gnus-forward-start-separator
181 "------- Start of forwarded message -------\n"
182 "*Delimiter inserted before forwarded messages.")
184 (defvar gnus-forward-end-separator
185 "------- End of forwarded message -------\n"
186 "*Delimiter inserted after forwarded messages.")
188 (defvar gnus-signature-before-forwarded-message t
189 "*If non-nil, put the signature before any included forwarded message.")
191 (defvar gnus-required-headers
192 '(From Date Newsgroups Subject Message-ID Organization Lines X-Newsreader)
193 "*Headers to be generated or prompted for when posting an article.
194 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
195 Message-ID. Organization, Lines, In-Reply-To, Expires, and
196 X-Newsreader are optional. If you want Gnus not to insert some
197 header, remove it from this list.")
199 (defvar gnus-required-mail-headers
200 '(From Date To Subject (optional . In-Reply-To) Message-ID Organization Lines)
201 "*Headers to be generated or prompted for when mailing a message.
202 RFC822 required that From, Date, To, Subject and Message-ID be
203 included. Organization, Lines and X-Mailer are optional.")
205 (defvar gnus-deletable-headers '(Message-ID Date)
206 "*Headers to be deleted if they already exists and were generated by Gnus previously.")
208 (defvar gnus-removable-headers '(NNTP-Posting-Host Bcc Xref)
209 "*Headers to be removed unconditionally before posting.")
211 (defvar gnus-article-expires 14
212 "*Number of days before your article expires.
213 This variable isn't used unless you have the `Expires' element in
214 `gnus-required-headers'.")
216 (defvar gnus-distribution-function nil
217 "*Function that should return the Distribution header for outgoing articles.
218 It will be called from the buffer where the outgoing article
219 is being prepared with the group name as the only parameter.
220 It should return a valid distribution.
222 The function will only be called if you have the `Distribution' header in
223 `gnus-required-headers'.")
225 (defvar gnus-check-before-posting
226 '(subject-cmsg multiple-headers sendsys message-id from
227 long-lines control-chars size new-text
228 signature approved sender)
229 "In non-nil, Gnus will attempt to run some checks on outgoing posts.
230 If this variable is t, Gnus will check everything it can. If it is a
231 list, then those elements in that list will be checked.")
233 (defvar gnus-delete-supersedes-headers
234 "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Supersedes:\\|^Xref:\\|^Lines:"
235 "*Header lines matching this regexp will be deleted before posting.
236 It's best to delete old Path and Date headers before posting to avoid
239 (defvar gnus-auto-mail-to-author nil
240 "*If non-nil, mail the authors of articles a copy of your follow-ups.
241 If this variable is `ask', the user will be prompted for whether to
242 mail a copy. The string given by `gnus-mail-courtesy-message' will be
243 inserted at the beginning of the mail copy.")
245 ;; Added by Ethan Bradford <ethanb@ptolemy.astro.washington.edu>.
246 (defvar gnus-mail-courtesy-message
247 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
248 "*This is inserted at the start of a mailed copy of a posted message.
249 If this variable is nil, no such courtesy message will be added.")
251 (defvar gnus-mail-reply-method (function gnus-mail-reply-using-mail)
252 "*Function to compose a reply.
253 Three pre-made functions are `gnus-mail-reply-using-mail' (sendmail);
254 `gnus-mail-reply-using-mhe' (MH-E); and `gnus-mail-reply-using-vm'.")
256 (defvar gnus-mail-forward-method (function gnus-mail-forward-using-mail)
257 "*Function to forward the current message to another user.
258 Three pre-made functions are `gnus-mail-forward-using-mail' (sendmail);
259 `gnus-mail-forward-using-mhe' (MH-E); and `gnus-mail-forward-using-vm'.")
261 (defvar gnus-mail-other-window-method 'gnus-mail-other-window-using-mail
262 "*Function to compose mail in the other window.
263 Three pre-made functions are `gnus-mail-other-window-using-mail'
264 (sendmail); `gnus-mail-other-window-using-mhe' (MH-E); and
265 `gnus-mail-other-window-using-vm'.")
267 (defvar gnus-inews-article-function 'gnus-inews-article
268 "*Function to post an article.")
270 (defvar gnus-bounced-headers-junk "^\\(Received\\):"
271 "*Regexp that matches headers to be removed in resent bounced mail.")
273 (defvar gnus-inews-article-hook (list 'gnus-inews-do-fcc)
274 "*A hook called before finally posting an article.
275 The default hook (`gnus-inews-do-fcc') does FCC processing (ie. saves
276 the article to a file).")
278 (defvar gnus-inews-article-header-hook nil
279 "*A hook called after inserting the headers in an article to be posted.
280 The hook is called from the *post-news* buffer, narrowed to the
283 (defvar gnus-mail-hook nil
284 "*A hook called as the last thing after setting up a mail buffer.")
286 (defvar gnus-message-sent-hook nil
287 "*A hook run after an article has been sent (or attempted sent).")
289 ;;; Internal variables.
291 (defvar gnus-post-news-buffer "*post-news*")
292 (defvar gnus-mail-buffer "*mail*")
293 (defvar gnus-summary-send-map nil)
294 (defvar gnus-send-bounce-map nil)
295 (defvar gnus-article-copy nil)
296 (defvar gnus-reply-subject nil)
297 (defvar gnus-add-to-address nil)
298 (defvar gnus-in-reply-to nil)
301 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
302 (autoload 'news-setup "rnewspost")
303 (autoload 'news-reply-mode "rnewspost")
304 (autoload 'rmail-output "rmailout"))
308 ;;; Gnus Posting Functions
311 (define-prefix-command 'gnus-summary-send-map)
312 (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
313 (define-key gnus-summary-send-map "p" 'gnus-summary-post-news)
314 (define-key gnus-summary-send-map "f" 'gnus-summary-followup)
315 (define-key gnus-summary-send-map "F" 'gnus-summary-followup-with-original)
316 (define-key gnus-summary-send-map "b" 'gnus-summary-followup-and-reply)
317 (define-key gnus-summary-send-map "B" 'gnus-summary-followup-and-reply-with-original)
318 (define-key gnus-summary-send-map "c" 'gnus-summary-cancel-article)
319 (define-key gnus-summary-send-map "s" 'gnus-summary-supersede-article)
320 (define-key gnus-summary-send-map "r" 'gnus-summary-reply)
321 (define-key gnus-summary-send-map "R" 'gnus-summary-reply-with-original)
322 (define-key gnus-summary-send-map "m" 'gnus-summary-mail-other-window)
323 (define-key gnus-summary-send-map "u" 'gnus-uu-post-news)
324 (define-key gnus-summary-send-map "om" 'gnus-summary-mail-forward)
325 (define-key gnus-summary-send-map "op" 'gnus-summary-post-forward)
326 (define-key gnus-summary-send-map "Om" 'gnus-uu-digest-mail-forward)
327 (define-key gnus-summary-send-map "Op" 'gnus-uu-digest-post-forward)
329 (define-prefix-command 'gnus-send-bounce-map)
330 (define-key gnus-summary-send-map "D" 'gnus-send-bounce-map)
331 (define-key gnus-send-bounce-map "b" 'gnus-summary-resend-bounced-mail)
332 (define-key gnus-send-bounce-map "c" 'gnus-summary-send-draft)
333 (define-key gnus-send-bounce-map "r" 'gnus-summary-resend-message)
335 ;;; Internal functions.
337 (defun gnus-number-base36 (num len)
338 (if (if (< len 0) (<= num 0) (= len 0))
340 (concat (gnus-number-base36 (/ num 36) (1- len))
341 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
344 ;;; Post news commands of Gnus group mode and summary mode
346 (defun gnus-group-mail ()
347 "Start composing a mail."
350 ;; We might want to prompt here.
351 (when (and gnus-interactive-post
352 (not gnus-expert-user))
353 (read-string "To: "))))
355 (defun gnus-group-post-news (&optional arg)
357 The newsgroup under the cursor is used as the group to post to.
359 If you wish to get an empty post buffer, use a prefix ARG. You can
360 also do this by calling this function from the bottom of the Group
363 (let ((gnus-newsgroup-name nil)
364 (group (unless arg (gnus-group-group-name)))
366 ;; We might want to prompt here.
367 (when (and gnus-interactive-post
368 (not gnus-expert-user))
369 (setq gnus-newsgroup-name
371 (completing-read "Group: " gnus-active-hashtb nil nil
372 (cons (or group "") 0)))))
373 (gnus-post-news 'post group nil gnus-article-buffer)))
375 (defun gnus-summary-post-news ()
378 (gnus-set-global-variables)
379 (gnus-post-news 'post gnus-newsgroup-name))
381 (defun gnus-summary-followup (yank &optional yank-articles)
382 "Compose a followup to an article.
383 If prefix argument YANK is non-nil, original article is yanked automatically."
385 (gnus-set-global-variables)
386 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
387 (save-window-excursion
388 (gnus-summary-select-article))
389 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
390 (gnus-newsgroup-name gnus-newsgroup-name))
391 ;; Check Followup-To: poster.
392 (set-buffer gnus-article-buffer)
393 (if (and gnus-use-followup-to
394 (string-equal "poster" (gnus-fetch-field "followup-to"))
395 (or (not (memq gnus-use-followup-to '(t ask)))
397 "Do you want to ignore `Followup-To: poster'? "))))
398 ;; Mail to the poster.
399 (gnus-summary-reply yank)
401 (gnus-post-news nil gnus-newsgroup-name
402 headers gnus-article-buffer
403 (or yank-articles (not (not yank)))))))
405 (defun gnus-summary-followup-with-original (n)
406 "Compose a followup to an article and include the original article."
408 (gnus-summary-followup t (gnus-summary-work-articles n)))
410 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
411 (defun gnus-summary-followup-and-reply (yank &optional yank-articles)
412 "Compose a followup and do an auto mail to author."
414 (gnus-set-global-variables)
415 (let ((gnus-auto-mail-to-author 'force))
416 (gnus-summary-followup yank yank-articles)))
418 (defun gnus-summary-followup-and-reply-with-original (n)
419 "Compose a followup, include the original, and do an auto mail to author."
421 (gnus-summary-followup-and-reply t (gnus-summary-work-articles n)))
423 (defun gnus-summary-cancel-article (n)
424 "Cancel an article you posted."
426 (gnus-set-global-variables)
427 (let ((articles (gnus-summary-work-articles n))
429 (while (setq article (pop articles))
430 (when (gnus-summary-select-article t nil nil article)
431 (when (gnus-eval-in-buffer-window
432 gnus-original-article-buffer (gnus-cancel-news))
433 (gnus-summary-mark-as-read article gnus-canceled-mark))
434 (gnus-article-hide-headers-if-wanted))
435 (gnus-summary-remove-process-mark article))))
437 (defun gnus-summary-supersede-article ()
438 "Compose an article that will supersede a previous article.
439 This is done simply by taking the old article and adding a Supersedes
440 header line with the old Message-ID."
442 (gnus-set-global-variables)
443 (gnus-summary-select-article t)
444 ;; Check whether the user owns the article that is to be superseded.
445 (unless (string-equal
446 (downcase (mail-strip-quoted-names
447 (mail-header-from gnus-current-headers)))
448 (downcase (mail-strip-quoted-names (gnus-inews-user-name))))
449 (error "This article is not yours."))
450 ;; Get a normal *post-news* buffer.
451 (gnus-new-news gnus-newsgroup-name t)
453 (insert-buffer-substring gnus-original-article-buffer)
454 (gnus-narrow-to-headers)
455 ;; Remove unwanted headers.
456 (when gnus-delete-supersedes-headers
457 (nnheader-remove-header gnus-delete-supersedes-headers t))
458 (goto-char (point-min))
459 (if (not (re-search-forward "^Message-ID: " nil t))
460 (error "No Message-ID in this article")
461 (replace-match "Supersedes: " t t))
462 (goto-char (point-max))
463 (insert mail-header-separator)
469 (defalias 'sendnews 'gnus-post-news)
472 (defalias 'postnews 'gnus-post-news)
474 (defun gnus-copy-article-buffer (&optional article-buffer)
475 ;; make a copy of the article buffer with all text properties removed
476 ;; this copy is in the buffer gnus-article-copy.
477 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
478 ;; this buffer should be passed to all mail/news reply/post routines.
479 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
480 (buffer-disable-undo gnus-article-copy)
481 (or (memq gnus-article-copy gnus-buffer-list)
482 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
483 (let ((article-buffer (or article-buffer gnus-article-buffer)))
484 (if (and (get-buffer article-buffer)
485 (buffer-name (get-buffer article-buffer)))
487 (set-buffer article-buffer)
489 (copy-to-buffer gnus-article-copy (point-min) (point-max))
490 (set-text-properties (point-min) (point-max)
491 nil gnus-article-copy)))))
493 (defun gnus-post-news (post &optional group header article-buffer yank subject)
494 "Begin editing a new USENET news article to be posted.
495 Type \\[describe-mode] in the buffer to get a list of commands."
496 (interactive (list t))
497 (let* ((group (or group gnus-newsgroup-name))
499 to-address to-group mailing-list to-list)
501 (setq to-address (gnus-group-get-parameter group 'to-address)
502 to-group (gnus-group-get-parameter group 'to-group)
503 to-list (gnus-group-get-parameter group 'to-list)
504 mailing-list (when gnus-mailing-list-groups
505 (string-match gnus-mailing-list-groups group))
506 group (gnus-group-real-name group)))
508 (and (gnus-news-group-p
509 (or pgroup gnus-newsgroup-name)
510 (if header (mail-header-number header) gnus-current-article))
516 (gnus-new-news (or to-group group))
517 (gnus-news-followup yank (or to-group group)))
521 (gnus-new-mail (or to-address to-list))
522 ;; Arrange for mail groups that have no `to-address' to
523 ;; get that when the user sends off the mail.
525 (make-local-variable 'gnus-add-to-address)
526 (setq gnus-add-to-address group)))
527 (gnus-mail-reply yank to-address 'followup)))))
529 (defun gnus-news-group-p (group &optional article)
530 "Return non-nil if GROUP (and ARTICLE) come from a news server."
531 (or (gnus-member-of-valid 'post group) ; Ordinary news group.
532 (and (gnus-member-of-valid 'post-mail group) ; Combined group.
533 (eq (gnus-request-type group article) 'post))))
535 (defun gnus-inews-news (&optional use-group-method)
536 "Send a news message.
537 If given a prefix, and the group is a foreign group, this function
538 will attempt to use the foreign server to post the article."
540 (or gnus-current-select-method
541 (setq gnus-current-select-method gnus-select-method))
542 (let* ((case-fold-search nil)
543 (reply gnus-article-reply)
546 (gnus-start-news-server) ;Use default server.
548 (goto-char (point-min))
549 (run-hooks 'news-inews-hook)
552 (gnus-message 5 "Posting to USENET...")
553 (setq post-result (funcall gnus-inews-article-function use-group-method))
554 (cond ((eq post-result 'illegal)
558 (gnus-message 5 "Posting to USENET...done")
559 (if (gnus-buffer-exists-p (car-safe reply))
562 (set-buffer gnus-summary-buffer)
563 (gnus-summary-mark-article-as-replied
565 (set-buffer-modified-p nil))
567 ;; We cannot signal an error.
571 1 "Article rejected: %s"
573 (gnus-post-method gnus-newsgroup-name use-group-method))))))
575 (let ((conf gnus-prev-winconf))
578 ;; Restore last window configuration.
579 (and conf (set-window-configuration conf))))))
581 (defun gnus-inews-narrow-to-headers ()
584 (goto-char (point-min))
585 (or (and (re-search-forward
586 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
590 (defun gnus-inews-send-mail-copy ()
591 ;; Mail the message if To, Bcc or Cc exists.
592 (let* ((types '("to" "bcc" "cc"))
594 (buffer (current-buffer))
598 (gnus-inews-narrow-to-headers)
601 (or (mail-fetch-field (car ty) nil t)
602 (setq types (delete (car ty) types)))
606 ;; We do not want to send mail.
608 (gnus-message 5 "Sending via mail...")
611 ;; We copy the article over to a temp buffer since we are
612 ;; going to modify it a little.
613 (nnheader-set-temp-buffer " *Gnus-mailing*")
614 (insert-buffer-substring buffer)
615 ;; We remove Fcc, because we don't want the mailer to see
617 (gnus-inews-narrow-to-headers)
618 (nnheader-remove-header "fcc")
620 ;; Insert the X-Courtesy-Message header.
621 (and (or (member "to" types)
624 (goto-char (point-max))
625 (insert "Posted-To: "
626 (mail-fetch-field "newsgroups") "\n")))
630 (if (and gnus-mail-courtesy-message
631 (or (member "to" types)
632 (member "cc" types)))
633 ;; We only want to insert the courtesy mail message if
634 ;; we use To or Cc; Bcc should not have one. Well, if
635 ;; both Bcc and To are present, it will get one
638 ;; Insert "courtesy" mail message.
639 (goto-char (point-min))
641 (concat "^" (regexp-quote mail-header-separator) "$"))
643 (insert gnus-mail-courtesy-message)))
646 (kill-buffer (current-buffer))
647 (gnus-message 5 "Sending via mail...done"))))))
649 (defun gnus-inews-remove-headers-after-mail ()
652 (let ((case-fold-search t))
653 (gnus-inews-narrow-to-headers)
654 ;; Remove Bcc completely.
655 (nnheader-remove-header "bcc")
656 ;; We transform To and Cc headers to avoid re-mailing if the user
657 ;; accidentally (or purposefully) leans on the `C-c C-c' keys
658 ;; and the news server rejects the posting.
659 (while (re-search-forward "^\\(to\\|[bcf]cc\\|cc\\):" nil t)
664 (defun gnus-inews-dex-headers ()
665 "Remove \"X-\" prefixes from To and Cc headers."
668 (let ((case-fold-search t))
669 (gnus-narrow-to-headers)
670 (while (re-search-forward "^X-\\(to\\|[bcf]cc\\|cc\\):" nil t)
675 (defun gnus-inews-remove-empty-headers ()
676 "Remove empty headers from news and mail.
677 The buffer should be narrowed to the headers before this function is
680 (goto-char (point-min))
681 (while (re-search-forward "^[^ \t:]+:\\([ \t]*\n\\)+[^ \t]" nil t)
682 (delete-region (match-beginning 0) (1- (match-end 0)))
683 (beginning-of-line))))
685 (defun gnus-inews-check-post ()
686 "Check whether the post looks ok."
688 (not gnus-check-before-posting)
690 ;; We narrow to the headers and check them first.
693 (goto-char (point-min))
698 (concat "^" (regexp-quote mail-header-separator) "$"))
699 (match-beginning 0)))
700 (goto-char (point-min))
702 ;; Check for commands in Subject.
704 (gnus-check-before-posting 'subject-cmsg)
706 (if (string-match "^cmsg " (mail-fetch-field "subject"))
708 "The control code \"cmsg \" is in the subject. Really post? ")
710 ;; Check for multiple identical headers.
711 (or (gnus-check-before-posting 'multiple-headers)
714 (while (and (not found) (re-search-forward "^[^ \t:]+: "
717 (or (re-search-forward
718 (concat "^" (setq found
721 (- (match-end 0) 2))))
726 (format "Multiple %s headers. Really post? " found))
728 ;; Check for Version and Sendsys.
729 (or (gnus-check-before-posting 'sendsys)
731 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
733 (format "The article contains a %s command. Really post? "
734 (buffer-substring (match-beginning 0)
735 (1- (match-end 0)))))
737 ;; Check for Approved.
738 (or (gnus-check-before-posting 'approved)
740 (if (re-search-forward "^Approved:" nil t)
742 "The article contains an Approved header. Really post? ")
744 ;; Check the Message-ID header.
745 (or (gnus-check-before-posting 'message-id)
747 (let* ((case-fold-search t)
748 (message-id (mail-fetch-field "message-id")))
750 (and (string-match "@" message-id)
751 (string-match "@[^\\.]*\\." message-id))
754 "The Message-ID looks strange: \"%s\". Really post? "
756 ;; Check the From header.
757 (or (gnus-check-before-posting 'from)
759 (let* ((case-fold-search t)
760 (from (mail-fetch-field "from")))
763 (gnus-y-or-n-p "There is no From line. Really post? "))
764 ((not (string-match "@[^\\.]*\\." from))
767 "The address looks strange: \"%s\". Really post? " from)))
768 ((string-match "(.*).*(.*)" from)
771 "The From header looks strange: \"%s\". Really post? "
773 ((string-match "<[^>]+> *$" from)
774 (let ((name (substring from 0 (match-beginning 0))))
776 (string-match "^ *\"[^\"]*\" *$" name)
777 (not (string-match "[][.!()<>@,;:\\]" name))
780 "The From header name has bogus characters. Really post? "
784 ;; Check for long lines.
785 (or (gnus-check-before-posting 'long-lines)
787 (goto-char (point-min))
789 (concat "^" (regexp-quote mail-header-separator) "$"))
793 (< (current-column) 80))
794 (zerop (forward-line 1))))
799 "You have lines longer than 79 characters. Really post? ")))))
800 ;; Check for control characters.
801 (or (gnus-check-before-posting 'control-chars)
803 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
805 "The article contains control characters. Really post? ")
807 ;; Check excessive size.
808 (or (gnus-check-before-posting 'size)
809 (if (> (buffer-size) 60000)
811 (format "The article is %d octets long. Really post? "
814 ;; Use the (size . checksum) variable to see whether the
815 ;; article is empty or has only quoted text.
817 (gnus-check-before-posting 'new-text)
818 (if (and (= (buffer-size) (car gnus-article-check-size))
819 (= (gnus-article-checksum) (cdr gnus-article-check-size)))
821 "It looks like there's no new text in your article. Really post? ")
823 ;; Check the length of the signature.
824 (or (gnus-check-before-posting 'signature)
826 (goto-char (point-max))
827 (if (not (re-search-backward gnus-signature-separator nil t))
829 (if (> (count-lines (point) (point-max)) 5)
832 "Your .sig is %d lines; it should be max 4. Really post? "
833 (count-lines (point) (point-max))))
836 (defun gnus-article-checksum ()
840 (setq sum (logxor sum (following-char)))
844 ;; Returns non-nil if this type is not to be checked.
845 (defun gnus-check-before-posting (type)
847 (or (not gnus-check-before-posting)
848 (if (listp gnus-check-before-posting)
849 (memq type gnus-check-before-posting)
852 (defun gnus-cancel-news ()
853 "Cancel an article you posted."
855 (if (or gnus-expert-user
856 (gnus-yes-or-no-p "Do you really want to cancel this article? "))
861 (or (gnus-news-group-p gnus-newsgroup-name)
862 (error "This backend does not support canceling"))
864 ;; Get header info. from original article.
866 (gnus-article-show-all-headers)
867 (goto-char (point-min))
868 (search-forward "\n\n" nil 'move)
869 (narrow-to-region (point-min) (point))
870 (setq from (mail-fetch-field "from"))
871 (setq newsgroups (mail-fetch-field "newsgroups"))
872 (setq message-id (mail-fetch-field "message-id"))
873 (setq distribution (mail-fetch-field "distribution")))
874 ;; Verify if the article is absolutely user's by comparing
875 ;; user id with value of its From: field.
878 (downcase (mail-strip-quoted-names from))
879 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
881 (ding) (gnus-message 3 "This article is not yours.")
883 ;; Make control article.
884 (set-buffer (get-buffer-create " *Gnus-canceling*"))
885 (buffer-disable-undo (current-buffer))
887 (insert "Newsgroups: " newsgroups "\n"
888 "From: " (gnus-inews-real-user-address) "\n"
889 "Subject: cancel " message-id "\n"
890 "Control: cancel " message-id "\n"
892 (concat "Distribution: " distribution "\n")
894 mail-header-separator "\n"
895 "This is a cancel message from " from ".\n")
896 ;; Send the control article to NNTP server.
897 (gnus-message 5 "Canceling your article...")
899 (if (funcall gnus-inews-article-function)
900 (gnus-message 5 "Canceling your article...done")
903 (gnus-message 1 "Cancel failed; %s"
904 (gnus-status-message gnus-newsgroup-name))
907 ;; Kill the article buffer.
908 (kill-buffer (current-buffer))))))))
911 ;;; Lowlevel inews interface.
913 ;; Dummy to avoid byte-compile warning.
914 (defvar nnspool-rejected-article-hook)
916 (defun gnus-inews-article (&optional use-group-method)
917 "Post an article in current buffer using NNTP protocol."
918 (let ((artbuf (current-buffer))
921 (goto-char (point-max))
922 ;; Require a newline at the end of the buffer since inews may
923 ;; append a .signature.
924 (or (= (preceding-char) ?\n)
926 ;; Prepare article headers. All message body such as signature
927 ;; must be inserted before Lines: field is prepared.
929 (gnus-inews-narrow-to-headers)
931 (gnus-inews-cleanup-headers)
932 ;; Remove some headers.
933 (gnus-inews-remove-headers)
934 ;; Insert some headers.
935 (gnus-inews-insert-headers)
936 ;; Let the user do all of the above.
937 (run-hooks 'gnus-inews-article-header-hook)
938 ;; Copy the Gcc header, if any.
939 (setq gcc (mail-fetch-field "gcc"))
941 ;; Check whether the article is a good Net Citizen.
942 (if (and gnus-article-check-size
943 (not (gnus-inews-check-post)))
946 ;; We fudge a hook for nnspool.
947 (setq nnspool-rejected-article-hook
953 (set-buffer (, (buffer-name)))
954 (gnus-put-in-draft-group nil 'silent))
958 1 "Couldn't enter rejected article into draft group")))))))
960 ;; Looks ok, so we do the nasty.
962 ;; This hook may insert a signature.
964 (goto-char (point-min))
965 (let ((gnus-newsgroup-name (or (mail-fetch-field "newsgroups")
966 gnus-newsgroup-name)))
967 (run-hooks 'gnus-prepare-article-hook)))
968 ;; Send off copies using mail, if that is wanted.
969 (gnus-inews-send-mail-copy)
970 ;; Remove more headers.
971 (gnus-inews-remove-headers-after-mail)
972 ;; Copy the article over to a temp buffer.
973 (nnheader-set-temp-buffer " *Gnus-posting*")
974 (insert-buffer-substring artbuf)
975 ;; Remove the header separator.
976 (goto-char (point-min))
978 (concat "^" (regexp-quote mail-header-separator) "$"))
979 (replace-match "" t t)
980 ;; Remove X- prefixes to headers.
981 (gnus-inews-dex-headers)
982 ;; Run final inews hooks. This hook may do FCC.
983 ;; The article must be saved before being posted because
984 ;; `gnus-request-post' modifies the buffer.
985 (run-hooks 'gnus-inews-article-hook)
986 ;; Copy the article over to some group, possibly.
987 (and gcc (gnus-inews-do-gcc gcc))
989 (let ((method (gnus-post-method gnus-newsgroup-name use-group-method)))
990 (setq result (gnus-request-post method)))
991 (kill-buffer (current-buffer)))
992 (run-hooks 'gnus-message-sent-hook)
993 ;; If the posting was unsuccessful (that it, it was rejected) we
994 ;; put it into the draft group.
995 (or result (gnus-put-in-draft-group))
998 (defun gnus-inews-cleanup-headers ()
999 ;; Correct newsgroups field: change sequence of spaces to comma and
1000 ;; eliminate spaces around commas. Eliminate imbedded line breaks.
1001 (goto-char (point-min))
1002 (if (re-search-forward "^Newsgroups: +" nil t)
1006 (if (re-search-forward "^[^ \t]" nil t)
1010 (goto-char (point-min))
1011 (while (re-search-forward "\n[ \t]+" nil t)
1012 (replace-match " " t t)) ;No line breaks (too confusing)
1013 (goto-char (point-min))
1014 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
1015 (replace-match "," t t))
1016 (goto-char (point-min))
1017 ;; Remove a trailing comma.
1018 (if (re-search-forward ",$" nil t)
1019 (replace-match "" t t))))
1021 ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
1022 ;; Help save the the world!
1025 (let ((newsgroups (mail-fetch-field "newsgroups"))
1026 (followup-to (mail-fetch-field "followup-to"))
1029 (string-match "," newsgroups) (not followup-to))
1031 (while (string-match "," newsgroups)
1033 (cons (list (substring newsgroups 0 (match-beginning 0)))
1035 (setq newsgroups (substring newsgroups (match-end 0))))
1036 (setq groups (nreverse (cons (list newsgroups) groups)))
1038 (setq to (completing-read
1039 "Followups to: (default all groups) " groups))
1040 (if (> (length to) 0)
1042 (goto-char (point-min))
1043 (insert "Followup-To: " to "\n")))))))
1045 ;; Cleanup Followup-To.
1046 (goto-char (point-min))
1047 (if (search-forward-regexp "^Followup-To: +" nil t)
1051 (if (re-search-forward "^[^ \t]" nil 'end)
1054 (goto-char (point-min))
1055 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
1056 (goto-char (point-min))
1057 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ","))))
1060 (defun gnus-inews-remove-headers ()
1061 (let ((case-fold-search t)
1062 (headers gnus-removable-headers))
1063 ;; Remove toxic headers.
1065 (goto-char (point-min))
1066 (and (re-search-forward
1067 (concat "^" (downcase (format "%s" (car headers))))
1069 (delete-region (progn (beginning-of-line) (point))
1070 (progn (forward-line 1) (point))))
1071 (setq headers (cdr headers)))))
1073 ;;; Since the X-Newsreader/X-Mailer are ``vanity'' headers, they might
1074 ;;; as well include the Emacs version as well.
1075 ;;; The following function works with later GNU Emacs, and XEmacs.
1076 (defun gnus-extended-version ()
1077 "Stringified Gnus version and Emacs version"
1083 ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
1084 (concat "Emacs " (substring emacs-version
1087 ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)" emacs-version)
1088 (concat (substring emacs-version
1091 (format " %d.%d" emacs-major-version emacs-minor-version)))
1092 (t emacs-version))))
1094 (defun gnus-inews-insert-headers (&optional headers)
1095 "Prepare article headers.
1096 Headers already prepared in the buffer are not modified.
1097 Headers in `gnus-required-headers' will be generated."
1098 (let* ((Date (gnus-inews-date))
1099 (Message-ID (gnus-inews-message-id))
1100 (Organization (gnus-inews-organization))
1101 (From (gnus-inews-user-name))
1102 (Path (gnus-inews-path))
1105 (In-Reply-To (gnus-inews-in-reply-to))
1107 (Distribution (gnus-inews-distribution))
1108 (Lines (gnus-inews-lines))
1109 (X-Newsreader (gnus-extended-version))
1110 (X-Mailer X-Newsreader)
1111 (Expires (gnus-inews-expires))
1112 (headers (or headers gnus-required-headers))
1113 (case-fold-search t)
1115 ;; First we remove any old generated headers.
1116 (let ((headers gnus-deletable-headers))
1118 (goto-char (point-min))
1119 (and (re-search-forward
1120 (concat "^" (symbol-name (car headers)) ": *") nil t)
1121 (get-text-property (1+ (match-beginning 0)) 'gnus-deletable)
1123 (setq headers (cdr headers))))
1124 ;; If there are References, and no "Re: ", then the thread has
1125 ;; changed name. See Son-of-1036.
1126 (if (and (mail-fetch-field "references")
1127 (get-buffer gnus-article-buffer))
1128 (let ((psubject (gnus-simplify-subject-re
1129 (mail-fetch-field "subject"))))
1130 (or (and psubject gnus-reply-subject
1131 (string= (gnus-simplify-subject-re gnus-reply-subject)
1134 (string-match "@" Message-ID)
1136 (concat (substring Message-ID 0 (match-beginning 0))
1138 (substring Message-ID (match-beginning 0))))))))
1139 ;; Go through all the required headers and see if they are in the
1140 ;; articles already. If they are not, or are empty, they are
1141 ;; inserted automatically - except for Subject, Newsgroups and
1144 (goto-char (point-min))
1145 (setq elem (pop headers))
1147 (setq header (car elem))
1149 (when (or (not (re-search-forward
1150 (concat "^" (downcase (symbol-name header)) ":") nil t))
1152 ;; The header was found. We insert a space after the
1153 ;; colon, if there is none.
1154 (if (/= (following-char) ? ) (insert " "))
1155 ;; Find out whether the header is empty...
1156 (looking-at "[ \t]*$")))
1157 ;; So we find out what value we should insert.
1160 ((and (consp elem) (eq (car elem) 'optional))
1161 ;; This is an optional header. If the cdr of this
1162 ;; is something that is nil, then we do not insert
1164 (setq header (cdr elem))
1165 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
1166 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
1168 ;; The element is a cons. Either the cdr is a
1169 ;; string to be inserted verbatim, or it is a
1170 ;; function, and we insert the value returned from
1172 (or (and (stringp (cdr elem)) (cdr elem))
1173 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
1174 ((and (boundp header) (symbol-value header))
1175 ;; The element is a symbol. We insert the value
1176 ;; of this symbol, if any.
1177 (symbol-value header))
1179 ;; We couldn't generate a value for this header,
1180 ;; so we just ask the user.
1181 (read-from-minibuffer
1182 (format "Empty header for %s; enter value: " header)))))
1183 ;; Finally insert the header.
1185 (not (equal value "")))
1189 ;; This header didn't exist, so we insert it.
1190 (goto-char (point-max))
1191 (insert (symbol-name header) ": " value "\n")
1193 ;; The value of this header was empty, so we clear
1194 ;; totally and insert the new value.
1195 (delete-region (point) (gnus-point-at-eol))
1197 ;; Add the deletable property to the headers that require it.
1198 (and (memq header gnus-deletable-headers)
1199 (progn (beginning-of-line) (looking-at "[^:]+: "))
1200 (add-text-properties
1201 (point) (match-end 0)
1202 '(gnus-deletable t face italic) (current-buffer)))))))
1203 ;; Insert new Sender if the From is strange.
1204 (let ((from (mail-fetch-field "from"))
1205 (sender (mail-fetch-field "sender")))
1207 (not (gnus-check-before-posting 'sender))
1209 (downcase (car (cdr (gnus-extract-address-components from))))
1210 (downcase (gnus-inews-real-user-address))))
1214 (downcase (car (cdr (gnus-extract-address-components sender))))
1215 (downcase (gnus-inews-real-user-address))))))
1217 (goto-char (point-min))
1218 (and (re-search-forward "^Sender:" nil t)
1221 (insert "Original-")
1222 (beginning-of-line)))
1223 (insert "Sender: " (gnus-inews-real-user-address) "\n"))))))
1226 (defun gnus-inews-insert-signature ()
1227 "Insert a signature file.
1228 If `gnus-signature-function' is bound and returns a string, this
1229 string is used instead of the variable `gnus-signature-file'.
1230 In either case, if the string is a file name, this file is
1231 inserted. If the string is not a file name, the string itself is
1234 If you never want any signature inserted, set both of these variables to
1238 (or (and gnus-signature-function
1239 (funcall gnus-signature-function gnus-newsgroup-name))
1240 gnus-signature-file)))
1242 (or (file-exists-p signature)
1243 (string-match " " signature)
1245 "^/[^/]+/" (expand-file-name signature)))))
1247 (goto-char (point-max))
1248 (if (and mail-signature (search-backward "\n-- \n" nil t))
1250 ;; Delete any previous signatures.
1251 (if (search-backward "\n-- \n" nil t)
1252 (delete-region (point) (point-max)))
1253 (or (eolp) (insert "\n"))
1255 (if (file-exists-p signature)
1256 (insert-file-contents signature)
1258 (goto-char (point-max))
1259 (or (bolp) (insert "\n"))))))))
1261 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1262 (defun gnus-inews-insert-mime-headers ()
1263 (goto-char (point-min))
1264 (let ((mail-header-separator
1266 (goto-char (point-min))
1267 (if (and (search-forward (concat "\n" mail-header-separator "\n")
1269 (not (search-backward "\n\n" nil t)))
1270 mail-header-separator
1272 (or (mail-position-on-field "Mime-Version")
1275 (goto-char (point-min))
1276 (re-search-forward "[\200-\377]" nil t))
1277 (or (mail-position-on-field "Content-Type")
1278 (insert "text/plain; charset=ISO-8859-1"))
1279 (or (mail-position-on-field "Content-Transfer-Encoding")
1281 (t (or (mail-position-on-field "Content-Type")
1282 (insert "text/plain; charset=US-ASCII"))
1283 (or (mail-position-on-field "Content-Transfer-Encoding")
1284 (insert "7bit")))))))
1286 (defun gnus-inews-do-fcc ()
1287 "Process Fcc headers in the current buffer.
1288 Unless the first character of the field is `|', the article is saved
1289 to the specified file using the function specified by the variable
1290 gnus-author-copy-saver. The default function rmail-output saves in
1291 Unix mailbox format.
1293 If the first character is `|', the contents of the article is sent to
1294 a program specified by the rest of the value."
1295 (let ((case-fold-search t) ;Should ignore case.
1299 (gnus-narrow-to-headers)
1300 (while (setq file (mail-fetch-field "fcc"))
1302 (nnheader-remove-header "fcc" nil t))
1303 ;; Process FCC operations.
1306 (setq file (pop list))
1307 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
1308 ;; Pipe the article to the program in question.
1309 (call-process-region (point-min) (point-max) shell-file-name
1310 nil nil nil "-c" (match-string 1 file))
1311 ;; Save the article.
1312 (setq file (expand-file-name file))
1313 (gnus-make-directory (file-name-directory file))
1314 (if (and gnus-author-copy-saver
1315 (not (eq gnus-author-copy-saver 'rmail-output)))
1316 (funcall gnus-author-copy-saver file)
1317 (if (and (file-readable-p file) (mail-file-babyl-p file))
1318 (gnus-output-to-rmail file)
1319 (let ((mail-use-rfc822 t))
1320 (rmail-output file 1 t t))))))))))
1322 (defun gnus-inews-path ()
1324 (let ((login-name (gnus-inews-login-name)))
1325 (cond ((null gnus-use-generic-path)
1326 (concat (nth 1 gnus-select-method) "!" login-name))
1327 ((stringp gnus-use-generic-path)
1328 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1329 (concat gnus-use-generic-path "!" login-name))
1332 (defun gnus-inews-user-name ()
1333 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1334 (let ((full-name (gnus-inews-full-name))
1335 (address (if (or gnus-user-login-name gnus-use-generic-from
1336 gnus-local-domain (getenv "DOMAINNAME"))
1337 (concat (gnus-inews-login-name) "@"
1338 (gnus-inews-domain-name gnus-use-generic-from))
1339 user-mail-address)))
1340 (or gnus-user-from-line
1342 ;; User's full name.
1343 (cond ((string-equal full-name "&") ;Unix hack.
1344 (concat " (" (user-login-name) ")"))
1345 ((string-match "[^ ]+@[^ ]+ +(.*)" address)
1348 (concat " (" full-name ")")))))))
1350 (defun gnus-inews-real-user-address ()
1351 "Return the \"real\" user address.
1352 This function tries to ignore all user modifications, and
1353 give as trustworthy answer as possible."
1354 (concat (user-login-name) "@" (gnus-inews-full-address)))
1356 (defun gnus-inews-login-name ()
1357 "Return login name."
1358 (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1360 (defun gnus-inews-full-name ()
1361 "Return full user name."
1362 (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1364 (defun gnus-inews-domain-name (&optional genericfrom)
1365 "Return user's domain name.
1366 If optional argument GENERICFROM is a string, use it as the domain
1367 name; if it is non-nil, strip off local host name from the domain name.
1368 If the function `system-name' returns full internet name and the
1369 domain is undefined, the domain name is got from it."
1370 (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1371 (let* ((system-name (system-name))
1373 (or (if (stringp genericfrom) genericfrom)
1374 (getenv "DOMAINNAME")
1376 ;; Function `system-name' may return full internet name.
1377 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1378 (if (string-match "\\.." system-name)
1379 ;; Some machines return "name.", and that's not
1381 (substring system-name (1- (match-end 0))))
1382 (read-string "Domain name (no host): ")))
1383 (host (or (if (string-match "\\." system-name)
1384 (substring system-name 0 (match-beginning 0)))
1386 (if (string-equal "." (substring domain 0 1))
1387 (setq domain (substring domain 1)))
1388 ;; Support GENERICFROM as same as standard Bnews system.
1389 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1390 (cond ((null genericfrom)
1391 (concat host "." domain))
1392 ;;((stringp genericfrom) genericfrom)
1394 (if (string-match "\\." (system-name))
1396 (if (string-match "@\\([^ ]+\\)\\($\\| \\)" user-mail-address)
1397 (substring user-mail-address
1398 (match-beginning 1) (match-end 1))
1401 (defun gnus-inews-full-address ()
1402 (let ((domain (gnus-inews-domain-name))
1403 (system (system-name))
1404 (case-fold-search t))
1405 (if (string-match "\\." system) system
1406 (if (string-match (concat "^" (regexp-quote system)) domain) domain
1407 (concat system "." domain)))))
1409 (defun gnus-inews-expires ()
1410 "Return an Expires header based on `gnus-article-expires'."
1411 (let ((current (current-time))
1412 (future (* 1.0 gnus-article-expires 60 60 24)))
1413 ;; Add the future to current.
1414 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
1415 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
1416 ;; Return the date in the future in UT.
1417 (timezone-make-date-arpa-standard
1418 (current-time-string current) (current-time-zone) '(0 "UT"))))
1420 (defun gnus-inews-distribution ()
1421 "Return the current Distribution header, if any."
1422 (when (and gnus-distribution-function
1423 (fboundp gnus-distribution-function))
1424 (funcall gnus-distribution-function (or gnus-newsgroup-name ""))))
1426 (defun gnus-inews-message-id ()
1427 "Generate unique Message-ID for user."
1428 ;; Message-ID should not contain a slash and should be terminated by
1429 ;; a number. I don't know the reason why it is so.
1430 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1432 (defvar gnus-unique-id-char nil)
1434 ;; If you ever change this function, make sure the new version
1435 ;; cannot generate IDs that the old version could.
1436 ;; You might for example insert a "." somewhere (not next to another dot
1437 ;; or string boundary), or modify the newsreader name to "Ding".
1438 (defun gnus-inews-unique-id ()
1439 ;; Dont use microseconds from (current-time), they may be unsupported.
1440 ;; Instead we use this randomly inited counter.
1441 (setq gnus-unique-id-char
1442 (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1443 ;; (current-time) returns 16-bit ints,
1444 ;; and 2^16*25 just fits into 4 digits i base 36.
1446 (let ((tm (if (fboundp 'current-time)
1447 (current-time) '(12191 46742 287898))))
1449 (if (memq system-type '(ms-dos emx vax-vms))
1450 (let ((user (downcase (gnus-inews-login-name))))
1451 (while (string-match "[^a-z0-9_]" user)
1452 (aset user (match-beginning 0) ?_))
1454 (gnus-number-base36 (user-uid) -1))
1455 (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1456 (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1457 ;; Append the newsreader name, because while the generated
1458 ;; ID is unique to this newsreader, other newsreaders might
1459 ;; otherwise generate the same ID via another algorithm.
1463 (defun gnus-inews-date ()
1464 "Current time string."
1465 (timezone-make-date-arpa-standard
1466 (current-time-string) (current-time-zone)))
1468 (defun gnus-inews-organization ()
1469 "Return user's organization.
1470 The ORGANIZATION environment variable is used if defined.
1471 If not, the variable `gnus-local-organization' is used instead.
1472 If it is a function, the function will be called with the current
1473 newsgroup name as the argument.
1474 If this is a file name, the contents of this file will be used as the
1476 (let* ((organization
1477 (or (getenv "ORGANIZATION")
1478 (if gnus-local-organization
1479 (if (gnus-functionp gnus-local-organization)
1480 (funcall gnus-local-organization gnus-newsgroup-name)
1481 gnus-local-organization))
1482 gnus-organization-file
1483 "~/.organization")))
1484 (and (stringp organization)
1485 (> (length organization) 0)
1486 (or (file-exists-p organization)
1487 (string-match " " organization)
1488 (not (string-match "^/usr/lib/\\|^~/" organization)))
1490 (gnus-set-work-buffer)
1491 (if (file-exists-p organization)
1492 (insert-file-contents organization)
1493 (insert organization))
1494 (goto-char (point-min))
1495 (while (re-search-forward " *\n *" nil t)
1496 (replace-match " " t t))
1497 (buffer-substring (point-min) (point-max))))))
1499 (defun gnus-inews-lines ()
1500 "Count the number of lines and return numeric string."
1504 (goto-char (point-min))
1506 (concat "^" (regexp-quote mail-header-separator) "$"))
1508 (int-to-string (count-lines (point) (point-max))))))
1510 (defun gnus-inews-in-reply-to ()
1511 "Return the In-Reply-To header for this message."
1516 ;;; Gnus Mail Functions
1519 ;;; Mail reply commands of Gnus summary mode
1521 (defun gnus-summary-reply (yank &optional yank-articles)
1522 "Reply mail to news author.
1523 If prefix argument YANK is non-nil, original article is yanked automatically.
1524 Customize the variable gnus-mail-reply-method to use another mailer."
1526 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1527 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1528 (gnus-set-global-variables)
1529 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1530 (gnus-summary-select-article)
1531 (bury-buffer gnus-article-buffer)
1532 (gnus-mail-reply (or yank-articles (not (not yank)))))
1534 (defun gnus-summary-reply-with-original (n)
1535 "Reply mail to news author with original article.
1536 Customize the variable gnus-mail-reply-method to use another mailer."
1538 (gnus-summary-reply t (gnus-summary-work-articles n)))
1540 (defun gnus-summary-mail-forward (post)
1541 "Forward the current message to another user.
1542 Customize the variable gnus-mail-forward-method to use another mailer."
1544 (gnus-set-global-variables)
1545 (gnus-summary-select-article)
1546 (gnus-copy-article-buffer)
1548 (gnus-forward-using-post gnus-article-copy)
1549 (gnus-mail-forward gnus-article-copy)))
1551 (defun gnus-summary-resend-message (address)
1552 "Resend the current article to ADDRESS."
1553 (interactive "sResend message to: ")
1554 (gnus-summary-select-article)
1557 ;; We first set up a normal mail buffer.
1558 (nnheader-set-temp-buffer " *Gnus resend*")
1559 ;; This code from sendmail.el
1561 (let ((fill-prefix "\t")
1562 (address-start (point)))
1563 (insert address "\n")
1564 (fill-region-as-paragraph address-start (point-max)))
1565 (insert mail-header-separator "\n")
1566 ;; Insert our usual headers.
1567 (gnus-inews-narrow-to-headers)
1568 (let ((headers '(From Date To)))
1569 (gnus-inews-insert-headers headers))
1570 (goto-char (point-min))
1571 ;; Rename them all to "Resent-*".
1572 (while (re-search-forward "^[A-Za-z]" nil t)
1577 (delete-region (point) (point-max))
1578 ;; Insert the message to be resent.
1579 (insert-buffer-substring gnus-original-article-buffer)
1580 (goto-char (point-min))
1581 (search-forward "\n\n")
1583 (insert mail-header-separator)
1586 (kill-buffer (current-buffer)))))
1588 (defun gnus-summary-post-forward ()
1589 "Forward the current article to a newsgroup."
1591 (gnus-summary-mail-forward t))
1593 (defvar gnus-nastygram-message
1594 "The following article was inappropriately posted to %s.\n"
1595 "Format string to insert in nastygrams.
1596 The current group name will be inserted at \"%s\".")
1598 (defun gnus-summary-mail-nastygram (n)
1599 "Send a nastygram to the author of the current article."
1601 (if (or gnus-expert-user
1603 "Really send a nastygram to the author of the current article? "))
1604 (let ((group gnus-newsgroup-name))
1605 (gnus-summary-reply-with-original n)
1606 (set-buffer gnus-mail-buffer)
1607 (insert (format gnus-nastygram-message group))
1608 (gnus-mail-send-and-exit))))
1610 (defun gnus-summary-mail-other-window ()
1611 "Compose mail in other window.
1612 Customize the variable `gnus-mail-other-window-method' to use another
1615 (gnus-set-global-variables)
1617 ;; We might want to prompt here.
1618 (when (and gnus-interactive-post
1619 (not gnus-expert-user))
1620 (read-string "To: ")))
1621 (gnus-configure-windows 'summary-mail 'force))
1623 (defun gnus-new-mail (&optional to)
1625 (when (and gnus-interactive-post
1626 (not gnus-expert-user))
1627 (setq subject (read-string "Subject: ")))
1628 (pop-to-buffer gnus-mail-buffer)
1630 (gnus-mail-setup 'new to subject)
1631 (run-hooks 'gnus-mail-hook)))
1633 (defun gnus-mail-reply (&optional yank to-address followup)
1635 (set-buffer gnus-summary-buffer)
1636 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1637 (cur (cons (current-buffer) (cdr gnus-article-current)))
1638 (winconf (current-window-configuration))
1639 from subject date reply-to message-of to cc
1640 references message-id sender follow-to sendto elt new-cc new-to
1642 (set-buffer (get-buffer-create gnus-mail-buffer))
1644 (if (and (buffer-modified-p)
1647 "Unsent message being composed; erase it? ")))
1651 (gnus-copy-article-buffer)
1653 (set-buffer gnus-article-copy)
1654 (gnus-narrow-to-headers)
1656 ;; This is a regular reply.
1657 (if (gnus-functionp gnus-reply-to-function)
1658 (setq follow-to (funcall gnus-reply-to-function group)))
1659 ;; This is a followup.
1660 (if (gnus-functionp gnus-followup-to-function)
1663 (funcall gnus-followup-to-function group)))))
1664 (setq from (mail-fetch-field "from"))
1665 (setq date (or (mail-fetch-field "date")
1666 (mail-header-date gnus-current-headers)))
1667 (setq message-of (gnus-message-of from date))
1668 (setq sender (mail-fetch-field "sender"))
1669 (setq subject (or (mail-fetch-field "subject") "none"))
1670 ;; Remove any (buggy) Re:'s that are present and make a
1672 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1673 (setq subject (substring subject (match-end 0))))
1674 (setq subject (concat "Re: " subject))
1675 (setq to (mail-fetch-field "to"))
1676 (setq cc (mail-fetch-field "cc"))
1677 (setq mct (mail-fetch-field "mail-copies-to"))
1678 (setq reply-to (mail-fetch-field "reply-to"))
1679 (setq references (mail-fetch-field "references"))
1680 (setq message-id (mail-fetch-field "message-id"))
1682 (setq mctdo (not (equal mct "never")))
1684 (if (not (and followup (not to-address)))
1685 (setq new-to (or reply-to from))
1688 (gnus-set-work-buffer)
1689 (unless (equal mct "never")
1690 (insert (or reply-to from "")))
1691 (insert (if (bolp) "" ", ")
1693 (if (or (not mct) (not mctdo)) ""
1694 (concat (if (bolp) "" ", ") mct))
1695 (if cc (concat (if (bolp) "" ", ") cc) ""))
1696 (goto-char (point-min))
1700 (cons (mail-strip-quoted-names addr) addr))
1701 (nreverse (mail-parse-comma-list))))
1704 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
1705 (setq new-to (cdr (pop ccalist)))
1708 (lambda (addr) (cdr addr))
1712 (setq news-reply-yank-from (or from "(nobody)"))
1713 (setq news-reply-yank-message-id
1714 (or message-id "(unknown Message-ID)"))
1716 ;; Gather the "to" addresses out of the follow-to list and remove
1718 (if (and follow-to (listp follow-to))
1719 (while (setq elt (assoc "To" follow-to))
1720 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1721 (setq follow-to (delq elt follow-to))))
1724 (if followup 'followup 'reply)
1726 (if (and follow-to (not (stringp follow-to))) sendto
1727 (or follow-to new-to sender "")))
1729 (if (zerop (length new-cc)) nil new-cc)
1732 (make-local-variable 'gnus-article-reply)
1733 (setq gnus-article-reply cur)
1734 (make-local-variable 'gnus-prev-winconf)
1735 (setq gnus-prev-winconf winconf)
1736 (make-local-variable 'gnus-reply-subject)
1737 (setq gnus-reply-subject subject)
1738 (make-local-variable 'gnus-in-reply-to)
1739 (setq gnus-in-reply-to message-of)
1741 (auto-save-mode auto-save-default)
1743 (if (and follow-to (listp follow-to))
1745 (goto-char (point-min))
1746 (re-search-forward "^To:" nil t)
1750 (insert (car (car follow-to)) ": " (cdr (car follow-to)) "\n")
1751 (setq follow-to (cdr follow-to)))))
1752 (nnheader-insert-references references message-id)
1754 ;; Now the headers should be ok, so we do the yanking.
1755 (goto-char (point-min))
1757 (concat "^" (regexp-quote mail-header-separator) "$"))
1760 (gnus-configure-windows 'reply 'force)
1761 (let ((last (point))
1763 (if (not (listp yank))
1765 ;; Just a single article being yanked.
1767 (mail-yank-original nil))
1768 (or mail-yank-hooks mail-citation-hook
1769 (run-hooks 'news-reply-header-hook)))
1771 (save-window-excursion
1772 (set-buffer gnus-summary-buffer)
1773 (gnus-summary-select-article nil nil nil (car yank))
1774 (gnus-summary-remove-process-mark (car yank)))
1777 (gnus-copy-article-buffer)
1778 (mail-yank-original nil)
1780 (narrow-to-region (point-min) (point))
1781 (goto-char (mark t))
1782 (let ((news-reply-yank-from
1784 (set-buffer gnus-article-buffer)
1785 (or (mail-fetch-field "from") "(nobody)")))
1786 (news-reply-yank-message-id
1788 (set-buffer gnus-article-buffer)
1789 (or (mail-fetch-field "message-id")
1790 "(unknown Message-ID)"))))
1791 (or mail-yank-hooks mail-citation-hook
1792 (run-hooks 'news-reply-header-hook))
1793 (setq end (point-max)))))
1795 (setq yank (cdr yank))))
1798 (gnus-configure-windows 'reply-yank 'force))
1799 (run-hooks 'gnus-mail-hook)))))
1801 (defun gnus-new-news (&optional group inhibit-prompt)
1802 "Set up a *post-news* buffer that points to GROUP.
1803 If INHIBIT-PROMPT, never prompt for a Subject."
1804 (let ((winconf (current-window-configuration))
1806 (when (and gnus-interactive-post
1807 (not inhibit-prompt)
1808 (not gnus-expert-user))
1809 (setq subject (read-string "Subject: ")))
1810 (pop-to-buffer gnus-post-news-buffer)
1813 ;; Let posting styles be configured.
1814 (gnus-configure-posting-styles)
1815 (news-setup nil subject nil (and group (gnus-group-real-name group)) nil)
1816 (goto-char (point-min))
1818 (unless (re-search-forward
1819 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1820 (goto-char (point-max)))
1823 (gnus-inews-insert-bfcc)
1824 (gnus-inews-insert-signature)
1825 (and gnus-post-prepare-function
1826 (gnus-functionp gnus-post-prepare-function)
1827 (funcall gnus-post-prepare-function group))
1828 (goto-char (point-min))
1830 (re-search-forward "^Subject: " nil t)
1831 (re-search-forward "^Newsgroups: " nil t))
1832 (run-hooks 'gnus-post-prepare-hook)
1833 (make-local-variable 'gnus-prev-winconf)
1834 (setq gnus-prev-winconf winconf)
1835 (gnus-inews-modify-mail-mode-map)
1836 (local-set-key "\C-c\C-c" 'gnus-inews-news)))
1838 (defun gnus-news-followup (&optional yank group)
1840 (set-buffer gnus-summary-buffer)
1841 (if (not (or (not gnus-novice-user)
1844 "Are you sure you want to post to all of USENET? ")))
1846 (let ((group (gnus-group-real-name (or group gnus-newsgroup-name)))
1847 (cur (cons (current-buffer) (cdr gnus-article-current)))
1848 (winconf (current-window-configuration))
1849 from subject date reply-to message-of
1850 references message-id sender follow-to sendto elt
1851 followup-to distribution newsgroups)
1852 (set-buffer (get-buffer-create gnus-post-news-buffer))
1854 (if (and (buffer-modified-p)
1857 "Unsent message being composed; erase it? ")))
1861 (gnus-copy-article-buffer)
1863 (set-buffer gnus-article-copy)
1864 (gnus-narrow-to-headers)
1865 (if (gnus-functionp gnus-followup-to-function)
1868 (funcall gnus-followup-to-function group))))
1869 (setq from (mail-fetch-field "from"))
1870 (setq date (or (mail-fetch-field "date")
1871 (mail-header-date gnus-current-headers)))
1872 (setq message-of (gnus-message-of from date))
1873 (setq subject (or (mail-fetch-field "subject") "none"))
1874 ;; Remove any (buggy) Re:'s that are present and make a
1876 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1877 (setq subject (substring subject (match-end 0))))
1878 (setq subject (concat "Re: " subject))
1879 (setq references (mail-fetch-field "references"))
1880 (setq message-id (mail-fetch-field "message-id"))
1881 (setq followup-to (mail-fetch-field "followup-to"))
1882 (setq newsgroups (mail-fetch-field "newsgroups"))
1883 (setq distribution (mail-fetch-field "distribution"))
1884 ;; Remove bogus distribution.
1885 (and (stringp distribution)
1886 (string-match "world" distribution)
1887 (setq distribution nil))
1890 (setq news-reply-yank-from (or from "(nobody)"))
1891 (setq news-reply-yank-message-id
1892 (or message-id "(unknown Message-ID)"))
1894 ;; Gather the "to" addresses out of the follow-to list and remove
1896 (if (and follow-to (listp follow-to))
1897 (while (setq elt (assoc "Newsgroups" follow-to))
1898 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1899 (setq follow-to (delq elt follow-to))))
1901 ;; Let posting styles be configured.
1902 (gnus-configure-posting-styles)
1904 (news-setup nil subject nil
1907 gnus-use-followup-to
1908 (or (not (eq gnus-use-followup-to 'ask))
1911 "Use Followup-To %s? " followup-to)))
1913 newsgroups group "")
1916 (make-local-variable 'gnus-article-reply)
1917 (setq gnus-article-reply cur)
1918 (make-local-variable 'gnus-prev-winconf)
1919 (setq gnus-prev-winconf winconf)
1920 (make-local-variable 'gnus-reply-subject)
1921 (setq gnus-reply-subject (mail-header-subject gnus-current-headers))
1922 (make-local-variable 'gnus-in-reply-to)
1923 (setq gnus-in-reply-to message-of)
1925 (gnus-inews-insert-signature)
1927 (and gnus-post-prepare-function
1928 (gnus-functionp gnus-post-prepare-function)
1929 (funcall gnus-post-prepare-function group))
1930 (run-hooks 'gnus-post-prepare-hook)
1932 (auto-save-mode auto-save-default)
1933 (gnus-inews-modify-mail-mode-map)
1934 (local-set-key "\C-c\C-c" 'gnus-inews-news)
1936 (if (and follow-to (listp follow-to))
1938 (goto-char (point-min))
1939 (and (re-search-forward "^Newsgroups:" nil t)
1942 (insert (car (car follow-to)) ": "
1943 (cdr (car follow-to)) "\n")
1944 (setq follow-to (cdr follow-to)))))
1946 ;; If a distribution existed, we use it.
1949 (mail-position-on-field "Distribution")
1950 (insert distribution)))
1952 (nnheader-insert-references references message-id)
1954 ;; Handle `gnus-auto-mail-to-author'.
1955 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
1956 ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
1957 (let ((to (if (if (eq gnus-auto-mail-to-author 'ask)
1958 (y-or-n-p "Also send mail to author? ")
1959 gnus-auto-mail-to-author)
1961 (set-buffer gnus-article-copy)
1962 (gnus-fetch-field "reply-to"))
1964 (x-mail (save-excursion
1965 (set-buffer gnus-article-copy)
1966 (gnus-fetch-field "x-mail-copy-to"))))
1967 ;; Deny sending copy if there's a negative X-Mail-Copy-To
1970 (if (and (string= x-mail "never")
1971 (not (eq gnus-auto-mail-to-author 'force)))
1974 ;; Insert a To or Cc header.
1976 (if (mail-fetch-field "To")
1979 (insert "Cc: " to "\n"))
1980 (mail-position-on-field "To")
1983 (gnus-inews-insert-bfcc)
1985 ;; Now the headers should be ok, so we do the yanking.
1986 (goto-char (point-min))
1988 (concat "^" (regexp-quote mail-header-separator) "$"))
1992 (gnus-configure-windows 'followup 'force)
1995 (let ((last (point))
1997 (if (not (listp yank))
2000 (mail-yank-original nil))
2001 (or mail-yank-hooks mail-citation-hook
2002 (run-hooks 'news-reply-header-hook)))
2004 (save-window-excursion
2005 (set-buffer gnus-summary-buffer)
2006 (gnus-summary-select-article nil nil nil (car yank))
2007 (gnus-summary-remove-process-mark (car yank)))
2009 (gnus-copy-article-buffer)
2010 (mail-yank-original nil)
2012 (or mail-yank-hooks mail-citation-hook
2013 (run-hooks 'news-reply-header-hook))
2015 (setq yank (cdr yank))))
2017 (gnus-configure-windows 'followup-yank 'force))
2019 (make-local-variable 'gnus-article-check-size)
2020 (setq gnus-article-check-size
2021 (cons (buffer-size) (gnus-article-checksum))))))))
2023 (defun gnus-message-of (from date)
2024 "Take a FROM and a DATE and create an IN-REPLY-TO."
2030 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2031 (concat (if stop-pos (substring from 0 stop-pos) from)
2033 (if (or (not date) (string= date ""))
2034 "(unknown date)" date))))))
2036 (defun gnus-mail-yank-original ()
2039 (mail-yank-original nil))
2040 (or mail-yank-hooks mail-citation-hook
2041 (run-hooks 'news-reply-header-hook)))
2043 (defun gnus-mail-send-and-exit (&optional dont-send)
2044 "Send the current mail and return to Gnus."
2046 (let* ((reply gnus-article-reply)
2047 (winconf gnus-prev-winconf)
2048 (address-group gnus-add-to-address)
2049 (to-address (and address-group
2050 (mail-fetch-field "to"))))
2051 (setq gnus-add-to-address nil)
2052 (or dont-send (gnus-mail-send))
2054 ;; This mail group doesn't have a `to-address', so we add one
2057 (gnus-group-add-parameter
2058 address-group (cons 'to-address to-address)))
2059 (if (get-buffer gnus-group-buffer)
2061 (if (gnus-buffer-exists-p (car-safe reply))
2063 (set-buffer (car reply))
2065 (gnus-summary-mark-article-as-replied
2067 (and winconf (set-window-configuration winconf))))))
2069 (defun gnus-put-message ()
2070 "Put the current message in some group and return to Gnus."
2072 (let ((reply gnus-article-reply)
2073 (winconf gnus-prev-winconf)
2074 (group gnus-newsgroup-name)
2077 (or (and group (not (gnus-group-read-only-p group)))
2078 (setq group (read-string "Put in group: " nil
2079 (gnus-writable-groups))))
2080 (and (gnus-gethash group gnus-newsrc-hashtb)
2081 (error "No such group: %s" group))
2086 (gnus-inews-narrow-to-headers)
2087 (let (gnus-deletable-headers)
2088 (if (eq major-mode 'mail-mode)
2089 (gnus-inews-insert-headers gnus-required-mail-headers)
2090 (gnus-inews-insert-headers)))
2091 (goto-char (point-max))
2092 (insert "Gcc: " group "\n")
2097 (if (get-buffer gnus-group-buffer)
2099 (if (gnus-buffer-exists-p (car-safe reply))
2101 (set-buffer (car reply))
2103 (gnus-summary-mark-article-as-replied
2105 (and winconf (set-window-configuration winconf))))))
2107 (defun gnus-forward-make-subject (buffer)
2110 (concat "[" (if (memq 'mail (assoc (symbol-name
2111 (car (gnus-find-method-for-group
2112 gnus-newsgroup-name)))
2113 gnus-valid-select-methods))
2114 (gnus-fetch-field "From")
2115 gnus-newsgroup-name)
2116 "] " (or (gnus-fetch-field "Subject") ""))))
2118 (defun gnus-forward-insert-buffer (buffer)
2121 (if gnus-signature-before-forwarded-message
2122 (goto-char (point-max))
2123 (goto-char (point-min))
2125 (concat "^" (regexp-quote mail-header-separator) "$"))
2127 ;; Narrow to the area we are to insert.
2128 (narrow-to-region (point) (point))
2129 ;; Insert the separators and the forwarded buffer.
2130 (insert gnus-forward-start-separator)
2131 (insert-buffer-substring buffer)
2132 (goto-char (point-max))
2133 (insert gnus-forward-end-separator)
2134 ;; Delete any invisible text.
2135 (goto-char (point-min))
2137 (while (setq beg (next-single-property-change (point) 'invisible))
2139 (delete-region beg (or (next-single-property-change
2143 (defun gnus-mail-forward (&optional buffer)
2144 "Forward the current message to another user using mail."
2145 (let* ((forward-buffer (or buffer (current-buffer)))
2146 (winconf (current-window-configuration))
2147 (subject (gnus-forward-make-subject forward-buffer)))
2148 (set-buffer (get-buffer-create gnus-mail-buffer))
2149 (if (and (buffer-modified-p)
2152 "Unsent message being composed; erase it? ")))
2155 (gnus-mail-setup 'forward nil subject)
2156 (make-local-variable 'gnus-prev-winconf)
2157 (setq gnus-prev-winconf winconf)
2158 (gnus-forward-insert-buffer forward-buffer)
2159 (goto-char (point-min))
2160 (re-search-forward "^To: ?" nil t)
2161 (gnus-configure-windows 'mail-forward 'force)
2162 ;; You have a chance to arrange the message.
2163 (run-hooks 'gnus-mail-forward-hook)
2164 (run-hooks 'gnus-mail-hook))))
2166 (defun gnus-forward-using-post (&optional buffer)
2168 (let* ((forward-buffer (or buffer (current-buffer)))
2169 (subject (gnus-forward-make-subject forward-buffer))
2170 (gnus-newsgroup-name nil))
2171 (gnus-post-news 'post nil nil nil nil subject)
2173 (gnus-forward-insert-buffer forward-buffer)
2174 ;; You have a chance to arrange the message.
2175 (run-hooks 'gnus-mail-forward-hook)))))
2177 (defun gnus-mail-other-window-using-mail ()
2178 "Compose mail other window using mail."
2179 (let ((winconf (current-window-configuration)))
2180 (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
2181 (gnus-inews-modify-mail-mode-map)
2182 (make-local-variable 'gnus-prev-winconf)
2183 (setq gnus-prev-winconf winconf)
2184 (run-hooks 'gnus-mail-hook)
2185 (gnus-configure-windows 'summary-mail 'force)))
2187 (defun gnus-article-mail (yank)
2188 "Send a reply to the address near point.
2189 If YANK is non-nil, include the original article."
2193 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
2194 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
2197 (switch-to-buffer gnus-summary-buffer)
2198 (gnus-mail-reply yank address)))))
2201 "Send a bug report to the Gnus maintainers."
2203 (let ((winconf (current-window-configuration)))
2204 (delete-other-windows)
2205 (switch-to-buffer "*Gnus Help Bug*")
2207 (insert gnus-bug-message)
2208 (goto-char (point-min))
2209 (pop-to-buffer "*Gnus Bug*")
2212 (mail-setup gnus-maintainer nil nil nil nil nil)
2213 (auto-save-mode auto-save-default)
2214 (make-local-variable 'gnus-prev-winconf)
2215 (setq gnus-prev-winconf winconf)
2216 (gnus-inews-modify-mail-mode-map)
2217 (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
2218 (goto-char (point-min))
2219 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2221 (insert (format "%s\n%s\n\n\n\n\n" (gnus-version) (emacs-version)))
2223 (goto-char (point-min))
2224 (search-forward "Subject: " nil t)
2227 (defun gnus-bug-mail-send-and-exit ()
2228 "Send the bug message and exit."
2230 (and (get-buffer "*Gnus Help Bug*")
2231 (kill-buffer "*Gnus Help Bug*"))
2232 (gnus-mail-send-and-exit))
2234 (defun gnus-debug ()
2235 "Attemps to go through the Gnus source file and report what variables have been changed.
2236 The source file has to be in the Emacs load path."
2238 (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el" "nnmail.el"))
2239 file dirs expr olist sym)
2240 (message "Please wait while we snoop your variables...")
2243 (set-buffer (get-buffer-create " *gnus bug info*"))
2244 (buffer-disable-undo (current-buffer))
2247 (setq dirs load-path)
2249 (if (or (not (car dirs))
2250 (not (stringp (car dirs)))
2252 (setq file (concat (file-name-as-directory
2253 (car dirs)) (car files))))))
2254 (setq dirs (cdr dirs))
2256 (insert-file-contents file)
2257 (goto-char (point-min))
2258 (or (re-search-forward "^;;* *Internal variables" nil t)
2259 (error "Malformed sources in file %s" file))
2260 (narrow-to-region (point-min) (point))
2261 (goto-char (point-min))
2262 (while (setq expr (condition-case ()
2263 (read (current-buffer)) (error nil)))
2265 (and (eq (car expr) 'defvar)
2266 (stringp (nth 3 expr))
2267 (or (not (boundp (nth 1 expr)))
2268 (not (equal (eval (nth 2 expr))
2269 (symbol-value (nth 1 expr)))))
2270 (setq olist (cons (nth 1 expr) olist)))
2272 (setq files (cdr files)))
2273 (kill-buffer (current-buffer)))
2274 (insert "------------------- Environment follows -------------------\n\n")
2275 (setq olist (nreverse olist))
2277 (if (boundp (car olist))
2278 (insert "(setq " (symbol-name (car olist))
2279 (if (or (consp (setq sym (symbol-value (car olist))))
2281 (not (or (eq sym nil)
2284 (prin1-to-string (symbol-value (car olist))) ")\n")
2285 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
2286 (setq olist (cdr olist)))
2288 ;; Remove any null chars - they seem to cause trouble for some
2289 ;; mailers. (Byte-compiled output from the stuff above.)
2290 (goto-char (point-min))
2291 (while (re-search-forward "[\000\200]" nil t)
2292 (replace-match "" t t))))
2295 ;;; Treatment of rejected articles.
2300 (defun gnus-summary-resend-bounced-mail (fetch)
2301 "Re-mail the current message.
2302 This only makes sense if the current message is a bounce message than
2303 contains some mail you have written which has been bounced back to
2305 If FETCH, try to fetch the article that this is a reply to, if indeed
2308 (gnus-summary-select-article t)
2309 ;; Create a mail buffer.
2312 (insert-buffer-substring gnus-article-buffer)
2313 (goto-char (point-min))
2314 (search-forward "\n\n")
2315 ;; We remove everything before the bounced mail.
2318 (if (re-search-forward "[^ \t]*:" nil t)
2324 (gnus-narrow-to-headers)
2325 (nnheader-remove-header gnus-bounced-headers-junk t)
2326 (setq references (mail-fetch-field "references"))
2327 (goto-char (point-max))
2328 (insert mail-header-separator)))
2329 ;; If there are references, we fetch the article we answered to.
2332 (string-match "\\(<[^]+>\\)[ \t]*$" references)
2333 (gnus-summary-refer-article
2334 (substring references (match-beginning 1) (match-end 1)))
2336 (gnus-summary-show-all-headers)
2337 (gnus-configure-windows 'compose-bounce))))
2338 (goto-char (point-min)))
2342 (defun gnus-mail-send ()
2343 "Send the current buffer as mail.
2344 Headers will be generated before sending."
2349 (gnus-inews-narrow-to-headers)
2350 (gnus-inews-insert-headers gnus-required-mail-headers)
2351 (gnus-inews-remove-empty-headers)))
2353 ;; Remove the header separator.
2354 (goto-char (point-min))
2355 (and (re-search-forward
2356 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2357 (replace-match "" t t))
2358 ;; Run final inews hooks. This hook may do FCC.
2359 (run-hooks 'gnus-inews-article-hook)
2361 (gnus-narrow-to-headers)
2362 (nnheader-remove-header "^[gf]cc:" t)
2364 (goto-char (point-min))
2365 (search-forward "\n\n")
2367 (insert mail-header-separator)
2369 (run-hooks 'gnus-message-sent-hook))
2371 (defun gnus-inews-modify-mail-mode-map ()
2372 (use-local-map (copy-keymap (current-local-map)))
2373 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
2374 (local-set-key "\C-c\C-p" 'gnus-put-message)
2375 (local-set-key "\C-c\C-d" 'gnus-enter-into-draft-group))
2377 (defun gnus-mail-setup (type &optional to subject in-reply-to cc
2378 replybuffer actions)
2379 ;; Let posting styles be configured.
2380 (gnus-configure-posting-styles)
2384 (and (or (eq type 'reply) (eq type 'followup))
2385 (eq gnus-mail-reply-method 'gnus-mail-reply-using-mhe))
2386 (and (eq type 'forward)
2387 (eq gnus-mail-forward-method 'gnus-mail-forward-using-mhe))
2389 (eq gnus-mail-other-window-method
2390 'gnus-mail-other-window-using-mhe)))
2391 'gnus-mh-mail-setup)
2393 (and (or (eq type 'reply) (eq type 'followup))
2394 (eq gnus-mail-reply-method 'gnus-mail-reply-using-vm))
2395 (and (eq type 'forward)
2396 (eq gnus-mail-forward-method 'gnus-mail-forward-using-vm))
2398 (eq gnus-mail-other-window-method
2399 'gnus-mail-other-window-using-vm)))
2400 'gnus-vm-mail-setup)
2401 (t 'gnus-sendmail-mail-setup))
2402 to subject in-reply-to cc replybuffer actions))
2404 (defun gnus-sendmail-mail-setup (to subject in-reply-to cc replybuffer actions)
2406 (mail-setup to subject nil cc replybuffer actions)
2407 (goto-char (point-min))
2408 (if (re-search-forward
2409 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2411 (goto-char (point-max)))
2412 (gnus-inews-modify-mail-mode-map))
2416 ;; Do Gcc handling, which copied the message over to some group.
2417 (defun gnus-inews-do-gcc (&optional gcc)
2420 (gnus-narrow-to-headers)
2421 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
2424 () ; Nothing to be done.
2425 (nnheader-remove-header "gcc")
2426 ;; Copy the article over to some group(s).
2427 (while (string-match
2428 "^[ \t]*\\([^ \t]+\\)\\([ \t]+\\|$\\)" gcc)
2429 (setq end (match-end 0))
2431 (gnus-request-accept-article
2432 (substring gcc (match-beginning 1) (match-end 1)) t)
2434 (setq gcc (substring gcc end))))))))
2436 (defun gnus-inews-insert-bfcc ()
2437 "Insert Bcc and Fcc headers."
2439 ;; Handle author copy using BCC field.
2440 (when (and gnus-mail-self-blind
2441 (not (mail-fetch-field "bcc")))
2442 (mail-position-on-field "Bcc")
2443 (insert (if (stringp gnus-mail-self-blind)
2444 gnus-mail-self-blind
2445 (user-login-name))))
2446 ;; Handle author copy using FCC field.
2447 (when gnus-author-copy
2448 (mail-position-on-field "Fcc")
2449 (insert gnus-author-copy))))
2451 (defun gnus-inews-insert-gcc ()
2452 (let* ((group gnus-outgoing-message-group)
2454 ((gnus-functionp group)
2456 ((or (stringp group) (list group))
2460 (if (stringp group) group
2461 (mapconcat 'identity group " "))
2464 ;;; Handling rejected (and postponed) news.
2466 (defun gnus-draft-group ()
2467 "Return the name of the draft group."
2468 (gnus-group-prefixed-name
2469 (file-name-nondirectory gnus-draft-group-directory)
2470 (list 'nndir gnus-draft-group-directory)))
2472 (defun gnus-make-draft-group ()
2473 "Make the draft group or die trying."
2474 (let* ((method (` (nndir "private"
2475 (nndir-directory (, gnus-draft-group-directory)))))
2476 (group (gnus-group-prefixed-name
2477 (file-name-nondirectory gnus-draft-group-directory)
2479 (or (gnus-gethash group gnus-newsrc-hashtb)
2480 (gnus-group-make-group (gnus-group-real-name group) method)
2481 (error "Can't create the draft group"))
2484 (defun gnus-enter-into-draft-group ()
2485 "Enter the current buffer into the draft group."
2487 (gnus-put-in-draft-group t))
2489 (defun gnus-put-in-draft-group (&optional generate silent)
2490 "Does the actual putting."
2491 (let ((group (gnus-make-draft-group))
2492 (type (list major-mode (buffer-name) gnus-newsgroup-name
2495 (buf (current-buffer)))
2498 (nnheader-set-temp-buffer " *enter-draft*")
2499 (insert-buffer-substring buf)
2502 (gnus-inews-narrow-to-headers)
2503 (let (gnus-deletable-headers)
2504 (if (eq mode 'mail-mode)
2505 (gnus-inews-insert-headers gnus-required-mail-headers)
2506 (gnus-inews-insert-headers)))
2509 (goto-char (point-min))
2510 ;; We have to store whether we are in a mail group or news group.
2511 (insert (format "X-Gnus-Draft-Type: %S\n" type))
2512 (and (re-search-forward
2513 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2514 (replace-match "" t t))
2516 (gnus-request-accept-article group t)
2517 (kill-buffer (current-buffer)))
2519 (gnus-mail-send-and-exit 'dont-send))))
2520 (set-buffer-modified-p nil)))
2522 (defun gnus-summary-send-draft ()
2523 "Enter a mail/post buffer to edit and send the draft."
2525 (gnus-set-global-variables)
2526 (gnus-summary-select-article t)
2527 ;; First we find the draft type.
2530 (set-buffer gnus-article-buffer)
2532 (gnus-narrow-to-headers)
2533 (setq type (condition-case ()
2534 (read (mail-fetch-field "x-gnus-draft-type"))
2538 (error "Unknown draft type"))
2539 ;; Get to the proper buffer.
2540 (set-buffer (get-buffer-create (nth 1 type)))
2541 ;; It might be modified.
2542 (and (buffer-modified-p)
2543 (or (gnus-yes-or-no-p "Unsent message being composed; discard it? ")
2545 (setq buffer-read-only nil)
2546 (buffer-enable-undo (current-buffer))
2549 (funcall (car type))
2550 (gnus-inews-modify-mail-mode-map)
2551 (when (eq major-mode 'news-reply-mode)
2552 (local-set-key "\C-c\C-c" 'gnus-inews-news))
2553 ;; Arrange for deletion of the draft after successful sending.
2554 (make-local-variable 'gnus-message-sent-hook)
2555 (setq gnus-message-sent-hook
2558 (gnus-request-expire-articles
2559 (quote ,(list (cdr gnus-article-current)))
2560 ,gnus-newsgroup-name t)
2561 (and (buffer-name ,gnus-summary-buffer)
2563 (set-buffer ,gnus-summary-buffer)
2564 (gnus-summary-mark-article
2565 ,(cdr gnus-article-current) gnus-canceled-mark))))))
2566 ;; Insert the draft.
2567 (insert-buffer-substring gnus-article-buffer)
2568 ;; Insert the separator.
2569 (goto-char (point-min))
2570 (search-forward "\n\n")
2572 (insert mail-header-separator)
2573 ;; Remove the draft header.
2574 (gnus-inews-narrow-to-headers)
2575 (nnheader-remove-header "x-gnus-draft-type")
2577 ;; Configure windows.
2578 (let ((gnus-draft-buffer (current-buffer)))
2579 (gnus-configure-windows 'draft))
2580 ;; Put point where you left it.
2581 (goto-char (nth 3 type))))
2583 (defun gnus-configure-posting-styles ()
2584 "Configure posting styles according to `gnus-posting-styles'."
2585 (let ((styles gnus-posting-styles)
2586 (gnus-newsgroup-name (or gnus-newsgroup-name ""))
2587 style match variable attribute value value-value)
2588 ;; Go through all styles and look for matches.
2590 (setq style (pop styles)
2592 (when (cond ((stringp match)
2593 ;; Regexp string match on the group name.
2594 (string-match match gnus-newsgroup-name))
2595 ((or (symbolp match)
2596 (gnus-functionp match))
2597 (cond ((gnus-functionp match)
2598 ;; Function to be called.
2601 ;; Variable to be checked.
2602 (symbol-value match))))
2604 ;; This is a form to be evaled.
2606 ;; We have a match, so we set the variables.
2608 (setq attribute (pop style)
2609 value (cdr attribute))
2610 ;; We find the variable that is to be modified.
2611 (if (and (not (stringp (car attribute)))
2612 (not (setq variable (cdr (assq (car attribute)
2613 gnus-posting-style-alist)))))
2614 (message "Couldn't find attribute %s" (car attribute))
2615 ;; We set the variable.
2617 (cond ((stringp value)
2619 ((or (symbolp value)
2620 (gnus-functionp value))
2621 (cond ((gnus-functionp value)
2624 (symbol-value value))))
2629 ;; This is an ordinary variable.
2630 (make-local-variable variable)
2631 (set variable value-value))
2632 ;; This is a header to be added to the headers when
2635 (make-local-variable gnus-required-headers)
2636 (make-local-variable gnus-required-mail-headers)
2637 (push (cons (car attribute) value-value)
2638 gnus-required-headers)
2639 (push (cons (car attribute) value-value)
2640 gnus-required-mail-headers)))))))))
2642 ;;; Allow redefinition of functions.
2648 ;;; gnus-msg.el ends here