<commit_before>require_dependency "letter_opener_web/application_controller"

module LetterOpenerWeb
  class LettersController < ApplicationController
    def index
      @letters = Letter.search
    end

    def show
      letter = Letter.find(params[:id])
      text   = letter.send("#{params[:style]}_text").
        gsub(/"plain\.html"/, "\"#{letter_path(:id => letter.id, :style => 'plain')}\"").
        gsub(/"rich\.html"/, "\"#{letter_path(:id => letter.id, :style => 'rich')}\"")
      render :text => text
    end

    def attachment
      letter   = Letter.find(params[:id])
      filename = "#{params[:file]}.#{params[:format]}"

      if file = letter.attachments[filename]
        send_file(file, :filename => filename, :disposition => 'inline')
      else
        render :text => 'Attachment not found!', :status => 404
      end
    end

    def clear
      Letter.destroy_all
      redirect_to letters_path
    end<commit_msg>Add controller action to delete the email with given id.<commit_after>require_dependency "letter_opener_web/application_controller"

module LetterOpenerWeb
  class LettersController < ApplicationController
    def index
      @letters = Letter.search
    end

    def show
      letter = Letter.find(params[:id])
      text   = letter.send("#{params[:style]}_text").
        gsub(/"plain\.html"/, "\"#{letter_path(:id => letter.id, :style => 'plain')}\"").
        gsub(/"rich\.html"/, "\"#{letter_path(:id => letter.id, :style => 'rich')}\"")
      render :text => text
    end

    def attachment
      letter   = Letter.find(params[:id])
      filename = "#{params[:file]}.#{params[:format]}"

      if file = letter.attachments[filename]
        send_file(file, :filename => filename, :disposition => 'inline')
      else
        render :text => 'Attachment not found!', :status => 404
      end
    end

    def clear
      Letter.destroy_all
      redirect_to letters_path
    end

    def destroy
      letter = Letter.find(params[:id])
      letter.delete
      redirect_to letters_path
    end
{'fraction_non_alphanumeric': 0.1452322738386308, 'fraction_numerical': 0.00293398533007335, 'mean_word_length': 2.8386491557223263, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '4437448', 'n_tokens_mistral': 617, 'n_tokens_neox': 599, 'n_words': 140}