-
Notifications
You must be signed in to change notification settings - Fork 15
/
mime-view.el
2204 lines (1982 loc) · 71 KB
/
mime-view.el
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
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
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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; mime-view.el --- interactive MIME viewer for GNU Emacs -*- lexical-binding: t -*-
;; Copyright (C) 1995,96,97,98,99,2000 Free Software Foundation, Inc.
;; Author: MORIOKA Tomohiko <[email protected]>
;; Created: 1994/07/13
;; Renamed: 1994/08/31 from tm-body.el
;; Renamed: 1997/02/19 from tm-view.el
;; Keywords: MIME, multimedia, mail, news
;; This file is part of SEMI (Sample of Elastic MIME Interfaces).
;; This program 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.
;; This program 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 GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Code:
(require 'mime)
(require 'semi-def)
(require 'calist)
(require 'alist)
(require 'mime-conf)
(require 'path-util)
(eval-when-compile (require 'static))
;;; @ version
;;;
(defconst mime-view-version
(concat (mime-product-name mime-user-interface-product) " MIME-View "
(mapconcat #'number-to-string
(mime-product-version mime-user-interface-product) ".")
" (" (mime-product-code-name mime-user-interface-product) ")"))
;;; @ variables
;;;
(defgroup mime-view nil
"MIME view mode"
:group 'mime)
(defcustom mime-situation-examples-file "~/.mime-example"
"*File name of situation-examples demonstrated by user."
:group 'mime-view
:type 'file)
(defcustom mime-preview-move-scroll nil
"*Decides whether to scroll when moving to next entity.
When t, scroll the buffer. Non-nil but not t means scroll when
the next entity is within next-screen-context-lines from top or
buttom. Nil means don't scroll at all."
:group 'mime-view
:type '(choice (const :tag "Off" nil)
(const :tag "On" t)
(sexp :tag "Situation" 1)))
(defcustom mime-view-mailcap-files
'("~/.mailcap" "/usr/etc/mailcap" "/etc/mailcap")
"List of mailcap files."
:group 'mime-view
:type '(repeat file))
(defcustom mime-view-buttons-visible t
"Toggle visibility of MIME buttons."
:group 'mime-view
:type 'boolean)
(defcustom mime-view-nobreak-char-display nil
"Override `nobreak-char-display' in preview buffer.
See `nobreak-char-display' for details."
:type '(choice (const :tag "Use harcoded face" t)
(const :tag "Use escape glyph" escape)
(const :tag "No special handling" nil))
:group 'mime-view)
(defcustom mime-view-multipart/related-show-all-children t
"When non-nil, do not hide child entities."
:group 'mime-view
:type 'boolean)
(defcustom mime-view-multipart/alternative-show-all-children t
"When non-nil, show hidden descendant entities's buttons in
multipart/alternative entities."
:group 'mime-view
:type 'boolean)
(defvar mime-display-multipart/multilingual-unknown-translation-type
"(unknown)")
(defcustom mime-display-multipart/multilingual-prefered-languages
(mapcar (lambda (lang)
(format "^%s\\(-.+\\)?" (regexp-quote (symbol-name lang))))
(let ((result (get-language-info
current-language-environment 'iso639-language)))
(if (eq result 'en)
(list result)
(cons result '(en)))))
"Specify language automatically choiced for
multipart/multilingual entities. See docstring of
`mime-display-multipart/multilingual' for details."
:group 'mime-view
:type '(repeat regexp))
(defcustom mime-display-multipart/multilingual-translation-type-score
`(("original" . 2)
("human" . 1)
("automated" . -1)
(,mime-display-multipart/multilingual-unknown-translation-type . 0))
"Specify scores Content-Translation-Type: header fields. When
score is negative value, corresponding entity is not displayed
automatically. If field calue is missing or field does not
exist, field value is treated as \"(unknown)\". See docstring of
`mime-display-multipart/multilingual' for details."
:group 'mime-view
:type '(repeat (cons string integer)))
(defcustom mime-display-multipart/multilingual-interactive nil
"When non-nil, you are asked which language entity should be
displayed for multipart/multilingual entity."
:group 'mime-view
:type 'boolean)
(defcustom mime-view-text/html-score 3
"Score for text/html entity when previewer is available."
:group 'mime-view
:type 'integer)
(defcustom mime-view-text/html-previewer-alist
(delq nil `((w3m mime-w3m-preview-text/html mime-w3m)
,(and (fboundp 'libxml-parse-html-region)
'(shr mime-shr-preview-text/html mime-shr))
(w3 mime-preview-text/html mime-w3)))
"Alist for text/html entity previewer.
Each element is a list consists of required module, previewer
function and required feature for previewer function."
:group 'mime-view
:type '(repeat (list (symbol :tag "Module")
(symbol :tag "Function")
(symbol :tag "Feature"))))
(defcustom mime-view-text/html-previewer
(let ((alist mime-view-text/html-previewer-alist))
(while (and alist (null (module-installed-p (caar alist))))
(setq alist (cdr alist)))
(caar alist))
"Indicate text/html entity previewer. Possible vaules are each
car of `mime-view-text/html-previewer-alist' element or nil.
When this value is nil or previewer is not available, text/html
entity is displayed as if text/plain part."
:group 'mime-view
:type `(choice ,@(mapcar (lambda (elt) (list 'const (car elt)))
mime-view-text/html-previewer-alist)
(const :tag "Disable previewer" nil)))
(defcustom mime-display-text/plain-flowed-fill-column nil
"Fill column for formatting flowed text."
:group 'mime-view
:type '(choice (integer :tag "Fixed value")
(number :tag "ratio to window's width")
(sexp :tag "S-expression")
(const :tag "Use fill-column's value" nil)))
(defcustom mime-pgp-verify-when-preview t
"When non-nil, verify signed part while viewing."
:group 'mime-view
:type 'boolean)
(defcustom mime-pgp-decrypt-when-preview nil
"When non-nil, decrypt encrypted part while viewing."
:group 'mime-view
:type 'boolean)
;;; @ in raw-buffer (representation space)
;;;
(defvar-local mime-preview-buffer nil
"MIME-preview buffer corresponding with the (raw) buffer.")
(defvar mime-raw-representation-type-alist
'((mime-show-message-mode . binary)
(mime-temp-message-mode . binary)
(t . cooked))
"Alist of major-mode vs. representation-type of mime-raw-buffer.
Each element looks like (SYMBOL . REPRESENTATION-TYPE). SYMBOL is
major-mode or t. t means default. REPRESENTATION-TYPE must be
`binary' or `cooked'.")
;;; @ in preview-buffer (presentation space)
;;;
(defvar-local mime-mother-buffer nil
"Mother buffer corresponding with the (MIME-preview) buffer.
If current MIME-preview buffer is generated by other buffer, such as
message/partial, it is called `mother-buffer'.")
;; (defvar mime-raw-buffer nil
;; "Raw buffer corresponding with the (MIME-preview) buffer.")
;; (make-variable-buffer-local 'mime-raw-buffer)
(defvar-local mime-preview-original-window-configuration nil
"Window-configuration before mime-view-mode is called.")
(defun mime-preview-original-major-mode (&optional recursive point)
"Return major-mode of original buffer.
If optional argument RECURSIVE is non-nil and current buffer has
mime-mother-buffer, it returns original major-mode of the
mother-buffer."
(if (and recursive mime-mother-buffer)
(with-current-buffer mime-mother-buffer
(mime-preview-original-major-mode recursive))
(cdr (assq 'major-mode
(get-text-property (or point
(if (> (point) (buffer-size))
(max (1- (point-max)) (point-min))
(point)))
'mime-view-situation)))))
;;; @ entity information
;;;
(defun mime-entity-situation (entity &optional situation)
"Return situation of ENTITY."
(let (rest param name)
;; Content-Type
(unless (assq 'type situation)
(setq rest (or (mime-entity-content-type entity)
(make-mime-content-type 'text 'plain))
situation (cons (car rest) situation)
rest (cdr rest)))
(unless (assq 'subtype situation)
(or rest
(setq rest (or (cdr (mime-entity-content-type entity))
'((subtype . plain)))))
(setq situation (cons (car rest) situation)
rest (cdr rest)))
(while rest
(setq param (car rest))
(or (assoc (car param) situation)
(setq situation (cons param situation)))
(setq rest (cdr rest)))
;; Content-Disposition
(setq rest nil)
(unless (assq 'disposition-type situation)
(setq rest (mime-entity-content-disposition entity))
(if rest
(setq situation (cons (cons 'disposition-type
(mime-content-disposition-type rest))
situation)
rest (mime-content-disposition-parameters rest))))
(while rest
(setq param (car rest)
name (car param))
(if (cond ((string= name "filename")
(if (assq 'filename situation)
nil
(setq name 'filename)))
((string= name "creation-date")
(if (assq 'creation-date situation)
nil
(setq name 'creation-date)))
((string= name "modification-date")
(if (assq 'modification-date situation)
nil
(setq name 'modification-date)))
((string= name "read-date")
(if (assq 'read-date situation)
nil
(setq name 'read-date)))
((string= name "size")
(if (assq 'size situation)
nil
(setq name 'size)))
(t (setq name (cons 'disposition name))
(if (assoc name situation)
nil
name)))
(setq situation
(cons (cons name (cdr param))
situation)))
(setq rest (cdr rest)))
;; Content-Transfer-Encoding
(or (assq 'encoding situation)
(setq situation
(cons (cons 'encoding (or (mime-entity-encoding entity)
"7bit"))
situation)))
situation))
(defsubst mime-delq-null-situation (situations field
&rest ignored-values)
(let (dest)
(while situations
(let* ((situation (car situations))
(cell (assq field situation)))
(if cell
(or (memq (cdr cell) ignored-values)
(setq dest (cons situation dest)))))
(setq situations (cdr situations)))
dest))
(defun mime-compare-situation-with-example (situation example)
(let ((example (copy-alist example))
(match 0))
(while situation
(let* ((cell (car situation))
(key (car cell))
(ecell (assoc key example)))
(when ecell
(if (equal cell ecell)
(setq match (1+ match))
(setq example (delq ecell example)))))
(setq situation (cdr situation)))
(cons match example)))
(defun mime-sort-situation (situation)
(sort situation
#'(lambda (a b)
(let ((a-t (car a))
(b-t (car b))
(order '((type . 1)
(subtype . 2)
(mode . 3)
(method . 4)
(major-mode . 5)
(disposition-type . 6)))
a-order b-order)
(if (symbolp a-t)
(let ((ret (assq a-t order)))
(if ret
(setq a-order (cdr ret))
(setq a-order 7)))
(setq a-order 8))
(if (symbolp b-t)
(let ((ret (assq b-t order)))
(if ret
(setq b-order (cdr ret))
(setq b-order 7)))
(setq b-order 8))
(if (= a-order b-order)
(string< (format "%s" a-t)(format "%s" b-t))
(< a-order b-order))))))
(defun mime-unify-situations (entity-situation
condition situation-examples
&optional required-name ignored-value
every-situations)
(let (ret)
(in-calist-package 'mime-view)
(setq ret
(ctree-find-calist condition entity-situation
every-situations))
(if required-name
(setq ret (mime-delq-null-situation ret required-name
ignored-value t)))
(or (assq 'ignore-examples entity-situation)
(if (cdr ret)
(let ((rest ret)
(max-score 0)
(max-escore 0)
max-examples
max-situations)
(while rest
(let ((situation (car rest))
(examples situation-examples))
(while examples
(let* ((ret
(mime-compare-situation-with-example
situation (caar examples)))
(ret-score (car ret)))
(cond ((> ret-score max-score)
(setq max-score ret-score
max-escore (cdar examples)
max-examples (list (cdr ret))
max-situations (list situation)))
((= ret-score max-score)
(cond ((> (cdar examples) max-escore)
(setq max-escore (cdar examples)
max-examples (list (cdr ret))
max-situations (list situation)))
((= (cdar examples) max-escore)
(setq max-examples
(cons (cdr ret) max-examples))
(or (member situation max-situations)
(setq max-situations
(cons situation max-situations))))))))
(setq examples (cdr examples))))
(setq rest (cdr rest)))
(when max-situations
(setq ret max-situations)
(while max-examples
(let* ((example (car max-examples))
(cell
(assoc example situation-examples)))
(if cell
(setcdr cell (1+ (cdr cell)))
(setq situation-examples
(cons (cons example 0)
situation-examples))))
(setq max-examples (cdr max-examples)))))))
(cons ret situation-examples)
;; ret: list of situations
;; situation-examples: new examples (notoce that contents of
;; argument `situation-examples' has bees modified)
))
(defun mime-view-entity-title (entity)
(or (mime-entity-read-field entity 'Content-Description)
(mime-entity-filename entity)
(mime-entity-read-field entity 'Subject)
""))
(defvar mime-preview-situation-example-list nil)
(defvar mime-preview-situation-example-list-max-size 16)
;; (defvar mime-preview-situation-example-condition nil)
(defvar mime-preview-condition nil
"Condition-tree about how to display entity.")
(defun mime-find-entity-preview-situation (entity
&optional default-situation)
(or (let ((ret
(mime-unify-situations
(append (mime-entity-situation entity)
default-situation)
mime-preview-condition
mime-preview-situation-example-list)))
(setq mime-preview-situation-example-list
(cdr ret))
(caar ret))
default-situation))
(defvar mime-acting-situation-example-list nil)
(defvar mime-acting-situation-example-list-max-size 16)
(defvar mime-situation-examples-file-coding-system nil)
(defun mime-view-read-situation-examples-file (&optional file)
(or file
(setq file mime-situation-examples-file))
(if (and file
(file-readable-p file))
(with-temp-buffer
(insert-file-contents file)
(setq mime-situation-examples-file-coding-system
buffer-file-coding-system)
(condition-case error
(eval-buffer)
(error (message "%s is broken: %s" file (cdr error))))
;; format check
(condition-case nil
(let ((i 0))
(while (and (> (length mime-preview-situation-example-list)
mime-preview-situation-example-list-max-size)
(< i 16))
(setq mime-preview-situation-example-list
(mime-reduce-situation-examples
mime-preview-situation-example-list))
(setq i (1+ i))))
(error (setq mime-preview-situation-example-list nil)))
;; (let ((rest mime-preview-situation-example-list))
;; (while rest
;; (ctree-set-calist-strictly 'mime-preview-condition
;; (caar rest))
;; (setq rest (cdr rest))))
(condition-case nil
(let ((i 0))
(while (and (> (length mime-acting-situation-example-list)
mime-acting-situation-example-list-max-size)
(< i 16))
(setq mime-acting-situation-example-list
(mime-reduce-situation-examples
mime-acting-situation-example-list))
(setq i (1+ i))))
(error (setq mime-acting-situation-example-list nil))))))
(defun mime-save-situation-examples ()
(if (or mime-preview-situation-example-list
mime-acting-situation-example-list)
(let ((file mime-situation-examples-file)
print-length print-level)
(when file
(with-temp-buffer
(insert ";;; " (file-name-nondirectory file) "\n")
(insert "\n;; This file is generated automatically by "
mime-view-version "\n\n")
(insert ";;; Code:\n\n")
(if mime-preview-situation-example-list
(pp `(setq mime-preview-situation-example-list
',mime-preview-situation-example-list)
(current-buffer)))
(if mime-acting-situation-example-list
(pp `(setq mime-acting-situation-example-list
',mime-acting-situation-example-list)
(current-buffer)))
(insert "\n;;; "
(file-name-nondirectory file)
" ends here.\n")
(setq buffer-file-coding-system
mime-situation-examples-file-coding-system)
(setq buffer-file-name file)
(save-buffer))))))
(add-hook 'kill-emacs-hook 'mime-save-situation-examples)
(defun mime-reduce-situation-examples (situation-examples)
(let ((len (length situation-examples))
i ir ic j jr jc ret
dest d-i d-j
(max-sim 0) sim
min-det-ret det-ret
min-det-org det-org
min-freq freq)
(setq i 0
ir situation-examples)
(while (< i len)
(setq ic (car ir)
j 0
jr situation-examples)
(while (< j len)
(unless (= i j)
(setq jc (car jr))
(setq ret (mime-compare-situation-with-example (car ic)(car jc))
sim (car ret)
det-ret (+ (length (car ic))(length (car jc)))
det-org (length (cdr ret))
freq (+ (cdr ic)(cdr jc)))
(cond ((< max-sim sim)
(setq max-sim sim
min-det-ret det-ret
min-det-org det-org
min-freq freq
d-i i
d-j j
dest (cons (cdr ret) freq)))
((= max-sim sim)
(cond ((> min-det-ret det-ret)
(setq min-det-ret det-ret
min-det-org det-org
min-freq freq
d-i i
d-j j
dest (cons (cdr ret) freq)))
((= min-det-ret det-ret)
(cond ((> min-det-org det-org)
(setq min-det-org det-org
min-freq freq
d-i i
d-j j
dest (cons (cdr ret) freq)))
((= min-det-org det-org)
(cond ((> min-freq freq)
(setq min-freq freq
d-i i
d-j j
dest (cons (cdr ret) freq)))))))))))
(setq jr (cdr jr)
j (1+ j)))
(setq ir (cdr ir)
i (1+ i)))
(if (> d-i d-j)
(setq i d-i
d-i d-j
d-j i))
(setq jr (nthcdr (1- d-j) situation-examples))
(setcdr jr (cddr jr))
(if (= d-i 0)
(setq situation-examples
(cdr situation-examples))
(setq ir (nthcdr (1- d-i) situation-examples))
(setcdr ir (cddr ir)))
(if (setq ir (assoc (car dest) situation-examples))
(progn
(setcdr ir (+ (cdr ir)(cdr dest)))
situation-examples)
(cons dest situation-examples)
;; situation-examples may be modified.
)))
;;; @ presentation of preview
;;;
;;; @@ entity-button
;;;
;;; @@@ predicate function
;;;
;; (defun mime-view-entity-button-visible-p (entity)
;; "Return non-nil if header of ENTITY is visible.
;; Please redefine this function if you want to change default setting."
;; (let ((media-type (mime-entity-media-type entity))
;; (media-subtype (mime-entity-media-subtype entity)))
;; (or (not (eq media-type 'application))
;; (and (not (eq media-subtype 'x-selection))
;; (or (not (eq media-subtype 'octet-stream))
;; (let ((mother-entity (mime-entity-parent entity)))
;; (or (not (eq (mime-entity-media-type mother-entity)
;; 'multipart))
;; (not (eq (mime-entity-media-subtype mother-entity)
;; 'encrypted)))
;; )
;; )))))
;;; @@@ entity button generator
;;;
(defun mime-view-insert-entity-button (entity)
"Insert entity-button of ENTITY."
(let ((entity-node-id (mime-entity-node-id entity))
(params (mime-entity-parameters entity))
(subject (mime-view-entity-title entity)))
(mime-insert-button
(let ((access-type (assoc "access-type" params))
(num (or (cdr (assoc "x-part-number" params))
(if (consp entity-node-id)
(mapconcat (function
(lambda (num)
(format "%s" (1+ num))))
(reverse entity-node-id) ".")
"0"))))
(cond (access-type
(let ((server (assoc "server" params)))
(setq access-type (cdr access-type))
(if server
(format "%s %s ([%s] %s)"
num subject access-type (cdr server))
(let ((site (cdr (assoc "site" params)))
(dir (cdr (assoc "directory" params)))
(url (cdr (assoc "url" params))))
(if url
(format "%s %s ([%s] %s)"
num subject access-type url)
(format "%s %s ([%s] %s:%s)"
num subject access-type site dir))))))
(t
(let* ((charset (cdr (assoc "charset" params)))
(encoding (mime-entity-encoding entity))
(language (mime-entity-read-field
entity "Content-Language"))
(rest (format " <%s/%s%s%s%s>"
(mime-entity-media-type entity)
(mime-entity-media-subtype entity)
(if language
(concat " (" language ")")
"")
(if charset
(concat "; " charset)
"")
(if encoding
(concat " (" encoding ")")
""))))
(concat
num " " subject
(if (>= (+ (current-column)(length rest))(window-width))
"\n\t")
rest)))))
(function mime-preview-play-current-entity))))
;;; @@ entity-header
;;;
(defvar mime-header-presentation-method-alist nil
"Alist of major mode vs. corresponding header-presentation-method functions.
Each element looks like (SYMBOL . FUNCTION).
SYMBOL must be major mode in raw-buffer or t. t means default.
Interface of FUNCTION must be (ENTITY SITUATION).")
(defvar mime-view-ignored-field-list
'(".*Received:" ".*Path:" ".*Id:" "^References:"
"^Replied:" "^Errors-To:"
"^Lines:" "^Sender:" ".*Host:" "^Xref:"
"^Content-Type:" "^Precedence:"
"^Status:" "^X-VM-.*:")
"All fields that match this list will be hidden in MIME preview buffer.
Each elements are regexp of field-name.")
(defvar mime-view-visible-field-list '("^Dnas.*:" "^Message-Id:")
"All fields that match this list will be displayed in MIME preview buffer.
Each elements are regexp of field-name.")
;;; @@ entity-body
;;;
;;; @@@ predicate function
;;;
(in-calist-package 'mime-view)
(defun mime-calist::field-match-method-as-default-rule (calist
field-type field-value)
(let ((s-field (assq field-type calist)))
(cond ((null s-field)
(cons (cons field-type field-value) calist))
(t calist))))
(define-calist-field-match-method
'header #'mime-calist::field-match-method-as-default-rule)
(define-calist-field-match-method
'body #'mime-calist::field-match-method-as-default-rule)
(defun mime-calist::field-match-method-ignore-case (calist
field-type field-value)
(let ((s-field (assoc field-type calist)))
(cond ((null s-field)
(cons (cons field-type field-value) calist))
((eq field-value t)
calist)
((string= (downcase (cdr s-field)) (downcase field-value))
calist))))
(define-calist-field-match-method
'access-type #'mime-calist::field-match-method-ignore-case)
(ctree-set-calist-strictly
'mime-preview-condition '((type . application)(subtype . octet-stream)
(encoding . nil)
(body . visible)
(major-mode . t)))
(ctree-set-calist-strictly
'mime-preview-condition '((type . application)(subtype . octet-stream)
(encoding . "7bit")
(body . visible)
(major-mode . t)))
(ctree-set-calist-strictly
'mime-preview-condition '((type . application)(subtype . octet-stream)
(encoding . "8bit")
(body . visible)
(major-mode . t)))
(ctree-set-calist-strictly
'mime-preview-condition '((type . application)(subtype . pgp)
(body . visible)
(major-mode . t)))
(ctree-set-calist-strictly
'mime-preview-condition '((type . application)(subtype . x-latex)
(body . visible)
(major-mode . t)))
(ctree-set-calist-strictly
'mime-preview-condition '((type . application)(subtype . x-selection)
(body . visible)
(major-mode . t)))
(ctree-set-calist-strictly
'mime-preview-condition '((type . application)(subtype . x-comment)
(body . visible)
(major-mode . t)))
(ctree-set-calist-strictly
'mime-preview-condition '((type . message)(subtype . delivery-status)
(body . visible)
(major-mode . t)))
(ctree-set-calist-strictly
'mime-preview-condition
'((body . visible)
(major-mode . t)
(body-presentation-method . mime-display-text/plain)))
(ctree-set-calist-strictly
'mime-preview-condition
'((type . nil)
(body . visible)
(major-mode . t)
(body-presentation-method . mime-display-text/plain)))
(ctree-set-calist-strictly
'mime-preview-condition
'((type . text)(subtype . enriched)
(body . visible)
(major-mode . t)
(body-presentation-method . mime-display-text/enriched)))
(ctree-set-calist-strictly
'mime-preview-condition
'((type . text)(subtype . richtext)
(body . visible)
(major-mode . t)
(body-presentation-method . mime-display-text/richtext)))
(ctree-set-calist-strictly
'mime-preview-condition
'((type . text)(subtype . html)
(body . visible)
(major-mode . t)
(body-presentation-method . mime-display-text/html)))
(autoload 'mime-display-application/x-postpet "postpet")
(ctree-set-calist-strictly
'mime-preview-condition
'((type . application)(subtype . x-postpet)
(body . visible)
(major-mode . t)
(body-presentation-method . mime-display-application/x-postpet)))
(ctree-set-calist-strictly
'mime-preview-condition
'((type . text)(subtype . t)
(body . visible)
(major-mode . t)
(body-presentation-method . mime-display-text/plain)))
(ctree-set-calist-strictly
'mime-preview-condition
'((type . multipart)(subtype . alternative)
(body . visible)
(major-mode . t)
(body-presentation-method . mime-display-multipart/alternative)))
(ctree-set-calist-strictly
'mime-preview-condition
'((type . multipart)(subtype . related)
(body . visible)
(major-mode . t)
(body-presentation-method . mime-display-multipart/related)))
(ctree-set-calist-strictly
'mime-preview-condition
'((type . multipart)(subtype . multilingual)
(body . visible)
(major-mode . t)
(body-presentation-method . mime-display-multipart/multilingual)))
(ctree-set-calist-strictly
'mime-preview-condition
'((type . multipart)(subtype . t)
(body . visible)
(major-mode . t)
(body-presentation-method . mime-display-multipart/mixed)))
(ctree-set-calist-strictly
'mime-preview-condition
'((type . message)(subtype . partial)
(body . visible)
(major-mode . t)
(body-presentation-method . mime-display-message/partial-button)))
(ctree-set-calist-strictly
'mime-preview-condition
'((type . message)(subtype . rfc822)
(body . visible)
(major-mode . t)
(body-presentation-method . mime-display-message/rfc822)
(childrens-situation (header . visible))))
(ctree-set-calist-strictly
'mime-preview-condition
'((type . message)(subtype . news)
(body . visible)
(major-mode . t)
(body-presentation-method . mime-display-message/rfc822)
(childrens-situation (header . visible))))
;;; @@@ entity presentation
;;;
(defun mime-display-insert-text-content (entity)
(condition-case signal
(progn (mime-insert-text-content entity)
(run-hooks 'mime-text-decode-hook)
t)
(error (let ((point (point)))
(insert (format "This entity can't be decoded. %s"
(or (cadr signal) "")))
(add-text-properties point (point) '(face highlight)))
(insert "\nHere is original data.\n\n")
(mime-insert-entity-body entity)
nil)))
(defun mime-display-text/plain-flowed-parse-line ()
(cons (point)
(cond
;; End of buffer
((eobp) nil)
;; Signature separator line
((looking-at "\\(>+\\)? ?\\(-- \\)$")
(list (length (match-string 1)) 'hard (match-beginning 2)))
;; Quoted line
((looking-at "\\(>+\\) ?\\(.*?\\)\\( ?\\)$")
(list (length (match-string 1))
(if (zerop (length (match-string 3))) t nil)
(match-beginning 2)))
;; Stuffed or normal line
((looking-at " ?\\(.*?\\)\\( ?\\)$")
(list 0 (if (zerop (length (match-string 2))) t nil)
(match-beginning 1))))))
(defun mime-display-text/plain-flowed (&optional buffer delete-space)
(with-current-buffer (or buffer (current-buffer))
(goto-char (point-min))
(let ((fill-column
(cond
((and (integerp mime-display-text/plain-flowed-fill-column)
(< mime-display-text/plain-flowed-fill-column 1))
(+ (window-width) mime-display-text/plain-flowed-fill-column))
((integerp mime-display-text/plain-flowed-fill-column)
mime-display-text/plain-flowed-fill-column)
((numberp mime-display-text/plain-flowed-fill-column)
(floor
(* (window-width) mime-display-text/plain-flowed-fill-column)))
(mime-display-text/plain-flowed-fill-column
(eval mime-display-text/plain-flowed-fill-column))
(t fill-column)))
(line (mime-display-text/plain-flowed-parse-line))
beg-flow depth next point fill-prefix adaptive-fill-mode)
(setq delete-space (if delete-space -2 -1))
(while (cdr line)
(unless (eq (point) (car line))
(setcar (cdr (cddr line)) (+ (nth 3 line) (- (point) (car line))))
(setcar line (point)))
(forward-line)
(setq next (mime-display-text/plain-flowed-parse-line))
(when (or (null (cdr next))
(null (eq (nth 1 line) (nth 1 next)))
(eq (nth 2 next) 'hard))
(setcar (cddr line) t))
(if beg-flow
;; Following flowed line.
(progn
(delete-region (+ (car line) delete-space) (nth 3 line))
(when (nth 2 line)
;; Fixed line
(setq fill-prefix (unless (zerop depth)
(concat (make-string depth ?>) " ")))
(fill-region beg-flow (point) 'left t)
(setq beg-flow nil)))
;; Following fixed line.
(if (zerop (nth 1 line))
;; Remove stuffed space
(delete-region (car line) (nth 3 line))
(when (eq (+ (car line) (nth 1 line)) (nth 3 line))
;; Insert stuffing space for quoted text
(setq point (point))
(goto-char (nth 3 line))
(insert 32)
(goto-char (1+ point))))
(unless (nth 2 line)
;; Beginnig of flowed text
(setq beg-flow (car line)
depth (nth 1 line))))
(setq line next)))))
(defun mime-display-text/plain (entity situation)
(save-restriction
(narrow-to-region (point-max)(point-max))
(when (mime-display-insert-text-content entity)
(when (null (eq (char-before (point-max)) ?\n))
(goto-char (point-max))
(insert "\n"))
(when (equal (downcase (or (cdr (assoc "format" situation)) ""))
"flowed")
(mime-display-text/plain-flowed
nil (equal (downcase (or (cdr (assoc "delsp" situation)) ""))
"yes")))
(mime-add-url-buttons)
(run-hooks 'mime-display-text/plain-hook))))
(autoload 'richtext-decode "richtext")
(defun mime-display-text/richtext (entity _situation)
(save-restriction
(narrow-to-region (point-max)(point-max))
(when (mime-display-insert-text-content entity)
(remove-text-properties (point-min) (point-max) '(face nil))
(richtext-decode (point-min) (point-max)))))
(defun mime-display-text/enriched (entity _situation)
(save-restriction
(narrow-to-region (point-max)(point-max))
(when (mime-display-insert-text-content entity)
(remove-text-properties (point-min) (point-max) '(face nil))
(enriched-decode (point-min) (point-max)))))