Add "Package:" file headers to denote built-in packages.
[bpt/emacs.git] / lisp / mail / emacsbug.el
index 9fafab5..b3ec3fb 100644 (file)
@@ -1,11 +1,13 @@
 ;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list
 
 ;; Copyright (C) 1985, 1994, 1997, 1998, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009, 2010
+;;   Free Software Foundation, Inc.
 
 ;; Author: K. Shane Hartman
 ;; Maintainer: FSF
 ;; Keywords: maint mail
+;; Package: emacs
 
 ;; This file is part of GNU Emacs.
 
   :group 'maint
   :group 'mail)
 
+(define-obsolete-variable-alias 'report-emacs-bug-pretest-address
+  'report-emacs-bug-address "24.1")
+
 (defcustom report-emacs-bug-address "bug-gnu-emacs@gnu.org"
   "Address of mailing list for GNU Emacs bugs."
   :group 'emacsbug
   :type 'string)
 
-(defcustom report-emacs-bug-pretest-address "emacs-pretest-bug@gnu.org"
-  "Address of mailing list for GNU Emacs pretest bugs."
-  :group 'emacsbug
-  :type 'string)
-
 (defcustom report-emacs-bug-no-confirmation nil
   "If non-nil, suppress the confirmations asked for the sake of novice users."
   :group 'emacsbug
 
 (declare-function x-server-vendor "xfns.c" (&optional terminal))
 (declare-function x-server-version "xfns.c" (&optional terminal))
+(declare-function message-sort-headers "message" ())
+(defvar message-strip-special-text-properties)
+
+(defun report-emacs-bug-can-use-xdg-email ()
+  "Check if xdg-email can be used, i.e. we are on Gnome, KDE or xfce4."
+  (and (getenv "DISPLAY")
+       (executable-find "xdg-email")
+       (or (getenv "GNOME_DESKTOP_SESSION_ID")
+          ;; GNOME_DESKTOP_SESSION_ID is deprecated, check on Dbus also.
+          (condition-case nil
+              (eq 0 (call-process
+                     "dbus-send" nil nil nil
+                                 "--dest=org.gnome.SessionManager"
+                                 "--print-reply"
+                                 "/org/gnome/SessionManager"
+                                 "org.gnome.SessionManager.CanShutdown"))
+            (error nil))
+          (equal (getenv "KDE_FULL_SESSION") "true")
+          (condition-case nil
+              (eq 0 (call-process
+                     "/bin/sh" nil nil nil
+                     "-c"
+                     "xprop -root _DT_SAVE_MODE|grep xfce4"))
+            (error nil)))))
+
+(defun report-emacs-bug-insert-to-mailer ()
+  (interactive)
+  (save-excursion
+    (let* ((to (progn
+                (goto-char (point-min))
+                (forward-line)
+                (and (looking-at "^To: \\(.*\\)")
+                     (match-string-no-properties 1))))
+          (subject (progn
+                     (forward-line)
+                     (and (looking-at "^Subject: \\(.*\\)")
+                          (match-string-no-properties 1))))
+          (body (progn
+                  (forward-line 2)
+                  (if (> (point-max) (point))
+                      (buffer-substring-no-properties (point) (point-max))))))
+      (if (and to subject body)
+         (start-process "xdg-email" nil "xdg-email"
+                        "--subject" subject
+                        "--body" body
+                        (concat "mailto:" to))
+       (error "Subject, To or body not found")))))
+
 
 ;;;###autoload
 (defun report-emacs-bug (topic &optional recent-keys)
@@ -86,32 +134,26 @@ Prompts for bug subject.  Leaves you in a mail buffer."
       (setq topic (concat emacs-version "; " topic))
     (when (string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
       (setq topic (concat (match-string 1 emacs-version) "; " topic))))
-  ;; If there are four numbers in emacs-version (three for MS-DOS),
-  ;; this is a pretest version.
-  (let* ((pretest-p (string-match (if (eq system-type 'ms-dos)
-                                     "\\..*\\."
-                                   "\\..*\\..*\\.")
-                                 emacs-version))
-        (from-buffer (current-buffer))
-        (reporting-address (if pretest-p
-                               report-emacs-bug-pretest-address
-                             report-emacs-bug-address))
-        ;; Put these properties on semantically-void text.
-        ;; report-emacs-bug-hook deletes these regions before sending.
-        (prompt-properties '(field emacsbug-prompt
-                                   intangible but-helpful
-                                   rear-nonsticky t))
-        user-point message-end-point)
+  (let ((from-buffer (current-buffer))
+        ;; Put these properties on semantically-void text.
+        ;; report-emacs-bug-hook deletes these regions before sending.
+        (prompt-properties '(field emacsbug-prompt
+                                   intangible but-helpful
+                                   rear-nonsticky t))
+       (can-xdg-email (report-emacs-bug-can-use-xdg-email))
+        user-point message-end-point)
     (setq message-end-point
          (with-current-buffer (get-buffer-create "*Messages*")
            (point-max-marker)))
-    (compose-mail reporting-address topic)
+    (compose-mail report-emacs-bug-address topic)
     ;; The rest of this does not execute if the user was asked to
     ;; confirm and said no.
-    ;; Message-mode sorts the headers before sending.  We sort now so
-    ;; that report-emacs-bug-orig-text remains valid.  (Bug#5178)
-    (if (eq major-mode 'message-mode)
-        (message-sort-headers))
+    (when (eq major-mode 'message-mode)
+      ;; Message-mode sorts the headers before sending.  We sort now so
+      ;; that report-emacs-bug-orig-text remains valid.  (Bug#5178)
+      (message-sort-headers)
+      ;; Stop message-mode stealing the properties we will add.
+      (set (make-local-variable 'message-strip-special-text-properties) nil))
     (rfc822-goto-eoh)
     (forward-line 1)
     (let ((signature (buffer-substring (point) (point-max))))
@@ -120,7 +162,7 @@ Prompts for bug subject.  Leaves you in a mail buffer."
       (backward-char (length signature)))
     (unless report-emacs-bug-no-explanations
       ;; Insert warnings for novice users.
-      (when (string-match "@gnu\\.org$" reporting-address)
+      (when (string-match "@gnu\\.org$" report-emacs-bug-address)
        (insert "This bug report will be sent to the Free Software Foundation,\n")
        (let ((pos (point)))
          (insert "not to your local site managers!")
@@ -132,17 +174,12 @@ Prompts for bug subject.  Leaves you in a mail buffer."
       (insert " if possible, because the Emacs maintainers
 usually do not have translators to read other languages for them.\n\n")
       (insert (format "Your bug report will be posted to the %s mailing list"
-                     reporting-address))
-      ;; Nowadays all bug reports end up there.
-;;;      (if pretest-p (insert ".\n\n")
+                     report-emacs-bug-address))
        (insert ",\nand to the gnu.emacs.bug news group.\n\n"))
 
     (insert "Please describe exactly what actions triggered the bug\n"
            "and the precise symptoms of the bug.  If you can, give\n"
            "a recipe starting from `emacs -Q':\n\n")
-    ;; Stop message-mode stealing the properties we are about to add.
-    (if (boundp 'message-strip-special-text-properties)
-        (set (make-local-variable 'message-strip-special-text-properties) nil))
     (add-text-properties (save-excursion
                            (rfc822-goto-eoh)
                            (line-beginning-position 2))
@@ -237,6 +274,9 @@ usually do not have translators to read other languages for them.\n\n")
     ;; This is so the user has to type something in order to send easily.
     (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
     (define-key (current-local-map) "\C-c\C-i" 'report-emacs-bug-info)
+    (if can-xdg-email
+       (define-key (current-local-map) "\C-cm"
+         'report-emacs-bug-insert-to-mailer))
     ;; Could test major-mode instead.
     (cond ((memq mail-user-agent '(message-user-agent gnus-user-agent))
            (setq report-emacs-bug-send-command "message-send-and-exit"
@@ -256,6 +296,9 @@ usually do not have translators to read other languages for them.\n\n")
                             report-emacs-bug-send-command))))
        (princ (substitute-command-keys
                "  Type \\[kill-buffer] RET to cancel (don't send it).\n"))
+       (if can-xdg-email
+           (princ (substitute-command-keys
+                   "  Type \\[report-emacs-bug-insert-to-mailer] to insert text to you preferred mail program.\n")))
        (terpri)
        (princ (substitute-command-keys
                "  Type \\[report-emacs-bug-info] to visit in Info the Emacs Manual section
@@ -282,14 +325,11 @@ usually do not have translators to read other languages for them.\n\n")
   (save-excursion
     (goto-char (point-max))
     (skip-chars-backward " \t\n")
-    ;; FIXME This check is defeated by message.el, which sorts the
-    ;; headers (!) before running message-send-hook.
     (and (= (- (point) (point-min))
             (length report-emacs-bug-orig-text))
          (string-equal (buffer-substring-no-properties (point-min) (point))
                        report-emacs-bug-orig-text)
          (error "No text entered in bug report"))
-
     ;; Check the buffer contents and reject non-English letters.
     ;; FIXME message-mode probably does this anyway.
     (goto-char (point-min))