summaryrefslogtreecommitdiff
blob: f7e1c89054a3d39c2d800800128f5919232351ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<h1 class="first-header">Gentoo Archives: <%= list %></h1>

<div class="table-responsive">
  <table class="table table-sm ag-header-table">
    <tr>
      <th class="ag-header-name-col">From:</th>
      <td><%= h strip_email_headers(message['_source']['from']).first %></td>
    </tr>
    <tr>
      <th>To:</th>
      <td><%= h strip_email_headers(message['_source']['to']).join ', ' %></td>
    </tr>
    <% unless message['_source']['cc'] == nil or message['_source']['cc'] == [] %>
    <tr>
      <th>Cc:</th>
      <td><%= h strip_email_headers(message['_source']['cc']).join ', ' %></td>
    </tr>
    <% end %>
    <tr>
      <th>Subject:</th>
      <td><strong><%= h message['_source']['subject'] %></strong></td>
    </tr>
    <tr>
      <th>Date:</th>
      <td><%= date_format message['_source']['date'] %></td>
    </tr>
    <tr>
      <th>Message-Id:</th>
      <td><tt><%= h message['_source']['raw_message_id'] %></tt></td>
    </tr>
    <% unless parent == nil %>
    <tr>
      <th>In Reply to:</th>
      <td colspan="3"><a href="<%= parent['_id'] %>"><%= parent['_source']['subject'] %></a> by <%= parent['_source']['from'] %></td>
    </tr>
    <% end %>
  </table>
</div>

<div style="border: 1px solid #ccc;font-size:12px;padding:10px;background-color: #f5f5f5;" class="mb-3 w-100">
  <table class="w-100">
    <% inquote = false %>
    <% linkize(strip_email(message['_source']['content'])).split("\n").each_with_index do |line, index| %>
      <tr id="L<%= index + 1 %>" class="ag-line">
        <td class="pr-3 text-right" style="line-height: 1.2;user-select: none;"><a style="font-family: monospace;font-size: 12px;" class="ag-line-number" href="#L<%= index + 1 %>"><%= index + 1 %></a></td>
        <% if line.start_with?('<div class="ag-quote">') %>
          <% inquote = true %>
          <td style="line-height: 1.2;font-family: monospace;font-size: 12px;color:#999"><%= line.sub('<div class="ag-quote">','') %></td>
        <% elsif line.end_with?('</div>') %>
          <% inquote = false %>
          <td style="line-height: 1.2;font-family: monospace;font-size: 12px;color:#999"><%= line.sub('</div>','') %></td>
        <% else %>
          <% if inquote %>
            <td style="line-height: 1.2;font-family: monospace;font-size: 12px;color:#999;"><%= line %></td>
          <% else %>
            <td style="line-height: 1.2;font-family: monospace;font-size: 12px;"><%= line %></td>
          <% end %>
        <% end %>
      </tr>
    <% end %>
  </table>
</div>


<% if message['_source']['attachments'] and not message['_source']['attachments'].empty? %>
<h3>Attachments</h3>

<div class="table-responsive">
  <table class="table table-sm ag-attachment-table">
    <tr>
      <th>File name</th>
      <th>MIME type</th>
    </tr>
    <% message['_source']['attachments'].each do |attachment| %>
      <tr>
        <td><%= h attachment['filename'] %></td>
        <td><%= h attachment['mime'] %></td>
      </tr>
    <% end %>
  </table>
</div>
<% end %>

<% unless children == nil %>
<h3>Replies</h3>

<div class="table-responsive">
  <table class="table table-sm ag-replies-table">
    <tr>
      <th>Subject</th>
      <th>Author</th>
    </tr>
    <% children.each do |child| %>
      <tr>
        <td><a href="<%= child['_id'] %>"><%= h child['_source']['subject'] %></a></td>
        <td><%= h strip_email_headers(child['_source']['from']).first %></td>
      </tr>
    <% end %>
  </table>
</div>
<% end %>

<div class="ag-message-actions">
  <a href="/<%= h list %>/report/<%= message['_id'] %>" class="btn btn-danger btn-sm"><span class="fa fa-fw fa-ban"></span> Report Message</a>
  <div class="btn-group btn-group-sm ml-3">
    <a href="<%= msgid_to_marc(message['_source']['raw_message_id']) %>" class="btn btn-outline-secondary"><span class="fa fa-fw fa-share-square"></span>Find on MARC</a>
    <a href="<%= msgid_to_googlegroup(message['_source']['raw_message_id']) %>" class="btn btn-outline-secondary"><span class="fa fa-fw fa-share-square"></span>Find on Google Groups</a>
  </div>
</div>

<script>
    // highlight based on parameter "h"
    var url = new URL(window.location.href);
    var highlights = url.searchParams.get("h");

    highlights.split(",").forEach(function(highlight){
        if(highlight.split("-").length == 2){
            var leftPart = highlight.split("-")[0];
            var rightPart = highlight.split("-")[1];
            if(isNumeric(leftPart) && isNumeric(rightPart) && parseFloat(leftPart) <= parseFloat(rightPart)){
                for(var i = parseFloat(leftPart); i <= parseFloat(rightPart); i++){
                    highlightLine(i);
                }
            }
        }else{
            highlightLine(highlight);
        }
    })

    // utility functions

    function highlightLine(lineNumber) {
        if(isNumeric(lineNumber)){
            document.querySelectorAll(".ag-line")[parseFloat(lineNumber) - 1].style.backgroundColor = '#FFF3CD';
        }
    }

    function isNumeric(possibleNumber) {
        return !isNaN(parseFloat(possibleNumber)) && isFinite(possibleNumber)
    }
</script>