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
13 ;; This regular expression controls what types of subject lines can be
14 ;; parsed. Currently handles lines like:
23 (defvar mime/gp:subject-start-regexp "[ \t]*\\(v[0-9]+i[0-9]+:[ \t]+\\)?")
25 (defvar mime/gp:subject-end-regexp "\\([[(]?\\)\\([0-9]+\\)\\(/\\| [oO][fF] \\)\\([0-9]+\\)\\([])]?\\)[ \t]*$")
27 ;; display Article at the cursor in Subject buffer.
28 (defun mime/gp:display-article ()
32 (gnus-summary-display-article (gnus-summary-article-number)))
36 (error "Fatal. Unsupported mode")))))
38 (defun mime/decode-message/grab-partials (beg end cal)
40 (let* ((id (cdr (assoc "id" cal)))
41 (number (cdr (assoc "number" cal)))
42 (total (cdr (assoc "total" cal)))
43 (buffer (generate-new-buffer id))
44 (mother mime/preview-buffer)
47 (article-buf (buffer-name (current-buffer)))
51 (cond ((eq major-mode 'gnus-article-mode)
53 (setq subject-buf gnus-summary-buffer)
54 (setq target 'gnus4)))
55 ((eq major-mode 'mh-show-mode)
57 (string-match "^show-\\(.+\\)$" article-buf)
58 (setq subject-buf (substring article-buf (match-beginning 1) (match-end 1)))
60 (t (error "%s is not supported. Sorry." major-mode)))
62 (if (and (eq beg (point-min)) (eq end (point-max)))
64 (goto-char (point-min))
65 (re-search-forward "^$")
66 (let ((delim (match-beginning 0)))
67 (goto-char (point-min))
68 (if (re-search-forward "^[Ss]ubject:.*$" delim t)
69 (let ((tail (match-end 0)))
71 (re-search-forward (concat "^[Ss]ubject:" mime/gp:subject-start-regexp) tail t)
72 (let ((start (point)))
73 (if (and (re-search-forward mime/gp:subject-end-regexp tail t)
74 (eq (string-to-int number)
75 (string-to-int (buffer-substring (match-beginning 2) (match-end 2))))
76 (eq (string-to-int total)
77 (string-to-int (buffer-substring (match-beginning 4) (match-end 4)))))
78 (setq subject-id (buffer-substring start (match-end 1)))
79 (setq part-missing (string-to-int number)))))
80 (setq part-missing t))))
81 (setq part-missing t))
83 ;; if you can't parse the subject line, try simple decoding method
85 (not (y-or-n-p "Merge partials?")))
88 (mime/decode-message/partial-region beg end cal))
90 (set-buffer subject-buf)
91 (setq part-missing (mime/gp:part-missing-p subject-id (string-to-int total)))
95 (error "Couldn't find part %d" part-missing)))
97 (while (<= part-num (string-to-int total))
98 (goto-char (point-min))
99 (message "Grabbing part %d of %d" part-num (string-to-int total))
101 (concat (regexp-quote subject-id) "0*"
102 (int-to-string part-num)) nil t)
103 (mime/gp:display-article)
105 (set-buffer article-buf)
106 (goto-char (point-min))
107 (re-search-forward "^$")
108 (let ((delimit (point)))
109 (goto-char (point-min))
113 "^[Cc]ontent-[Tt]ype:[ \t]*message/partial;" delimit t)
115 (concat "[ \t]+id=[ \t]*\""
116 (regexp-quote id) "\";") delimit)
118 (concat "[ \t]+number=[ \t]*"
119 (int-to-string part-num) ";") delimit)))
122 (error "Couldn't find part %d" part-num)))
123 (append-to-buffer buffer (+ delimit 1) (point-max))))
124 (setq part-num (+ part-num 1))))
125 (mime/gp:display-article)
127 (set-buffer article-buf)
128 (make-variable-buffer-local 'mime/content-list)
129 (setq mime/content-list (mime/parse-contents)))
130 (delete-other-windows)
131 (switch-to-buffer buffer)
132 (goto-char (point-min))
133 (setq major-mode 'mime/show-message-mode)
134 (mime/viewer-mode mother)
135 (pop-to-buffer (current-buffer))
138 ;; Check if all the parts are there
139 (defun mime/gp:part-missing-p (subject-string num-parts)
144 (while (and (<= part-num num-parts) (not cant-find))
145 (goto-char (point-min))
146 ;; If the parts are numbered 01/10, then chop off the leading 0
147 (if (not (re-search-forward
148 (concat (regexp-quote subject-id) "0*"
149 (int-to-string part-num))
151 (setq cant-find part-num)
153 (message "Found part %d of %d." part-num num-parts)
154 (setq part-num (+ part-num 1)))))
158 (set-atype 'mime/content-decoding-condition
159 '((type . "message/partial")
160 (method . mime/decode-message/grab-partials)
163 (provide 'tm-partial)