Resolve CVS conflicts
[bpt/emacs.git] / lisp / url / url-imap.el
1 ;;; url-imap.el --- IMAP retrieval routines
2 ;; Author: Simon Josefsson <jas@pdc.kth.se>
3 ;; Created: $Date: 2004/04/04 01:21:46 $
4 ;; Version: $Revision: 1.1.1.1 $
5 ;; Keywords: comm, data, processes
6
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;;; Copyright (c) 1999 Free Software Foundation, Inc.
9 ;;;
10 ;;; This file is part of GNU Emacs.
11 ;;;
12 ;;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;;; it under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 2, or (at your option)
15 ;;; any later version.
16 ;;;
17 ;;; GNU Emacs is distributed in the hope that it will be useful,
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;;; GNU General Public License for more details.
21 ;;;
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;;; Boston, MA 02111-1307, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27
28 ; Anyway, here's a teaser. It's quite broken in lots of regards, but at
29 ; least it seem to work. At least a little. At least when called
30 ; manually like this (I've no idea how it's supposed to be called):
31
32 ; (url-imap (url-generic-parse-url "imap://cyrus.andrew.cmu.edu/archive.c-client;UID=1021"))
33
34 (eval-when-compile (require 'cl))
35 (require 'url-util)
36 (require 'url-parse)
37 (require 'nnimap)
38 (require 'mm-util)
39
40 (defconst url-imap-default-port 143 "Default IMAP port")
41
42 (defun url-imap-open-host (host port user pass)
43 ;; xxx use user and password
44 (if (fboundp 'nnheader-init-server-buffer)
45 (nnheader-init-server-buffer))
46 (let ((imap-username user)
47 (imap-password pass)
48 (authenticator (if user 'login 'anonymous)))
49 (if (stringp port)
50 (setq port (string-to-int port)))
51 (nnimap-open-server host
52 `((nnimap-server-port ,port)
53 (nnimap-stream 'network)
54 (nnimap-authenticator ,authenticator)))))
55
56 (defun url-imap (url)
57 (check-type url vector "Need a pre-parsed URL.")
58 (save-excursion
59 (set-buffer (generate-new-buffer " *url-imap*"))
60 (mm-disable-multibyte)
61 (let* ((host (url-host url))
62 (port (url-port url))
63 ;; xxx decode mailbox (see rfc2192)
64 (mailbox (url-filename url))
65 (coding-system-for-read 'binary))
66 (and (eq (string-to-char mailbox) ?/)
67 (setq mailbox (substring mailbox 1)))
68 (url-imap-open-host host port (url-user url) (url-password url))
69 (cond ((assoc "TYPE" (url-attributes url))
70 ;; xxx list mailboxes (start gnus?)
71 )
72 ((assoc "UID" (url-attributes url))
73 ;; fetch message part
74 ;; xxx handle partial fetches
75 (insert "Content-type: message/rfc822\n\n")
76 (nnimap-request-article (cdr (assoc "UID" (url-attributes url)))
77 mailbox host (current-buffer)))
78 (t
79 ;; xxx list messages in mailbox (start gnus?)
80 )))
81 (current-buffer)))
82
83 ;;; arch-tag: 034991ff-5425-48ea-b911-c96c90e6f47d