-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.rkt
executable file
·72 lines (54 loc) · 1.99 KB
/
mail.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#lang racket
; Possible future requires
;net/unihead
;net/mime
;net/base64
;net/qp
(provide (all-defined-out))
(require net/imap
net/head)
; Default to INBOX mailbox
(define mailbox "INBOX")
(define use-ssl #t )
(imap-port-number 993)
(define server (make-parameter "imap-mail.outlook.com"))
(define username (make-parameter ""))
(define password (make-parameter ""))
(struct rmail
(connection total-messages recent-messages))
(define (rmail-connect imap-server username password)
;(displayln (string-append (imap-server) (username) (password)))
(imap-connect imap-server username password mailbox #:tls? use-ssl))
; This should be included in the above struct
(define (rmail-mailboxes imap-connection)
(map (lambda (mailbox-information)
(last mailbox-information))
(imap-list-child-mailboxes imap-connection #f)))
(define (create-mailbox imap-connection mailbox)
(unless (imap-mailbox-exists? imap-connection mailbox)
(imap-create-mailbox imap-connection mailbox)))
; A header is returned as:
; '(uid #bytes)
; bytes->string/utf-8 can be used to output bytes, though something like
; this will be called by display
(define (headers imap-connection total-messages)
(imap-get-messages
imap-connection (stream->list (in-range 1 (+ total-messages 1))) '(uid header)))
(define (get-subject header)
(extract-field #"SUBJECT" header))
(define (get-date header)
(extract-field #"DATE" header))
(define (get-from header)
(extract-field #"FROM" header))
(define (get-imap-message imap-connection index)
(imap-get-messages
imap-connection index '(body)))
(define (rmail-disconnect imap-connection)
(imap-disconnect imap-connection))
(define (make-rmail server username password)
(let-values ([(imap-connection total-messages recent-messages)
(rmail-connect server username password)])
(rmail imap-connection total-messages recent-messages)))
(define (disconnect-and-exit imap)
(rmail-disconnect (rmail-connection imap))
(exit))