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 7.0 1995/10/18 08:19:27 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 ((or (eq major-mode 'gnus-article-mode)
75 (eq major-mode 'gnus-original-article-mode)
77 (setq subject-buf gnus-summary-buffer)
80 ((eq major-mode 'mh-show-mode)
81 (string-match "^show-\\(.+\\)$" article-buf)
83 (substring article-buf (match-beginning 1) (match-end 1)))
86 ((eq major-mode 'vm-mode)
87 (setq subject-buf vm-summary-buffer)
90 (t (error "%s is not supported. Sorry." major-mode)))
92 (if (and (eq beg (point-min)) (eq end (point-max)))
94 (goto-char (point-min))
95 (re-search-forward "^$")
96 (let ((delim (match-beginning 0)))
97 (goto-char (point-min))
98 (if (re-search-forward "^[Ss]ubject:.*$" delim t)
99 (let ((tail (match-end 0)))
101 (re-search-forward (concat "^[Ss]ubject:" mime/gp:subject-start-regexp) tail t)
102 (let ((start (point)))
103 (if (and (re-search-forward mime/gp:subject-end-regexp tail t)
104 (eq (string-to-int number)
105 (string-to-int (buffer-substring (match-beginning 2) (match-end 2))))
106 (eq (string-to-int total)
107 (string-to-int (buffer-substring (match-beginning 4) (match-end 4)))))
108 (setq subject-id (buffer-substring start (match-end 1)))
109 (setq part-missing (string-to-int number)))))
110 (setq part-missing t))))
111 (setq part-missing t))
113 ;; if you can't parse the subject line, try simple decoding method
115 (not (y-or-n-p "Merge partials?")))
118 (mime/decode-message/partial-region beg end cal))
120 (set-buffer subject-buf)
121 (setq part-missing (mime/gp:part-missing-p subject-id (string-to-int total)))
125 (error "Couldn't find part %d" part-missing)))
127 (while (<= part-num (string-to-int total))
128 (goto-char (point-min))
129 (message "Grabbing part %d of %d" part-num (string-to-int total))
131 (concat (regexp-quote subject-id) "0*"
132 (int-to-string part-num)) nil t)
133 (mime/gp:display-article)
135 (set-buffer article-buf)
136 (goto-char (point-min))
137 (re-search-forward "^$")
138 (let ((delimit (1+ (point))))
139 (goto-char (point-min))
141 (let ((params (cdr (mime/Content-Type))))
142 (and (equal (assoc-value "id" params) id)
143 (= (string-to-int (assoc-value "number" params))
148 (error "Couldn't find part %d" part-num)))
149 (if (< delimit (point-max))
150 (append-to-buffer buffer delimit (point-max))
152 (setq part-num (+ part-num 1))))
153 (mime/gp:display-article)
155 (set-buffer article-buf)
156 ;; (make-variable-buffer-local 'mime/content-list)
157 ;; (setq mime/content-list (mime/parse-contents))
158 (make-variable-buffer-local 'mime::article/content-info)
159 (setq mime::article/content-info (mime/parse-message))
161 (delete-other-windows)
162 (switch-to-buffer buffer)
163 (goto-char (point-min))
164 (setq major-mode 'mime/show-message-mode)
165 (mime/viewer-mode mother)
166 (pop-to-buffer (current-buffer))
169 ;; Check if all the parts are there
170 (defun mime/gp:part-missing-p (subject-string num-parts)
175 (while (and (<= part-num num-parts) (not cant-find))
176 (goto-char (point-min))
177 ;; If the parts are numbered 01/10, then chop off the leading 0
178 (if (not (re-search-forward
179 (concat (regexp-quote subject-id) "0*"
180 (int-to-string part-num))
182 (setq cant-find part-num)
184 (message "Found part %d of %d." part-num num-parts)
185 (setq part-num (+ part-num 1)))))
192 (set-atype 'mime/content-decoding-condition
193 '((type . "message/partial")
194 (method . mime/decode-message/grab-partials)
195 (major-mode . gnus-article-mode)
198 (set-atype 'mime/content-decoding-condition
199 '((type . "message/partial")
200 (method . mime/decode-message/grab-partials)
201 (major-mode . gnus-original-article-mode)
204 (set-atype 'mime/content-decoding-condition
205 '((type . "message/partial")
206 (method . mime/decode-message/grab-partials)
207 (major-mode . mh-show-mode)
210 (set-atype 'mime/content-decoding-condition
211 '((type . "message/partial")
212 (method . mime/decode-message/grab-partials)
213 (major-mode . vm-mode)
216 (provide 'tm-partial)