* smime.el (from):
[emacs.git] / lisp / gnus / mm-uu.el
blob18ff2ae0838ec60c900c40e9609aa13ca1a6884b
1 ;;; mm-uu.el --- Return uu stuff as mm handles
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
7 ;; Keywords: postscript uudecode binhex shar forward gnatsweb pgp
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
26 ;;; Commentary:
28 ;;; Code:
30 (eval-when-compile (require 'cl))
31 (require 'mail-parse)
32 (require 'nnheader)
33 (require 'mm-decode)
34 (require 'mailcap)
35 (require 'mml2015)
37 (autoload 'uudecode-decode-region "uudecode")
38 (autoload 'uudecode-decode-region-external "uudecode")
39 (autoload 'uudecode-decode-region-internal "uudecode")
41 (autoload 'binhex-decode-region "binhex")
42 (autoload 'binhex-decode-region-external "binhex")
43 (autoload 'binhex-decode-region-internal "binhex")
45 (autoload 'yenc-decode-region "yenc")
46 (autoload 'yenc-extract-filename "yenc")
48 (defcustom mm-uu-decode-function 'uudecode-decode-region
49 "*Function to uudecode.
50 Internal function is done in Lisp by default, therefore decoding may
51 appear to be horribly slow. You can make Gnus use an external
52 decoder, such as uudecode."
53 :type '(choice
54 (function-item :tag "Auto detect" uudecode-decode-region)
55 (function-item :tag "Internal" uudecode-decode-region-internal)
56 (function-item :tag "External" uudecode-decode-region-external))
57 :group 'gnus-article-mime)
59 (defcustom mm-uu-binhex-decode-function 'binhex-decode-region
60 "*Function to binhex decode.
61 Internal function is done in elisp by default, therefore decoding may
62 appear to be horribly slow . You can make Gnus use the external Unix
63 decoder, such as hexbin."
64 :type '(choice (function-item :tag "Auto detect" binhex-decode-region)
65 (function-item :tag "Internal" binhex-decode-region-internal)
66 (function-item :tag "External" binhex-decode-region-external))
67 :group 'gnus-article-mime)
69 (defvar mm-uu-yenc-decode-function 'yenc-decode-region)
71 (defvar mm-uu-beginning-regexp nil)
73 (defvar mm-dissect-disposition "inline"
74 "The default disposition of uu parts.
75 This can be either \"inline\" or \"attachment\".")
77 (defcustom mm-uu-emacs-sources-regexp "\\.emacs\\.sources"
78 "The regexp of Emacs sources groups."
79 :version "22.1"
80 :type 'regexp
81 :group 'gnus-article-mime)
83 (defcustom mm-uu-diff-groups-regexp
84 "\\(gmane\\|gnu\\)\\..*\\(diff\\|commit\\|cvs\\|bug\\|devel\\)"
85 "Regexp matching diff groups."
86 :version "22.1"
87 :type 'regexp
88 :group 'gnus-article-mime)
90 (defcustom mm-uu-tex-groups-regexp "\\.tex\\>"
91 "*Regexp matching TeX groups."
92 :version "23.0"
93 :type 'regexp
94 :group 'gnus-article-mime)
96 (defvar mm-uu-type-alist
97 '((postscript
98 "^%!PS-"
99 "^%%EOF$"
100 mm-uu-postscript-extract
101 nil)
102 (uu ;; Maybe we should have a more strict test here.
103 "^begin[ \t]+0?[0-7][0-7][0-7][ \t]+"
104 "^end[ \t]*$"
105 mm-uu-uu-extract
106 mm-uu-uu-filename)
107 (binhex
108 "^:.\\{63,63\\}$"
109 ":$"
110 mm-uu-binhex-extract
112 mm-uu-binhex-filename)
113 (yenc
114 "^=ybegin.*size=[0-9]+.*name=.*$"
115 "^=yend.*size=[0-9]+"
116 mm-uu-yenc-extract
117 mm-uu-yenc-filename)
118 (shar
119 "^#! */bin/sh"
120 "^exit 0$"
121 mm-uu-shar-extract)
122 (forward
123 ;; Thanks to Edward J. Sabol <sabol@alderaan.gsfc.nasa.gov> and
124 ;; Peter von der Ah\'e <pahe@daimi.au.dk>
125 "^-+ \\(Start of \\)?Forwarded message"
126 "^-+ End \\(of \\)?forwarded message"
127 mm-uu-forward-extract
129 mm-uu-forward-test)
130 (gnatsweb
131 "^----gnatsweb-attachment----"
133 mm-uu-gnatsweb-extract)
134 (pgp-signed
135 "^-----BEGIN PGP SIGNED MESSAGE-----"
136 "^-----END PGP SIGNATURE-----"
137 mm-uu-pgp-signed-extract
139 nil)
140 (pgp-encrypted
141 "^-----BEGIN PGP MESSAGE-----"
142 "^-----END PGP MESSAGE-----"
143 mm-uu-pgp-encrypted-extract
145 nil)
146 (pgp-key
147 "^-----BEGIN PGP PUBLIC KEY BLOCK-----"
148 "^-----END PGP PUBLIC KEY BLOCK-----"
149 mm-uu-pgp-key-extract
150 mm-uu-gpg-key-skip-to-last
151 nil)
152 (emacs-sources
153 "^;;;?[ \t]*[^ \t]+\\.el[ \t]*--"
154 "^;;;?[ \t]*\\([^ \t]+\\.el\\)[ \t]+ends here"
155 mm-uu-emacs-sources-extract
157 mm-uu-emacs-sources-test)
158 (diff
159 "^Index: "
161 mm-uu-diff-extract
163 mm-uu-diff-test)
164 (message-marks
165 ;; Text enclosed with tags similar to `message-mark-insert-begin' and
166 ;; `message-mark-insert-end'. Don't use those variables to avoid
167 ;; dependency on `message.el'.
168 "^-+[8<>]*-\\{9,\\}[a-z ]+-\\{9,\\}[a-z ]+-\\{9,\\}[8<>]*-+$"
169 "^-+[8<>]*-\\{9,\\}[a-z ]+-\\{9,\\}[a-z ]+-\\{9,\\}[8<>]*-+$"
170 (lambda () (mm-uu-verbatim-marks-extract 0 -1 1 -1))
171 nil)
172 ;; Omitting [a-z8<] leads to false positives (bogus signature separators
173 ;; and mailing list banners).
174 (insert-marks
175 "^ *\\(-\\|_\\)\\{30,\\}.*[a-z8<].*\\(-\\|_\\)\\{30,\\} *$"
176 "^ *\\(-\\|_\\)\\{30,\\}.*[a-z8<].*\\(-\\|_\\)\\{30,\\} *$"
177 (lambda () (mm-uu-verbatim-marks-extract 0 0 1 -1))
178 nil)
179 (verbatim-marks
180 ;; slrn-style verbatim marks, see
181 ;; http://www.slrn.org/manual/slrn-manual-6.html#ss6.81
182 "^#v\\+"
183 "^#v\\-$"
184 (lambda () (mm-uu-verbatim-marks-extract 0 0))
185 nil)
186 (LaTeX
187 "^\\([\\\\%][^\n]+\n\\)*\\\\documentclass.*[[{%]"
188 "^\\\\end{document}"
189 mm-uu-latex-extract
191 mm-uu-latex-test))
192 "A list of specifications for non-MIME attachments.
193 Each element consist of the following entries: label,
194 start-regexp, end-regexp, extract-function, test-function.
196 After modifying this list you must run \\[mm-uu-configure].
198 You can disable elements from this list by customizing
199 `mm-uu-configure-list'.")
201 (defcustom mm-uu-configure-list '((shar . disabled))
202 "A list of mm-uu configuration.
203 To disable dissecting shar codes, for instance, add
204 `(shar . disabled)' to this list."
205 :type 'alist
206 :options (mapcar (lambda (entry)
207 (list (car entry) '(const disabled)))
208 mm-uu-type-alist)
209 :group 'gnus-article-mime)
211 (defvar mm-uu-text-plain-type '("text/plain" (charset . gnus-decoded))
212 "MIME type and parameters for text/plain parts.
213 `gnus-decoded' is a fake charset, which means no further decoding.")
215 ;; functions
217 (defsubst mm-uu-type (entry)
218 (car entry))
220 (defsubst mm-uu-beginning-regexp (entry)
221 (nth 1 entry))
223 (defsubst mm-uu-end-regexp (entry)
224 (nth 2 entry))
226 (defsubst mm-uu-function-extract (entry)
227 (nth 3 entry))
229 (defsubst mm-uu-function-1 (entry)
230 (nth 4 entry))
232 (defsubst mm-uu-function-2 (entry)
233 (nth 5 entry))
235 ;; In Emacs 22, we could use `min-colors' in the face definition. But Emacs
236 ;; 21 and XEmacs don't support it.
237 (defcustom mm-uu-hide-markers
238 (< 16 (or (and (fboundp 'defined-colors)
239 (length (defined-colors)))
240 (and (fboundp 'device-color-cells)
241 (device-color-cells))
243 "If non-nil, hide verbatim markers.
244 The value should be nil on displays where the face
245 `mm-uu-extract' isn't distinguishable to the face `default'."
246 :type '(choice (const :tag "Hide" t)
247 (const :tag "Don't hide" nil))
248 :version "23.0" ;; No Gnus
249 :group 'gnus-article-mime)
251 (defface mm-uu-extract '(;; Colors from `gnus-cite-3' plus background:
252 (((class color)
253 (background dark))
254 (:foreground "light yellow"
255 :background "dark green"))
256 (((class color)
257 (background light))
258 (:foreground "dark green"
259 :background "light yellow"))
261 ()))
262 "Face for extracted buffers."
263 ;; See `mm-uu-verbatim-marks-extract'.
264 :version "23.0" ;; No Gnus
265 :group 'gnus-article-mime)
267 (defun mm-uu-copy-to-buffer (&optional from to properties)
268 "Copy the contents of the current buffer to a fresh buffer.
269 Return that buffer.
271 If PROPERTIES is non-nil, PROPERTIES are applied to the buffer,
272 see `set-text-properties'. If PROPERTIES equals t, this means to
273 apply the face `mm-uu-extract'."
274 (let ((obuf (current-buffer))
275 (coding-system
276 ;; Might not exist in non-MULE XEmacs
277 (when (boundp 'buffer-file-coding-system)
278 buffer-file-coding-system)))
279 (with-current-buffer (generate-new-buffer " *mm-uu*")
280 (setq buffer-file-coding-system coding-system)
281 (insert-buffer-substring obuf from to)
282 (cond ((eq properties t)
283 (set-text-properties (point-min) (point-max)
284 '(face mm-uu-extract)))
285 (properties
286 (set-text-properties (point-min) (point-max) properties)))
287 (current-buffer))))
289 (defun mm-uu-configure-p (key val)
290 (member (cons key val) mm-uu-configure-list))
292 (defun mm-uu-configure (&optional symbol value)
293 "Configure detection of non-MIME attachments."
294 (interactive)
295 (if symbol (set-default symbol value))
296 (setq mm-uu-beginning-regexp nil)
297 (mapcar (lambda (entry)
298 (if (mm-uu-configure-p (mm-uu-type entry) 'disabled)
300 (setq mm-uu-beginning-regexp
301 (concat mm-uu-beginning-regexp
302 (if mm-uu-beginning-regexp "\\|")
303 (mm-uu-beginning-regexp entry)))))
304 mm-uu-type-alist))
306 (mm-uu-configure)
308 (defvar file-name)
309 (defvar start-point)
310 (defvar end-point)
311 (defvar entry)
313 (defun mm-uu-uu-filename ()
314 (if (looking-at ".+")
315 (setq file-name
316 (let ((nnheader-file-name-translation-alist
317 '((?/ . ?,) (?\ . ?_) (?* . ?_) (?$ . ?_))))
318 (nnheader-translate-file-chars (match-string 0))))))
320 (defun mm-uu-binhex-filename ()
321 (setq file-name
322 (ignore-errors
323 (binhex-decode-region start-point end-point t))))
325 (defun mm-uu-yenc-filename ()
326 (goto-char start-point)
327 (setq file-name
328 (ignore-errors
329 (yenc-extract-filename))))
331 (defun mm-uu-forward-test ()
332 (save-excursion
333 (goto-char start-point)
334 (forward-line)
335 (looking-at "[\r\n]*[a-zA-Z][a-zA-Z0-9-]*:")))
337 (defun mm-uu-postscript-extract ()
338 (mm-make-handle (mm-uu-copy-to-buffer start-point end-point)
339 '("application/postscript")))
341 (defun mm-uu-verbatim-marks-extract (start-offset end-offset
342 &optional
343 start-hide
344 end-hide)
345 (let ((start (or (and mm-uu-hide-markers
346 start-hide)
347 start-offset
349 (end (or (and mm-uu-hide-markers
350 end-hide)
351 end-offset
352 -1)))
353 (mm-make-handle
354 (mm-uu-copy-to-buffer
355 (progn (goto-char start-point)
356 (forward-line start)
357 (point))
358 (progn (goto-char end-point)
359 (forward-line end)
360 (point))
362 '("text/x-verbatim" (charset . gnus-decoded)))))
364 (defun mm-uu-latex-extract ()
365 (mm-make-handle
366 (mm-uu-copy-to-buffer start-point end-point t)
367 ;; application/x-tex?
368 '("text/x-verbatim" (charset . gnus-decoded))))
370 (defun mm-uu-emacs-sources-extract ()
371 (mm-make-handle (mm-uu-copy-to-buffer start-point end-point)
372 '("application/emacs-lisp" (charset . gnus-decoded))
373 nil nil
374 (list mm-dissect-disposition
375 (cons 'filename file-name))))
377 (defvar gnus-newsgroup-name)
379 (defun mm-uu-emacs-sources-test ()
380 (setq file-name (match-string 1))
381 (and gnus-newsgroup-name
382 mm-uu-emacs-sources-regexp
383 (string-match mm-uu-emacs-sources-regexp gnus-newsgroup-name)))
385 (defun mm-uu-diff-extract ()
386 (mm-make-handle (mm-uu-copy-to-buffer start-point end-point)
387 '("text/x-patch" (charset . gnus-decoded))))
389 (defun mm-uu-diff-test ()
390 (and gnus-newsgroup-name
391 mm-uu-diff-groups-regexp
392 (string-match mm-uu-diff-groups-regexp gnus-newsgroup-name)))
394 (defun mm-uu-latex-test ()
395 (and gnus-newsgroup-name
396 mm-uu-tex-groups-regexp
397 (string-match mm-uu-tex-groups-regexp gnus-newsgroup-name)))
399 (defun mm-uu-forward-extract ()
400 (mm-make-handle (mm-uu-copy-to-buffer
401 (progn (goto-char start-point) (forward-line) (point))
402 (progn (goto-char end-point) (forward-line -1) (point)))
403 '("message/rfc822" (charset . gnus-decoded))))
405 (defun mm-uu-uu-extract ()
406 (mm-make-handle (mm-uu-copy-to-buffer start-point end-point)
407 (list (or (and file-name
408 (string-match "\\.[^\\.]+$"
409 file-name)
410 (mailcap-extension-to-mime
411 (match-string 0 file-name)))
412 "application/octet-stream"))
413 'x-uuencode nil
414 (if (and file-name (not (equal file-name "")))
415 (list mm-dissect-disposition
416 (cons 'filename file-name)))))
418 (defun mm-uu-binhex-extract ()
419 (mm-make-handle (mm-uu-copy-to-buffer start-point end-point)
420 (list (or (and file-name
421 (string-match "\\.[^\\.]+$" file-name)
422 (mailcap-extension-to-mime
423 (match-string 0 file-name)))
424 "application/octet-stream"))
425 'x-binhex nil
426 (if (and file-name (not (equal file-name "")))
427 (list mm-dissect-disposition
428 (cons 'filename file-name)))))
430 (defun mm-uu-yenc-extract ()
431 (mm-make-handle (mm-uu-copy-to-buffer start-point end-point)
432 (list (or (and file-name
433 (string-match "\\.[^\\.]+$" file-name)
434 (mailcap-extension-to-mime
435 (match-string 0 file-name)))
436 "application/octet-stream"))
437 'x-yenc nil
438 (if (and file-name (not (equal file-name "")))
439 (list mm-dissect-disposition
440 (cons 'filename file-name)))))
443 (defun mm-uu-shar-extract ()
444 (mm-make-handle (mm-uu-copy-to-buffer start-point end-point)
445 '("application/x-shar")))
447 (defun mm-uu-gnatsweb-extract ()
448 (save-restriction
449 (goto-char start-point)
450 (forward-line)
451 (narrow-to-region (point) end-point)
452 (mm-dissect-buffer t)))
454 (defun mm-uu-pgp-signed-test (&rest rest)
455 (and
456 mml2015-use
457 (mml2015-clear-verify-function)
458 (cond
459 ((eq mm-verify-option 'never) nil)
460 ((eq mm-verify-option 'always) t)
461 ((eq mm-verify-option 'known) t)
462 (t (prog1
463 (y-or-n-p "Verify pgp signed part? ")
464 (message ""))))))
466 (defvar gnus-newsgroup-charset)
468 (defun mm-uu-pgp-signed-extract-1 (handles ctl)
469 (let ((buf (mm-uu-copy-to-buffer (point-min) (point-max))))
470 (with-current-buffer buf
471 (if (mm-uu-pgp-signed-test)
472 (progn
473 (mml2015-clean-buffer)
474 (let ((coding-system-for-write (or gnus-newsgroup-charset
475 'iso-8859-1))
476 (coding-system-for-read (or gnus-newsgroup-charset
477 'iso-8859-1)))
478 (funcall (mml2015-clear-verify-function))))
479 (when (and mml2015-use (null (mml2015-clear-verify-function)))
480 (mm-set-handle-multipart-parameter
481 mm-security-handle 'gnus-details
482 (format "Clear verification not supported by `%s'.\n" mml2015-use)))
483 (mml2015-extract-cleartext-signature))
484 (list (mm-make-handle buf mm-uu-text-plain-type)))))
486 (defun mm-uu-pgp-signed-extract ()
487 (let ((mm-security-handle (list (format "multipart/signed"))))
488 (mm-set-handle-multipart-parameter
489 mm-security-handle 'protocol "application/x-gnus-pgp-signature")
490 (save-restriction
491 (narrow-to-region start-point end-point)
492 (add-text-properties 0 (length (car mm-security-handle))
493 (list 'buffer (mm-uu-copy-to-buffer))
494 (car mm-security-handle))
495 (setcdr mm-security-handle
496 (mm-uu-pgp-signed-extract-1 nil
497 mm-security-handle)))
498 mm-security-handle))
500 (defun mm-uu-pgp-encrypted-test (&rest rest)
501 (and
502 mml2015-use
503 (mml2015-clear-decrypt-function)
504 (cond
505 ((eq mm-decrypt-option 'never) nil)
506 ((eq mm-decrypt-option 'always) t)
507 ((eq mm-decrypt-option 'known) t)
508 (t (prog1
509 (y-or-n-p "Decrypt pgp encrypted part? ")
510 (message ""))))))
512 (defun mm-uu-pgp-encrypted-extract-1 (handles ctl)
513 (let ((buf (mm-uu-copy-to-buffer (point-min) (point-max)))
514 (first t)
515 charset)
516 ;; Make sure there's a blank line between header and body.
517 (with-current-buffer buf
518 (goto-char (point-min))
519 (while (prog2
520 (forward-line 1)
521 (if first
522 (looking-at "[^\t\n ]+:")
523 (looking-at "[^\t\n ]+:\\|[\t ]"))
524 (setq first nil)))
525 (unless (memq (char-after) '(?\n nil))
526 (insert "\n"))
527 (save-restriction
528 (narrow-to-region (point-min) (point))
529 (setq charset (mail-fetch-field "charset")))
530 (if (and (mm-uu-pgp-encrypted-test)
531 (progn
532 (mml2015-clean-buffer)
533 (funcall (mml2015-clear-decrypt-function))
534 (equal (mm-handle-multipart-ctl-parameter mm-security-handle
535 'gnus-info)
536 "OK")))
537 (progn
538 ;; Decode charset.
539 (if (and (or charset
540 (setq charset gnus-newsgroup-charset))
541 (setq charset (mm-charset-to-coding-system charset))
542 (not (eq charset 'ascii)))
543 ;; Assume that buffer's multibyteness is turned off.
544 ;; See `mml2015-pgg-clear-decrypt'.
545 (insert (mm-decode-coding-string (prog1
546 (buffer-string)
547 (erase-buffer)
548 (mm-enable-multibyte))
549 charset))
550 (mm-enable-multibyte))
551 (list (mm-make-handle buf mm-uu-text-plain-type)))
552 (list (mm-make-handle buf '("application/pgp-encrypted")))))))
554 (defun mm-uu-pgp-encrypted-extract ()
555 (let ((mm-security-handle (list (format "multipart/encrypted"))))
556 (mm-set-handle-multipart-parameter
557 mm-security-handle 'protocol "application/x-gnus-pgp-encrypted")
558 (save-restriction
559 (narrow-to-region start-point end-point)
560 (add-text-properties 0 (length (car mm-security-handle))
561 (list 'buffer (mm-uu-copy-to-buffer))
562 (car mm-security-handle))
563 (setcdr mm-security-handle
564 (mm-uu-pgp-encrypted-extract-1 nil
565 mm-security-handle)))
566 mm-security-handle))
568 (defun mm-uu-gpg-key-skip-to-last ()
569 (let ((point (point))
570 (end-regexp (mm-uu-end-regexp entry))
571 (beginning-regexp (mm-uu-beginning-regexp entry)))
572 (when (and end-regexp
573 (not (mm-uu-configure-p (mm-uu-type entry) 'disabled)))
574 (while (re-search-forward end-regexp nil t)
575 (skip-chars-forward " \t\n\r")
576 (if (looking-at beginning-regexp)
577 (setq point (match-end 0)))))
578 (goto-char point)))
580 (defun mm-uu-pgp-key-extract ()
581 (let ((buf (mm-uu-copy-to-buffer start-point end-point)))
582 (mm-make-handle buf
583 '("application/pgp-keys"))))
585 ;;;###autoload
586 (defun mm-uu-dissect (&optional noheader mime-type)
587 "Dissect the current buffer and return a list of uu handles.
588 The optional NOHEADER means there's no header in the buffer.
589 MIME-TYPE specifies a MIME type and parameters, which defaults to the
590 value of `mm-uu-text-plain-type'."
591 (let ((case-fold-search t)
592 (mm-uu-text-plain-type (or mime-type mm-uu-text-plain-type))
593 text-start start-point end-point file-name result entry func)
594 (save-excursion
595 (goto-char (point-min))
596 (cond
597 (noheader)
598 ((looking-at "\n")
599 (forward-line))
600 ((search-forward "\n\n" nil t)
602 (t (goto-char (point-max))))
603 (setq text-start (point))
604 (while (re-search-forward mm-uu-beginning-regexp nil t)
605 (setq start-point (match-beginning 0)
606 entry nil)
607 (let ((alist mm-uu-type-alist)
608 (beginning-regexp (match-string 0)))
609 (while (not entry)
610 (if (string-match (mm-uu-beginning-regexp (car alist))
611 beginning-regexp)
612 (setq entry (car alist))
613 (pop alist))))
614 (if (setq func (mm-uu-function-1 entry))
615 (funcall func))
616 (forward-line);; in case of failure
617 (when (and (not (mm-uu-configure-p (mm-uu-type entry) 'disabled))
618 (let ((end-regexp (mm-uu-end-regexp entry)))
619 (if (not end-regexp)
620 (or (setq end-point (point-max)) t)
621 (prog1
622 (re-search-forward end-regexp nil t)
623 (forward-line)
624 (setq end-point (point)))))
625 (or (not (setq func (mm-uu-function-2 entry)))
626 (funcall func)))
627 (if (and (> start-point text-start)
628 (progn
629 (goto-char text-start)
630 (re-search-forward "." start-point t)))
631 (push
632 (mm-make-handle (mm-uu-copy-to-buffer text-start start-point)
633 mm-uu-text-plain-type)
634 result))
635 (push
636 (funcall (mm-uu-function-extract entry))
637 result)
638 (goto-char (setq text-start end-point))))
639 (when result
640 (if (and (> (point-max) (1+ text-start))
641 (save-excursion
642 (goto-char text-start)
643 (re-search-forward "." nil t)))
644 (push
645 (mm-make-handle (mm-uu-copy-to-buffer text-start (point-max))
646 mm-uu-text-plain-type)
647 result))
648 (setq result (cons "multipart/mixed" (nreverse result))))
649 result)))
651 ;;;###autoload
652 (defun mm-uu-dissect-text-parts (handle &optional decoded)
653 "Dissect text parts and put uu handles into HANDLE.
654 Assume text has been decoded if DECODED is non-nil."
655 (let ((buffer (mm-handle-buffer handle)))
656 (cond ((stringp buffer)
657 (dolist (elem (cdr handle))
658 (mm-uu-dissect-text-parts elem decoded)))
659 ((bufferp buffer)
660 (let ((type (mm-handle-media-type handle))
661 (case-fold-search t) ;; string-match
662 children charset encoding)
663 (when (and
664 (stringp type)
665 ;; Mutt still uses application/pgp even though
666 ;; it has already been withdrawn.
667 (string-match "\\`text/\\|\\`application/pgp\\'" type)
668 (setq
669 children
670 (with-current-buffer buffer
671 (cond
672 ((or decoded
673 (eq (setq charset (mail-content-type-get
674 (mm-handle-type handle)
675 'charset))
676 'gnus-decoded))
677 (setq decoded t)
678 (mm-uu-dissect
679 t (cons type '((charset . gnus-decoded)))))
680 (charset
681 (setq decoded t)
682 (mm-with-multibyte-buffer
683 (insert (mm-decode-string (mm-get-part handle)
684 charset))
685 (mm-uu-dissect
686 t (cons type '((charset . gnus-decoded))))))
687 ((setq encoding (mm-handle-encoding handle))
688 (setq decoded nil)
689 ;; Inherit the multibyteness of the `buffer'.
690 (with-temp-buffer
691 (insert-buffer-substring buffer)
692 (mm-decode-content-transfer-encoding
693 encoding type)
694 (mm-uu-dissect t (list type))))
696 (setq decoded nil)
697 (mm-uu-dissect t (list type)))))))
698 ;; Ignore it if a given part is dissected into a single
699 ;; part of which the type is the same as the given one.
700 (if (and (<= (length children) 2)
701 (string-equal (mm-handle-media-type (cadr children))
702 type))
703 (kill-buffer (mm-handle-buffer (cadr children)))
704 (kill-buffer buffer)
705 (setcdr handle (cdr children))
706 (setcar handle (car children)) ;; "multipart/mixed"
707 (dolist (elem (cdr children))
708 (mm-uu-dissect-text-parts elem decoded))))))
710 (dolist (elem handle)
711 (mm-uu-dissect-text-parts elem decoded))))))
713 (provide 'mm-uu)
715 ;; arch-tag: 7db076bf-53db-4320-aa19-ca76a1d2ab2c
716 ;;; mm-uu.el ends here