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