url-imap.el 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ;;; url-imap.el --- IMAP retrieval routines
  2. ;; Copyright (C) 1999, 2004-2012 Free Software Foundation, Inc.
  3. ;; Author: Simon Josefsson <jas@pdc.kth.se>
  4. ;; Keywords: comm, data, processes
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; Anyway, here's a teaser. It's quite broken in lots of regards, but at
  18. ;; least it seem to work. At least a little. At least when called
  19. ;; manually like this (I've no idea how it's supposed to be called):
  20. ;; (url-imap (url-generic-parse-url "imap://cyrus.andrew.cmu.edu/archive.c-client;UID=1021"))
  21. ;;; Code:
  22. (require 'url-util)
  23. (require 'url-parse)
  24. (require 'nnimap)
  25. (require 'mm-util)
  26. (defconst url-imap-default-port 143 "Default IMAP port.")
  27. (defun url-imap-open-host (host port user pass)
  28. ;; xxx use user and password
  29. (if (fboundp 'nnheader-init-server-buffer)
  30. (nnheader-init-server-buffer))
  31. (let ((imap-username user)
  32. (imap-password pass)
  33. (authenticator (if user 'login 'anonymous)))
  34. (nnimap-open-server host
  35. `((nnimap-server-port ,port)
  36. (nnimap-stream 'network)
  37. (nnimap-authenticator ,authenticator)))))
  38. (defun url-imap (url)
  39. (unless (vectorp url)
  40. (signal 'wrong-type-error (list "Need a pre-parsed URL." url)))
  41. (with-current-buffer (generate-new-buffer " *url-imap*")
  42. (mm-disable-multibyte)
  43. (let* ((host (url-host url))
  44. (port (url-port url))
  45. ;; xxx decode mailbox (see rfc2192)
  46. (mailbox (url-filename url))
  47. (coding-system-for-read 'binary))
  48. (and (eq (string-to-char mailbox) ?/)
  49. (setq mailbox (substring mailbox 1)))
  50. (url-imap-open-host host port (url-user url) (url-password url))
  51. (cond ((assoc "TYPE" (url-attributes url))
  52. ;; xxx list mailboxes (start gnus?)
  53. )
  54. ((assoc "UID" (url-attributes url))
  55. ;; fetch message part
  56. ;; xxx handle partial fetches
  57. (insert "Content-type: message/rfc822\n\n")
  58. (nnimap-request-article (cdr (assoc "UID" (url-attributes url)))
  59. mailbox host (current-buffer)))
  60. (t
  61. ;; xxx list messages in mailbox (start gnus?)
  62. )))
  63. (current-buffer)))
  64. ;;; url-imap.el ends here