54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1 ;;; url-cid.el --- Content-ID URL loader
|
57612
|
2
|
|
3 ;; Copyright (c) 1998 - 1999 Free Software Foundation, Inc.
|
|
4
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5 ;; Keywords: comm, data, processes
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
6
|
57612
|
7 ;; This file is part of GNU Emacs.
|
|
8
|
|
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
10 ;; it under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 ;; GNU General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
|
23
|
|
24 ;;; Code:
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
25
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
26 (require 'url-vars)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
27 (require 'url-parse)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
28
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
29 (require 'mm-decode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
30
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 (defun url-cid-gnus (cid)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
32 (let ((content-type nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
33 (encoding nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34 (part nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
35 (data nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 (setq part (mm-get-content-id cid))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37 (if (not part)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
38 (message "Unknown CID encountered: %s" cid)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
39 (setq data (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
40 (set-buffer (mm-handle-buffer part))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
41 (buffer-string))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
42 content-type (mm-handle-type part)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
43 encoding (symbol-name (mm-handle-encoding part)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 (if (= 0 (length content-type)) (setq content-type "text/plain"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45 (if (= 0 (length encoding)) (setq encoding "8bit"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
46 (if (listp content-type)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
47 (setq content-type (car content-type)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
48 (insert (format "Content-type: %d\r\n" (length data))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
49 "Content-type: " content-type "\r\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
50 "Content-transfer-encoding: " encoding "\r\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
51 "\r\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
52 (or data "")))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
53
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
54 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
55 (defun url-cid (url)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
56 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 ((fboundp 'mm-get-content-id)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
58 ;; Using Pterodactyl Gnus or later
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
60 (set-buffer (generate-new-buffer " *url-cid*"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 (url-cid-gnus (url-filename url))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
62 (t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
63 (message "Unable to handle CID URL: %s" url))))
|
54699
|
64
|
|
65 ;;; arch-tag: 23d9ab74-fad4-4dba-b1e7-292871e8bda5
|
57612
|
66 ;;; url-cid.el ends here
|