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