@@ -0,0 +1,43 | |||||
|
1 | # redMine - project management software | |||
|
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU General Public License | |||
|
15 | # along with this program; if not, write to the Free Software | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
|
18 | require 'net/imap' | |||
|
19 | ||||
|
20 | module Redmine | |||
|
21 | module IMAP | |||
|
22 | class << self | |||
|
23 | def check(imap_options={}, options={}) | |||
|
24 | host = imap_options[:host] || '127.0.0.1' | |||
|
25 | port = imap_options[:port] || '143' | |||
|
26 | ssl = !imap_options[:ssl].nil? | |||
|
27 | folder = imap_options[:folder] || 'INBOX' | |||
|
28 | ||||
|
29 | imap = Net::IMAP.new(host, port, ssl) | |||
|
30 | imap.login(imap_options[:username], imap_options[:password]) unless imap_options[:username].nil? | |||
|
31 | imap.select(folder) | |||
|
32 | imap.search(['ALL']).each do |message_id| | |||
|
33 | puts "Receiving message #{message_id}" | |||
|
34 | msg = imap.fetch(message_id,'RFC822')[0].attr['RFC822'] | |||
|
35 | if MailHandler.receive(msg, options) | |||
|
36 | imap.store(message_id, "+FLAGS", [:Deleted]) | |||
|
37 | end | |||
|
38 | end | |||
|
39 | imap.expunge | |||
|
40 | end | |||
|
41 | end | |||
|
42 | end | |||
|
43 | end |
@@ -15,7 +15,10 | |||||
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | desc <<-END_DESC |
|
18 | namespace :redmine do | |
|
19 | namespace :email do | |||
|
20 | ||||
|
21 | desc <<-END_DESC | |||
19 | Read an email from standard input. |
|
22 | Read an email from standard input. | |
20 |
|
23 | |||
21 | Available options: |
|
24 | Available options: | |
@@ -25,13 +28,42 Example: | |||||
25 | rake redmine:email:receive project=foo RAILS_ENV="production" |
|
28 | rake redmine:email:receive project=foo RAILS_ENV="production" | |
26 | END_DESC |
|
29 | END_DESC | |
27 |
|
30 | |||
28 | namespace :redmine do |
|
|||
29 | namespace :email do |
|
|||
30 | task :receive => :environment do |
|
31 | task :receive => :environment do | |
31 | options = {} |
|
32 | options = {} | |
32 | options[:project] = ENV['project'] if ENV['project'] |
|
33 | options[:project] = ENV['project'] if ENV['project'] | |
33 |
|
34 | |||
34 | MailHandler.receive(STDIN.read, options) |
|
35 | MailHandler.receive(STDIN.read, options) | |
35 | end |
|
36 | end | |
|
37 | ||||
|
38 | desc <<-END_DESC | |||
|
39 | Read emails from an IMAP server. | |||
|
40 | ||||
|
41 | Available IMAP options: | |||
|
42 | * host => IMAP server host (default: 127.0.0.1) | |||
|
43 | * port => IMAP server port (default: 143) | |||
|
44 | * ssl => Use SSL? (default: false) | |||
|
45 | * username => IMAP account | |||
|
46 | * password => IMAP password | |||
|
47 | * folder => IMAP folder to read (default: INBOX) | |||
|
48 | Other options: | |||
|
49 | * project => identifier of the project the issue should be added to | |||
|
50 | ||||
|
51 | Example: | |||
|
52 | rake redmine:email:receive_iamp host=imap.foo.bar username=redmine@somenet.foo password=xxx project=foo RAILS_ENV="production" | |||
|
53 | END_DESC | |||
|
54 | ||||
|
55 | task :receive_imap => :environment do | |||
|
56 | imap_options = {:host => ENV['host'], | |||
|
57 | :port => ENV['port'], | |||
|
58 | :ssl => ENV['ssl'], | |||
|
59 | :username => ENV['username'], | |||
|
60 | :password => ENV['password'], | |||
|
61 | :folder => ENV['folder']} | |||
|
62 | ||||
|
63 | options = {} | |||
|
64 | options[:project] = ENV['project'] if ENV['project'] | |||
|
65 | ||||
|
66 | Redmine::IMAP.check(imap_options, options) | |||
|
67 | end | |||
36 | end |
|
68 | end | |
37 | end |
|
69 | end |
General Comments 0
You need to be logged in to leave comments.
Login now