Project

General

Profile

Actions

Defect #18649

closed

mail_handler.rb - does not encode non-utf8 characters

Added by Dave Nichols over 9 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Email receiving
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Duplicate
Affected version:

Description

Sorry, naive windoze user here, so apologies if i'm breaking some etiquette.

I had a problem where users posting emails to our redmine system that embedded certain unicode characters caused the email system to stall - MySQL squeaked about illegal characters and the script aborted, so no emails processed. To overcome the problem I hacked the code as shown below. This worked for us, but I no very little about ruby or rails or redmine internals so don't know if its a 'good' hack and useful to others.

def self.receive(email, options={})
    @@handler_options = options.dup

    @@handler_options[:issue] ||= {}

    if @@handler_options[:allow_override].is_a?(String)
      @@handler_options[:allow_override] = @@handler_options[:allow_override].split(',').collect(&:strip)
    end
    @@handler_options[:allow_override] ||= []
    # Project needs to be overridable if not specified
    @@handler_options[:allow_override] << 'project' unless @@handler_options[:issue].has_key?(:project)
    # Status overridable by default
    @@handler_options[:allow_override] << 'status' unless @@handler_options[:issue].has_key?(:status)

    @@handler_options[:no_account_notice] = (@@handler_options[:no_account_notice].to_s == '1')
    @@handler_options[:no_notification] = (@@handler_options[:no_notification].to_s == '1')
    @@handler_options[:no_permission_check] = (@@handler_options[:no_permission_check].to_s == '1')

    email.force_encoding('ASCII-8BIT') if email.respond_to?(:force_encoding)
    email = email.encode("UTF-8",:invalid=>:replace,:undef=>:replace,:replace=>"?") ##15/12/14 DCN HACK added
    super(email)
  end

Environment:
Redmine version 2.5.2.stable
Ruby version 1.9.3-p545 (2014-02-24) [i386-mingw32]
Rails version 3.2.19
Environment production
Database adapter Mysql2
SCM:
Subversion 1.7.2
Git 1.9.4
Filesystem
Redmine plugins:
contracts 1.2.0
redmine_customized_report 0.0.1
redmine_image_clipboard_paste 1.0.0
redmine_impersonate_plugin 0.0.1
redmine_knowledgebase 3.0.4
redmine_silencer 0.4.0
redmine_todos 2.0.5


Related issues

Is duplicate of Redmine - Defect #16122: redmine:email:receive should not abort with buggy mailNew

Actions
Actions

Also available in: Atom PDF