ruby 检查电子邮件内容差异。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 检查电子邮件内容差异。相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env ruby
# See https://workflow.advisory.com/browse/CAM-11198

if __FILE__ != $0
  exit 0
end

$stderr.sync = true
require "optparse"

usage = %{
  Usage: ruby script/CAM-11198.rb

  Output data for a sample group of 1000 emails with HTML content, the idea is to
  compare sanitized to unsanitezed HTML.

  Options:
    -h, --help    Shows usage information
}

file_name = "CAM-11198-output-diff.html"

ARGV.options do |opts|
  opts.on_tail("-h", "--help") do
    warn usage
    exit 1
  end
  opts.parse!
end

require "bundler/setup"
require File.expand_path("../../config/environment", __FILE__)
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.clear_reloadable_connections!

begin
  output = File.open( file_name , "w" )
  output << <<-HTML
    <html>
      <head>
        <title>CAM-11198 diff</title>
        <style>
          #{Diffy::CSS_COLORBLIND_1}
          .message{
            border: 2px solid #000;
            margin-bottom: 10px;
          }
          p {
            border-bottom: 1px solid #777;
            margin: 0;
            background: #ddd;
            padding: 10px;
          }
        </style>
      </head>
    <body>
  HTML

  # Get the message list and compare.
  messages = GradesFirst::Message.all(
    select: "id, message",
    conditions: [
      "message LIKE ? AND created_at < ?",
      "%>%",
      Date.today.beginning_of_year
    ],
    order: "created_at",
    limit: 1000
  )

  output << "nothing to compare!" if messages.empty?
  messages.each do |msg|
    sanitized_message = Sanitize.fragment(msg.message, Sanitize::Config::RELAXED)
    output << '<div class="message">'
    output << "<p>Message ID: #{msg.id}</p>"
    output << Diffy::Diff.new(msg.message, sanitized_message).to_s(:html)
    output << '</div>'
  end

ensure
  output << "</body></html>"
  output.close
end

以上是关于ruby 检查电子邮件内容差异。的主要内容,如果未能解决你的问题,请参考以下文章

电子病历与纸质病历的差异

如何在 ruby​​ 中从 net//smtp 发送电子邮件中的 HTML 内容?

ruby Ruby:确定时间差异

ruby 布尔运算符或 ||差异[重复]

ruby + =和= +之间的差异

如何解决 ruby​​ on rails 版本差异(向后/向前兼容性)