1 ;;; gnus-msg.el --- mail and post interface for Gnus
2 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
5 ;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
31 (eval-when-compile (require 'cl))
33 (defvar gnus-organization-file "/usr/lib/news/organization"
34 "*Local news organization file.")
36 (defvar gnus-prepare-article-hook nil
37 "*A hook called after preparing body, but before preparing header headers.")
39 (defvar gnus-post-prepare-function nil
40 "*Function that is run after a post buffer has been prepared.
41 It is called with the name of the newsgroup that is posted to. It
42 might be used, for instance, for inserting signatures based on the
43 newsgroup name. (In that case, `gnus-signature-file' and
44 `mail-signature' should both be set to nil).")
46 (defvar gnus-post-prepare-hook nil
47 "*Hook that is run after a post buffer has been prepared.
48 If you want to insert the signature, you might put
49 `gnus-inews-insert-signature' in this hook.")
51 (defvar gnus-use-followup-to t
52 "*Specifies what to do with Followup-To header.
53 If nil, ignore the header. If it is t, use its value, but ignore
54 `poster'. If it is the symbol `ask', query the user before posting.
55 If it is the symbol `use', always use the value.")
57 (defvar gnus-followup-to-function nil
58 "*A variable that contains a function that returns a followup address.
59 The function will be called in the buffer of the article that is being
60 followed up. The buffer will be narrowed to the headers of the
61 article. To pick header headers, one might use `mail-fetch-field'. The
62 function will be called with the name of the current newsgroup as the
65 Here's an example `gnus-followup-to-function':
67 (setq gnus-followup-to-function
69 (cond ((string= group \"mail.list\")
70 (or (mail-fetch-field \"sender\")
71 (mail-fetch-field \"from\")))
73 (or (mail-fetch-field \"reply-to\")
74 (mail-fetch-field \"from\"))))))")
76 (defvar gnus-reply-to-function nil
77 "*A variable that contains a function that returns a reply address.
78 See the `gnus-followup-to-function' variable for an explanation of how
79 this variable is used.
81 This function should return a string that will be used to fill in the
82 header. This function may also return a list. In that case, every
83 list element should be a cons where the first car should be a string
84 with the header name, and the cdr should be a string with the header
87 (defvar gnus-author-copy (getenv "AUTHORCOPY")
88 "*Save outgoing articles in this file.
89 Initialized from the AUTHORCOPY environment variable.
91 If this variable begins with the character \"|\", outgoing articles
92 will be piped to the named program. It is possible to save an article
93 in an MH folder as follows:
95 \(setq gnus-author-copy \"|/usr/local/lib/mh/rcvstore +Article\")
97 If the first character is not a pipe, articles are saved using the
98 function specified by the `gnus-author-copy-saver' variable.")
100 (defvar gnus-mail-self-blind nil
101 "*Non-nil means insert a BCC header in all outgoing articles.
102 This will result in having a copy of the article mailed to yourself.
103 The BCC header is inserted when the post buffer is initialized, so you
104 can remove or alter the BCC header to override the default.")
106 (defvar gnus-author-copy-saver (function rmail-output)
107 "*A function called to save outgoing articles.
108 This function will be called with the same of the file to store the
109 article in. The default function is `rmail-output' which saves in Unix
112 (defvar gnus-outgoing-message-group nil
113 "*All outgoing messages will be put in this group.
114 If you want to store all your outgoing mail and articles in the group
115 \"nnml:archive\", you set this variable to that value. This variable
116 can also be a list of group names.
118 If you want to have greater control over what group to put each
119 message in, you can set this variable to a function that checks the
120 current newsgroup name and then returns a suitable group name (or list
123 (defvar gnus-mailing-list-groups nil
124 "*Regexp matching groups that are really mailing lists.
125 This is useful when you're reading a mailing list that has been
126 gatewayed to a newsgroup, and you want to followup to an article in
129 (defvar gnus-draft-group-directory
131 (concat (file-name-as-directory gnus-article-save-directory)
133 "*The directory where draft messages will be stored.")
135 (defvar gnus-posting-styles nil
136 "*Alist of styles to use when posting.")
138 (defvar gnus-posting-style-alist
139 '((organization . gnus-organization-file)
140 (signature . gnus-signature-file)
141 (from . gnus-user-from-line)))
143 (defvar gnus-user-login-name nil
144 "*The login name of the user.
145 Got from the function `user-login-name' if undefined.")
147 (defvar gnus-user-full-name nil
148 "*The full name of the user.
149 Got from the NAME environment variable if undefined.")
151 (defvar gnus-user-from-line nil
152 "*Your full, complete e-mail address.
153 Overrides the other Gnus variables if it is non-nil.
155 Here are two example values of this variable:
157 \"Lars Magne Ingebrigtsen <larsi@ifi.uio.no>\"
161 \"larsi@ifi.uio.no (Lars Magne Ingebrigtsen)\"
163 The first version is recommended, but the name has to be quoted if it
164 contains non-alphanumerical characters.")
166 (defvar gnus-signature-file "~/.signature"
167 "*Your signature file.
168 If the variable is a string that doesn't correspond to a file, the
169 string itself is inserted.")
171 (defvar gnus-signature-function nil
172 "*A function that should return a signature file name.
173 The function will be called with the name of the newsgroup being
175 If the function returns a string that doesn't correspond to a file, the
176 string itself is inserted.
177 If the function returns nil, the `gnus-signature-file' variable will
180 (defvar gnus-required-headers
181 '(From Date Newsgroups Subject Message-ID Organization Lines X-Newsreader)
182 "*Headers to be generated or prompted for when posting an article.
183 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
184 Message-ID. Organization, Lines, In-Reply-To and X-Newsreader are
185 optional. If you want Gnus not to insert some header, remove it from
188 (defvar gnus-required-mail-headers
189 '(From Date To Subject (optional . In-Reply-To) Message-ID Organization Lines)
190 "*Headers to be generated or prompted for when mailing a message.
191 RFC822 required that From, Date, To, Subject and Message-ID be
192 included. Organization, Lines and X-Mailer are optional.")
194 (defvar gnus-deletable-headers '(Message-ID Date)
195 "*Headers to be deleted if they already exists and were generated by Gnus previously.")
197 (defvar gnus-removable-headers '(NNTP-Posting-Host Bcc Xref)
198 "*Headers to be removed unconditionally before posting.")
200 (defvar gnus-check-before-posting
201 '(subject-cmsg multiple-headers sendsys message-id from
202 long-lines control-chars size new-text
203 signature approved sender)
204 "In non-nil, Gnus will attempt to run some checks on outgoing posts.
205 If this variable is t, Gnus will check everything it can. If it is a
206 list, then those elements in that list will be checked.")
208 (defvar gnus-delete-supersedes-headers
209 "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Supersedes:"
210 "*Header lines matching this regexp will be deleted before posting.
211 It's best to delete old Path and Date headers before posting to avoid
214 (defvar gnus-auto-mail-to-author nil
215 "*If non-nil, mail the authors of articles a copy of your follow-ups.
216 If this variable is `ask', the user will be prompted for whether to
217 mail a copy. The string given by `gnus-mail-courtesy-message' will be
218 inserted at the beginning of the mail copy.
220 Mail is sent using the function specified by the
221 `gnus-mail-send-method' variable.")
223 ;; Added by Ethan Bradford <ethanb@ptolemy.astro.washington.edu>.
224 (defvar gnus-mail-courtesy-message
225 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
226 "*This is inserted at the start of a mailed copy of a posted message.
227 If this variable is nil, no such courtesy message will be added.")
229 (defvar gnus-mail-reply-method (function gnus-mail-reply-using-mail)
230 "*Function to compose a reply.
231 Three pre-made functions are `gnus-mail-reply-using-mail' (sendmail);
232 `gnus-mail-reply-using-mhe' (MH-E); and `gnus-mail-reply-using-vm'.")
234 (defvar gnus-mail-forward-method (function gnus-mail-forward-using-mail)
235 "*Function to forward the current message to another user.
236 Three pre-made functions are `gnus-mail-forward-using-mail' (sendmail);
237 `gnus-mail-forward-using-mhe' (MH-E); and `gnus-mail-forward-using-vm'.")
239 (defvar gnus-mail-other-window-method 'gnus-mail-other-window-using-mail
240 "*Function to compose mail in the other window.
241 Three pre-made functions are `gnus-mail-other-window-using-mail'
242 (sendmail); `gnus-mail-other-window-using-mhe' (MH-E); and
243 `gnus-mail-other-window-using-vm'.")
245 (defvar gnus-mail-send-method send-mail-function
246 "*Function to mail a message which is also being posted as an article.
247 The message must have To or Cc header. The default is copied from
248 the variable `send-mail-function'.")
250 (defvar gnus-inews-article-function 'gnus-inews-article
251 "*Function to post an article.")
253 (defvar gnus-bounced-headers-junk "^\\(Received\\):"
254 "*Regexp that matches headers to be removed in resent bounced mail.")
256 (defvar gnus-inews-article-hook (list 'gnus-inews-do-fcc)
257 "*A hook called before finally posting an article.
258 The default hook (`gnus-inews-do-fcc') does FCC processing (ie. saves
259 the article to a file).")
261 (defvar gnus-inews-article-header-hook nil
262 "*A hook called after inserting the headers in an article to be posted.
263 The hook is called from the *post-news* buffer, narrowed to the
266 (defvar gnus-mail-hook nil
267 "*A hook called as the last thing after setting up a mail buffer.")
269 (defvar gnus-message-sent-hook nil
270 "*A hook run after an article has been sent (or attempted sent).")
272 ;;; Internal variables.
274 (defvar gnus-post-news-buffer "*post-news*")
275 (defvar gnus-mail-buffer "*mail*")
276 (defvar gnus-summary-send-map nil)
277 (defvar gnus-article-copy nil)
278 (defvar gnus-reply-subject nil)
279 (defvar gnus-add-to-address nil)
280 (defvar gnus-in-reply-to nil)
283 (autoload 'gnus-uu-post-news "gnus-uu" nil t)
284 (autoload 'news-setup "rnewspost")
285 (autoload 'news-reply-mode "rnewspost")
286 (autoload 'rmail-output "rmailout"))
290 ;;; Gnus Posting Functions
293 (define-prefix-command 'gnus-summary-send-map)
294 (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
295 (define-key gnus-summary-send-map "p" 'gnus-summary-post-news)
296 (define-key gnus-summary-send-map "f" 'gnus-summary-followup)
297 (define-key gnus-summary-send-map "F" 'gnus-summary-followup-with-original)
298 (define-key gnus-summary-send-map "b" 'gnus-summary-followup-and-reply)
299 (define-key gnus-summary-send-map "B" 'gnus-summary-followup-and-reply-with-original)
300 (define-key gnus-summary-send-map "c" 'gnus-summary-cancel-article)
301 (define-key gnus-summary-send-map "s" 'gnus-summary-supersede-article)
302 (define-key gnus-summary-send-map "r" 'gnus-summary-reply)
303 (define-key gnus-summary-send-map "R" 'gnus-summary-reply-with-original)
304 (define-key gnus-summary-send-map "m" 'gnus-summary-mail-other-window)
305 (define-key gnus-summary-send-map "Db" 'gnus-summary-resend-bounced-mail)
306 (define-key gnus-summary-send-map "Dc" 'gnus-summary-send-draft)
307 (define-key gnus-summary-send-map "u" 'gnus-uu-post-news)
308 (define-key gnus-summary-send-map "om" 'gnus-summary-mail-forward)
309 (define-key gnus-summary-send-map "op" 'gnus-summary-post-forward)
310 (define-key gnus-summary-send-map "Om" 'gnus-uu-digest-mail-forward)
311 (define-key gnus-summary-send-map "Op" 'gnus-uu-digest-post-forward)
313 ;;; Internal functions.
315 (defun gnus-number-base36 (num len)
316 (if (if (< len 0) (<= num 0) (= len 0))
318 (concat (gnus-number-base36 (/ num 36) (1- len))
319 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
322 ;;; Post news commands of Gnus group mode and summary mode
324 (defun gnus-group-mail ()
325 "Start composing a mail."
329 (defun gnus-group-post-news ()
332 (let ((gnus-newsgroup-name nil))
333 (gnus-post-news 'post nil nil gnus-article-buffer)))
335 (defun gnus-summary-post-news ()
338 (gnus-set-global-variables)
339 (gnus-post-news 'post gnus-newsgroup-name))
341 (defun gnus-summary-followup (yank &optional yank-articles)
342 "Compose a followup to an article.
343 If prefix argument YANK is non-nil, original article is yanked automatically."
345 (gnus-set-global-variables)
346 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
347 (save-window-excursion
348 (gnus-summary-select-article))
349 (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
350 (gnus-newsgroup-name gnus-newsgroup-name))
351 ;; Check Followup-To: poster.
352 (set-buffer gnus-article-buffer)
353 (if (and gnus-use-followup-to
354 (string-equal "poster" (gnus-fetch-field "followup-to"))
355 (or (not (memq gnus-use-followup-to '(t ask)))
357 "Do you want to ignore `Followup-To: poster'? "))))
358 ;; Mail to the poster.
359 (gnus-summary-reply yank)
361 (gnus-post-news nil gnus-newsgroup-name
362 headers gnus-article-buffer
363 (or yank-articles (not (not yank)))))))
365 (defun gnus-summary-followup-with-original (n)
366 "Compose a followup to an article and include the original article."
368 (gnus-summary-followup t (gnus-summary-work-articles n)))
370 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
371 (defun gnus-summary-followup-and-reply (yank &optional yank-articles)
372 "Compose a followup and do an auto mail to author."
374 (gnus-set-global-variables)
375 (let ((gnus-auto-mail-to-author 'force))
376 (gnus-summary-followup yank yank-articles)))
378 (defun gnus-summary-followup-and-reply-with-original (n)
379 "Compose a followup, include the original, and do an auto mail to author."
381 (gnus-summary-followup-and-reply t (gnus-summary-work-articles n)))
383 (defun gnus-summary-cancel-article (n)
384 "Cancel an article you posted."
386 (gnus-set-global-variables)
387 (let ((articles (gnus-summary-work-articles n)))
389 (gnus-summary-select-article t nil nil (car articles))
390 (and (gnus-eval-in-buffer-window gnus-article-buffer (gnus-cancel-news))
391 (gnus-summary-mark-as-read (car articles) gnus-canceled-mark))
392 (gnus-summary-remove-process-mark (car articles))
393 (gnus-article-hide-headers-if-wanted)
394 (setq articles (cdr articles)))))
396 (defun gnus-summary-supersede-article ()
397 "Compose an article that will supersede a previous article.
398 This is done simply by taking the old article and adding a Supersedes
399 header line with the old Message-ID."
401 (gnus-set-global-variables)
402 (gnus-summary-select-article t)
405 (downcase (mail-strip-quoted-names
406 (mail-header-from gnus-current-headers)))
407 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
408 (error "This article is not yours."))
410 (set-buffer gnus-article-buffer)
411 (let ((buffer-read-only nil))
412 (goto-char (point-min))
413 (search-forward "\n\n" nil t)
414 (if (not (re-search-backward "^Message-ID: " nil t))
415 (error "No Message-ID in this article"))))
416 (if (gnus-post-news 'post gnus-newsgroup-name)
419 (insert-buffer-substring gnus-article-buffer)
420 (if (search-forward "\n\n" nil t)
422 (goto-char (point-max)))
423 (narrow-to-region (point-min) (point))
424 (goto-char (point-min))
425 (and gnus-delete-supersedes-headers
426 (delete-matching-lines gnus-delete-supersedes-headers))
427 (goto-char (point-min))
428 (if (not (re-search-forward "^Message-ID: " nil t))
429 (error "No Message-ID in this article")
430 (replace-match "Supersedes: " t t))
431 (goto-char (point-max))
432 (insert mail-header-separator)
438 (defalias 'sendnews 'gnus-post-news)
441 (defalias 'postnews 'gnus-post-news)
443 (defun gnus-copy-article-buffer (&optional article-buffer)
444 ;; make a copy of the article buffer with all text properties removed
445 ;; this copy is in the buffer gnus-article-copy.
446 ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
447 ;; this buffer should be passed to all mail/news reply/post routines.
448 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
449 (buffer-disable-undo gnus-article-copy)
450 (or (memq gnus-article-copy gnus-buffer-list)
451 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
452 (let ((article-buffer (or article-buffer gnus-article-buffer)))
453 (if (and (get-buffer article-buffer)
454 (buffer-name (get-buffer article-buffer)))
456 (set-buffer article-buffer)
458 (copy-to-buffer gnus-article-copy (point-min) (point-max))
459 (set-text-properties (point-min) (point-max)
460 nil gnus-article-copy)))))
462 (defun gnus-post-news (post &optional group header article-buffer yank subject)
463 "Begin editing a new USENET news article to be posted.
464 Type \\[describe-mode] in the buffer to get a list of commands."
465 (interactive (list t))
466 (let* ((group (or group gnus-newsgroup-name))
471 (nth 5 (nth 2 (gnus-gethash
472 group gnus-newsrc-hashtb)))))))
474 (and group gnus-mailing-list-groups
475 (string-match gnus-mailing-list-groups group))))
476 (if (and (gnus-member-of-valid 'post (or group gnus-newsgroup-name))
481 (gnus-new-news group)
482 (gnus-news-followup yank group))
486 (gnus-new-mail to-address)
487 ;; Arrange for mail groups that have no `to-address' to
488 ;; get that when the user sends off the mail.
491 (make-local-variable 'gnus-add-to-address)
492 (setq gnus-add-to-address group))))
493 (gnus-mail-reply yank to-address 'followup)))))
495 (defun gnus-inews-news (&optional use-group-method)
496 "Send a news message.
497 If given a prefix, and the group is a foreign group, this function
498 will attempt to use the foreign server to post the article."
500 (or gnus-current-select-method
501 (setq gnus-current-select-method gnus-select-method))
502 (let* ((case-fold-search nil)
503 (server-running (gnus-server-opened gnus-current-select-method))
504 (reply gnus-article-reply)
507 (gnus-start-news-server) ;Use default server.
509 (goto-char (point-min))
510 (run-hooks 'news-inews-hook)
513 (gnus-message 5 "Posting to USENET...")
514 (setq post-result (funcall gnus-inews-article-function use-group-method))
515 (cond ((eq post-result 'illegal)
519 (gnus-message 5 "Posting to USENET...done")
520 (if (gnus-buffer-exists-p (car-safe reply))
523 (set-buffer gnus-summary-buffer)
524 (gnus-summary-mark-article-as-replied
526 (set-buffer-modified-p nil))
528 ;; We cannot signal an error.
531 (gnus-message 1 "Article rejected: %s"
532 (gnus-status-message gnus-select-method)))))
534 (let ((conf gnus-prev-winconf))
538 ;; Restore last window configuration.
539 (and conf (set-window-configuration conf)))))))
541 (defun gnus-inews-narrow-to-headers ()
544 (goto-char (point-min))
545 (or (and (re-search-forward
546 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
550 (defun gnus-inews-send-mail-copy ()
551 ;; Mail the message if To, Bcc or Cc exists.
552 (let* ((types '("to" "bcc" "cc"))
554 (buffer (current-buffer))
558 (gnus-inews-narrow-to-headers)
561 (or (mail-fetch-field (car ty) nil t)
562 (setq types (delete (car ty) types)))
566 ;; We do not want to send mail.
568 (gnus-message 5 "Sending via mail...")
571 ;; We copy the article over to a temp buffer since we are
572 ;; going to modify it a little.
573 (nnheader-set-temp-buffer " *Gnus-mailing*")
574 (insert-buffer-substring buffer)
575 ;; We remove Fcc, because we don't want the mailer to see
577 (gnus-inews-narrow-to-headers)
578 (nnheader-remove-header "fcc")
580 ;; Insert the X-Courtesy-Message header.
581 (and (or (member "to" types)
584 (goto-char (point-max))
585 (insert "Posted-To: "
586 (mail-fetch-field "newsgroups") "\n")))
590 (if (and gnus-mail-courtesy-message
591 (or (member "to" types)
592 (member "cc" types)))
593 ;; We only want to insert the courtesy mail message if
594 ;; we use To or Cc; Bcc should not have one. Well, if
595 ;; both Bcc and To are present, it will get one
598 ;; Insert "courtesy" mail message.
599 (goto-char (point-min))
601 (concat "^" (regexp-quote mail-header-separator) "$"))
603 (insert gnus-mail-courtesy-message)))
606 (kill-buffer (current-buffer))
607 (gnus-message 5 "Sending via mail...done"))))))
609 (defun gnus-inews-remove-headers-after-mail ()
612 (gnus-inews-narrow-to-headers)
613 (nnheader-remove-header "bcc"))))
615 (defun gnus-inews-check-post ()
616 "Check whether the post looks ok."
618 (not gnus-check-before-posting)
620 ;; We narrow to the headers and check them first.
623 (goto-char (point-min))
628 (concat "^" (regexp-quote mail-header-separator) "$"))
629 (match-beginning 0)))
630 (goto-char (point-min))
632 ;; Check for commands in Subject.
634 (gnus-check-before-posting 'subject-cmsg)
636 (if (string-match "^cmsg " (mail-fetch-field "subject"))
638 "The control code \"cmsg \" is in the subject. Really post? ")
640 ;; Check for multiple identical headers.
641 (or (gnus-check-before-posting 'multiple-headers)
644 (while (and (not found) (re-search-forward "^[^ \t:]+: "
647 (or (re-search-forward
648 (concat "^" (setq found
651 (- (match-end 0) 2))))
656 (format "Multiple %s headers. Really post? " found))
658 ;; Check for Version and Sendsys.
659 (or (gnus-check-before-posting 'sendsys)
661 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
663 (format "The article contains a %s command. Really post? "
664 (buffer-substring (match-beginning 0)
665 (1- (match-end 0)))))
667 ;; Check for Approved.
668 (or (gnus-check-before-posting 'approved)
670 (if (re-search-forward "^Approved:" nil t)
672 "The article contains an Approved header. Really post? ")
674 ;; Check the Message-ID header.
675 (or (gnus-check-before-posting 'message-id)
677 (let* ((case-fold-search t)
678 (message-id (mail-fetch-field "message-id")))
680 (and (string-match "@" message-id)
681 (string-match "@[^\\.]*\\." message-id))
684 "The Message-ID looks strange: \"%s\". Really post? "
686 ;; Check the From header.
687 (or (gnus-check-before-posting 'from)
689 (let* ((case-fold-search t)
690 (from (mail-fetch-field "from")))
693 (gnus-y-or-n-p "There is no From line. Really post? "))
694 ((not (string-match "@[^\\.]*\\." from))
697 "The address looks strange: \"%s\". Really post? " from)))
698 ((string-match "(.*).*(.*)" from)
701 "The From header looks strange: \"%s\". Really post? "
703 ((string-match "<[^>]+> *$" from)
704 (let ((name (substring from 0 (match-beginning 0))))
706 (string-match "^ *\"[^\"]*\" *$" name)
707 (not (string-match "[][.!()<>@,;:\\]" name))
710 "The From header name has bogus characters. Really post? "
714 ;; Check for long lines.
715 (or (gnus-check-before-posting 'long-lines)
717 (goto-char (point-min))
719 (concat "^" (regexp-quote mail-header-separator) "$"))
723 (< (current-column) 80))
724 (zerop (forward-line 1))))
729 "You have lines longer than 79 characters. Really post? ")))))
730 ;; Check for control characters.
731 (or (gnus-check-before-posting 'control-chars)
733 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
735 "The article contains control characters. Really post? ")
737 ;; Check excessive size.
738 (or (gnus-check-before-posting 'size)
739 (if (> (buffer-size) 60000)
741 (format "The article is %d octets long. Really post? "
744 ;; Use the (size . checksum) variable to see whether the
745 ;; article is empty or has only quoted text.
747 (gnus-check-before-posting 'new-text)
748 (if (and (= (buffer-size) (car gnus-article-check-size))
749 (= (gnus-article-checksum) (cdr gnus-article-check-size)))
751 "It looks like there's no new text in your article. Really post? ")
753 ;; Check the length of the signature.
754 (or (gnus-check-before-posting 'signature)
756 (goto-char (point-max))
757 (if (not (re-search-backward gnus-signature-separator nil t))
759 (if (> (count-lines (point) (point-max)) 4)
762 "Your .sig is %d lines; it should be max 4. Really post? "
763 (count-lines (point) (point-max))))
766 (defun gnus-article-checksum ()
770 (setq sum (logxor sum (following-char)))
774 ;; Returns non-nil if this type is not to be checked.
775 (defun gnus-check-before-posting (type)
777 (or (not gnus-check-before-posting)
778 (if (listp gnus-check-before-posting)
779 (memq type gnus-check-before-posting)
782 (defun gnus-cancel-news ()
783 "Cancel an article you posted."
785 (if (or gnus-expert-user
786 (gnus-yes-or-no-p "Do you really want to cancel this article? "))
791 (or (gnus-member-of-valid 'post gnus-newsgroup-name)
792 (error "This backend does not support canceling"))
794 ;; Get header info. from original article.
796 (gnus-article-show-all-headers)
797 (goto-char (point-min))
798 (search-forward "\n\n" nil 'move)
799 (narrow-to-region (point-min) (point))
800 (setq from (mail-fetch-field "from"))
801 (setq newsgroups (mail-fetch-field "newsgroups"))
802 (setq message-id (mail-fetch-field "message-id"))
803 (setq distribution (mail-fetch-field "distribution")))
804 ;; Verify if the article is absolutely user's by comparing
805 ;; user id with value of its From: field.
808 (downcase (mail-strip-quoted-names from))
809 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
811 (ding) (gnus-message 3 "This article is not yours.")
813 ;; Make control article.
814 (set-buffer (get-buffer-create " *Gnus-canceling*"))
815 (buffer-disable-undo (current-buffer))
817 (insert "Newsgroups: " newsgroups "\n"
818 "From: " (gnus-inews-real-user-address) "\n"
819 "Subject: cancel " message-id "\n"
820 "Control: cancel " message-id "\n"
822 (concat "Distribution: " distribution "\n")
824 mail-header-separator "\n"
825 "This is a cancel message from " from ".\n")
826 ;; Send the control article to NNTP server.
827 (gnus-message 5 "Canceling your article...")
829 (if (funcall gnus-inews-article-function)
830 (gnus-message 5 "Canceling your article...done")
833 (gnus-message 1 "Cancel failed; %s"
834 (gnus-status-message gnus-newsgroup-name))
837 ;; Kill the article buffer.
838 (kill-buffer (current-buffer))))))))
841 ;;; Lowlevel inews interface.
843 ;; Dummy to avoid byte-compile warning.
844 (defvar nnspool-rejected-article-hook)
846 (defun gnus-inews-article (&optional use-group-method)
847 "Post an article in current buffer using NNTP protocol."
848 (let ((artbuf (current-buffer))
851 (goto-char (point-max))
852 ;; Require a newline at the end of the buffer since inews may
853 ;; append a .signature.
854 (or (= (preceding-char) ?\n)
856 ;; Prepare article headers. All message body such as signature
857 ;; must be inserted before Lines: field is prepared.
859 (gnus-inews-narrow-to-headers)
861 (gnus-inews-cleanup-headers)
862 ;; Remove some headers.
863 (gnus-inews-remove-headers)
864 ;; Insert some headers.
865 (gnus-inews-insert-headers)
866 ;; Let the user do all of the above.
867 (run-hooks 'gnus-inews-article-header-hook)
868 ;; Copy the Gcc header, if any.
869 (setq gcc (mail-fetch-field "gcc"))
871 ;; Check whether the article is a good Net Citizen.
872 (if (and gnus-article-check-size
873 (not (gnus-inews-check-post)))
876 ;; We fudge a hook for nnspool.
877 (setq nnspool-rejected-article-hook
883 (set-buffer (, (buffer-name)))
884 (gnus-put-in-draft-group nil 'silent))
888 1 "Couldn't enter rejected article into draft group")))))))
890 ;; Looks ok, so we do the nasty.
892 ;; This hook may insert a signature.
894 (goto-char (point-min))
895 (let ((gnus-newsgroup-name (or (mail-fetch-field "newsgroups")
896 gnus-newsgroup-name)))
897 (run-hooks 'gnus-prepare-article-hook)))
898 ;; Send off copies using mail, if that is wanted.
899 (gnus-inews-send-mail-copy)
900 ;; Remove more headers.
901 (gnus-inews-remove-headers-after-mail)
902 ;; Copy the article over to a temp buffer.
903 (nnheader-set-temp-buffer " *Gnus-posting*")
904 (insert-buffer-substring artbuf)
905 ;; Remove the header separator.
906 (goto-char (point-min))
908 (concat "^" (regexp-quote mail-header-separator) "$"))
909 (replace-match "" t t)
910 ;; Run final inews hooks. This hook may do FCC.
911 ;; The article must be saved before being posted because
912 ;; `gnus-request-post' modifies the buffer.
913 (run-hooks 'gnus-inews-article-hook)
914 ;; Copy the article over to some group, possibly.
915 (and gcc (gnus-inews-do-gcc gcc))
920 (gnus-find-method-for-group gnus-newsgroup-name)
921 gnus-select-method) use-group-method))
922 (kill-buffer (current-buffer)))
923 (run-hooks 'gnus-message-sent-hook)
924 ;; We remove To and Cc headers to avoid re-mailing if the user
925 ;; accidentally (or purposefully) leans on the `C-c C-c' keys
926 ;; and the news server rejects the posting.
927 (gnus-inews-narrow-to-headers)
928 (nnheader-remove-header "^\\(to\\|[bcf]cc\\|cc\\):" t)
930 ;; If the posting was unsuccessful (that it, it was rejected) we
931 ;; put it into the draft group.
932 (or result (gnus-put-in-draft-group))
935 (defun gnus-inews-cleanup-headers ()
936 ;; Correct newsgroups field: change sequence of spaces to comma and
937 ;; eliminate spaces around commas. Eliminate imbedded line breaks.
938 (goto-char (point-min))
939 (if (re-search-forward "^Newsgroups: +" nil t)
943 (if (re-search-forward "^[^ \t]" nil t)
947 (goto-char (point-min))
948 (while (re-search-forward "\n[ \t]+" nil t)
949 (replace-match " " t t)) ;No line breaks (too confusing)
950 (goto-char (point-min))
951 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
952 (replace-match "," t t))
953 (goto-char (point-min))
954 ;; Remove a trailing comma.
955 (if (re-search-forward ",$" nil t)
956 (replace-match "" t t))))
958 ;; Added by Per Abrahamsen <abraham@iesd.auc.dk>.
959 ;; Help save the the world!
962 (let ((newsgroups (mail-fetch-field "newsgroups"))
963 (followup-to (mail-fetch-field "followup-to"))
966 (string-match "," newsgroups) (not followup-to))
968 (while (string-match "," newsgroups)
970 (cons (list (substring newsgroups 0 (match-beginning 0)))
972 (setq newsgroups (substring newsgroups (match-end 0))))
973 (setq groups (nreverse (cons (list newsgroups) groups)))
975 (setq to (completing-read
976 "Followups to: (default all groups) " groups))
977 (if (> (length to) 0)
979 (goto-char (point-min))
980 (insert "Followup-To: " to "\n")))))))
982 ;; Cleanup Followup-To.
983 (goto-char (point-min))
984 (if (search-forward-regexp "^Followup-To: +" nil t)
988 (if (re-search-forward "^[^ \t]" nil 'end)
991 (goto-char (point-min))
992 (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing)
993 (goto-char (point-min))
994 (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ","))))
997 (defun gnus-inews-remove-headers ()
998 (let ((case-fold-search t)
999 (headers gnus-removable-headers))
1000 ;; Remove toxic headers.
1002 (goto-char (point-min))
1003 (and (re-search-forward
1004 (concat "^" (downcase (format "%s" (car headers))))
1006 (delete-region (progn (beginning-of-line) (point))
1007 (progn (forward-line 1) (point))))
1008 (setq headers (cdr headers)))))
1010 (defun gnus-inews-insert-headers (&optional headers)
1011 "Prepare article headers.
1012 Headers already prepared in the buffer are not modified.
1013 Headers in `gnus-required-headers' will be generated."
1014 (let ((Date (gnus-inews-date))
1015 (Message-ID (gnus-inews-message-id))
1016 (Organization (gnus-inews-organization))
1017 (From (gnus-inews-user-name))
1018 (Path (gnus-inews-path))
1021 (In-Reply-To (gnus-inews-in-reply-to))
1024 (Lines (gnus-inews-lines))
1025 (X-Newsreader gnus-version)
1026 (X-Mailer gnus-version)
1027 (headers (or headers gnus-required-headers))
1028 (case-fold-search t)
1030 ;; First we remove any old generated headers.
1031 (let ((headers gnus-deletable-headers))
1033 (goto-char (point-min))
1034 (and (re-search-forward
1035 (concat "^" (symbol-name (car headers)) ": *") nil t)
1036 (get-text-property (1+ (match-beginning 0)) 'gnus-deletable)
1038 (setq headers (cdr headers))))
1039 ;; If there are References, and no "Re: ", then the thread has
1040 ;; changed name. See Son-of-1036.
1041 (if (and (mail-fetch-field "references")
1042 (get-buffer gnus-article-buffer))
1043 (let ((psubject (gnus-simplify-subject-re
1044 (mail-fetch-field "subject"))))
1045 (or (and psubject gnus-reply-subject
1046 (string= (gnus-simplify-subject-re gnus-reply-subject)
1049 (string-match "@" Message-ID)
1051 (concat (substring Message-ID 0 (match-beginning 0))
1053 (substring Message-ID (match-beginning 0))))))))
1054 ;; Go through all the required headers and see if they are in the
1055 ;; articles already. If they are not, or are empty, they are
1056 ;; inserted automatically - except for Subject, Newsgroups and
1059 (goto-char (point-min))
1060 (setq elem (car headers))
1062 (setq header (car elem))
1064 (if (or (not (re-search-forward
1065 (concat "^" (downcase (symbol-name header)) ":") nil t))
1067 ;; The header was found. We insert a space after the
1068 ;; colon, if there is none.
1069 (if (/= (following-char) ? ) (insert " "))
1070 ;; Find out whether the header is empty...
1071 (looking-at "[ \t]*$")))
1072 ;; So we find out what value we should insert.
1076 ((and (consp elem) (eq (car elem) 'optional))
1077 ;; This is an optional header. If the cdr of this
1078 ;; is something that is nil, then we do not insert
1080 (setq header (cdr elem))
1081 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
1082 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
1084 ;; The element is a cons. Either the cdr is a
1085 ;; string to be inserted verbatim, or it is a
1086 ;; function, and we insert the value returned from
1088 (or (and (stringp (cdr elem)) (cdr elem))
1089 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
1090 ((and (boundp header) (symbol-value header))
1091 ;; The element is a symbol. We insert the value
1092 ;; of this symbol, if any.
1093 (symbol-value header))
1095 ;; We couldn't generate a value for this header,
1096 ;; so we just ask the user.
1097 (read-from-minibuffer
1098 (format "Empty header for %s; enter value: " header)))))
1099 ;; Finally insert the header.
1105 (goto-char (point-max))
1106 (insert (symbol-name header) ": " value "\n")
1108 (replace-match value t t))
1109 ;; Add the deletable property to the headers that require it.
1110 (and (memq header gnus-deletable-headers)
1111 (progn (beginning-of-line) (looking-at "[^:]+: "))
1112 (add-text-properties
1113 (point) (match-end 0)
1114 '(gnus-deletable t face italic) (current-buffer)))))))
1115 (setq headers (cdr headers)))
1116 ;; Insert new Sender if the From is strange.
1117 (let ((from (mail-fetch-field "from"))
1118 (sender (mail-fetch-field "sender")))
1120 (not (gnus-check-before-posting 'sender))
1122 (downcase (car (gnus-extract-address-components from)))
1123 (downcase (gnus-inews-real-user-address))))
1127 (downcase (car (gnus-extract-address-components sender)))
1128 (downcase (gnus-inews-real-user-address))))))
1130 (goto-char (point-min))
1131 (and (re-search-forward "^Sender:" nil t)
1134 (insert "Original-")
1135 (beginning-of-line)))
1136 (insert "Sender: " (gnus-inews-real-user-address) "\n"))))))
1139 (defun gnus-inews-insert-signature ()
1140 "Insert a signature file.
1141 If `gnus-signature-function' is bound and returns a string, this
1142 string is used instead of the variable `gnus-signature-file'.
1143 In either case, if the string is a file name, this file is
1144 inserted. If the string is not a file name, the string itself is
1147 If you never want any signature inserted, set both of these variables to
1151 (or (and gnus-signature-function
1152 (funcall gnus-signature-function gnus-newsgroup-name))
1153 gnus-signature-file)))
1155 (or (file-exists-p signature)
1156 (string-match " " signature)
1158 "^/[^/]+/" (expand-file-name signature)))))
1160 (goto-char (point-max))
1161 (if (and mail-signature (search-backward "\n-- \n" nil t))
1163 ;; Delete any previous signatures.
1164 (if (search-backward "\n-- \n" nil t)
1165 (delete-region (point) (point-max)))
1166 (or (eolp) (insert "\n"))
1168 (if (file-exists-p signature)
1169 (insert-file-contents signature)
1171 (goto-char (point-max))
1172 (or (bolp) (insert "\n"))))))))
1174 ;; Written by "Mr. Per Persson" <pp@solace.mh.se>.
1175 (defun gnus-inews-insert-mime-headers ()
1176 (goto-char (point-min))
1177 (let ((mail-header-separator
1179 (goto-char (point-min))
1180 (if (and (search-forward (concat "\n" mail-header-separator "\n")
1182 (not (search-backward "\n\n" nil t)))
1183 mail-header-separator
1185 (or (mail-position-on-field "Mime-Version")
1188 (goto-char (point-min))
1189 (re-search-forward "[\200-\377]" nil t))
1190 (or (mail-position-on-field "Content-Type")
1191 (insert "text/plain; charset=ISO-8859-1"))
1192 (or (mail-position-on-field "Content-Transfer-Encoding")
1194 (t (or (mail-position-on-field "Content-Type")
1195 (insert "text/plain; charset=US-ASCII"))
1196 (or (mail-position-on-field "Content-Transfer-Encoding")
1197 (insert "7bit")))))))
1199 (defun gnus-inews-do-fcc ()
1200 "Process FCC: fields in current article buffer.
1201 Unless the first character of the field is `|', the article is saved
1202 to the specified file using the function specified by the variable
1203 gnus-author-copy-saver. The default function rmail-output saves in
1204 Unix mailbox format.
1205 If the first character is `|', the contents of the article is send to
1206 a program specified by the rest of the value."
1207 (let ((fcc-list nil)
1209 (case-fold-search t)) ;Should ignore case.
1212 (goto-char (point-min))
1213 (search-forward "\n\n")
1214 (narrow-to-region (point-min) (point))
1215 (goto-char (point-min))
1216 (while (re-search-forward "^FCC:[ \t]*" nil t)
1218 (cons (buffer-substring
1222 (skip-chars-backward " \t")
1225 (delete-region (match-beginning 0)
1226 (progn (forward-line 1) (point))))
1227 ;; Process FCC operations.
1230 (setq fcc-file (car fcc-list))
1231 (setq fcc-list (cdr fcc-list))
1232 (cond ((string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" fcc-file)
1233 (let ((program (substring fcc-file
1234 (match-beginning 1) (match-end 1))))
1235 ;; Suggested by yuki@flab.fujitsu.junet.
1236 ;; Send article to named program.
1237 (call-process-region (point-min) (point-max) shell-file-name
1238 nil nil nil "-c" program)))
1240 ;; Suggested by hyoko@flab.fujitsu.junet.
1241 ;; Save article in Unix mail format by default.
1242 (gnus-make-directory (file-name-directory fcc-file))
1243 (if (and gnus-author-copy-saver
1244 (not (eq gnus-author-copy-saver 'rmail-output)))
1245 (funcall gnus-author-copy-saver fcc-file)
1246 (if (and (file-readable-p fcc-file) (rmail-file-p fcc-file))
1247 (gnus-output-to-rmail fcc-file)
1248 (rmail-output fcc-file 1 t t))))))))))
1250 (defun gnus-inews-path ()
1252 (let ((login-name (gnus-inews-login-name)))
1253 (cond ((null gnus-use-generic-path)
1254 (concat (nth 1 gnus-select-method) "!" login-name))
1255 ((stringp gnus-use-generic-path)
1256 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1257 (concat gnus-use-generic-path "!" login-name))
1260 (defun gnus-inews-user-name ()
1261 "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"."
1262 (let ((full-name (gnus-inews-full-name))
1263 (address (if (or gnus-user-login-name gnus-use-generic-from
1264 gnus-local-domain (getenv "DOMAINNAME"))
1265 (concat (gnus-inews-login-name) "@"
1266 (gnus-inews-domain-name gnus-use-generic-from))
1267 user-mail-address)))
1268 (or gnus-user-from-line
1270 ;; User's full name.
1271 (cond ((string-equal full-name "&") ;Unix hack.
1272 (concat " (" (user-login-name) ")"))
1273 ((string-match "[^ ]+@[^ ]+ +(.*)" address)
1276 (concat " (" full-name ")")))))))
1278 (defun gnus-inews-real-user-address ()
1279 "Return the \"real\" user address.
1280 This function tries to ignore all user modifications, and
1281 give as trustworthy answer as possible."
1282 (concat (user-login-name) "@" (gnus-inews-full-address)))
1284 (defun gnus-inews-login-name ()
1285 "Return login name."
1286 (or gnus-user-login-name (getenv "LOGNAME") (user-login-name)))
1288 (defun gnus-inews-full-name ()
1289 "Return full user name."
1290 (or gnus-user-full-name (getenv "NAME") (user-full-name)))
1292 (defun gnus-inews-domain-name (&optional genericfrom)
1293 "Return user's domain name.
1294 If optional argument GENERICFROM is a string, use it as the domain
1295 name; if it is non-nil, strip off local host name from the domain name.
1296 If the function `system-name' returns full internet name and the
1297 domain is undefined, the domain name is got from it."
1298 (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME"))
1299 (let* ((system-name (system-name))
1301 (or (if (stringp genericfrom) genericfrom)
1302 (getenv "DOMAINNAME")
1304 ;; Function `system-name' may return full internet name.
1305 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
1306 (if (string-match "\\.." system-name)
1307 ;; Some machines return "name.", and that's not
1309 (substring system-name (1- (match-end 0))))
1310 (read-string "Domain name (no host): ")))
1311 (host (or (if (string-match "\\." system-name)
1312 (substring system-name 0 (match-beginning 0)))
1314 (if (string-equal "." (substring domain 0 1))
1315 (setq domain (substring domain 1)))
1316 ;; Support GENERICFROM as same as standard Bnews system.
1317 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
1318 (cond ((null genericfrom)
1319 (concat host "." domain))
1320 ;;((stringp genericfrom) genericfrom)
1322 (if (string-match "\\." (system-name))
1324 (substring user-mail-address
1325 (1+ (string-match "@" user-mail-address))))))
1327 (defun gnus-inews-full-address ()
1328 (let ((domain (gnus-inews-domain-name))
1329 (system (system-name))
1330 (case-fold-search t))
1331 (if (string-match "\\." system) system
1332 (if (string-match (concat "^" (regexp-quote system)) domain) domain
1333 (concat system "." domain)))))
1335 (defun gnus-inews-message-id ()
1336 "Generate unique Message-ID for user."
1337 ;; Message-ID should not contain a slash and should be terminated by
1338 ;; a number. I don't know the reason why it is so.
1339 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">"))
1341 (defvar gnus-unique-id-char nil)
1343 ;; If you ever change this function, make sure the new version
1344 ;; cannot generate IDs that the old version could.
1345 ;; You might for example insert a "." somewhere (not next to another dot
1346 ;; or string boundary), or modify the newsreader name to "Ding".
1347 (defun gnus-inews-unique-id ()
1348 ;; Dont use microseconds from (current-time), they may be unsupported.
1349 ;; Instead we use this randomly inited counter.
1350 (setq gnus-unique-id-char
1351 (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1352 ;; (current-time) returns 16-bit ints,
1353 ;; and 2^16*25 just fits into 4 digits i base 36.
1355 (let ((tm (if (fboundp 'current-time)
1356 (current-time) '(12191 46742 287898))))
1358 (if (memq system-type '(ms-dos emx vax-vms))
1359 (let ((user (downcase (gnus-inews-login-name))))
1360 (while (string-match "[^a-z0-9_]" user)
1361 (aset user (match-beginning 0) ?_))
1363 (gnus-number-base36 (user-uid) -1))
1364 (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4)
1365 (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4)
1366 ;; Append the newsreader name, because while the generated
1367 ;; ID is unique to this newsreader, other newsreaders might
1368 ;; otherwise generate the same ID via another algorithm.
1372 (defun gnus-inews-date ()
1373 "Current time string."
1374 (timezone-make-date-arpa-standard
1375 (current-time-string) (current-time-zone)))
1377 (defun gnus-inews-organization ()
1378 "Return user's organization.
1379 The ORGANIZATION environment variable is used if defined.
1380 If not, the variable `gnus-local-organization' is used instead.
1381 If it is a function, the function will be called with the current
1382 newsgroup name as the argument.
1383 If this is a file name, the contents of this file will be used as the
1385 (let* ((organization
1386 (or (getenv "ORGANIZATION")
1387 (if gnus-local-organization
1388 (if (and (symbolp gnus-local-organization)
1389 (fboundp gnus-local-organization))
1390 (funcall gnus-local-organization gnus-newsgroup-name)
1391 gnus-local-organization))
1392 gnus-organization-file
1393 "~/.organization")))
1394 (and (stringp organization)
1395 (> (length organization) 0)
1396 (or (file-exists-p organization)
1397 (string-match " " organization)
1398 (not (string-match "^/usr/lib/" organization)))
1400 (gnus-set-work-buffer)
1401 (if (file-exists-p organization)
1402 (insert-file-contents organization)
1403 (insert organization))
1404 (goto-char (point-min))
1405 (while (re-search-forward " *\n *" nil t)
1406 (replace-match " " t t))
1407 (buffer-substring (point-min) (point-max))))))
1409 (defun gnus-inews-lines ()
1410 "Count the number of lines and return numeric string."
1414 (goto-char (point-min))
1416 (concat "^" (regexp-quote mail-header-separator) "$"))
1418 (int-to-string (count-lines (point) (point-max))))))
1420 (defun gnus-inews-in-reply-to ()
1421 "Return the In-Reply-To header for this message."
1426 ;;; Gnus Mail Functions
1429 ;;; Mail reply commands of Gnus summary mode
1431 (defun gnus-summary-reply (yank &optional yank-articles)
1432 "Reply mail to news author.
1433 If prefix argument YANK is non-nil, original article is yanked automatically.
1434 Customize the variable gnus-mail-reply-method to use another mailer."
1436 ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells)
1437 ;; Stripping headers should be specified with mail-yank-ignored-headers.
1438 (gnus-set-global-variables)
1439 (if yank-articles (gnus-summary-goto-subject (car yank-articles)))
1440 (gnus-summary-select-article)
1441 (bury-buffer gnus-article-buffer)
1442 (gnus-mail-reply (or yank-articles (not (not yank)))))
1444 (defun gnus-summary-reply-with-original (n)
1445 "Reply mail to news author with original article.
1446 Customize the variable gnus-mail-reply-method to use another mailer."
1448 (gnus-summary-reply t (gnus-summary-work-articles n)))
1450 (defun gnus-summary-mail-forward (post)
1451 "Forward the current message to another user.
1452 Customize the variable gnus-mail-forward-method to use another mailer."
1454 (gnus-set-global-variables)
1455 (gnus-summary-select-article)
1456 (gnus-copy-article-buffer)
1458 (gnus-forward-using-post gnus-article-copy)
1459 (gnus-mail-forward gnus-article-copy)))
1461 (defun gnus-summary-post-forward ()
1462 "Forward the current article to a newsgroup."
1464 (gnus-summary-mail-forward t))
1466 (defvar gnus-nastygram-message
1467 "The following article was inappropriately posted to %s.\n"
1468 "Format string to insert in nastygrams.
1469 The current group name will be inserted at \"%s\".")
1471 (defun gnus-summary-mail-nastygram (n)
1472 "Send a nastygram to the author of the current article."
1474 (if (or gnus-expert-user
1476 "Really send a nastygram to the author of the current article? "))
1477 (let ((group gnus-newsgroup-name))
1478 (gnus-summary-reply-with-original n)
1479 (set-buffer gnus-mail-buffer)
1480 (insert (format gnus-nastygram-message group))
1481 (gnus-mail-send-and-exit))))
1483 (defun gnus-summary-mail-other-window ()
1484 "Compose mail in other window.
1485 Customize the variable `gnus-mail-other-window-method' to use another
1488 (gnus-set-global-variables)
1491 (defun gnus-new-mail (&optional to)
1492 (pop-to-buffer gnus-mail-buffer)
1494 (gnus-mail-setup 'new to)
1495 (gnus-inews-modify-mail-mode-map))
1497 (defun gnus-mail-reply (&optional yank to-address followup)
1499 (set-buffer gnus-summary-buffer)
1500 (let ((group (gnus-group-real-name gnus-newsgroup-name))
1501 (cur (cons (current-buffer) (cdr gnus-article-current)))
1502 (winconf (current-window-configuration))
1503 from subject date reply-to message-of to cc
1504 references message-id sender follow-to sendto elt new-cc)
1505 (set-buffer (get-buffer-create gnus-mail-buffer))
1507 (if (and (buffer-modified-p)
1510 "Unsent message being composed; erase it? ")))
1514 (gnus-copy-article-buffer)
1516 (set-buffer gnus-article-copy)
1517 (gnus-narrow-to-headers)
1519 ;; This is a regular reply.
1520 (if (and (symbolp gnus-reply-to-function)
1521 (fboundp gnus-reply-to-function))
1522 (setq follow-to (funcall gnus-reply-to-function group)))
1523 ;; This is a followup.
1524 (if (and (symbolp gnus-followup-to-function)
1525 (fboundp gnus-followup-to-function))
1528 (funcall gnus-followup-to-function group)))))
1529 (setq from (mail-fetch-field "from"))
1530 (setq date (or (mail-fetch-field "date")
1531 (mail-header-date gnus-current-headers)))
1532 (setq message-of (gnus-message-of from date))
1533 (setq sender (mail-fetch-field "sender"))
1534 (setq subject (or (mail-fetch-field "subject") "none"))
1535 ;; Remove any (buggy) Re:'s that are present and make a
1537 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1538 (setq subject (substring subject (match-end 0))))
1539 (setq subject (concat "Re: " subject))
1540 (setq to (mail-fetch-field "to"))
1541 (setq cc (mail-fetch-field "cc"))
1542 (setq reply-to (mail-fetch-field "reply-to"))
1543 (setq references (mail-fetch-field "references"))
1544 (setq message-id (mail-fetch-field "message-id"))
1548 ;; When we followup, we want all the headers, I would think.
1549 (setq new-cc (rmail-dont-reply-to
1551 (if cc (concat (if to ", " "") cc) ""))))
1552 (let ((rmail-dont-reply-to-names
1553 (regexp-quote (mail-strip-quoted-names
1554 (or to-address reply-to from "")))))
1555 (setq new-cc (rmail-dont-reply-to new-cc))))
1559 (setq news-reply-yank-from (or from "(nobody)"))
1560 (setq news-reply-yank-message-id
1561 (or message-id "(unknown Message-ID)"))
1563 ;; Gather the "to" addresses out of the follow-to list and remove
1565 (if (and follow-to (listp follow-to))
1566 (while (setq elt (assoc "To" follow-to))
1567 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1568 (setq follow-to (delq elt follow-to))))
1571 (if followup 'followup 'reply)
1573 (if (and follow-to (not (stringp follow-to))) sendto
1574 (or follow-to reply-to from sender "")))
1576 (if (zerop (length new-cc)) nil new-cc)
1579 (make-local-variable 'gnus-article-reply)
1580 (setq gnus-article-reply cur)
1581 (make-local-variable 'gnus-prev-winconf)
1582 (setq gnus-prev-winconf winconf)
1583 (make-local-variable 'gnus-reply-subject)
1584 (setq gnus-reply-subject subject)
1585 (make-local-variable 'gnus-in-reply-to)
1586 (setq gnus-in-reply-to message-of)
1588 (auto-save-mode auto-save-default)
1589 (gnus-inews-modify-mail-mode-map)
1591 (if (and follow-to (listp follow-to))
1593 (goto-char (point-min))
1594 (re-search-forward "^To:" nil t)
1598 (insert (car (car follow-to)) ": " (cdr (car follow-to)) "\n")
1599 (setq follow-to (cdr follow-to)))))
1600 (nnheader-insert-references references message-id)
1602 ;; Now the headers should be ok, so we do the yanking.
1603 (goto-char (point-min))
1605 (concat "^" (regexp-quote mail-header-separator) "$"))
1608 (gnus-configure-windows 'reply 'force)
1609 (let ((last (point))
1611 (if (not (listp yank))
1614 (mail-yank-original nil))
1615 (or mail-yank-hooks mail-citation-hook
1616 (run-hooks 'news-reply-header-hook)))
1618 (save-window-excursion
1619 (set-buffer gnus-summary-buffer)
1620 (gnus-summary-select-article nil nil nil (car yank))
1621 (gnus-summary-remove-process-mark (car yank)))
1623 (gnus-copy-article-buffer)
1624 (mail-yank-original nil)
1626 (or mail-yank-hooks mail-citation-hook
1627 (run-hooks 'news-reply-header-hook))
1629 (setq yank (cdr yank))))
1631 (gnus-configure-windows 'reply-yank 'force))
1632 (run-hooks 'gnus-mail-hook)))))
1634 (defun gnus-new-news (&optional group)
1635 (let ((winconf (current-window-configuration))
1637 (and gnus-interactive-post
1638 (not gnus-expert-user)
1641 (setq gnus-newsgroup-name
1643 (completing-read "Group: " gnus-active-hashtb)))
1644 (setq subject (read-string "Subject: "))))
1645 (pop-to-buffer gnus-post-news-buffer)
1648 ;; Let posting styles be configured.
1649 (gnus-configure-posting-styles)
1650 (news-setup nil subject nil (gnus-group-real-name group) nil)
1651 (gnus-inews-insert-signature)
1652 (and gnus-post-prepare-function
1653 (symbolp gnus-post-prepare-function)
1654 (fboundp gnus-post-prepare-function)
1655 (funcall gnus-post-prepare-function group))
1656 (run-hooks 'gnus-post-prepare-hook)
1657 (make-local-variable 'gnus-prev-winconf)
1658 (setq gnus-prev-winconf winconf)
1659 (gnus-inews-modify-mail-mode-map)
1660 (local-set-key "\C-c\C-c" 'gnus-inews-news)))
1662 (defun gnus-news-followup (&optional yank group)
1664 (set-buffer gnus-summary-buffer)
1665 (if (not (or (not gnus-novice-user)
1668 "Are you sure you want to post to all of USENET? ")))
1670 (let ((group (gnus-group-real-name (or group gnus-newsgroup-name)))
1671 (cur (cons (current-buffer) (cdr gnus-article-current)))
1672 (winconf (current-window-configuration))
1673 from subject date reply-to message-of
1674 references message-id sender follow-to sendto elt
1675 followup-to distribution)
1676 (set-buffer (get-buffer-create gnus-post-news-buffer))
1678 (if (and (buffer-modified-p)
1681 "Unsent message being composed; erase it? ")))
1685 (gnus-copy-article-buffer)
1687 (set-buffer gnus-article-copy)
1688 (gnus-narrow-to-headers)
1689 (if (and (symbolp gnus-followup-to-function)
1690 (fboundp gnus-followup-to-function))
1693 (funcall gnus-followup-to-function group))))
1694 (setq from (mail-fetch-field "from"))
1695 (setq date (or (mail-fetch-field "date")
1696 (mail-header-date gnus-current-headers)))
1697 (setq message-of (gnus-message-of from date))
1698 (setq subject (or (mail-fetch-field "subject") "none"))
1699 ;; Remove any (buggy) Re:'s that are present and make a
1701 (and (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
1702 (setq subject (substring subject (match-end 0))))
1703 (setq subject (concat "Re: " subject))
1704 (setq references (mail-fetch-field "references"))
1705 (setq message-id (mail-fetch-field "message-id"))
1706 (setq followup-to (mail-fetch-field "followup-to"))
1707 (setq distribution (mail-fetch-field "distribution"))
1708 ;; Remove bogus distribution.
1709 (and (stringp distribution)
1710 (string-match "world" distribution)
1711 (setq distribution nil))
1714 (setq news-reply-yank-from (or from "(nobody)"))
1715 (setq news-reply-yank-message-id
1716 (or message-id "(unknown Message-ID)"))
1718 ;; Gather the "to" addresses out of the follow-to list and remove
1720 (if (and follow-to (listp follow-to))
1721 (while (setq elt (assoc "Newsgroups" follow-to))
1722 (setq sendto (concat sendto (and sendto ", ") (cdr elt)))
1723 (setq follow-to (delq elt follow-to))))
1725 ;; Let posting styles be configured.
1726 (gnus-configure-posting-styles)
1728 (news-setup nil subject nil
1731 gnus-use-followup-to
1732 (or (not (eq gnus-use-followup-to 'ask))
1735 "Use Followup-To %s? " follow-to))))
1739 (make-local-variable 'gnus-article-reply)
1740 (setq gnus-article-reply cur)
1741 (make-local-variable 'gnus-prev-winconf)
1742 (setq gnus-prev-winconf winconf)
1743 (make-local-variable 'gnus-reply-subject)
1744 (setq gnus-reply-subject (mail-header-subject gnus-current-headers))
1745 (make-local-variable 'gnus-in-reply-to)
1746 (setq gnus-in-reply-to message-of)
1748 (gnus-inews-insert-signature)
1750 (and gnus-post-prepare-function
1751 (symbolp gnus-post-prepare-function)
1752 (fboundp gnus-post-prepare-function)
1753 (funcall gnus-post-prepare-function group))
1754 (run-hooks 'gnus-post-prepare-hook)
1756 (auto-save-mode auto-save-default)
1757 (gnus-inews-modify-mail-mode-map)
1758 (local-set-key "\C-c\C-c" 'gnus-inews-news)
1760 (if (and follow-to (listp follow-to))
1762 (goto-char (point-min))
1763 (and (re-search-forward "^Newsgroups:" nil t)
1766 (insert (car (car follow-to)) ": "
1767 (cdr (car follow-to)) "\n")
1768 (setq follow-to (cdr follow-to)))))
1770 ;; If a distribution existed, we use it.
1773 (mail-position-on-field "Distribution")
1774 (insert distribution)))
1776 (nnheader-insert-references references message-id)
1778 ;; Handle `gnus-auto-mail-to-author'.
1779 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
1780 ;; Revised to respect Reply-To by Ulrik Dickow <dickow@nbi.dk>.
1781 (let ((to (if (if (eq gnus-auto-mail-to-author 'ask)
1782 (y-or-n-p "Also send mail to author? ")
1783 gnus-auto-mail-to-author)
1785 (set-buffer gnus-article-copy)
1786 (gnus-fetch-field "reply-to"))
1788 (x-mail (save-excursion
1789 (set-buffer gnus-article-copy)
1790 (gnus-fetch-field "x-mail-copy-to"))))
1791 ;; Deny sending copy if there's a negative X-Mail-Copy-To
1794 (if (and (string= x-mail "never")
1795 (not (eq gnus-auto-mail-to-author 'force)))
1798 ;; Insert a To or Cc header.
1800 (if (mail-fetch-field "To")
1803 (insert "Cc: " to "\n"))
1804 (mail-position-on-field "To")
1807 ;; Handle author copy using BCC field.
1808 (if (and gnus-mail-self-blind
1809 (not (mail-fetch-field "bcc")))
1811 (mail-position-on-field "Bcc")
1812 (insert (if (stringp gnus-mail-self-blind)
1813 gnus-mail-self-blind
1814 (user-login-name)))))
1815 ;; Handle author copy using FCC field.
1816 (if gnus-author-copy
1818 (mail-position-on-field "Fcc")
1819 (insert gnus-author-copy)))
1821 ;; Now the headers should be ok, so we do the yanking.
1822 (goto-char (point-min))
1824 (concat "^" (regexp-quote mail-header-separator) "$"))
1827 (gnus-configure-windows 'followup 'force)
1828 (let ((last (point))
1830 (if (not (listp yank))
1833 (mail-yank-original nil))
1834 (or mail-yank-hooks mail-citation-hook
1835 (run-hooks 'news-reply-header-hook)))
1837 (save-window-excursion
1838 (set-buffer gnus-summary-buffer)
1839 (gnus-summary-select-article nil nil nil (car yank))
1840 (gnus-summary-remove-process-mark (car yank)))
1842 (gnus-copy-article-buffer)
1843 (mail-yank-original nil)
1845 (or mail-yank-hooks mail-citation-hook
1846 (run-hooks 'news-reply-header-hook))
1848 (setq yank (cdr yank))))
1850 (gnus-configure-windows 'followup-yank 'force))
1852 (make-local-variable 'gnus-article-check-size)
1853 (setq gnus-article-check-size
1854 (cons (buffer-size) (gnus-article-checksum))))))))
1856 (defun gnus-message-of (from date)
1857 "Take a FROM and a DATE and create an IN-REPLY-TO."
1863 (string-match " *at \\| *@ \\| *(\\| *<" from)))
1864 (concat (if stop-pos (substring from 0 stop-pos) from)
1866 (if (or (not date) (string= date ""))
1867 "(unknown date)" date))))))
1869 (defun gnus-mail-yank-original ()
1872 (mail-yank-original nil))
1873 (or mail-yank-hooks mail-citation-hook
1874 (run-hooks 'news-reply-header-hook)))
1876 (defun gnus-mail-send-and-exit (&optional dont-send)
1877 "Send the current mail and return to Gnus."
1879 (let* ((reply gnus-article-reply)
1880 (winconf gnus-prev-winconf)
1881 (address-group gnus-add-to-address)
1882 (to-address (and address-group
1883 (mail-fetch-field "to"))))
1884 (setq gnus-add-to-address nil)
1885 (or dont-send (gnus-mail-send))
1887 ;; This mail group doesn't have a `to-address', so we add one
1890 (gnus-group-add-parameter
1891 address-group (cons 'to-address to-address)))
1892 (if (get-buffer gnus-group-buffer)
1894 (if (gnus-buffer-exists-p (car-safe reply))
1896 (set-buffer (car reply))
1898 (gnus-summary-mark-article-as-replied
1900 (and winconf (set-window-configuration winconf))))))
1902 (defun gnus-put-message ()
1903 "Put the current message in some group and return to Gnus."
1905 (let ((reply gnus-article-reply)
1906 (winconf gnus-prev-winconf)
1907 (group gnus-newsgroup-name)
1910 (or (and group (not (gnus-group-read-only-p group)))
1911 (setq group (read-string "Put in group: " nil
1912 (gnus-writable-groups))))
1913 (and (gnus-gethash group gnus-newsrc-hashtb)
1914 (error "No such group: %s" group))
1919 (gnus-inews-narrow-to-headers)
1920 (let (gnus-deletable-headers)
1921 (if (eq major-mode 'mail-mode)
1922 (gnus-inews-insert-headers gnus-required-mail-headers)
1923 (gnus-inews-insert-headers)))
1924 (goto-char (point-max))
1925 (insert "Gcc: " group "\n")
1930 (if (get-buffer gnus-group-buffer)
1932 (if (gnus-buffer-exists-p (car-safe reply))
1934 (set-buffer (car reply))
1936 (gnus-summary-mark-article-as-replied
1938 (and winconf (set-window-configuration winconf))))))
1941 (defun gnus-forward-make-subject (buffer)
1944 (concat "[" (if (memq 'mail (assoc (symbol-name
1945 (car (gnus-find-method-for-group
1946 gnus-newsgroup-name)))
1947 gnus-valid-select-methods))
1948 (gnus-fetch-field "From")
1949 gnus-newsgroup-name)
1950 "] " (or (gnus-fetch-field "Subject") ""))))
1952 (defun gnus-forward-insert-buffer (buffer)
1953 (let ((beg (goto-char (point-max))))
1954 (insert "------- Start of forwarded message -------\n")
1955 (insert-buffer-substring buffer)
1956 (goto-char (point-max))
1957 (insert "------- End of forwarded message -------\n")
1958 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
1960 (while (setq beg (next-single-property-change (point) 'invisible))
1962 (delete-region beg (or (next-single-property-change
1966 (defun gnus-mail-forward (&optional buffer)
1967 "Forward the current message to another user using mail."
1968 (let* ((forward-buffer (or buffer (current-buffer)))
1969 (winconf (current-window-configuration))
1970 (subject (gnus-forward-make-subject forward-buffer)))
1971 (set-buffer (get-buffer-create gnus-mail-buffer))
1972 (if (and (buffer-modified-p)
1975 "Unsent message being composed; erase it? ")))
1978 (gnus-mail-setup 'forward nil subject)
1979 (gnus-inews-modify-mail-mode-map)
1980 (make-local-variable 'gnus-prev-winconf)
1981 (setq gnus-prev-winconf winconf)
1982 (gnus-forward-insert-buffer forward-buffer)
1983 (goto-char (point-min))
1984 (re-search-forward "^To: " nil t)
1985 (gnus-configure-windows 'mail-forward 'force)
1986 ;; You have a chance to arrange the message.
1987 (run-hooks 'gnus-mail-forward-hook)
1988 (run-hooks 'gnus-mail-hook))))
1990 (defun gnus-forward-using-post (&optional buffer)
1992 (let* ((forward-buffer (or buffer (current-buffer)))
1993 (subject (gnus-forward-make-subject forward-buffer))
1994 (gnus-newsgroup-name nil))
1995 (gnus-post-news 'post nil nil nil nil subject)
1997 (gnus-forward-insert-buffer forward-buffer)
1998 ;; You have a chance to arrange the message.
1999 (run-hooks 'gnus-mail-forward-hook)))))
2001 (defun gnus-mail-other-window-using-mail ()
2002 "Compose mail other window using mail."
2003 (let ((winconf (current-window-configuration)))
2004 (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer))
2005 (gnus-inews-modify-mail-mode-map)
2006 (make-local-variable 'gnus-prev-winconf)
2007 (setq gnus-prev-winconf winconf)
2008 (run-hooks 'gnus-mail-hook)
2009 (gnus-configure-windows 'summary-mail 'force)))
2011 (defun gnus-article-mail (yank)
2012 "Send a reply to the address near point.
2013 If YANK is non-nil, include the original article."
2017 (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
2018 (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
2021 (switch-to-buffer gnus-summary-buffer)
2022 (gnus-mail-reply yank address)))))
2025 "Send a bug report to the Gnus maintainers."
2027 (let ((winconf (current-window-configuration)))
2028 (delete-other-windows)
2029 (switch-to-buffer "*Gnus Help Bug*")
2031 (insert gnus-bug-message)
2032 (goto-char (point-min))
2033 (pop-to-buffer "*Gnus Bug*")
2036 (mail-setup gnus-maintainer nil nil nil nil nil)
2037 (auto-save-mode auto-save-default)
2038 (make-local-variable 'gnus-prev-winconf)
2039 (setq gnus-prev-winconf winconf)
2040 (gnus-inews-modify-mail-mode-map)
2041 (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit)
2042 (goto-char (point-min))
2043 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2045 (insert (format "%s\n%s\n\n\n\n\n" (gnus-version) (emacs-version)))
2047 (goto-char (point-min))
2048 (search-forward "Subject: " nil t)
2051 (defun gnus-bug-mail-send-and-exit ()
2052 "Send the bug message and exit."
2054 (and (get-buffer "*Gnus Help Bug*")
2055 (kill-buffer "*Gnus Help Bug*"))
2056 (gnus-mail-send-and-exit))
2058 (defun gnus-debug ()
2059 "Attemps to go through the Gnus source file and report what variables have been changed.
2060 The source file has to be in the Emacs load path."
2062 (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el"))
2063 file dirs expr olist sym)
2064 (message "Please wait while we snoop your variables...")
2067 (set-buffer (get-buffer-create " *gnus bug info*"))
2068 (buffer-disable-undo (current-buffer))
2071 (setq dirs load-path)
2073 (if (or (not (car dirs))
2074 (not (stringp (car dirs)))
2076 (setq file (concat (file-name-as-directory
2077 (car dirs)) (car files))))))
2078 (setq dirs (cdr dirs))
2080 (insert-file-contents file)
2081 (goto-char (point-min))
2082 (or (re-search-forward "^;;* *Internal variables" nil t)
2083 (error "Malformed sources in file %s" file))
2084 (narrow-to-region (point-min) (point))
2085 (goto-char (point-min))
2086 (while (setq expr (condition-case ()
2087 (read (current-buffer)) (error nil)))
2089 (and (eq (car expr) 'defvar)
2090 (stringp (nth 3 expr))
2091 (or (not (boundp (nth 1 expr)))
2092 (not (equal (eval (nth 2 expr))
2093 (symbol-value (nth 1 expr)))))
2094 (setq olist (cons (nth 1 expr) olist)))
2096 (setq files (cdr files)))
2097 (kill-buffer (current-buffer)))
2098 (insert "------------------- Environment follows -------------------\n\n")
2100 (if (boundp (car olist))
2101 (insert "(setq " (symbol-name (car olist))
2102 (if (or (consp (setq sym (symbol-value (car olist))))
2104 (not (or (eq sym nil)
2107 (prin1-to-string (symbol-value (car olist))) ")\n")
2108 (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n"))
2109 (setq olist (cdr olist)))
2111 ;; Remove any null chars - they seem to cause trouble for some
2112 ;; mailers. (Byte-compiled output from the stuff above.)
2113 (goto-char (point-min))
2114 (while (re-search-forward "[\000\200]" nil t)
2115 (replace-match "" t t))))
2118 ;;; Treatment of rejected articles.
2123 (defun gnus-summary-resend-bounced-mail (fetch)
2124 "Re-mail the current message.
2125 This only makes sense if the current message is a bounce message than
2126 contains some mail you have written which has been bounced back to
2128 If FETCH, try to fetch the article that this is a reply to, if indeed
2131 (gnus-summary-select-article t)
2132 ;; Create a mail buffer.
2135 (insert-buffer-substring gnus-article-buffer)
2136 (goto-char (point-min))
2137 (search-forward "\n\n")
2138 ;; We remove everything before the bounced mail.
2141 (if (re-search-forward "[^ \t]*:" nil t)
2147 (gnus-narrow-to-headers)
2148 (nnheader-remove-header gnus-bounced-headers-junk t)
2149 (setq references (mail-fetch-field "references"))
2150 (goto-char (point-max))
2151 (insert mail-header-separator)))
2152 ;; If there are references, we fetch the article we answered to.
2155 (string-match "\\(<[^]+>\\)[ \t]*$" references)
2156 (gnus-summary-refer-article
2157 (substring references (match-beginning 1) (match-end 1)))
2159 (gnus-summary-show-all-headers)
2160 (gnus-configure-windows 'compose-bounce))))
2161 (goto-char (point-min)))
2165 (defun gnus-mail-send ()
2166 "Send the current buffer as mail.
2167 Headers will be generated before sending."
2172 (gnus-inews-narrow-to-headers)
2173 (gnus-inews-insert-headers gnus-required-mail-headers)))
2175 ;; Remove the header separator.
2176 (goto-char (point-min))
2177 (and (re-search-forward
2178 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2179 (replace-match "" t t))
2180 ;; Run final inews hooks. This hook may do FCC.
2181 (run-hooks 'gnus-inews-article-hook)
2183 (gnus-narrow-to-headers)
2184 (nnheader-remove-header "^[gf]cc:" t)
2186 (goto-char (point-min))
2187 (search-forward "\n\n")
2189 (insert mail-header-separator)
2191 (run-hooks 'gnus-message-sent-hook))
2193 (defun gnus-inews-modify-mail-mode-map ()
2194 (use-local-map (copy-keymap (current-local-map)))
2195 (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit)
2196 (local-set-key "\C-c\C-p" 'gnus-put-message)
2197 (local-set-key "\C-c\C-d" 'gnus-enter-into-draft-group))
2199 (defun gnus-mail-setup (type &optional to subject in-reply-to cc
2200 replybuffer actions)
2201 ;; Let posting styles be configured.
2202 (gnus-configure-posting-styles)
2206 (and (eq type 'reply)
2207 (eq gnus-mail-reply-method 'gnus-mail-reply-using-mhe))
2208 (and (eq type 'forward)
2209 (eq gnus-mail-forward-method 'gnus-mail-forward-using-mhe))
2211 (eq gnus-mail-other-window-method
2212 'gnus-mail-other-window-using-mhe)))
2213 'gnus-mh-mail-setup)
2215 (and (eq type 'reply)
2216 (eq gnus-mail-reply-method 'gnus-mail-reply-using-vm))
2217 (and (eq type 'forward)
2218 (eq gnus-mail-forward-method 'gnus-mail-forward-using-vm))
2220 (eq gnus-mail-other-window-method
2221 'gnus-mail-other-window-using-vm)))
2222 'gnus-vm-mail-setup)
2223 (t 'gnus-sendmail-mail-setup))
2224 to subject in-reply-to cc replybuffer actions))
2226 (defun gnus-sendmail-mail-setup (to subject in-reply-to cc replybuffer actions)
2228 (mail-setup to subject nil cc replybuffer actions))
2232 ;; Do Gcc handling, which copied the message over to some group.
2233 (defun gnus-inews-do-gcc (&optional gcc)
2236 (gnus-narrow-to-headers)
2237 (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
2240 () ; Nothing to be done.
2241 (nnheader-remove-header "gcc")
2242 ;; Copy the article over to some group(s).
2243 (while (string-match
2244 "^[ \t]*\\([^ \t]+\\)\\([ \t]+\\|$\\)" gcc)
2245 (setq end (match-end 0))
2247 (gnus-request-accept-article
2248 (substring gcc (match-beginning 1) (match-end 1)) t)
2250 (setq gcc (substring gcc end))))))))
2252 (defun gnus-inews-insert-gcc ()
2253 (let* ((group gnus-outgoing-message-group)
2255 ((and (symbolp group) (fboundp group))
2257 ((or (stringp group) (list group))
2262 (if (stringp group) group
2263 (mapconcat 'identity group " "))
2266 ;;; Handling rejected (and postponed) news.
2268 (defun gnus-draft-group ()
2269 "Return the name of the draft group."
2270 (gnus-group-prefixed-name
2271 (file-name-nondirectory gnus-draft-group-directory)
2272 (list 'nndir gnus-draft-group-directory)))
2274 (defun gnus-make-draft-group ()
2275 "Make the draft group or die trying."
2276 (let* ((method (` (nndir "private"
2277 (nndir-directory (, gnus-draft-group-directory)))))
2278 (group (gnus-group-prefixed-name
2279 (file-name-nondirectory gnus-draft-group-directory)
2281 (or (gnus-gethash group gnus-newsrc-hashtb)
2282 (gnus-group-make-group (gnus-group-real-name group) method)
2283 (error "Can't create the draft group"))
2286 (defun gnus-enter-into-draft-group ()
2287 "Enter the current buffer into the draft group."
2289 (gnus-put-in-draft-group t))
2291 (defun gnus-put-in-draft-group (&optional generate silent)
2292 "Does the actual putting."
2293 (let ((group (gnus-make-draft-group))
2294 (type (list major-mode (buffer-name) gnus-newsgroup-name
2297 (buf (current-buffer)))
2300 (nnheader-set-temp-buffer " *enter-draft*")
2301 (insert-buffer-substring buf)
2304 (gnus-inews-narrow-to-headers)
2305 (let (gnus-deletable-headers)
2306 (if (eq mode 'mail-mode)
2307 (gnus-inews-insert-headers gnus-required-mail-headers)
2308 (gnus-inews-insert-headers)))
2311 (goto-char (point-min))
2312 ;; We have to store whether we are in a mail group or news group.
2313 (insert (format "X-Gnus-Draft-Type: %S\n" type))
2314 (and (re-search-forward
2315 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2316 (replace-match "" t t))
2318 (gnus-request-accept-article group t)
2319 (kill-buffer (current-buffer)))
2321 (gnus-mail-send-and-exit 'dont-send))))
2322 (set-buffer-modified-p nil)))
2324 (defun gnus-summary-send-draft ()
2325 "Enter a mail/post buffer to edit and send the draft."
2327 (gnus-set-global-variables)
2328 (gnus-summary-select-article t)
2329 ;; First we find the draft type.
2332 (set-buffer gnus-article-buffer)
2334 (gnus-narrow-to-headers)
2335 (setq type (condition-case ()
2336 (read (mail-fetch-field "x-gnus-draft-type"))
2340 (error "Unknown draft type"))
2341 ;; Get to the proper buffer.
2342 (set-buffer (get-buffer-create (nth 1 type)))
2343 ;; It might be modified.
2344 (and (buffer-modified-p)
2345 (or (gnus-yes-or-no-p "Unsent message being composed; discard it? ")
2347 (setq buffer-read-only nil)
2348 (buffer-enable-undo (current-buffer))
2351 (funcall (car type))
2352 (and (eq major-mode 'mail-mode)
2353 (gnus-inews-modify-mail-mode-map))
2354 ;; Arrange for deletion of the draft after successful sending.
2355 (make-local-variable 'gnus-message-sent-hook)
2356 (setq gnus-message-sent-hook
2360 (gnus-request-expire-articles
2361 (quote (, (list (cdr gnus-article-current))))
2362 (, gnus-newsgroup-name) t)))))
2363 ;; Insert the draft.
2364 (insert-buffer-substring gnus-article-buffer)
2365 ;; Insert the separator.
2366 (goto-char (point-min))
2367 (search-forward "\n\n")
2369 (insert mail-header-separator)
2370 ;; Remove the draft header.
2371 (gnus-inews-narrow-to-headers)
2372 (nnheader-remove-header "x-gnus-draft-type")
2374 ;; Configure windows.
2375 (let ((gnus-draft-buffer (current-buffer)))
2376 (gnus-configure-windows 'draft))
2377 ;; Put point where you left it.
2378 (goto-char (nth 3 type))))
2380 (defun gnus-configure-posting-styles ()
2381 "Configure posting styles according to `gnus-posting-styles'."
2382 (let ((styles gnus-posting-styles)
2383 style match variable attribute value value-value)
2384 ;; Go through all styles and look for matches.
2386 (setq style (pop styles)
2388 (when (cond ((stringp match)
2389 ;; Regexp string match on the group name.
2390 (string-match match gnus-newsgroup-name))
2392 (cond ((fboundp match)
2393 ;; Function to be called.
2396 ;; Variable to be checked.
2397 (symbol-value match))))
2399 ;; This is a form to be evaled.
2401 ;; We have a match, so we set the variables.
2403 (setq attribute (pop style)
2404 value (cdr attribute))
2405 ;; We find the variable that is to be modified.
2406 (if (and (not (stringp (car attribute)))
2407 (not (setq variable (cdr (assq (car attribute)
2408 gnus-posting-style-alist)))))
2409 (message "Couldn't find attribute %s" (car attribute))
2410 ;; We set the variable.
2412 (cond ((stringp value)
2415 (cond ((fboundp value)
2418 (symbol-value value))))
2423 ;; This is an ordinary variable.
2424 (make-local-variable variable)
2425 (set variable value-value))
2426 ;; This is a header to be added to the headers when
2429 (make-local-variable gnus-required-headers)
2430 (make-local-variable gnus-required-mail-headers)
2431 (push (cons (car attribute) value-value)
2432 gnus-required-headers)
2433 (push (cons (car attribute) value-value)
2434 gnus-required-mail-headers)))))))))
2436 ;;; Allow redefinition of functions.
2442 ;;; gnus-msg.el ends here