Просмотр исходного кода

Maintenance: Switch to 'mail' gem v2.8 rather than a custom patched version.

Martin Gruner 2 лет назад
Родитель
Сommit
bbfac62c12

+ 1 - 2
Gemfile

@@ -114,8 +114,7 @@ gem 'twitter'
 # channels - email additions
 gem 'email_address'
 gem 'htmlentities'
-# TODO: remove git information once v2.8 is released and works with Zammad
-gem 'mail', git: 'https://github.com/zammad-deps/mail', branch: '2-7-stable'
+gem 'mail'
 gem 'mime-types'
 gem 'rchardet', '>= 1.8.0'
 

+ 15 - 9
Gemfile.lock

@@ -8,14 +8,6 @@ GIT
       nokogiri
       nori
 
-GIT
-  remote: https://github.com/zammad-deps/mail
-  revision: 9265cf75bbe376f595944bd10d2dd953f863e765
-  branch: 2-7-stable
-  specs:
-    mail (2.7.2.edge)
-      mini_mime (>= 0.1.1)
-
 GEM
   remote: https://rubygems.org/
   specs:
@@ -277,6 +269,11 @@ GEM
     loofah (2.19.0)
       crass (~> 1.0.2)
       nokogiri (>= 1.5.9)
+    mail (2.8.0)
+      mini_mime (>= 0.1.1)
+      net-imap
+      net-pop
+      net-smtp
     marcel (1.0.2)
     matrix (0.4.2)
     memoizable (0.4.2)
@@ -298,7 +295,15 @@ GEM
     mysql2 (0.5.4)
     naught (1.1.0)
     nestful (1.1.4)
+    net-imap (0.3.1)
+      net-protocol
     net-ldap (0.17.1)
+    net-pop (0.1.2)
+      net-protocol
+    net-protocol (0.2.0)
+      timeout
+    net-smtp (0.3.3)
+      net-protocol
     nio4r (2.5.8)
     nokogiri (1.13.10)
       mini_portile2 (~> 2.8.0)
@@ -541,6 +546,7 @@ GEM
     thor (1.2.1)
     thread_safe (0.3.6)
     tilt (2.0.11)
+    timeout (0.3.1)
     twilio-ruby (5.73.4)
       faraday (>= 0.9, < 3.0)
       jwt (>= 1.5, <= 2.5)
@@ -653,7 +659,7 @@ DEPENDENCIES
   json
   koala
   listen
-  mail!
+  mail
   messagebird-rest
   mime-types
   minitest-profile

+ 3 - 3
app/models/channel/email_parser.rb

@@ -600,10 +600,10 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again
       h['x-any-recipient'] = h.values.select(&:present?).join(', ')
       h['message_id']      = imported_fields['message-id']
       h['subject']         = imported_fields['subject']
-      begin
-        h['date'] = Time.zone.parse(mail.date.to_s) || imported_fields['date']
+      h['date']            = begin
+        Time.zone.parse(mail.date.to_s)
       rescue
-        h['date'] = nil
+        nil
       end
     end
 

+ 1 - 1
spec/models/channel/driver/sendmail_spec.rb

@@ -7,7 +7,7 @@ RSpec.describe Channel::Driver::Sendmail do
 
     let(:address) { Faker::Internet.email }
     let(:body)    { Faker::Lorem.sentence(word_count: 3) }
-    let(:file)    { Rails.root.join("tmp/mails/#{address}") }
+    let(:file)    { Rails.root.join("tmp/mails/#{address}.eml") }
 
     around do |example|
       ENV['ZAMMAD_MAIL_TO_FILE'] = '1'

+ 1 - 1
spec/models/channel/email_build_spec.rb

@@ -86,7 +86,7 @@ RSpec.describe Channel::EmailBuild, type: :model do
 
       it 'does not include content* properties in attachment preferences' do
         expect(file_attachment).not_to include(
-          'preferences' => include('content-alternative')
+          'preferences' => include('content-alternative', 'Content-ID')
         )
       end
     end

+ 31 - 0
spec/models/channel/email_parser_spec.rb

@@ -91,6 +91,37 @@ RSpec.describe Channel::EmailParser, type: :model do
         RAW
       end
     end
+
+    describe 'inline attachment' do
+      let(:cid)   { '485376C9-2486-4351-B932-E2010998F579@home' }
+      let(:html)  { "test <img src='cid:#{cid}'>" }
+      let(:store) { create(:store_image, preferences: store_preferences) }
+
+      let(:store_preferences) do
+        {
+          'Content-ID':   cid,
+          'Mime-Type':    'image/jpg',
+          'Content-Type': 'application/others; name=inline_image.jpg'
+        }
+      end
+
+      it 'gets Content-ID' do
+        mail = Channel::EmailBuild.build(
+          from:         'sender@example.com',
+          to:           'recipient@example.com',
+          body:         html,
+          content_type: 'text/html',
+          attachments:  [ store ],
+        )
+
+        parser = described_class.new
+        data = parser.parse(mail.to_s)
+
+        inline_image_attachment = data[:attachments].last
+
+        expect(inline_image_attachment[:preferences]['Content-ID']).to eq cid
+      end
+    end
   end
 
   describe '#process' do

+ 12 - 1
spec/models/channel/filter/internal_article_check_spec.rb

@@ -7,7 +7,7 @@ RSpec.describe Channel::Filter::InternalArticleCheck do
   let(:vendor_email)    { 'vendor@example.com' }
   let(:article_to)      { vendor_email }
   let(:from)            { "From: <#{vendor_email}>" }
-  let(:message_id)      { 'some_message_id_999@example.com' }
+  let(:message_id)      { '<some_message_id_999@example.com>' }
   let(:in_reply_to)     { message_id }
   let(:article_subject) { "Subject: #{ticket.subject_build('some subject')}" }
   let(:ticket_article)  { build(:ticket_article, ticket: ticket, to: article_to, internal: false, message_id: message_id) }
@@ -184,5 +184,16 @@ RSpec.describe Channel::Filter::InternalArticleCheck do
 
       include_examples 'checks last outgoing mail'
     end
+
+    # Mail gem changed Message-Id handling in 2.7 -> 2.8
+    # Now Message-ID is automatically wrapped in <...>
+    # This checks that email incoming with non-wrapped Message-ID is successfully matched to stored wrapped Message-ID
+    context 'when <Message-Id> is stored in database, but incoming email has Message-Id' do
+      let(:message_id) { 'some_message_id_999@example.com' }
+
+      before { ticket_article.update! internal: true, message_id: "<#{message_id}>" }
+
+      include_examples 'sets new article to internal'
+    end
   end
 end

+ 8 - 3
test/data/mail/mail087.yml

@@ -16,9 +16,14 @@ attachments:
     Mime-Type: application/pdf
     Charset: UTF-8
 - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
-  data: "Sehr geehrter Kunde,\r\n\r\nSie haben soeben ein neues Fax von +491234, fuer
-    Rufnummer 012347 empfangen.\r\n\r\nEmpfangszeit: Thursday, January 23 2020, at
-    03:39 PM\r\nAbsender: +491234\r\nEmpfaenger: 01234\r\n"
+  data: |
+    Sehr geehrter Kunde,
+
+    Sie haben soeben ein neues Fax von +491234, fuer Rufnummer 012347 empfangen.
+
+    Empfangszeit: Thursday, January 23 2020, at 03:39 PM
+    Absender: +491234
+    Empfaenger: 01234
   filename: file
   preferences: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
     Charset: UTF-8