aux-items.el 19.6 KB
Newer Older
David Byers's avatar
David Byers committed
1
;;;;; -*-coding: iso-8859-1;-*-
2
3
4
5
6
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
;;;;;
;;;;; $Id$
;;;;; Copyright (C) 1991, 1996  Lysator Academic Computer Association.
;;;;;
;;;;; This file is part of the LysKOM server.
;;;;; 
;;;;; 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"))

39
40
41
42
;;; (eval-when-compile
;;;   (require 'lyskom-defvar "defvar.el")
;;;   (require 'lyskom-vars "vars.el")
;;;   (require 'lyskom-types "komtypes.el"))
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65


(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))

(defun lyskom-map-aux-items (fn text-stat)
  "Apply FN to every aux item in TEXT-STAT."
  (let ((items (text-stat->aux-items text-stat)))
    (while items
      (when (and (car items) 
David Byers's avatar
David Byers committed
66
                 (not (aux-item-flags->deleted (aux-item->flags items))))
67
68
69
70
71
        (funcall fn (car items)))
      (setq items (cdr items)))))



72
73
74
(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)))
75
  (cond ((listp method)
76
77
         (let ((result nil)
               (found nil))
78
           (while method
79
             (when (lyskom-aux-item-definition-field item (car method))
80
               (setq result
81
                     (apply (lyskom-aux-item-definition-field item
82
                                                              (car method))
83
84
85
                            args)
                     found t
                     method nil))
86
             (setq method (cdr method)))
87
88
89
90
91
92
93
94
           (if found result default)))
        (t (if (lyskom-aux-item-definition-field item method)
             (apply (lyskom-aux-item-definition-field item method) args)
             default))))


(defun lyskom-aux-item-call (def method &rest args)
  (apply 'lyskom-aux-item-try-call def method nil args))
95
96
97


(defun lyskom-aux-item-definition-field (def method)
98
  (when (lyskom-aux-item-p def)
99
100
101
102
103
104
105
    (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))

106
107
108
109
110
111
112
113
114
115
116
(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)))

117
118
119
120
121
122
123
                                        
(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))))


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
(defun lyskom-aux-item-terminating-button (item obj)
  (if obj
       (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)))
                                                   (t item))))
     ""))

143
144
145
146
147
148
149
150
151
152
(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
                            (aux-item->data item)))


153
154
155
;;; ======================================================================

(def-aux-item content-type 1
David Byers's avatar
David Byers committed
156
  (text-print-when . never) 
157
  (parse . lyskom-parse-content-type)
David Byers's avatar
David Byers committed
158
  (text-print . lyskom-print-content-type)
159
160
161
  (info  . lyskom-aux-item-info))

(def-aux-item fast-reply 2
David Byers's avatar
David Byers committed
162
  (text-print-when . footer)
163
  (parse . nil)
164
165
  (parse-data . lyskom-aux-item-decode-data)
  (output-data . lyskom-aux-item-encode-data)
David Byers's avatar
David Byers committed
166
  (text-print . lyskom-print-fast-reply)
167
168
169
  (info . lyskom-aux-item-info))

(def-aux-item cross-reference 3
David Byers's avatar
David Byers committed
170
171
  (status-print . lyskom-status-print-cross-reference)
  (text-print-when . comment)
172
  (parse . lyskom-parse-cross-reference)
173
174
  (parse-data . lyskom-aux-item-decode-data)
  (output-data . lyskom-aux-item-encode-data)
David Byers's avatar
David Byers committed
175
  (text-print . lyskom-print-cross-reference)
176
177
178
179
  (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
180
  (text-print-when . footer)
181
  (parse . lyskom-parse-no-comments)
David Byers's avatar
David Byers committed
182
  (text-print . lyskom-print-no-comments)
183
184
185
186
  (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
187
  (text-print-when . footer)
188
  (parse . lyskom-parse-personal-comments)
David Byers's avatar
David Byers committed
189
  (text-print . lyskom-print-personal-comments)
190
191
192
193
  (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
194
  (text-print-when . header)
195
  (parse . lyskom-parse-request-confirmation)
David Byers's avatar
David Byers committed
196
  (text-print . lyskom-print-request-confirmation)
197
198
199
200
201
  (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
202
203
  (text-print-when . header)
  (text-print . lyskom-print-read-confirm)
204
205
206
207
208
209
210
211
212
213
214
  (info  . lyskom-aux-item-info))

(def-aux-item redirect 8
  (print . lyskom-print-redirect)
  (info  . lyskom-aux-item-info))

(def-aux-item x-face 9
  (print . lyskom-print-xface)
  (info  . lyskom-aux-item-info))

(def-aux-item alternate-name 10
David Byers's avatar
David Byers committed
215
216
  (text-print-when . header)
  (text-print . lyskom-print-alternate-name)
217
218
  (output-data . lyskom-aux-item-encode-data)
  (parse-data . lyskom-aux-item-decode-data)
219
220
221
222
223
224
225
226
227
228
229
  (info  . lyskom-aux-item-info))

(def-aux-item pgp-signature 11
  (info  . lyskom-aux-item-info))

(def-aux-item pgp-public-key 12
  (info  . lyskom-aux-item-info))

(def-aux-item e-mail-address 13
  (info  . lyskom-aux-item-info))

David Byers's avatar
David Byers committed
230
231
232
233
234
235
236
(def-aux-item faq-text 14
  (info . lyskom-aux-item-info)
  (status-print . lyskom-status-print-faq-text))

(def-aux-item creating-software 15
  (info . lyskom-aux-item-info)
  (text-print-when . header)
237
238
  (parse-data . lyskom-aux-item-decode-data)
  (output-data . lyskom-aux-item-encode-data)
David Byers's avatar
David Byers committed
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
  (text-print . lyskom-print-creating-software))

(def-aux-item mx-author 16
  (info . lyskom-aux-item-info))

(def-aux-item mx-from 17
  (info . lyskom-aux-item-info))

(def-aux-item mx-reply-to 18
  (info . lyskom-aux-item-info))

(def-aux-item mx-to 19
  (info . lyskom-aux-item-info))

(def-aux-item mx-cc 20
  (info . lyskom-aux-item-info))

(def-aux-item mx-date 21
  (info . lyskom-aux-item-info))

(def-aux-item mx-message-id 22
  (info . lyskom-aux-item-info))

(def-aux-item mx-in-reply-to 23
  (info . lyskom-aux-item-info))

(def-aux-item mx-misc 24
  (info . lyskom-aux-item-info))

(def-aux-item mx-allow-filter 25
  (info . lyskom-aux-item-info))

(def-aux-item mx-reject-forward 26
  (info . lyskom-aux-item-info))

(def-aux-item notify-comments 27
  (info . lyskom-aux-item-info))

(def-aux-item faq-for-conf 28
  (text-print . lyskom-print-faq-for-conf)
  (text-print-when . header)
  (info . lyskom-aux-item-info))


283
284
285
286
287
288


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



289
290
291
292
293
294
295
296
297
298
299
(defun lyskom-aux-item-decode-data (item)
  (set-aux-item->data 
   item
   (decode-coding-string (aux-item->data item) lyskom-server-coding-system)))

(defun lyskom-aux-item-encode-data (item)
  (encode-coding-string (aux-item->data item) lyskom-server-coding-system)
  )



300
301
302
303
304
305
306
307
308
309
(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
310
      (aux-item->tag item)
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
      (if def
          (lyskom-aux-item-definition->name def)
        "unknown")
      (aux-item->creator item)
      (lyskom-return-date-and-time (aux-item->sent-at item))
      (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-print-fast-reply (item &optional obj)
David Byers's avatar
David Byers committed
350
  (concat (lyskom-format 'fast-reply-aux
351
352
353
354
355
356
357
358
359
360
361
362
                         (aux-item->data item)
                         (aux-item->creator item))
          (lyskom-aux-item-terminating-button item obj)))

(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
363
364
(defun lyskom-edit-insert-cross-reference (item pers)
  (lyskom-print-cross-reference item nil pers))
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396

(defun lyskom-print-cross-reference (item &optional obj pers)
  (let ((pers (if (and (zerop (aux-item->creator item))
                       pers)
                  pers
                (aux-item->creator item))))
    (concat
     (cond ((string-match "^P\\([0-9]+\\)" (aux-item->data item))
            (lyskom-format 'cross-reference-pers-aux 
                           (string-to-int 
                            (match-string 1 (aux-item->data item)))
                           pers
                           ))
           ((string-match "^C\\([0-9]+\\)" (aux-item->data item))
            (lyskom-format 'cross-reference-conf-aux 
                           (string-to-int 
                            (match-string 1 (aux-item->data item)))
                           pers
                           ))
           ((string-match "^T\\([0-9]+\\)" (aux-item->data item))
            (lyskom-format 'cross-reference-text-aux 
                           (string-to-int 
                            (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
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
(defun lyskom-status-print-cross-reference (item &optional obj pers)
  (lyskom-insert 
   (concat
    (cond ((string-match "^P\\([0-9]+\\)" (aux-item->data item))
           (lyskom-format 'cross-reference-pers-status-aux 
                          (string-to-int 
                           (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 
                          (string-to-int 
                           (match-string 1 (aux-item->data item)))
                          pers
                          ))
          ((string-match "^T\\([0-9]+\\)" (aux-item->data item))
           (lyskom-format 'cross-reference-text-status-aux 
                          (string-to-int 
                           (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")))  

425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
(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)
  (lyskom-format 'no-comments-edit-aux))

(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)
  (lyskom-format 'personal-comment-edit-aux))

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

(defun lyskom-print-request-confirmation (item &optional obj)
452
453
  (concat (lyskom-format 'request-confirmation-aux
                         (aux-item->creator item))
454
455
456
457
458
459
460
461
462
463
464
465
466
          (lyskom-aux-item-terminating-button item obj)))

(defun lyskom-edit-insert-request-confirmation (item &optional obj)
  (lyskom-format 'request-confirmation-edit-aux))

(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)))
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
    (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)))))))
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506

(defun lyskom-print-read-confirm (item &optional obj)
  (concat 
   (lyskom-format 'read-confirm-aux
                  (aux-item->creator item)
                  (lyskom-return-date-and-time (aux-item->sent-at item)))
   (lyskom-aux-item-terminating-button item obj)))



(defun lyskom-print-redirect (item &optional obj)
  (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 
                         (string-to-int 
                          (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
507
508
   (lyskom-maybe-add-face-to-string item
                                    (make-string 0 ?X))
509
510
   nil))

511
512
513
514
(defun lyskom-maybe-add-face-to-string (item string)
  (lyskom-xemacs-or-gnu
   (if (null item)
       string
David Byers's avatar
David Byers committed
515
     (setq item (car item))
516
517
     (unless (find-face 'kom-xface)
       (make-face 'kom-xface))
518
     (let* ((h (concat "X-Face: " (aux-item->data item)))
519
            (g (intern h lyskom-xface-cache))
David Byers's avatar
David Byers committed
520
            (e (make-extent 0 (length string) string)))
521
522
523
       (if (boundp g)
           (setq g (symbol-value g))
         (set g (make-glyph
David Byers's avatar
David Byers committed
524
525
526
527
                 (list
                  (list 'global (cons '(tty) [nothing]))
                  (list 'global (cons '(win) 
                                      (vector 'xface ':data h))))))
528
529
530
         (setq g (symbol-value g))
         (set-glyph-face g 'kom-xface))
       (set-extent-begin-glyph e g)
David Byers's avatar
David Byers committed
531
532
533
534
       (set-extent-property e 'end-open nil)
       (set-extent-property e 'start-open nil)
       (set-extent-property e 'duplicable t)
       string))
535
536
537
   string))


538
(defun lyskom-print-alternate-name (item &optional obj)
David Byers's avatar
David Byers committed
539
  (concat "[" (aux-item->data item) "] "
540
541
          (lyskom-aux-item-terminating-button item obj)))

David Byers's avatar
David Byers committed
542
543
544
545
546
547
548
549
550
551
552
553
554
(defun lyskom-status-print-faq-text (item &optional obj)
  (lyskom-insert 
   (concat 
    (lyskom-format 'faq-in-text-aux (string-to-int (aux-item->data item)))
    (lyskom-aux-item-terminating-button item obj)
    "\n")))

(defun lyskom-print-faq-for-conf (item &optional obj)
  (concat 
   (lyskom-format 'faq-for-conf-aux (string-to-int (aux-item->data item)))
   (lyskom-aux-item-terminating-button item obj)))

(defun lyskom-print-creating-software (item &optional obj)
555
556
557
558
  (when kom-show-creating-software
    (concat
     (lyskom-format 'creating-software-aux (aux-item->data item))
     (lyskom-aux-item-terminating-button item obj))))
David Byers's avatar
David Byers committed
559

560
561

(provide 'lyskom-aux-items)