You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

email.rake 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 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. namespace :redmine do
  18. namespace :email do
  19. desc <<-END_DESC
  20. Read an email from standard input.
  21. General options:
  22. unknown_user=ACTION how to handle emails from an unknown user
  23. ACTION can be one of the following values:
  24. ignore: email is ignored (default)
  25. accept: accept as anonymous user
  26. create: create a user account
  27. no_permission_check=1 disable permission checking when receiving
  28. the email
  29. no_account_notice=1 disable new user account notification
  30. default_group=foo,bar adds created user to foo and bar groups
  31. Issue attributes control options:
  32. project=PROJECT identifier of the target project
  33. status=STATUS name of the target status
  34. tracker=TRACKER name of the target tracker
  35. category=CATEGORY name of the target category
  36. priority=PRIORITY name of the target priority
  37. allow_override=ATTRS allow email content to override attributes
  38. specified by previous options
  39. ATTRS is a comma separated list of attributes
  40. Examples:
  41. # No project specified. Emails MUST contain the 'Project' keyword:
  42. rake redmine:email:read RAILS_ENV="production" < raw_email
  43. # Fixed project and default tracker specified, but emails can override
  44. # both tracker and priority attributes:
  45. rake redmine:email:read RAILS_ENV="production" \\
  46. project=foo \\
  47. tracker=bug \\
  48. allow_override=tracker,priority < raw_email
  49. END_DESC
  50. task :read => :environment do
  51. MailHandler.receive(STDIN.read, MailHandler.extract_options_from_env(ENV))
  52. end
  53. desc <<-END_DESC
  54. Read emails from an IMAP server.
  55. General options:
  56. unknown_user=ACTION how to handle emails from an unknown user
  57. ACTION can be one of the following values:
  58. ignore: email is ignored (default)
  59. accept: accept as anonymous user
  60. create: create a user account
  61. no_permission_check=1 disable permission checking when receiving
  62. the email
  63. no_account_notice=1 disable new user account notification
  64. default_group=foo,bar adds created user to foo and bar groups
  65. Available IMAP options:
  66. host=HOST IMAP server host (default: 127.0.0.1)
  67. port=PORT IMAP server port (default: 143)
  68. ssl=SSL Use SSL? (default: false)
  69. username=USERNAME IMAP account
  70. password=PASSWORD IMAP password
  71. folder=FOLDER IMAP folder to read (default: INBOX)
  72. Issue attributes control options:
  73. project=PROJECT identifier of the target project
  74. status=STATUS name of the target status
  75. tracker=TRACKER name of the target tracker
  76. category=CATEGORY name of the target category
  77. priority=PRIORITY name of the target priority
  78. allow_override=ATTRS allow email content to override attributes
  79. specified by previous options
  80. ATTRS is a comma separated list of attributes
  81. Processed emails control options:
  82. move_on_success=MAILBOX move emails that were successfully received
  83. to MAILBOX instead of deleting them
  84. move_on_failure=MAILBOX move emails that were ignored to MAILBOX
  85. Examples:
  86. # No project specified. Emails MUST contain the 'Project' keyword:
  87. rake redmine:email:receive_imap RAILS_ENV="production" \\
  88. host=imap.foo.bar username=redmine@example.net password=xxx
  89. # Fixed project and default tracker specified, but emails can override
  90. # both tracker and priority attributes:
  91. rake redmine:email:receive_imap RAILS_ENV="production" \\
  92. host=imap.foo.bar username=redmine@example.net password=xxx ssl=1 \\
  93. project=foo \\
  94. tracker=bug \\
  95. allow_override=tracker,priority
  96. END_DESC
  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. Redmine::IMAP.check(imap_options, MailHandler.extract_options_from_env(ENV))
  107. end
  108. desc <<-END_DESC
  109. Read emails from an POP3 server.
  110. Available POP3 options:
  111. host=HOST POP3 server host (default: 127.0.0.1)
  112. port=PORT POP3 server port (default: 110)
  113. username=USERNAME POP3 account
  114. password=PASSWORD POP3 password
  115. apop=1 use APOP authentication (default: false)
  116. delete_unprocessed=1 delete messages that could not be processed
  117. successfully from the server (default
  118. behaviour is to leave them on the server)
  119. See redmine:email:receive_imap for more options and examples.
  120. END_DESC
  121. task :receive_pop3 => :environment do
  122. pop_options = {:host => ENV['host'],
  123. :port => ENV['port'],
  124. :apop => ENV['apop'],
  125. :username => ENV['username'],
  126. :password => ENV['password'],
  127. :delete_unprocessed => ENV['delete_unprocessed']}
  128. Redmine::POP3.check(pop_options, MailHandler.extract_options_from_env(ENV))
  129. end
  130. desc "Send a test email to the user with the provided login name"
  131. task :test, [:login] => :environment do |task, args|
  132. include Redmine::I18n
  133. abort l(:notice_email_error, "Please include the user login to test with. Example: rake redmine:email:test[login]") if args[:login].blank?
  134. user = User.find_by_login(args[:login])
  135. abort l(:notice_email_error, "User #{args[:login]} not found") unless user && user.logged?
  136. ActionMailer::Base.raise_delivery_errors = true
  137. begin
  138. Mailer.with_synched_deliveries do
  139. Mailer.test_email(user).deliver
  140. end
  141. puts l(:notice_email_sent, user.mail)
  142. rescue Exception => e
  143. abort l(:notice_email_error, e.message)
  144. end
  145. end
  146. end
  147. end