4 ;;; Grabbing all MIME "message/partial"s.
5 ;;; by Yasuo OKABE @ Kyoto University 1994
6 ;;; modified by MORIOKA Tomohiko
7 ;;; and Shuhei KOBAYASHI <shuhei@cmpt01.phys.tohoku.ac.jp>
10 ;;; gif.el written by Art Mellor @ Cayman Systems, Inc. 1991
12 ;;; This file is a part of tm (Tools for MIME).
14 ;;; $Id: tm-partial.el,v 6.1 1995/09/26 14:50:54 morioka Exp $
19 ;; This regular expression controls what types of subject lines can be
20 ;; parsed. Currently handles lines like:
29 (defvar mime/gp:subject-start-regexp "[ \t]*\\(v[0-9]+i[0-9]+:[ \t]+\\)?")
31 (defvar mime/gp:subject-end-regexp
32 "\\([[(]?\\)\\([0-9]+\\)\\(/\\| [oO][fF] \\)\\([0-9]+\\)\\([])]?\\)[ \t]*$")
34 ;; display Article at the cursor in Subject buffer.
35 (defun mime/gp:display-article ()
39 (let ((gnus-show-all-headers t))
40 (gnus-summary-display-article (gnus-summary-article-number))
46 (let ((vm-follow-summary-cursor t))
47 (vm-follow-summary-cursor)
48 (vm-select-folder-buffer)
49 (vm-check-for-killed-summary)
50 (vm-error-if-folder-empty)
51 (vm-display (current-buffer) t '(tm-vm/view-message)
52 '(tm-vm/view-mesage reading-message))
54 (goto-char (point-max))
56 (narrow-to-region (point) (vm-start-of (car vm-message-pointer)))
57 (goto-char (point-min))
59 (t (error "Fatal. Unsupported mode")))))
61 (defun mime/decode-message/grab-partials (beg end cal)
63 (let* ((id (cdr (assoc "id" cal)))
64 (number (cdr (assoc "number" cal)))
65 (total (cdr (assoc "total" cal)))
66 (buffer (generate-new-buffer id))
67 (mother mime::article/preview-buffer)
70 (article-buf (buffer-name (current-buffer)))
74 (cond ((eq major-mode 'gnus-article-mode)
75 (setq subject-buf gnus-summary-buffer)
78 ((eq major-mode 'mh-show-mode)
79 (string-match "^show-\\(.+\\)$" article-buf)
81 (substring article-buf (match-beginning 1) (match-end 1)))
84 ((eq major-mode 'vm-mode)
85 (setq subject-buf vm-summary-buffer)
88 (t (error "%s is not supported. Sorry." major-mode)))
90 (if (and (eq beg (point-min)) (eq end (point-max)))
92 (goto-char (point-min))
93 (re-search-forward "^$")
94 (let ((delim (match-beginning 0)))
95 (goto-char (point-min))
96 (if (re-search-forward "^[Ss]ubject:.*$" delim t)
97 (let ((tail (match-end 0)))
99 (re-search-forward (concat "^[Ss]ubject:" mime/gp:subject-start-regexp) tail t)
100 (let ((start (point)))
101 (if (and (re-search-forward mime/gp:subject-end-regexp tail t)
102 (eq (string-to-int number)
103 (string-to-int (buffer-substring (match-beginning 2) (match-end 2))))
104 (eq (string-to-int total)
105 (string-to-int (buffer-substring (match-beginning 4) (match-end 4)))))
106 (setq subject-id (buffer-substring start (match-end 1)))
107 (setq part-missing (string-to-int number)))))
108 (setq part-missing t))))
109 (setq part-missing t))
111 ;; if you can't parse the subject line, try simple decoding method
113 (not (y-or-n-p "Merge partials?")))
116 (mime/decode-message/partial-region beg end cal))
118 (set-buffer subject-buf)
119 (setq part-missing (mime/gp:part-missing-p subject-id (string-to-int total)))
123 (error "Couldn't find part %d" part-missing)))
125 (while (<= part-num (string-to-int total))
126 (goto-char (point-min))
127 (message "Grabbing part %d of %d" part-num (string-to-int total))
129 (concat (regexp-quote subject-id) "0*"
130 (int-to-string part-num)) nil t)
131 (mime/gp:display-article)
133 (set-buffer article-buf)
134 (goto-char (point-min))
135 (re-search-forward "^$")
136 (let ((delimit (1+ (point))))
137 (goto-char (point-min))
139 (let ((params (cdr (mime/Content-Type))))
140 (and (equal (assoc-value "id" params) id)
141 (= (string-to-int (assoc-value "number" params))
146 (error "Couldn't find part %d" part-num)))
147 (if (< delimit (point-max))
148 (append-to-buffer buffer delimit (point-max))
150 (setq part-num (+ part-num 1))))
151 (mime/gp:display-article)
153 (set-buffer article-buf)
154 ;; (make-variable-buffer-local 'mime/content-list)
155 ;; (setq mime/content-list (mime/parse-contents))
156 (make-variable-buffer-local 'mime::article/content-info)
157 (setq mime::article/content-info (mime/parse-message))
159 (delete-other-windows)
160 (switch-to-buffer buffer)
161 (goto-char (point-min))
162 (setq major-mode 'mime/show-message-mode)
163 (mime/viewer-mode mother)
164 (pop-to-buffer (current-buffer))
167 ;; Check if all the parts are there
168 (defun mime/gp:part-missing-p (subject-string num-parts)
173 (while (and (<= part-num num-parts) (not cant-find))
174 (goto-char (point-min))
175 ;; If the parts are numbered 01/10, then chop off the leading 0
176 (if (not (re-search-forward
177 (concat (regexp-quote subject-id) "0*"
178 (int-to-string part-num))
180 (setq cant-find part-num)
182 (message "Found part %d of %d." part-num num-parts)
183 (setq part-num (+ part-num 1)))))
190 (set-atype 'mime/content-decoding-condition
191 '((type . "message/partial")
192 (method . mime/decode-message/grab-partials)
193 (major-mode . gnus-article-mode)
196 (set-atype 'mime/content-decoding-condition
197 '((type . "message/partial")
198 (method . mime/decode-message/grab-partials)
199 (major-mode . mh-show-mode)
202 (set-atype 'mime/content-decoding-condition
203 '((type . "message/partial")
204 (method . mime/decode-message/grab-partials)
205 (major-mode . vm-mode)
208 (provide 'tm-partial)