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-convert-soap-value-to-string (string-value)
268 "If STRING-VALUE is unibyte, decode its contents as a UTF-8 string.
269 If STRING-VALUE is a multibyte string, then `soap-client'
270 received an xsd:string for this value, and will have decoded it
273 If STRING-VALUE is a unibyte string, then `soap-client' received
274 an xsd:base64Binary, and ran `base64-decode-string' on it to
275 produce a unibyte string of bytes.
277 For some reason, the Debbugs server code base64-encodes strings
278 that contain UTF-8 characters, and returns them as
279 xsd:base64Binary, instead of just returning them as xsd:string.
280 Therefore, when STRING-VALUE is a unibyte string, we assume its
281 bytes represent a UTF-8 string and decode them accordingly."
282 (if (stringp string-value)
283 (if (not (multibyte-string-p string-value))
284 (decode-coding-string string-value 'utf-8)
286 (error "Invalid string value")))
288 (defun debbugs-get-status (&rest bug-numbers)
289 "Return a list of status entries for the bugs identified by BUG-NUMBERS.
291 Every returned entry is an association list with the following attributes:
293 `bug_num': The bug number.
295 `package': A list of package names the bug belongs to.
297 `severity': The severity of the bug report. This can be
298 \"critical\", \"grave\", \"serious\", \"important\",
299 \"normal\", \"minor\" or \"wishlist\".
301 `tags': The status of the bug report, a list of strings. This
302 can be \"fixed\", \"notabug\", \"wontfix\", \"unreproducible\",
303 \"moreinfo\" or \"patch\".
305 `pending': The string \"pending\", \"forwarded\" or \"done\".
307 `subject': Subject/Title of the bugreport.
309 `originator': Submitter of the bugreport.
311 `mergedwith': A list of bug numbers this bug was merged with.
312 If it is a single bug, then this attribute contains just a
315 `source': Source package name of the bug report.
317 `date': Date of bug creation.
319 `log_modified', `last_modified': Date of last update.
321 `found_date', `fixed_date': Date of bug report / bug fix
324 `done': The email address of the worker who has closed the bug (if done).
326 `archived': `t' if the bug is archived, `nil' otherwise.
328 `unarchived': The date the bug has been unarchived, if ever.
330 `found_versions', `fixed_versions': List of version strings.
332 `forwarded': A URL or an email address.
334 `blocks': A list of bug numbers this bug blocks.
336 `blockedby': A list of bug numbers this bug is blocked by.
338 `msgid': The message id of the initial bug report.
340 `owner': Who is responsible for fixing.
342 `location': Always the string \"db-h\" or \"archive\".
344 `affects': A list of package names.
346 `summary': Arbitrary text.
350 \(debbugs-get-status 10)
352 => ;; Attributes with empty values are not shown
354 \(source . \"unknown\")
355 \(date . 1203606305.0)
356 \(msgid . \"<87zltuz7eh.fsf@freemail.hu>\")
357 \(severity . \"wishlist\")
358 \(owner . \"Magnus Henoch <mange@freemail.hu>\")
359 \(log_modified . 1261079402.0)
360 \(location . \"db-h\")
361 \(subject . \"url-gw should support HTTP CONNECT proxies\")
362 \(originator . \"Magnus Henoch <mange@freemail.hu>\")
363 \(last_modified . 1271200046.0)
364 \(pending . \"pending\")
365 \(package \"emacs\")))"
367 ;; Check for cached bugs.
368 (setq bug-numbers (delete-dups bug-numbers)
374 (let ((status (gethash bug debbugs-cache-data)))
378 (null debbugs-cache-expiry)
380 (natnump debbugs-cache-expiry)
381 (> (cdr (assoc 'cache_time status))
382 (- (float-time)) debbugs-cache-expiry))))
384 (setq cached-bugs (append cached-bugs (list status)))
389 ;; Retrieve the data.
390 (setq debbugs-soap-invoke-async-object nil)
392 ;; Retrieve bugs asynchronously.
393 (let ((bug-ids bug-numbers)
400 (debbugs-soap-invoke-async
405 bug-ids (- (length bug-ids)
406 debbugs-max-hits-per-request))))))
409 (last bug-ids (- (length bug-ids)
410 debbugs-max-hits-per-request))))
412 (dolist (res results)
414 ;; This is soap-client 3.0.
415 (while (buffer-live-p res)
416 (accept-process-output (get-buffer-process res) 0.1))
417 ;; Fallback with async.
418 (dolist (status (async-get res))
419 (setq debbugs-soap-invoke-async-object
420 (append debbugs-soap-invoke-async-object status)))))))
428 ;; "archived" is the number 1 or 0.
429 (setq y (assoc 'archived (cdr (assoc 'value x))))
430 (setcdr y (= (cdr y) 1))
431 ;; "found_versions" and "fixed_versions" are lists,
432 ;; containing strings or numbers.
433 (dolist (attribute '(found_versions fixed_versions))
434 (setq y (assoc attribute (cdr (assoc 'value x))))
436 (lambda (z) (if (numberp z) (number-to-string z) z))
438 ;; "mergedwith", "blocks" and "blockedby are strings,
439 ;; containing blank separated bug numbers.
440 (dolist (attribute '(mergedwith blocks blockedby))
441 (setq y (assoc attribute (cdr (assoc 'value x))))
442 (when (stringp (cdr y))
444 'string-to-number (split-string (cdr y) " " t)))))
445 ;; "subject", "originator", "owner" and "summary" may be an
446 ;; xsd:base64Binary value containing a UTF-8-encoded string.
447 (dolist (attribute '(subject originator owner summary))
448 (setq y (assoc attribute (cdr (assoc 'value x))))
449 (when (stringp (cdr y))
450 (setcdr y (debbugs-convert-soap-value-to-string (cdr y)))))
451 ;; "package" is a string, containing comma separated
452 ;; package names. "keywords" and "tags" are strings,
453 ;; containing blank separated package names.
454 (dolist (attribute '(package keywords tags))
455 (setq y (assoc attribute (cdr (assoc 'value x))))
456 (when (stringp (cdr y))
457 (setcdr y (split-string (cdr y) ",\\| " t))))
458 ;; Cache the result, and return.
459 (if (and debbugs-cache-expiry (natnump debbugs-cache-expiry))
462 ;; Put also a time stamp.
463 (cons (cons 'cache_time (floor (float-time)))
464 (cdr (assoc 'value x)))
467 (cdr (assoc 'value x)))))
468 debbugs-soap-invoke-async-object))))
470 (defun debbugs-get-usertag (&rest query)
471 "Return a list of bug numbers which match QUERY.
473 QUERY is a sequence of keyword-value pairs where the values are
474 strings, i.e. :KEYWORD \"VALUE\" [:KEYWORD \"VALUE\"]*
478 :user -- The value is the name of the package a bug belongs to,
479 like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\". It can
480 also be an email address of a user who has applied a user tag.
481 The special email address \"me\" is used as pattern, replaced
482 with `user-mail-address'. There must be at least one such
483 entry; it is recommended to have exactly one.
485 :tag -- A string applied as user tag. Often, it is a
486 subproduct identification, like \"cedet\" or \"tramp\" for the
489 If there is no :tag entry, no bug numbers will be returned but a list of
490 existing user tags for :user.
494 \(debbugs-get-usertag :user \"emacs\")
496 => (\"www\" \"solaris\" \"ls-lisp\" \"cygwin\")
498 \(debbugs-get-usertag :user \"emacs\" :tag \"www\" :tag \"cygwin\")
502 (let (user tags kw key val object result)
504 (while (and (consp query) (<= 2 (length query)))
507 (unless (and (keywordp kw) (stringp val))
508 (error "Wrong query: %s %s" kw val))
509 (setq key (substring (symbol-name kw) 1))
512 ;; Value shall be one word. Extract email address, if existing.
513 (if (string-match "\\`\\S-+\\'" val)
515 (when (string-equal "me" val)
516 (setq val user-mail-address))
517 (when (string-match "<\\(.+\\)>" val)
518 (setq val (match-string 1 val)))
519 (pushnew val user :test #'equal))
520 (error "Wrong %s: %s" key val)))
522 ;; Value shall be one word.
523 (if (string-match "\\`\\S-+\\'" val)
524 (pushnew val tags :test #'equal)
525 (error "Wrong %s: %s" key val)))
526 (t (error "Unknown key: %s" kw))))
529 (error "Unknown key: %s" (car query)))
530 (unless (= (length user) 1)
531 (error "There must be exactly one :user entry"))
535 (car (soap-invoke debbugs-wsdl debbugs-port "get_usertag" (car user))))
538 ;; Return the list of existing tags.
539 (mapcar (lambda (x) (symbol-name (car x))) object)
541 ;; Return bug numbers.
542 (dolist (elt object result)
543 (when (member (symbol-name (car elt)) tags)
544 (setq result (append (cdr elt) result)))))))
546 (defun debbugs-get-bug-log (bug-number)
547 "Return a list of messages related to BUG-NUMBER.
549 Every message is an association list with the following attributes:
551 `msg_num': The number of the message inside the bug log. The
552 numbers are ascending, newer messages have a higher number.
554 `header': The message header lines, as arrived at the bug tracker.
556 `body': The message body.
558 `attachments' A list of possible attachments, or `nil'. Not
559 implemented yet server side."
560 (car (soap-invoke debbugs-wsdl debbugs-port "get_bug_log" bug-number)))
562 (defun debbugs-search-est (&rest query)
563 "Return the result of a full text search according to QUERY.
565 QUERY is a sequence of lists of keyword-value pairs where the
566 values are strings or numbers, i.e. :KEYWORD \"VALUE\" [:KEYWORD
569 Every sublist of the QUERY forms a hyperestraier condition. A
570 detailed description of hyperestraier conditions can be found at
571 URL `http://fallabs.com/hyperestraier/uguide-en.html#searchcond'.
573 The following conditions are possible:
575 \[:phrase SEARCH-PHRASE :skip NUMBER :max NUMBER\]
577 The string SEARCH-PHRASE forms the search on the database. It
578 contains words to be searched for, combined by operators like
579 AND, ANDNOT and OR. If there is no operator between the words,
580 AND is used by default. The phrase keyword and value can also
581 be omitted, this is useful in combination with other conditions.
583 :skip and :max are optional. They specify, how many hits are
584 skipped, and how many maximal hits are returned. This can be
585 used for paged results. Per default, :skip is 0 and all
586 possible hits are returned.
588 There must be exactly one such condition.
590 \[ATTRIBUTE VALUE+ :operation OPERATION :order ORDER\]
592 ATTRIBUTE is one of the following keywords:
594 :status -- Status of bug. Valid values are \"done\",
595 \"forwarded\" and \"open\".
597 :subject, :@title -- The subject of a message or the title of
600 :date, :@cdate -- The submission or modification dates of a
603 :submitter, :@author -- The email address of the submitter of a
604 bug or the author of a message belonging to this bug, a string.
605 The special email address \"me\" is used as pattern, replaced
606 with `user-mail-address'.
608 :package -- The value is the name of the package a bug belongs
609 to, like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\".
611 :tags -- An arbitrary string the bug is annotated with.
613 :severity -- This is the severity of the bug. The exact set of
614 allowed values depends on the Debbugs port. Examples are
615 \"normal\", \"minor\", \"wishlist\" etc.
617 :operator defines the comparison operator to be applied to
618 ATTRIBUTE. For string attributes this could be \"STREQ\" \(is
619 equal to the string), \"STRNE\" \(is not equal to the string),
620 \"STRINC\" \(includes the string), \"STRBW\" \(begins with the
621 string), \"STREW\" \(ends with the string), \"STRAND\"
622 \(includes all tokens in the string), \"STROR\" \(includes at
623 least one token in the string), \"STROREQ\" \(is equal to at
624 least one token in the string) or \"STRRX\" \(matches regular
625 expressions of the string). For operators with tokens, several
626 values for ATTRIBUTE shall be used.
628 Numbers can be compared by the operators \"NUMEQ\" \(is equal
629 to the number), \"NUMNE\" \(is not equal to the number),
630 \"NUMGT\" \(is greater than the number), \"NUMGE\" \(is greater
631 than or equal to the number), \"NUMLT\" \(is less than the
632 number), \"NUMLE\" \(is less than or equal to the number) or
633 \"NUMBT\" \(is between the two numbers). In the last case,
634 there must be two values for ATTRIBUTE.
636 If an operator is leaded by \"!\", the meaning is inverted. If
637 a string operator is leaded by \"I\", the case of the value is
640 The optional :order can be specified only in one condition. It
641 means, that ATTRIBUTE is used for sorting the results. The
642 following order operators exist: \"STRA\" \(ascending by
643 string), \"STRD\" \(descending by string), \"NUMA\" \(ascending
644 by number) or \"NUMD\" \(descending by number).
646 A special case is an :order, where there is no corresponding
647 attribute value and no operator. In this case, ATTRIBUTE is
648 not used for the search.
650 The result of the QUERY is a list of association lists with the
651 same attributes as in the conditions. Additional attributes are
653 `id': The bug number.
655 `msg_num': The number of the message inside the bug log.
657 `snippet': The surrounding text found by the search. For the
658 syntax of the snippet, consult the hyperestraier user guide.
663 '\(:phrase \"armstrong AND debbugs\" :skip 10 :max 2)
664 '\(:severity \"normal\" :operator \"STRINC\")
665 '\(:date :order \"NUMA\"))
667 => \(\(\(msg_num . 21)
669 \(@author . \"Glenn Morris <rgm@gnu.org>\")
670 \(@title . \"Re: bug#1567: Mailing an archived bug\")
672 \(severity . \"normal\")
673 \(@cdate . \"Wed, 17 Dec 2008 14:34:50 -0500\")
675 \(subject . \"Mailing an archived bug\")
676 \(package . \"debbugs.gnu.org\"))
679 ;; Show all messages from me between 2011-08-01 and 2011-08-31.
682 '\(:@author \"me\" :operator \"ISTRINC\")
684 ,\(floor \(float-time \(encode-time 0 0 0 1 8 2011)))
685 ,\(floor \(float-time \(encode-time 0 0 0 31 8 2011)))
686 :operator \"NUMBT\"))"
688 (let ((phrase (assoc :phrase query))
690 (if (and phrase (not (member :skip phrase)) (not (member :skip phrase)))
691 ;; We loop, until we have all results.
693 (query (delete phrase query))
702 phrase `(:skip ,skip)
703 `(:max ,debbugs-max-hits-per-request)))
705 skip (and (= (length result1) debbugs-max-hits-per-request)
706 (+ skip debbugs-max-hits-per-request))
707 result (append result result1)))
710 ;; Compile search arguments.
713 phrase-cond attr-cond)
715 ;; Phrase is mandatory, even if empty.
716 (when (and (or (member :skip elt) (member :max elt))
717 (not (member :phrase elt)))
718 (setq vec (vector "phrase" "")))
723 (unless (keywordp kw)
724 (error "Wrong keyword: %s" kw))
725 (setq key (substring (symbol-name kw) 1))
729 ;; It shouldn't happen in an attribute condition.
731 (error "Wrong keyword: %s" kw))
732 (setq phrase-cond t val (pop elt))
733 ;; Value is a string.
735 (setq vec (vconcat vec (list key val)))
736 (error "Wrong %s: %s" key val)))
739 ;; It shouldn't happen in an attribute condition.
741 (error "Wrong keyword: %s" kw))
742 (setq phrase-cond t val (pop elt))
743 ;; Value is a number.
745 (setq vec (vconcat vec (list key (number-to-string val))))
746 (error "Wrong %s: %s" key val)))
748 ;; Attribute condition.
749 ((:submitter :@author)
750 ;; It shouldn't happen in a phrase condition.
752 (error "Wrong keyword: %s" kw))
753 (if (not (stringp (car elt)))
754 (setq vec (vconcat vec (list key "")))
755 ;; Value is an email address.
756 (while (and (stringp (car elt))
757 (string-match "\\`\\S-+\\'" (car elt)))
758 (when (string-equal "me" (car elt))
759 (setcar elt user-mail-address))
760 (when (string-match "<\\(.+\\)>" (car elt))
761 (setcar elt (match-string 1 (car elt))))
763 (unless (member x val)
764 (setq val (append val (list x))))))
766 (vconcat vec (list key (mapconcat 'identity val " "))))))
769 ;; It shouldn't happen in a phrase condition.
771 (error "Wrong keyword: %s" kw))
773 (if (not (stringp (car elt)))
774 (setq vec (vconcat vec (list key "")))
775 ;; Possible values: "done", "forwarded" and "open"
776 (while (and (stringp (car elt))
778 "\\`\\(done\\|forwarded\\|open\\)\\'" (car elt)))
780 (unless (member x val)
781 (setq val (append val (list x))))))
783 (vconcat vec (list key (mapconcat 'identity val " "))))))
785 ((:subject :package :tags :severity :@title)
786 ;; It shouldn't happen in a phrase condition.
788 (error "Wrong keyword: %s" kw))
790 (if (not (stringp (car elt)))
791 (setq vec (vconcat vec (list key "")))
793 (while (stringp (car elt))
795 (unless (member x val)
796 (setq val (append val (list x))))))
798 (vconcat vec (list key (mapconcat 'identity val " "))))))
801 ;; It shouldn't happen in a phrase condition.
803 (error "Wrong keyword: %s" kw))
805 (if (not (numberp (car elt)))
806 (setq vec (vconcat vec (list key "")))
808 (while (numberp (car elt))
810 (unless (member x val)
811 (setq val (append val (list x))))))
814 vec (list key (mapconcat 'number-to-string val " "))))))
817 ;; It shouldn't happen in a phrase condition.
819 (error "Wrong keyword: %s" kw))
820 (setq attr-cond t val (pop elt))
821 ;; Value is a number.
823 (setq vec (vconcat vec (list key val)))
824 (error "Wrong %s: %s" key val)))
826 (t (error "Unknown key: %s" kw))))
828 (setq args (vconcat args (list vec)))))
831 (car (soap-invoke debbugs-wsdl debbugs-port "search_est" args)))
832 ;; The result contains lists (key value). We transform it into
833 ;; cons cells (key . value).
834 (dolist (elt1 result result)
836 (setcdr elt2 (cadr elt2)))))))
838 (defun debbugs-get-attribute (bug-or-message attribute)
839 "Return the value of key ATTRIBUTE.
841 BUG-OR-MESSAGE must be list element returned by either
842 `debbugs-get-status' or `debbugs-get-bug-log'.
844 Example: Return the originator of last submitted bug.
846 \(debbugs-get-attribute
847 \(car \(apply 'debbugs-get-status \(debbugs-newest-bugs 1))) 'originator)"
848 (cdr (assoc attribute bug-or-message)))
850 (defun debbugs-get-message-numbers (messages)
851 "Return the message numbers of MESSAGES.
852 MESSAGES must be the result of a `debbugs-get-bug-log' call."
853 (mapcar (lambda (x) (debbugs-get-attribute x 'msg_num)) messages))
855 (defun debbugs-get-message (messages message-number)
856 "Return the message MESSAGE-NUMBER of MESSAGES.
857 MESSAGES must be the result of a `debbugs-get-bug-log' call.
859 The returned message is a list of strings. The first element are
860 the header lines of the message, the second element is the body
861 of the message. Further elements of the list, if any, are
862 attachments of the message.
864 If there is no message with MESSAGE-NUMBER, the function returns `nil'.
866 Example: Return the first message of last submitted bug.
868 \(let \(\(messages \(apply 'debbugs-get-bug-log \(debbugs-newest-bugs 1))))
869 \(debbugs-get-message messages
870 \(car \(debbugs-get-message-numbers messages))))"
872 (/= (debbugs-get-attribute (car messages) 'msg_num)
874 (setq messages (cdr messages)))
876 (append (list (debbugs-get-attribute (car messages) 'header)
877 (debbugs-get-attribute (car messages) 'body))
878 (debbugs-get-attribute (car messages) 'attachments))))
880 (defun debbugs-get-mbox (bug-number mbox-type &optional filename)
881 "Download mbox with messages of bug BUG-NUMBER from Debbugs server.
882 BUG-NUMBER is a number of bug. It must be of integer type.
884 MBOX-TYPE specifies a type of mbox and can be one of the
887 `mboxfolder': Download mbox folder.
889 `mboxmaint': Download maintainer's mbox.
891 `mboxstat', `mboxstatus': Download status mbox. The use of
892 either symbol depends on actual Debbugs server configuration.
893 For gnu.org, use the former; for debian.org - the latter.
895 FILENAME, if non-`nil', is the name of file to store mbox. If
896 FILENAME is `nil', the downloaded mbox is inserted into the
898 (let (url (mt "") bn)
899 (unless (setq url (plist-get
900 (cdr (assoc debbugs-port debbugs-servers))
902 (error "URL of bugreport script for port %s is not specified"
904 (setq bn (format "bug=%s;" (number-to-string bug-number)))
905 (unless (eq mbox-type 'mboxfolder)
906 (if (memq mbox-type '(mboxmaint mboxstat mboxstatus))
907 (setq mt (concat (symbol-name mbox-type) "=yes;"))
908 (error "Unknown mbox type: %s" mbox-type)))
909 (setq url (concat url (format "?%s%smbox=yes" bn mt)))
911 (url-copy-file url filename t)
912 (url-insert-file-contents url))))
918 ;; * SOAP interface extensions (wishlist).
919 ;; - Server-side sorting.
920 ;; - Regexp and/or wildcards search.
921 ;; - Returning message attachments.
923 ;;; debbugs.el ends here