Project

General

Profile

Patch #2420 » email.rake

modified email.rake file (lib\tasks) - Alex Popov, 2008-12-30 23:59

 
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
namespace :redmine do
19
  namespace :email do
20

    
21
    desc <<-END_DESC
22
Read an email from standard input.
23

    
24
Issue attributes control options:
25
  project=PROJECT          identifier of the target project
26
  status=STATUS            name of the target status
27
  tracker=TRACKER          name of the target tracker
28
  category=CATEGORY        name of the target category
29
  priority=PRIORITY        name of the target priority
30
  allow_override=ATTRS     allow email content to override attributes
31
                           specified by previous options
32
                           ATTRS is a comma separated list of attributes
33

    
34
Examples:
35
  # No project specified. Emails MUST contain the 'Project' keyword:
36
  rake redmine:email:read RAILS_ENV="production" < raw_email
37

    
38
  # Fixed project and default tracker specified, but emails can override
39
  # both tracker and priority attributes:
40
  rake redmine:email:read RAILS_ENV="production" \\
41
                  project=foo \\
42
                  tracker=bug \\
43
                  allow_override=tracker,priority < raw_email
44
END_DESC
45

    
46
    task :read => :environment do
47
      options = { :issue => {} }
48
      %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
49
      options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
50
      
51
      MailHandler.receive(STDIN.read, options)
52
    end
53
    
54
    desc <<-END_DESC
55
Read emails from an IMAP server.
56

    
57
Available IMAP options:
58
  host=HOST                IMAP server host (default: 127.0.0.1)
59
  port=PORT                IMAP server port (default: 143)
60
  ssl=SSL                  Use SSL? (default: false)
61
  username=USERNAME        IMAP account
62
  password=PASSWORD        IMAP password
63
  folder=FOLDER            IMAP folder to read (default: INBOX)
64

    
65
Issue attributes control options:
66
  project=PROJECT          identifier of the target project
67
  status=STATUS            name of the target status
68
  tracker=TRACKER          name of the target tracker
69
  category=CATEGORY        name of the target category
70
  priority=PRIORITY        name of the target priority
71
  allow_override=ATTRS     allow email content to override attributes
72
                           specified by previous options
73
                           ATTRS is a comma separated list of attributes
74
  
75
Examples:
76
  # No project specified. Emails MUST contain the 'Project' keyword:
77
  
78
  rake redmine:email:receive_iamp RAILS_ENV="production" \\
79
    host=imap.foo.bar username=redmine@example.net password=xxx
80

    
81

    
82
  # Fixed project and default tracker specified, but emails can override
83
  # both tracker and priority attributes:
84
  
85
  rake redmine:email:receive_iamp RAILS_ENV="production" \\
86
    host=imap.foo.bar username=redmine@example.net password=xxx ssl=1 \\
87
    project=foo \\
88
    tracker=bug \\
89
    allow_override=tracker,priority
90
END_DESC
91

    
92
    task :receive_imap => :environment do
93
      imap_options = {:host => ENV['host'],
94
                      :port => ENV['port'],
95
                      :ssl => ENV['ssl'],
96
                      :username => ENV['username'],
97
                      :password => ENV['password'],
98
                      :folder => ENV['folder']}
99
                      
100
      options = { :issue => {} }
101
      %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
102
      options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
103

    
104
      Redmine::IMAP.check(imap_options, options)
105
    end
106

    
107
    task :receive_pop => :environment do
108
      pop_options  = {:host => ENV['host'],
109
                      :port => ENV['port'],
110
                      :username => ENV['username'],
111
                      :password => ENV['password']}
112
                      
113
      options = { :issue => {} }
114
      %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
115
      options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
116

    
117
      Redmine::POP3.check(pop_options, options)
118
    end
119

    
120
  end
121
end
(1-1/2)