email_parser.rb 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. # encoding: utf-8
  3. require 'mail'
  4. require 'encode'
  5. class Channel::EmailParser
  6. =begin
  7. parser = Channel::EmailParser.new
  8. mail = parser.parse(msg_as_string)
  9. mail = {
  10. from: 'Some Name <some@example.com>',
  11. from_email: 'some@example.com',
  12. from_local: 'some',
  13. from_domain: 'example.com',
  14. from_display_name: 'Some Name',
  15. message_id: 'some_message_id@example.com',
  16. to: 'Some System <system@example.com>',
  17. cc: 'Somebody <somebody@example.com>',
  18. subject: 'some message subject',
  19. body: 'some message body',
  20. content_type: 'text/html', # text/plain
  21. date: Time.zone.now,
  22. attachments: [
  23. {
  24. data: 'binary of attachment',
  25. filename: 'file_name_of_attachment.txt',
  26. preferences: {
  27. content-alternative: true,
  28. Mime-Type: 'text/plain',
  29. Charset: 'iso-8859-1',
  30. },
  31. },
  32. ],
  33. # ignore email header
  34. x-zammad-ignore: 'false',
  35. # customer headers
  36. x-zammad-customer-login: '',
  37. x-zammad-customer-email: '',
  38. x-zammad-customer-firstname: '',
  39. x-zammad-customer-lastname: '',
  40. # ticket headers (for new tickets)
  41. x-zammad-ticket-group: 'some_group',
  42. x-zammad-ticket-state: 'some_state',
  43. x-zammad-ticket-priority: 'some_priority',
  44. x-zammad-ticket-owner: 'some_owner_login',
  45. # ticket headers (for existing tickets)
  46. x-zammad-ticket-followup-group: 'some_group',
  47. x-zammad-ticket-followup-state: 'some_state',
  48. x-zammad-ticket-followup-priority: 'some_priority',
  49. x-zammad-ticket-followup-owner: 'some_owner_login',
  50. # article headers
  51. x-zammad-article-internal: false,
  52. x-zammad-article-type: 'agent',
  53. x-zammad-article-sender: 'customer',
  54. # all other email headers
  55. some-header: 'some_value',
  56. }
  57. =end
  58. def parse(msg)
  59. data = {}
  60. mail = Mail.new(msg)
  61. # set all headers
  62. mail.header.fields.select(&:name).each { |field|
  63. # full line, encode, ready for storage
  64. data[field.name.to_s.downcase.to_sym] = Encode.conv('utf8', field.to_s)
  65. # if we need to access the lines by objects later again
  66. data[ "raw-#{field.name.downcase}".to_sym ] = field
  67. }
  68. # get sender
  69. from = nil
  70. ['from', 'reply-to', 'return-path'].each { |item|
  71. next if !mail[ item.to_sym ]
  72. from = mail[ item.to_sym ].value
  73. break if from
  74. }
  75. # set x-any-recipient
  76. data['x-any-recipient'.to_sym] = ''
  77. ['to', 'cc', 'delivered-to', 'x-original-to', 'envelope-to'].each { |item|
  78. next if !mail[item.to_sym]
  79. if data['x-any-recipient'.to_sym] != ''
  80. data['x-any-recipient'.to_sym] += ', '
  81. end
  82. data['x-any-recipient'.to_sym] += mail[item.to_sym].to_s
  83. }
  84. # set extra headers
  85. begin
  86. data[:from_email] = Mail::Address.new(from).address
  87. data[:from_local] = Mail::Address.new(from).local
  88. data[:from_domain] = Mail::Address.new(from).domain
  89. data[:from_display_name] = Mail::Address.new(from).display_name ||
  90. (Mail::Address.new(from).comments && Mail::Address.new(from).comments[0])
  91. rescue
  92. data[:from_email] = from
  93. data[:from_local] = from
  94. data[:from_domain] = from
  95. end
  96. # do extra decoding because we needed to use field.value
  97. data[:from_display_name] = Mail::Field.new('X-From', data[:from_display_name]).to_s
  98. # compat headers
  99. data[:message_id] = data['message-id'.to_sym]
  100. # body
  101. # plain_part = mail.multipart? ? (mail.text_part ? mail.text_part.body.decoded : nil) : mail.body.decoded
  102. # html_part = message.html_part ? message.html_part.body.decoded : nil
  103. data[:attachments] = []
  104. # multi part email
  105. if mail.multipart?
  106. # html attachment/body may exists and will be converted to strict html
  107. if mail.html_part && mail.html_part.body
  108. data[:body] = mail.html_part.body.to_s
  109. data[:body] = Encode.conv(mail.html_part.charset.to_s, data[:body])
  110. data[:body] = data[:body].html2html_strict.to_s.force_encoding('utf-8')
  111. if !data[:body].force_encoding('UTF-8').valid_encoding?
  112. data[:body] = data[:body].encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
  113. end
  114. data[:content_type] = 'text/html'
  115. end
  116. # text attachment/body exists
  117. if data[:body].empty? && mail.text_part
  118. data[:body] = mail.text_part.body.decoded
  119. data[:body] = Encode.conv(mail.text_part.charset, data[:body])
  120. if !data[:body].valid_encoding?
  121. data[:body] = data[:body].encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
  122. end
  123. data[:content_type] = 'text/plain'
  124. end
  125. # any other attachments
  126. if data[:body].empty?
  127. data[:body] = 'no visible content'
  128. data[:content_type] = 'text/plain'
  129. end
  130. # add html attachment/body as real attachment
  131. if mail.html_part
  132. filename = 'message.html'
  133. headers_store = {
  134. 'content-alternative' => true,
  135. }
  136. if mail.mime_type
  137. headers_store['Mime-Type'] = mail.html_part.mime_type
  138. end
  139. if mail.charset
  140. headers_store['Charset'] = mail.html_part.charset
  141. end
  142. attachment = {
  143. data: mail.html_part.body.to_s,
  144. filename: mail.html_part.filename || filename,
  145. preferences: headers_store
  146. }
  147. data[:attachments].push attachment
  148. end
  149. # get attachments
  150. if mail.parts
  151. mail.parts.each { |part|
  152. # protect process to work fine with spam emails, see test/fixtures/mail15.box
  153. begin
  154. attachs = _get_attachment(part, data[:attachments], mail)
  155. data[:attachments].concat(attachs)
  156. rescue
  157. attachs = _get_attachment(part, data[:attachments], mail)
  158. data[:attachments].concat(attachs)
  159. end
  160. }
  161. end
  162. # not multipart email
  163. # html part only, convert to text and add it as attachment
  164. elsif mail.mime_type && mail.mime_type.to_s.casecmp('text/html').zero?
  165. filename = 'message.html'
  166. data[:body] = mail.body.decoded
  167. data[:body] = Encode.conv(mail.charset, data[:body])
  168. data[:body] = data[:body].html2html_strict.to_s.force_encoding('utf-8')
  169. if !data[:body].valid_encoding?
  170. data[:body] = data[:body].encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
  171. end
  172. data[:content_type] = 'text/html'
  173. # add body as attachment
  174. headers_store = {
  175. 'content-alternative' => true,
  176. }
  177. if mail.mime_type
  178. headers_store['Mime-Type'] = mail.mime_type
  179. end
  180. if mail.charset
  181. headers_store['Charset'] = mail.charset
  182. end
  183. attachment = {
  184. data: mail.body.decoded,
  185. filename: mail.filename || filename,
  186. preferences: headers_store
  187. }
  188. data[:attachments].push attachment
  189. # text part only
  190. elsif !mail.mime_type || mail.mime_type.to_s == '' || mail.mime_type.to_s.casecmp('text/plain').zero?
  191. data[:body] = mail.body.decoded
  192. data[:body] = Encode.conv(mail.charset, data[:body])
  193. if !data[:body].force_encoding('UTF-8').valid_encoding?
  194. data[:body] = data[:body].encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
  195. end
  196. data[:content_type] = 'text/plain'
  197. else
  198. filename = '-no name-'
  199. data[:body] = 'no visible content'
  200. data[:content_type] = 'text/plain'
  201. # add body as attachment
  202. headers_store = {
  203. 'content-alternative' => true,
  204. }
  205. if mail.mime_type
  206. headers_store['Mime-Type'] = mail.mime_type
  207. end
  208. if mail.charset
  209. headers_store['Charset'] = mail.charset
  210. end
  211. attachment = {
  212. data: mail.body.decoded,
  213. filename: mail.filename || filename,
  214. preferences: headers_store
  215. }
  216. data[:attachments].push attachment
  217. end
  218. # strip not wanted chars
  219. data[:body].gsub!(/\n\r/, "\n")
  220. data[:body].gsub!(/\r\n/, "\n")
  221. data[:body].tr!("\r", "\n")
  222. # get mail date
  223. begin
  224. if mail.date
  225. data[:date] = Time.zone.parse(mail.date.to_s)
  226. end
  227. rescue
  228. data[:date] = nil
  229. end
  230. # remember original mail instance
  231. data[:mail_instance] = mail
  232. data
  233. end
  234. def _get_attachment(file, attachments, mail)
  235. # check if sub parts are available
  236. if !file.parts.empty?
  237. a = []
  238. file.parts.each { |p|
  239. attachment = _get_attachment(p, attachments, mail)
  240. a.concat(attachment)
  241. }
  242. return a
  243. end
  244. # ignore text/plain attachments - already shown in view
  245. return [] if mail.text_part && mail.text_part.body.to_s == file.body.to_s
  246. # ignore text/html - html part, already shown in view
  247. return [] if mail.html_part && mail.html_part.body.to_s == file.body.to_s
  248. # get file preferences
  249. headers_store = {}
  250. file.header.fields.each { |field|
  251. headers_store[field.name.to_s] = field.value.to_s
  252. }
  253. # get filename from content-disposition
  254. filename = nil
  255. # workaround for: NoMethodError: undefined method `filename' for #<Mail::UnstructuredField:0x007ff109e80678>
  256. begin
  257. filename = file.header[:content_disposition].filename
  258. rescue
  259. begin
  260. result = file.header[:content_disposition].to_s.scan( /filename=("|)(.+?)("|);/i )
  261. if result && result[0] && result[0][1]
  262. filename = result[0][1]
  263. end
  264. rescue
  265. Rails.logger.debug 'Unable to get filename'
  266. end
  267. end
  268. # for some broken sm mail clients (X-MimeOLE: Produced By Microsoft Exchange V6.5)
  269. filename ||= file.header[:content_location].to_s
  270. # generate file name
  271. if filename.blank?
  272. attachment_count = 0
  273. (1..1000).each { |count|
  274. filename_exists = false
  275. filename = 'file-' + count.to_s
  276. attachments.each { |attachment|
  277. if attachment[:filename] == filename
  278. filename_exists = true
  279. end
  280. }
  281. break if filename_exists == false
  282. }
  283. end
  284. # get mime type
  285. if file.header[:content_type] && file.header[:content_type].string
  286. headers_store['Mime-Type'] = file.header[:content_type].string
  287. end
  288. # get charset
  289. if file.header && file.header.charset
  290. headers_store['Charset'] = file.header.charset
  291. end
  292. # remove not needed header
  293. headers_store.delete('Content-Transfer-Encoding')
  294. headers_store.delete('Content-Disposition')
  295. attach = {
  296. data: file.body.to_s,
  297. filename: filename,
  298. preferences: headers_store,
  299. }
  300. [attach]
  301. end
  302. =begin
  303. parser = Channel::EmailParser.new
  304. ticket, article, user = parser.process(channel, email_raw_string)
  305. returns
  306. [ticket, article, user]
  307. do not raise an exception - e. g. if used by scheduler
  308. parser = Channel::EmailParser.new
  309. ticket, article, user = parser.process(channel, email_raw_string, fakse)
  310. returns
  311. [ticket, article, user] || false
  312. =end
  313. def process(channel, msg, exception = true)
  314. _process(channel, msg)
  315. rescue => e
  316. # store unprocessable email for bug reporting
  317. path = "#{Rails.root}/tmp/unprocessable_mail/"
  318. FileUtils.mkpath path
  319. md5 = Digest::MD5.hexdigest(msg)
  320. filename = "#{path}/#{md5}.eml"
  321. message = "ERROR: Can't process email, you will find it for bug reporting under #{filename}, please create an issue at https://github.com/zammad/zammad/issues"
  322. p message # rubocop:disable Rails/Output
  323. p 'ERROR: ' + e.inspect # rubocop:disable Rails/Output
  324. Rails.logger.error message
  325. Rails.logger.error 'ERROR: ' + e.inspect
  326. Rails.logger.error 'ERROR: ' + e.backtrace.inspect
  327. File.open(filename, 'wb') { |file|
  328. file.write msg
  329. }
  330. return false if exception == false
  331. raise e.inspect + e.backtrace.inspect
  332. end
  333. def _process(channel, msg)
  334. # parse email
  335. mail = parse(msg)
  336. # run postmaster pre filter
  337. UserInfo.current_user_id = 1
  338. filters = {}
  339. Setting.where(area: 'Postmaster::PreFilter').order(:name).each { |setting|
  340. filters[setting.name] = Kernel.const_get(Setting.get(setting.name))
  341. }
  342. filters.each { |_prio, backend|
  343. Rails.logger.debug "run postmaster pre filter #{backend}"
  344. begin
  345. backend.run(channel, mail)
  346. rescue => e
  347. Rails.logger.error "can't run postmaster pre filter #{backend}"
  348. Rails.logger.error e.inspect
  349. raise e
  350. end
  351. }
  352. # check ignore header
  353. if mail[ 'x-zammad-ignore'.to_sym ] == 'true' || mail[ 'x-zammad-ignore'.to_sym ] == true
  354. Rails.logger.info "ignored email with msgid '#{mail[:message_id]}' from '#{mail[:from]}' because of x-zammad-ignore header"
  355. return true
  356. end
  357. # set interface handle
  358. original_interface_handle = ApplicationHandleInfo.current
  359. ticket = nil
  360. article = nil
  361. session_user = nil
  362. # use transaction
  363. Transaction.execute(interface_handle: "#{original_interface_handle}.postmaster") do
  364. # get sender user
  365. session_user_id = mail[ 'x-zammad-session-user-id'.to_sym ]
  366. if !session_user_id
  367. raise 'No x-zammad-session-user-id, no sender set!'
  368. end
  369. session_user = User.lookup(id: session_user_id)
  370. if !session_user
  371. raise "No user found for x-zammad-session-user-id: #{session_user_id}!"
  372. end
  373. # set current user
  374. UserInfo.current_user_id = session_user.id
  375. # get ticket# based on email headers
  376. if mail[ 'x-zammad-ticket-id'.to_sym ]
  377. ticket = Ticket.find_by(id: mail[ 'x-zammad-ticket-id'.to_sym ])
  378. end
  379. if mail[ 'x-zammad-ticket-number'.to_sym ]
  380. ticket = Ticket.find_by(number: mail[ 'x-zammad-ticket-number'.to_sym ])
  381. end
  382. # set ticket state to open if not new
  383. if ticket
  384. set_attributes_by_x_headers(ticket, 'ticket', mail, 'followup')
  385. # save changes set by x-zammad-ticket-followup-* headers
  386. ticket.save if ticket.changed?
  387. state = Ticket::State.find(ticket.state_id)
  388. state_type = Ticket::StateType.find(state.state_type_id)
  389. # if tickte is merged, find linked ticket
  390. if state_type.name == 'merged'
  391. end
  392. # set ticket to open again
  393. if !mail[ 'x-zammad-ticket-followup-state'.to_sym ]
  394. if state_type.name != 'new' && !mail[ 'x-zammad-out-of-office'.to_sym ]
  395. ticket.state = Ticket::State.find_by(name: 'open')
  396. ticket.save!
  397. end
  398. end
  399. end
  400. # create new ticket
  401. if !ticket
  402. preferences = {}
  403. if channel[:id]
  404. preferences = {
  405. channel_id: channel[:id]
  406. }
  407. end
  408. # get default group where ticket is created
  409. group = nil
  410. if channel[:group_id]
  411. group = Group.lookup(id: channel[:group_id])
  412. end
  413. if !group || group && !group.active
  414. group = Group.where(active: true).order('id ASC').first
  415. end
  416. if !group
  417. group = Group.first
  418. end
  419. ticket = Ticket.new(
  420. group_id: group.id,
  421. title: mail[:subject] || '',
  422. state_id: Ticket::State.find_by(name: 'new').id,
  423. priority_id: Ticket::Priority.find_by(name: '2 normal').id,
  424. preferences: preferences,
  425. )
  426. set_attributes_by_x_headers(ticket, 'ticket', mail)
  427. # create ticket
  428. ticket.save!
  429. end
  430. # set attributes
  431. ticket.with_lock do
  432. article = Ticket::Article.new(
  433. ticket_id: ticket.id,
  434. type_id: Ticket::Article::Type.find_by(name: 'email').id,
  435. sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
  436. content_type: mail[:content_type],
  437. body: mail[:body],
  438. from: mail[:from],
  439. to: mail[:to],
  440. cc: mail[:cc],
  441. subject: mail[:subject],
  442. message_id: mail[:message_id],
  443. internal: false,
  444. )
  445. # x-headers lookup
  446. set_attributes_by_x_headers(article, 'article', mail)
  447. # create article
  448. article.save!
  449. # store mail plain
  450. article.save_as_raw(msg)
  451. # store attachments
  452. if mail[:attachments]
  453. mail[:attachments].each do |attachment|
  454. Store.add(
  455. object: 'Ticket::Article',
  456. o_id: article.id,
  457. data: attachment[:data],
  458. filename: attachment[:filename],
  459. preferences: attachment[:preferences]
  460. )
  461. end
  462. end
  463. end
  464. end
  465. # run postmaster post filter
  466. filters = {}
  467. Setting.where(area: 'Postmaster::PostFilter').order(:name).each { |setting|
  468. filters[setting.name] = Kernel.const_get(Setting.get(setting.name))
  469. }
  470. filters.each { |_prio, backend|
  471. Rails.logger.debug "run postmaster post filter #{backend}"
  472. begin
  473. backend.run(channel, mail, ticket, article, session_user)
  474. rescue => e
  475. Rails.logger.error "can't run postmaster post filter #{backend}"
  476. Rails.logger.error e.inspect
  477. end
  478. }
  479. # return new objects
  480. [ticket, article, session_user, mail]
  481. end
  482. def self.check_attributes_by_x_headers(header_name, value)
  483. class_name = nil
  484. attribute = nil
  485. if header_name =~ /^x-zammad-(.+?)-(followup-|)(.*)$/i
  486. class_name = $1
  487. attribute = $3
  488. end
  489. return true if !class_name
  490. if class_name.downcase == 'article'
  491. class_name = 'Ticket::Article'
  492. end
  493. return true if !attribute
  494. key_short = attribute[ attribute.length - 3, attribute.length ]
  495. return true if key_short != '_id'
  496. class_object = Object.const_get(class_name.to_classname)
  497. return if !class_object
  498. class_instance = class_object.new
  499. return false if !class_instance.association_id_check(attribute, value)
  500. true
  501. end
  502. def set_attributes_by_x_headers(item_object, header_name, mail, suffix = false)
  503. # loop all x-zammad-hedaer-* headers
  504. item_object.attributes.each { |key, _value|
  505. # ignore read only attributes
  506. next if key == 'updated_by_id'
  507. next if key == 'created_by_id'
  508. # check if id exists
  509. key_short = key[ key.length - 3, key.length ]
  510. if key_short == '_id'
  511. key_short = key[ 0, key.length - 3 ]
  512. header = "x-zammad-#{header_name}-#{key_short}"
  513. if suffix
  514. header = "x-zammad-#{header_name}-#{suffix}-#{key_short}"
  515. end
  516. # only set value on _id if value/reference lookup exists
  517. if mail[ header.to_sym ]
  518. Rails.logger.info "header #{header} found #{mail[ header.to_sym ]}"
  519. item_object.class.reflect_on_all_associations.map { |assoc|
  520. next if assoc.name.to_s != key_short
  521. Rails.logger.info "ASSOC found #{assoc.class_name} lookup #{mail[ header.to_sym ]}"
  522. item = assoc.class_name.constantize
  523. assoc_object = nil
  524. assoc_has_object = false
  525. if item.respond_to?(:name)
  526. assoc_has_object = true
  527. if item.lookup(name: mail[ header.to_sym ])
  528. assoc_object = item.lookup(name: mail[ header.to_sym ])
  529. end
  530. elsif item.respond_to?(:login)
  531. assoc_has_object = true
  532. if item.lookup(login: mail[ header.to_sym ])
  533. assoc_object = item.lookup(login: mail[ header.to_sym ])
  534. end
  535. end
  536. next if assoc_has_object == false
  537. if assoc_object
  538. item_object[key] = assoc_object.id
  539. next
  540. end
  541. # no assoc exists, remove header
  542. mail.delete(header.to_sym)
  543. }
  544. end
  545. end
  546. # check if attribute exists
  547. header = "x-zammad-#{header_name}-#{key}"
  548. if suffix
  549. header = "x-zammad-#{header_name}-#{suffix}-#{key}"
  550. end
  551. if mail[ header.to_sym ]
  552. Rails.logger.info "header #{header} found #{mail[ header.to_sym ]}"
  553. item_object[key] = mail[ header.to_sym ]
  554. end
  555. }
  556. end
  557. end
  558. module Mail
  559. # workaround to parse subjects with 2 different encodings correctly (e. g. quoted-printable see test/fixtures/mail9.box)
  560. module Encodings
  561. def self.value_decode(str)
  562. # Optimization: If there's no encoded-words in the string, just return it
  563. return str unless str.index('=?')
  564. str = str.gsub(/\?=(\s*)=\?/, '?==?') # Remove whitespaces between 'encoded-word's
  565. # Split on white-space boundaries with capture, so we capture the white-space as well
  566. str.split(/([ \t])/).map do |text|
  567. if text.index('=?') .nil?
  568. text
  569. else
  570. # Join QP encoded-words that are adjacent to avoid decoding partial chars
  571. # text.gsub!(/\?\=\=\?.+?\?[Qq]\?/m, '') if text =~ /\?==\?/
  572. # Search for occurences of quoted strings or plain strings
  573. text.scan(/( # Group around entire regex to include it in matches
  574. \=\?[^?]+\?([QB])\?[^?]+?\?\= # Quoted String with subgroup for encoding method
  575. | # or
  576. .+?(?=\=\?|$) # Plain String
  577. )/xmi).map do |matches|
  578. string, method = *matches
  579. if method == 'b' || method == 'B'
  580. b_value_decode(string)
  581. elsif method == 'q' || method == 'Q'
  582. q_value_decode(string)
  583. else
  584. string
  585. end
  586. end
  587. end
  588. end.join('')
  589. end
  590. end
  591. # issue#348 - IMAP mail fetching stops because of broken spam email (e. g. broken Content-Transfer-Encoding value see test/fixtures/mail43.box)
  592. # https://github.com/zammad/zammad/issues/348
  593. class Body
  594. def decoded
  595. if !Encodings.defined?(encoding)
  596. #raise UnknownEncodingType, "Don't know how to decode #{encoding}, please call #encoded and decode it yourself."
  597. Rails.logger.info "UnknownEncodingType: Don't know how to decode #{encoding}!"
  598. raw_source
  599. else
  600. Encodings.get_encoding(encoding).decode(raw_source)
  601. end
  602. end
  603. end
  604. end