]> code.delx.au - gnu-emacs/blob - lisp/mail/emacsbug.el
epg: Adjust to GnuPG 2.1 key listing change
[gnu-emacs] / lisp / mail / emacsbug.el
1 ;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list
2
3 ;; Copyright (C) 1985, 1994, 1997-1998, 2000-2014 Free Software
4 ;; Foundation, Inc.
5
6 ;; Author: K. Shane Hartman
7 ;; Maintainer: emacs-devel@gnu.org
8 ;; Keywords: maint mail
9 ;; Package: emacs
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25
26 ;;; Commentary:
27
28 ;; `M-x report-emacs-bug' starts an email note to the Emacs maintainers
29 ;; describing a problem. You need to be able to send mail from Emacs
30 ;; to complete the process. Alternatively, compose the bug report in
31 ;; Emacs then paste it into your normal mail client.
32
33 ;;; Code:
34
35 (require 'sendmail)
36 (require 'message)
37
38 (defgroup emacsbug nil
39 "Sending Emacs bug reports."
40 :group 'maint
41 :group 'mail)
42
43 (define-obsolete-variable-alias 'report-emacs-bug-pretest-address
44 'report-emacs-bug-address "24.1")
45
46 (defcustom report-emacs-bug-address "bug-gnu-emacs@gnu.org"
47 "Address of mailing list for GNU Emacs bugs."
48 :group 'emacsbug
49 :type 'string)
50
51 (defcustom report-emacs-bug-no-confirmation nil
52 "If non-nil, suppress the confirmations asked for the sake of novice users."
53 :group 'emacsbug
54 :type 'boolean)
55
56 (defcustom report-emacs-bug-no-explanations nil
57 "If non-nil, suppress the explanations given for the sake of novice users."
58 :group 'emacsbug
59 :type 'boolean)
60
61 ;; User options end here.
62
63 (defvar report-emacs-bug-orig-text nil
64 "The automatically-created initial text of the bug report.")
65
66 (defvar report-emacs-bug-send-command nil
67 "Name of the command to send the bug report, as a string.")
68 (make-variable-buffer-local 'report-emacs-bug-send-command)
69
70 (defvar report-emacs-bug-send-hook nil
71 "Hook run before sending the bug report.")
72 (make-variable-buffer-local 'report-emacs-bug-send-hook)
73
74 (declare-function x-server-vendor "xfns.c" (&optional terminal))
75 (declare-function x-server-version "xfns.c" (&optional terminal))
76 (declare-function message-sort-headers "message" ())
77 (defvar message-strip-special-text-properties)
78
79 (defun report-emacs-bug-can-use-osx-open ()
80 "Return non-nil if the OS X \"open\" command is available for mailing."
81 (and (featurep 'ns)
82 (equal (executable-find "open") "/usr/bin/open")
83 (memq system-type '(darwin))))
84
85 ;; FIXME this duplicates much of the logic from browse-url-can-use-xdg-open.
86 (defun report-emacs-bug-can-use-xdg-email ()
87 "Return non-nil if the \"xdg-email\" command can be used.
88 xdg-email is a desktop utility that calls your preferred mail client.
89 This requires you to be running either Gnome, KDE, or Xfce4."
90 (and (getenv "DISPLAY")
91 (executable-find "xdg-email")
92 (or (getenv "GNOME_DESKTOP_SESSION_ID")
93 ;; GNOME_DESKTOP_SESSION_ID is deprecated, check on Dbus also.
94 (condition-case nil
95 (eq 0 (call-process
96 "dbus-send" nil nil nil
97 "--dest=org.gnome.SessionManager"
98 "--print-reply"
99 "/org/gnome/SessionManager"
100 "org.gnome.SessionManager.CanShutdown"))
101 (error nil))
102 (equal (getenv "KDE_FULL_SESSION") "true")
103 ;; FIXME? browse-url-can-use-xdg-open also accepts LXDE.
104 ;; Is that no good here, or just overlooked?
105 (condition-case nil
106 (eq 0 (call-process
107 "/bin/sh" nil nil nil
108 "-c"
109 ;; FIXME use string-match rather than grep.
110 "xprop -root _DT_SAVE_MODE|grep xfce4"))
111 (error nil)))))
112
113 (defun report-emacs-bug-insert-to-mailer ()
114 "Send the message to your preferred mail client.
115 This requires either the OS X \"open\" command, or the freedesktop
116 \"xdg-email\" command to be available."
117 (interactive)
118 (save-excursion
119 ;; FIXME? use mail-fetch-field?
120 (let* ((to (progn
121 (goto-char (point-min))
122 (forward-line)
123 (and (looking-at "^To: \\(.*\\)")
124 (match-string-no-properties 1))))
125 (subject (progn
126 (forward-line)
127 (and (looking-at "^Subject: \\(.*\\)")
128 (match-string-no-properties 1))))
129 (body (progn
130 (forward-line 2)
131 (if (> (point-max) (point))
132 (buffer-substring-no-properties (point) (point-max))))))
133 (if (and to subject body)
134 (if (report-emacs-bug-can-use-osx-open)
135 (start-process "/usr/bin/open" nil "open"
136 (concat "mailto:" to
137 "?subject=" (url-hexify-string subject)
138 "&body=" (url-hexify-string body)))
139 (start-process "xdg-email" nil "xdg-email"
140 "--subject" subject
141 "--body" body
142 (concat "mailto:" to)))
143 (error "Subject, To or body not found")))))
144
145 ;;;###autoload
146 (defun report-emacs-bug (topic &optional unused)
147 "Report a bug in GNU Emacs.
148 Prompts for bug subject. Leaves you in a mail buffer."
149 (declare (advertised-calling-convention (topic) "24.5"))
150 (interactive "sBug Subject: ")
151 ;; The syntax `version;' is preferred to `[version]' because the
152 ;; latter could be mistakenly stripped by mailing software.
153 (if (eq system-type 'ms-dos)
154 (setq topic (concat emacs-version "; " topic))
155 (when (string-match "^\\(\\([.0-9]+\\)*\\)\\.[0-9]+$" emacs-version)
156 (setq topic (concat (match-string 1 emacs-version) "; " topic))))
157 (let ((from-buffer (current-buffer))
158 (can-insert-mail (or (report-emacs-bug-can-use-xdg-email)
159 (report-emacs-bug-can-use-osx-open)))
160 user-point message-end-point)
161 (setq message-end-point
162 (with-current-buffer (messages-buffer)
163 (point-max-marker)))
164 (compose-mail report-emacs-bug-address topic)
165 ;; The rest of this does not execute if the user was asked to
166 ;; confirm and said no.
167 (when (eq major-mode 'message-mode)
168 ;; Message-mode sorts the headers before sending. We sort now so
169 ;; that report-emacs-bug-orig-text remains valid. (Bug#5178)
170 (message-sort-headers)
171 ;; Stop message-mode stealing the properties we will add.
172 (set (make-local-variable 'message-strip-special-text-properties) nil))
173 (rfc822-goto-eoh)
174 (forward-line 1)
175 ;; Move the mail signature to the proper place.
176 (let ((signature (buffer-substring (point) (point-max)))
177 (inhibit-read-only t))
178 (delete-region (point) (point-max))
179 (insert signature)
180 (backward-char (length signature)))
181 (unless report-emacs-bug-no-explanations
182 ;; Insert warnings for novice users.
183 (if (not (equal "bug-gnu-emacs@gnu.org" report-emacs-bug-address))
184 (insert (format "The report will be sent to %s.\n\n"
185 report-emacs-bug-address))
186 (insert "This bug report will be sent to the ")
187 (insert-text-button
188 "Bug-GNU-Emacs"
189 'face 'link
190 'help-echo (concat "mouse-2, RET: Follow this link")
191 'action (lambda (button)
192 (browse-url "http://lists.gnu.org/archive/html/bug-gnu-emacs/"))
193 'follow-link t)
194 (insert " mailing list\nand the GNU bug tracker at ")
195 (insert-text-button
196 "debbugs.gnu.org"
197 'face 'link
198 'help-echo (concat "mouse-2, RET: Follow this link")
199 'action (lambda (button)
200 (browse-url "http://debbugs.gnu.org/"))
201 'follow-link t)
202
203 (insert ". Please check that
204 the From: line contains a valid email address. After a delay of up
205 to one day, you should receive an acknowledgment at that address.
206
207 Please write in English if possible, as the Emacs maintainers
208 usually do not have translators for other languages.\n\n")))
209
210 (insert "Please describe exactly what actions triggered the bug, and\n"
211 "the precise symptoms of the bug. If you can, give a recipe\n"
212 "starting from `emacs -Q':\n\n")
213 (let ((txt (delete-and-extract-region
214 (save-excursion (rfc822-goto-eoh) (line-beginning-position 2))
215 (point))))
216 (insert (propertize "\n" 'display txt)))
217 (setq user-point (point))
218 (insert "\n\n")
219
220 (insert "If Emacs crashed, and you have the Emacs process in the gdb debugger,\n"
221 "please include the output from the following gdb commands:\n"
222 " `bt full' and `xbacktrace'.\n")
223
224 (let ((debug-file (expand-file-name "DEBUG" data-directory)))
225 (if (file-readable-p debug-file)
226 (insert "For information about debugging Emacs, please read the file\n"
227 debug-file ".\n")))
228 (let ((txt (delete-and-extract-region (1+ user-point) (point))))
229 (insert (propertize "\n" 'display txt)))
230
231 (insert "\n\nIn " (emacs-version) "\n")
232 (if (stringp emacs-repository-version)
233 (insert "Repository revision: " emacs-repository-version "\n"))
234 (if (fboundp 'x-server-vendor)
235 (condition-case nil
236 ;; This is used not only for X11 but also W32 and others.
237 (insert "Windowing system distributor `" (x-server-vendor)
238 "', version "
239 (mapconcat 'number-to-string (x-server-version) ".") "\n")
240 (error t)))
241 (let ((lsb (with-temp-buffer
242 (if (eq 0 (ignore-errors
243 (call-process "lsb_release" nil '(t nil)
244 nil "-d")))
245 (buffer-string)))))
246 (if (stringp lsb)
247 (insert "System " lsb "\n")))
248 (when (and system-configuration-options
249 (not (equal system-configuration-options "")))
250 (insert "Configured using:\n `configure "
251 system-configuration-options "'\n\n")
252 (fill-region (line-beginning-position -1) (point)))
253 (insert "Important settings:\n")
254 (mapc
255 (lambda (var)
256 (let ((val (getenv var)))
257 (if val (insert (format " value of $%s: %s\n" var val)))))
258 '("EMACSDATA" "EMACSDOC" "EMACSLOADPATH" "EMACSPATH"
259 "LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES"
260 "LC_MONETARY" "LC_NUMERIC" "LC_TIME" "LANG" "XMODIFIERS"))
261 (insert (format " locale-coding-system: %s\n" locale-coding-system))
262 ;; Only ~ 0.2% of people from a sample of 3200 changed this from
263 ;; the default, t.
264 (or (default-value 'enable-multibyte-characters)
265 (insert (format " default enable-multibyte-characters: %s\n"
266 (default-value 'enable-multibyte-characters))))
267 (insert "\n")
268 (insert (format "Major mode: %s\n"
269 (format-mode-line
270 (buffer-local-value 'mode-name from-buffer)
271 nil nil from-buffer)))
272 (insert "\n")
273 (insert "Minor modes in effect:\n")
274 (dolist (mode minor-mode-list)
275 (and (boundp mode) (buffer-local-value mode from-buffer)
276 (insert (format " %s: %s\n" mode
277 (buffer-local-value mode from-buffer)))))
278 (let ((message-buf (get-buffer "*Messages*")))
279 (if message-buf
280 (let (beg-pos
281 (end-pos message-end-point))
282 (with-current-buffer message-buf
283 (goto-char end-pos)
284 (forward-line -10)
285 (setq beg-pos (point)))
286 (insert "\nRecent messages:\n")
287 (insert-buffer-substring message-buf beg-pos end-pos))))
288 ;; After Recent messages, to avoid the messages produced by
289 ;; list-load-path-shadows.
290 (unless (looking-back "\n")
291 (insert "\n"))
292 (insert "\n")
293 (insert "Load-path shadows:\n")
294 (let* ((msg "Checking for load-path shadows...")
295 (result "done")
296 (shadows (progn (message "%s" msg)
297 (condition-case nil (list-load-path-shadows t)
298 (error
299 (setq result "error")
300 "Error during checking")))))
301 (message "%s%s" msg result)
302 (insert (if (zerop (length shadows))
303 "None found.\n"
304 shadows)))
305 (insert (format "\nFeatures:\n%s\n" features))
306 (fill-region (line-beginning-position 0) (point))
307
308 (insert (format "\nMemory information:\n"))
309 (pp (garbage-collect) (current-buffer))
310
311 ;; This is so the user has to type something in order to send easily.
312 (use-local-map (nconc (make-sparse-keymap) (current-local-map)))
313 (define-key (current-local-map) "\C-c\C-i" 'info-emacs-bug)
314 (if can-insert-mail
315 (define-key (current-local-map) "\C-c\M-i"
316 'report-emacs-bug-insert-to-mailer))
317 (setq report-emacs-bug-send-command (get mail-user-agent 'sendfunc)
318 report-emacs-bug-send-hook (get mail-user-agent 'hookvar))
319 (if report-emacs-bug-send-command
320 (setq report-emacs-bug-send-command
321 (symbol-name report-emacs-bug-send-command)))
322 (unless report-emacs-bug-no-explanations
323 (with-output-to-temp-buffer "*Bug Help*"
324 (princ "While in the mail buffer:\n\n")
325 (if report-emacs-bug-send-command
326 (princ (substitute-command-keys
327 (format " Type \\[%s] to send the bug report.\n"
328 report-emacs-bug-send-command))))
329 (princ (substitute-command-keys
330 " Type \\[kill-buffer] RET to cancel (don't send it).\n"))
331 (if can-insert-mail
332 (princ (substitute-command-keys
333 " Type \\[report-emacs-bug-insert-to-mailer] to copy text to your preferred mail program.\n")))
334 (terpri)
335 (princ (substitute-command-keys
336 " Type \\[info-emacs-bug] to visit in Info the Emacs Manual section
337 about when and how to write a bug report, and what
338 information you should include to help fix the bug.")))
339 (shrink-window-if-larger-than-buffer (get-buffer-window "*Bug Help*")))
340 ;; Make it less likely people will send empty messages.
341 (if report-emacs-bug-send-hook
342 (add-hook report-emacs-bug-send-hook 'report-emacs-bug-hook nil t))
343 (goto-char (point-max))
344 (skip-chars-backward " \t\n")
345 (make-local-variable 'report-emacs-bug-orig-text)
346 (setq report-emacs-bug-orig-text
347 (buffer-substring-no-properties (point-min) (point)))
348 (goto-char user-point)))
349
350 (define-obsolete-function-alias 'report-emacs-bug-info 'info-emacs-bug "24.3")
351
352 ;; It's the default mail mode, so it seems OK to use its features.
353 (autoload 'message-bogus-recipient-p "message")
354 (defvar message-send-mail-function)
355
356 (defun report-emacs-bug-hook ()
357 "Do some checking before sending a bug report."
358 (save-excursion
359 (goto-char (point-max))
360 (skip-chars-backward " \t\n")
361 (and (= (- (point) (point-min))
362 (length report-emacs-bug-orig-text))
363 (string-equal (buffer-substring-no-properties (point-min) (point))
364 report-emacs-bug-orig-text)
365 (error "No text entered in bug report"))
366 ;; Warning for novice users.
367 (unless (or report-emacs-bug-no-confirmation
368 (yes-or-no-p
369 "Send this bug report to the Emacs maintainers? "))
370 (goto-char (point-min))
371 (if (search-forward "To: ")
372 (delete-region (point) (line-end-position)))
373 (if report-emacs-bug-send-hook
374 (kill-local-variable report-emacs-bug-send-hook))
375 (with-output-to-temp-buffer "*Bug Help*"
376 (princ (substitute-command-keys
377 (format "\
378 You invoked the command M-x report-emacs-bug,
379 but you decided not to mail the bug report to the Emacs maintainers.
380
381 If you want to mail it to someone else instead,
382 please insert the proper e-mail address after \"To: \",
383 and send the mail again%s."
384 (if report-emacs-bug-send-command
385 (format " using \\[%s]"
386 report-emacs-bug-send-command)
387 "")))))
388 (error "M-x report-emacs-bug was canceled, please read *Bug Help* buffer"))
389 ;; Query the user for the SMTP method, so that we can skip
390 ;; questions about From header validity if the user is going to
391 ;; use mailclient, anyway.
392 (when (or (and (derived-mode-p 'message-mode)
393 (eq message-send-mail-function 'sendmail-query-once))
394 (and (not (derived-mode-p 'message-mode))
395 (eq send-mail-function 'sendmail-query-once)))
396 (sendmail-query-user-about-smtp)
397 (when (derived-mode-p 'message-mode)
398 (setq message-send-mail-function (message-default-send-mail-function))))
399 (or report-emacs-bug-no-confirmation
400 ;; mailclient.el does not need a valid From
401 (if (derived-mode-p 'message-mode)
402 (eq message-send-mail-function 'message-send-mail-with-mailclient)
403 (eq send-mail-function 'mailclient-send-it))
404 ;; Not narrowing to the headers, but that's OK.
405 (let ((from (mail-fetch-field "From")))
406 (and (or (not from)
407 (message-bogus-recipient-p from)
408 ;; This is the default user-mail-address. On today's
409 ;; systems, it seems more likely to be wrong than right,
410 ;; since most people don't run their own mail server.
411 (string-match (format "\\<%s@%s\\>"
412 (regexp-quote (user-login-name))
413 (regexp-quote (system-name)))
414 from))
415 (not (yes-or-no-p
416 (format "Is `%s' really your email address? " from)))
417 (error "Please edit the From address and try again"))))))
418
419
420 (provide 'emacsbug)
421
422 ;;; emacsbug.el ends here