url-cid.el 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. ;;; url-cid.el --- Content-ID URL loader
  2. ;; Copyright (C) 1998-1999, 2004-2012 Free Software Foundation, Inc.
  3. ;; Keywords: comm, data, processes
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (require 'url-vars)
  17. (require 'url-parse)
  18. (require 'mm-decode)
  19. (defun url-cid-gnus (cid)
  20. (let ((content-type nil)
  21. (encoding nil)
  22. (part nil)
  23. (data nil))
  24. (setq part (mm-get-content-id cid))
  25. (if (not part)
  26. (message "Unknown CID encountered: %s" cid)
  27. (setq data (with-current-buffer (mm-handle-buffer part)
  28. (buffer-string))
  29. content-type (mm-handle-type part)
  30. encoding (symbol-name (mm-handle-encoding part)))
  31. (if (= 0 (length content-type)) (setq content-type "text/plain"))
  32. (if (= 0 (length encoding)) (setq encoding "8bit"))
  33. (if (listp content-type)
  34. (setq content-type (car content-type)))
  35. (insert (format "Content-length: %d\r\n" (length data))
  36. "Content-type: " content-type "\r\n"
  37. "Content-transfer-encoding: " encoding "\r\n"
  38. "\r\n"
  39. (or data "")))))
  40. ;;;###autoload
  41. (defun url-cid (url)
  42. (cond
  43. ((fboundp 'mm-get-content-id)
  44. ;; Using Pterodactyl Gnus or later
  45. (with-current-buffer (generate-new-buffer " *url-cid*")
  46. (url-cid-gnus (url-filename url))))
  47. (t
  48. (message "Unable to handle CID URL: %s" url))))
  49. ;;; url-cid.el ends here