Commit | Line | Data |
---|---|---|
8c8b8430 | 1 | ;;; url-imap.el --- IMAP retrieval routines |
00eef4de | 2 | |
12dc447f | 3 | ;; Copyright (C) 1999, 2004, 2005, 2006, 2007, 2008 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 | ||
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 | |
8c0ee52a | 12 | ;; the Free Software Foundation; either version 3, or (at your option) |
00eef4de LH |
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 | |
4fc5845f LK |
22 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 | ;; Boston, MA 02110-1301, USA. | |
00eef4de LH |
24 | |
25 | ;;; Commentary: | |
26 | ||
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): | |
8c8b8430 | 30 | |
00eef4de | 31 | ;; (url-imap (url-generic-parse-url "imap://cyrus.andrew.cmu.edu/archive.c-client;UID=1021")) |
8c8b8430 | 32 | |
00eef4de | 33 | ;;; Code: |
8c8b8430 | 34 | |
8c8b8430 SM |
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))) | |
8c8b8430 SM |
49 | (nnimap-open-server host |
50 | `((nnimap-server-port ,port) | |
51 | (nnimap-stream 'network) | |
52 | (nnimap-authenticator ,authenticator))))) | |
53 | ||
54 | (defun url-imap (url) | |
e05b1e72 GM |
55 | (unless (vectorp url) |
56 | (signal 'wrong-type-error (list "Need a pre-parsed URL." url))) | |
8c8b8430 SM |
57 | (save-excursion |
58 | (set-buffer (generate-new-buffer " *url-imap*")) | |
59 | (mm-disable-multibyte) | |
60 | (let* ((host (url-host url)) | |
61 | (port (url-port url)) | |
62 | ;; xxx decode mailbox (see rfc2192) | |
63 | (mailbox (url-filename url)) | |
64 | (coding-system-for-read 'binary)) | |
65 | (and (eq (string-to-char mailbox) ?/) | |
66 | (setq mailbox (substring mailbox 1))) | |
67 | (url-imap-open-host host port (url-user url) (url-password url)) | |
68 | (cond ((assoc "TYPE" (url-attributes url)) | |
69 | ;; xxx list mailboxes (start gnus?) | |
70 | ) | |
71 | ((assoc "UID" (url-attributes url)) | |
72 | ;; fetch message part | |
73 | ;; xxx handle partial fetches | |
74 | (insert "Content-type: message/rfc822\n\n") | |
75 | (nnimap-request-article (cdr (assoc "UID" (url-attributes url))) | |
76 | mailbox host (current-buffer))) | |
77 | (t | |
78 | ;; xxx list messages in mailbox (start gnus?) | |
79 | ))) | |
80 | (current-buffer))) | |
e5566bd5 | 81 | |
cbee283d | 82 | ;; arch-tag: 034991ff-5425-48ea-b911-c96c90e6f47d |
00eef4de | 83 | ;;; url-imap.el ends here |