Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show email size in table and mail detail #353

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions assets/javascripts/mailcatcher.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ class MailCatcher
date &&= @offsetTimeZone(date)
date &&= date.toString("dddd, d MMM yyyy h:mm:ss tt")

formatSize: (bytes) ->
thresh = 1000
units = ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']

if Math.abs(bytes) < thresh
return bytes + ' B'
u = -1
loop
bytes /= thresh
++u
unless Math.abs(bytes) >= thresh and u < units.length - 1
break
bytes.toFixed(1) + ' ' + units[u]

messagesCount: ->
$("#messages tr").length - 1

Expand Down Expand Up @@ -193,6 +207,7 @@ class MailCatcher
.append($("<td/>").text((message.recipients || []).join(", ") or "No receipients").toggleClass("blank", !message.recipients.length))
.append($("<td/>").text(message.subject or "No subject").toggleClass("blank", !message.subject))
.append($("<td/>").text(@formatDate(message.created_at)))
.append($("<td/>").text(@formatSize(message.size)))
.prependTo($("#messages tbody"))
@updateMessagesCount()

Expand Down Expand Up @@ -226,6 +241,11 @@ class MailCatcher
$("#message .metadata dd.from").text(message.sender)
$("#message .metadata dd.to").text((message.recipients || []).join(", "))
$("#message .metadata dd.subject").text(message.subject)
$("#message .metadata dd.size").html(
$('<span />')
.attr('title', message.size+' bytes')
.text(@formatSize(message.size))
)
$("#message .views .tab.format").each (i, el) ->
$el = $(el)
format = $el.attr("data-message-format")
Expand Down
3 changes: 3 additions & 0 deletions views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<th>To</th>
<th>Subject</th>
<th>Received</th>
<th>Size</th>
</tr>
</thead>
<tbody></tbody>
Expand All @@ -45,6 +46,8 @@
<dd class="to"></dd>
<dt class="subject">Subject</dt>
<dd class="subject"></dd>
<dt class="size">Size</dt>
<dd class="size"></dd>
<dt class="attachments">Attachments</dt>
<dd class="attachments"></dd>
</dl>
Expand Down