Browse Source

Introduced config.interface_handle to find out via which interface the source code got executed.

Martin Edenhofer 8 years ago
parent
commit
4628299d20

+ 5 - 1
app/controllers/application_controller.rb

@@ -15,7 +15,7 @@ class ApplicationController < ActionController::Base
                 :model_index_render
 
   skip_before_action :verify_authenticity_token
-  before_action :set_user, :session_update, :user_device_check, :cors_preflight_check
+  before_action :set_interface_handle, :set_user, :session_update, :user_device_check, :cors_preflight_check
   after_action  :trigger_events, :http_log, :set_access_control_headers
 
   rescue_from StandardError, with: :server_error
@@ -58,6 +58,10 @@ class ApplicationController < ActionController::Base
 
   private
 
+  def set_interface_handle
+    ApplicationHandleInfo.current = 'application_server'
+  end
+
   # execute events
   def trigger_events
     Observer::Transaction.commit

+ 15 - 6
app/models/channel/email_parser.rb

@@ -390,6 +390,8 @@ retrns
   end
 
   def _process(channel, msg)
+
+    # parse email
     mail = parse(msg)
 
     # run postmaster pre filter
@@ -410,7 +412,14 @@ retrns
     }
 
     # check ignore header
-    return true if mail[ 'x-zammad-ignore'.to_sym ] == 'true' || mail[ 'x-zammad-ignore'.to_sym ] == true
+    if mail[ 'x-zammad-ignore'.to_sym ] == 'true' || mail[ 'x-zammad-ignore'.to_sym ] == true
+      Rails.logger.info "ignored email with msgid '#{mail[:message_id]}' from '#{mail[:from]}' because of x-zammad-ignore header"
+      return true
+    end
+
+    # set interface handle
+    original_interface_handle = ApplicationHandleInfo.current
+    ApplicationHandleInfo.current = "#{original_interface_handle}.postmaster"
 
     ticket  = nil
     article = nil
@@ -497,11 +506,9 @@ retrns
         set_attributes_by_x_headers(ticket, 'ticket', mail)
 
         # create ticket
-        ticket.save
+        ticket.save!
       end
 
-      # import mail
-
       # set attributes
       article = Ticket::Article.new(
         ticket_id: ticket.id,
@@ -521,7 +528,7 @@ retrns
       set_attributes_by_x_headers(article, 'article', mail)
 
       # create article
-      article.save
+      article.save!
 
       # store mail plain
       Store.add(
@@ -546,6 +553,8 @@ retrns
       end
     end
 
+    ApplicationHandleInfo.current = original_interface_handle
+
     # execute object transaction
     Observer::Transaction.commit
 
@@ -617,8 +626,8 @@ retrns
         item_object[key] = mail[ header.to_sym ]
       end
     }
-
   end
+
 end
 
 # workaround to parse subjects with 2 different encodings correctly (e. g. quoted-printable see test/fixtures/mail9.box)

+ 1 - 1
app/models/channel/filter/database.rb

@@ -8,7 +8,7 @@ module Channel::Filter::Database
     # process postmaster filter
     filters = PostmasterFilter.where( active: true, channel: 'email' ).order(:name, :created_at)
     filters.each { |filter|
-      Rails.logger.info " proccess filter #{filter.name} ..."
+      Rails.logger.info " process filter #{filter.name} ..."
       all_matches_ok = true
       min_one_rule_exists = false
       filter[:match].each { |key, meta|

+ 5 - 1
app/models/observer/ticket/article/communicate_email.rb

@@ -8,7 +8,11 @@ class Observer::Ticket::Article::CommunicateEmail < ActiveRecord::Observer
     # return if we run import mode
     return if Setting.get('import_mode')
 
-    # if sender is customer, do not communication
+    # only do send email if article got created via application_server (e. g. not
+    # if article and sender type is set via *.postmaster)
+    return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
+
+    # if sender is customer, do not communicate
     sender = Ticket::Article::Sender.lookup(id: record.sender_id)
     return 1 if sender.nil?
     return 1 if sender['name'] == 'Customer'

+ 3 - 1
app/models/observer/ticket/article/communicate_email/background_job.rb

@@ -66,7 +66,7 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
     record.preferences['delivery_status_message'] = nil
     record.preferences['delivery_status'] = 'success'
     record.preferences['delivery_status_date'] = Time.zone.now
-    record.save
+    record.save!
 
     # store mail plain
     Store.add(
@@ -91,6 +91,8 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
       recipient_list += record[key]
     }
 
+    Rails.logger.info "Send email to: '#{recipient_list}' (from #{record.from})"
+
     return if recipient_list == ''
 
     History.add(

+ 5 - 1
app/models/observer/ticket/article/communicate_facebook.rb

@@ -10,7 +10,11 @@ class Observer::Ticket::Article::CommunicateFacebook < ActiveRecord::Observer
     # return if we run import mode
     return if Setting.get('import_mode')
 
-    # if sender is customer, do not communication
+    # only do send email if article got created via application_server (e. g. not
+    # if article and sender type is set via *.postmaster)
+    return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
+
+    # if sender is customer, do not communicate
     sender = Ticket::Article::Sender.lookup(id: record.sender_id)
     return 1 if sender.nil?
     return 1 if sender['name'] == 'Customer'

+ 5 - 1
app/models/observer/ticket/article/communicate_facebook/background_job.rb

@@ -59,7 +59,11 @@ class Observer::Ticket::Article::CommunicateFacebook::BackgroundJob
     article.preferences['delivery_status'] = 'success'
     article.preferences['delivery_status_date'] = Time.zone.now
 
-    article.save
+    article.save!
+
+    Rails.logger.info "Send facebook to: '#{article.to}' (from #{article.from})"
+
+    article
   end
 
   def log_error(local_record, message)

+ 5 - 1
app/models/observer/ticket/article/communicate_twitter.rb

@@ -8,7 +8,11 @@ class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer
     # return if we run import mode
     return if Setting.get('import_mode')
 
-    # if sender is customer, do not communication
+    # only do send email if article got created via application_server (e. g. not
+    # if article and sender type is set via *.postmaster)
+    return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
+
+    # if sender is customer, do not communicate
     sender = Ticket::Article::Sender.lookup(id: record.sender_id)
     return if sender.nil?
     return if sender['name'] == 'Customer'

+ 4 - 1
app/models/observer/ticket/article/communicate_twitter/background_job.rb

@@ -68,8 +68,11 @@ class Observer::Ticket::Article::CommunicateTwitter::BackgroundJob
     article.preferences['delivery_status_date'] = Time.zone.now
 
     article.message_id = tweet.id.to_s
-    article.save
+    article.save!
 
+    Rails.logger.info "Send twitter (#{tweet.class}) to: '#{article.to}' (from #{article.from})"
+
+    article
   end
 
   def log_error(local_record, message)

+ 4 - 0
app/models/observer/ticket/article/fillup_from_email.rb

@@ -8,6 +8,10 @@ class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer
     # return if we run import mode
     return if Setting.get('import_mode')
 
+    # only do fill of email from if article got created via application_server (e. g. not
+    # if article and sender type is set via *.postmaster)
+    return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
+
     # if sender is customer, do not change anything
     sender = Ticket::Article::Sender.lookup(id: record.sender_id)
     return if sender.nil?

Some files were not shown because too many files changed in this diff