54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1 ;;; url-imap.el --- IMAP retrieval routines
|
57612
|
2
|
75347
|
3 ;; Copyright (C) 1999, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
|
57612
|
4
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5 ;; Author: Simon Josefsson <jas@pdc.kth.se>
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
6 ;; Keywords: comm, data, processes
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
7
|
57612
|
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.
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
19
|
57612
|
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
|
64084
|
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
23 ;; Boston, MA 02110-1301, USA.
|
57612
|
24
|
|
25 ;;; Commentary:
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
26
|
57612
|
27 ;; Anyway, here's a teaser. It's quite broken in lots of regards, but at
|
|
28 ;; least it seem to work. At least a little. At least when called
|
|
29 ;; manually like this (I've no idea how it's supposed to be called):
|
|
30
|
|
31 ;; (url-imap (url-generic-parse-url "imap://cyrus.andrew.cmu.edu/archive.c-client;UID=1021"))
|
|
32
|
|
33 ;;; Code:
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
35 (eval-when-compile (require 'cl))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 (require 'url-util)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37 (require 'url-parse)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
38 (require 'nnimap)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
39 (require 'mm-util)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
40
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
41 (defconst url-imap-default-port 143 "Default IMAP port")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
42
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
43 (defun url-imap-open-host (host port user pass)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 ;; xxx use user and password
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45 (if (fboundp 'nnheader-init-server-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
46 (nnheader-init-server-buffer))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
47 (let ((imap-username user)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
48 (imap-password pass)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
49 (authenticator (if user 'login 'anonymous)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
50 (nnimap-open-server host
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
51 `((nnimap-server-port ,port)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
52 (nnimap-stream 'network)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
53 (nnimap-authenticator ,authenticator)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
54
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
55 (defun url-imap (url)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
56 (check-type url vector "Need a pre-parsed URL.")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
58 (set-buffer (generate-new-buffer " *url-imap*"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 (mm-disable-multibyte)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
60 (let* ((host (url-host url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 (port (url-port url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
62 ;; xxx decode mailbox (see rfc2192)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
63 (mailbox (url-filename url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
64 (coding-system-for-read 'binary))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65 (and (eq (string-to-char mailbox) ?/)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 (setq mailbox (substring mailbox 1)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
67 (url-imap-open-host host port (url-user url) (url-password url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
68 (cond ((assoc "TYPE" (url-attributes url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
69 ;; xxx list mailboxes (start gnus?)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
70 )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71 ((assoc "UID" (url-attributes url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
72 ;; fetch message part
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
73 ;; xxx handle partial fetches
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
74 (insert "Content-type: message/rfc822\n\n")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 (nnimap-request-article (cdr (assoc "UID" (url-attributes url)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
76 mailbox host (current-buffer)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
77 (t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
78 ;; xxx list messages in mailbox (start gnus?)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
79 )))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
80 (current-buffer)))
|
54699
|
81
|
|
82 ;;; arch-tag: 034991ff-5425-48ea-b911-c96c90e6f47d
|
57612
|
83 ;;; url-imap.el ends here
|