Project

General

Profile

Feature #4882 » email.rake

in lib/tasks - Francois-Xavier CAUVIN, 2010-02-19 16:31

 
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
Processed emails control options:
76
  move_on_success=MAILBOX  move emails that were successfully received
77
                           to MAILBOX instead of deleting them
78
  move_on_failure=MAILBOX  move emails that were ignored to MAILBOX
79
  
80
Examples:
81
  # No project specified. Emails MUST contain the 'Project' keyword:
82
  
83
  rake redmine:email:receive_iamp RAILS_ENV="production" \\
84
    host=imap.foo.bar username=redmine@example.net password=xxx
85

    
86

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

    
97
    task :receive_imap => :environment do
98
      imap_options = {:host => ENV['host'],
99
                      :port => ENV['port'],
100
                      :ssl => ENV['ssl'],
101
                      :username => ENV['username'],
102
                      :password => ENV['password'],
103
                      :folder => ENV['folder'],
104
                      :move_on_success => ENV['move_on_success'],
105
                      :move_on_failure => ENV['move_on_failure']}
106
                      
107
      options = { :issue => {} }
108
      %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
109
      options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
110

    
111
      Redmine::IMAP.check(imap_options, options)
112
    end
113
	
114
	task :receive_pop => :environment do
115
      pop_options  = {:host => ENV['host'],
116
                      :port => ENV['port'],
117
                      :username => ENV['username'],
118
                      :password => ENV['password']}
119

    
120
      options = { :issue => {} }
121
      %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
122
      options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
123

    
124
      Redmine::POP3.check(pop_options, options)
125
    end
126
	
127
	task :receive_mapi => :environment do
128

    
129
		mapi_options  = {}
130
					  
131
		options = { :issue => {} }
132
		%w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
133
		options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
134

    
135
		Redmine::MAPI.check(mapi_options, options)
136
    end
137

    
138
  end
139
end
(1-1/3)