Update copyright notices for 2013.
[bpt/emacs.git] / lisp / url / url-imap.el
CommitLineData
8c8b8430 1;;; url-imap.el --- IMAP retrieval routines
00eef4de 2
ab422c4d 3;; Copyright (C) 1999, 2004-2013 Free Software Foundation, Inc.
00eef4de 4
8c8b8430 5;; Author: Simon Josefsson <jas@pdc.kth.se>
8c8b8430
SM
6;; Keywords: comm, data, processes
7
00eef4de
LH
8;; This file is part of GNU Emacs.
9
4936186e 10;; GNU Emacs is free software: you can redistribute it and/or modify
00eef4de 11;; it under the terms of the GNU General Public License as published by
4936186e
GM
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
00eef4de
LH
14
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.
19
20;; You should have received a copy of the GNU General Public License
4936186e 21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
00eef4de
LH
22
23;;; Commentary:
24
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):
8c8b8430 28
00eef4de 29;; (url-imap (url-generic-parse-url "imap://cyrus.andrew.cmu.edu/archive.c-client;UID=1021"))
8c8b8430 30
00eef4de 31;;; Code:
8c8b8430 32
8c8b8430
SM
33(require 'url-util)
34(require 'url-parse)
35(require 'nnimap)
36(require 'mm-util)
37
d1ce47b0 38(defconst url-imap-default-port 143 "Default IMAP port.")
8c8b8430
SM
39
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)))
8c8b8430
SM
47 (nnimap-open-server host
48 `((nnimap-server-port ,port)
49 (nnimap-stream 'network)
50 (nnimap-authenticator ,authenticator)))))
51
52(defun url-imap (url)
e05b1e72
GM
53 (unless (vectorp url)
54 (signal 'wrong-type-error (list "Need a pre-parsed URL." url)))
937e6a56 55 (with-current-buffer (generate-new-buffer " *url-imap*")
8c8b8430
SM
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?)
67 )
68 ((assoc "UID" (url-attributes url))
69 ;; fetch message part
70 ;; xxx handle partial fetches
71 (insert "Content-type: message/rfc822\n\n")
d1ce47b0 72 (nnimap-request-article (cdr (assoc "UID" (url-attributes url)))
8c8b8430
SM
73 mailbox host (current-buffer)))
74 (t
75 ;; xxx list messages in mailbox (start gnus?)
76 )))
77 (current-buffer)))
e5566bd5 78
00eef4de 79;;; url-imap.el ends here