4 ;;; Grabbing all MIME "message/partial"s.
5 ;;; by Yasuo OKABE @ Kyoto University 1994
6 ;;; modified by MORIOKA Tomohiko
9 ;; gif.el written by Art Mellor @ Cayman Systems, Inc. 1991
11 ;;; $Id: tm-partial.el,v 2.0 1995/03/12 16:14:44 morioka Exp $
15 ;; This regular expression controls what types of subject lines can be
16 ;; parsed. Currently handles lines like:
25 (defvar mime/gp:subject-start-regexp "[ \t]*\\(v[0-9]+i[0-9]+:[ \t]+\\)?")
27 (defvar mime/gp:subject-end-regexp "\\([[(]?\\)\\([0-9]+\\)\\(/\\| [oO][fF] \\)\\([0-9]+\\)\\([])]?\\)[ \t]*$")
29 ;; display Article at the cursor in Subject buffer.
30 (defun mime/gp:display-article ()
34 (gnus-summary-display-article (gnus-summary-article-number)))
38 (error "Fatal. Unsupported mode")))))
40 (defun mime/decode-message/grab-partials (beg end cal)
42 (let* ((id (cdr (assoc "id" cal)))
43 (number (cdr (assoc "number" cal)))
44 (total (cdr (assoc "total" cal)))
45 (buffer (generate-new-buffer id))
46 (mother mime::article/preview-buffer)
49 (article-buf (buffer-name (current-buffer)))
53 (cond ((eq major-mode 'gnus-article-mode)
55 (setq subject-buf gnus-summary-buffer)
56 (setq target 'gnus4)))
57 ((eq major-mode 'mh-show-mode)
59 (string-match "^show-\\(.+\\)$" article-buf)
60 (setq subject-buf (substring article-buf (match-beginning 1) (match-end 1)))
62 (t (error "%s is not supported. Sorry." major-mode)))
64 (if (and (eq beg (point-min)) (eq end (point-max)))
66 (goto-char (point-min))
67 (re-search-forward "^$")
68 (let ((delim (match-beginning 0)))
69 (goto-char (point-min))
70 (if (re-search-forward "^[Ss]ubject:.*$" delim t)
71 (let ((tail (match-end 0)))
73 (re-search-forward (concat "^[Ss]ubject:" mime/gp:subject-start-regexp) tail t)
74 (let ((start (point)))
75 (if (and (re-search-forward mime/gp:subject-end-regexp tail t)
76 (eq (string-to-int number)
77 (string-to-int (buffer-substring (match-beginning 2) (match-end 2))))
78 (eq (string-to-int total)
79 (string-to-int (buffer-substring (match-beginning 4) (match-end 4)))))
80 (setq subject-id (buffer-substring start (match-end 1)))
81 (setq part-missing (string-to-int number)))))
82 (setq part-missing t))))
83 (setq part-missing t))
85 ;; if you can't parse the subject line, try simple decoding method
87 (not (y-or-n-p "Merge partials?")))
90 (mime/decode-message/partial-region beg end cal))
92 (set-buffer subject-buf)
93 (setq part-missing (mime/gp:part-missing-p subject-id (string-to-int total)))
97 (error "Couldn't find part %d" part-missing)))
99 (while (<= part-num (string-to-int total))
100 (goto-char (point-min))
101 (message "Grabbing part %d of %d" part-num (string-to-int total))
103 (concat (regexp-quote subject-id) "0*"
104 (int-to-string part-num)) nil t)
105 (mime/gp:display-article)
107 (set-buffer article-buf)
108 (goto-char (point-min))
109 (re-search-forward "^$")
110 (let ((delimit (point)))
111 (goto-char (point-min))
115 "^[Cc]ontent-[Tt]ype:[ \t]*message/partial;" delimit t)
117 (concat "[ \t]+id=[ \t]*\""
118 (regexp-quote id) "\";") delimit)
120 (concat "[ \t]+number=[ \t]*"
121 (int-to-string part-num) ";") delimit)))
124 (error "Couldn't find part %d" part-num)))
125 (append-to-buffer buffer (+ delimit 1) (point-max))))
126 (setq part-num (+ part-num 1))))
127 (mime/gp:display-article)
129 (set-buffer article-buf)
130 ;; (make-variable-buffer-local 'mime/content-list)
131 ;; (setq mime/content-list (mime/parse-contents))
132 (make-variable-buffer-local 'mime::article/content-info)
133 (setq mime::article/content-info (mime-viewer/parse))
135 (delete-other-windows)
136 (switch-to-buffer buffer)
137 (goto-char (point-min))
138 (setq major-mode 'mime/show-message-mode)
139 (mime/viewer-mode mother)
140 (pop-to-buffer (current-buffer))
143 ;; Check if all the parts are there
144 (defun mime/gp:part-missing-p (subject-string num-parts)
149 (while (and (<= part-num num-parts) (not cant-find))
150 (goto-char (point-min))
151 ;; If the parts are numbered 01/10, then chop off the leading 0
152 (if (not (re-search-forward
153 (concat (regexp-quote subject-id) "0*"
154 (int-to-string part-num))
156 (setq cant-find part-num)
158 (message "Found part %d of %d." part-num num-parts)
159 (setq part-num (+ part-num 1)))))
166 (set-atype 'mime/content-decoding-condition
167 '((type . "message/partial")
168 (method . mime/decode-message/grab-partials)
169 (major-mode . gnus-article-mode)
172 (set-atype 'mime/content-decoding-condition
173 '((type . "message/partial")
174 (method . mime/decode-message/grab-partials)
175 (major-mode . mh-show-mode)
178 (provide 'tm-partial)