mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-04 04:57:51 +00:00 
			
		
		
		
	Fix: parse verification mail (#3864)
Email parsing logic was stripping of HTML tables which was causing the issue in this case. Fixes: #3731
This commit is contained in:
		@@ -5,7 +5,7 @@ module MailboxHelper
 | 
				
			|||||||
    @message = @conversation.messages.create(
 | 
					    @message = @conversation.messages.create(
 | 
				
			||||||
      account_id: @conversation.account_id,
 | 
					      account_id: @conversation.account_id,
 | 
				
			||||||
      sender: @conversation.contact,
 | 
					      sender: @conversation.contact,
 | 
				
			||||||
      content: processed_mail.text_content[:reply],
 | 
					      content: mail_content,
 | 
				
			||||||
      inbox_id: @conversation.inbox_id,
 | 
					      inbox_id: @conversation.inbox_id,
 | 
				
			||||||
      message_type: 'incoming',
 | 
					      message_type: 'incoming',
 | 
				
			||||||
      content_type: 'incoming_email',
 | 
					      content_type: 'incoming_email',
 | 
				
			||||||
@@ -48,4 +48,12 @@ module MailboxHelper
 | 
				
			|||||||
    # notification emails are send via mailer sender email address. so it should match
 | 
					    # notification emails are send via mailer sender email address. so it should match
 | 
				
			||||||
    @processed_mail.original_sender == Mail::Address.new(ENV.fetch('MAILER_SENDER_EMAIL', 'Chatwoot <accounts@chatwoot.com>')).address
 | 
					    @processed_mail.original_sender == Mail::Address.new(ENV.fetch('MAILER_SENDER_EMAIL', 'Chatwoot <accounts@chatwoot.com>')).address
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def mail_content
 | 
				
			||||||
 | 
					    if processed_mail.text_content.present?
 | 
				
			||||||
 | 
					      processed_mail.text_content[:reply]
 | 
				
			||||||
 | 
					    elsif processed_mail.html_content.present?
 | 
				
			||||||
 | 
					      processed_mail.html_content[:reply]
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,7 +15,6 @@ class HtmlParser
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  def filter_replies!
 | 
					  def filter_replies!
 | 
				
			||||||
    document.xpath('//blockquote').each { |n| n.replace('> ') }
 | 
					    document.xpath('//blockquote').each { |n| n.replace('> ') }
 | 
				
			||||||
    document.xpath('//table').each(&:remove)
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def filtered_html
 | 
					  def filtered_html
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,15 +27,16 @@ class MailPresenter < SimpleDelegator
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # returns encoded mail body text_part if available.
 | 
					  # returns encoded mail body text_part if available.
 | 
				
			||||||
 | 
					  # returns encoded mail body as it is if mail_part not available.
 | 
				
			||||||
  # else returns parsed the html body if contains text/html content.
 | 
					  # else returns parsed the html body if contains text/html content.
 | 
				
			||||||
  def select_body(mail_part)
 | 
					  def select_body(mail_part)
 | 
				
			||||||
    return '' unless mail_part
 | 
					    return encoded_mail_body unless mail_part
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    decoded = encode_to_unicode(mail_part.decoded)
 | 
					    decoded = encode_to_unicode(mail_part.decoded)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if mail.text_part
 | 
					    if mail.text_part
 | 
				
			||||||
      decoded
 | 
					      decoded
 | 
				
			||||||
    elsif (mail.content_type || '').include? 'text/html'
 | 
					    elsif html_mail_body?
 | 
				
			||||||
      ::HtmlParser.parse_reply(decoded)
 | 
					      ::HtmlParser.parse_reply(decoded)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
@@ -128,4 +129,15 @@ class MailPresenter < SimpleDelegator
 | 
				
			|||||||
  rescue StandardError
 | 
					  rescue StandardError
 | 
				
			||||||
    ''
 | 
					    ''
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def html_mail_body?
 | 
				
			||||||
 | 
					    ((mail.content_type || '').include? 'text/html') || @mail.html_part || @mail.html_part.content_type.include?('text/html')
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # returns mail body if mail content_type is text/plain
 | 
				
			||||||
 | 
					  def encoded_mail_body
 | 
				
			||||||
 | 
					    return encode_to_unicode(@mail.body.decoded) if (@mail.content_type || '').include? 'text/plain'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ''
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user