Re: [racket-users] [Racket-users] IMAP with racket

2017-02-11 Thread Tim Hanson
p.s. I just found this:
  
https://planet.racket-lang.org/package-source/gh/gapi.plt/1/3/planet-docs/manual/Examples.html

which leads here:
  
https://github.com/greghendershott/gapi/blob/master/examples/macro/gplus-oauth.rkt

and looks promising. (I didn't find any signs of oauth use in sirmail (or for 
that matter in racket on github, but I probably don't know where to look)).

I found this:
  
https://pkgs.racket-lang.org/#(!deprecated)(!main-distribution)(!main-tests)(oauth)

Why does google rely on / require a thing which is an emerging standard and 
still unstable?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] [Racket-users] IMAP with racket

2017-02-11 Thread Tim Hanson
Bravo! This parallels my motivation. I'm kind of a beginner in Racket, but it 
is powerful, portable, elegant, well-documented, and well-supported, so I keep 
dabbling ...

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] [Racket-users] IMAP with racket

2017-02-11 Thread Huang, Ying
Anthony Carrico  writes:

> FYI, on the subject of Racket + IMAP:
>
> 1. Greg Hendershott's feeds2gmail pushes RSS feeds to the gmail host
> over IMAP. I fixed a few gmail specific bugs and limitations making it a
> general "feeds2imap" in this branch:
>   https://github.com/acarrico/feeds2gmail/tree/imap
> I've tested this with the popular Courier imap server.
>
> I think my branch will remain a fork since since Greg isn't currently
> using feeds2gmail (I'm actually curious what he's using, after putting
> the effort into feeds2gmail, but we haven't made the time to discuss
> it). As for me, I've setup a few feeds using my branch, but haven't
> decided if I'll use it long term. If I do so, I'll probably need a
> couple more features/fixes.
>
> 2. I've played with the Lua based imapfilter, which seems nice. I'm not
> sure if there is a good argument for porting that to Racket:
>   https://github.com/lefcha/imapfilter

One of my email service provider don't support server side searching
which I found imapfilter depends on.  So I write a script in Racket to
filter the email in client side.  Because I don't familiar with lua, so
Racket is a better tool for me to customize at this level.

Best Regards,
Huang, Ying


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] IMAP with racket

2017-02-11 Thread Tim Hanson
Thanks, all, this rings a bell and I note that:

  https://docs.racket-lang.org/webapi/oauth2.html

says use with caution. I will look around and see if I can figure out how to do 
imap in conjunction with oauth2.

Cheers,

Tim

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] IMAP with racket

2017-02-11 Thread Philip McGrath
I have used net/imap with gmail, though it does require enabling "less
secure apps" (the link George sent has instructions). I believe the only
"less secure" part is that you want to use IMAP for authentication and not
OAuth.

-Philip

On Sat, Feb 11, 2017 at 7:55 AM, George Neuner  wrote:

>
> On 2/11/2017 7:04 AM, Tim Hanson wrote:
>
> I have successfully connected to two of the mail servers I use this way, but 
> not yet to gmail. Has anyone successfully connected to gmail using either of 
> the approaches tested here? Maybe someone can point out what I'm doing wrong?
>
>
> I haven't messed with IMAP.  I have successfully used SMTP and POP with
> gmail.
>
> (I remember gmail was finicky a while back when I tried connecting to it 
> using Thunderbird; at some point it broke, with google warning some insecure 
> app was trying to access my mail (same thing happens with my racket attempts 
> so far). I was later able to connect after sufficiently upgrading 
> Thunderbird. (More at 
> https://support.mozilla.org/t5/Set-up-email/Thunderbird-and-Gmail/ta-p/14181)).
>
>
> See:   https://support.google.com/accounts/answer/6010255
>
>
> George
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] [Racket-users] IMAP with racket

2017-02-11 Thread Anthony Carrico
FYI, on the subject of Racket + IMAP:

1. Greg Hendershott's feeds2gmail pushes RSS feeds to the gmail host
over IMAP. I fixed a few gmail specific bugs and limitations making it a
general "feeds2imap" in this branch:
  https://github.com/acarrico/feeds2gmail/tree/imap
I've tested this with the popular Courier imap server.

I think my branch will remain a fork since since Greg isn't currently
using feeds2gmail (I'm actually curious what he's using, after putting
the effort into feeds2gmail, but we haven't made the time to discuss
it). As for me, I've setup a few feeds using my branch, but haven't
decided if I'll use it long term. If I do so, I'll probably need a
couple more features/fixes.

2. I've played with the Lua based imapfilter, which seems nice. I'm not
sure if there is a good argument for porting that to Racket:
  https://github.com/lefcha/imapfilter

-- 
Anthony Carrico


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: [racket-users] IMAP with racket

2017-02-11 Thread George Neuner


On 2/11/2017 7:04 AM, Tim Hanson wrote:
I have successfully connected to two of the mail servers I use this 
way, but not yet to gmail. Has anyone successfully connected to gmail 
using either of the approaches tested here? Maybe someone can point 
out what I'm doing wrong?


I haven't messed with IMAP.  I have successfully used SMTP and POP with 
gmail.


(I remember gmail was finicky a while back when I tried connecting to 
it using Thunderbird; at some point it broke, with google warning some 
insecure app was trying to access my mail (same thing happens with my 
racket attempts so far). I was later able to connect after 
sufficiently upgrading Thunderbird. (More at 
https://support.mozilla.org/t5/Set-up-email/Thunderbird-and-Gmail/ta-p/14181)).


See:   https://support.google.com/accounts/answer/6010255


George

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] IMAP with racket

2017-02-11 Thread Tim Hanson
Thanks again for several helpful pointers. I've recorded humble beginnings here:

  https://github.com/tbhanson/imap-with-racket

Comments and suggestions very welcome. (I know in particular I'd like to have a 
handy way to store my credentials somewhere, am using ~/.myImapCreds for now, 
but am unsure whether to keep server connection details in the same place or a 
kind of parallel place.) 

I have successfully connected to two of the mail servers I use this way, but 
not yet to gmail. Has anyone successfully connected to gmail using either of 
the approaches tested here? Maybe someone can point out what I'm doing wrong? 

(I remember gmail was finicky a while back when I tried connecting to it using 
Thunderbird; at some point it broke, with google warning some insecure app was 
trying to access my mail (same thing happens with my racket attempts so far). I 
was later able to connect after sufficiently upgrading Thunderbird. (More at 
https://support.mozilla.org/t5/Set-up-email/Thunderbird-and-Gmail/ta-p/14181)).

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] IMAP with racket

2017-02-10 Thread Huang, Ying
Hi, Tim,

Tim Hanson  writes:

> I should have dug around in sirmail sooner. Armed with the hint about 
> parametrize I've now found this:
>
>   (if (get-pref 'sirmail:use-ssl?)
>   (let-values ([(in out) (ssl-connect server port-no)])
> (imap-connect* in out (USERNAME) passwd mailbox-name))
>   (parameterize ([imap-port-number port-no])
> (imap-connect server (USERNAME) 
>   passwd
>   mailbox-name)))
>
> I guess I naively thought I'd be able to do something like this
>
> (let-values
> ([(imap-connection messages# nu)
>   (parameterize ([imap-port-number port])
>(imap-connect hostname mailaddress password folder 
> #:tls? tls-before? #:try-tls? try-tls?))])
>
> but so far I think it has worked only with an account that uses #:try-tls?, 
> not yet for #:tls?.
>
> I had seen 
>   
> https://docs.racket-lang.org/net/imap.html#%28def._%28%28lib._net%2Fimap..rkt%29._imap-connect%2A%29%29
>
> in the docs, but wasn't sure how to do it. I can try following the example 
> above.

Recently, I just implemented an IMAP mail filter based on net/imap.
Hope it is useful for you.

Best Regards,
Huang, Ying

#!/usr/bin/env racket
#lang racket

(require net/imap)

(define read-string-batch 4096)

(define (read-string/all [in (current-input-port)])
  (apply string-append
 (for/list ([str (in-producer (λ ()
(read-string read-string-batch in))
  eof)])
   str)))

(define (process/out/s command #:set-pwd?
   [set-pwd? (member (system-type) '(unix macosx))])
  (let ([outp null])
(dynamic-wind
  values
  (thunk
   (set! outp
 (car (process/ports #f (current-input-port) (current-error-port)
 command #:set-pwd? set-pwd?)))
   (read-string/all outp))
  (thunk (when (port? outp)
   (close-input-port outp))

(define (process/out/ss command #:set-pwd?
[set-pwd? (member (system-type) '(unix macosx))])
  (string-trim (process/out/s command #:set-pwd? set-pwd?)))

(define (imap-fetch imap total start len)
  (let* ([end (min (add1 total) (+ start len))]
 [msg-nums (sequence->list (in-range start end))])
(when (pair? msg-nums)
  (imap-get-messages imap msg-nums '(header)

(define (messages-filter messages start pattern)
  (for/fold ([result empty])
([msg messages]
 [num (in-naturals start)])
(let ([header (car msg)])
  (if (regexp-match? pattern header)
  (cons num result)
  result

(define (messages-remove messages start to-remove-msg-nums)
  (reverse
   (for/fold ([result empty])
 ([msg messages]
  [num (in-naturals start)])
 (if (member num to-remove-msg-nums eqv?)
 result
 (cons msg result)

(define (header-contain header pattern)
  (regexp (format "(?im:^~a: .*~a.*$)" header pattern)))

(define (imap-get-expunges-number imap)
  (length (imap-get-expunges imap)))

(define (call-with-check-expunges imap thk with without)
  (let* ([val-list (call-with-values thk list)]
 [expunges-number (imap-get-expunges-number imap)])
(if (> expunges-number 0)
(with expunges-number)
(apply without val-list

(define (imap-filter-move imap total . pattern_dest-mailboxes)
  (let filter-move ([start 1]
[total total])
(when (and (> total 0)
   (<= start total)
   (pair? pattern_dest-mailboxes))
  (let ([start (max start 1)])
(call-with-check-expunges imap
 (thunk (imap-fetch imap total start batch))
 (λ (expunges-number)
   (filter-move (- start expunges-number)
(- total expunges-number)))
 (λ (msgs)
  (let loop ([pds pattern_dest-mailboxes]
 [total total]
 [msgs msgs])
(if (and (pair? pds) (pair? msgs))
(let* ([pattern_dest-mailbox (car pds)]
   [pattern (first pattern_dest-mailbox)]
   [dest-mailbox (second pattern_dest-mailbox)]
   [tm-msg-nums (messages-filter msgs start pattern)])
  (if (pair? tm-msg-nums)
  (call-with-check-expunges imap
   (thunk (imap-copy imap tm-msg-nums dest-mailbox))
   (λ (expunges-number)
 (filter-move (- start expunges-number)
  (- total expunges-number)))
   (λ (v)
 (call-with-check-expunges imap
  (thunk
   (imap-store imap '+ tm-msg-nums
   (list 

Re: [racket-users] IMAP with racket

2017-02-08 Thread Tim Hanson
Cool, thank you! I had no idea about parameterize. I will try that and continue 
my investigations.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] IMAP with racket

2017-02-08 Thread Matthew Flatt
At Tue, 7 Feb 2017 21:54:40 -0800 (PST), Tim Hanson wrote:
> https://docs.racket-lang.org/net/imap.html#%28def._%28%28lib._net%2Fimap..rkt%2
> 9._imap-port-number%29%29
> 
> Does this make imap-port-number a kind of global variable?

Normally, `imap-port-number` would be used with `parameterize` to
localize a setting:

 (parameterize ([imap-port-number 12345])
   (imap-connect ))

I agree that an optional keyword argument would be better in this case,
and it's just that the parameter predates keyword-argument support.
(It's a relatively old library.) Arguments like `#:tls?` were added
later.

A `#:port-number` argument that defaults to the parameter value would
work well.

At Wed, 8 Feb 2017 01:38:05 -0800 (PST), Tim Hanson wrote:
> P.s. For that matter couldn't folder also be optional, defaulting to "INBOX"?

That also sounds to me like a fine improvement.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] IMAP with racket

2017-02-08 Thread Tim Hanson
P.s. For that matter couldn't folder also be optional, defaulting to "INBOX"?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] IMAP with racket

2017-02-07 Thread Tim Hanson
hi, I'm finally finding time to dig into this a little and have a question about

  
https://docs.racket-lang.org/net/imap.html#%28def._%28%28lib._net%2Fimap..rkt%29._imap-port-number%29%29

Does this make imap-port-number a kind of global variable? My naive view is it 
would be somewhat friendlier to make it an optional parameter to imap-connect 
along the lines of

  [ #:tls? tls?  
#:try-tls? try-tls?]

but defaulting to 143. 

Does it become an attribute of an open imap-connection or does it remain a 
global, say if I hypothetically had two imap-connections going at once? 

I will experiment and maybe learn more, but thought I'd ask about this in the 
meantime.

Cheers,

Tim

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] IMAP with racket

2016-12-27 Thread Tim Hanson
Thanks for both answers! I'll report back when I've made some progress!

Cheers,

Tim

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] IMAP with racket

2016-12-27 Thread Matthias Felleisen

> On Dec 27, 2016, at 2:32 AM, Tim Hanson  wrote:
> 
> Hi, I think I'd like to try using racket as a way to explore relatively 
> simple ways of getting a grip on some mail accounts that have gotten out of 
> hand. Specifically I'd like to be able to
> - compute some statistics, such as number of mails from various addresses
> - reorganize / clean-up, say by moving mails into folders according to rules 
> or deleting mails from specific senders older than a given amount
> 
> I have done similar things in the past using built-in functions in mail 
> clients such as outlook or entourage. (If thunderbird supports such functions 
> I could use that now, but I haven't found clues that it does; I even looked 
> at AppleScript and began using it to explore, but quickly got pretty 
> frustrated with the language and its documentation.)
> 
> I like racket, though, and it would seem to be great to be able to try out 
> functions interactively in the REPL.
> 
> My impression on first glance though, was that the built-in IMAP support 
> would require quite a bit of assembly and additions. I also found SirMail, 
> which looks like more than what I need, though presumably I could make use of 
> its foundation parts if I could figure out which and how.
> 
> Might it be appropriate to build something between the IMAP basics and 
> SirMail? Alternatively, is there a brief how-to for SirMail? I found the 
> sources on github and they seemed to work immediately, but I have some 
> questions about set-up. Perhaps I could even help write a brief "how to" with 
> input from the authors?
> 
> (Maybe there are more appropriate, "easier" ways of doing what I want to do 
> that others think of immediately, in which case clues would be appreciated.)


I recently had to download, parse, and pre-grade IMAP folders. Other than 
fiddling with a bunch of flags, it turned out to be a relatively 
straightforward scripting task. What you’re asking for is a scrip that will 
sooner or later turn into an application. Once you have that, I bet it will be 
easy to factor out a library that you can package up and deposit at 
pkgs.racket-lang.org . 

I am appending the module that connected my script to the IMAP server. 

(The script was used by a number of colleagues here, which uncovered a weakness 
in the encoding step of IMAP. If you are using ‘unusual’ passwords, work with 
GIT HEAD instead of 6.7.) 



#lang racket

(provide
 ;; type Message = (list String String String [Listof String])
 
 ;; String String String -> [Listof Message]
 ;; retrieves messages from user's Zimbra CCS email at folder
 retrieve-messages)

;; 
---
;; dependencies

(require net/imap)
(require net/head)

;; 
---
;; implementation 

(define ZIMBRA “…")
(define TLS-1? #true)

(define (retrieve-messages user password folder)
  (define flags '(header body))
  (define-values (imap-connection messages# nu)
(imap-connect ZIMBRA user password folder #:try-tls? TLS-1?))

  (define messages (imap-get-messages imap-connection (build-list messages# 
add1) flags))

  (for/list ((s messages))
(define head (first s))
(define to(bytes->string/utf-8 (extract-field #"to" head)))
(define from  (bytes->string/utf-8 (extract-field #"from" head)))
(define subject   (bytes->string/utf-8 (extract-field #"subject" head)))
(list to from subject (bytes->strings (second s)

;; [Listof Bytes] -> [Listof String]
(define (bytes->strings b)
  (for/list ((l (port->bytes-lines (open-input-bytes b
(bytes->string/utf-8 l)))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] IMAP with racket

2016-12-26 Thread Tim Hanson
Hi, I think I'd like to try using racket as a way to explore relatively simple 
ways of getting a grip on some mail accounts that have gotten out of hand. 
Specifically I'd like to be able to
- compute some statistics, such as number of mails from various addresses
- reorganize / clean-up, say by moving mails into folders according to rules or 
deleting mails from specific senders older than a given amount

I have done similar things in the past using built-in functions in mail clients 
such as outlook or entourage. (If thunderbird supports such functions I could 
use that now, but I haven't found clues that it does; I even looked at 
AppleScript and began using it to explore, but quickly got pretty frustrated 
with the language and its documentation.)

I like racket, though, and it would seem to be great to be able to try out 
functions interactively in the REPL.

My impression on first glance though, was that the built-in IMAP support would 
require quite a bit of assembly and additions. I also found SirMail, which 
looks like more than what I need, though presumably I could make use of its 
foundation parts if I could figure out which and how.

Might it be appropriate to build something between the IMAP basics and SirMail? 
Alternatively, is there a brief how-to for SirMail? I found the sources on 
github and they seemed to work immediately, but I have some questions about 
set-up. Perhaps I could even help write a brief "how to" with input from the 
authors?

 (Maybe there are more appropriate, "easier" ways of doing what I want to do 
that others think of immediately, in which case clues would be appreciated.)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.