<commit_before># Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/

class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer
  observe 'ticket::_article'

  def before_create(record)

    # return if we run import mode
    return if Setting.get('import_mode')

    # if sender is customer, do not change anything
    sender = Ticket::Article::Sender.lookup( :id => record.ticket_article_sender_id )
    return if sender == nil
    return if sender['name'] == 'Customer'

    # set email attributes
    type = Ticket::Article::Type.lookup( :id => record.ticket_article_type_id )
    return if type['name'] != 'email'

    # set subject if empty
    ticket = Ticket.lookup( :id => record.ticket_id )
    if !record.subject || record.subject == ''
      record.subject = ticket.title
    end

    # clean subject
    record.subject = ticket.subject_clean( record.subject )

    # generate message id
    fqdn = Setting.get('fqdn')
    record.message_id = '<' + DateTime.current.to_s(:number) + '.' + record.ticket_id.to_s + '.' + rand(999999).to_s() + '@' + fqdn + '>'

    # set sender
    email_address = ticket.group.email_address
    system_sender = "#{email_address.realname} <#{email_address.email}>"
    if Setting.get('ticket_define_email_from') == 'AgentNameSystemAddressName'
      seperator = Setting.get('ticket_define_email_from_seperator')
      sender    = User.find( record.created_by_id )
      record.from = "#{sender.firstname} #{sender.lastname} #{seperator} #{system_sender}"<commit_msg>Improved error handling.<commit_after># Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/

class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer
  observe 'ticket::_article'

  def before_create(record)

    # return if we run import mode
    return if Setting.get('import_mode')

    # if sender is customer, do not change anything
    sender = Ticket::Article::Sender.lookup( :id => record.ticket_article_sender_id )
    return if sender == nil
    return if sender['name'] == 'Customer'

    # set email attributes
    type = Ticket::Article::Type.lookup( :id => record.ticket_article_type_id )
    return if type['name'] != 'email'

    # set subject if empty
    ticket = Ticket.lookup( :id => record.ticket_id )
    if !record.subject || record.subject == ''
      record.subject = ticket.title
    end

    # clean subject
    record.subject = ticket.subject_clean( record.subject )

    # generate message id
    fqdn = Setting.get('fqdn')
    record.message_id = '<' + DateTime.current.to_s(:number) + '.' + record.ticket_id.to_s + '.' + rand(999999).to_s() + '@' + fqdn + '>'

    # set sender
    email_address = ticket.group.email_address
    if !email_address
      raise "No email address found for group '#{ticket.group.name}'"
    end
    system_sender = "#{email_address.realname} <#{email_address.email}>"
    if Setting.get('ticket_define_email_from') == 'AgentNameSystemAddressName'
      seperator = Setting.get('ticket_define_email_from_seperator')
      sender    = User.find( record.created_by_id )
      record.from = "#{sender.firstname} #{sender.lastname} #{seperator} #{system_sender}"
{'fraction_non_alphanumeric': 0.13277100905966885, 'fraction_numerical': 0.008747266479225243, 'mean_word_length': 3.800599700149925, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3628639', 'n_tokens_mistral': 1037, 'n_tokens_neox': 976, 'n_words': 218}