<commit_before># Encoding: utf-8
module Bouncefetch
  class BBMail
    attr_reader :uid, :raw, :app

    def initialize app, uid
      @app, @uid = app, uid
      app.stats.mails_checked +1
      load!
    end

    def load!
      fetchdata = app.connection.uid_fetch(uid, "RFC822")[0]
      @raw = Mail.new(fetchdata.attr["RFC822"])
    end

    def plog msg, color = :yellow
      app.log app.c("#{msg}", color)
    end

    def handle! mode = :soft, rule = nil, ignore_missing_ref = false
      cid = candidate
      if cid.present?
        plog "X", :green
        app.stats.send("handled_#{mode}_bounces", +1)
        app.registry.handle(cid, mode, raw.date, rule)
        delete! if app.cfg("general.remove_processed")
      else
        if ignore_missing_ref
          plog "X", :yellow
          app.stats.ignored_mails +1<commit_msg>Add body helper for inspecting<commit_after># Encoding: utf-8
module Bouncefetch
  class BBMail
    attr_reader :uid, :raw, :app

    def initialize app, uid
      @app, @uid = app, uid
      app.stats.mails_checked +1
      load!
    end

    def load!
      fetchdata = app.connection.uid_fetch(uid, "RFC822")[0]
      @raw = Mail.new(fetchdata.attr["RFC822"])
    end

    def mbody stripped = false
      body = raw.body.decoded.force_encoding("UTF-8")
      if stripped
        body = body.gsub(/<("[^"]*"|'[^']*'|[^'">])*>/, "").strip
      end
      body
    end

    def plog msg, color = :yellow
      app.log app.c("#{msg}", color)
    end

    def handle! mode = :soft, rule = nil, ignore_missing_ref = false
      cid = candidate
      if cid.present?
        plog "X", :green
        app.stats.send("handled_#{mode}_bounces", +1)
        app.registry.handle(cid, mode, raw.date, rule)
        delete! if app.cfg("general.remove_processed")
      else
        if ignore_missing_ref
          plog "X", :yellow
          app.stats.ignored_mails +1
{'fraction_non_alphanumeric': 0.13210526315789473, 'fraction_numerical': 0.012105263157894737, 'mean_word_length': 2.329246935201401, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1846782', 'n_tokens_mistral': 670, 'n_tokens_neox': 645, 'n_words': 161}