summaryrefslogtreecommitdiffstats
path: root/extra
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-06-25 19:25:28 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-06-25 19:25:28 +0000
commit25bba80c9eb112b8ded40d2baf9f202c79d4e2ad (patch)
tree12be06ddc7c8af57a853531ea630ee3230f70c1a /extra
parent4d6f50d3febff0e9cbbab158d39b2d8c0375c6a7 (diff)
downloadredmine-25bba80c9eb112b8ded40d2baf9f202c79d4e2ad.tar.gz
redmine-25bba80c9eb112b8ded40d2baf9f202c79d4e2ad.zip
Adds a simple API and a standalone script that can be used to forward emails from a local or remote email server to Redmine (#1110).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1584 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'extra')
-rw-r--r--extra/mail_handler/rdm-mailhandler.rb79
1 files changed, 79 insertions, 0 deletions
diff --git a/extra/mail_handler/rdm-mailhandler.rb b/extra/mail_handler/rdm-mailhandler.rb
new file mode 100644
index 000000000..585afefef
--- /dev/null
+++ b/extra/mail_handler/rdm-mailhandler.rb
@@ -0,0 +1,79 @@
+#!/usr/bin/ruby
+
+# rdm-mailhandler
+# Reads an email from standard input and forward it to a Redmine server
+# Can be used from a remote mail server
+
+require 'net/http'
+require 'net/https'
+require 'uri'
+require 'getoptlong'
+
+class RedmineMailHandler
+ VERSION = '0.1'
+
+ attr_accessor :verbose, :project, :url, :key
+
+ def initialize
+ opts = GetoptLong.new(
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
+ [ '--version', '-V', GetoptLong::NO_ARGUMENT ],
+ [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
+ [ '--url', '-u', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--key', '-k', GetoptLong::REQUIRED_ARGUMENT],
+ [ '--project', '-p', GetoptLong::REQUIRED_ARGUMENT ]
+ )
+
+ opts.each do |opt, arg|
+ case opt
+ when '--url'
+ self.url = arg.dup
+ when '--key'
+ self.key = arg.dup
+ when '--help'
+ usage
+ when '--verbose'
+ self.verbose = true
+ when '--version'
+ puts VERSION; exit
+ when '--project'
+ self.project = arg.dup
+ end
+ end
+
+ usage if url.nil?
+ end
+
+ def submit(email)
+ uri = url.gsub(%r{/*$}, '') + '/mail_handler'
+ debug "Posting to #{uri}..."
+ data = { 'key' => key, 'project' => project, 'email' => email }
+ response = Net::HTTP.post_form(URI.parse(uri), data)
+ debug "Response received: #{response.code}"
+ response.code == 201 ? 0 : 1
+ end
+
+ private
+
+ def usage
+ puts "Usage: rdm-mailhandler [options] --url=<Redmine URL> --key=<API key>"
+ puts "Reads an email from standard input and forward it to a Redmine server"
+ puts
+ puts "Options:"
+ puts " --help show this help"
+ puts " --verbose show extra information"
+ puts " --project identifier of the target project"
+ puts
+ puts "Examples:"
+ puts " rdm-mailhandler --url http://redmine.domain.foo --key secret"
+ puts " rdm-mailhandler --url https://redmine.domain.foo --key secret --project foo"
+ exit
+ end
+
+ def debug(msg)
+ puts msg if verbose
+ end
+end
+
+handler = RedmineMailHandler.new
+handler.submit(STDIN.read)