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-cache-data
110 (make-hash-table :test 'equal :size debbugs-max-hits-per-request)
111 "Hash table of retrieved bugs.")
113 (defcustom debbugs-cache-expiry (* 60 60)
114 "How many seconds debbugs query results are cached.
115 `t' or 0 disables caching, `nil' disables expiring."
117 :type '(choice (const :tag "Always" t)
118 (const :tag "Never" nil)
119 (integer :tag "Seconds")))
121 (defvar debbugs-soap-invoke-async-object nil
122 "The object manipulated by `debbugs-soap-invoke-async'.")
124 (defun debbugs-soap-invoke-async (operation-name &rest parameters)
125 "Invoke the SOAP connection asynchronously.
126 If possible, it uses `soap-invoke-async' from soapclient 3.0.
127 Otherwise, `async-start' from the async package is used."
128 (if (fboundp 'soap-invoke-async)
129 ;; This is soap-client 3.0.
132 (lambda (response &rest args)
133 (setq debbugs-soap-invoke-async-object
134 (append debbugs-soap-invoke-async-object (car response))))
136 debbugs-wsdl debbugs-port operation-name parameters)
137 ;; Fallback with async.
140 (load ,(locate-library "soap-client"))
146 (file-name-directory (locate-library "debbugs"))))
147 ,debbugs-port ,operation-name ',parameters)))))
149 (defun debbugs-get-bugs (&rest query)
150 "Return a list of bug numbers which match QUERY.
152 QUERY is a sequence of keyword-value pairs where the values are
153 strings, i.e. :KEYWORD \"VALUE\" [:KEYWORD \"VALUE\"]*
155 The keyword-value pair is a subquery. The keywords are allowed to
156 have multiple occurrence within the query at any place. The
157 subqueries with the same keyword form the logical subquery, which
158 returns the union of bugs of every subquery it contains.
160 The result of the QUERY is an intersection of results of all
165 :package -- The value is the name of the package a bug belongs
166 to, like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\".
168 :src -- This is used to retrieve bugs that belong to source
171 :severity -- This is the severity of the bug. The exact set of
172 allowed values depends on the Debbugs port. Examples are
173 \"normal\", \"minor\", \"wishlist\" etc.
175 :tag -- An arbitrary string the bug is annotated with.
176 Usually, this is used to mark the status of the bug, like
177 \"fixed\", \"moreinfo\", \"notabug\", \"patch\",
178 \"unreproducible\" or \"wontfix\". The exact set of tags
179 depends on the Debbugs port.
181 :owner -- This is used to identify bugs by the owner's email
182 address. The special email address \"me\" is used as pattern,
183 replaced with `user-mail-address'.
185 :submitter -- With this keyword it is possible to filter bugs
186 by the submitter's email address. The special email address
187 \"me\" is used as pattern, replaced with `user-mail-address'.
189 :maint -- This is used to find bugs of the packages which are
190 maintained by the person with the given email address. The
191 special email address \"me\" is used as pattern, replaced with
194 :correspondent -- This allows to find bug reports where the
195 person with the given email address has participated. The
196 special email address \"me\" is used as pattern, replaced with
199 :affects -- With this keyword it is possible to find bugs which
200 affect the package with the given name. The bugs are chosen by
201 the value of field `affects' in bug's status. The returned bugs
202 do not necessary belong to this package.
204 :status -- Status of bug. Valid values are \"done\",
205 \"forwarded\" and \"open\".
207 :archive -- A keyword to filter for bugs which are already
208 archived, or not. Valid values are \"0\" (not archived),
209 \"1\" (archived) or \"both\". If this keyword is not given in
210 the query, `:archive \"0\"' is assumed by default.
212 Example. Get all opened and forwarded release critical bugs for
213 the packages which are maintained by \"me\" and which have a
216 \(debbugs-get-bugs :maint \"me\" :tag \"patch\"
217 :severity \"critical\"
220 :status \"forwarded\"
221 :severity \"serious\")"
223 (let (vec kw key val)
225 (while (and (consp query) (<= 2 (length query)))
228 (unless (and (keywordp kw) (stringp val))
229 (error "Wrong query: %s %s" kw val))
230 (setq key (substring (symbol-name kw) 1))
232 ((:package :severity :tag :src :affects)
233 ;; Value shall be one word.
234 (if (string-match "\\`\\S-+\\'" val)
235 (setq vec (vconcat vec (list key val)))
236 (error "Wrong %s: %s" key val)))
237 ((:owner :submitter :maint :correspondent)
238 ;; Value is an email address.
239 (if (string-match "\\`\\S-+\\'" val)
241 (when (string-equal "me" val)
242 (setq val user-mail-address))
243 (when (string-match "<\\(.+\\)>" val)
244 (setq val (match-string 1 val)))
245 (setq vec (vconcat vec (list key val))))
246 (error "Wrong %s: %s" key val)))
248 ;; Possible values: "done", "forwarded" and "open"
249 (if (string-match "\\`\\(done\\|forwarded\\|open\\)\\'" val)
250 (setq vec (vconcat vec (list key val)))
251 (error "Wrong %s: %s" key val)))
253 ;; Value is `0' or `1' or `both'.
254 (if (string-match "\\`\\(0\\|1\\|both\\)\\'" val)
255 (setq vec (vconcat vec (list key val)))
256 (error "Wrong %s: %s" key val)))
257 (t (error "Unknown key: %s" kw))))
260 (error "Unknown key: %s" (car query)))
261 (sort (car (soap-invoke debbugs-wsdl debbugs-port "get_bugs" vec)) '<)))
263 (defun debbugs-newest-bugs (amount)
264 "Return the list of bug numbers, according to AMOUNT (a number) latest bugs."
265 (sort (car (soap-invoke debbugs-wsdl debbugs-port "newest_bugs" amount)) '<))
267 (defun debbugs-get-status (&rest bug-numbers)
268 "Return a list of status entries for the bugs identified by BUG-NUMBERS.
270 Every returned entry is an association list with the following attributes:
272 `bug_num': The bug number.
274 `package': A list of package names the bug belongs to.
276 `severity': The severity of the bug report. This can be
277 \"critical\", \"grave\", \"serious\", \"important\",
278 \"normal\", \"minor\" or \"wishlist\".
280 `tags': The status of the bug report, a list of strings. This
281 can be \"fixed\", \"notabug\", \"wontfix\", \"unreproducible\",
282 \"moreinfo\" or \"patch\".
284 `pending': The string \"pending\", \"forwarded\" or \"done\".
286 `subject': Subject/Title of the bugreport.
288 `originator': Submitter of the bugreport.
290 `mergedwith': A list of bug numbers this bug was merged with.
291 If it is a single bug, then this attribute contains just a
294 `source': Source package name of the bug report.
296 `date': Date of bug creation.
298 `log_modified', `last_modified': Date of last update.
300 `found_date', `fixed_date': Date of bug report / bug fix
303 `done': The email address of the worker who has closed the bug (if done).
305 `archived': `t' if the bug is archived, `nil' otherwise.
307 `unarchived': The date the bug has been unarchived, if ever.
309 `found_versions', `fixed_versions': List of version strings.
311 `forwarded': A URL or an email address.
313 `blocks': A list of bug numbers this bug blocks.
315 `blockedby': A list of bug numbers this bug is blocked by.
317 `msgid': The message id of the initial bug report.
319 `owner': Who is responsible for fixing.
321 `location': Always the string \"db-h\" or \"archive\".
323 `affects': A list of package names.
325 `summary': Arbitrary text.
329 \(debbugs-get-status 10)
331 => ;; Attributes with empty values are not shown
333 \(source . \"unknown\")
334 \(date . 1203606305.0)
335 \(msgid . \"<87zltuz7eh.fsf@freemail.hu>\")
336 \(severity . \"wishlist\")
337 \(owner . \"Magnus Henoch <mange@freemail.hu>\")
338 \(log_modified . 1261079402.0)
339 \(location . \"db-h\")
340 \(subject . \"url-gw should support HTTP CONNECT proxies\")
341 \(originator . \"Magnus Henoch <mange@freemail.hu>\")
342 \(last_modified . 1271200046.0)
343 \(pending . \"pending\")
344 \(package \"emacs\")))"
346 ;; Check for cached bugs.
347 (setq bug-numbers (delete-dups bug-numbers)
353 (let ((status (gethash bug debbugs-cache-data)))
357 (null debbugs-cache-expiry)
359 (natnump debbugs-cache-expiry)
360 (> (cdr (assoc 'cache_time status))
361 (- (float-time)) debbugs-cache-expiry))))
363 (setq cached-bugs (append cached-bugs (list status)))
368 ;; Retrieve the data.
369 (setq debbugs-soap-invoke-async-object nil)
371 ;; Retrieve bugs asynchronously.
372 (let ((bug-ids bug-numbers)
379 (debbugs-soap-invoke-async
384 bug-ids (- (length bug-ids)
385 debbugs-max-hits-per-request))))))
388 (last bug-ids (- (length bug-ids)
389 debbugs-max-hits-per-request))))
391 (dolist (res results)
393 ;; This is soap-client 3.0.
394 (while (buffer-live-p res)
395 (accept-process-output (get-buffer-process res) 0.1))
396 ;; Fallback with async.
397 (dolist (status (async-get res))
398 (setq debbugs-soap-invoke-async-object
399 (append debbugs-soap-invoke-async-object status)))))))
407 ;; "archived" is the number 1 or 0.
408 (setq y (assoc 'archived (cdr (assoc 'value x))))
409 (setcdr y (= (cdr y) 1))
410 ;; "found_versions" and "fixed_versions" are lists,
411 ;; containing strings or numbers.
412 (dolist (attribute '(found_versions fixed_versions))
413 (setq y (assoc attribute (cdr (assoc 'value x))))
415 (lambda (z) (if (numberp z) (number-to-string z) z))
417 ;; "mergedwith", "blocks" and "blockedby are strings,
418 ;; containing blank separated bug numbers.
419 (dolist (attribute '(mergedwith blocks blockedby))
420 (setq y (assoc attribute (cdr (assoc 'value x))))
421 (when (stringp (cdr y))
423 'string-to-number (split-string (cdr y) " " t)))))
424 ;; "package" is a string, containing comma separated
425 ;; package names. "keywords" and "tags" are strings,
426 ;; containing blank separated package names.
427 (dolist (attribute '(package keywords tags))
428 (setq y (assoc attribute (cdr (assoc 'value x))))
429 (when (stringp (cdr y))
430 (setcdr y (split-string (cdr y) ",\\| " t))))
431 ;; Cache the result, and return.
432 (if (and debbugs-cache-expiry (natnump debbugs-cache-expiry))
435 ;; Put also a time stamp.
436 (cons (cons 'cache_time (floor (float-time)))
437 (cdr (assoc 'value x)))
440 (cdr (assoc 'value x)))))
441 debbugs-soap-invoke-async-object))))
443 (defun debbugs-get-usertag (&rest query)
444 "Return a list of bug numbers which match QUERY.
446 QUERY is a sequence of keyword-value pairs where the values are
447 strings, i.e. :KEYWORD \"VALUE\" [:KEYWORD \"VALUE\"]*
451 :user -- The value is the name of the package a bug belongs to,
452 like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\". It can
453 also be an email address of a user who has applied a user tag.
454 The special email address \"me\" is used as pattern, replaced
455 with `user-mail-address'. There must be at least one such
456 entry; it is recommended to have exactly one.
458 :tag -- A string applied as user tag. Often, it is a
459 subproduct identification, like \"cedet\" or \"tramp\" for the
462 If there is no :tag entry, no bug numbers will be returned but a list of
463 existing user tags for :user.
467 \(debbugs-get-usertag :user \"emacs\")
469 => (\"www\" \"solaris\" \"ls-lisp\" \"cygwin\")
471 \(debbugs-get-usertag :user \"emacs\" :tag \"www\" :tag \"cygwin\")
475 (let (user tags kw key val object result)
477 (while (and (consp query) (<= 2 (length query)))
480 (unless (and (keywordp kw) (stringp val))
481 (error "Wrong query: %s %s" kw val))
482 (setq key (substring (symbol-name kw) 1))
485 ;; Value shall be one word. Extract email address, if existing.
486 (if (string-match "\\`\\S-+\\'" val)
488 (when (string-equal "me" val)
489 (setq val user-mail-address))
490 (when (string-match "<\\(.+\\)>" val)
491 (setq val (match-string 1 val)))
492 (pushnew val user :test #'equal))
493 (error "Wrong %s: %s" key val)))
495 ;; Value shall be one word.
496 (if (string-match "\\`\\S-+\\'" val)
497 (pushnew val tags :test #'equal)
498 (error "Wrong %s: %s" key val)))
499 (t (error "Unknown key: %s" kw))))
502 (error "Unknown key: %s" (car query)))
503 (unless (= (length user) 1)
504 (error "There must be exactly one :user entry"))
508 (car (soap-invoke debbugs-wsdl debbugs-port "get_usertag" (car user))))
511 ;; Return the list of existing tags.
512 (mapcar (lambda (x) (symbol-name (car x))) object)
514 ;; Return bug numbers.
515 (dolist (elt object result)
516 (when (member (symbol-name (car elt)) tags)
517 (setq result (append (cdr elt) result)))))))
519 (defun debbugs-get-bug-log (bug-number)
520 "Return a list of messages related to BUG-NUMBER.
522 Every message is an association list with the following attributes:
524 `msg_num': The number of the message inside the bug log. The
525 numbers are ascending, newer messages have a higher number.
527 `header': The message header lines, as arrived at the bug tracker.
529 `body': The message body.
531 `attachments' A list of possible attachments, or `nil'. Not
532 implemented yet server side."
533 (car (soap-invoke debbugs-wsdl debbugs-port "get_bug_log" bug-number)))
535 (defun debbugs-search-est (&rest query)
536 "Return the result of a full text search according to QUERY.
538 QUERY is a sequence of lists of keyword-value pairs where the
539 values are strings or numbers, i.e. :KEYWORD \"VALUE\" [:KEYWORD
542 Every sublist of the QUERY forms a hyperestraier condition. A
543 detailed description of hyperestraier conditions can be found at
544 URL `http://fallabs.com/hyperestraier/uguide-en.html#searchcond'.
546 The following conditions are possible:
548 \[:phrase SEARCH-PHRASE :skip NUMBER :max NUMBER\]
550 The string SEARCH-PHRASE forms the search on the database. It
551 contains words to be searched for, combined by operators like
552 AND, ANDNOT and OR. If there is no operator between the words,
553 AND is used by default. The phrase keyword and value can also
554 be omitted, this is useful in combination with other conditions.
556 :skip and :max are optional. They specify, how many hits are
557 skipped, and how many maximal hits are returned. This can be
558 used for paged results. Per default, :skip is 0 and all
559 possible hits are returned.
561 There must be exactly one such condition.
563 \[ATTRIBUTE VALUE+ :operation OPERATION :order ORDER\]
565 ATTRIBUTE is one of the following keywords:
567 :status -- Status of bug. Valid values are \"done\",
568 \"forwarded\" and \"open\".
570 :subject, :@title -- The subject of a message or the title of
573 :date, :@cdate -- The submission or modification dates of a
576 :submitter, :@author -- The email address of the submitter of a
577 bug or the author of a message belonging to this bug, a string.
578 The special email address \"me\" is used as pattern, replaced
579 with `user-mail-address'.
581 :package -- The value is the name of the package a bug belongs
582 to, like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\".
584 :tags -- An arbitrary string the bug is annotated with.
586 :severity -- This is the severity of the bug. The exact set of
587 allowed values depends on the Debbugs port. Examples are
588 \"normal\", \"minor\", \"wishlist\" etc.
590 :operator defines the comparison operator to be applied to
591 ATTRIBUTE. For string attributes this could be \"STREQ\" \(is
592 equal to the string), \"STRNE\" \(is not equal to the string),
593 \"STRINC\" \(includes the string), \"STRBW\" \(begins with the
594 string), \"STREW\" \(ends with the string), \"STRAND\"
595 \(includes all tokens in the string), \"STROR\" \(includes at
596 least one token in the string), \"STROREQ\" \(is equal to at
597 least one token in the string) or \"STRRX\" \(matches regular
598 expressions of the string). For operators with tokens, several
599 values for ATTRIBUTE shall be used.
601 Numbers can be compared by the operators \"NUMEQ\" \(is equal
602 to the number), \"NUMNE\" \(is not equal to the number),
603 \"NUMGT\" \(is greater than the number), \"NUMGE\" \(is greater
604 than or equal to the number), \"NUMLT\" \(is less than the
605 number), \"NUMLE\" \(is less than or equal to the number) or
606 \"NUMBT\" \(is between the two numbers). In the last case,
607 there must be two values for ATTRIBUTE.
609 If an operator is leaded by \"!\", the meaning is inverted. If
610 a string operator is leaded by \"I\", the case of the value is
613 The optional :order can be specified only in one condition. It
614 means, that ATTRIBUTE is used for sorting the results. The
615 following order operators exist: \"STRA\" \(ascending by
616 string), \"STRD\" \(descending by string), \"NUMA\" \(ascending
617 by number) or \"NUMD\" \(descending by number).
619 A special case is an :order, where there is no corresponding
620 attribute value and no operator. In this case, ATTRIBUTE is
621 not used for the search.
623 The result of the QUERY is a list of association lists with the
624 same attributes as in the conditions. Additional attributes are
626 `id': The bug number.
628 `msg_num': The number of the message inside the bug log.
630 `snippet': The surrounding text found by the search. For the
631 syntax of the snippet, consult the hyperestraier user guide.
636 '\(:phrase \"armstrong AND debbugs\" :skip 10 :max 2)
637 '\(:severity \"normal\" :operator \"STRINC\")
638 '\(:date :order \"NUMA\"))
640 => \(\(\(msg_num . 21)
642 \(@author . \"Glenn Morris <rgm@gnu.org>\")
643 \(@title . \"Re: bug#1567: Mailing an archived bug\")
645 \(severity . \"normal\")
646 \(@cdate . \"Wed, 17 Dec 2008 14:34:50 -0500\")
648 \(subject . \"Mailing an archived bug\")
649 \(package . \"debbugs.gnu.org\"))
652 ;; Show all messages from me between 2011-08-01 and 2011-08-31.
655 '\(:@author \"me\" :operator \"ISTRINC\")
657 ,\(floor \(float-time \(encode-time 0 0 0 1 8 2011)))
658 ,\(floor \(float-time \(encode-time 0 0 0 31 8 2011)))
659 :operator \"NUMBT\"))"
661 (let ((phrase (assoc :phrase query))
663 (if (and phrase (not (member :skip phrase)) (not (member :skip phrase)))
664 ;; We loop, until we have all results.
666 (query (delete phrase query))
675 phrase `(:skip ,skip)
676 `(:max ,debbugs-max-hits-per-request)))
678 skip (and (= (length result1) debbugs-max-hits-per-request)
679 (+ skip debbugs-max-hits-per-request))
680 result (append result result1)))
683 ;; Compile search arguments.
686 phrase-cond attr-cond)
688 ;; Phrase is mandatory, even if empty.
689 (when (and (or (member :skip elt) (member :max elt))
690 (not (member :phrase elt)))
691 (setq vec (vector "phrase" "")))
696 (unless (keywordp kw)
697 (error "Wrong keyword: %s" kw))
698 (setq key (substring (symbol-name kw) 1))
702 ;; It shouldn't happen in an attribute condition.
704 (error "Wrong keyword: %s" kw))
705 (setq phrase-cond t val (pop elt))
706 ;; Value is a string.
708 (setq vec (vconcat vec (list key val)))
709 (error "Wrong %s: %s" key val)))
712 ;; It shouldn't happen in an attribute condition.
714 (error "Wrong keyword: %s" kw))
715 (setq phrase-cond t val (pop elt))
716 ;; Value is a number.
718 (setq vec (vconcat vec (list key (number-to-string val))))
719 (error "Wrong %s: %s" key val)))
721 ;; Attribute condition.
722 ((:submitter :@author)
723 ;; It shouldn't happen in a phrase condition.
725 (error "Wrong keyword: %s" kw))
726 (if (not (stringp (car elt)))
727 (setq vec (vconcat vec (list key "")))
728 ;; Value is an email address.
729 (while (and (stringp (car elt))
730 (string-match "\\`\\S-+\\'" (car elt)))
731 (when (string-equal "me" (car elt))
732 (setcar elt user-mail-address))
733 (when (string-match "<\\(.+\\)>" (car elt))
734 (setcar elt (match-string 1 (car elt))))
736 (unless (member x val)
737 (setq val (append val (list x))))))
739 (vconcat vec (list key (mapconcat 'identity val " "))))))
742 ;; It shouldn't happen in a phrase condition.
744 (error "Wrong keyword: %s" kw))
746 (if (not (stringp (car elt)))
747 (setq vec (vconcat vec (list key "")))
748 ;; Possible values: "done", "forwarded" and "open"
749 (while (and (stringp (car elt))
751 "\\`\\(done\\|forwarded\\|open\\)\\'" (car elt)))
753 (unless (member x val)
754 (setq val (append val (list x))))))
756 (vconcat vec (list key (mapconcat 'identity val " "))))))
758 ((:subject :package :tags :severity :@title)
759 ;; It shouldn't happen in a phrase condition.
761 (error "Wrong keyword: %s" kw))
763 (if (not (stringp (car elt)))
764 (setq vec (vconcat vec (list key "")))
766 (while (stringp (car elt))
768 (unless (member x val)
769 (setq val (append val (list x))))))
771 (vconcat vec (list key (mapconcat 'identity val " "))))))
774 ;; It shouldn't happen in a phrase condition.
776 (error "Wrong keyword: %s" kw))
778 (if (not (numberp (car elt)))
779 (setq vec (vconcat vec (list key "")))
781 (while (numberp (car elt))
783 (unless (member x val)
784 (setq val (append val (list x))))))
787 vec (list key (mapconcat 'number-to-string val " "))))))
790 ;; It shouldn't happen in a phrase condition.
792 (error "Wrong keyword: %s" kw))
793 (setq attr-cond t val (pop elt))
794 ;; Value is a number.
796 (setq vec (vconcat vec (list key val)))
797 (error "Wrong %s: %s" key val)))
799 (t (error "Unknown key: %s" kw))))
801 (setq args (vconcat args (list vec)))))
804 (car (soap-invoke debbugs-wsdl debbugs-port "search_est" args)))
805 ;; The result contains lists (key value). We transform it into
806 ;; cons cells (key . value).
807 (dolist (elt1 result result)
809 (setcdr elt2 (cadr elt2)))))))
811 (defun debbugs-get-attribute (bug-or-message attribute)
812 "Return the value of key ATTRIBUTE.
814 BUG-OR-MESSAGE must be list element returned by either
815 `debbugs-get-status' or `debbugs-get-bug-log'.
817 Example: Return the originator of last submitted bug.
819 \(debbugs-get-attribute
820 \(car \(apply 'debbugs-get-status \(debbugs-newest-bugs 1))) 'originator)"
821 (cdr (assoc attribute bug-or-message)))
823 (defun debbugs-get-message-numbers (messages)
824 "Return the message numbers of MESSAGES.
825 MESSAGES must be the result of a `debbugs-get-bug-log' call."
826 (mapcar (lambda (x) (debbugs-get-attribute x 'msg_num)) messages))
828 (defun debbugs-get-message (messages message-number)
829 "Return the message MESSAGE-NUMBER of MESSAGES.
830 MESSAGES must be the result of a `debbugs-get-bug-log' call.
832 The returned message is a list of strings. The first element are
833 the header lines of the message, the second element is the body
834 of the message. Further elements of the list, if any, are
835 attachments of the message.
837 If there is no message with MESSAGE-NUMBER, the function returns `nil'.
839 Example: Return the first message of last submitted bug.
841 \(let \(\(messages \(apply 'debbugs-get-bug-log \(debbugs-newest-bugs 1))))
842 \(debbugs-get-message messages
843 \(car \(debbugs-get-message-numbers messages))))"
845 (/= (debbugs-get-attribute (car messages) 'msg_num)
847 (setq messages (cdr messages)))
849 (append (list (debbugs-get-attribute (car messages) 'header)
850 (debbugs-get-attribute (car messages) 'body))
851 (debbugs-get-attribute (car messages) 'attachments))))
853 (defun debbugs-get-mbox (bug-number mbox-type &optional filename)
854 "Download mbox with messages of bug BUG-NUMBER from Debbugs server.
855 BUG-NUMBER is a number of bug. It must be of integer type.
857 MBOX-TYPE specifies a type of mbox and can be one of the
860 `mboxfolder': Download mbox folder.
862 `mboxmaint': Download maintainer's mbox.
864 `mboxstat', `mboxstatus': Download status mbox. The use of
865 either symbol depends on actual Debbugs server configuration.
866 For gnu.org, use the former; for debian.org - the latter.
868 FILENAME, if non-`nil', is the name of file to store mbox. If
869 FILENAME is `nil', the downloaded mbox is inserted into the
871 (let (url (mt "") bn)
872 (unless (setq url (plist-get
873 (cdr (assoc debbugs-port debbugs-servers))
875 (error "URL of bugreport script for port %s is not specified"
877 (setq bn (format "bug=%s;" (number-to-string bug-number)))
878 (unless (eq mbox-type 'mboxfolder)
879 (if (memq mbox-type '(mboxmaint mboxstat mboxstatus))
880 (setq mt (concat (symbol-name mbox-type) "=yes;"))
881 (error "Unknown mbox type: %s" mbox-type)))
882 (setq url (concat url (format "?%s%smbox=yes" bn mt)))
884 (url-copy-file url filename t)
885 (url-insert-file-contents url))))
891 ;; * SOAP interface extensions (wishlist).
892 ;; - Server-side sorting.
893 ;; - Regexp and/or wildcards search.
894 ;; - Returning message attachments.
896 ;;; debbugs.el ends here