]> code.delx.au - gnu-emacs/blob - lisp/url/url-imap.el
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-196
[gnu-emacs] / lisp / url / url-imap.el
1 ;;; url-imap.el --- IMAP retrieval routines
2 ;; Author: Simon Josefsson <jas@pdc.kth.se>
3 ;; Keywords: comm, data, processes
4
5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6 ;;; Copyright (c) 1999 Free Software Foundation, Inc.
7 ;;;
8 ;;; This file is part of GNU Emacs.
9 ;;;
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 2, or (at your option)
13 ;;; any later version.
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
21 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;;; Boston, MA 02111-1307, USA.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25
26 ; Anyway, here's a teaser. It's quite broken in lots of regards, but at
27 ; least it seem to work. At least a little. At least when called
28 ; manually like this (I've no idea how it's supposed to be called):
29
30 ; (url-imap (url-generic-parse-url "imap://cyrus.andrew.cmu.edu/archive.c-client;UID=1021"))
31
32 (eval-when-compile (require 'cl))
33 (require 'url-util)
34 (require 'url-parse)
35 (require 'nnimap)
36 (require 'mm-util)
37
38 (defconst url-imap-default-port 143 "Default IMAP port")
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)))
47 (if (stringp port)
48 (setq port (string-to-int port)))
49 (nnimap-open-server host
50 `((nnimap-server-port ,port)
51 (nnimap-stream 'network)
52 (nnimap-authenticator ,authenticator)))))
53
54 (defun url-imap (url)
55 (check-type url vector "Need a pre-parsed URL.")
56 (save-excursion
57 (set-buffer (generate-new-buffer " *url-imap*"))
58 (mm-disable-multibyte)
59 (let* ((host (url-host url))
60 (port (url-port url))
61 ;; xxx decode mailbox (see rfc2192)
62 (mailbox (url-filename url))
63 (coding-system-for-read 'binary))
64 (and (eq (string-to-char mailbox) ?/)
65 (setq mailbox (substring mailbox 1)))
66 (url-imap-open-host host port (url-user url) (url-password url))
67 (cond ((assoc "TYPE" (url-attributes url))
68 ;; xxx list mailboxes (start gnus?)
69 )
70 ((assoc "UID" (url-attributes url))
71 ;; fetch message part
72 ;; xxx handle partial fetches
73 (insert "Content-type: message/rfc822\n\n")
74 (nnimap-request-article (cdr (assoc "UID" (url-attributes url)))
75 mailbox host (current-buffer)))
76 (t
77 ;; xxx list messages in mailbox (start gnus?)
78 )))
79 (current-buffer)))
80
81 ;;; arch-tag: 034991ff-5425-48ea-b911-c96c90e6f47d