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."
246 ;; We cache it as bug "0" in `debbugs-cache-data'.
247 (list (cdr (assoc 'newest_bug
248 (let ((status (gethash 0 debbugs-cache-data)))
252 (null debbugs-cache-expiry)
254 (natnump debbugs-cache-expiry)
255 (> (cdr (assoc 'cache_time status))
256 (- (float-time) debbugs-cache-expiry)))))
257 ;; Take the cached value.
262 ;; Put also a time stamp.
264 (cons 'cache_time (float-time))
268 debbugs-wsdl debbugs-port "newest_bugs" amount)))))
269 (if (and debbugs-cache-expiry (natnump debbugs-cache-expiry))
271 (puthash 0 status debbugs-cache-data)
276 (car (soap-invoke debbugs-wsdl debbugs-port "newest_bugs" amount)) '<)))
278 (defun debbugs-convert-soap-value-to-string (string-value)
279 "If STRING-VALUE is unibyte, decode its contents as a UTF-8 string.
280 If STRING-VALUE is a multibyte string, then `soap-client'
281 received an xsd:string for this value, and will have decoded it
284 If STRING-VALUE is a unibyte string, then `soap-client' received
285 an xsd:base64Binary, and ran `base64-decode-string' on it to
286 produce a unibyte string of bytes.
288 For some reason, the Debbugs server code base64-encodes strings
289 that contain UTF-8 characters, and returns them as
290 xsd:base64Binary, instead of just returning them as xsd:string.
291 Therefore, when STRING-VALUE is a unibyte string, we assume its
292 bytes represent a UTF-8 string and decode them accordingly."
293 (if (stringp string-value)
294 (if (not (multibyte-string-p string-value))
295 (decode-coding-string string-value 'utf-8)
297 (error "Invalid string value")))
299 (defun debbugs-get-status (&rest bug-numbers)
300 "Return a list of status entries for the bugs identified by BUG-NUMBERS.
302 Every returned entry is an association list with the following attributes:
304 `bug_num': The bug number.
306 `package': A list of package names the bug belongs to.
308 `severity': The severity of the bug report. This can be
309 \"critical\", \"grave\", \"serious\", \"important\",
310 \"normal\", \"minor\" or \"wishlist\".
312 `tags': The status of the bug report, a list of strings. This
313 can be \"fixed\", \"notabug\", \"wontfix\", \"unreproducible\",
314 \"moreinfo\" or \"patch\".
316 `pending': The string \"pending\", \"forwarded\", \"fixed\" or \"done\".
318 `subject': Subject/Title of the bugreport.
320 `originator': Submitter of the bugreport.
322 `mergedwith': A list of bug numbers this bug was merged with.
323 If it is a single bug, then this attribute contains just a
326 `source': Source package name of the bug report.
328 `date': Date of bug creation.
330 `log_modified', `last_modified': Date of last update.
332 `found_date', `fixed_date': Date of bug report / bug fix
335 `done': The email address of the worker who has closed the bug (if done).
337 `archived': t if the bug is archived, nil otherwise.
339 `unarchived': The date the bug has been unarchived, if ever.
341 `found_versions', `fixed_versions': List of version strings.
343 `forwarded': A URL or an email address.
345 `blocks': A list of bug numbers this bug blocks.
347 `blockedby': A list of bug numbers this bug is blocked by.
349 `msgid': The message id of the initial bug report.
351 `owner': Who is responsible for fixing.
353 `location': Always the string \"db-h\" or \"archive\".
355 `affects': A list of package names.
357 `summary': Arbitrary text.
361 \(debbugs-get-status 10)
363 => ;; Attributes with empty values are not shown
365 \(source . \"unknown\")
366 \(date . 1203606305.0)
367 \(msgid . \"<87zltuz7eh.fsf@freemail.hu>\")
368 \(severity . \"wishlist\")
369 \(owner . \"Magnus Henoch <mange@freemail.hu>\")
370 \(log_modified . 1261079402.0)
371 \(location . \"db-h\")
372 \(subject . \"url-gw should support HTTP CONNECT proxies\")
373 \(originator . \"Magnus Henoch <mange@freemail.hu>\")
374 \(last_modified . 1271200046.0)
375 \(pending . \"pending\")
376 \(package \"emacs\")))"
378 ;; Check for cached bugs.
379 (setq bug-numbers (delete-dups bug-numbers)
385 (let ((status (gethash bug debbugs-cache-data)))
389 (null debbugs-cache-expiry)
391 (natnump debbugs-cache-expiry)
392 (> (cdr (assoc 'cache_time status))
393 (- (float-time) debbugs-cache-expiry)))))
395 (setq cached-bugs (append cached-bugs (list status)))
400 ;; Retrieve the data.
401 (setq debbugs-soap-invoke-async-object nil)
403 ;; Retrieve bugs asynchronously.
404 (let ((bug-ids bug-numbers)
411 (debbugs-soap-invoke-async
416 bug-ids (- (length bug-ids)
417 debbugs-max-hits-per-request))))))
420 (last bug-ids (- (length bug-ids)
421 debbugs-max-hits-per-request))))
423 (dolist (res results)
424 (while (buffer-live-p res)
425 (accept-process-output (get-buffer-process res) 0.1)))))
433 ;; "archived" is the number 1 or 0.
434 (setq y (assoc 'archived (cdr (assoc 'value x))))
435 (setcdr y (= (cdr y) 1))
436 ;; "found_versions" and "fixed_versions" are lists,
437 ;; containing strings or numbers.
438 (dolist (attribute '(found_versions fixed_versions))
439 (setq y (assoc attribute (cdr (assoc 'value x))))
441 (lambda (z) (if (numberp z) (number-to-string z) z))
443 ;; "mergedwith", "blocks" and "blockedby are strings,
444 ;; containing blank separated bug numbers.
445 (dolist (attribute '(mergedwith blocks blockedby))
446 (setq y (assoc attribute (cdr (assoc 'value x))))
447 (when (stringp (cdr y))
449 #'string-to-number (split-string (cdr y) " " t)))))
450 ;; "subject", "originator", "owner" and "summary" may be an
451 ;; xsd:base64Binary value containing a UTF-8-encoded string.
452 (dolist (attribute '(subject originator owner summary))
453 (setq y (assoc attribute (cdr (assoc 'value x))))
454 (when (stringp (cdr y))
455 (setcdr y (debbugs-convert-soap-value-to-string (cdr y)))))
456 ;; "package" is a string, containing comma separated
457 ;; package names. "keywords" and "tags" are strings,
458 ;; containing blank separated package names.
459 (dolist (attribute '(package keywords tags))
460 (setq y (assoc attribute (cdr (assoc 'value x))))
461 (when (stringp (cdr y))
462 (setcdr y (split-string (cdr y) ",\\| " t))))
463 ;; Cache the result, and return.
464 (if (and debbugs-cache-expiry (natnump debbugs-cache-expiry))
467 ;; Put also a time stamp.
468 (cons (cons 'cache_time (float-time))
469 (cdr (assoc 'value x)))
472 (cdr (assoc 'value x)))))
473 debbugs-soap-invoke-async-object))))
475 (defun debbugs-get-usertag (&rest query)
476 "Return a list of bug numbers which match QUERY.
478 QUERY is a sequence of keyword-value pairs where the values are
479 strings, i.e. :KEYWORD \"VALUE\" [:KEYWORD \"VALUE\"]*
483 :user -- The value is the name of the package a bug belongs to,
484 like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\". It can
485 also be an email address of a user who has applied a user tag.
486 The special email address \"me\" is used as pattern, replaced
487 with `user-mail-address'. There must be at least one such
488 entry; it is recommended to have exactly one.
490 :tag -- A string applied as user tag. Often, it is a
491 subproduct identification, like \"cedet\" or \"tramp\" for the
494 If there is no :tag entry, no bug numbers will be returned but a list of
495 existing user tags for :user.
499 \(debbugs-get-usertag :user \"emacs\")
501 => (\"www\" \"solaris\" \"ls-lisp\" \"cygwin\")
503 \(debbugs-get-usertag :user \"emacs\" :tag \"www\" :tag \"cygwin\")
507 (let (user tags kw key val object result)
509 (while (and (consp query) (<= 2 (length query)))
512 (unless (and (keywordp kw) (stringp val))
513 (error "Wrong query: %s %s" kw val))
514 (setq key (substring (symbol-name kw) 1))
517 ;; Value shall be one word. Extract email address, if existing.
518 (if (string-match "\\`\\S-+\\'" val)
520 (when (string-equal "me" val)
521 (setq val user-mail-address))
522 (when (string-match "<\\(.+\\)>" val)
523 (setq val (match-string 1 val)))
524 (cl-pushnew val user :test #'equal))
525 (error "Wrong %s: %s" key val)))
527 ;; Value shall be one word.
528 (if (string-match "\\`\\S-+\\'" val)
529 (cl-pushnew val tags :test #'equal)
530 (error "Wrong %s: %s" key val)))
531 (t (error "Unknown key: %s" kw))))
534 (error "Unknown key: %s" (car query)))
535 (unless (= (length user) 1)
536 (error "There must be exactly one :user entry"))
540 (car (soap-invoke debbugs-wsdl debbugs-port "get_usertag" (car user))))
543 ;; Return the list of existing tags.
544 (mapcar (lambda (x) (symbol-name (car x))) object)
546 ;; Return bug numbers.
547 (dolist (elt object result)
548 (when (member (symbol-name (car elt)) tags)
549 (setq result (append (cdr elt) result)))))))
551 (defun debbugs-get-bug-log (bug-number)
552 "Return a list of messages related to BUG-NUMBER.
554 Every message is an association list with the following attributes:
556 `msg_num': The number of the message inside the bug log. The
557 numbers are ascending, newer messages have a higher number.
559 `header': The message header lines, as arrived at the bug tracker.
561 `body': The message body.
563 `attachments' A list of possible attachments, or nil. Not
564 implemented yet server side."
565 (car (soap-invoke debbugs-wsdl debbugs-port "get_bug_log" bug-number)))
567 (defun debbugs-search-est (&rest query)
568 "Return the result of a full text search according to QUERY.
570 QUERY is a sequence of lists of keyword-value pairs where the
571 values are strings or numbers, i.e. :KEYWORD \"VALUE\" [:KEYWORD
574 Every sublist of the QUERY forms a hyperestraier condition. A
575 detailed description of hyperestraier conditions can be found at
576 URL `http://fallabs.com/hyperestraier/uguide-en.html#searchcond'.
578 The following conditions are possible:
580 \[:phrase SEARCH-PHRASE :skip NUMBER :max NUMBER\]
582 The string SEARCH-PHRASE forms the search on the database. It
583 contains words to be searched for, combined by operators like
584 AND, ANDNOT and OR. If there is no operator between the words,
585 AND is used by default. The phrase keyword and value can also
586 be omitted, this is useful in combination with other conditions.
588 :skip and :max are optional. They specify, how many hits are
589 skipped, and how many maximal hits are returned. This can be
590 used for paged results. Per default, :skip is 0 and all
591 possible hits are returned.
593 There must be exactly one such condition.
595 \[ATTRIBUTE VALUE+ :operation OPERATION :order ORDER\]
597 ATTRIBUTE is one of the following keywords:
599 :subject, :@title -- The subject of a message or the title of
602 :date, :@cdate -- The submission or modification dates of a
605 :@author -- The email address of the author of a message
606 belonging to this bug, a string. It may be different than
607 the email of the person submitting the bug.
608 The special email address \"me\" is used as pattern, replaced
609 with `user-mail-address'.
611 :package -- The value is the name of the package a bug belongs
612 to, like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\".
614 :tags -- An arbitrary string the bug is annotated with.
616 :severity -- This is the severity of the bug. The exact set of
617 allowed values depends on the Debbugs port. Examples are
618 \"normal\", \"minor\", \"wishlist\" etc.
620 :operator defines the comparison operator to be applied to
621 ATTRIBUTE. For string attributes this could be \"STREQ\" \(is
622 equal to the string), \"STRNE\" \(is not equal to the string),
623 \"STRINC\" \(includes the string), \"STRBW\" \(begins with the
624 string), \"STREW\" \(ends with the string), \"STRAND\"
625 \(includes all tokens in the string), \"STROR\" \(includes at
626 least one token in the string), \"STROREQ\" \(is equal to at
627 least one token in the string) or \"STRRX\" \(matches regular
628 expressions of the string). For operators with tokens, several
629 values for ATTRIBUTE shall be used.
631 Numbers can be compared by the operators \"NUMEQ\" \(is equal
632 to the number), \"NUMNE\" \(is not equal to the number),
633 \"NUMGT\" \(is greater than the number), \"NUMGE\" \(is greater
634 than or equal to the number), \"NUMLT\" \(is less than the
635 number), \"NUMLE\" \(is less than or equal to the number) or
636 \"NUMBT\" \(is between the two numbers). In the last case,
637 there must be two values for ATTRIBUTE.
639 If an operator is leaded by \"!\", the meaning is inverted. If
640 a string operator is leaded by \"I\", the case of the value is
643 The optional :order can be specified only in one condition. It
644 means, that ATTRIBUTE is used for sorting the results. The
645 following order operators exist: \"STRA\" \(ascending by
646 string), \"STRD\" \(descending by string), \"NUMA\" \(ascending
647 by number) or \"NUMD\" \(descending by number).
649 A special case is an :order, where there is no corresponding
650 attribute value and no operator. In this case, ATTRIBUTE is
651 not used for the search.
653 The result of the QUERY is a list of association lists with the
654 same attributes as in the conditions. Additional attributes are
656 `id': The bug number.
658 `msg_num': The number of the message inside the bug log.
660 `snippet': The surrounding text found by the search. For the
661 syntax of the snippet, consult the hyperestraier user guide.
666 \\='\(:phrase \"armstrong AND debbugs\" :skip 10 :max 2)
667 \\='\(:severity \"normal\" :operator \"STRINC\")
668 \\='\(:date :order \"NUMA\"))
670 => \(\(\(msg_num . 21)
672 \(@author . \"Glenn Morris <rgm@gnu.org>\")
673 \(@title . \"Re: bug#1567: Mailing an archived bug\")
675 \(severity . \"normal\")
676 \(@cdate . \"Wed, 17 Dec 2008 14:34:50 -0500\")
678 \(subject . \"Mailing an archived bug\")
679 \(package . \"debbugs.gnu.org\"))
682 ;; Show all messages from me between 2011-08-01 and 2011-08-31.
685 \\='\(:@author \"me\" :operator \"ISTRINC\")
687 ,\(floor \(float-time \(encode-time 0 0 0 1 8 2011)))
688 ,\(floor \(float-time \(encode-time 0 0 0 31 8 2011)))
689 :operator \"NUMBT\"))"
691 (let ((phrase (assoc :phrase query))
693 (if (and phrase (not (member :skip phrase)) (not (member :max phrase)))
694 ;; We loop, until we have all results.
696 (query (delete phrase query))
705 phrase `(:skip ,skip)
706 `(:max ,debbugs-max-hits-per-request)))
708 skip (and (= (length result1) debbugs-max-hits-per-request)
709 (+ skip debbugs-max-hits-per-request))
710 result (append result result1)))
713 ;; Compile search arguments.
715 ;; FIXME: `vec' is used in an O(N²) way. It should be a list instead,
716 ;; on which we push elements, and we only convert it to a vector at
719 phrase-cond attr-cond)
721 ;; Phrase is mandatory, even if empty.
722 (when (and (or (member :skip elt) (member :max elt))
723 (not (member :phrase elt)))
724 (setq vec (vector "phrase" "")))
729 (unless (keywordp kw)
730 (error "Wrong keyword: %s" kw))
731 (setq key (substring (symbol-name kw) 1))
735 ;; It shouldn't happen in an attribute condition.
737 (error "Wrong keyword: %s" kw))
738 (setq phrase-cond t val (pop elt))
739 ;; Value is a string.
741 (setq vec (vconcat vec (list key val)))
742 (error "Wrong %s: %s" key val)))
745 ;; It shouldn't happen in an attribute condition.
747 (error "Wrong keyword: %s" kw))
748 (setq phrase-cond t val (pop elt))
749 ;; Value is a number.
751 (setq vec (vconcat vec (list key (number-to-string val))))
752 (error "Wrong %s: %s" key val)))
754 ;; Attribute condition.
755 ((:submitter :@author)
756 ;; It shouldn't happen.
757 (if (or (and (eq kw :submitter) phrase-cond)
758 (and (eq kw :@author) attr-cond))
759 (error "Wrong keyword: %s" kw))
760 (if (not (stringp (car elt)))
761 (setq vec (vconcat vec (list key "")))
762 ;; Value is an email address.
763 (while (and (stringp (car elt))
764 (string-match "\\`\\S-+\\'" (car elt)))
765 (when (string-equal "me" (car elt))
766 (setcar elt user-mail-address))
767 (when (string-match "<\\(.+\\)>" (car elt))
768 (setcar elt (match-string 1 (car elt))))
770 (unless (member x val)
771 (setq val (append val (list x))))))
774 vec (list key (mapconcat #'identity val " "))))))
777 ;; It shouldn't happen in a phrase condition.
779 (error "Wrong keyword: %s" kw))
781 (if (not (stringp (car elt)))
782 (setq vec (vconcat vec (list key "")))
783 ;; Possible values: "open", "forwarded" and "done".
784 (while (and (stringp (car elt))
786 "\\`\\(open\\|forwarded\\|done\\)\\'" (car elt)))
788 (unless (member x val)
789 (setq val (append val (list x))))))
792 vec (list key (mapconcat #'identity val " "))))))
794 ((:subject :package :tags :severity :@title)
795 ;; It shouldn't happen in a phrase condition.
797 (error "Wrong keyword: %s" kw))
799 (if (not (stringp (car elt)))
800 (setq vec (vconcat vec (list key "")))
802 (while (stringp (car elt))
804 (unless (member x val)
805 (setq val (append val (list x))))))
808 vec (list key (mapconcat #'identity val " "))))))
811 ;; It shouldn't happen in a phrase condition.
813 (error "Wrong keyword: %s" kw))
815 (if (not (numberp (car elt)))
816 (setq vec (vconcat vec (list key "")))
818 (while (numberp (car elt))
820 (unless (member x val)
821 (setq val (append val (list x))))))
825 (list key (mapconcat #'number-to-string val " "))))))
828 ;; It shouldn't happen in a phrase condition.
830 (error "Wrong keyword: %s" kw))
831 (setq attr-cond t val (pop elt))
832 ;; Value is a number.
834 (setq vec (vconcat vec (list key val)))
835 (error "Wrong %s: %s" key val)))
837 (t (error "Unknown key: %s" kw))))
839 (setq args (vconcat args (list vec)))))
842 (car (soap-invoke debbugs-wsdl debbugs-port "search_est" args)))
843 ;; The result contains lists (key value). We transform it into
844 ;; cons cells (key . value).
845 (dolist (elt1 result result)
847 (setcdr elt2 (cadr elt2)))))))
849 (defun debbugs-get-attribute (bug-or-message attribute)
850 "Return the value of key ATTRIBUTE.
852 BUG-OR-MESSAGE must be list element returned by either
853 `debbugs-get-status' or `debbugs-get-bug-log'.
855 Example: Return the originator of last submitted bug.
857 \(debbugs-get-attribute
858 \(car \(apply #\\='debbugs-get-status \(debbugs-newest-bugs 1))) \\='originator)"
859 (cdr (assoc attribute bug-or-message)))
861 (defun debbugs-get-message-numbers (messages)
862 "Return the message numbers of MESSAGES.
863 MESSAGES must be the result of a `debbugs-get-bug-log' call."
864 (mapcar (lambda (x) (debbugs-get-attribute x 'msg_num)) messages))
866 (defun debbugs-get-message (messages message-number)
867 "Return the message MESSAGE-NUMBER of MESSAGES.
868 MESSAGES must be the result of a `debbugs-get-bug-log' call.
870 The returned message is a list of strings. The first element are
871 the header lines of the message, the second element is the body
872 of the message. Further elements of the list, if any, are
873 attachments of the message.
875 If there is no message with MESSAGE-NUMBER, the function returns nil.
877 Example: Return the first message of last submitted bug.
879 \(let \(\(messages \(apply #\\='debbugs-get-bug-log \(debbugs-newest-bugs 1))))
880 \(debbugs-get-message messages
881 \(car \(debbugs-get-message-numbers messages))))"
883 (/= (debbugs-get-attribute (car messages) 'msg_num)
885 (setq messages (cdr messages)))
887 (append (list (debbugs-get-attribute (car messages) 'header)
888 (debbugs-get-attribute (car messages) 'body))
889 (debbugs-get-attribute (car messages) 'attachments))))
891 (defun debbugs-get-mbox (bug-number mbox-type &optional filename)
892 "Download mbox with messages of bug BUG-NUMBER from Debbugs server.
893 BUG-NUMBER is a number of bug. It must be of integer type.
895 MBOX-TYPE specifies a type of mbox and can be one of the
898 `mboxfolder': Download mbox folder.
900 `mboxmaint': Download maintainer's mbox.
902 `mboxstat', `mboxstatus': Download status mbox. The use of
903 either symbol depends on actual Debbugs server configuration.
904 For gnu.org, use the former; for debian.org - the latter.
906 FILENAME, if non-nil, is the name of file to store mbox. If
907 FILENAME is nil, the downloaded mbox is inserted into the
909 (let (url (mt "") bn)
910 (unless (setq url (plist-get
911 (cdr (assoc debbugs-port debbugs-servers))
913 (error "URL of bugreport script for port %s is not specified"
915 (setq bn (format "bug=%s;" (number-to-string bug-number)))
916 (unless (eq mbox-type 'mboxfolder)
917 (if (memq mbox-type '(mboxmaint mboxstat mboxstatus))
918 (setq mt (concat (symbol-name mbox-type) "=yes;"))
919 (error "Unknown mbox type: %s" mbox-type)))
920 (setq url (concat url (format "?%s%smbox=yes" bn mt)))
922 (url-copy-file url filename t)
923 (url-insert-file-contents url))))
929 ;; * SOAP interface extensions (wishlist).
930 ;; - Server-side sorting.
931 ;; - Regexp and/or wildcards search.
932 ;; - Returning message attachments.
934 ;;; debbugs.el ends here