letter_thief 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39bd9fdf0035b1bf8b6ffdaadb8dd5df7eca96b2d9bb03c7b0a9db6c0dc80667
4
- data.tar.gz: 213afbdd43435763f9b2c40e5d62f3190a99ac96e8d2e97cffad46165ba43170
3
+ metadata.gz: 967473d3c9121f2d1d82d1d477284f251b0b19666f2511cdde5a1123b58255c2
4
+ data.tar.gz: 174d09ccdf13d992281e8533e565646069f494f36fd49b221dd7c1e665b9e1a0
5
5
  SHA512:
6
- metadata.gz: c84699514d01c43ee6fe829a98fab49642c682fbeab3cd4aa1b683b647426a37c8d3dcb5ab49e8392afa81990bc6dc7fcfae5d0c49d617003c6d9b9e637053a6
7
- data.tar.gz: eb1d35d8fec2b7130d15efd7ab616598a74d2e50d57da32a32b294292cad9215ad422218c7c0ed52940a3ff8a09059cd74de5df9cb3835b0d42105969fdfbf68
6
+ metadata.gz: 6233fbd351a7e103122aa373593bd2acab90a4143dc8fb32c31ef71642255bf2a7a796363ea4fe32daca5d0c4c2adb1677fc6a589f39da36bf90b84420838de2
7
+ data.tar.gz: ccf721f2572308ad7e592bc9afeb1c5b902fd27d30f55e97aa414068610891ead8fe1d56516a68bbadc70499674187dc482447d41ad9f813adcecfe79a5b847e
@@ -4,6 +4,10 @@ module LetterThief
4
4
  class EmailMessagesController < ApplicationController
5
5
  layout "letter_thief/application"
6
6
 
7
+ content_security_policy do |policy|
8
+ policy.style_src :self, :https, :unsafe_inline
9
+ end
10
+
7
11
  PAGE_SIZE = 20
8
12
 
9
13
  def index
@@ -2,7 +2,10 @@ module LetterThief
2
2
  class EmailMessage < ApplicationRecord
3
3
  self.table_name = "letter_thief_email_messages"
4
4
 
5
+ connects_to(**LetterThief.connects_to) if LetterThief.connects_to
6
+
5
7
  has_many_attached :attachments
8
+ has_one_attached :raw_email
6
9
 
7
10
  unless ActiveRecord::Base.connection.adapter_name.downcase.include?("postgresql")
8
11
  serialize :to, coder: JSON, type: Array
@@ -1,7 +1,9 @@
1
1
  <% content_for :title, "Letter Thief" %>
2
2
 
3
- <h1>📬 Intercepted Emails</h1>
4
-
3
+ <h1>📬 Intercepted Emails (Outbox)</h1>
4
+ <p>
5
+ Currently occupying <%= number_to_human_size(LetterThief.used_activestorage_space)%>
6
+ </p>
5
7
  <form method="get" style="margin-bottom: 1rem;">
6
8
  <fieldset class="grid">
7
9
  <label>
@@ -44,6 +46,7 @@
44
46
  <th>To</th>
45
47
  <th>Subject</th>
46
48
  <th>Time</th>
49
+ <th>Size</th>
47
50
  </tr>
48
51
  </thead>
49
52
  <tbody>
@@ -57,6 +60,7 @@
57
60
  </a>
58
61
  </td>
59
62
  <td><%= email.intercepted_at.strftime("%Y-%m-%d %H:%M") %></td>
63
+ <td><%= number_to_human_size(email.raw_email.byte_size) %></td>
60
64
  </tr>
61
65
  <% end %>
62
66
  </tbody>
@@ -1,6 +1,6 @@
1
1
  <% content_for :title, "Message ##{@email.id}" %>
2
2
 
3
- <p><a href="<%= email_messages_path %>">&larr; Back to Inbox 📬</a></p>
3
+ <p><a href="<%= email_messages_path %>">&larr; Back to Outbox 📬</a></p>
4
4
 
5
5
  <section id="message_headers">
6
6
  <dl>
@@ -43,6 +43,9 @@
43
43
  </dd>
44
44
  <% end %>
45
45
  </dl>
46
+ <% if @email.raw_email.attached? %>
47
+ <%= link_to "Download", main_app.rails_blob_path(@email.raw_email, disposition: "attachment") %>
48
+ <% end %>
46
49
  </section>
47
50
 
48
51
  <hr>
@@ -21,7 +21,6 @@ class CreateLetterThiefEmailMessages < ActiveRecord::Migration<%= migration_vers
21
21
  t.text :body_text
22
22
  t.text :body_html
23
23
  t.text :headers
24
- t.text :raw_message
25
24
  t.string :content_type
26
25
  t.datetime :intercepted_at
27
26
 
@@ -1,6 +1,7 @@
1
1
  module LetterThief
2
2
  class Interceptor
3
3
  def self.delivering_email(mail)
4
+ string_io = StringIO.new(mail.to_s)
4
5
  email = EmailMessage.create!(
5
6
  to: mail.to,
6
7
  from: mail.from,
@@ -11,7 +12,6 @@ module LetterThief
11
12
  body_text: mail.text_part&.decoded || mail.body.decoded,
12
13
  body_html: mail.html_part&.decoded,
13
14
  headers: mail.header.to_s,
14
- raw_message: mail.to_s,
15
15
  content_type: mail.content_type,
16
16
  intercepted_at: Time.current
17
17
  )
@@ -25,6 +25,12 @@ module LetterThief
25
25
  ar_attachment.blob.metadata["cid"] = attachment.cid
26
26
  ar_attachment.blob.save!
27
27
  end
28
+
29
+ email.raw_email.attach(
30
+ io: string_io,
31
+ filename: "message-#{email.id}.eml",
32
+ content_type: "message/rfc822"
33
+ )
28
34
  rescue => e
29
35
  Rails.logger.error("[LetterThief] Failed to store intercepted email: #{e.message}")
30
36
  end
@@ -1,3 +1,3 @@
1
1
  module LetterThief
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/letter_thief.rb CHANGED
@@ -2,5 +2,13 @@ require "letter_thief/version"
2
2
  require "letter_thief/engine"
3
3
 
4
4
  module LetterThief
5
- # Your code goes here...
5
+ mattr_accessor :connects_to
6
+
7
+ def self.used_activestorage_space
8
+ ActiveStorage::Blob
9
+ .joins(:attachments)
10
+ .where(active_storage_attachments: {
11
+ record_type: "LetterThief::EmailMessage"
12
+ }).sum(:byte_size)
13
+ end
6
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: letter_thief
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Rodi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-04 00:00:00.000000000 Z
11
+ date: 2025-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails