-
Notifications
You must be signed in to change notification settings - Fork 15
/
mime-edit.el
3268 lines (2957 loc) · 101 KB
/
mime-edit.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
;; -*- mode: emacs-lisp; coding: utf-8; lexical-binding: t -*-
;;; mime-edit.el --- Simple MIME Composer for GNU Emacs
;; Copyright (C) 1993,94,95,96,97,98,99,2000,01,02,03
;; Free Software Foundation, Inc.
;; Author: UMEDA Masanobu <[email protected]>
;; MORIOKA Tomohiko <[email protected]>
;; Daiki Ueno <[email protected]>
;; Created: 1994/08/21 renamed from mime.el
;; Renamed: 1997/2/21 from tm-edit.el
;; Keywords: MIME, multimedia, multilingual, mail, news
;; This file is part of SEMI (Sophisticated Emacs 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.
;;; Commentary:
;; This is an Emacs minor mode for editing Internet multimedia
;; messages formatted in MIME (RFC 2045, 2046, 2047, 2048 and 2049).
;; All messages in this mode are composed in the tagged MIME format,
;; that are described in the following examples. The messages
;; composed in the tagged MIME format are automatically translated
;; into a MIME compliant message when exiting the mode.
;; Mule (multilingual feature of Emacs 20 and multilingual extension
;; for XEmacs 20) has a capability of handling multilingual text in
;; limited ISO-2022 manner that is based on early experiences in
;; Japanese Internet community and resulted in RFC 1468 (ISO-2022-JP
;; charset for MIME). In order to enable multilingual capability in
;; single text message in MIME, charset of multilingual text written
;; in Mule is declared as either `ISO-2022-JP-2' [RFC 1554]. Mule is
;; required for reading the such messages.
;; This MIME composer can work with Mail mode, mh-e letter Mode, and
;; News mode. First of all, you need the following autoload
;; definition to load mime-edit-mode automatically:
;;
;; (autoload 'turn-on-mime-edit "mime-edit"
;; "Minor mode for editing MIME message." t)
;;
;; In case of Mail mode (includes VM mode), you need the following
;; hook definition:
;;
;; (add-hook 'mail-mode-hook 'turn-on-mime-edit)
;; (add-hook 'mail-send-hook 'mime-edit-maybe-translate)
;;
;; In case of MH-E, you need the following hook definition:
;;
;; (add-hook 'mh-letter-mode-hook
;; (function
;; (lambda ()
;; (turn-on-mime-edit)
;; (make-local-variable 'mail-header-separator)
;; (setq mail-header-separator "--------")
;; ))))
;; (add-hook 'mh-before-send-letter-hook 'mime-edit-maybe-translate)
;;
;; In case of News mode, you need the following hook definition:
;;
;; (add-hook 'news-reply-mode-hook 'turn-on-mime-edit)
;; (add-hook 'news-inews-hook 'mime-edit-maybe-translate)
;;
;; In case of Emacs 19, it is possible to emphasize the message tags
;; using font-lock mode as follows:
;;
;; (add-hook 'mime-edit-mode-hook
;; (function
;; (lambda ()
;; (font-lock-mode 1)
;; (setq font-lock-keywords (list mime-edit-tag-regexp))
;; ))))
;; The message tag looks like:
;;
;; --[[TYPE/SUBTYPE;PARAMETERS
;; OPTIONAL-FIELDS][ENCODING]]
;;
;; The tagged MIME message examples:
;;
;; This is a conventional plain text. It should be translated into
;; text/plain.
;;
;;--[[text/plain]]
;; This is also a plain text. But, it is explicitly specified as is.
;;--[[text/plain; charset=ISO-8859-1]]
;; This is also a plain text. But charset is specified as iso-8859-1.
;;
;; ¡Hola! Buenos días. ¿Cómo está usted?
;;--[[text/enriched]]
;; <center>This is a richtext.</center>
;;
;;--[[image/gif][base64]]^M...image encoded in base64 comes here...
;;
;;--[[audio/basic][base64]]^M...audio encoded in base64 comes here...
;;; Code:
(require 'mail-utils)
(require 'sendmail)
(require 'alist)
(require 'pccl)
(require 'invisible)
(require 'mel)
(require 'mime-view)
(require 'epa)
(autoload 'eword-encode-string "eword-encode")
(autoload 'eword-decode-and-unfold-unstructured-field-body "eword-decode")
;;; @ version
;;;
(eval-and-compile
(defconst mime-edit-version
(concat
(mime-product-name mime-user-interface-product) " "
(mapconcat #'number-to-string
(mime-product-version mime-user-interface-product) ".")
" - \"" (mime-product-code-name mime-user-interface-product) "\"")))
;;; @ variables
;;;
(defgroup mime-edit nil
"MIME edit mode"
:group 'mime)
(defcustom mime-ignore-preceding-spaces nil
"*Ignore preceding white spaces if non-nil."
:group 'mime-edit
:type 'boolean)
(defcustom mime-ignore-trailing-spaces nil
"*Ignore trailing white spaces if non-nil."
:group 'mime-edit
:type 'boolean)
(defcustom mime-ignore-same-text-tag t
"*Ignore preceding text content-type tag that is same with new one.
If non-nil, the text tag is not inserted unless something different."
:group 'mime-edit
:type 'boolean)
(defcustom mime-auto-hide-body t
"*Hide non-textual body encoded in base64 after insertion if non-nil."
:group 'mime-edit
:type 'boolean)
(defcustom mime-edit-insert-file-confirm t
"*Confirm guessed mime type when inserting files."
:group 'mime-edit
:type 'boolean)
(defcustom mime-edit-voice-recorder
(function mime-edit-voice-recorder-for-sun)
"*Function to record a voice message and encode it."
:group 'mime-edit
:type 'function)
(defcustom mime-edit-mode-hook nil
"*Hook called when enter MIME mode."
:group 'mime-edit
:type 'hook)
(defcustom mime-edit-translate-hook nil
"*Hook called before translating into a MIME compliant message.
To insert a signature file automatically, call the function
`mime-edit-insert-signature' from this hook."
:group 'mime-edit
:type 'hook)
(defcustom mime-edit-exit-hook nil
"*Hook called when exit MIME mode."
:group 'mime-edit
:type 'hook)
(defvar mime-content-types
'(("text"
;; Charset parameter need not to be specified, since it is
;; defined automatically while translation.
("plain"
;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
)
("enriched")
("html")
("css") ; rfc2318
("csv") ; rfc4180
("xml") ; rfc2376
("xml") ; rfc2376
("vcard") ; rfc6350
;; ("x-rot13-47-48")
)
("message"
("external-body"
("access-type"
("anon-ftp"
("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
("directory" "/pub/GNU/elisp/mime")
("name")
("mode" "image" "ascii" "local8"))
("ftp"
("site")
("directory")
("name")
("mode" "image" "ascii" "local8"))
("tftp" ("site") ("name"))
("afs" ("site") ("name"))
("local-file" ("site") ("name"))
("mail-server"
("server" "[email protected]")
("subject"))
("url" ("url"))))
("rfc822")
("news"))
("application"
("javascript")
("msword")
("octet-stream" ("type" "" "tar" "shar"))
("postscript")
("pdf")
("rtf")
("zip")
("x-shockwave-flash")
("x-7z-compressed")
; OpenOffice
("vnd.oasis.opendocument.text")
("vnd.oasis.opendocument.spreadsheet")
("vnd.oasis.opendocument.graphics")
("vnd.oasis.opendocument.chart")
("vnd.oasis.opendocument.formula")
("vnd.oasis.opendocument.text-master")
("vnd.oasis.opendocument.presentation")
("vnd.oasis.opendocument.text-template")
("vnd.oasis.opendocument.spreadsheet-template")
("vnd.oasis.opendocument.presentation-template")
("vnd.oasis.opendocument.graphics-template")
("msword")
("vnd.ms-excel")
("vnd.ms-powerpoint")
; Microsoft Office (OpenXML)
("vnd.ms-excel.addin.macroEnabled.12")
("vnd.ms-excel.sheet.binary.macroEnabled.12")
("vnd.ms-excel.sheet.macroEnabled.12")
("vnd.ms-excel.template.macroEnabled.12")
("vnd.ms-powerpoint.addin.macroEnabled.12")
("vnd.ms-powerpoint.presentation.macroEnabled.12")
("vnd.ms-powerpoint.slideshow.macroEnabled.12")
("vnd.ms-powerpoint.template.macroEnabled.12")
("vnd.ms-word.document.macroEnabled.12")
("vnd.ms-word.template.macroEnabled.12")
("vnd.openxmlformats-officedocument.presentationml.presentation")
("vnd.openxmlformats-officedocument.presentationml.slideshow")
("vnd.openxmlformats-officedocument.presentationml.template")
("vnd.openxmlformats-officedocument.spreadsheetml.sheet")
("vnd.openxmlformats-officedocument.spreadsheetml.template")
("vnd.openxmlformats-officedocument.wordprocessingml.document")
("vnd.openxmlformats-officedocument.wordprocessingml.template")
("vnd.ms-xpsdocument")
; Microsoft Project
("vnd.ms-project")
("vnd.ms-tnef")
("ms-tnef")
("x-kiss" ("x-cnf")))
("image"
("bmp")
("gif")
("jpeg")
("png")
("svg+xml")
("tiff")
("x-pic")
("x-mag")
("x-xwd")
("x-xbm"))
("audio"
("basic")
("mpeg")
("ogg")
("vorbis"))
("video"
("mpeg")
("ogg")
("mp4")
("quicktime")
("x-flv")))
"*Alist of content-type, subtype, parameters and its values.")
(defcustom mime-file-types
(eval-when-compile
(mapcar
(lambda (list)
(let ((name '(nil nil nil "name" nil nil "filename")))
(mapcar (lambda (elt)
(prog1
(if (and (car name)
(null (assoc (car name) elt)))
(nreverse `((,(car name) . file)
. ,(reverse elt)))
elt)
(setq name (cdr name))))
list)))
'(
;; Programming languages
("\\.cc$"
"application" "octet-stream" (("type" . "C++") ("charset" . charset))
"7bit"
"attachment" nil)
("\\.el$"
"application" "octet-stream" (("type" . "emacs-lisp") ("charset" . charset))
"7bit"
"attachment" nil)
("\\.lsp$"
"application" "octet-stream" (("type" . "common-lisp") ("charset" . charset))
"7bit"
"attachment" nil)
("\\.pl$"
"application" "octet-stream" (("type" . "perl") ("charset" . charset))
"7bit"
"attachment" nil)
;; Text or translated text
("\\.txt$\\|\\.pln$"
"text" "plain" (("charset" . charset))
nil
"inline" nil)
("\\.css$"
"text" "css" (("charset" . charset))
nil
"inline" nil)
("\\.csv$"
"text" "csv" (("charset" . charset))
nil
"inline" nil)
("\\.tex$\\|\\.latex$"
"text" "x-latex" (("charset" . charset))
nil
"inline" nil)
;; .rc : procmail modules pm-xxxx.rc
;; *rc : other resource files
("\\.\\(rc\\|lst\\|log\\|sql\\|mak\\)$\\|\\..*rc$"
"text" "plain" (("charset" . charset))
nil
"attachment" nil)
("\\.html$"
"text" "html" (("charset" . charset))
nil
nil nil)
("\\.diff$\\|\\.patch$"
"application" "octet-stream" (("type" . "patch"))
nil
"attachment" nil)
("\\.signature"
"text" "plain" (("charset" . charset)) nil nil nil)
("\\.js$"
"application" "javascript" (("charset" . charset))
nil
"inline" nil)
("\\.vcf$"
"text" "vcard" (("charset" . "UTF-8"))
nil
"inline" nil)
;; Microsoft Project
("\\.mpp$"
"application" "vnd.ms-project" nil
"base64"
"attachment" nil)
;; Microsoft Office (none-OpenXML)
("\\.rtf$" ; Rich text format
"application" "rtf" nil
"base64"
"attachment" nil)
("\\.doc$" ;MS Word
"application" "msword" nil
"base64"
"attachment" nil)
("\\.xls$" ; MS Excel
"application" "vnd.ms-excel" nil
"base64"
"attachment" nil)
("\\.ppt$" ; MS Power Point
"application" "vnd.ms-powerpoint" nil
"base64"
"attachment" nil)
;; Microsoft Office (OpenXML)
; MS Word
("\\.docm$"
"application" "vnd.ms-word.document.macroEnabled.12" nil
"base64"
"attachment" nil)
("\\.docx$"
"application" "vnd.openxmlformats-officedocument.wordprocessingml.document" nil
"base64"
"attachment" nil)
("\\.dotm$"
"application" "vnd.ms-word.template.macroEnabled.12" nil
"base64"
"attachment" nil)
("\\.dotx$"
"application" "vnd.openxmlformats-officedocument.wordprocessingml.template" nil
"base64"
"attachment" nil)
; MS Power Point
("\\.potm$"
"application" "vnd.ms-powerpoint.template.macroEnabled.12" nil
"base64"
"attachment" nil)
("\\.potx$"
"application" "vnd.openxmlformats-officedocument.presentationml.template" nil
"base64"
"attachment" nil)
("\\.ppam$"
"application" "vnd.ms-powerpoint.addin.macroEnabled.12" nil
"base64"
"attachment" nil)
("\\.ppsm$"
"application" "vnd.ms-powerpoint.slideshow.macroEnabled.12" nil
"base64"
"attachment" nil)
("\\.ppsx$"
"application" "vnd.openxmlformats-officedocument.presentationml.slideshow" nil
"base64"
"attachment" nil)
("\\.pptm$"
"application" "vnd.ms-powerpoint.presentation.macroEnabled.12" nil
"base64"
"attachment" nil)
("\\.pptx$"
"application" "vnd.openxmlformats-officedocument.presentationml.presentation" nil
"base64"
"attachment" nil)
; MS Excel
("\\.xlam$"
"application" "vnd.ms-excel.addin.macroEnabled.12" nil
"base64"
"attachment" nil)
("\\.xlsb$"
"application" "vnd.ms-excel.sheet.binary.macroEnabled.12" nil
"base64"
"attachment" nil)
("\\.xlsm$"
"application" "vnd.ms-excel.sheet.macroEnabled.12" nil
"base64"
"attachment" nil)
("\\.xlsx$"
"application" "vnd.openxmlformats-officedocument.spreadsheetml.sheet" nil
"base64"
"attachment" nil)
("\\.xltm$"
"application" "vnd.ms-excel.template.macroEnabled.12" nil
"base64"
"attachment" nil)
("\\.xltx$"
"application" "vnd.openxmlformats-officedocument.spreadsheetml.template" nil
"base64"
"attachment" nil)
;; Open Office
("\\.odt$"
"application" "vnd.oasis.opendocument.text" nil
"base64"
"attachment" nil)
("\\.ods$"
"application" "vnd.oasis.opendocument.spreadsheet" nil
"base64"
"attachment" nil)
("\\.odg$"
"application" "vnd.oasis.opendocument.graphics" nil
"base64"
"attachment" nil)
("\\.odf$"
"application" "vnd.oasis.opendocument.formula" nil
"base64"
"attachment" nil)
("\\.odm$"
"application" "vnd.oasis.opendocument.text-master" nil
"base64"
"attachment" nil)
("\\.odp$"
"application" "vnd.oasis.opendocument.presentation" nil
"base64"
"attachment" nil)
("\\.ott$"
"application" "vnd.oasis.opendocument.text-template" nil
"base64"
"attachment" nil)
("\\.ots$"
"application" "vnd.oasis.opendocument.spreadsheet-template" nil
"base64"
"attachment" nil)
("\\.otp$"
"application" "vnd.oasis.opendocument.presentation-template" nil
"base64"
"attachment" nil)
("\\.otg$"
"application" "vnd.oasis.opendocument.graphics-template" nil
"base64"
"attachment" nil)
;; Postscript and PDF
("\\.ps$"
"application" "postscript" nil
"base64"
"attachment" nil)
("\\.pdf$"
"application" "pdf" nil
"base64"
"attachment" nil)
;; Pure binary
("\\.jpg$\\|\\.jpeg$"
"image" "jpeg" nil
"base64"
"inline" nil)
("\\.gif$"
"image" "gif" nil
"base64"
"inline" nil)
("\\.png$"
"image" "png" nil
"base64"
"inline" nil)
("\\.bmp$"
"image" "bmp" nil
"base64"
"inline" nil)
("\\.svg$"
"image" "svg+xml" nil
"base64"
"inline" nil)
("\\.tiff$"
"image" "tiff" nil
"base64"
"inline" nil)
("\\.pic$"
"image" "x-pic" nil
"base64"
"inline" nil)
("\\.mag$"
"image" "x-mag" nil
"base64"
"inline" nil)
("\\.xbm$"
"image" "x-xbm" nil
"base64"
"inline" nil)
("\\.xwd$"
"image" "x-xwd" nil
"base64"
"inline" nil)
;; Audio and video
("\\.au$\\|\\.snd$"
"audio" "basic" nil
"base64"
"attachment" nil)
("\\.mp[234]\\|\\.m4[abp]$"
"audio" "mpeg" nil
"base64"
"attachment" nil)
("\\.ogg$"
"audio" "ogg" nil
"base64"
"attachment" nil)
("\\.ogg$"
"audio" "vorbis" nil
"base64"
"attachment" nil)
("\\.mpg\\|\\.mpeg$"
"video" "mpeg" nil
"base64"
"attachment" nil)
("\\.mp4\\|\\.m4v$"
"video" "mp4" nil
"base64"
"attachment" nil)
("\\.qt$\\|\\.mov$"
"video" "quicktime" nil
"base64"
"attachment" nil)
("\\.flv$"
"video" "x-flv" nil
"base64"
"attachment" nil)
("\\.swf$"
"application" "x-shockwave-flash" nil
"base64"
"attachment" nil)
;; Compressed files
("\\.tar\\.gz$"
"application" "octet-stream" (("type" . "tar+gzip"))
"base64"
"attachment" nil)
("\\.tgz$"
"application" "octet-stream" (("type" . "tar+gzip"))
"base64"
"attachment" nil)
("\\.tar\\.Z$"
"application" "octet-stream" (("type" . "tar+compress"))
"base64"
"attachment" nil)
("\\.taz$"
"application" "octet-stream" (("type" . "tar+compress"))
"base64"
"attachment" nil)
("\\.gz$"
"application" "octet-stream" (("type" . "gzip"))
"base64"
"attachment" nil)
("\\.Z$"
"application" "octet-stream" (("type" . "compress"))
"base64"
"attachment" nil)
("\\.lzh$"
"application" "octet-stream" (("type" . "lha"))
"base64"
"attachment" nil)
("\\.zip$"
"application" "zip" nil
"base64"
"attachment" nil)
("\\.7z$"
"application" "x-7z-compressed" nil
"base64"
"attachment" nil)
("winmail\\.dat$"
"application" "ms-tnef" nil
"base64"
"attachment" nil)
;; Rest
(".*"
"application" "octet-stream" nil
nil
"attachment" nil))))
"*Alist of file name, types, parameters, and default encoding.
If encoding is nil, it is determined from its contents."
:type `(repeat
(list regexp
;; primary-type
(choice :tag "Primary-Type"
,@(nconc (mapcar (lambda (cell)
(list 'item (car cell)))
mime-content-types)
'(string)))
;; subtype
(choice :tag "Sub-Type"
,@(nconc
(apply #'nconc
(mapcar (lambda (cell)
(mapcar (lambda (cell)
(list 'item (car cell)))
(cdr cell)))
mime-content-types))
'(string)))
;; parameters
(repeat :tag "Parameters of Content-Type field"
(cons string (choice string symbol)))
;; content-transfer-encoding
(choice :tag "Encoding"
,@(cons
'(const nil)
(mapcar (lambda (cell)
(list 'item cell))
(mime-encoding-list))))
;; disposition-type
(choice :tag "Disposition-Type"
(item nil)
(item "inline")
(item "attachment")
string)
;; parameters
(repeat :tag "Parameters of Content-Disposition field"
(cons string (choice string symbol)))))
:group 'mime-edit)
(defvar mime-edit-debug nil)
;;; @@ about charset, encoding and transfer-level
;;;
(defvar mime-charset-type-list
'((us-ascii 7 nil)
(iso-8859-1 8 "quoted-printable")
(iso-8859-2 8 "quoted-printable")
(iso-8859-3 8 "quoted-printable")
(iso-8859-4 8 "quoted-printable")
(iso-8859-5 8 "quoted-printable")
(koi8-r 8 "quoted-printable")
(iso-8859-7 8 "quoted-printable")
(iso-8859-8 8 "quoted-printable")
(iso-8859-9 8 "quoted-printable")
(iso-8859-14 8 "quoted-printable")
(iso-8859-15 8 "quoted-printable")
(iso-2022-jp 7 "base64")
(iso-2022-jp-3 7 "base64")
(iso-2022-kr 7 "base64")
(euc-kr 8 "base64")
(cn-gb 8 "base64")
(gb2312 8 "base64")
(cn-big5 8 "base64")
(big5 8 "base64")
(shift_jis 8 "base64")
(tis-620 8 "base64")
(iso-2022-jp-2 7 "base64")
(iso-2022-int-1 7 "base64")))
(defvar-local mime-transfer-level 7
"*A number of network transfer level. It should be 7 or bigger.")
(defsubst mime-encoding-name (transfer-level &optional not-omit)
(cond ((> transfer-level 8) "binary")
((= transfer-level 8) "8bit")
(not-omit "7bit")))
(defvar-local mime-transfer-level-string
(mime-encoding-name mime-transfer-level 'not-omit)
"A string formatted version of mime-transfer-level")
;;; @@ about content transfer encoding
(defvar mime-content-transfer-encoding-priority-list
'(nil "8bit" "binary"))
;;; @@ about message inserting
;;;
(defvar mime-edit-yank-ignored-field-list
'("Received" "Approved" "Path" "Replied" "Status"
"Xref" "X-UIDL" "X-Filter" "X-Gnus-.*" "X-VM-.*")
"Delete these fields from original message when it is inserted
as message/rfc822 part.
Each elements are regexp of field-name.")
(defvar mime-edit-yank-ignored-field-regexp
(concat "^"
(apply (function regexp-or) mime-edit-yank-ignored-field-list)
":"))
(defvar mime-edit-message-inserter-alist nil)
(defvar mime-edit-mail-inserter-alist nil)
;;; @@ about message splitting
;;;
(defcustom mime-edit-split-message nil
"*Split large message if it is non-nil."
:group 'mime-edit
:type 'boolean)
(defcustom mime-edit-message-default-max-lines 1000
"*Default maximum lines of a message."
:group 'mime-edit
:type 'integer)
(defcustom mime-edit-message-max-lines-alist
'((news-reply-mode . 500))
"Alist of major-mode vs maximum lines of a message.
If it is not specified for a major-mode,
`mime-edit-message-default-max-lines' is used."
:group 'mime-edit
:type '(repeat (cons (symbol :tag "major-mode")
(integer :tag "maximum lines"))))
(defconst mime-edit-split-ignored-field-regexp
"\\(^Content-\\|^Subject:\\|^Mime-Version:\\|^Message-Id:\\)")
(defcustom mime-edit-split-blind-field-regexp
"\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)"
"*Regular expression to match field-name to be ignored when split sending."
:group 'mime-edit
:type 'regexp)
(defvar mime-edit-split-message-sender-alist nil)
(defvar mime-edit-news-reply-mode-server-running nil)
;;; @@ about PGP/MIME
;;;
(defgroup mime-edit-pgp nil
"MIME edit mode (PGP/MIME)"
:group 'mime-edit)
(defcustom mime-edit-pgp-verbose nil
"If non-nil, ask the user about the current operation more verbosely."
:group 'mime-edit-pgp
:type 'boolean)
(defcustom mime-edit-pgp-signers nil
"A list of your own key ID which will be preferredly used to sign a message."
:group 'mime-edit-pgp
:type '(repeat (string :tag "Key ID")))
(defcustom mime-edit-pgp-encrypt-to-self t
"If t, add your own key ID to recipient list when encryption."
:group 'mime-edit-pgp
:type 'boolean)
(defcustom mime-edit-pgp-filtered-validities
'(invalid disabled revoked expired never)
"A list of keys's validities which are not used for signing and encrypting."
:group 'mime-edit-pgp
:type
'(choice
(const :tag "Any keys are used." nil)
(repeat (choice (const unknow)
(const invalid)
(const disabled)
(const revoked)
(const expired)
(const none)
(const undefined)
(const never)
(const marginal)
(const full)
(const ultimate)))))
;;; @@ about tag
;;;
(defconst mime-edit-single-part-tag-regexp
"--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
"*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
(defconst mime-edit-quoted-single-part-tag-regexp
(concat "- " (substring mime-edit-single-part-tag-regexp 1)))
(defconst mime-edit-multipart-beginning-regexp "--<<\\([^<>]+\\)>>-{\n")
(defconst mime-edit-multipart-end-regexp "--}-<<\\([^<>]+\\)>>\n")
(defconst mime-edit-beginning-tag-regexp
(regexp-or mime-edit-single-part-tag-regexp
mime-edit-multipart-beginning-regexp))
(defconst mime-edit-end-tag-regexp
(regexp-or mime-edit-single-part-tag-regexp
mime-edit-multipart-end-regexp))
(defconst mime-edit-tag-regexp
(regexp-or mime-edit-single-part-tag-regexp
mime-edit-multipart-beginning-regexp
mime-edit-multipart-end-regexp))
(defvar mime-tag-format "--[[%s]]"
"*Control-string making a MIME tag.")
(defvar mime-tag-format-with-encoding "--[[%s][%s]]"
"*Control-string making a MIME tag with encoding.")
;;; @@ multipart boundary
;;;
(defvar mime-multipart-boundary "Multipart"
"*Boundary of a multipart message.")
;;; @@ optional header fields
;;;
(defvar mime-edit-insert-user-agent-field t
"*If non-nil, insert User-Agent header field.")
(defvar mime-edit-user-agent-value
(concat (mime-product-name mime-user-interface-product)
"/"
(mapconcat #'number-to-string
(mime-product-version mime-user-interface-product) ".")
" ("
(mime-product-code-name mime-user-interface-product)
") "
(mime-product-name mime-library-product)
"/"
(mapconcat #'number-to-string
(mime-product-version mime-library-product) ".")
" ("
(mime-product-code-name mime-library-product)
") "
(if (fboundp 'apel-version)
(concat (apel-version) " "))
(if (boundp 'epg-version-number)
(concat "EasyPG/" epg-version-number " "))
(let ((ver (if (and (not (boundp 'emacs-build-number))
(string-match "\\.[0-9]+$" emacs-version))
(substring emacs-version 0 (match-beginning 0))
emacs-version)))
(concat "Emacs/" ver " (" system-configuration ")"
(if (boundp 'mule-version)
(concat " MULE/" mule-version)))))
"Body of User-Agent field.
If variable `mime-edit-insert-user-agent-field' is not nil, it is
inserted into message header.")
;;; @ constants
;;;
(defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
"*Specify MIME tspecials.
Tspecials means any character that matches with it in header must be quoted.")
(defconst mime-edit-mime-version-value
(concat "1.0 (generated by " mime-edit-version ")")
"MIME version number.")
(defconst mime-edit-mime-version-field-for-message/partial
(concat "MIME-Version:"
(mime-encode-field-body
(concat " 1.0 (split by " mime-edit-version ")\n")
"MIME-Version"))
"MIME version field for message/partial.")
;;; @ keymap and menu
;;;
(defvar-local mime-edit-mode-flag nil)
(defvar mime-edit-mode-entity-prefix "\C-c\C-x"
"Keymap prefix for MIME-Edit mode commands to insert entity or set status.")
(defvar mime-edit-mode-entity-map (make-sparse-keymap)
"Keymap for MIME-Edit mode commands to insert entity or set status.")
(define-key mime-edit-mode-entity-map "\C-t" 'mime-edit-insert-text)
(define-key mime-edit-mode-entity-map "\C-i" 'mime-edit-insert-file)
(define-key mime-edit-mode-entity-map "i" 'mime-edit-insert-file-as-text)
(define-key mime-edit-mode-entity-map "\C-e" 'mime-edit-insert-external)
(define-key mime-edit-mode-entity-map "\C-v" 'mime-edit-insert-voice)
(define-key mime-edit-mode-entity-map "\C-y" 'mime-edit-insert-message)
(define-key mime-edit-mode-entity-map "\C-m" 'mime-edit-insert-mail)
(define-key mime-edit-mode-entity-map "\C-w" 'mime-edit-insert-signature)
(define-key mime-edit-mode-entity-map "\C-s" 'mime-edit-insert-signature)
(define-key mime-edit-mode-entity-map "\C-k" 'mime-edit-insert-key)
(define-key mime-edit-mode-entity-map "t" 'mime-edit-insert-tag)
(define-key mime-edit-mode-entity-map "7" 'mime-edit-set-transfer-level-7bit)
(define-key mime-edit-mode-entity-map "8" 'mime-edit-set-transfer-level-8bit)
(define-key mime-edit-mode-entity-map "/" 'mime-edit-set-split)
(define-key mime-edit-mode-entity-map "s" 'mime-edit-set-sign)
(define-key mime-edit-mode-entity-map "v" 'mime-edit-set-sign)
(define-key mime-edit-mode-entity-map "e" 'mime-edit-set-encrypt)
(define-key mime-edit-mode-entity-map "h" 'mime-edit-set-encrypt)
(define-key mime-edit-mode-entity-map "p" 'mime-edit-preview-message)
(define-key mime-edit-mode-entity-map "\C-z" 'mime-edit-exit)
(define-key mime-edit-mode-entity-map "?" 'mime-edit-help)
(defvar mime-edit-mode-enclosure-prefix "\C-c\C-m"