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 +4 -4
- data/app/controllers/letter_thief/email_messages_controller.rb +4 -0
- data/app/models/letter_thief/email_message.rb +3 -0
- data/app/views/letter_thief/email_messages/index.html.erb +6 -2
- data/app/views/letter_thief/email_messages/show.html.erb +4 -1
- data/lib/generators/letter_thief/templates/create_email_messages.rb.erb +0 -1
- data/lib/letter_thief/interceptor.rb +7 -1
- data/lib/letter_thief/version.rb +1 -1
- data/lib/letter_thief.rb +9 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 967473d3c9121f2d1d82d1d477284f251b0b19666f2511cdde5a1123b58255c2
|
4
|
+
data.tar.gz: 174d09ccdf13d992281e8533e565646069f494f36fd49b221dd7c1e665b9e1a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6233fbd351a7e103122aa373593bd2acab90a4143dc8fb32c31ef71642255bf2a7a796363ea4fe32daca5d0c4c2adb1677fc6a589f39da36bf90b84420838de2
|
7
|
+
data.tar.gz: ccf721f2572308ad7e592bc9afeb1c5b902fd27d30f55e97aa414068610891ead8fe1d56516a68bbadc70499674187dc482447d41ad9f813adcecfe79a5b847e
|
@@ -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 %>">← Back to
|
3
|
+
<p><a href="<%= email_messages_path %>">← 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>
|
@@ -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
|
data/lib/letter_thief/version.rb
CHANGED
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
|
-
|
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.
|
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-
|
11
|
+
date: 2025-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|