##// END OF EJS Templates
Use Mail instead of TMail in MailHandler....
Jean-Philippe Lang -
r9447:1ab261dda6df
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -101,10 +101,15 class Attachment < ActiveRecord::Base
101 logger.info("Saving attachment '#{self.diskfile}' (#{@temp_file.size} bytes)")
101 logger.info("Saving attachment '#{self.diskfile}' (#{@temp_file.size} bytes)")
102 md5 = Digest::MD5.new
102 md5 = Digest::MD5.new
103 File.open(diskfile, "wb") do |f|
103 File.open(diskfile, "wb") do |f|
104 buffer = ""
104 if @temp_file.respond_to?(:read)
105 while (buffer = @temp_file.read(8192))
105 buffer = ""
106 f.write(buffer)
106 while (buffer = @temp_file.read(8192))
107 md5.update(buffer)
107 f.write(buffer)
108 md5.update(buffer)
109 end
110 else
111 f.write(@temp_file)
112 md5.update(@temp_file)
108 end
113 end
109 end
114 end
110 self.digest = md5.hexdigest
115 self.digest = md5.hexdigest
@@ -15,9 +15,7
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 require 'vendor/tmail'
18 class MailHandler < ActionMailer::Base
19
20 class MailHandler
21 include ActionView::Helpers::SanitizeHelper
19 include ActionView::Helpers::SanitizeHelper
22 include Redmine::I18n
20 include Redmine::I18n
23
21
@@ -42,9 +40,8 class MailHandler
42
40
43 @@handler_options[:no_permission_check] = (@@handler_options[:no_permission_check].to_s == '1' ? true : false)
41 @@handler_options[:no_permission_check] = (@@handler_options[:no_permission_check].to_s == '1' ? true : false)
44
42
45 mail = TMail::Mail.parse(email)
43 email.force_encoding('ASCII-8BIT') if email.respond_to?(:force_encoding)
46 mail.base64_decode
44 super(email)
47 new.receive(mail)
48 end
45 end
49
46
50 def logger
47 def logger
@@ -71,7 +68,7 class MailHandler
71 end
68 end
72 # Ignore auto generated emails
69 # Ignore auto generated emails
73 self.class.ignored_emails_headers.each do |key, ignored_value|
70 self.class.ignored_emails_headers.each do |key, ignored_value|
74 value = email.header_string(key)
71 value = email.header[key]
75 if value && value.to_s.downcase == ignored_value.downcase
72 if value && value.to_s.downcase == ignored_value.downcase
76 if logger && logger.info
73 if logger && logger.info
77 logger.info "MailHandler: ignoring email with #{key}:#{value} header"
74 logger.info "MailHandler: ignoring email with #{key}:#{value} header"
@@ -118,7 +115,7 class MailHandler
118
115
119 private
116 private
120
117
121 MESSAGE_ID_RE = %r{^<redmine\.([a-z0-9_]+)\-(\d+)\.\d+@}
118 MESSAGE_ID_RE = %r{^<?redmine\.([a-z0-9_]+)\-(\d+)\.\d+@}
122 ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]*#(\d+)\]}
119 ISSUE_REPLY_SUBJECT_RE = %r{\[[^\]]*#(\d+)\]}
123 MESSAGE_REPLY_SUBJECT_RE = %r{\[[^\]]*msg(\d+)\]}
120 MESSAGE_REPLY_SUBJECT_RE = %r{\[[^\]]*msg(\d+)\]}
124
121
@@ -245,9 +242,10 class MailHandler
245 if email.attachments && email.attachments.any?
242 if email.attachments && email.attachments.any?
246 email.attachments.each do |attachment|
243 email.attachments.each do |attachment|
247 obj.attachments << Attachment.create(:container => obj,
244 obj.attachments << Attachment.create(:container => obj,
248 :file => attachment,
245 :file => attachment.decoded,
246 :filename => attachment.filename,
249 :author => user,
247 :author => user,
250 :content_type => attachment.content_type)
248 :content_type => attachment.mime_type)
251 end
249 end
252 end
250 end
253 end
251 end
@@ -295,8 +293,13 class MailHandler
295 keys.reject! {|k| k.blank?}
293 keys.reject! {|k| k.blank?}
296 keys.collect! {|k| Regexp.escape(k)}
294 keys.collect! {|k| Regexp.escape(k)}
297 format ||= '.+'
295 format ||= '.+'
298 text.gsub!(/^(#{keys.join('|')})[ \t]*:[ \t]*(#{format})\s*$/i, '')
296 keyword = nil
299 $2 && $2.strip
297 regexp = /^(#{keys.join('|')})[ \t]*:[ \t]*(#{format})\s*$/i
298 if m = text.match(regexp)
299 keyword = m[2].strip
300 text.gsub!(regexp, '')
301 end
302 keyword
300 end
303 end
301
304
302 def target_project
305 def target_project
@@ -347,20 +350,17 class MailHandler
347 # If not found (eg. HTML-only email), returns the body with tags removed
350 # If not found (eg. HTML-only email), returns the body with tags removed
348 def plain_text_body
351 def plain_text_body
349 return @plain_text_body unless @plain_text_body.nil?
352 return @plain_text_body unless @plain_text_body.nil?
350 parts = @email.parts.collect {|c| (c.respond_to?(:parts) && !c.parts.empty?) ? c.parts : c}.flatten
353
351 if parts.empty?
354 part = email.text_part || email.html_part || email
352 parts << @email
355 @plain_text_body = Redmine::CodesetUtil.to_utf8(part.body.decoded, part.charset)
353 end
356
354 plain_text_part = parts.detect {|p| p.content_type == 'text/plain'}
357 if @plain_text_body.respond_to?(:force_encoding)
355 if plain_text_part.nil?
358 # @plain_text_body = @plain_text_body.force_encoding(@email.charset).encode("UTF-8")
356 # no text/plain part found, assuming html-only email
357 # strip html tags and remove doctype directive
358 @plain_text_body = strip_tags(@email.body.to_s)
359 @plain_text_body.gsub! %r{^<!DOCTYPE .*$}, ''
360 else
361 @plain_text_body = plain_text_part.body.to_s
362 end
359 end
363 @plain_text_body.strip!
360
361 # strip html tags and remove doctype directive
362 @plain_text_body = strip_tags(@plain_text_body.strip)
363 @plain_text_body.sub! %r{^<!DOCTYPE .*$}, ''
364 @plain_text_body
364 @plain_text_body
365 end
365 end
366
366
@@ -407,9 +407,13 class MailHandler
407 # Creates a User for the +email+ sender
407 # Creates a User for the +email+ sender
408 # Returns the user or nil if it could not be created
408 # Returns the user or nil if it could not be created
409 def create_user_from_email
409 def create_user_from_email
410 addr = email.from_addrs.to_a.first
410 from = email.header['from'].to_s
411 if addr && !addr.spec.blank?
411 addr, name = from, nil
412 user = self.class.new_user_from_attributes(addr.spec, TMail::Unquoter.unquote_and_convert_to(addr.name, 'utf-8'))
412 if m = from.match(/^"?(.+?)"?\s+<(.+@.+)>$/)
413 addr, name = m[2], m[1]
414 end
415 if addr.present?
416 user = self.class.new_user_from_attributes(addr, name)
413 if user.save
417 if user.save
414 user
418 user
415 else
419 else
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (590 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (962 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (1162 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (578 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (1060 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (504 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (927 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (596 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now