1 ;;; debbugs.el --- SOAP library to access debbugs servers
3 ;; Copyright (C) 2011-2016 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
6 ;; Keywords: comm, hypermedia
9 ;; Package-Requires: ((async "1.6"))
11 ;; This file is not part of GNU Emacs.
13 ;; This program 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.
18 ;; This program 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.
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/>.
28 ;; This package provides basic functions to access a Debbugs SOAP
29 ;; server (see <http://wiki.debian.org/DebbugsSoapInterface>).
31 ;; The function "get_versions" is not implemented (yet). "search_est"
32 ;; is an extension on <http://debbugs.gnu.org>.
36 ;(setq soap-debug t message-log-max t)
37 (require 'soap-client)
38 (eval-when-compile (require 'cl))
40 (declare-function soap-invoke-async "soap-client")
41 (declare-function async-start "async")
42 (declare-function async-get "async")
48 (defcustom debbugs-servers
50 :wsdl "http://debbugs.gnu.org/cgi/soap.cgi?WSDL"
51 :bugreport-url "http://debbugs.gnu.org/cgi/bugreport.cgi")
53 :wsdl "http://bugs.debian.org/cgi-bin/soap.cgi?WSDL"
54 :bugreport-url "http://bugs.debian.org/cgi-bin/bugreport.cgi"))
55 "*List of Debbugs server specifiers.
56 Each entry is a list that contains a string identifying the port
57 name and the server parameters in keyword-value form. Allowed
60 `:wsdl' -- Location of WSDL. The value is a string with URL that
61 should return the WSDL specification of Debbugs/SOAP service.
63 `:bugreport-url' -- URL of the server script that returns mboxes
66 The list initially contains two predefined and configured Debbugs
67 servers: \"gnu.org\" and \"debian.org\"."
69 :link '(custom-manual "(debbugs)Debbugs server specifiers")
74 (string :tag "Port name")
75 (checklist :tag "Options" :greedy t
77 (const :format "" :value :wsdl)
80 (const :format "" :value :bugreport-url)
81 (string :tag "Bugreport URL")))))))
83 (defcustom debbugs-port "gnu.org"
84 "The port instance to be applied from `debbugs-wsdl'.
85 This corresponds to the Debbugs server to be accessed, either
86 \"gnu.org\", or \"debian.org\", or user defined port name."
87 ;; Maybe we should create an own group?
89 :type '(choice :tag "Debbugs server" (const "gnu.org") (const "debian.org")
90 (string :tag "user defined port name")))
92 ;; It would be nice if we could retrieve it from the debbugs server.
94 (defconst debbugs-wsdl
99 (file-name-directory load-file-name)
101 "The WSDL object to be used describing the SOAP interface.")
103 ;; Please do not increase this value, otherwise we would run into
104 ;; performance problems on the server. Maybe we need to change this a
105 ;; server specific value.
106 (defconst debbugs-max-hits-per-request 500
107 "The max number of bugs or results per soap invocation.")
109 (defvar debbugs-soap-invoke-async-object nil
110 "The object manipulated by `debbugs-soap-invoke-async'.")
112 (defun debbugs-soap-invoke-async (operation-name &rest parameters)
113 "Invoke the SOAP connection asynchronously.
114 If possible, it uses `soap-invoke-async' from soapclient 3.0.
115 Otherwise, `async-start' from the async package is used."
116 (if (fboundp 'soap-invoke-async)
117 ;; This is soap-client 3.0.
120 (lambda (response &rest args)
121 (setq debbugs-soap-invoke-async-object
122 (append debbugs-soap-invoke-async-object (car response))))
124 debbugs-wsdl debbugs-port operation-name parameters)
125 ;; Fallback with async.
128 (load ,(locate-library "soap-client"))
134 (file-name-directory (locate-library "debbugs"))))
135 ,debbugs-port ,operation-name ',parameters)))))
137 (defun debbugs-get-bugs (&rest query)
138 "Return a list of bug numbers which match QUERY.
140 QUERY is a sequence of keyword-value pairs where the values are
141 strings, i.e. :KEYWORD \"VALUE\" [:KEYWORD \"VALUE\"]*
143 The keyword-value pair is a subquery. The keywords are allowed to
144 have multiple occurrence within the query at any place. The
145 subqueries with the same keyword form the logical subquery, which
146 returns the union of bugs of every subquery it contains.
148 The result of the QUERY is an intersection of results of all
153 :package -- The value is the name of the package a bug belongs
154 to, like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\".
156 :src -- This is used to retrieve bugs that belong to source
159 :severity -- This is the severity of the bug. The exact set of
160 allowed values depends on the Debbugs port. Examples are
161 \"normal\", \"minor\", \"wishlist\" etc.
163 :tag -- An arbitrary string the bug is annotated with.
164 Usually, this is used to mark the status of the bug, like
165 \"fixed\", \"moreinfo\", \"notabug\", \"patch\",
166 \"unreproducible\" or \"wontfix\". The exact set of tags
167 depends on the Debbugs port.
169 :owner -- This is used to identify bugs by the owner's email
170 address. The special email address \"me\" is used as pattern,
171 replaced with `user-mail-address'.
173 :submitter -- With this keyword it is possible to filter bugs
174 by the submitter's email address. The special email address
175 \"me\" is used as pattern, replaced with `user-mail-address'.
177 :maint -- This is used to find bugs of the packages which are
178 maintained by the person with the given email address. The
179 special email address \"me\" is used as pattern, replaced with
182 :correspondent -- This allows to find bug reports where the
183 person with the given email address has participated. The
184 special email address \"me\" is used as pattern, replaced with
187 :affects -- With this keyword it is possible to find bugs which
188 affect the package with the given name. The bugs are chosen by
189 the value of field `affects' in bug's status. The returned bugs
190 do not necessary belong to this package.
192 :status -- Status of bug. Valid values are \"done\",
193 \"forwarded\" and \"open\".
195 :archive -- A keyword to filter for bugs which are already
196 archived, or not. Valid values are \"0\" (not archived),
197 \"1\" (archived) or \"both\". If this keyword is not given in
198 the query, `:archive \"0\"' is assumed by default.
200 Example. Get all opened and forwarded release critical bugs for
201 the packages which are maintained by \"me\" and which have a
204 \(debbugs-get-bugs :maint \"me\" :tag \"patch\"
205 :severity \"critical\"
208 :status \"forwarded\"
209 :severity \"serious\")"
211 (let (vec kw key val)
213 (while (and (consp query) (<= 2 (length query)))
216 (unless (and (keywordp kw) (stringp val))
217 (error "Wrong query: %s %s" kw val))
218 (setq key (substring (symbol-name kw) 1))
220 ((:package :severity :tag :src :affects)
221 ;; Value shall be one word.
222 (if (string-match "\\`\\S-+\\'" val)
223 (setq vec (vconcat vec (list key val)))
224 (error "Wrong %s: %s" key val)))
225 ((:owner :submitter :maint :correspondent)
226 ;; Value is an email address.
227 (if (string-match "\\`\\S-+\\'" val)
229 (when (string-equal "me" val)
230 (setq val user-mail-address))
231 (when (string-match "<\\(.+\\)>" val)
232 (setq val (match-string 1 val)))
233 (setq vec (vconcat vec (list key val))))
234 (error "Wrong %s: %s" key val)))
236 ;; Possible values: "done", "forwarded" and "open"
237 (if (string-match "\\`\\(done\\|forwarded\\|open\\)\\'" val)
238 (setq vec (vconcat vec (list key val)))
239 (error "Wrong %s: %s" key val)))
241 ;; Value is `0' or `1' or `both'.
242 (if (string-match "\\`\\(0\\|1\\|both\\)\\'" val)
243 (setq vec (vconcat vec (list key val)))
244 (error "Wrong %s: %s" key val)))
245 (t (error "Unknown key: %s" kw))))
248 (error "Unknown key: %s" (car query)))
249 (sort (car (soap-invoke debbugs-wsdl debbugs-port "get_bugs" vec)) '<)))
251 (defun debbugs-newest-bugs (amount)
252 "Return the list of bug numbers, according to AMOUNT (a number) latest bugs."
253 (sort (car (soap-invoke debbugs-wsdl debbugs-port "newest_bugs" amount)) '<))
255 (defun debbugs-get-status (&rest bug-numbers)
256 "Return a list of status entries for the bugs identified by BUG-NUMBERS.
258 Every returned entry is an association list with the following attributes:
260 `bug_num': The bug number.
262 `package': A list of package names the bug belongs to.
264 `severity': The severity of the bug report. This can be
265 \"critical\", \"grave\", \"serious\", \"important\",
266 \"normal\", \"minor\" or \"wishlist\".
268 `tags': The status of the bug report, a list of strings. This
269 can be \"fixed\", \"notabug\", \"wontfix\", \"unreproducible\",
270 \"moreinfo\" or \"patch\".
272 `pending': The string \"pending\", \"forwarded\" or \"done\".
274 `subject': Subject/Title of the bugreport.
276 `originator': Submitter of the bugreport.
278 `mergedwith': A list of bug numbers this bug was merged with.
279 If it is a single bug, then this attribute contains just a
282 `source': Source package name of the bug report.
284 `date': Date of bug creation.
286 `log_modified', `last_modified': Date of last update.
288 `found_date', `fixed_date': Date of bug report / bug fix
291 `done': The email address of the worker who has closed the bug (if done).
293 `archived': `t' if the bug is archived, `nil' otherwise.
295 `unarchived': The date the bug has been unarchived, if ever.
297 `found_versions', `fixed_versions': List of version strings.
299 `forwarded': A URL or an email address.
301 `blocks': A list of bug numbers this bug blocks.
303 `blockedby': A list of bug numbers this bug is blocked by.
305 `msgid': The message id of the initial bug report.
307 `owner': Who is responsible for fixing.
309 `location': Always the string \"db-h\" or \"archive\".
311 `affects': A list of package names.
313 `summary': Arbitrary text.
317 \(debbugs-get-status 10)
319 => ;; Attributes with empty values are not shown
321 \(source . \"unknown\")
322 \(date . 1203606305.0)
323 \(msgid . \"<87zltuz7eh.fsf@freemail.hu>\")
324 \(severity . \"wishlist\")
325 \(owner . \"Magnus Henoch <mange@freemail.hu>\")
326 \(log_modified . 1261079402.0)
327 \(location . \"db-h\")
328 \(subject . \"url-gw should support HTTP CONNECT proxies\")
329 \(originator . \"Magnus Henoch <mange@freemail.hu>\")
330 \(last_modified . 1271200046.0)
331 \(pending . \"pending\")
332 \(package \"emacs\")))"
334 (if (<= (length bug-numbers) debbugs-max-hits-per-request)
336 (setq debbugs-soap-invoke-async-object
338 debbugs-wsdl debbugs-port "get_status"
339 (apply 'vector bug-numbers))))
341 ;; Retrieve bugs asynchronously.
342 (let ((bug-ids bug-numbers)
344 (setq debbugs-soap-invoke-async-object nil)
350 (debbugs-soap-invoke-async
355 bug-ids (- (length bug-ids)
356 debbugs-max-hits-per-request))))))
359 (last bug-ids (- (length bug-ids)
360 debbugs-max-hits-per-request))))
362 (dolist (res results)
364 ;; This is soap-client 3.0.
365 (while (buffer-live-p res)
366 (accept-process-output (get-buffer-process res) 0.1))
367 ;; Fallback with async.
368 (dolist (status (async-get res))
369 (setq debbugs-soap-invoke-async-object
370 (append debbugs-soap-invoke-async-object status)))))))
375 ;; "archived" is the number 1 or 0.
376 (setq y (assoc 'archived (cdr (assoc 'value x))))
377 (setcdr y (= (cdr y) 1))
378 ;; "found_versions" and "fixed_versions" are lists,
379 ;; containing strings or numbers.
380 (dolist (attribute '(found_versions fixed_versions))
381 (setq y (assoc attribute (cdr (assoc 'value x))))
383 (lambda (z) (if (numberp z) (number-to-string z) z))
385 ;; "mergedwith", "blocks" and "blockedby are strings,
386 ;; containing blank separated bug numbers.
387 (dolist (attribute '(mergedwith blocks blockedby))
388 (setq y (assoc attribute (cdr (assoc 'value x))))
389 (when (stringp (cdr y))
391 'string-to-number (split-string (cdr y) " " t)))))
392 ;; "package" is a string, containing comma separated
393 ;; package names. "keywords" and "tags" are strings,
394 ;; containing blank separated package names.
395 (dolist (attribute '(package keywords tags))
396 (setq y (assoc attribute (cdr (assoc 'value x))))
397 (when (stringp (cdr y))
398 (setcdr y (split-string (cdr y) ",\\| " t))))
399 (cdr (assoc 'value x))))
400 debbugs-soap-invoke-async-object)))
402 (defun debbugs-get-usertag (&rest query)
403 "Return a list of bug numbers which match QUERY.
405 QUERY is a sequence of keyword-value pairs where the values are
406 strings, i.e. :KEYWORD \"VALUE\" [:KEYWORD \"VALUE\"]*
410 :user -- The value is the name of the package a bug belongs to,
411 like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\". It can
412 also be an email address of a user who has applied a user tag.
413 The special email address \"me\" is used as pattern, replaced
414 with `user-mail-address'. There must be at least one such
415 entry; it is recommended to have exactly one.
417 :tag -- A string applied as user tag. Often, it is a
418 subproduct identification, like \"cedet\" or \"tramp\" for the
421 If there is no :tag entry, no bug numbers will be returned but a list of
422 existing user tags for :user.
426 \(debbugs-get-usertag :user \"emacs\")
428 => (\"www\" \"solaris\" \"ls-lisp\" \"cygwin\")
430 \(debbugs-get-usertag :user \"emacs\" :tag \"www\" :tag \"cygwin\")
434 (let (user tags kw key val object result)
436 (while (and (consp query) (<= 2 (length query)))
439 (unless (and (keywordp kw) (stringp val))
440 (error "Wrong query: %s %s" kw val))
441 (setq key (substring (symbol-name kw) 1))
444 ;; Value shall be one word. Extract email address, if existing.
445 (if (string-match "\\`\\S-+\\'" val)
447 (when (string-equal "me" val)
448 (setq val user-mail-address))
449 (when (string-match "<\\(.+\\)>" val)
450 (setq val (match-string 1 val)))
451 (pushnew val user :test #'equal))
452 (error "Wrong %s: %s" key val)))
454 ;; Value shall be one word.
455 (if (string-match "\\`\\S-+\\'" val)
456 (pushnew val tags :test #'equal)
457 (error "Wrong %s: %s" key val)))
458 (t (error "Unknown key: %s" kw))))
461 (error "Unknown key: %s" (car query)))
462 (unless (= (length user) 1)
463 (error "There must be exactly one :user entry"))
467 (car (soap-invoke debbugs-wsdl debbugs-port "get_usertag" (car user))))
470 ;; Return the list of existing tags.
471 (mapcar (lambda (x) (symbol-name (car x))) object)
473 ;; Return bug numbers.
474 (dolist (elt object result)
475 (when (member (symbol-name (car elt)) tags)
476 (setq result (append (cdr elt) result)))))))
478 (defun debbugs-get-bug-log (bug-number)
479 "Return a list of messages related to BUG-NUMBER.
481 Every message is an association list with the following attributes:
483 `msg_num': The number of the message inside the bug log. The
484 numbers are ascending, newer messages have a higher number.
486 `header': The message header lines, as arrived at the bug tracker.
488 `body': The message body.
490 `attachments' A list of possible attachments, or `nil'. Not
491 implemented yet server side."
492 (car (soap-invoke debbugs-wsdl debbugs-port "get_bug_log" bug-number)))
494 (defun debbugs-search-est (&rest query)
495 "Return the result of a full text search according to QUERY.
497 QUERY is a sequence of lists of keyword-value pairs where the
498 values are strings or numbers, i.e. :KEYWORD \"VALUE\" [:KEYWORD
501 Every sublist of the QUERY forms a hyperestraier condition. A
502 detailed description of hyperestraier conditions can be found at
503 URL `http://fallabs.com/hyperestraier/uguide-en.html#searchcond'.
505 The following conditions are possible:
507 \[:phrase SEARCH-PHRASE :skip NUMBER :max NUMBER\]
509 The string SEARCH-PHRASE forms the search on the database. It
510 contains words to be searched for, combined by operators like
511 AND, ANDNOT and OR. If there is no operator between the words,
512 AND is used by default. The phrase keyword and value can also
513 be omitted, this is useful in combination with other conditions.
515 :skip and :max are optional. They specify, how many hits are
516 skipped, and how many maximal hits are returned. This can be
517 used for paged results. Per default, :skip is 0 and :max is 10.
519 There must be exactly one such condition.
521 \[ATTRIBUTE VALUE+ :operation OPERATION :order ORDER\]
523 ATTRIBUTE is one of the following keywords:
525 :status -- Status of bug. Valid values are \"done\",
526 \"forwarded\" and \"open\".
528 :subject, :@title -- The subject of a message or the title of
531 :date, :@cdate -- The submission or modification dates of a
534 :submitter, :@author -- The email address of the submitter of a
535 bug or the author of a message belonging to this bug, a string.
536 The special email address \"me\" is used as pattern, replaced
537 with `user-mail-address'.
539 :package -- The value is the name of the package a bug belongs
540 to, like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\".
542 :tags -- An arbitrary string the bug is annotated with.
544 :severity -- This is the severity of the bug. The exact set of
545 allowed values depends on the Debbugs port. Examples are
546 \"normal\", \"minor\", \"wishlist\" etc.
548 :operator defines the comparison operator to be applied to
549 ATTRIBUTE. For string attributes this could be \"STREQ\" \(is
550 equal to the string), \"STRNE\" \(is not equal to the string),
551 \"STRINC\" \(includes the string), \"STRBW\" \(begins with the
552 string), \"STREW\" \(ends with the string), \"STRAND\"
553 \(includes all tokens in the string), \"STROR\" \(includes at
554 least one token in the string), \"STROREQ\" \(is equal to at
555 least one token in the string) or \"STRRX\" \(matches regular
556 expressions of the string). For operators with tokens, several
557 values for ATTRIBUTE shall be used.
559 Numbers can be compared by the operators \"NUMEQ\" \(is equal
560 to the number), \"NUMNE\" \(is not equal to the number),
561 \"NUMGT\" \(is greater than the number), \"NUMGE\" \(is greater
562 than or equal to the number), \"NUMLT\" \(is less than the
563 number), \"NUMLE\" \(is less than or equal to the number) or
564 \"NUMBT\" \(is between the two numbers). In the last case,
565 there must be two values for ATTRIBUTE.
567 If an operator is leaded by \"!\", the meaning is inverted. If
568 a string operator is leaded by \"I\", the case of the value is
571 The optional :order can be specified only in one condition. It
572 means, that ATTRIBUTE is used for sorting the results. The
573 following order operators exist: \"STRA\" \(ascending by
574 string), \"STRD\" \(descending by string), \"NUMA\" \(ascending
575 by number) or \"NUMD\" \(descending by number).
577 A special case is an :order, where there is no corresponding
578 attribute value and no operator. In this case, ATTRIBUTE is
579 not used for the search.
581 The result of the QUERY is a list of association lists with the
582 same attributes as in the conditions. Additional attributes are
584 `id': The bug number.
586 `msg_num': The number of the message inside the bug log.
588 `snippet': The surrounding text found by the search. For the
589 syntax of the snippet, consult the hyperestraier user guide.
594 '\(:phrase \"armstrong AND debbugs\" :skip 10 :max 2)
595 '\(:severity \"normal\" :operator \"STRINC\")
596 '\(:date :order \"NUMA\"))
598 => \(\(\(msg_num . 21)
600 \(@author . \"Glenn Morris <rgm@gnu.org>\")
601 \(@title . \"Re: bug#1567: Mailing an archived bug\")
603 \(severity . \"normal\")
604 \(@cdate . \"Wed, 17 Dec 2008 14:34:50 -0500\")
606 \(subject . \"Mailing an archived bug\")
607 \(package . \"debbugs.gnu.org\"))
610 ;; Show all messages from me between 2011-08-01 and 2011-08-31.
613 '\(:@author \"me\" :operator \"ISTRINC\")
615 ,\(floor \(float-time \(encode-time 0 0 0 1 8 2011)))
616 ,\(floor \(float-time \(encode-time 0 0 0 31 8 2011)))
617 :operator \"NUMBT\"))"
620 ;; Compile search arguments.
623 phrase-cond attr-cond)
625 ;; Phrase is mandatory, even if empty.
626 (when (and (or (member :skip elt) (member :max elt))
627 (not (member :phrase elt)))
628 (setq vec (vector "phrase" "")))
633 (unless (keywordp kw)
634 (error "Wrong keyword: %s" kw))
635 (setq key (substring (symbol-name kw) 1))
639 ;; It shouldn't happen in an attribute condition.
641 (error "Wrong keyword: %s" kw))
642 (setq phrase-cond t val (pop elt))
643 ;; Value is a string.
645 (setq vec (vconcat vec (list key val)))
646 (error "Wrong %s: %s" key val)))
649 ;; It shouldn't happen in an attribute condition.
651 (error "Wrong keyword: %s" kw))
652 (setq phrase-cond t val (pop elt))
653 ;; Value is a number.
655 (setq vec (vconcat vec (list key (number-to-string val))))
656 (error "Wrong %s: %s" key val)))
658 ;; Attribute condition.
659 ((:submitter :@author)
660 ;; It shouldn't happen in a phrase condition.
662 (error "Wrong keyword: %s" kw))
663 (if (not (stringp (car elt)))
664 (setq vec (vconcat vec (list key "")))
665 ;; Value is an email address.
666 (while (and (stringp (car elt))
667 (string-match "\\`\\S-+\\'" (car elt)))
668 (when (string-equal "me" (car elt))
669 (setcar elt user-mail-address))
670 (when (string-match "<\\(.+\\)>" (car elt))
671 (setcar elt (match-string 1 (car elt))))
673 (unless (member x val)
674 (setq val (append val (list x))))))
676 (vconcat vec (list key (mapconcat 'identity val " "))))))
679 ;; It shouldn't happen in a phrase condition.
681 (error "Wrong keyword: %s" kw))
683 (if (not (stringp (car elt)))
684 (setq vec (vconcat vec (list key "")))
685 ;; Possible values: "done", "forwarded" and "open"
686 (while (and (stringp (car elt))
688 "\\`\\(done\\|forwarded\\|open\\)\\'" (car elt)))
690 (unless (member x val)
691 (setq val (append val (list x))))))
693 (vconcat vec (list key (mapconcat 'identity val " "))))))
695 ((:subject :package :tags :severity :@title)
696 ;; It shouldn't happen in a phrase condition.
698 (error "Wrong keyword: %s" kw))
700 (if (not (stringp (car elt)))
701 (setq vec (vconcat vec (list key "")))
703 (while (stringp (car elt))
705 (unless (member x val)
706 (setq val (append val (list x))))))
708 (vconcat vec (list key (mapconcat 'identity val " "))))))
711 ;; It shouldn't happen in a phrase condition.
713 (error "Wrong keyword: %s" kw))
715 (if (not (numberp (car elt)))
716 (setq vec (vconcat vec (list key "")))
718 (while (numberp (car elt))
720 (unless (member x val)
721 (setq val (append val (list x))))))
724 vec (list key (mapconcat 'number-to-string val " "))))))
727 ;; It shouldn't happen in a phrase condition.
729 (error "Wrong keyword: %s" kw))
730 (setq attr-cond t val (pop elt))
731 ;; Value is a number.
733 (setq vec (vconcat vec (list key val)))
734 (error "Wrong %s: %s" key val)))
736 (t (error "Unknown key: %s" kw))))
738 (setq args (vconcat args (list vec)))))
741 (car (soap-invoke debbugs-wsdl debbugs-port "search_est" args)))
742 ;; The result contains lists (key value). We transform it into
743 ;; cons cells (key . value).
744 (dolist (elt1 result result)
746 (setcdr elt2 (cadr elt2))))))
748 (defun debbugs-get-attribute (bug-or-message attribute)
749 "Return the value of key ATTRIBUTE.
751 BUG-OR-MESSAGE must be list element returned by either
752 `debbugs-get-status' or `debbugs-get-bug-log'.
754 Example: Return the originator of last submitted bug.
756 \(debbugs-get-attribute
757 \(car \(apply 'debbugs-get-status \(debbugs-newest-bugs 1))) 'originator)"
758 (cdr (assoc attribute bug-or-message)))
760 (defun debbugs-get-message-numbers (messages)
761 "Return the message numbers of MESSAGES.
762 MESSAGES must be the result of a `debbugs-get-bug-log' call."
763 (mapcar (lambda (x) (debbugs-get-attribute x 'msg_num)) messages))
765 (defun debbugs-get-message (messages message-number)
766 "Return the message MESSAGE-NUMBER of MESSAGES.
767 MESSAGES must be the result of a `debbugs-get-bug-log' call.
769 The returned message is a list of strings. The first element are
770 the header lines of the message, the second element is the body
771 of the message. Further elements of the list, if any, are
772 attachments of the message.
774 If there is no message with MESSAGE-NUMBER, the function returns `nil'.
776 Example: Return the first message of last submitted bug.
778 \(let \(\(messages \(apply 'debbugs-get-bug-log \(debbugs-newest-bugs 1))))
779 \(debbugs-get-message messages
780 \(car \(debbugs-get-message-numbers messages))))"
782 (/= (debbugs-get-attribute (car messages) 'msg_num)
784 (setq messages (cdr messages)))
786 (append (list (debbugs-get-attribute (car messages) 'header)
787 (debbugs-get-attribute (car messages) 'body))
788 (debbugs-get-attribute (car messages) 'attachments))))
790 (defun debbugs-get-mbox (bug-number mbox-type &optional filename)
791 "Download mbox with messages of bug BUG-NUMBER from Debbugs server.
792 BUG-NUMBER is a number of bug. It must be of integer type.
794 MBOX-TYPE specifies a type of mbox and can be one of the
797 `mboxfolder': Download mbox folder.
799 `mboxmaint': Download maintainer's mbox.
801 `mboxstat', `mboxstatus': Download status mbox. The use of
802 either symbol depends on actual Debbugs server configuration.
803 For gnu.org, use the former; for debian.org - the latter.
805 FILENAME, if non-`nil', is the name of file to store mbox. If
806 FILENAME is `nil', the downloaded mbox is inserted into the
808 (let (url (mt "") bn)
809 (unless (setq url (plist-get
810 (cdr (assoc debbugs-port debbugs-servers))
812 (error "URL of bugreport script for port %s is not specified"
814 (setq bn (format "bug=%s;" (number-to-string bug-number)))
815 (unless (eq mbox-type 'mboxfolder)
816 (if (memq mbox-type '(mboxmaint mboxstat mboxstatus))
817 (setq mt (concat (symbol-name mbox-type) "=yes;"))
818 (error "Unknown mbox type: %s" mbox-type)))
819 (setq url (concat url (format "?%s%smbox=yes" bn mt)))
821 (url-copy-file url filename t)
822 (url-insert-file-contents url))))
828 ;; * SOAP interface extensions (wishlist).
829 ;; - Server-side sorting.
830 ;; - Regexp and/or wildcards search.
831 ;; - Returning message attachments.
833 ;;; debbugs.el ends here