Skip to content

Commit

Permalink
fixes to make the imap email receiver more stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Gorod skidok staff committed Oct 4, 2011
1 parent 1db2d8a commit d410750
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 40 deletions.
10 changes: 0 additions & 10 deletions db/migrate/20110411125235_add_send_attachments_to_project.rb

This file was deleted.

10 changes: 0 additions & 10 deletions db/migrate/20110413113003_add_mail_from_to_issue.rb

This file was deleted.

1 change: 0 additions & 1 deletion files/delete.me

This file was deleted.

18 changes: 12 additions & 6 deletions lib/redmine/imap.rb
Expand Up @@ -5,12 +5,12 @@
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Expand All @@ -25,8 +25,8 @@ def check(imap_options={}, options={})
port = imap_options[:port] || '143'
ssl = !imap_options[:ssl].nil?
folder = imap_options[:folder] || 'INBOX'
imap = Net::IMAP.new(host, port, ssl)

imap = Net::IMAP.new(host, port, ssl)
imap.login(imap_options[:username], imap_options[:password]) unless imap_options[:username].nil?
imap.select(folder)
imap.search(['NOT', 'SEEN']).each do |message_id|
Expand All @@ -48,13 +48,19 @@ def check(imap_options={}, options={})
end
end
imap.expunge

unless imap.disconnected?
imap.logout
imap.disconnect
end
end

private

def logger
RAILS_DEFAULT_LOGGER
end
end
end
end

30 changes: 17 additions & 13 deletions lib/tasks/email.rake
Expand Up @@ -45,19 +45,23 @@ END_DESC
options[:unknown_user] = cfg['unknown_user'] if cfg['unknown_user']
options[:no_permission_check] = cfg['no_permission_check'] if cfg['no_permission_check']

case cfg['protocol']
when 'imap'
protocol_options.merge!({:ssl => cfg['ssl'],
:folder => cfg['folder'],
:move_on_success => cfg['move_on_success'],
:move_on_failure => cfg['move_on_failure']})
Redmine::IMAP.check(protocol_options, options)
when 'pop3'
protocol_options.merge!({:apop => cfg['apop'],
:delete_unprocessed => cfg['delete_unprocessed']})
Redmine::POP3.check(protocol_options, options)
else
MailHandler.receive(STDIN.read, options)
begin
case cfg['protocol']
when 'imap'
protocol_options.merge!({:ssl => cfg['ssl'],
:folder => cfg['folder'],
:move_on_success => cfg['move_on_success'],
:move_on_failure => cfg['move_on_failure']})
Redmine::IMAP.check(protocol_options, options)
when 'pop3'
protocol_options.merge!({:apop => cfg['apop'],
:delete_unprocessed => cfg['delete_unprocessed']})
Redmine::POP3.check(protocol_options, options)
else
MailHandler.receive(STDIN.read, options)
end
rescue Exception => e
puts "Error: #{e.message}"
end
end
end
Expand Down

0 comments on commit d410750

Please sign in to comment.