aux-items.el 29.5 KB
Newer Older
David Byers's avatar
David Byers committed
1
;;;;; -*-coding: iso-8859-1;-*-
2
3
;;;;;
;;;;; $Id$
4
;;;;; Copyright (C) 1991-2002  Lysator Academic Computer Association.
5
;;;;;
6
;;;;; This file is part of the LysKOM Emacs LISP client.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
;;;;; 
;;;;; LysKOM is free software; you can redistribute it and/or modify it
;;;;; under the terms of the GNU General Public License as published by 
;;;;; the Free Software Foundation; either version 2, or (at your option) 
;;;;; any later version.
;;;;; 
;;;;; LysKOM is distributed in the hope that it will be useful, but WITHOUT
;;;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;;;;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
;;;;; for more details.
;;;;; 
;;;;; You should have received a copy of the GNU General Public License
;;;;; along with LysKOM; see the file COPYING.  If not, write to
;;;;; Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
;;;;; or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
;;;;; MA 02139, USA.
;;;;;
;;;;; Please mail bug reports to bug-lyskom@lysator.liu.se. 
;;;;;
;;;; ================================================================
;;;; ================================================================
;;;;
;;;; File: aux-items.el
;;;;
;;;; Implementation of aux-item specific stuff.
;;;; Hopefulle more of this will be made more general in the future.
;;;;

(setq lyskom-clientversion-long 
      (concat lyskom-clientversion-long
	      "$Id$\n"))

(def-kom-var lyskom-aux-item-definitions nil
  "List of aux item definitions.")

(defmacro def-aux-item (name number &rest data)
  (` (setq lyskom-aux-item-definitions 
           (add-to-list 'lyskom-aux-item-definitions
                        (cons (, number)
                              (cons (cons 'name (quote (, name)))
                                    (quote (, data))))))))

(defun lyskom-aux-item-definition->name (def)
  (cdr (assq 'name def)))

(defun lyskom-aux-item-definition->number (def)
  (car def))


56
57
58
(defun lyskom-aux-item-try-call (item method default &rest args)
  (when (lyskom-aux-item-p item)
    (setq item (lyskom-find-aux-item-definition item)))
59
  (cond ((listp method)
60
61
         (let ((result nil)
               (found nil))
62
           (while method
63
             (when (lyskom-aux-item-definition-field item (car method))
64
               (setq result
65
                     (apply (lyskom-aux-item-definition-field item
66
                                                              (car method))
67
68
69
                            args)
                     found t
                     method nil))
70
             (setq method (cdr method)))
71
72
73
74
75
           (if found result default)))
        (t (if (lyskom-aux-item-definition-field item method)
             (apply (lyskom-aux-item-definition-field item method) args)
             default))))

David Byers's avatar
David Byers committed
76
77
78
79
80
(defun lyskom-aux-item-has-call (item method)
  "Return non-nil if aux-item ITEM has a defined method METHOD"
  (when (lyskom-aux-item-p item)
    (setq item (lyskom-find-aux-item-definition item)))
  (lyskom-aux-item-definition-field item method))
81
82
83

(defun lyskom-aux-item-call (def method &rest args)
  (apply 'lyskom-aux-item-try-call def method nil args))
84
85
86


(defun lyskom-aux-item-definition-field (def method)
87
  (when (lyskom-aux-item-p def)
88
89
90
91
92
93
94
    (setq def (lyskom-find-aux-item-definition def)))
  (cdr (assq method def)))


(defun lyskom-find-aux-item-definition (aux)
  (assq (aux-item->tag aux) lyskom-aux-item-definitions))

95
96
97
98
99
100
101
102
103
104
105
(defun lyskom-match-aux-items (item-list predicate)
  "Return a list of all aux-items in ITEM-LIST that match PREDICATE.
PREDICATE should receives a single aux-item as its argument and should
return non-nil if the item is to be included in the list."
  (let ((result nil))
    (while item-list
      (when (funcall predicate (car item-list))
        (setq result (cons (car item-list) result)))
      (setq item-list (cdr item-list)))
    (nreverse result)))

106
107
108
109
110
111
(defun lyskom-get-aux-item (item-list tag)
  "Return all aux-items in ITEM-LIST with tag TAG."
  (lyskom-match-aux-items item-list
                          (lambda (el) (eq (aux-item->tag el) tag))))


112
113
(defun lyskom-aux-item-terminating-button (item obj)
  (if obj
114
115
116
117
118
119
120
121
122
123
124
125
       (lyskom-format 
        " %#1@%[[*]%]" 
        (lyskom-default-button 
         'aux 
         (cond ((lyskom-text-stat-p obj) (list 'text
                                               (text-stat->text-no obj)
                                               (aux-item->aux-no item)))
               ((lyskom-conf-stat-p obj) (list 'conf
                                               (conf-stat->conf-no obj)
                                               (aux-item->aux-no item)))
               ((eq obj 'server) (list 'server nil (aux-item->aux-no item)))
               (t item))))
126
127
     ""))

128
129
130
131
132
133
134
(defun lyskom-aux-item-after-parse (item)
  (lyskom-aux-item-try-call item 'decode-data nil)
  item)

(defun lyskom-aux-item-output-data (item)
  (lyskom-aux-item-try-call item 
                            'encode-data
135
136
                            (aux-item->data item)
			    item))
137

138
139
140
141
142
(defun lyskom-aux-item-modify-list (item-list deleted added)
  "Return a copy of ITEM-LIST with items in DELETED removed and items
in ADDED added."
  (let ((new-nos (nconc (mapcar 'aux-item->aux-no deleted)
                        (mapcar 'aux-item->aux-no added))))
143
    (nconc (lyskom-filter-list (lambda (el) (not (memq (aux-item->aux-no el) new-nos)))
144
145
146
                        item-list)
           added)))

David Byers's avatar
David Byers committed
147
148
149
150
151
152
153
154
155
156
157
158
159
(defun lyskom-aux-item-validate (data &rest tests)
  "Validata aux-item data.
DATA is data to validate. TESTS are the tests to use.
A test can be a function or a regular expression to match.
Invalid tests are silently ignored."
  (not (lyskom-traverse test tests
         (condition-case nil
             (unless
                 (cond ((stringp test) (string-match test data))
                       ((functionp test) (funcall test data)))
               (lyskom-traverse-break t))
           (error (lyskom-traverse-break t))))))

160

161
162
163
;;; ======================================================================

(def-aux-item content-type 1
David Byers's avatar
David Byers committed
164
  (text-name aux-content-type-name)
165
  (parse . lyskom-parse-content-type)
David Byers's avatar
David Byers committed
166
  (text-print . lyskom-print-content-type)
167
168
169
  (info  . lyskom-aux-item-info))

(def-aux-item fast-reply 2
David Byers's avatar
David Byers committed
170
  (text-name aux-fast-reply-name)
171
  (parse . nil)
172
  (parse-data . lyskom-aux-item-decode-data)
173
  (encode-data . lyskom-aux-item-encode-data)
174
175
176
  (info . lyskom-aux-item-info))

(def-aux-item cross-reference 3
David Byers's avatar
David Byers committed
177
  (text-name aux-cross-reference-name)
David Byers's avatar
David Byers committed
178
179
  (status-print . lyskom-status-print-cross-reference)
  (text-print-when . comment)
180
  (parse . lyskom-parse-cross-reference)
181
  (parse-data . lyskom-aux-item-decode-data)
182
  (encode-data . lyskom-aux-item-encode-data)
David Byers's avatar
David Byers committed
183
  (text-print . lyskom-print-cross-reference)
184
185
186
187
  (edit-insert . lyskom-edit-insert-cross-reference)
  (info  . lyskom-aux-item-info))

(def-aux-item no-comments 4
David Byers's avatar
David Byers committed
188
  (text-name aux-no-comments-name)
David Byers's avatar
David Byers committed
189
  (text-print-when . footer)
190
  (parse . lyskom-parse-no-comments)
David Byers's avatar
David Byers committed
191
  (text-print . lyskom-print-no-comments)
192
193
194
195
  (edit-insert . lyskom-edit-insert-no-comments)
  (info  . lyskom-aux-item-info))

(def-aux-item personal-comment 5
David Byers's avatar
David Byers committed
196
  (text-name aux-personal-comment-name)
David Byers's avatar
David Byers committed
197
  (text-print-when . footer)
198
  (parse . lyskom-parse-personal-comments)
David Byers's avatar
David Byers committed
199
  (text-print . lyskom-print-personal-comments)
200
201
202
203
  (edit-insert . lyskom-edit-insert-personal-comments)
  (info  . lyskom-aux-item-info))

(def-aux-item request-confirmation 6
David Byers's avatar
David Byers committed
204
  (text-name aux-request-confirmation-name)
David Byers's avatar
David Byers committed
205
  (text-print-when . header)
206
  (parse . lyskom-parse-request-confirmation)
David Byers's avatar
David Byers committed
207
  (text-print . lyskom-print-request-confirmation)
208
209
210
211
212
  (edit-insert . lyskom-edit-insert-request-confirmation)
  (info  . lyskom-aux-item-info)
  (read-action . lyskom-request-confirmation-action))

(def-aux-item read-confirm 7
David Byers's avatar
David Byers committed
213
  (text-name aux-read-confirm-name)
David Byers's avatar
David Byers committed
214
215
  (text-print-when . header)
  (text-print . lyskom-print-read-confirm)
216
217
218
  (info  . lyskom-aux-item-info))

(def-aux-item redirect 8
David Byers's avatar
David Byers committed
219
  (text-name aux-redirect-name)
220
221
222
223
  (print . lyskom-print-redirect)
  (info  . lyskom-aux-item-info))

(def-aux-item x-face 9
David Byers's avatar
David Byers committed
224
  (text-name aux-x-face-name)
225
226
227
228
  (print . lyskom-print-xface)
  (info  . lyskom-aux-item-info))

(def-aux-item alternate-name 10
David Byers's avatar
David Byers committed
229
  (text-name aux-alternate-name-name)
David Byers's avatar
David Byers committed
230
231
  (text-print-when . header)
  (text-print . lyskom-print-alternate-name)
232
  (encode-data . lyskom-aux-item-encode-data)
233
  (parse-data . lyskom-aux-item-decode-data)
234
235
236
  (info  . lyskom-aux-item-info))

(def-aux-item pgp-signature 11
David Byers's avatar
David Byers committed
237
  (text-name aux-pgp-signature-name)
238
239
240
  (info  . lyskom-aux-item-info))

(def-aux-item pgp-public-key 12
David Byers's avatar
David Byers committed
241
  (text-name aux-pgp-public-key-name)
242
243
244
  (info  . lyskom-aux-item-info))

(def-aux-item e-mail-address 13
David Byers's avatar
David Byers committed
245
  (text-name aux-e-mail-address-name)
246
247
  (info  . lyskom-aux-item-info))

David Byers's avatar
David Byers committed
248
(def-aux-item faq-text 14
David Byers's avatar
David Byers committed
249
  (text-name aux-faq-text-name)
David Byers's avatar
David Byers committed
250
  (info . lyskom-aux-item-info)
251
  (text-header-line . (faq-in-text faq-in-text-by))
David Byers's avatar
David Byers committed
252
253
254
  (status-print . lyskom-status-print-faq-text))

(def-aux-item creating-software 15
David Byers's avatar
David Byers committed
255
  (text-name aux-creating-software-name)
David Byers's avatar
David Byers committed
256
257
  (info . lyskom-aux-item-info)
  (text-print-when . header)
258
  (parse-data . lyskom-aux-item-decode-data)
259
  (encode-data . lyskom-aux-item-encode-data)
David Byers's avatar
David Byers committed
260
261
262
  (text-print . lyskom-print-creating-software))

(def-aux-item mx-author 16
David Byers's avatar
David Byers committed
263
  (text-name aux-mx-author-name)
David Byers's avatar
David Byers committed
264
265
266
  (info . lyskom-aux-item-info))

(def-aux-item mx-from 17
David Byers's avatar
David Byers committed
267
  (text-name aux-mx-from-name)
David Byers's avatar
David Byers committed
268
269
270
  (info . lyskom-aux-item-info))

(def-aux-item mx-reply-to 18
David Byers's avatar
David Byers committed
271
  (text-name aux-mx-reply-to-name)
David Byers's avatar
David Byers committed
272
273
274
  (info . lyskom-aux-item-info))

(def-aux-item mx-to 19
David Byers's avatar
David Byers committed
275
  (text-name aux-mx-to-name)
David Byers's avatar
David Byers committed
276
277
278
  (info . lyskom-aux-item-info))

(def-aux-item mx-cc 20
David Byers's avatar
David Byers committed
279
  (text-name aux-mx-cc-name)
David Byers's avatar
David Byers committed
280
281
282
  (info . lyskom-aux-item-info))

(def-aux-item mx-date 21
David Byers's avatar
David Byers committed
283
  (text-name aux-mx-date-name)
David Byers's avatar
David Byers committed
284
285
286
  (info . lyskom-aux-item-info))

(def-aux-item mx-message-id 22
David Byers's avatar
David Byers committed
287
  (text-name aux-mx-message-id-name)
David Byers's avatar
David Byers committed
288
289
290
  (info . lyskom-aux-item-info))

(def-aux-item mx-in-reply-to 23
David Byers's avatar
David Byers committed
291
  (text-name aux-mx-in-reply-to-name)
David Byers's avatar
David Byers committed
292
293
294
  (info . lyskom-aux-item-info))

(def-aux-item mx-misc 24
David Byers's avatar
David Byers committed
295
  (text-name aux-mx-misc-name)
David Byers's avatar
David Byers committed
296
297
298
  (info . lyskom-aux-item-info))

(def-aux-item mx-allow-filter 25
David Byers's avatar
David Byers committed
299
  (text-name aux-mx-allow-filter-name)
David Byers's avatar
David Byers committed
300
301
302
  (info . lyskom-aux-item-info))

(def-aux-item mx-reject-forward 26
David Byers's avatar
David Byers committed
303
  (text-name aux-mx-reject-forward-name)
David Byers's avatar
David Byers committed
304
305
306
  (info . lyskom-aux-item-info))

(def-aux-item notify-comments 27
David Byers's avatar
David Byers committed
307
  (text-name aux-notify-comments-name)
David Byers's avatar
David Byers committed
308
309
310
  (info . lyskom-aux-item-info))

(def-aux-item faq-for-conf 28
David Byers's avatar
David Byers committed
311
  (text-name aux-faq-for-conf-name)
David Byers's avatar
David Byers committed
312
313
  (text-print . lyskom-print-faq-for-conf)
  (text-print-when . header)
David Byers's avatar
David Byers committed
314
315
316
  (info . lyskom-aux-item-info)
  (read-action . lyskom-faq-for-conf-action))

David Byers's avatar
David Byers committed
317

318
(def-aux-item recommended-conf 29
David Byers's avatar
David Byers committed
319
  (text-name aux-recommended-conf-name)
320
  (status-print . lyskom-print-recommended-conf)
321
322
323
  (info . lyskom-aux-item-info))

(def-aux-item allowed-content-type 30
David Byers's avatar
David Byers committed
324
  (text-name aux-allowed-content-type-name)
325
326
  (info . lyskom-aux-item-info))

327
(def-aux-item canonical-name 31
David Byers's avatar
David Byers committed
328
  (text-name aux-canonical-name-name)
329
330
331
  (info . lyskom-aux-item-info))

(def-aux-item mx-list-name 32
David Byers's avatar
David Byers committed
332
  (text-name aux-mx-list-name-name)
333
334
335
336
  (info . lyskom-aux-item-info)
  (status-print . lyskom-print-mx-list-name))

(def-aux-item send-comments-to 33
David Byers's avatar
David Byers committed
337
  (text-name aux-send-comments-to-name)
338
  (info . lyskom-aux-item-info)
339
340
341
  (status-print . lyskom-print-send-comments-to))

(def-aux-item world-readable 34
David Byers's avatar
David Byers committed
342
  (text-name aux-world-readable-name)
343
344
345
346
347
348
  (info . lyskom-aux-item-info)
  (text-print . lyskom-print-world-readable)
  (parse . lyskom-parse-world-readable)
  (edit-insert . lyskom-edit-insert-world-readable)
  (text-print-when . header))

349
350
351
352
353
(def-aux-item mx-refuse-import 35
  (text-name aux-mx-refuse-import)
  (info . lyskom-aux-item-info)
  (status-print . lyskom-print-mx-refuse-import))

David Byers's avatar
David Byers committed
354
(def-aux-item elisp-client-read-faq 10000
David Byers's avatar
David Byers committed
355
  (text-name aux-elisp-client-read-faq-name)
David Byers's avatar
David Byers committed
356
357
  (info . lyskom-aux-item-info)
  (status-print . lyskom-print-elisp-client-read-faq))
358

359
(def-aux-item elisp-client-rejected-invitation 10001
David Byers's avatar
David Byers committed
360
  (text-name aux-elisp-client-rejected-invitation-name)
361
362
363
  (info . lyskom-aux-item-info)
  (status-print . lyskom-print-elisp-client-rejected-invitation))

David Byers's avatar
   
David Byers committed
364
365
(def-aux-item elisp-client-enriched-headers 10002)

366
367
368
369
370

;;; ================================================================



371
372
373
(defun lyskom-aux-item-decode-data (item)
  (set-aux-item->data 
   item
374
   (lyskom-decode-coding-string (aux-item->data item) lyskom-server-coding-system)))
375
376

(defun lyskom-aux-item-encode-data (item)
377
  (lyskom-encode-coding-string (aux-item->data item) lyskom-server-coding-system)
378
379
380
  )


381
382
383
384
385
386
387
388
389
390
(defun lyskom-aux-item-info (item header)
  (let ((def (lyskom-find-aux-item-definition item)))
    
    (concat 
     (lyskom-get-string 'aux-item-for)
     header
     "\n"
     (lyskom-format
      'aux-item-info
      (aux-item->aux-no item)
David Byers's avatar
David Byers committed
391
      (aux-item->tag item)
392
393
394
395
      (if def
          (lyskom-aux-item-definition->name def)
        "unknown")
      (aux-item->creator item)
396
      (lyskom-format-time 'date-and-time (aux-item->sent-at item))
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
      (if (aux-item-flags->deleted (aux-item->flags item))
          (format "(%s)" (lyskom-get-string 'deleted))
        "")
      (mapconcat 'identity
                 (delq nil
                       (list
                        (and (aux-item-flags->secret (aux-item->flags item))
                             (lyskom-get-string 'secret))
                        (and (aux-item-flags->anonymous (aux-item->flags item))
                             (lyskom-get-string 'hide-creator))
                        (and (aux-item-flags->inherit (aux-item->flags item))
                             (lyskom-get-string 'inherit))))
                 ", ")
      (cond ((not (aux-item-flags->inherit (aux-item->flags item)))
             (lyskom-get-string 'no-inheritance))
            ((zerop (aux-item->inherit-limit item))
             (lyskom-get-string 'unlimited-inherit))
            ((eq 1  (aux-item->inherit-limit item))
             (lyskom-get-string 'no-more-inherit))
            (t (lyskom-format 'inherit-steps
                              (1- (aux-item->inherit-limit item)))))
      (aux-item->data item)))))

                 

(defun lyskom-print-content-type (item &optional obj)
  (concat (lyskom-format 'content-type-aux (aux-item->data item))
          (lyskom-aux-item-terminating-button item obj)))

(defun lyskom-parse-content-type ()
  (and (looking-at (lyskom-get-string 'content-type-regexp))
       (match-string 1)))

(defun lyskom-parse-cross-reference ()
  (or (and (looking-at (lyskom-get-string 'cross-reference-text-regexp))
           (concat "T" (match-string 1)))
      (and (looking-at (lyskom-get-string 'cross-reference-conf-regexp))
           (concat "C" (match-string 1)))
      (and (looking-at (lyskom-get-string 'cross-reference-pers-regexp))
           (concat "P" (match-string 1)))))

David Byers's avatar
David Byers committed
438
(defun lyskom-edit-insert-cross-reference (item pers)
439
440
441
  (concat
   (lyskom-print-cross-reference item nil pers)
   (lyskom-edit-generate-aux-item-flags (aux-item->flags item))))
442
443
444
445
446
447

(defun lyskom-print-cross-reference (item &optional obj pers)
  (let ((pers (if (and (zerop (aux-item->creator item))
                       pers)
                  pers
                (aux-item->creator item))))
David Byers's avatar
David Byers committed
448
449
450
451

    ;; We use string-to-int here since we handle floats in 
    ;; lyskom-format.

452
453
454
    (concat
     (cond ((string-match "^P\\([0-9]+\\)" (aux-item->data item))
            (lyskom-format 'cross-reference-pers-aux 
455
                           (lyskom-string-to-number 
456
457
458
459
460
                            (match-string 1 (aux-item->data item)))
                           pers
                           ))
           ((string-match "^C\\([0-9]+\\)" (aux-item->data item))
            (lyskom-format 'cross-reference-conf-aux 
461
                           (lyskom-string-to-number 
462
463
464
465
466
                            (match-string 1 (aux-item->data item)))
                           pers
                           ))
           ((string-match "^T\\([0-9]+\\)" (aux-item->data item))
            (lyskom-format 'cross-reference-text-aux 
467
                           (lyskom-string-to-number 
468
469
470
471
472
473
474
475
476
477
                            (match-string 1 (aux-item->data item)))
                           pers
                           ))
           (t (lyskom-format 'strange-cross-reference 
                             (aux-item->data item)
                             pers
                             )))
     (lyskom-aux-item-terminating-button item obj)
     )))

David Byers's avatar
David Byers committed
478
(defun lyskom-status-print-cross-reference (item &optional obj pers)
David Byers's avatar
David Byers committed
479
480
  ;; We use string-to-int here since we handle floats in 
  ;; lyskom-format.
David Byers's avatar
David Byers committed
481
482
483
484
  (lyskom-insert 
   (concat
    (cond ((string-match "^P\\([0-9]+\\)" (aux-item->data item))
           (lyskom-format 'cross-reference-pers-status-aux 
485
                          (lyskom-string-to-number 
David Byers's avatar
David Byers committed
486
487
488
489
490
                           (match-string 1 (aux-item->data item)))
                          (aux-item->creator pers)
                          ))
          ((string-match "^C\\([0-9]+\\)" (aux-item->data item))
           (lyskom-format 'cross-reference-conf-status-aux 
491
                          (lyskom-string-to-number 
David Byers's avatar
David Byers committed
492
493
494
495
496
                           (match-string 1 (aux-item->data item)))
                          pers
                          ))
          ((string-match "^T\\([0-9]+\\)" (aux-item->data item))
           (lyskom-format 'cross-reference-text-status-aux 
497
                          (lyskom-string-to-number 
David Byers's avatar
David Byers committed
498
499
500
501
502
503
504
505
506
507
                           (match-string 1 (aux-item->data item)))
                          (aux-item->creator pers)
                          ))
          (t (lyskom-format 'strange-cross-reference-status 
                            (aux-item->data item)
                            (aux-item->creator pers)
                            )))
    (lyskom-aux-item-terminating-button item obj)
    "\n")))  

508
509
510
511
512
513
514
515
516
(defun lyskom-parse-no-comments ()
  (and (looking-at (lyskom-get-string 'no-comments-regexp))
       ""))

(defun lyskom-print-no-comments (item &optional obj)
  (concat (lyskom-format 'no-comments-aux)
          (lyskom-aux-item-terminating-button item obj)))

(defun lyskom-edit-insert-no-comments (item &optional obj)
517
518
519
  (concat
   (lyskom-format 'no-comments-edit-aux)
   (lyskom-edit-generate-aux-item-flags (aux-item->flags item))))
520
521
522
523
524
525
526
527
528
529

(defun lyskom-parse-personal-comments ()
  (and (looking-at (lyskom-get-string 'personal-comment-regexp))
       ""))

(defun lyskom-print-personal-comments (item &optional obj)
  (concat (lyskom-format 'personal-comment-aux)
          (lyskom-aux-item-terminating-button item obj)))

(defun lyskom-edit-insert-personal-comments (item &optional obj)
530
531
532
  (concat
   (lyskom-format 'personal-comment-edit-aux)
   (lyskom-edit-generate-aux-item-flags (aux-item->flags item))))
533
534
535
536
537
538

(defun lyskom-parse-request-confirmation ()
  (and (looking-at (lyskom-get-string 'request-confirmation-regexp))
       ""))

(defun lyskom-print-request-confirmation (item &optional obj)
539
540
  (concat (lyskom-format 'request-confirmation-aux
                         (aux-item->creator item))
541
542
543
          (lyskom-aux-item-terminating-button item obj)))

(defun lyskom-edit-insert-request-confirmation (item &optional obj)
544
545
546
  (concat
   (lyskom-format 'request-confirmation-edit-aux)
   (lyskom-edit-generate-aux-item-flags (aux-item->flags item))))
547

David Byers's avatar
David Byers committed
548
549
550
(defun lyskom-faq-for-conf-action (text-stat)
  (let ((faqs (text-stat-find-aux text-stat 28)))
    (lyskom-traverse aux faqs
David Byers's avatar
David Byers committed
551
552
553
554
555
      (condition-case nil
          (lyskom-register-read-faq (lyskom-string-to-int
                                     (aux-item->data aux) t)
                                    (text-stat->text-no text-stat))
       (lyskom-integer-conversion-error nil)))))
David Byers's avatar
David Byers committed
556

557
558
559
560
561
562
563
564
(defun lyskom-request-confirmation-action (text-stat)
  (let ((confirmations (text-stat-find-aux text-stat 7))
        (have-confirmation nil))
    (while confirmations
      (when (eq lyskom-pers-no (aux-item->creator (car confirmations)))
        (setq have-confirmation t)
        (setq confirmations nil))
      (setq confirmations (cdr confirmations)))
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
    (when  (not have-confirmation)
      (lyskom-scroll)
      (when (lyskom-j-or-n-p
             (lyskom-format (lyskom-get-string 'confirm-read-q)
                            text-stat))
        (let ((item (lyskom-create-aux-item 0 7 lyskom-pers-no
                                            nil 
                                            (lyskom-create-aux-item-flags
                                             nil nil nil nil nil nil nil nil)
                                            0 "")))
          (initiate-modify-text-info 'background
                                     nil
                                     (text-stat->text-no text-stat)
                                     nil
                                     (list item))
          (cache-del-text-stat (text-stat->text-no text-stat)))))))
581
582
583
584
585

(defun lyskom-print-read-confirm (item &optional obj)
  (concat 
   (lyskom-format 'read-confirm-aux
                  (aux-item->creator item)
586
                  (lyskom-format-time 'date-and-time (aux-item->sent-at item)))
587
588
589
590
591
   (lyskom-aux-item-terminating-button item obj)))



(defun lyskom-print-redirect (item &optional obj)
David Byers's avatar
David Byers committed
592
593
  ;; We use string-to-int here since we handle floats in 
  ;; lyskom-format.
594
595
596
597
598
599
  (concat
   (cond ((string-match "^E-mail:\\(.*\\)$" (aux-item->data item))
          (lyskom-format 'redirect-email-aux 
                         (match-string 1 (aux-item->data item))))
         ((string-match "^LysKOM:\\(.*\\)$" (aux-item->data item))
          (lyskom-format 'redirect-lyskom-aux 
600
                         (lyskom-string-to-number 
601
602
603
604
605
606
                          (match-string 1 (aux-item->data item))))))
   (lyskom-aux-item-terminating-button item obj)))   


(defun lyskom-print-xface (item &optional obj)
  (lyskom-xemacs-or-gnu
607
608
   (lyskom-maybe-add-face-to-string item
                                    (make-string 0 ?X))
609
610
   nil))

611
612
613
614
(defun lyskom-maybe-add-face-to-string (item string)
  (lyskom-xemacs-or-gnu
   (if (null item)
       string
David Byers's avatar
David Byers committed
615
     (setq item (car item))
616
     (unless (lyskom-find-face 'kom-xface)
617
       (make-face 'kom-xface))
618
     (let* ((h (concat "X-Face: " (aux-item->data item)))
619
            (g (intern h lyskom-xface-cache))
David Byers's avatar
David Byers committed
620
            (e (make-extent 0 (length string) string)))
621
622
623
       (if (boundp g)
           (setq g (symbol-value g))
         (set g (make-glyph
David Byers's avatar
David Byers committed
624
625
626
627
                 (list
                  (list 'global (cons '(tty) [nothing]))
                  (list 'global (cons '(win) 
                                      (vector 'xface ':data h))))))
628
629
630
         (setq g (symbol-value g))
         (set-glyph-face g 'kom-xface))
       (set-extent-begin-glyph e g)
David Byers's avatar
David Byers committed
631
632
633
634
       (set-extent-property e 'end-open nil)
       (set-extent-property e 'start-open nil)
       (set-extent-property e 'duplicable t)
       string))
635
636
637
   string))


638
(defun lyskom-print-alternate-name (item &optional obj)
David Byers's avatar
David Byers committed
639
  (concat "[" (aux-item->data item) "] "
640
641
          (lyskom-aux-item-terminating-button item obj)))

David Byers's avatar
David Byers committed
642
(defun lyskom-print-faq-format-subject (text text-stat text-no)
David Byers's avatar
David Byers committed
643
644
645
646
647
648
  (if (and text text-stat)
      (concat "\""
	      (cond ((string-match "\n" (text->decoded-text-mass text text-stat))
		     (substring (text->decoded-text-mass text text-stat) 0 (match-beginning 0)))
		    (t ""))
	      "\"")
649
    (lyskom-format 'no-such-text-m text-no)))
David Byers's avatar
David Byers committed
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666

(defun lyskom-deferred-print-faq (text-stat defer-info)
  (if text-stat
      (initiate-get-text 
       'deferred 
       (lambda (text text-stat defer-info)
         (lyskom-replace-deferred defer-info 
                                  (lyskom-format "%#1r" 
                                                 (lyskom-print-faq-format-subject text
                                                                                  text-stat
                                                                                  (defer-info->data defer-info)))))
       (text-stat->text-no text-stat)
       text-stat
       defer-info)
    (lyskom-replace-deferred defer-info
                             (lyskom-print-faq-format-subject nil nil (defer-info->data defer-info)))))

David Byers's avatar
David Byers committed
667
(defun lyskom-status-print-faq-text (item &optional obj)
David Byers's avatar
David Byers committed
668
  (if (lyskom-aux-item-validate (aux-item->data item) 'lyskom-string-to-int)
669
      (let* ((text-no (lyskom-string-to-number (aux-item->data item)))
David Byers's avatar
David Byers committed
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
             (subject (if kom-deferred-printing
                          (lyskom-create-defer-info 'get-text-stat
                                                    text-no
                                                    'lyskom-deferred-print-faq
                                                    nil nil nil
                                                    text-no)
                        (blocking-do-multiple ((text (get-text text-no))
                                               (text-stat (get-text-stat text-no)))
                          (lyskom-print-faq-format-subject text text-stat text-no)))))
        (lyskom-format-insert 'faq-in-text-aux 
                              text-no
                              subject)
        (lyskom-insert (lyskom-aux-item-terminating-button item obj)))
    (lyskom-format-insert 'bad-faq-in-text-aux
                          (aux-item->data item)
                          `(face ,kom-warning-face)
                          (lyskom-aux-item-terminating-button item obj)))
  (lyskom-insert "\n"))
David Byers's avatar
David Byers committed
688
689

(defun lyskom-print-faq-for-conf (item &optional obj)
David Byers's avatar
David Byers committed
690
  (if (lyskom-aux-item-validate (aux-item->data item) 'lyskom-string-to-int)
691
      (let ((conf-no (lyskom-string-to-number (aux-item->data item))))
David Byers's avatar
David Byers committed
692
693
694
695
696
697
698
699
        (concat 
         (cond ((zerop conf-no) (lyskom-get-string 'faq-for-server-aux))
               (t (lyskom-format 'faq-for-conf-aux conf-no)))
         (lyskom-aux-item-terminating-button item obj)))
    (lyskom-format 'bad-faq-for-conf-aux 
                   (aux-item->data item)
                   `(face ,kom-warning-face)
                   (lyskom-aux-item-terminating-button item obj))))
David Byers's avatar
David Byers committed
700
701

(defun lyskom-print-creating-software (item &optional obj)
702
  (when (or kom-show-creating-software
David Byers's avatar
David Byers committed
703
            (lyskom-viewing-noconversion))
704
705
706
    (concat
     (lyskom-format 'creating-software-aux (aux-item->data item))
     (lyskom-aux-item-terminating-button item obj))))
David Byers's avatar
David Byers committed
707

David Byers's avatar
David Byers committed
708
(defun lyskom-print-send-comments-to (item &optional obj)
David Byers's avatar
David Byers committed
709
  (if (lyskom-aux-item-validate (aux-item->data item) 'lyskom-string-to-int)
710
      (let ((conf-no (lyskom-string-to-number (aux-item->data item))))
David Byers's avatar
David Byers committed
711
712
713
714
715
716
717
        (lyskom-format-insert 'status-send-comments-to
                              conf-no 
                              (lyskom-aux-item-terminating-button item obj)))
    (lyskom-format-insert 'bad-status-send-comments-to
                          (aux-item->data item)
                          `(face ,kom-warning-face)
                          (lyskom-aux-item-terminating-button item obj))))
David Byers's avatar
David Byers committed
718
719
720



721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
(defun lyskom-parse-world-readable ()
  (and (looking-at (regexp-quote 
                    (lyskom-get-string 'world-readable-text-edit-aux)))
       ""))

(defun lyskom-edit-insert-world-readable (item &optional obj)
  (concat
   (lyskom-format 'world-readable-text-edit-aux)
   (lyskom-edit-generate-aux-item-flags (aux-item->flags item))))

(defun lyskom-print-world-readable (item &optional obj)
  (concat (lyskom-format 'world-readable-text-aux)
          (lyskom-aux-item-terminating-button item obj)))

(defun lyskom-print-mx-list-name (item &optional obj)
  (lyskom-format-insert 'conf-mx-list-name 
                        (aux-item->data item)
                        (lyskom-aux-item-terminating-button item obj)))

740
741
742
743
744
745
746
(defun lyskom-print-mx-refuse-import (item &optional obj)
  (let* ((sym (intern (format "mx-refuse-import-%s" (aux-item->data item))))
         (s (or (lyskom-try-get-string sym 'lyskom-message)
                (format "'%s'" (aux-item->data item)))))
    (lyskom-format-insert 'conf-mx-refuse-import s
                          (lyskom-aux-item-terminating-button item obj))))

747
(defun lyskom-print-recommended-conf (item &optional obj)
David Byers's avatar
David Byers committed
748
  (if (lyskom-aux-item-validate (aux-item->data item) 'lyskom-string-to-int)
749
      (let ((conf-no (lyskom-string-to-number (aux-item->data item))))
David Byers's avatar
David Byers committed
750
751
752
753
754
755
        (lyskom-format-insert 'recommended-conf-aux
                              conf-no
                              (lyskom-aux-item-terminating-button item obj)))
    (lyskom-format-insert 'bad-recommended-conf-aux
                          (aux-item->data item)
                          `(face ,kom-warning-face)
756
                          (lyskom-aux-item-terminating-button item obj))))
David Byers's avatar
David Byers committed
757
758

(defun lyskom-print-elisp-client-read-faq (item &optional obj)
759
  (when (lyskom-extended-status-information 'read-faq)
760
    (when (string-match "^\\([0-9]+\\) \\([0-9]+\\)" (aux-item->data item))
David Byers's avatar
David Byers committed
761
762
763
764
765
766
767
768
769
770
771
772
      (condition-case nil
          (let ((conf-no (lyskom-string-to-int (match-string 1 (aux-item->data item)) t))
                (text-no (lyskom-string-to-int (match-string 2 (aux-item->data item)) t)))
            (lyskom-format-insert 'status-read-faq-aux-item 
                                  conf-no 
                                  text-no
                                  (lyskom-aux-item-terminating-button item obj)))
        (lyskom-integer-conversion-error
         (lyskom-format-insert 'bad-status-read-faq-aux-item
                               (aux-item->data item)
                               `(face ,kom-warning-face)
                               (lyskom-aux-item-terminating-button item obj)))))))
773

774
(defun lyskom-print-elisp-client-rejected-invitation (item &optional obj)
David Byers's avatar
David Byers committed
775
  (if (lyskom-aux-item-validate (aux-item->data item) 'lyskom-string-to-int)
776
      (let ((conf-no (lyskom-string-to-number (aux-item->data item))))
David Byers's avatar
David Byers committed
777
778
779
780
781
782
783
        (lyskom-format-insert 'status-rejected-recommendation-aux-item
                              conf-no 
                              (lyskom-aux-item-terminating-button item obj)))
    (lyskom-format-insert 'bad-status-rejected-recommendation-aux-item
                          (aux-item->data item)
                          `(face ,kom-warning-face)
                          (lyskom-aux-item-terminating-button item obj))))
784

785
(provide 'lyskom-aux-items)