Project

General

Profile

Actions

Feature #16823

closed

IMAP STARTTLS support

Added by Jan Pipek over 10 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Low
Category:
Email receiving
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed

Description

Dear developers of Redmine,

I was setting up receiving emails along the guidelines in http://www.redmine.org/projects/redmine/wiki/RedmineReceivingEmails .
Our IMAP server listens on port 143, but not on the SSL port 993. It does not accept password in PLAIN format by default, for that you have to switch to TLS. Current Redmine code does not enable to configure this :-(

I think this situation might be quite common and so the possibility to use TLS (supported by Net::IMAP) might be appreciated by many users. I am including a patch (basicly a git diff) that proposes the solution by adding another option ('tls') similar to 'ssl'. I am not an expert on mail services so the code clearly has to be evaluated by someone, but at least it works for me (applied on v2.3.2).

diff --git a/lib/redmine/imap.rb b/lib/redmine/imap.rb
index 093ac3e..52e1040 100644
--- a/lib/redmine/imap.rb
+++ b/lib/redmine/imap.rb
@@ -24,9 +24,13 @@ module Redmine
         host = imap_options[:host] || '127.0.0.1'
         port = imap_options[:port] || '143'
         ssl = !imap_options[:ssl].nil?
+        tls = !imap_options[:tls].nil?
         folder = imap_options[:folder] || 'INBOX'

         imap = Net::IMAP.new(host, port, ssl)
+        if tls
+          imap.starttls
+        end
         imap.login(imap_options[:username], imap_options[:password]) unless imap_options[:username].nil?
         imap.select(folder)
         imap.uid_search(['NOT', 'SEEN']).each do |uid|
diff --git a/lib/tasks/email.rake b/lib/tasks/email.rake
index 934070e..302328d 100644
--- a/lib/tasks/email.rake
+++ b/lib/tasks/email.rake
@@ -84,6 +84,7 @@ Available IMAP options:
   host=HOST                IMAP server host (default: 127.0.0.1)
   port=PORT                IMAP server port (default: 143)
   ssl=SSL                  Use SSL? (default: false)
+  tls=TLS                  Use TLS? (default: false)
   username=USERNAME        IMAP account
   password=PASSWORD        IMAP password
   folder=FOLDER            IMAP folder to read (default: INBOX)
@@ -124,6 +125,7 @@ END_DESC
       imap_options = {:host => ENV['host'],
                       :port => ENV['port'],
                       :ssl => ENV['ssl'],
+                      :tls => ENV['tls'],
                       :username => ENV['username'],
                       :password => ENV['password'],
                       :folder => ENV['folder'],

I hope my idea is at least somewhat interesting and useful.

Regards,
Jan


Related issues

Related to Redmine - Defect #19232: IMAP STARTTLS options typo :tlsClosedJean-Philippe Lang

Actions
Actions #1

Updated by T. Hauptman about 10 years ago

+1

I just had this problem and the patch fixed it for me.

Actions #2

Updated by Jean-Baptiste Barth about 10 years ago

  • Assignee set to Jean-Baptiste Barth
  • Target version set to Candidate for next minor release

Looks good to me. Can you confirm it is automatically activated by Net::IMAP depending on the port ? I mean, if port is 993, I think starttls is performed automatically. My question is just for improving task description, the rest looks OK.

Actions #3

Updated by Jan Pipek about 10 years ago

Dear Jean-Baptiste,
my patch does not do any guessing (I believe default port is 143), it is up to the user to select SSL or TLS or nothing AND the port (see the redmine/imap.rb code), but it can be implemented easily, for sure.

Actions #4

Updated by Dmitry Kushpet almost 10 years ago

+1

Really useful idea.

Same problem. Patch helped.

Actions #5

Updated by Jean-Philippe Lang almost 10 years ago

  • Subject changed from IMAP TLS support (with proposed patch) to IMAP STARTTLS support
  • Status changed from New to Closed
  • Target version changed from Candidate for next minor release to 3.0.0
  • Resolution set to Fixed

Patch applied, with tls option renamed to starttls. Thanks.

Actions #6

Updated by Marcel Müller over 9 years ago

Jean-Philippe: Just wanted to make sure that this line is actually correct?! With your renaming to "starttls" shouldn't that be

starttls = !imap_options[:starttls].nil?

instead of
 
starttls = !imap_options[:tls].nil?

Actions #7

Updated by Toshi MARUYAMA over 9 years ago

Marcel Müller wrote:

With your renaming to "starttls" shouldn't that be
[...]
instead of
[...]

I have created #19232.

Actions #8

Updated by Go MAEDA over 9 years ago

  • Related to Defect #19232: IMAP STARTTLS options typo :tls added
Actions

Also available in: Atom PDF