1 ;;; debbugs.el --- SOAP library to access debbugs servers -*- lexical-binding:t -*-
3 ;; Copyright (C) 2011-2016 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
6 ;; Keywords: comm, hypermedia
9 ;; Package-Requires: ((soap-client "3.1.1") (cl-lib "0.5"))
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-lib))
44 (defcustom debbugs-servers
46 :wsdl "http://debbugs.gnu.org/cgi/soap.cgi?WSDL"
47 :bugreport-url "http://debbugs.gnu.org/cgi/bugreport.cgi")
49 :wsdl "http://bugs.debian.org/cgi-bin/soap.cgi?WSDL"
50 :bugreport-url "http://bugs.debian.org/cgi-bin/bugreport.cgi"))
51 "*List of Debbugs server specifiers.
52 Each entry is a list that contains a string identifying the port
53 name and the server parameters in keyword-value form. Allowed
56 `:wsdl' -- Location of WSDL. The value is a string with URL that
57 should return the WSDL specification of Debbugs/SOAP service.
59 `:bugreport-url' -- URL of the server script that returns mboxes
62 The list initially contains two predefined and configured Debbugs
63 servers: \"gnu.org\" and \"debian.org\"."
65 :link '(custom-manual "(debbugs)Debbugs server specifiers")
70 (string :tag "Port name")
71 (checklist :tag "Options" :greedy t
73 (const :format "" :value :wsdl)
76 (const :format "" :value :bugreport-url)
77 (string :tag "Bugreport URL")))))))
79 (defcustom debbugs-port "gnu.org"
80 "The port instance to be applied from `debbugs-wsdl'.
81 This corresponds to the Debbugs server to be accessed, either
82 \"gnu.org\", or \"debian.org\", or user defined port name."
83 ;; Maybe we should create an own group?
85 :type '(choice :tag "Debbugs server" (const "gnu.org") (const "debian.org")
86 (string :tag "user defined port name")))
88 ;; It would be nice if we could retrieve it from the debbugs server.
90 (defconst debbugs-wsdl
95 (file-name-directory load-file-name)
97 "The WSDL object to be used describing the SOAP interface.")
99 ;; Please do not increase this value, otherwise we would run into
100 ;; performance problems on the server. Maybe we need to change this a
101 ;; server specific value.
102 (defconst debbugs-max-hits-per-request 500
103 "The max number of bugs or results per soap invocation.")
105 (defvar debbugs-cache-data
106 (make-hash-table :test 'equal :size debbugs-max-hits-per-request)
107 "Hash table of retrieved bugs.")
109 (defcustom debbugs-cache-expiry (* 60 60)
110 "How many seconds debbugs query results are cached.
111 `t' or 0 disables caching, `nil' disables expiring."
113 :type '(choice (const :tag "Always" t)
114 (const :tag "Never" nil)
115 (integer :tag "Seconds")))
117 (defvar debbugs-soap-invoke-async-object nil
118 "The object manipulated by `debbugs-soap-invoke-async'.")
120 (defun debbugs-soap-invoke-async (operation-name &rest parameters)
121 "Invoke the SOAP connection asynchronously."
124 (lambda (response &rest _args)
125 (setq debbugs-soap-invoke-async-object
126 (append debbugs-soap-invoke-async-object (car response))))
127 nil debbugs-wsdl debbugs-port operation-name parameters))
129 (defun debbugs-get-bugs (&rest query)
130 "Return a list of bug numbers which match QUERY.
132 QUERY is a sequence of keyword-value pairs where the values are
133 strings, i.e. :KEYWORD \"VALUE\" [:KEYWORD \"VALUE\"]*
135 The keyword-value pair is a subquery. The keywords are allowed to
136 have multiple occurrence within the query at any place. The
137 subqueries with the same keyword form the logical subquery, which
138 returns the union of bugs of every subquery it contains.
140 The result of the QUERY is an intersection of results of all
145 :package -- The value is the name of the package a bug belongs
146 to, like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\".
148 :src -- This is used to retrieve bugs that belong to source
151 :severity -- This is the severity of the bug. The exact set of
152 allowed values depends on the Debbugs port. Examples are
153 \"normal\", \"minor\", \"wishlist\" etc.
155 :tag -- An arbitrary string the bug is annotated with.
156 Usually, this is used to mark the status of the bug, like
157 \"fixed\", \"moreinfo\", \"notabug\", \"patch\",
158 \"unreproducible\" or \"wontfix\". The exact set of tags
159 depends on the Debbugs port.
161 :owner -- This is used to identify bugs by the owner's email
162 address. The special email address \"me\" is used as pattern,
163 replaced with `user-mail-address'.
165 :submitter -- With this keyword it is possible to filter bugs
166 by the submitter's email address. The special email address
167 \"me\" is used as pattern, replaced with `user-mail-address'.
169 :maint -- This is used to find bugs of the packages which are
170 maintained by the person with the given email address. The
171 special email address \"me\" is used as pattern, replaced with
174 :correspondent -- This allows to find bug reports where the
175 person with the given email address has participated. The
176 special email address \"me\" is used as pattern, replaced with
179 :affects -- With this keyword it is possible to find bugs which
180 affect the package with the given name. The bugs are chosen by
181 the value of field `affects' in bug's status. The returned bugs
182 do not necessary belong to this package.
184 :status -- Status of bug. Valid values are \"open\",
185 \"forwarded\" and \"done\".
187 :archive -- A keyword to filter for bugs which are already
188 archived, or not. Valid values are \"0\" (not archived),
189 \"1\" (archived) or \"both\". If this keyword is not given in
190 the query, `:archive \"0\"' is assumed by default.
192 Example. Get all opened and forwarded release critical bugs for
193 the packages which are maintained by \"me\" and which have a
196 \(debbugs-get-bugs :maint \"me\" :tag \"patch\"
197 :severity \"critical\"
200 :status \"forwarded\"
201 :severity \"serious\")"
203 (let (vec kw key val)
205 (while (and (consp query) (<= 2 (length query)))
208 (unless (and (keywordp kw) (stringp val))
209 (error "Wrong query: %s %s" kw val))
210 (setq key (substring (symbol-name kw) 1))
212 ((:package :severity :tag :src :affects)
213 ;; Value shall be one word.
214 (if (string-match "\\`\\S-+\\'" val)
215 (setq vec (vconcat vec (list key val)))
216 (error "Wrong %s: %s" key val)))
217 ((:owner :submitter :maint :correspondent)
218 ;; Value is an email address.
219 (if (string-match "\\`\\S-+\\'" val)
221 (when (string-equal "me" val)
222 (setq val user-mail-address))
223 (when (string-match "<\\(.+\\)>" val)
224 (setq val (match-string 1 val)))
225 (setq vec (vconcat vec (list key val))))
226 (error "Wrong %s: %s" key val)))
228 ;; Possible values: "open", "forwarded" and "done".
229 (if (string-match "\\`\\(open\\|forwarded\\|done\\)\\'" val)
230 (setq vec (vconcat vec (list key val)))
231 (error "Wrong %s: %s" key val)))
233 ;; Value is `0' or `1' or `both'.
234 (if (string-match "\\`\\(0\\|1\\|both\\)\\'" val)
235 (setq vec (vconcat vec (list key val)))
236 (error "Wrong %s: %s" key val)))
237 (t (error "Unknown key: %s" kw))))
240 (error "Unknown key: %s" (car query)))
241 (sort (car (soap-invoke debbugs-wsdl debbugs-port "get_bugs" vec)) '<)))
243 (defun debbugs-newest-bugs (amount)
244 "Return the list of bug numbers, according to AMOUNT (a number) latest bugs."
245 (sort (car (soap-invoke debbugs-wsdl debbugs-port "newest_bugs" amount)) '<))
247 (defun debbugs-convert-soap-value-to-string (string-value)
248 "If STRING-VALUE is unibyte, decode its contents as a UTF-8 string.
249 If STRING-VALUE is a multibyte string, then `soap-client'
250 received an xsd:string for this value, and will have decoded it
253 If STRING-VALUE is a unibyte string, then `soap-client' received
254 an xsd:base64Binary, and ran `base64-decode-string' on it to
255 produce a unibyte string of bytes.
257 For some reason, the Debbugs server code base64-encodes strings
258 that contain UTF-8 characters, and returns them as
259 xsd:base64Binary, instead of just returning them as xsd:string.
260 Therefore, when STRING-VALUE is a unibyte string, we assume its
261 bytes represent a UTF-8 string and decode them accordingly."
262 (if (stringp string-value)
263 (if (not (multibyte-string-p string-value))
264 (decode-coding-string string-value 'utf-8)
266 (error "Invalid string value")))
268 (defun debbugs-get-status (&rest bug-numbers)
269 "Return a list of status entries for the bugs identified by BUG-NUMBERS.
271 Every returned entry is an association list with the following attributes:
273 `bug_num': The bug number.
275 `package': A list of package names the bug belongs to.
277 `severity': The severity of the bug report. This can be
278 \"critical\", \"grave\", \"serious\", \"important\",
279 \"normal\", \"minor\" or \"wishlist\".
281 `tags': The status of the bug report, a list of strings. This
282 can be \"fixed\", \"notabug\", \"wontfix\", \"unreproducible\",
283 \"moreinfo\" or \"patch\".
285 `pending': The string \"pending\", \"forwarded\", \"fixed\" or \"done\".
287 `subject': Subject/Title of the bugreport.
289 `originator': Submitter of the bugreport.
291 `mergedwith': A list of bug numbers this bug was merged with.
292 If it is a single bug, then this attribute contains just a
295 `source': Source package name of the bug report.
297 `date': Date of bug creation.
299 `log_modified', `last_modified': Date of last update.
301 `found_date', `fixed_date': Date of bug report / bug fix
304 `done': The email address of the worker who has closed the bug (if done).
306 `archived': `t' if the bug is archived, `nil' otherwise.
308 `unarchived': The date the bug has been unarchived, if ever.
310 `found_versions', `fixed_versions': List of version strings.
312 `forwarded': A URL or an email address.
314 `blocks': A list of bug numbers this bug blocks.
316 `blockedby': A list of bug numbers this bug is blocked by.
318 `msgid': The message id of the initial bug report.
320 `owner': Who is responsible for fixing.
322 `location': Always the string \"db-h\" or \"archive\".
324 `affects': A list of package names.
326 `summary': Arbitrary text.
330 \(debbugs-get-status 10)
332 => ;; Attributes with empty values are not shown
334 \(source . \"unknown\")
335 \(date . 1203606305.0)
336 \(msgid . \"<87zltuz7eh.fsf@freemail.hu>\")
337 \(severity . \"wishlist\")
338 \(owner . \"Magnus Henoch <mange@freemail.hu>\")
339 \(log_modified . 1261079402.0)
340 \(location . \"db-h\")
341 \(subject . \"url-gw should support HTTP CONNECT proxies\")
342 \(originator . \"Magnus Henoch <mange@freemail.hu>\")
343 \(last_modified . 1271200046.0)
344 \(pending . \"pending\")
345 \(package \"emacs\")))"
347 ;; Check for cached bugs.
348 (setq bug-numbers (delete-dups bug-numbers)
354 (let ((status (gethash bug debbugs-cache-data)))
358 (null debbugs-cache-expiry)
360 (natnump debbugs-cache-expiry)
361 (> (cdr (assoc 'cache_time status))
362 (- (float-time)) debbugs-cache-expiry))))
364 (setq cached-bugs (append cached-bugs (list status)))
369 ;; Retrieve the data.
370 (setq debbugs-soap-invoke-async-object nil)
372 ;; Retrieve bugs asynchronously.
373 (let ((bug-ids bug-numbers)
380 (debbugs-soap-invoke-async
385 bug-ids (- (length bug-ids)
386 debbugs-max-hits-per-request))))))
389 (last bug-ids (- (length bug-ids)
390 debbugs-max-hits-per-request))))
392 (dolist (res results)
393 (while (buffer-live-p res)
394 (accept-process-output (get-buffer-process res) 0.1)))))
402 ;; "archived" is the number 1 or 0.
403 (setq y (assoc 'archived (cdr (assoc 'value x))))
404 (setcdr y (= (cdr y) 1))
405 ;; "found_versions" and "fixed_versions" are lists,
406 ;; containing strings or numbers.
407 (dolist (attribute '(found_versions fixed_versions))
408 (setq y (assoc attribute (cdr (assoc 'value x))))
410 (lambda (z) (if (numberp z) (number-to-string z) z))
412 ;; "mergedwith", "blocks" and "blockedby are strings,
413 ;; containing blank separated bug numbers.
414 (dolist (attribute '(mergedwith blocks blockedby))
415 (setq y (assoc attribute (cdr (assoc 'value x))))
416 (when (stringp (cdr y))
418 #'string-to-number (split-string (cdr y) " " t)))))
419 ;; "subject", "originator", "owner" and "summary" may be an
420 ;; xsd:base64Binary value containing a UTF-8-encoded string.
421 (dolist (attribute '(subject originator owner summary))
422 (setq y (assoc attribute (cdr (assoc 'value x))))
423 (when (stringp (cdr y))
424 (setcdr y (debbugs-convert-soap-value-to-string (cdr y)))))
425 ;; "package" is a string, containing comma separated
426 ;; package names. "keywords" and "tags" are strings,
427 ;; containing blank separated package names.
428 (dolist (attribute '(package keywords tags))
429 (setq y (assoc attribute (cdr (assoc 'value x))))
430 (when (stringp (cdr y))
431 (setcdr y (split-string (cdr y) ",\\| " t))))
432 ;; Cache the result, and return.
433 (if (and debbugs-cache-expiry (natnump debbugs-cache-expiry))
436 ;; Put also a time stamp.
437 (cons (cons 'cache_time (float-time))
438 (cdr (assoc 'value x)))
441 (cdr (assoc 'value x)))))
442 debbugs-soap-invoke-async-object))))
444 (defun debbugs-get-usertag (&rest query)
445 "Return a list of bug numbers which match QUERY.
447 QUERY is a sequence of keyword-value pairs where the values are
448 strings, i.e. :KEYWORD \"VALUE\" [:KEYWORD \"VALUE\"]*
452 :user -- The value is the name of the package a bug belongs to,
453 like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\". It can
454 also be an email address of a user who has applied a user tag.
455 The special email address \"me\" is used as pattern, replaced
456 with `user-mail-address'. There must be at least one such
457 entry; it is recommended to have exactly one.
459 :tag -- A string applied as user tag. Often, it is a
460 subproduct identification, like \"cedet\" or \"tramp\" for the
463 If there is no :tag entry, no bug numbers will be returned but a list of
464 existing user tags for :user.
468 \(debbugs-get-usertag :user \"emacs\")
470 => (\"www\" \"solaris\" \"ls-lisp\" \"cygwin\")
472 \(debbugs-get-usertag :user \"emacs\" :tag \"www\" :tag \"cygwin\")
476 (let (user tags kw key val object result)
478 (while (and (consp query) (<= 2 (length query)))
481 (unless (and (keywordp kw) (stringp val))
482 (error "Wrong query: %s %s" kw val))
483 (setq key (substring (symbol-name kw) 1))
486 ;; Value shall be one word. Extract email address, if existing.
487 (if (string-match "\\`\\S-+\\'" val)
489 (when (string-equal "me" val)
490 (setq val user-mail-address))
491 (when (string-match "<\\(.+\\)>" val)
492 (setq val (match-string 1 val)))
493 (cl-pushnew val user :test #'equal))
494 (error "Wrong %s: %s" key val)))
496 ;; Value shall be one word.
497 (if (string-match "\\`\\S-+\\'" val)
498 (cl-pushnew val tags :test #'equal)
499 (error "Wrong %s: %s" key val)))
500 (t (error "Unknown key: %s" kw))))
503 (error "Unknown key: %s" (car query)))
504 (unless (= (length user) 1)
505 (error "There must be exactly one :user entry"))
509 (car (soap-invoke debbugs-wsdl debbugs-port "get_usertag" (car user))))
512 ;; Return the list of existing tags.
513 (mapcar (lambda (x) (symbol-name (car x))) object)
515 ;; Return bug numbers.
516 (dolist (elt object result)
517 (when (member (symbol-name (car elt)) tags)
518 (setq result (append (cdr elt) result)))))))
520 (defun debbugs-get-bug-log (bug-number)
521 "Return a list of messages related to BUG-NUMBER.
523 Every message is an association list with the following attributes:
525 `msg_num': The number of the message inside the bug log. The
526 numbers are ascending, newer messages have a higher number.
528 `header': The message header lines, as arrived at the bug tracker.
530 `body': The message body.
532 `attachments' A list of possible attachments, or `nil'. Not
533 implemented yet server side."
534 (car (soap-invoke debbugs-wsdl debbugs-port "get_bug_log" bug-number)))
536 (defun debbugs-search-est (&rest query)
537 "Return the result of a full text search according to QUERY.
539 QUERY is a sequence of lists of keyword-value pairs where the
540 values are strings or numbers, i.e. :KEYWORD \"VALUE\" [:KEYWORD
543 Every sublist of the QUERY forms a hyperestraier condition. A
544 detailed description of hyperestraier conditions can be found at
545 URL `http://fallabs.com/hyperestraier/uguide-en.html#searchcond'.
547 The following conditions are possible:
549 \[:phrase SEARCH-PHRASE :skip NUMBER :max NUMBER\]
551 The string SEARCH-PHRASE forms the search on the database. It
552 contains words to be searched for, combined by operators like
553 AND, ANDNOT and OR. If there is no operator between the words,
554 AND is used by default. The phrase keyword and value can also
555 be omitted, this is useful in combination with other conditions.
557 :skip and :max are optional. They specify, how many hits are
558 skipped, and how many maximal hits are returned. This can be
559 used for paged results. Per default, :skip is 0 and all
560 possible hits are returned.
562 There must be exactly one such condition.
564 \[ATTRIBUTE VALUE+ :operation OPERATION :order ORDER\]
566 ATTRIBUTE is one of the following keywords:
568 :subject, :@title -- The subject of a message or the title of
571 :date, :@cdate -- The submission or modification dates of a
574 :@author -- The email address of the author of a message
575 belonging to this bug, a string. It may be different than
576 the email of the person submitting the bug.
577 The special email address \"me\" is used as pattern, replaced
578 with `user-mail-address'.
580 :package -- The value is the name of the package a bug belongs
581 to, like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\".
583 :tags -- An arbitrary string the bug is annotated with.
585 :severity -- This is the severity of the bug. The exact set of
586 allowed values depends on the Debbugs port. Examples are
587 \"normal\", \"minor\", \"wishlist\" etc.
589 :operator defines the comparison operator to be applied to
590 ATTRIBUTE. For string attributes this could be \"STREQ\" \(is
591 equal to the string), \"STRNE\" \(is not equal to the string),
592 \"STRINC\" \(includes the string), \"STRBW\" \(begins with the
593 string), \"STREW\" \(ends with the string), \"STRAND\"
594 \(includes all tokens in the string), \"STROR\" \(includes at
595 least one token in the string), \"STROREQ\" \(is equal to at
596 least one token in the string) or \"STRRX\" \(matches regular
597 expressions of the string). For operators with tokens, several
598 values for ATTRIBUTE shall be used.
600 Numbers can be compared by the operators \"NUMEQ\" \(is equal
601 to the number), \"NUMNE\" \(is not equal to the number),
602 \"NUMGT\" \(is greater than the number), \"NUMGE\" \(is greater
603 than or equal to the number), \"NUMLT\" \(is less than the
604 number), \"NUMLE\" \(is less than or equal to the number) or
605 \"NUMBT\" \(is between the two numbers). In the last case,
606 there must be two values for ATTRIBUTE.
608 If an operator is leaded by \"!\", the meaning is inverted. If
609 a string operator is leaded by \"I\", the case of the value is
612 The optional :order can be specified only in one condition. It
613 means, that ATTRIBUTE is used for sorting the results. The
614 following order operators exist: \"STRA\" \(ascending by
615 string), \"STRD\" \(descending by string), \"NUMA\" \(ascending
616 by number) or \"NUMD\" \(descending by number).
618 A special case is an :order, where there is no corresponding
619 attribute value and no operator. In this case, ATTRIBUTE is
620 not used for the search.
622 The result of the QUERY is a list of association lists with the
623 same attributes as in the conditions. Additional attributes are
625 `id': The bug number.
627 `msg_num': The number of the message inside the bug log.
629 `snippet': The surrounding text found by the search. For the
630 syntax of the snippet, consult the hyperestraier user guide.
635 '\(:phrase \"armstrong AND debbugs\" :skip 10 :max 2)
636 '\(:severity \"normal\" :operator \"STRINC\")
637 '\(:date :order \"NUMA\"))
639 => \(\(\(msg_num . 21)
641 \(@author . \"Glenn Morris <rgm@gnu.org>\")
642 \(@title . \"Re: bug#1567: Mailing an archived bug\")
644 \(severity . \"normal\")
645 \(@cdate . \"Wed, 17 Dec 2008 14:34:50 -0500\")
647 \(subject . \"Mailing an archived bug\")
648 \(package . \"debbugs.gnu.org\"))
651 ;; Show all messages from me between 2011-08-01 and 2011-08-31.
654 '\(:@author \"me\" :operator \"ISTRINC\")
656 ,\(floor \(float-time \(encode-time 0 0 0 1 8 2011)))
657 ,\(floor \(float-time \(encode-time 0 0 0 31 8 2011)))
658 :operator \"NUMBT\"))"
660 (let ((phrase (assoc :phrase query))
662 (if (and phrase (not (member :skip phrase)) (not (member :max phrase)))
663 ;; We loop, until we have all results.
665 (query (delete phrase query))
674 phrase `(:skip ,skip)
675 `(:max ,debbugs-max-hits-per-request)))
677 skip (and (= (length result1) debbugs-max-hits-per-request)
678 (+ skip debbugs-max-hits-per-request))
679 result (append result result1)))
682 ;; Compile search arguments.
684 ;; FIXME: `vec' is used in an O(N²) way. It should be a list instead,
685 ;; on which we push elements, and we only convert it to a vector at
688 phrase-cond attr-cond)
690 ;; Phrase is mandatory, even if empty.
691 (when (and (or (member :skip elt) (member :max elt))
692 (not (member :phrase elt)))
693 (setq vec (vector "phrase" "")))
698 (unless (keywordp kw)
699 (error "Wrong keyword: %s" kw))
700 (setq key (substring (symbol-name kw) 1))
704 ;; It shouldn't happen in an attribute condition.
706 (error "Wrong keyword: %s" kw))
707 (setq phrase-cond t val (pop elt))
708 ;; Value is a string.
710 (setq vec (vconcat vec (list key val)))
711 (error "Wrong %s: %s" key val)))
714 ;; It shouldn't happen in an attribute condition.
716 (error "Wrong keyword: %s" kw))
717 (setq phrase-cond t val (pop elt))
718 ;; Value is a number.
720 (setq vec (vconcat vec (list key (number-to-string val))))
721 (error "Wrong %s: %s" key val)))
723 ;; Attribute condition.
724 ((:submitter :@author)
725 ;; It shouldn't happen.
726 (if (or (and (eq kw :submitter) phrase-cond)
727 (and (eq kw :@author) attr-cond))
728 (error "Wrong keyword: %s" kw))
729 (if (not (stringp (car elt)))
730 (setq vec (vconcat vec (list key "")))
731 ;; Value is an email address.
732 (while (and (stringp (car elt))
733 (string-match "\\`\\S-+\\'" (car elt)))
734 (when (string-equal "me" (car elt))
735 (setcar elt user-mail-address))
736 (when (string-match "<\\(.+\\)>" (car elt))
737 (setcar elt (match-string 1 (car elt))))
739 (unless (member x val)
740 (setq val (append val (list x))))))
743 vec (list key (mapconcat #'identity val " "))))))
746 ;; It shouldn't happen in a phrase condition.
748 (error "Wrong keyword: %s" kw))
750 (if (not (stringp (car elt)))
751 (setq vec (vconcat vec (list key "")))
752 ;; Possible values: "open", "forwarded" and "done".
753 (while (and (stringp (car elt))
755 "\\`\\(open\\|forwarded\\|done\\)\\'" (car elt)))
757 (unless (member x val)
758 (setq val (append val (list x))))))
761 vec (list key (mapconcat #'identity val " "))))))
763 ((:subject :package :tags :severity :@title)
764 ;; It shouldn't happen in a phrase condition.
766 (error "Wrong keyword: %s" kw))
768 (if (not (stringp (car elt)))
769 (setq vec (vconcat vec (list key "")))
771 (while (stringp (car elt))
773 (unless (member x val)
774 (setq val (append val (list x))))))
777 vec (list key (mapconcat #'identity val " "))))))
780 ;; It shouldn't happen in a phrase condition.
782 (error "Wrong keyword: %s" kw))
784 (if (not (numberp (car elt)))
785 (setq vec (vconcat vec (list key "")))
787 (while (numberp (car elt))
789 (unless (member x val)
790 (setq val (append val (list x))))))
794 (list key (mapconcat #'number-to-string val " "))))))
797 ;; It shouldn't happen in a phrase condition.
799 (error "Wrong keyword: %s" kw))
800 (setq attr-cond t val (pop elt))
801 ;; Value is a number.
803 (setq vec (vconcat vec (list key val)))
804 (error "Wrong %s: %s" key val)))
806 (t (error "Unknown key: %s" kw))))
808 (setq args (vconcat args (list vec)))))
811 (car (soap-invoke debbugs-wsdl debbugs-port "search_est" args)))
812 ;; The result contains lists (key value). We transform it into
813 ;; cons cells (key . value).
814 (dolist (elt1 result result)
816 (setcdr elt2 (cadr elt2)))))))
818 (defun debbugs-get-attribute (bug-or-message attribute)
819 "Return the value of key ATTRIBUTE.
821 BUG-OR-MESSAGE must be list element returned by either
822 `debbugs-get-status' or `debbugs-get-bug-log'.
824 Example: Return the originator of last submitted bug.
826 \(debbugs-get-attribute
827 \(car \(apply #'debbugs-get-status \(debbugs-newest-bugs 1))) 'originator)"
828 (cdr (assoc attribute bug-or-message)))
830 (defun debbugs-get-message-numbers (messages)
831 "Return the message numbers of MESSAGES.
832 MESSAGES must be the result of a `debbugs-get-bug-log' call."
833 (mapcar (lambda (x) (debbugs-get-attribute x 'msg_num)) messages))
835 (defun debbugs-get-message (messages message-number)
836 "Return the message MESSAGE-NUMBER of MESSAGES.
837 MESSAGES must be the result of a `debbugs-get-bug-log' call.
839 The returned message is a list of strings. The first element are
840 the header lines of the message, the second element is the body
841 of the message. Further elements of the list, if any, are
842 attachments of the message.
844 If there is no message with MESSAGE-NUMBER, the function returns `nil'.
846 Example: Return the first message of last submitted bug.
848 \(let \(\(messages \(apply #'debbugs-get-bug-log \(debbugs-newest-bugs 1))))
849 \(debbugs-get-message messages
850 \(car \(debbugs-get-message-numbers messages))))"
852 (/= (debbugs-get-attribute (car messages) 'msg_num)
854 (setq messages (cdr messages)))
856 (append (list (debbugs-get-attribute (car messages) 'header)
857 (debbugs-get-attribute (car messages) 'body))
858 (debbugs-get-attribute (car messages) 'attachments))))
860 (defun debbugs-get-mbox (bug-number mbox-type &optional filename)
861 "Download mbox with messages of bug BUG-NUMBER from Debbugs server.
862 BUG-NUMBER is a number of bug. It must be of integer type.
864 MBOX-TYPE specifies a type of mbox and can be one of the
867 `mboxfolder': Download mbox folder.
869 `mboxmaint': Download maintainer's mbox.
871 `mboxstat', `mboxstatus': Download status mbox. The use of
872 either symbol depends on actual Debbugs server configuration.
873 For gnu.org, use the former; for debian.org - the latter.
875 FILENAME, if non-`nil', is the name of file to store mbox. If
876 FILENAME is `nil', the downloaded mbox is inserted into the
878 (let (url (mt "") bn)
879 (unless (setq url (plist-get
880 (cdr (assoc debbugs-port debbugs-servers))
882 (error "URL of bugreport script for port %s is not specified"
884 (setq bn (format "bug=%s;" (number-to-string bug-number)))
885 (unless (eq mbox-type 'mboxfolder)
886 (if (memq mbox-type '(mboxmaint mboxstat mboxstatus))
887 (setq mt (concat (symbol-name mbox-type) "=yes;"))
888 (error "Unknown mbox type: %s" mbox-type)))
889 (setq url (concat url (format "?%s%smbox=yes" bn mt)))
891 (url-copy-file url filename t)
892 (url-insert-file-contents url))))
898 ;; * SOAP interface extensions (wishlist).
899 ;; - Server-side sorting.
900 ;; - Regexp and/or wildcards search.
901 ;; - Returning message attachments.
903 ;;; debbugs.el ends here