Skip to content

Commit 70da7db

Browse files
committed
📚 Update examples with modern SASL mechanisms
Also added greeting PREAUTH check to connections examples.
1 parent 9562b22 commit 70da7db

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,24 @@ Or install it yourself as:
2121

2222
## Usage
2323

24+
### Connect with TLS to port 993
25+
26+
```ruby
27+
imap = Net::IMAP.new('mail.example.com', ssl: true)
28+
imap.port => 993
29+
imap.tls_verified? => true
30+
case imap.greeting.name
31+
in /OK/i
32+
# The client is connected in the "Not Authenticated" state.
33+
imap.authenticate("PLAIN", "joe_user", "joes_password")
34+
in /PREAUTH/i
35+
# The client is connected in the "Authenticated" state.
36+
end
37+
```
38+
2439
### List sender and subject of all recent messages in the default mailbox
2540

2641
```ruby
27-
imap = Net::IMAP.new('mail.example.com')
28-
imap.authenticate('LOGIN', 'joe_user', 'joes_password')
2942
imap.examine('INBOX')
3043
imap.search(["RECENT"]).each do |message_id|
3144
envelope = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
@@ -36,8 +49,6 @@ end
3649
### Move all messages from April 2003 from "Mail/sent-mail" to "Mail/sent-apr03"
3750

3851
```ruby
39-
imap = Net::IMAP.new('mail.example.com')
40-
imap.authenticate('LOGIN', 'joe_user', 'joes_password')
4152
imap.select('Mail/sent-mail')
4253
if not imap.list('Mail/', 'sent-apr03')
4354
imap.create('Mail/sent-apr03')

lib/net/imap.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module Net
8080
# ==== List sender and subject of all recent messages in the default mailbox
8181
#
8282
# imap = Net::IMAP.new('mail.example.com')
83-
# imap.authenticate('LOGIN', 'joe_user', 'joes_password')
83+
# imap.authenticate('PLAIN', 'joe_user', 'joes_password')
8484
# imap.examine('INBOX')
8585
# imap.search(["RECENT"]).each do |message_id|
8686
# envelope = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
@@ -90,7 +90,7 @@ module Net
9090
# ==== Move all messages from April 2003 from "Mail/sent-mail" to "Mail/sent-apr03"
9191
#
9292
# imap = Net::IMAP.new('mail.example.com')
93-
# imap.authenticate('LOGIN', 'joe_user', 'joes_password')
93+
# imap.authenticate('PLAIN', 'joe_user', 'joes_password')
9494
# imap.select('Mail/sent-mail')
9595
# if not imap.list('Mail/', 'sent-apr03')
9696
# imap.create('Mail/sent-apr03')
@@ -190,7 +190,7 @@ module Net
190190
# Net::IMAP supports concurrent threads. For example,
191191
#
192192
# imap = Net::IMAP.new("imap.foo.net", "imap2")
193-
# imap.authenticate("cram-md5", "bar", "password")
193+
# imap.authenticate("scram-md5", "bar", "password")
194194
# imap.select("inbox")
195195
# fetch_thread = Thread.start { imap.fetch(1..-1, "UID") }
196196
# search_result = imap.search(["BODY", "hello"])
@@ -772,13 +772,18 @@ class << self
772772
# status # => "OK"
773773
# # The client is connected in the "Not Authenticated" state.
774774
#
775-
# Connect with TLS to port 993 at mail.example.com:
775+
# Connect with TLS to port 993
776776
# imap = Net::IMAP.new('mail.example.com', ssl: true) # => #<Net::IMAP:0x00007f79b0872bd0>
777777
# imap.port => 993
778778
# imap.tls_verified? => true
779-
# imap.greeting => name: ("OK" | "PREAUTH") => status
780-
# status # => "OK"
781-
# # The client is connected in the "Not Authenticated" state.
779+
# imap.greeting => name: (/OK/i | /PREAUTH/i) => status
780+
# case status
781+
# in /OK/i
782+
# # The client is connected in the "Not Authenticated" state.
783+
# imap.authenticate("PLAIN", "joe_user", "joes_password")
784+
# in /PREAUTH/i
785+
# # The client is connected in the "Authenticated" state.
786+
# end
782787
#
783788
# Connect with prior authentication, for example using an SSL certificate:
784789
# ssl_ctx_params = {

0 commit comments

Comments
 (0)