Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
add starttls option to imap
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Dec 21, 2014
1 parent 961f97f commit 968ec46
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 4 additions & 2 deletions USER_GUIDE.md
Expand Up @@ -188,15 +188,17 @@ Gmail and set it to keep messages after they have been retrieved with POP3.

### IMAP

The IMAP receiver is enabled when the `Mailman.config.imap` hash is set.
The IMAP receiver is enabled when the `Mailman.config.imap` hash is set.
Polling can be set with `Mailman.config.poll_interval`. This will read all unread messages in the INBOX by default.
Here are example settings for gmail.

```ruby
Mailman.config.imap = {
server: 'imap.gmail.com',
server: 'imap.gmail.com',
port: 993, # usually 995, 993 for gmail
ssl: true,
# Use starttls instead of ssl (do not specify both)
#starttls: true,
username: 'foo@somedomain.com',
password: 'totallyunsecuredpassword'
}
Expand Down
13 changes: 12 additions & 1 deletion lib/mailman/receiver/imap.rb
Expand Up @@ -13,7 +13,10 @@ class IMAP
# messages to
# @option options [String] :server the server to connect to
# @option options [Integer] :port the port to connect to
# @option options [Boolean] :ssl whether or not to use ssl
# @option options [Boolean] :ssl if options is true, then an attempt will
# be made to use SSL (now TLS) to connect to the server.
# @option options [Boolean] :starttls use STARTTLS command to start
# TLS session.
# @option options [String] :username the username to authenticate with
# @option options [String] :password the password to authenticate with
# @option options [String] :folder the mail folder to search
Expand All @@ -30,14 +33,22 @@ def initialize(options)
@done_flags = options[:done_flags] || [Net::IMAP::SEEN]
@port = options[:port] || 143
@ssl = options[:ssl] || false
@starttls = options[:starttls] || false
@folder = options[:folder] || "INBOX"

if @starttls && @ssl
raise StandardError.new("either specify ssl or starttls, not both")
end
end

# Connects to the IMAP server.
def connect
tries ||= 5
if @connection.nil? or @connection.disconnected?
@connection = Net::IMAP.new(@server, port: @port, ssl: @ssl)
if @starttls
@connection.starttls
end
@connection.login(@username, @password)
end
@connection.select(@folder)
Expand Down

0 comments on commit 968ec46

Please sign in to comment.