Delete mmgeneric.el.
[elisp/flim.git] / ew-var.el
1 (provide 'ew-var)
2
3 ;;; user customizable variables.
4
5 (defvar ew-decode-sticked-encoded-word nil)
6 (defvar ew-decode-quoted-encoded-word nil)
7 (defvar ew-ignore-75bytes-limit nil)
8 (defvar ew-ignore-76bytes-limit nil)
9 (defvar ew-permit-sticked-comment nil)
10 (defvar ew-permit-sticked-special nil)
11 (defvar ew-permit-null-encoded-text nil)
12
13 (defvar ew-remove-bare-crlf nil)
14 (defvar ew-default-mime-charset 'x-ctext)
15
16 ;;;
17 (defvar ew-decode-field-syntax-alist
18   '(
19 ;;; std11 (rfc822, rfc1123)
20     (from                 ew-scan-unibyte-std11 . ew:tag-mailbox+)
21     (sender               ew-scan-unibyte-std11 . ew:tag-mailbox)
22     (to                   ew-scan-unibyte-std11 . ew:tag-address+)
23     (resent-to            ew-scan-unibyte-std11 . ew:tag-address+)
24     (cc                   ew-scan-unibyte-std11 . ew:tag-address+)
25     (resent-cc            ew-scan-unibyte-std11 . ew:tag-address+)
26     (bcc                  ew-scan-unibyte-std11 . ew:tag-address*)
27     (resent-bcc           ew-scan-unibyte-std11 . ew:tag-address*)
28     (message-id           ew-scan-unibyte-std11)
29     (resent-message-id    ew-scan-unibyte-std11)
30     (in-reply-to          ew-scan-unibyte-std11 . ew:tag-phrase-msg-id*)
31     (references           ew-scan-unibyte-std11 . ew:tag-phrase-msg-id*)
32     (keywords             ew-scan-unibyte-std11 . ew:tag-phrase*)
33     (subject              ew-scan-unibyte-unstructured)
34     (comments             ew-scan-unibyte-unstructured)
35     (encrypted            ew-scan-unibyte-std11)
36     (date                 ew-scan-unibyte-std11)
37     (reply-to             ew-scan-unibyte-std11 . ew:tag-address+)
38     (received             ew-scan-unibyte-std11)
39     (resent-reply-to      ew-scan-unibyte-std11 . ew:tag-address+)
40     (resent-from          ew-scan-unibyte-std11 . ew:tag-mailbox+)
41     (resent-sender        ew-scan-unibyte-std11 . ew:tag-mailbox)
42     (resent-date          ew-scan-unibyte-std11)
43     (return-path          ew-scan-unibyte-std11)
44 ;;; rfc1049
45     ;; (content-type         ew-scan-unibyte-std11)
46 ;;; rfc2045
47     (mime-version         ew-scan-unibyte-std11)
48     (content-type         ew-scan-unibyte-mime)
49     (content-transfer-encoding    ew-scan-unibyte-mime)
50     (content-id           ew-scan-unibyte-std11)
51     (content-description  ew-scan-unibyte-unstructured)
52 ;;; rfc2183
53     (content-disposition  ew-scan-unibyte-mime)
54 ;;; rfc1864
55     (content-md5          ew-scan-unibyte-none)
56 ;;; rfc2076
57     (status               ew-scan-unibyte-none)
58 ;;; draft-ietf-drums-msg-fmt-05
59     ;; (date                 ew-scan-unibyte-std11)
60     ;; (from                 ew-scan-unibyte-std11 . ew:tag-mailbox+)
61     ;; (sender               ew-scan-unibyte-std11 . ew:tag-mailbox)
62     ;; (reply-to             ew-scan-unibyte-std11 . ew:tag-address+)
63     ;; (to                   ew-scan-unibyte-std11 . ew:tag-address+)
64     ;; (cc                   ew-scan-unibyte-std11 . ew:tag-address+)
65     ;; (bcc                  ew-scan-unibyte-std11 . ew:tag-address*)
66     ;; (message-id           ew-scan-unibyte-std11)
67     ;; (in-reply-to          ew-scan-unibyte-std11)
68     ;; (references           ew-scan-unibyte-std11)
69     ;; (subject              ew-scan-unibyte-unstructured)
70     ;; (comments             ew-scan-unibyte-unstructured)
71     ;; (keywords             ew-scan-unibyte-std11 . ew:tag-phrase*)
72     ;; (resent-date          ew-scan-unibyte-std11)
73     ;; (resent-from          ew-scan-unibyte-std11 . ew:tag-mailbox+)
74     ;; (resent-sender        ew-scan-unibyte-std11 . ew:tag-mailbox)
75     ;; (resent-to            ew-scan-unibyte-std11 . ew:tag-address+)
76     ;; (resent-cc            ew-scan-unibyte-std11 . ew:tag-address+)
77     ;; (resent-bcc           ew-scan-unibyte-std11 . ew:tag-address*)
78     ;; (resent-message-id    ew-scan-unibyte-std11)
79     ;; (return-path          ew-scan-unibyte-std11)
80     ;; (received             ew-scan-unibyte-std11)
81 ;;; draft-ietf-drums-mail-followup-to-00
82     (mail-followup-to     ew-scan-unibyte-std11 . ew:tag-mailbox+)
83 ;;; draft-ietf-usefor-article-01
84     ;; (date                 ew-scan-unibyte-std11)
85     ;; (from                 ew-scan-unibyte-std11 . ew:tag-mailbox+)
86     ;; (message-id           ew-scan-unibyte-std11)
87     ;; (subject              ew-scan-unibyte-unstructured)
88     (newsgroups           ew-scan-unibyte-none)
89     (path                 ew-scan-unibyte-none)
90     (followup-to          ew-scan-unibyte-none)
91     (expires              ew-scan-unibyte-std11)
92     ;; (reply-to             ew-scan-unibyte-std11 . ew:tag-address+)
93     ;; (references           ew-scan-unibyte-std11 . ew:tag-phrase-msg-id*)
94     (control              ew-scan-unibyte-none)
95     (distribution         ew-scan-unibyte-none)
96     ;; (keywords             ew-scan-unibyte-std11 . ew:tag-phrase*)
97     (summary              ew-scan-unibyte-unstructured)
98     (approved             ew-scan-unibyte-std11 . ew:tag-mailbox+)
99     (lines                ew-scan-unibyte-none)
100     (xref                 ew-scan-unibyte-none)
101     (organization         ew-scan-unibyte-unstructured)
102     (user-agent           ew-scan-unibyte-mime)
103     (supersedes           ew-scan-unibyte-std11)
104     (replaces             ew-scan-unibyte-std11)
105     (replaced-by          ew-scan-unibyte-std11)
106     (archive              ew-scan-unibyte-none)
107 ;;; draft-ietf-usefor-posted-mailed-01
108     (posted-and-mailed    ew-scan-unibyte-none)
109     (followup-host        ew-scan-unibyte-none) ; news-url
110 ;;; draft-ietf-mailext-new-fields-13
111     (auto-submitted       ew-scan-unibyte-mime)
112     ;; (supersedes           ew-scan-unibyte-std11)
113     ;; (expires              ew-scan-unibyte-std11)
114 ;;; others
115     (x-face               ew-scan-unibyte-none)
116     (x-face-version       ew-scan-unibyte-none)
117     (x-pgp-sig            ew-scan-unibyte-none)
118     (x-pgp-sig-version    ew-scan-unibyte-none)
119     (x-pgp-key-info       ew-scan-unibyte-none)
120     (x-info               ew-scan-unibyte-none)
121     ))
122
123 (defvar ew-decode-field-default-syntax '(ew-scan-unibyte-unstructured))
124
125 (defvar ew-parse-error-sit-for-seconds 0)
126
127 ;;; constants.
128
129 (defconst ew-token-regexp "[-!#-'*+0-9A-Z^-~]+")
130 (defconst ew-encoded-text-regexp "[!->@-~]*")
131
132 (defconst ew-encoded-word-regexp
133   (concat (regexp-quote "=?")
134           "\\(" ew-token-regexp "\\)"
135           (regexp-quote "?")
136           "\\(" ew-token-regexp "\\)"
137           (regexp-quote "?")
138           "\\(" ew-encoded-text-regexp "\\)"
139           (regexp-quote "?=")))
140
141 (defconst ew-anchored-encoded-word-regexp
142   (concat "\\`" ew-encoded-word-regexp "\\'"))
143
144 (defconst ew-b-regexp
145   (eval-when-compile
146     (concat "\\`\\("
147             "[A-Za-z0-9+/]"
148             "[A-Za-z0-9+/]"
149             "[A-Za-z0-9+/]"
150             "[A-Za-z0-9+/]"
151             "\\)*"
152             "\\("
153             "[A-Za-z0-9+/]"
154             "[A-Za-z0-9+/]"
155             "\\(==\\|[A-Za-z0-9+/]=\\)"
156             "\\)?"
157             "\\'")))
158
159 (defconst ew-q-regexp
160   "\\`\\([^=?]\\|=[0-9A-Fa-f][0-9A-Fa-f]\\)*\\'")
161
162 (defconst ew-quoting-char ?+)
163 (defconst ew-quoting-chars-regexp
164   (concat (regexp-quote (char-to-string ew-quoting-char)) "*"))
165
166 (defconst ew-type2-regexp
167   (concat (regexp-quote "=?")
168           "\\(" ew-token-regexp "\\)"
169           (regexp-quote "?")
170           "\\(" ew-token-regexp "\\)"
171           (regexp-quote "?")
172           "\\(" ew-encoded-text-regexp "\\)"
173           (regexp-quote "?")
174           "\\'"))
175
176 (defconst ew-byte-decoder-alist
177   '(("B" . ew-decode-b)
178     ("Q" . ew-decode-q)))
179
180 (defconst ew-byte-checker-alist
181   '(("B" . ew-b-check)
182     ("Q" . ew-q-check)))
183
184 ;;; utilities for variables.
185
186 (defconst ew-option-list
187   '(ew-decode-sticked-encoded-word
188     ew-decode-quoted-encoded-word
189     ew-ignore-75bytes-limit
190     ew-ignore-76bytes-limit
191     ew-permit-sticked-comment
192     ew-permit-sticked-special
193     ew-permit-null-encoded-text))
194
195 (defun ew-save-boolean-options ()
196   (let ((tmp 1) (opts ew-option-list) (val 0))
197     (while opts
198       (when (symbol-value (car opts)) (setq val (logior val tmp)))
199       (setq tmp (lsh tmp 1)
200             opts (cdr opts)))
201     val))
202
203 (defun ew-restore-boolean-options (val)
204   (let ((tmp 1) (opts ew-option-list))
205     (while opts
206       (set (car opts) (not (zerop (logand val tmp))))
207       (setq tmp (lsh tmp 1)
208             opts (cdr opts)))))
209
210 (defun ew-dynamic-options ()
211   (cons
212    ew-default-mime-charset
213    (ew-save-boolean-options)))
214