]> code.delx.au - gnu-emacs-elpa/blob - packages/debbugs/debbugs.el
725a394f9b5b20edffb9c704f704047fd2c47c3f
[gnu-emacs-elpa] / packages / debbugs / debbugs.el
1 ;;; debbugs.el --- SOAP library to access debbugs servers
2
3 ;; Copyright (C) 2011-2014 Free Software Foundation, Inc.
4
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
6 ;; Keywords: comm, hypermedia
7 ;; Package: debbugs
8 ;; Version: 0.6
9
10 ;; This file is not part of GNU Emacs.
11
12 ;; This program is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
16
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24
25 ;;; Commentary:
26
27 ;; This package provides basic functions to access a Debbugs SOAP
28 ;; server (see <http://wiki.debian.org/DebbugsSoapInterface>).
29
30 ;; The function "get_versions" is not implemented (yet). "search_est"
31 ;; is an extension on <http://debbugs.gnu.org>.
32
33 ;;; Code:
34
35 ;(setq soap-debug t message-log-max t)
36 (require 'soap-client)
37 (eval-when-compile (require 'cl))
38
39 (defgroup debbugs nil
40 "Debbugs library"
41 :group 'hypermedia)
42
43 (defcustom debbugs-servers
44 '(("gnu.org"
45 :wsdl "http://debbugs.gnu.org/cgi/soap.cgi?WSDL"
46 :bugreport-url "http://debbugs.gnu.org/cgi/bugreport.cgi")
47 ("debian.org"
48 :wsdl "http://bugs.debian.org/cgi-bin/soap.cgi?WSDL"
49 :bugreport-url "http://bugs.debian.org/cgi-bin/bugreport.cgi"))
50 "*List of Debbugs server specifiers.
51 Each entry is a list that contains a string identifying the port
52 name and the server parameters in keyword-value form. Allowed
53 keywords are:
54
55 `:wsdl' -- Location of WSDL. The value is a string with URL that
56 should return the WSDL specification of Debbugs/SOAP service.
57
58 `:bugreport-url' -- URL of the server script that returns mboxes
59 with bug logs.
60
61 The list initially contains two predefined and configured Debbugs
62 servers: \"gnu.org\" and \"debian.org\"."
63 :group 'debbugs
64 :link '(custom-manual "(debbugs)Debbugs server specifiers")
65 :type '(choice
66 (const nil)
67 (repeat
68 (cons :tag "Server"
69 (string :tag "Port name")
70 (checklist :tag "Options" :greedy t
71 (group :inline t
72 (const :format "" :value :wsdl)
73 (string :tag "WSDL"))
74 (group :inline t
75 (const :format "" :value :bugreport-url)
76 (string :tag "Bugreport URL")))))))
77
78 (defcustom debbugs-port "gnu.org"
79 "The port instance to be applied from `debbugs-wsdl'.
80 This corresponds to the Debbugs server to be accessed, either
81 \"gnu.org\", or \"debian.org\", or user defined port name."
82 ;; Maybe we should create an own group?
83 :group 'debbugs
84 :type '(choice :tag "Debbugs server" (const "gnu.org") (const "debian.org")
85 (string :tag "user defined port name")))
86
87 ;; It would be nice if we could retrieve it from the debbugs server.
88 ;; Not supported yet.
89 (defconst debbugs-wsdl
90 (soap-load-wsdl
91 (expand-file-name
92 "Debbugs.wsdl"
93 (if load-in-progress
94 (file-name-directory load-file-name)
95 default-directory)))
96 "The WSDL object to be used describing the SOAP interface.")
97
98 (defun debbugs-get-bugs (&rest query)
99 "Return a list of bug numbers which match QUERY.
100
101 QUERY is a sequence of keyword-value pairs where the values are
102 strings, i.e. :KEYWORD \"VALUE\" [:KEYWORD \"VALUE\"]*
103
104 The keyword-value pair is a subquery. The keywords are allowed to
105 have multiple occurrence within the query at any place. The
106 subqueries with the same keyword form the logical subquery, which
107 returns the union of bugs of every subquery it contains.
108
109 The result of the QUERY is an intersection of results of all
110 subqueries.
111
112 Valid keywords are:
113
114 :package -- The value is the name of the package a bug belongs
115 to, like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\".
116
117 :src -- This is used to retrieve bugs that belong to source
118 with given name.
119
120 :severity -- This is the severity of the bug. The exact set of
121 allowed values depends on the Debbugs port. Examples are
122 \"normal\", \"minor\", \"wishlist\" etc.
123
124 :tag -- An arbitrary string the bug is annotated with.
125 Usually, this is used to mark the status of the bug, like
126 \"fixed\", \"moreinfo\", \"notabug\", \"patch\",
127 \"unreproducible\" or \"wontfix\". The exact set of tags
128 depends on the Debbugs port.
129
130 :owner -- This is used to identify bugs by the owner's email
131 address. The special email address \"me\" is used as pattern,
132 replaced with `user-mail-address'.
133
134 :submitter -- With this keyword it is possible to filter bugs
135 by the submitter's email address. The special email address
136 \"me\" is used as pattern, replaced with `user-mail-address'.
137
138 :maint -- This is used to find bugs of the packages which are
139 maintained by the person with the given email address. The
140 special email address \"me\" is used as pattern, replaced with
141 `user-mail-address'.
142
143 :correspondent -- This allows to find bug reports where the
144 person with the given email address has participated. The
145 special email address \"me\" is used as pattern, replaced with
146 `user-mail-address'.
147
148 :affects -- With this keyword it is possible to find bugs which
149 affect the package with the given name. The bugs are chosen by
150 the value of field `affects' in bug's status. The returned bugs
151 do not necessary belong to this package.
152
153 :status -- Status of bug. Valid values are \"done\",
154 \"forwarded\" and \"open\".
155
156 :archive -- A keyword to filter for bugs which are already
157 archived, or not. Valid values are \"0\" (not archived),
158 \"1\" (archived) or \"both\". If this keyword is not given in
159 the query, `:archive \"0\"' is assumed by default.
160
161 Example. Get all opened and forwarded release critical bugs for
162 the packages which are maintained by \"me\" and which have a
163 patch:
164
165 \(debbugs-get-bugs :maint \"me\" :tag \"patch\"
166 :severity \"critical\"
167 :status \"open\"
168 :severity \"grave\"
169 :status \"forwarded\"
170 :severity \"serious\")"
171
172 (let (vec kw key val)
173 ;; Check query.
174 (while (and (consp query) (<= 2 (length query)))
175 (setq kw (pop query)
176 val (pop query))
177 (unless (and (keywordp kw) (stringp val))
178 (error "Wrong query: %s %s" kw val))
179 (setq key (substring (symbol-name kw) 1))
180 (case kw
181 ((:package :severity :tag :src :affects)
182 ;; Value shall be one word.
183 (if (string-match "\\`\\S-+\\'" val)
184 (setq vec (vconcat vec (list key val)))
185 (error "Wrong %s: %s" key val)))
186 ((:owner :submitter :maint :correspondent)
187 ;; Value is an email address.
188 (if (string-match "\\`\\S-+\\'" val)
189 (progn
190 (when (string-equal "me" val)
191 (setq val user-mail-address))
192 (when (string-match "<\\(.+\\)>" val)
193 (setq val (match-string 1 val)))
194 (setq vec (vconcat vec (list key val))))
195 (error "Wrong %s: %s" key val)))
196 (:status
197 ;; Possible values: "done", "forwarded" and "open"
198 (if (string-match "\\`\\(done\\|forwarded\\|open\\)\\'" val)
199 (setq vec (vconcat vec (list key val)))
200 (error "Wrong %s: %s" key val)))
201 (:archive
202 ;; Value is `0' or `1' or `both'.
203 (if (string-match "\\`\\(0\\|1\\|both\\)\\'" val)
204 (setq vec (vconcat vec (list key val)))
205 (error "Wrong %s: %s" key val)))
206 (t (error "Unknown key: %s" kw))))
207
208 (unless (null query)
209 (error "Unknown key: %s" (car query)))
210 (sort (car (soap-invoke debbugs-wsdl debbugs-port "get_bugs" vec)) '<)))
211
212 (defun debbugs-newest-bugs (amount)
213 "Return the list of bug numbers, according to AMOUNT (a number) latest bugs."
214 (sort (car (soap-invoke debbugs-wsdl debbugs-port "newest_bugs" amount)) '<))
215
216 (defun debbugs-get-status (&rest bug-numbers)
217 "Return a list of status entries for the bugs identified by BUG-NUMBERS.
218
219 Every returned entry is an association list with the following attributes:
220
221 `bug_num': The bug number.
222
223 `package': A list of package names the bug belongs to.
224
225 `severity': The severity of the bug report. This can be
226 \"important\", \"grave\", \"normal\", \"minor\" or \"wishlist\".
227
228 `tags': The status of the bug report, a list of strings. This
229 can be \"fixed\", \"notabug\", \"wontfix\", \"unreproducible\",
230 \"moreinfo\" or \"patch\".
231
232 `pending': The string \"pending\", \"forwarded\" or \"done\".
233
234 `subject': Subject/Title of the bugreport.
235
236 `originator': Submitter of the bugreport.
237
238 `mergedwith': A list of bug numbers this bug was merged with.
239 If it is a single bug, then this attribute contains just a
240 number.
241
242 `source': Source package name of the bug report.
243
244 `date': Date of bug creation.
245
246 `log_modified', `last_modified': Date of last update.
247
248 `found_date', `fixed_date': Date of bug report / bug fix
249 \(empty for now).
250
251 `done': The email address of the worker who has closed the bug (if done).
252
253 `archived': `t' if the bug is archived, `nil' otherwise.
254
255 `unarchived': The date the bug has been unarchived, if ever.
256
257 `found_versions', `fixed_versions': List of version strings.
258
259 `forwarded': A URL or an email address.
260
261 `blocks': A list of bug numbers this bug blocks.
262
263 `blockedby': A list of bug numbers this bug is blocked by.
264
265 `msgid': The message id of the initial bug report.
266
267 `owner': Who is responsible for fixing.
268
269 `location': Always the string \"db-h\" or \"archive\".
270
271 `affects': A list of package names.
272
273 `summary': Arbitrary text.
274
275 Example:
276
277 \(debbugs-get-status 10)
278
279 => ;; Attributes with empty values are not shown
280 \(\(\(bug_num . 10)
281 \(source . \"unknown\")
282 \(date . 1203606305.0)
283 \(msgid . \"<87zltuz7eh.fsf@freemail.hu>\")
284 \(severity . \"wishlist\")
285 \(owner . \"Magnus Henoch <mange@freemail.hu>\")
286 \(log_modified . 1261079402.0)
287 \(location . \"db-h\")
288 \(subject . \"url-gw should support HTTP CONNECT proxies\")
289 \(originator . \"Magnus Henoch <mange@freemail.hu>\")
290 \(last_modified . 1271200046.0)
291 \(pending . \"pending\")
292 \(package \"emacs\")))"
293 (when bug-numbers
294 (let ((object
295 (car
296 (soap-invoke
297 debbugs-wsdl debbugs-port "get_status"
298 (apply 'vector bug-numbers)))))
299 (mapcar
300 (lambda (x)
301 (let (y)
302 ;; "archived" is the number 1 or 0.
303 (setq y (assoc 'archived (cdr (assoc 'value x))))
304 (setcdr y (= (cdr y) 1))
305 ;; "found_versions" and "fixed_versions" are lists,
306 ;; containing strings or numbers.
307 (dolist (attribute '(found_versions fixed_versions))
308 (setq y (assoc attribute (cdr (assoc 'value x))))
309 (setcdr y (mapcar
310 (lambda (z) (if (numberp z) (number-to-string z) z))
311 (cdr y))))
312 ;; "mergedwith" is a string, containing blank separated bug numbers.
313 (setq y (assoc 'mergedwith (cdr (assoc 'value x))))
314 (when (stringp (cdr y))
315 (setcdr y (mapcar 'string-to-number (split-string (cdr y) " " t))))
316 ;; "package" is a string, containing comma separated
317 ;; package names. "keywords" and "tags" are strings,
318 ;; containing blank separated package names.
319 (dolist (attribute '(package keywords tags))
320 (setq y (assoc attribute (cdr (assoc 'value x))))
321 (when (stringp (cdr y))
322 (setcdr y (split-string (cdr y) ",\\| " t))))
323 (cdr (assoc 'value x))))
324 object))))
325
326 (defun debbugs-get-usertag (&rest query)
327 "Return a list of bug numbers which match QUERY.
328
329 QUERY is a sequence of keyword-value pairs where the values are
330 strings, i.e. :KEYWORD \"VALUE\" [:KEYWORD \"VALUE\"]*
331
332 Valid keywords are:
333
334 :user -- The value is the name of the package a bug belongs to,
335 like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\". It can
336 also be an email address of a user who has applied a user tag.
337 The special email address \"me\" is used as pattern, replaced
338 with `user-mail-address'. There must be at least one such
339 entry; it is recommended to have exactly one.
340
341 :tag -- A string applied as user tag. Often, it is a
342 subproduct identification, like \"cedet\" or \"tramp\" for the
343 package \"emacs\".
344
345 If there is no :tag entry, no bug numbers will be returned but a list of
346 existing user tags for :user.
347
348 Example:
349
350 \(debbugs-get-usertag :user \"emacs\")
351
352 => (\"www\" \"solaris\" \"ls-lisp\" \"cygwin\")
353
354 \(debbugs-get-usertag :user \"emacs\" :tag \"www\" :tag \"cygwin\")
355
356 => (807 1223 5637)"
357
358 (let (user tags kw key val object result)
359 ;; Check query.
360 (while (and (consp query) (<= 2 (length query)))
361 (setq kw (pop query)
362 val (pop query))
363 (unless (and (keywordp kw) (stringp val))
364 (error "Wrong query: %s %s" kw val))
365 (setq key (substring (symbol-name kw) 1))
366 (case kw
367 ((:user)
368 ;; Value shall be one word. Extract email address, if existing.
369 (if (string-match "\\`\\S-+\\'" val)
370 (progn
371 (when (string-equal "me" val)
372 (setq val user-mail-address))
373 (when (string-match "<\\(.+\\)>" val)
374 (setq val (match-string 1 val)))
375 (pushnew val user :test #'equal))
376 (error "Wrong %s: %s" key val)))
377 ((:tag)
378 ;; Value shall be one word.
379 (if (string-match "\\`\\S-+\\'" val)
380 (pushnew val tags :test #'equal)
381 (error "Wrong %s: %s" key val)))
382 (t (error "Unknown key: %s" kw))))
383
384 (unless (null query)
385 (error "Unknown key: %s" (car query)))
386 (unless (= (length user) 1)
387 (error "There must be exactly one :user entry"))
388
389 (setq
390 object
391 (car (soap-invoke debbugs-wsdl debbugs-port "get_usertag" (car user))))
392
393 (if (null tags)
394 ;; Return the list of existing tags.
395 (mapcar (lambda (x) (symbol-name (car x))) object)
396
397 ;; Return bug numbers.
398 (dolist (elt object result)
399 (when (member (symbol-name (car elt)) tags)
400 (setq result (append (cdr elt) result)))))))
401
402 (defun debbugs-get-bug-log (bug-number)
403 "Return a list of messages related to BUG-NUMBER.
404
405 Every message is an association list with the following attributes:
406
407 `msg_num': The number of the message inside the bug log. The
408 numbers are ascending, newer messages have a higher number.
409
410 `header': The message header lines, as arrived at the bug tracker.
411
412 `body': The message body.
413
414 `attachments' A list of possible attachments, or `nil'. Not
415 implemented yet server side."
416 (car (soap-invoke debbugs-wsdl debbugs-port "get_bug_log" bug-number)))
417
418 (defun debbugs-search-est (&rest query)
419 "Return the result of a full text search according to QUERY.
420
421 QUERY is a sequence of lists of keyword-value pairs where the
422 values are strings or numbers, i.e. :KEYWORD \"VALUE\" [:KEYWORD
423 VALUE]*
424
425 Every sublist of the QUERY forms a hyperestraier condition. A
426 detailed description of hyperestraier conditions can be found at
427 URL `http://fallabs.com/hyperestraier/uguide-en.html#searchcond'.
428
429 The following conditions are possible:
430
431 \[:phrase SEARCH-PHRASE :skip NUMBER :max NUMBER\]
432
433 The string SEARCH-PHRASE forms the search on the database. It
434 contains words to be searched for, combined by operators like
435 AND, ANDNOT and OR. If there is no operator between the words,
436 AND is used by default. The phrase keyword and value can also
437 be omitted, this is useful in combination with other conditions.
438
439 :skip and :max are optional. They specify, how many hits are
440 skipped, and how many maximal hits are returned. This can be
441 used for paged results. Per default, :skip is 0 and :max is 10.
442
443 There must be exactly one such condition.
444
445 \[ATTRIBUTE VALUE+ :operation OPERATION :order ORDER\]
446
447 ATTRIBUTE is one of the following keywords:
448
449 :status -- Status of bug. Valid values are \"done\",
450 \"forwarded\" and \"open\".
451
452 :subject, :@title -- The subject of a message or the title of
453 the bug, a string.
454
455 :date, :@cdate -- The submission or modification dates of a
456 message, a number.
457
458 :submitter, :@author -- The email address of the submitter of a
459 bug or the author of a message belonging to this bug, a string.
460 The special email address \"me\" is used as pattern, replaced
461 with `user-mail-address'.
462
463 :package -- The value is the name of the package a bug belongs
464 to, like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\".
465
466 :tags -- An arbitrary string the bug is annotated with.
467
468 :severity -- This is the severity of the bug. The exact set of
469 allowed values depends on the Debbugs port. Examples are
470 \"normal\", \"minor\", \"wishlist\" etc.
471
472 :operator defines the comparison operator to be applied to
473 ATTRIBUTE. For string attributes this could be \"STREQ\" \(is
474 equal to the string), \"STRNE\" \(is not equal to the string),
475 \"STRINC\" \(includes the string), \"STRBW\" \(begins with the
476 string), \"STREW\" \(ends with the string), \"STRAND\"
477 \(includes all tokens in the string), \"STROR\" \(includes at
478 least one token in the string), \"STROREQ\" \(is equal to at
479 least one token in the string) or \"STRRX\" \(matches regular
480 expressions of the string). For operators with tokens, several
481 values for ATTRIBUTE shall be used.
482
483 Numbers can be compared by the operators \"NUMEQ\" \(is equal
484 to the number), \"NUMNE\" \(is not equal to the number),
485 \"NUMGT\" \(is greater than the number), \"NUMGE\" \(is greater
486 than or equal to the number), \"NUMLT\" \(is less than the
487 number), \"NUMLE\" \(is less than or equal to the number) or
488 \"NUMBT\" \(is between the two numbers). In the last case,
489 there must be two values for ATTRIBUTE.
490
491 If an operator is leaded by \"!\", the meaning is inverted. If
492 a string operator is leaded by \"I\", the case of the value is
493 ignored.
494
495 The optional :order can be specified only in one condition. It
496 means, that ATTRIBUTE is used for sorting the results. The
497 following order operators exist: \"STRA\" \(ascending by
498 string), \"STRD\" \(descending by string), \"NUMA\" \(ascending
499 by number) or \"NUMD\" \(descending by number).
500
501 A special case is an :order, where there is no corresponding
502 attribute value and no operator. In this case, ATTRIBUTE is
503 not used for the search.
504
505 The result of the QUERY is a list of association lists with the
506 same attributes as in the conditions. Additional attributes are
507
508 `id': The bug number.
509
510 `msg_num': The number of the message inside the bug log.
511
512 `snippet': The surrounding text found by the search. For the
513 syntax of the snippet, consult the hyperestraier user guide.
514
515 Examples:
516
517 \(debbugs-search-est
518 '\(:phrase \"armstrong AND debbugs\" :skip 10 :max 2)
519 '\(:severity \"normal\" :operator \"STRINC\")
520 '\(:date :order \"NUMA\"))
521
522 => \(\(\(msg_num . 21)
523 \(date . 1229208302)
524 \(@author . \"Glenn Morris <rgm@gnu.org>\")
525 \(@title . \"Re: bug#1567: Mailing an archived bug\")
526 \(id . 1567)
527 \(severity . \"normal\")
528 \(@cdate . \"Wed, 17 Dec 2008 14:34:50 -0500\")
529 \(snippet . \"...\")
530 \(subject . \"Mailing an archived bug\")
531 \(package . \"debbugs.gnu.org\"))
532 ...)
533
534 ;; Show all messages from me between 2011-08-01 and 2011-08-31.
535 \(debbugs-search-est
536 '\(:max 20)
537 '\(:@author \"me\" :operator \"ISTRINC\")
538 `\(:date
539 ,\(floor \(float-time \(encode-time 0 0 0 1 8 2011)))
540 ,\(floor \(float-time \(encode-time 0 0 0 31 8 2011)))
541 :operator \"NUMBT\"))"
542
543 (let (args result)
544 ;; Compile search arguments.
545 (dolist (elt query)
546 (let (vec kw key val
547 phrase-cond attr-cond)
548
549 ;; Phrase is mandatory, even if empty.
550 (when (and (or (member :skip elt) (member :max elt))
551 (not (member :phrase elt)))
552 (setq vec (vector "phrase" "")))
553
554 ;; Parse condition.
555 (while (consp elt)
556 (setq kw (pop elt))
557 (unless (keywordp kw)
558 (error "Wrong keyword: %s" kw))
559 (setq key (substring (symbol-name kw) 1))
560 (case kw
561 ;; Phrase condition.
562 (:phrase
563 ;; It shouldn't happen in an attribute condition.
564 (if attr-cond
565 (error "Wrong keyword: %s" kw))
566 (setq phrase-cond t val (pop elt))
567 ;; Value is a string.
568 (if (stringp val)
569 (setq vec (vconcat vec (list key val)))
570 (error "Wrong %s: %s" key val)))
571
572 ((:skip :max)
573 ;; It shouldn't happen in an attribute condition.
574 (if attr-cond
575 (error "Wrong keyword: %s" kw))
576 (setq phrase-cond t val (pop elt))
577 ;; Value is a number.
578 (if (numberp val)
579 (setq vec (vconcat vec (list key (number-to-string val))))
580 (error "Wrong %s: %s" key val)))
581
582 ;; Attribute condition.
583 ((:submitter :@author)
584 ;; It shouldn't happen in a phrase condition.
585 (if phrase-cond
586 (error "Wrong keyword: %s" kw))
587 (if (not (stringp (car elt)))
588 (setq vec (vconcat vec (list key "")))
589 ;; Value is an email address.
590 (while (and (stringp (car elt))
591 (string-match "\\`\\S-+\\'" (car elt)))
592 (when (string-equal "me" (car elt))
593 (setcar elt user-mail-address))
594 (when (string-match "<\\(.+\\)>" (car elt))
595 (setcar elt (match-string 1 (car elt))))
596 (let ((x (pop elt)))
597 (unless (member x val)
598 (setq val (append val (list x))))))
599 (setq vec
600 (vconcat vec (list key (mapconcat 'identity val " "))))))
601
602 (:status
603 ;; It shouldn't happen in a phrase condition.
604 (if phrase-cond
605 (error "Wrong keyword: %s" kw))
606 (setq attr-cond t)
607 (if (not (stringp (car elt)))
608 (setq vec (vconcat vec (list key "")))
609 ;; Possible values: "done", "forwarded" and "open"
610 (while (and (stringp (car elt))
611 (string-match
612 "\\`\\(done\\|forwarded\\|open\\)\\'" (car elt)))
613 (let ((x (pop elt)))
614 (unless (member x val)
615 (setq val (append val (list x))))))
616 (setq vec
617 (vconcat vec (list key (mapconcat 'identity val " "))))))
618
619 ((:subject :package :tags :severity :@title)
620 ;; It shouldn't happen in a phrase condition.
621 (if phrase-cond
622 (error "Wrong keyword: %s" kw))
623 (setq attr-cond t)
624 (if (not (stringp (car elt)))
625 (setq vec (vconcat vec (list key "")))
626 ;; Just a string.
627 (while (stringp (car elt))
628 (let ((x (pop elt)))
629 (unless (member x val)
630 (setq val (append val (list x))))))
631 (setq vec
632 (vconcat vec (list key (mapconcat 'identity val " "))))))
633
634 ((:date :@cdate)
635 ;; It shouldn't happen in a phrase condition.
636 (if phrase-cond
637 (error "Wrong keyword: %s" kw))
638 (setq attr-cond t)
639 (if (not (numberp (car elt)))
640 (setq vec (vconcat vec (list key "")))
641 ;; Just a number.
642 (while (numberp (car elt))
643 (let ((x (pop elt)))
644 (unless (member x val)
645 (setq val (append val (list x))))))
646 (setq vec
647 (vconcat
648 vec (list key (mapconcat 'number-to-string val " "))))))
649
650 ((:operator :order)
651 ;; It shouldn't happen in a phrase condition.
652 (if phrase-cond
653 (error "Wrong keyword: %s" kw))
654 (setq attr-cond t val (pop elt))
655 ;; Value is a number.
656 (if (stringp val)
657 (setq vec (vconcat vec (list key val)))
658 (error "Wrong %s: %s" key val)))
659
660 (t (error "Unknown key: %s" kw))))
661
662 (setq args (vconcat args (list vec)))))
663
664 (setq result
665 (car (soap-invoke debbugs-wsdl debbugs-port "search_est" args)))
666 ;; The result contains lists (key value). We transform it into
667 ;; cons cells (key . value).
668 (dolist (elt1 result result)
669 (dolist (elt2 elt1)
670 (setcdr elt2 (cadr elt2))))))
671
672 (defun debbugs-get-attribute (bug-or-message attribute)
673 "Return the value of key ATTRIBUTE.
674
675 BUG-OR-MESSAGE must be list element returned by either
676 `debbugs-get-status' or `debbugs-get-bug-log'.
677
678 Example: Return the originator of last submitted bug.
679
680 \(debbugs-get-attribute
681 \(car \(apply 'debbugs-get-status \(debbugs-newest-bugs 1))) 'originator)"
682 (cdr (assoc attribute bug-or-message)))
683
684 (defun debbugs-get-message-numbers (messages)
685 "Return the message numbers of MESSAGES.
686 MESSAGES must be the result of a `debbugs-get-bug-log' call."
687 (mapcar (lambda (x) (debbugs-get-attribute x 'msg_num)) messages))
688
689 (defun debbugs-get-message (messages message-number)
690 "Return the message MESSAGE-NUMBER of MESSAGES.
691 MESSAGES must be the result of a `debbugs-get-bug-log' call.
692
693 The returned message is a list of strings. The first element are
694 the header lines of the message, the second element is the body
695 of the message. Further elements of the list, if any, are
696 attachments of the message.
697
698 If there is no message with MESSAGE-NUMBER, the function returns `nil'.
699
700 Example: Return the first message of last submitted bug.
701
702 \(let \(\(messages \(apply 'debbugs-get-bug-log \(debbugs-newest-bugs 1))))
703 \(debbugs-get-message messages
704 \(car \(debbugs-get-message-numbers messages))))"
705 (while (and messages
706 (/= (debbugs-get-attribute (car messages) 'msg_num)
707 message-number))
708 (setq messages (cdr messages)))
709 (when messages
710 (append (list (debbugs-get-attribute (car messages) 'header)
711 (debbugs-get-attribute (car messages) 'body))
712 (debbugs-get-attribute (car messages) 'attachments))))
713
714 (defun debbugs-get-mbox (bug-number mbox-type &optional filename)
715 "Download mbox with messages of bug BUG-NUMBER from Debbugs server.
716 BUG-NUMBER is a number of bug. It must be of integer type.
717
718 MBOX-TYPE specifies a type of mbox and can be one of the
719 following symbols:
720
721 `mboxfolder': Download mbox folder.
722
723 `mboxmaint': Download maintainer's mbox.
724
725 `mboxstat', `mboxstatus': Download status mbox. The use of
726 either symbol depends on actual Debbugs server configuration.
727 For gnu.org, use the former; for debian.org - the latter.
728
729 FILENAME, if non-`nil', is the name of file to store mbox. If
730 FILENAME is `nil', the downloaded mbox is inserted into the
731 current buffer."
732 (let (url (mt "") bn)
733 (unless (setq url (plist-get
734 (cdr (assoc debbugs-port debbugs-servers))
735 :bugreport-url))
736 (error "URL of bugreport script for port %s is not specified"
737 debbugs-port))
738 (setq bn (format "bug=%s;" (number-to-string bug-number)))
739 (unless (eq mbox-type 'mboxfolder)
740 (if (memq mbox-type '(mboxmaint mboxstat mboxstatus))
741 (setq mt (concat (symbol-name mbox-type) "=yes;"))
742 (error "Unknown mbox type: %s" mbox-type)))
743 (setq url (concat url (format "?%s%smbox=yes" bn mt)))
744 (if filename
745 (url-copy-file url filename t)
746 (url-insert-file-contents url))))
747
748 (provide 'debbugs)
749
750 ;;; TODO:
751
752 ;; * SOAP interface extensions (wishlist).
753 ;; - Server-side sorting.
754 ;; - Regexp and/or wildcards search.
755 ;; - Returning message attachments.
756
757 ;;; debbugs.el ends here