Browse Source

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

This reverts commit bbfac62c124b95ee2a2f35cb3b930c3881e08ea8.
Martin Gruner 2 years ago
parent
commit
1ff3e0f99c

+ 2 - 1
Gemfile

@@ -114,7 +114,8 @@ gem 'twitter'
 # channels - email additions
 gem 'email_address'
 gem 'htmlentities'
-gem 'mail'
+# 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 'mime-types'
 gem 'rchardet', '>= 1.8.0'
 

+ 9 - 15
Gemfile.lock

@@ -8,6 +8,14 @@ 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:
@@ -269,11 +277,6 @@ 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)
@@ -295,15 +298,7 @@ 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)
@@ -546,7 +541,6 @@ 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)
@@ -659,7 +653,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']
-      h['date']            = begin
-        Time.zone.parse(mail.date.to_s)
+      begin
+        h['date'] = Time.zone.parse(mail.date.to_s) || imported_fields['date']
       rescue
-        nil
+        h['date'] = 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}.eml") }
+    let(:file)    { Rails.root.join("tmp/mails/#{address}") }
 
     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', 'Content-ID')
+          'preferences' => include('content-alternative')
         )
       end
     end

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

@@ -91,37 +91,6 @@ 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

+ 1 - 12
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,16 +184,5 @@ 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

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

@@ -16,14 +16,9 @@ attachments:
     Mime-Type: application/pdf
     Charset: UTF-8
 - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
-  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
+  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"
   filename: file
   preferences: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
     Charset: UTF-8