1 ;;; gnus-picon.el --- displaying pretty icons in Gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Wes Hardaker <hardaker@ece.ucdavis.edu>
5 ;; Keywords: news xpm annotation glyph faces
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
30 (require 'annotations)
38 "Show pictures of people, domains, and newsgroups (XEmacs).
39 For this to work, you must add gnus-group-display-picons to the
40 gnus-summary-display-hook or to the gnus-article-display-hook
41 depending on what gnus-picons-display-where is set to. You must
42 also add gnus-article-display-picons to gnus-article-display-hook."
45 (defcustom gnus-picons-display-where 'picons
46 "Where to display the group and article icons.
47 Legal values are `article' and `picons'."
48 :type '(choice symbol string)
51 (defcustom gnus-picons-has-modeline-p t
52 "*Whether the picons window should have a modeline.
53 This is only useful if `gnus-picons-display-where' is `picons'."
57 (defcustom gnus-picons-database "/usr/local/faces"
58 "*Defines the location of the faces database.
59 For information on obtaining this database of pretty pictures, please
60 see http://www.cs.indiana.edu/picons/ftp/index.html"
64 (defcustom gnus-picons-news-directories '("news")
65 "*List of directories to search for newsgroups faces."
66 :type '(repeat string)
68 (define-obsolete-variable-alias 'gnus-picons-news-directory
69 'gnus-picons-news-directories)
71 (defcustom gnus-picons-user-directories '("local" "users" "usenix" "misc")
72 "*List of directories to search for user faces."
73 :type '(repeat string)
76 (defcustom gnus-picons-domain-directories '("domains")
77 "*List of directories to search for domain faces.
78 Some people may want to add \"unknown\" to this list."
79 :type '(repeat string)
82 (defcustom gnus-picons-refresh-before-display nil
83 "*If non-nil, display the article buffer before computing the picons."
87 (defcustom gnus-picons-group-excluded-groups nil
88 "*If this regexp matches the group name, group picons will be disabled."
92 (defcustom gnus-picons-x-face-file-name
93 (format "/tmp/picon-xface.%s.xbm" (user-login-name))
94 "*The name of the file in which to store the converted X-face header."
98 (defcustom gnus-picons-convert-x-face (format "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | pbmtoxbm > %s" gnus-picons-x-face-file-name)
99 "*Command to convert the x-face header into a xbm file."
103 (defcustom gnus-picons-display-as-address t
104 "*If t display textual email addresses along with pictures."
108 (defcustom gnus-picons-file-suffixes
110 (let ((types (list "xbm")))
111 (when (featurep 'gif)
113 (when (featurep 'xpm)
116 "*List of suffixes on picon file names to try."
117 :type '(repeat string)
120 (defcustom gnus-picons-display-article-move-p nil
121 "*Whether to move point to first empty line when displaying picons.
122 This has only an effect if `gnus-picons-display-where' has value `article'."
126 (defcustom gnus-picons-clear-cache-on-shutdown t
127 "*Whether to clear the picons cache when exiting gnus.
128 Gnus caches every picons it finds while it is running. This saves
129 some time in the search process but eats some memory. If this
130 variable is set to nil, Gnus will never clear the cache itself; you
131 will have to manually call `gnus-picons-clear-cache' to clear it.
132 Otherwise the cache will be cleared every time you exit Gnus."
136 (defcustom gnus-picons-piconsearch-url nil
137 "*The url to query for picons. Setting this to nil will disable it.
138 The only publicly available address currently known is
139 http://www.cs.indiana.edu:800/piconsearch. If you know of any other,
140 please tell me so that we can list it."
141 :type '(choice (const :tag "Disable" :value nil)
142 (const :tag "www.cs.indiana.edu"
143 :value "http://www.cs.indiana.edu:800/piconsearch")
147 (defface gnus-picons-xbm-face '((t (:foreground "black" :background "white")))
148 "Face to show xbm picons in."
151 (defcustom gnus-picons-setup-hook nil
152 "Hook run in Picons buffers."
156 ;;; Internal variables:
158 (defvar gnus-picons-processes-alist nil
159 "Picons processes currently running and their environment.")
160 (defvar gnus-picons-glyph-alist nil
161 "Picons glyphs cache.
162 List of pairs (KEY . GLYPH) where KEY is either a filename or an URL.")
163 (defvar gnus-picons-url-alist nil
164 "Picons file names cache.
165 List of pairs (KEY . NAME) where KEY is (USER HOST DBS) and NAME is an URL.")
167 (defvar gnus-picons-jobs-alist nil
168 "List of jobs that still need be done.
169 This is a list of (SYM-ANN TAG ARGS...) where SYM-ANN three annotations list,
170 TAG is one of `picon' or `search' indicating that the job should query a
171 picon or do a search for picons file names, and ARGS is some additionnal
172 arguments necessary for the job.")
174 (defvar gnus-picons-job-already-running nil
175 "Lock to ensure only one stream of http requests is running.")
179 (defun gnus-picons-remove-all ()
180 "Removes all picons from the Gnus display(s)."
182 (map-extents (function (lambda (ext unused) (delete-annotation ext) nil))
183 nil nil nil nil nil 'gnus-picon)
184 (setq gnus-picons-jobs-alist '())
185 ;; notify running job that it may have been preempted
186 (if (and (listp gnus-picons-job-already-running)
187 gnus-picons-job-already-running)
188 (setq gnus-picons-job-already-running t)))
190 (defun gnus-get-buffer-name (variable)
191 "Returns the buffer name associated with the contents of a variable."
192 (let ((buf (gnus-get-buffer-create
193 (gnus-window-to-buffer-helper
194 (cdr (assq variable gnus-window-to-buffer))))))
198 (defun gnus-picons-buffer-name ()
199 (cond ((or (stringp gnus-picons-display-where)
200 (bufferp gnus-picons-display-where))
201 gnus-picons-display-where)
202 ((eq gnus-picons-display-where 'picons)
203 (if gnus-single-article-buffer
205 (concat "*Picons " gnus-newsgroup-name "*")))
207 (gnus-get-buffer-name gnus-picons-display-where))))
209 (defun gnus-picons-kill-buffer ()
210 (let ((buf (get-buffer (gnus-picons-buffer-name))))
211 (when (buffer-live-p buf)
214 (defun gnus-picons-setup-buffer ()
215 (let ((name (gnus-picons-buffer-name)))
217 (if (get-buffer name)
219 (set-buffer (gnus-get-buffer-create name))
220 (buffer-disable-undo)
221 (setq buffer-read-only t)
222 (run-hooks 'gnus-picons-setup-hook)
223 (add-hook 'gnus-summary-prepare-exit-hook 'gnus-picons-kill-buffer))
226 (defun gnus-picons-set-buffer ()
227 (set-buffer (gnus-picons-setup-buffer))
228 (goto-char (point-min))
229 (if (and (eq gnus-picons-display-where 'article)
230 gnus-picons-display-article-move-p)
231 (if (search-forward "\n\n" nil t)
233 (goto-char (point-max)))
234 (setq buffer-read-only t)
235 (unless gnus-picons-has-modeline-p
236 (set-specifier has-modeline-p
237 (list (list (current-buffer)
238 (cons nil gnus-picons-has-modeline-p)))))))
240 (defun gnus-picons-prepare-for-annotations ()
241 "Prepare picons buffer for putting annotations."
242 ;; let drawing catch up
243 (when gnus-picons-refresh-before-display
245 (gnus-picons-set-buffer)
246 (gnus-picons-remove-all))
248 (defun gnus-picons-make-annotation (&rest args)
249 (let ((annot (apply 'make-annotation args)))
250 (set-extent-property annot 'gnus-picon t)
251 (set-extent-property annot 'duplicable t)
254 (defun gnus-picons-article-display-x-face ()
255 "Display the x-face header bitmap in the 'gnus-picons-display-where buffer."
256 (let ((gnus-article-x-face-command 'gnus-picons-display-x-face))
257 (gnus-article-display-x-face)))
259 (defun gnus-picons-x-face-sentinel (process event)
260 (when (memq process gnus-picons-processes-alist)
261 (setq gnus-picons-processes-alist
262 (delq process gnus-picons-processes-alist))
263 (gnus-picons-set-buffer)
264 (gnus-picons-make-annotation (make-glyph gnus-picons-x-face-file-name)
266 (when (file-exists-p gnus-picons-x-face-file-name)
267 (delete-file gnus-picons-x-face-file-name))))
269 (defun gnus-picons-display-x-face (beg end)
270 "Function to display the x-face header in the picons window.
271 To use: (setq gnus-article-x-face-command 'gnus-picons-display-x-face)"
273 (if (featurep 'xface)
274 ;; Use builtin support
276 ;; Don't remove this binding, it is really needed: when
277 ;; `gnus-picons-set-buffer' changes buffer (like when it is
278 ;; set to display picons outside of the article buffer), BEG
279 ;; and END still refer the buffer current now !
280 (let ((buf (current-buffer)))
281 (gnus-picons-set-buffer)
282 (gnus-picons-make-annotation
284 :data (concat "X-Face: " (buffer-substring beg end buf)))
285 nil 'text nil nil nil t)))
286 ;; convert the x-face header to a .xbm file
287 (let* ((process-connection-type nil)
288 (process (start-process-shell-command "gnus-x-face" nil
289 gnus-picons-convert-x-face)))
290 (push process gnus-picons-processes-alist)
291 (process-kill-without-query process)
292 (set-process-sentinel process 'gnus-picons-x-face-sentinel)
293 (process-send-region process beg end)
294 (process-send-eof process))))
296 (defun gnus-article-display-picons ()
297 "Display faces for an author and her domain in gnus-picons-display-where."
300 (when (and (featurep 'xpm)
301 (or (not (fboundp 'device-type)) (equal (device-type) 'x))
302 (setq from (mail-fetch-field "from"))
303 (setq from (downcase (or (cadr
304 (funcall gnus-extract-address-components
307 (or (setq at-idx (string-match "@" from))
308 (setq at-idx (length from))))
310 (let ((username (downcase (substring from 0 at-idx)))
311 (addrs (if (eq at-idx (length from))
312 (if gnus-local-domain
313 (message-tokenize-header gnus-local-domain "."))
314 (message-tokenize-header (substring from (1+ at-idx))
316 (gnus-picons-prepare-for-annotations)
317 (gnus-group-display-picons)
318 (unless gnus-picons-display-article-move-p
320 (let ((buffer-read-only nil))
321 (when (re-search-forward "^From: " nil t)
322 (narrow-to-region (point) (gnus-point-at-eol))
323 (when (search-forward from nil t)
324 (gnus-put-text-property
325 (match-beginning 0) (match-end 0)
327 (if (null gnus-picons-piconsearch-url)
329 (gnus-picons-display-pairs (gnus-picons-lookup-pairs
331 gnus-picons-domain-directories)
332 gnus-picons-display-as-address
334 (if (and gnus-picons-display-as-address addrs)
335 (gnus-picons-make-annotation
336 [string :data "@"] nil 'text nil nil nil t))
337 (gnus-picons-display-picon-or-name
338 (gnus-picons-lookup-user username addrs)
340 (push (list 'gnus-article-annotations 'search username addrs
341 gnus-picons-domain-directories t)
342 gnus-picons-jobs-alist)
343 (gnus-picons-next-job)))))))
345 (defun gnus-group-display-picons ()
346 "Display icons for the group in the `gnus-picons-display-where' buffer."
348 (when (and (featurep 'xpm)
349 (or (not (fboundp 'device-type)) (equal (device-type) 'x))
350 (or (null gnus-picons-group-excluded-groups)
351 (not (string-match gnus-picons-group-excluded-groups
352 gnus-newsgroup-name))))
353 (let* ((newsgroups (mail-fetch-field "newsgroups"))
355 (if (or gnus-picons-display-article-move-p
356 (not newsgroups))(mail-fetch-field "newsgroups")
357 (list (gnus-group-real-name gnus-newsgroup-name))
358 (split-string newsgroups ",")))
361 (gnus-picons-prepare-for-annotations)
362 (while (setq group (pop groups))
363 (unless gnus-picons-display-article-move-p
365 (let ((buffer-read-only nil))
366 (goto-char (point-min))
367 (when (re-search-forward "^Newsgroups:" nil t)
368 (narrow-to-region (point) (gnus-point-at-eol))
369 (when (search-forward group nil t)
370 (gnus-put-text-property
371 (match-beginning 0) (match-end 0)
373 (if (null gnus-picons-piconsearch-url)
374 (gnus-picons-display-pairs
375 (gnus-picons-lookup-pairs
376 (reverse (split-string group "\\."))
377 gnus-picons-news-directories)
379 (push (list 'gnus-group-annotations 'search nil
380 (split-string group "\\.")
381 (if (listp gnus-picons-news-directories)
382 gnus-picons-news-directories
383 (list gnus-picons-news-directories))
385 gnus-picons-jobs-alist)
386 (gnus-picons-next-job))
388 (add-hook 'gnus-summary-exit-hook 'gnus-picons-remove-all))))))
390 (defun gnus-picons-lookup-internal (addrs dir)
391 (setq dir (expand-file-name dir gnus-picons-database))
392 (gnus-picons-try-face (dolist (part (reverse addrs) dir)
393 (setq dir (expand-file-name part dir)))))
395 (defun gnus-picons-lookup (addrs dirs)
396 "Lookup the picon for ADDRS in databases DIRS.
397 Returns the picon filename or NIL if none found."
399 (while (and dirs (null result))
400 (setq result (gnus-picons-lookup-internal addrs (pop dirs))))
403 (defun gnus-picons-lookup-user-internal (user domains)
404 (let ((dirs gnus-picons-user-directories)
405 domains-tmp dir picon)
406 (while (and dirs (null picon))
407 (setq domains-tmp domains
409 (while (and domains-tmp
410 (null (setq picon (gnus-picons-lookup-internal
411 (cons user domains-tmp) dir))))
413 ;; Also make a try in MISC subdir
415 (setq picon (gnus-picons-lookup-internal (list user "MISC") dir))))
418 (defun gnus-picons-lookup-user (user domains)
419 "Lookup the picon for USER at DOMAINS.
420 USER is a string containing a name.
421 DOMAINS is a list of strings from the fully qualified domain name."
422 (or (gnus-picons-lookup-user-internal user domains)
423 (gnus-picons-lookup-user-internal "unknown" domains)))
425 (defun gnus-picons-lookup-pairs (domains directories)
426 "Lookup picons for DOMAINS and all its parents in DIRECTORIES.
427 Returns a list of PAIRS whose CAR is the picon filename or NIL if
428 none, and whose CDR is the corresponding element of DOMAINS."
430 (setq directories (if (listp directories)
434 (push (list (gnus-picons-lookup (cons "unknown" domains) directories)
439 (defun gnus-picons-display-picon-or-name (picon name &optional right-p)
440 (cond (picon (gnus-picons-display-glyph picon name right-p))
441 (gnus-picons-display-as-address (list (gnus-picons-make-annotation
442 (vector 'string :data name)
444 nil nil nil right-p)))))
446 (defun gnus-picons-display-pairs (pairs &optional bar-p dot-p right-p)
447 "Display picons in list PAIRS."
448 (let ((domain-p (and gnus-picons-display-as-address dot-p))
450 (when (and bar-p domain-p right-p
451 gnus-picons-display-article-move-p)
452 (setq picons (gnus-picons-display-glyph
453 (let ((gnus-picons-file-suffixes '("xbm")))
454 (gnus-picons-try-face
455 gnus-xmas-glyph-directory "bar."))
457 (while (setq pair (pop pairs))
458 (setq picons (nconc picons
459 (gnus-picons-display-picon-or-name
460 (car pair) (cadr pair) right-p)
461 (if (and domain-p pairs)
462 (list (gnus-picons-make-annotation
463 (vector 'string :data dot-p)
464 nil 'text nil nil nil right-p))))))
467 (defun gnus-picons-try-face (dir &optional filebase)
468 (let* ((dir (file-name-as-directory dir))
469 (filebase (or filebase "face."))
470 (key (concat dir filebase))
471 (glyph (cdr (assoc key gnus-picons-glyph-alist)))
472 (suffixes gnus-picons-file-suffixes)
474 (while (setq suf (pop suffixes))
475 (when (file-exists-p (setq f (expand-file-name
476 (concat filebase suf)
479 glyph (make-glyph f))
480 (when (equal suf "xbm")
481 (set-glyph-face glyph 'gnus-picons-xbm-face))
482 (push (cons key glyph) gnus-picons-glyph-alist)))
485 (defun gnus-picons-display-glyph (glyph &optional part rightp)
486 (set-glyph-baseline glyph 70)
487 (let ((new (gnus-picons-make-annotation
488 glyph (point) 'text nil nil nil rightp)))
489 (when (and part gnus-picons-display-as-address)
491 new (cons new (make-glyph (vector 'string :data part))))
492 (set-annotation-action new 'gnus-picons-action-toggle))
495 (if (and (eq major-mode 'gnus-article-mode)
496 (not gnus-picons-display-as-address)
498 (list (gnus-picons-make-annotation [string :data " "] (point)
499 'text nil nil nil rightp))))))
501 (defun gnus-picons-action-toggle (data)
504 (let* ((annot (car data))
505 (glyph (annotation-glyph annot)))
506 (set-annotation-glyph annot (cdr data))
507 (set-annotation-data annot (cons annot glyph))))
509 (defun gnus-picons-clear-cache ()
510 "Clear the picons cache."
512 (setq gnus-picons-glyph-alist nil
513 gnus-picons-url-alist nil))
515 (gnus-add-shutdown 'gnus-picons-close 'gnus)
517 (defun gnus-picons-close ()
518 "Shut down the picons."
519 (if gnus-picons-clear-cache-on-shutdown
520 (gnus-picons-clear-cache)))
522 ;;; Query a remote DB. This requires some stuff from w3 !
527 (require 'w3-forms)))
529 (defun gnus-picons-url-retrieve (url fn arg)
530 (let ((old-asynch (default-value 'url-be-asynchronous))
531 (url-working-buffer (generate-new-buffer " *picons*"))
532 (url-package-name "Gnus")
533 (url-package-version gnus-version-number)
535 (setq-default url-be-asynchronous t)
537 (set-buffer url-working-buffer)
538 (setq url-be-asynchronous t
539 url-current-callback-data arg
540 url-current-callback-func fn)
541 (url-retrieve url t))
542 (setq-default url-be-asynchronous old-asynch)))
544 (defun gnus-picons-make-glyph (type)
545 "Make a TYPE glyph using current buffer as data. Handles xbm nicely."
546 (cond ((null type) nil)
547 ((eq type 'xbm) (let ((fname (make-temp-name "/tmp/picon")))
548 (write-region (point-min) (point-max) fname
550 (prog1 (make-glyph (vector 'xbm :file fname))
551 (delete-file fname))))
552 (t (make-glyph (vector type :data (buffer-string))))))
554 ;;; Parsing of piconsearch result page.
557 ;; 1 - each value field has the form: "<strong>key</strong> = <kbd>value</kbd>"
558 ;; 2 - a "<p>" separates the keywords from the results
559 ;; 3 - every results begins by the path within the database at the beginning
560 ;; of the line in raw text.
561 ;; 3b - and the href following it is the preferred image type.
563 ;; if 1 or 2 is not met, it will probably cause an error. The other
564 ;; will go undetected
566 (defun gnus-picons-parse-value (name)
567 (goto-char (point-min))
568 (re-search-forward (concat "<strong>"
570 "</strong> *= *<kbd> *\\([^ <][^<]*\\) *</kbd>"))
571 (buffer-substring (match-beginning 1) (match-end 1)))
573 (defun gnus-picons-parse-filenames ()
574 ;; returns an alist of ((USER ADDRS DB) . URL)
575 (let* ((case-fold-search t)
576 (user (gnus-picons-parse-value "user"))
577 (host (gnus-picons-parse-value "host"))
578 (dbs (message-tokenize-header (gnus-picons-parse-value "db") " "))
582 "^\\(" (mapconcat 'identity dbs "\\|") "\\)/"
584 "\\(\\(" (replace-in-string host "\\." "/\\|" t) "/\\|MISC/\\)*\\)"
586 "\\(" (regexp-quote user) "\\|unknown\\)/"
588 cur-db cur-host cur-user types res)
589 ;; now point will be somewhere in the header. Find beginning of
591 (re-search-forward "<p>[ \t\n]*")
592 (while (re-search-forward start-re nil t)
593 (setq cur-db (buffer-substring (match-beginning 1) (match-end 1))
594 cur-host (buffer-substring (match-beginning 2) (match-end 2))
595 cur-user (buffer-substring (match-beginning 4) (match-end 4))
596 cur-host (nreverse (message-tokenize-header cur-host "/")))
597 ;; XXX - KLUDGE: there is a blank picon in news/MISC/unknown
598 (unless (and (string-equal cur-db "news")
599 (string-equal cur-user "unknown")
600 (equal cur-host '("MISC")))
601 ;; ok now we have found an entry (USER HOST DB), find the
602 ;; corresponding picon URL
604 ;; restrict region to this entry
605 (narrow-to-region (point) (search-forward "<br>"))
606 (goto-char (point-min))
607 (setq types gnus-picons-file-suffixes)
609 (not (re-search-forward
610 (concat "<a[ \t\n]+href=\"\\([^\"]*\\."
611 (regexp-quote (car types)) "\\)\"")
614 (push (cons (list cur-user cur-host cur-db)
615 (buffer-substring (match-beginning 1) (match-end 1)))
619 ;;; picon network display functions :
621 (defun gnus-picons-network-display-internal (sym-ann glyph part right-p)
622 (gnus-picons-set-buffer)
623 (gnus-picons-display-picon-or-name glyph part right-p)
624 (gnus-picons-next-job-internal))
626 (defun gnus-picons-network-display-callback (url part sym-ann right-p)
627 (let ((glyph (gnus-picons-make-glyph (cdr (assoc url-current-mime-type
628 w3-image-mappings)))))
629 (kill-buffer (current-buffer))
630 (push (cons url glyph) gnus-picons-glyph-alist)
631 ;; only do the job if it has not been preempted.
632 (if (equal gnus-picons-job-already-running
633 (list sym-ann 'picon url part right-p))
634 (gnus-picons-network-display-internal sym-ann glyph part right-p)
635 (gnus-picons-next-job-internal))))
637 (defun gnus-picons-network-display (url part sym-ann right-p)
638 (let ((cache (assoc url gnus-picons-glyph-alist)))
639 (if (or cache (null url))
640 (gnus-picons-network-display-internal sym-ann (cdr cache) part right-p)
641 (gnus-picons-url-retrieve url 'gnus-picons-network-display-callback
642 (list url part sym-ann right-p)))))
644 ;;; search job functions
646 (defun gnus-picons-network-search-internal (user addrs dbs sym-ann right-p
648 (let (curkey dom pfx url dbs-tmp cache new-jobs)
649 ;; First do the domain search
650 (dolist (part (if right-p
653 (setq pfx (nconc (list part) pfx)
654 dom (cond ((and dom right-p) (concat part "." dom))
655 (dom (concat dom "." part))
657 curkey (list "unknown" dom dbs))
658 (when (null (setq cache (assoc curkey gnus-picons-url-alist)))
659 ;; This one is not yet in the cache, create a new entry
660 ;; Search for an entry
663 (while (and dbs-tmp (null url))
664 (setq url (or (cdr (assoc (list "unknown" pfx (car dbs-tmp)) fnames))
666 ;; This is the first component. Try the
667 ;; catch-all MISC component
668 (cdr (assoc (list "unknown"
673 (push (setq cache (cons curkey url)) gnus-picons-url-alist))
674 ;; Put this glyph in the job list
675 (if (and (not (eq dom part)) gnus-picons-display-as-address)
676 (push (list sym-ann "." right-p) new-jobs))
677 (push (list sym-ann 'picon (cdr cache) part right-p) new-jobs))
678 ;; next, the user search
680 (setq curkey (list user dom gnus-picons-user-directories))
681 (if (null (setq cache (assoc curkey gnus-picons-url-alist)))
682 (let ((users (list user "unknown"))
683 dirs usr domains-tmp dir picon)
684 (while (and users (null picon))
685 (setq dirs gnus-picons-user-directories
687 (while (and dirs (null picon))
688 (setq domains-tmp addrs
690 (while (and domains-tmp
691 (null (setq picon (assoc (list usr domains-tmp dir)
695 (setq picon (assoc (list usr '("MISC") dir) fnames)))))
696 (push (setq cache (cons curkey (cdr picon)))
697 gnus-picons-url-alist)))
698 (if (and gnus-picons-display-as-address new-jobs)
699 (push (list sym-ann "@" right-p) new-jobs))
700 (push (list sym-ann 'picon (cdr cache) user right-p) new-jobs))
701 (if (and gnus-picons-display-as-address (not right-p))
702 (push (list sym-ann 'bar right-p) new-jobs))
703 ;; only put the jobs in the queue if this job has not been preempted.
704 (if (equal gnus-picons-job-already-running
705 (list sym-ann 'search user addrs dbs right-p))
706 (setq gnus-picons-jobs-alist
707 (nconc (if (and gnus-picons-display-as-address right-p)
708 (list (list sym-ann 'bar right-p)))
710 gnus-picons-jobs-alist)))
711 (gnus-picons-next-job-internal)))
713 (defun gnus-picons-network-search-callback (user addrs dbs sym-ann right-p)
714 (gnus-picons-network-search-internal user addrs dbs sym-ann right-p
715 (prog1 (gnus-picons-parse-filenames)
716 (kill-buffer (current-buffer)))))
718 ;; Initiate a query on the picon database
719 (defun gnus-picons-network-search (user addrs dbs sym-ann right-p)
720 (let* ((host (mapconcat 'identity addrs "."))
721 (key (list (or user "unknown") host (if user
722 gnus-picons-user-directories
724 (cache (assoc key gnus-picons-url-alist)))
726 (gnus-picons-url-retrieve
727 (concat gnus-picons-piconsearch-url
728 "?user=" (w3-form-encode-xwfu (or user "unknown"))
729 "&host=" (w3-form-encode-xwfu host)
730 "&db=" (mapconcat 'w3-form-encode-xwfu
733 gnus-picons-user-directories)
736 'gnus-picons-network-search-callback
737 (list user addrs dbs sym-ann right-p))
738 (gnus-picons-network-search-internal user addrs dbs sym-ann right-p))))
740 ;;; Main jobs dispatcher function
742 (defun gnus-picons-next-job-internal ()
743 (when (setq gnus-picons-job-already-running (pop gnus-picons-jobs-alist))
744 (let* ((job gnus-picons-job-already-running)
749 ((stringp tag);; (SYM-ANN "..." RIGHT-P)
750 (gnus-picons-network-display-internal
751 sym-ann nil tag (pop job)))
753 (gnus-picons-network-display-internal
755 (let ((gnus-picons-file-suffixes '("xbm")))
756 (gnus-picons-try-face
757 gnus-xmas-glyph-directory "bar."))
759 ((eq 'search tag);; (SYM-ANN 'search USER ADDRS DBS RIGHT-P)
760 (gnus-picons-network-search
761 (pop job) (pop job) (pop job) sym-ann (pop job)))
762 ((eq 'picon tag);; (SYM-ANN 'picon URL PART RIGHT-P)
763 (gnus-picons-network-display
764 (pop job) (pop job) sym-ann (pop job)))
766 (setq gnus-picons-job-already-running nil)
767 (error "Unknown picon job tag %s" tag)))))))
769 (defun gnus-picons-next-job ()
770 "Start processing the job queue if it is not in progress."
771 (unless gnus-picons-job-already-running
772 (gnus-picons-next-job-internal)))
774 (provide 'gnus-picon)
776 ;;; gnus-picon.el ends here