+ (if (= amount 1)
+ ;; We cache it as bug "0" in `debbugs-cache-data'.
+ (let ((status (gethash 0 debbugs-cache-data)))
+ (unless (and
+ status
+ (or
+ (null debbugs-cache-expiry)
+ (and
+ (natnump debbugs-cache-expiry)
+ (> (cdr (assoc 'cache_time status))
+ (- (float-time) debbugs-cache-expiry)))))
+ ;; Due to `debbugs-gnu-completion-table', this function
+ ;; could be called in rapid sequence. We cache temporarily
+ ;; the value nil, therefore.
+ (when (natnump debbugs-cache-expiry)
+ (puthash
+ 0
+ (list (cons 'cache_time (1+ (- (float-time) debbugs-cache-expiry)))
+ (list 'newest_bug))
+ debbugs-cache-data))
+ ;; Compute the value.
+ (setq
+ status
+ (list
+ (cons 'cache_time (float-time))
+ (cons 'newest_bug
+ (caar
+ (soap-invoke
+ debbugs-wsdl debbugs-port "newest_bugs" amount)))))
+
+ ;; Cache it.
+ (when (or (null debbugs-cache-expiry) (natnump debbugs-cache-expiry))
+ (puthash 0 status debbugs-cache-data)))
+
+ ;; Return the value, as list.
+ (list (cdr (assoc 'newest_bug status))))
+
+ (sort
+ (car (soap-invoke debbugs-wsdl debbugs-port "newest_bugs" amount)) '<)))
+
+(defun debbugs-convert-soap-value-to-string (string-value)
+ "If STRING-VALUE is unibyte, decode its contents as a UTF-8 string.
+If STRING-VALUE is a multibyte string, then `soap-client'
+received an xsd:string for this value, and will have decoded it
+already.
+
+If STRING-VALUE is a unibyte string, then `soap-client' received
+an xsd:base64Binary, and ran `base64-decode-string' on it to
+produce a unibyte string of bytes.
+
+For some reason, the Debbugs server code base64-encodes strings
+that contain UTF-8 characters, and returns them as
+xsd:base64Binary, instead of just returning them as xsd:string.
+Therefore, when STRING-VALUE is a unibyte string, we assume its
+bytes represent a UTF-8 string and decode them accordingly."
+ (if (stringp string-value)
+ (if (not (multibyte-string-p string-value))
+ (decode-coding-string string-value 'utf-8)
+ string-value)
+ (error "Invalid string value")))