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 ;;; $Id: tm-partial.el,v 5.0 1995/05/22 17:06:31 morioka Exp $
16 ;; This regular expression controls what types of subject lines can be
17 ;; parsed. Currently handles lines like:
26 (defvar mime/gp:subject-start-regexp "[ \t]*\\(v[0-9]+i[0-9]+:[ \t]+\\)?")
28 (defvar mime/gp:subject-end-regexp
29 "\\([[(]?\\)\\([0-9]+\\)\\(/\\| [oO][fF] \\)\\([0-9]+\\)\\([])]?\\)[ \t]*$")
31 ;; display Article at the cursor in Subject buffer.
32 (defun mime/gp:display-article ()
36 (let ((gnus-show-all-headers t))
37 (gnus-summary-display-article (gnus-summary-article-number))
43 (let ((vm-follow-summary-cursor t))
44 (vm-follow-summary-cursor)
45 (vm-select-folder-buffer)
46 (vm-check-for-killed-summary)
47 (vm-error-if-folder-empty)
48 (vm-display (current-buffer) t '(tm-vm/view-message)
49 '(tm-vm/view-mesage reading-message))
51 (goto-char (point-max))
53 (narrow-to-region (point) (vm-start-of (car vm-message-pointer)))
54 (goto-char (point-min))
56 (t (error "Fatal. Unsupported mode")))))
58 (defun mime/decode-message/grab-partials (beg end cal)
60 (let* ((id (cdr (assoc "id" cal)))
61 (number (cdr (assoc "number" cal)))
62 (total (cdr (assoc "total" cal)))
63 (buffer (generate-new-buffer id))
64 (mother mime::article/preview-buffer)
67 (article-buf (buffer-name (current-buffer)))
71 (cond ((eq major-mode 'gnus-article-mode)
72 (setq subject-buf gnus-summary-buffer)
75 ((eq major-mode 'mh-show-mode)
76 (string-match "^show-\\(.+\\)$" article-buf)
78 (substring article-buf (match-beginning 1) (match-end 1)))
81 ((eq major-mode 'vm-mode)
82 (setq subject-buf vm-summary-buffer)
85 (t (error "%s is not supported. Sorry." major-mode)))
87 (if (and (eq beg (point-min)) (eq end (point-max)))
89 (goto-char (point-min))
90 (re-search-forward "^$")
91 (let ((delim (match-beginning 0)))
92 (goto-char (point-min))
93 (if (re-search-forward "^[Ss]ubject:.*$" delim t)
94 (let ((tail (match-end 0)))
96 (re-search-forward (concat "^[Ss]ubject:" mime/gp:subject-start-regexp) tail t)
97 (let ((start (point)))
98 (if (and (re-search-forward mime/gp:subject-end-regexp tail t)
99 (eq (string-to-int number)
100 (string-to-int (buffer-substring (match-beginning 2) (match-end 2))))
101 (eq (string-to-int total)
102 (string-to-int (buffer-substring (match-beginning 4) (match-end 4)))))
103 (setq subject-id (buffer-substring start (match-end 1)))
104 (setq part-missing (string-to-int number)))))
105 (setq part-missing t))))
106 (setq part-missing t))
108 ;; if you can't parse the subject line, try simple decoding method
110 (not (y-or-n-p "Merge partials?")))
113 (mime/decode-message/partial-region beg end cal))
115 (set-buffer subject-buf)
116 (setq part-missing (mime/gp:part-missing-p subject-id (string-to-int total)))
120 (error "Couldn't find part %d" part-missing)))
122 (while (<= part-num (string-to-int total))
123 (goto-char (point-min))
124 (message "Grabbing part %d of %d" part-num (string-to-int total))
126 (concat (regexp-quote subject-id) "0*"
127 (int-to-string part-num)) nil t)
128 (mime/gp:display-article)
130 (set-buffer article-buf)
131 (goto-char (point-min))
132 (re-search-forward "^$")
133 (let ((delimit (point)))
134 (goto-char (point-min))
136 (let ((params (cdr (mime/Content-Type))))
137 (and (equal (assoc-value "id" params) id)
138 (= (string-to-int (assoc-value "number" params))
143 (error "Couldn't find part %d" part-num)))
144 (append-to-buffer buffer (+ delimit 1) (point-max))))
145 (setq part-num (+ part-num 1))))
146 (mime/gp:display-article)
148 (set-buffer article-buf)
149 ;; (make-variable-buffer-local 'mime/content-list)
150 ;; (setq mime/content-list (mime/parse-contents))
151 (make-variable-buffer-local 'mime::article/content-info)
152 (setq mime::article/content-info (mime-viewer/parse))
154 (delete-other-windows)
155 (switch-to-buffer buffer)
156 (goto-char (point-min))
157 (setq major-mode 'mime/show-message-mode)
158 (mime/viewer-mode mother)
159 (pop-to-buffer (current-buffer))
162 ;; Check if all the parts are there
163 (defun mime/gp:part-missing-p (subject-string num-parts)
168 (while (and (<= part-num num-parts) (not cant-find))
169 (goto-char (point-min))
170 ;; If the parts are numbered 01/10, then chop off the leading 0
171 (if (not (re-search-forward
172 (concat (regexp-quote subject-id) "0*"
173 (int-to-string part-num))
175 (setq cant-find part-num)
177 (message "Found part %d of %d." part-num num-parts)
178 (setq part-num (+ part-num 1)))))
185 (set-atype 'mime/content-decoding-condition
186 '((type . "message/partial")
187 (method . mime/decode-message/grab-partials)
188 (major-mode . gnus-article-mode)
191 (set-atype 'mime/content-decoding-condition
192 '((type . "message/partial")
193 (method . mime/decode-message/grab-partials)
194 (major-mode . mh-show-mode)
197 (set-atype 'mime/content-decoding-condition
198 '((type . "message/partial")
199 (method . mime/decode-message/grab-partials)
200 (major-mode . vm-mode)
203 (provide 'tm-partial)