]> git.rmz.io Git - dotfiles.git/blob - mutt/dmarc.xsl
b942425ce01a16441d6e3b42ebe6e37521b68de9
[dotfiles.git] / mutt / dmarc.xsl
1 <xsl:stylesheet version="1.0"
2 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:date="http://exslt.org/dates-and-times"
4 xmlns="http://www.w3.org/1999/xhtml">
5 <xsl:output
6 omit-xml-declaration = "yes"
7 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
8 doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />
9 <xsl:param name="source_ip_href">
10 <!-- customize this -->
11 <!-- <xsl:text>http://www.tana.it/lookup.php?host=</xsl:text> -->
12 <!-- <xsl:text>http://network-tools.com/default.asp?prog=lookup&#38;amp;host=</xsl:text> -->
13 <!-- <xsl:text>https://dnschecker.org/ip-whois-lookup.php?query=</xsl:text> -->
14 <xsl:text>https://ipalyzer.com/</xsl:text>
15 <!-- alternative examples:
16 <xsl:text>http://www.ip-adress.com/reverse_ip/</xsl:text>
17 -->
18 </xsl:param>
19 <xsl:template match="feedback">
20 <html xmlns="http://www.w3.org/1999/xhtml">
21 <xsl:variable name="title">
22 Feedback from
23 <xsl:value-of select="report_metadata/org_name"/>
24 </xsl:variable>
25 <head>
26 <title>
27 <xsl:value-of select="$title"/>
28 </title>
29 <style type="text/css" id="internal-style">
30 body {
31 font-family: Arial, Helvetica, sans-serif;
32 color: #003300;
33 background-color: #ffcc66;
34 }
35 table, p {
36 margin: 1em;
37 padding: 4pt;
38 background-color: #ffeeaa;
39 border: 3pt solid #776633;
40 }
41 td, th {
42 margin: 2pt;
43 padding: 2pt;
44 border: 1pt solid #776633;
45 }
46 .pass {
47 background-color: #11bb00;
48 }
49 .fail {
50 background-color: #cc0000;
51 }
52 .dkimpolicy {
53 background-color: #ffff66;
54 }
55 .error {
56 background-color: #bbaaaa;
57 font-weight: bold;
58 }
59 .softfail {
60 background-color: #ff8866;
61 }
62 .reject {
63 background-color: #cc0000;
64 }
65 .quarantine {
66 background-color: #ff8866;
67 }
68 .normal {
69 }
70 .field {
71 font-weight: bold;
72 }
73 </style>
74 </head>
75 <body>
76 <h1>
77 <xsl:value-of select="$title"/>
78 </h1>
79 <p>
80 <xsl:apply-templates select="report_metadata"/>
81 <br/>
82 <xsl:apply-templates select="policy_published"/>
83 </p>
84 <table>
85 <tr>
86 <th>
87 Relaying IP
88 </th>
89 <th>
90 message count
91 </th>
92 <th>
93 reason and disposition
94 </th>
95 <th>
96 From header
97 <br/>
98 (opt. envelope)
99 </th>
100 <th>
101 SPF
102 </th>
103 <xsl:variable name="signatures">
104 <xsl:for-each select="record/auth_results">
105 <xsl:sort select="count(dkim)"
106 data-type="number" order="descending"/>
107 <xsl:if test="position()=1">
108 <xsl:value-of select="count(dkim)"/>
109 </xsl:if>
110 </xsl:for-each>
111 </xsl:variable>
112 <xsl:if test="$signatures > 0">
113 <th>
114 DKIM
115 </th>
116 <xsl:if test="$signatures > 1">
117 <th>
118 2nd DKIM
119 </th>
120 <xsl:if test="$signatures > 2">
121 <th>
122 3rd DKIM
123 </th>
124 </xsl:if>
125 </xsl:if>
126 </xsl:if>
127 </tr>
128 <xsl:text>
129 </xsl:text>
130 <xsl:apply-templates select="record"/>
131 </table>
132 <p>
133 <b><u>Legend</u><br/>
134 disposition: </b>
135 <span class="quarantine">quarantine</span>,
136 <span class="reject">reject</span>.<br/>
137 <b>spf: </b>
138 <span class="pass">pass</span>,
139 <span class="fail">fail</span>,
140 <span class="softfail">softfail</span>,
141 <span class="error">temperror or permerror</span>.<br/>
142 <b>dkim: </b>
143 <span class="pass">pass</span>,
144 <span class="fail">fail</span>,
145 <span class="dkimpolicy">policy</span>.
146 </p>
147 </body>
148 </html>
149 </xsl:template>
150 <xsl:template match="policy_published">
151 <span class="field">Domain: </span>
152 <xsl:value-of select="domain"/>
153 <xsl:text>; </xsl:text>
154 <span class="field">DKIM: </span>
155 <xsl:apply-templates select="adkim"/>
156 <xsl:text>; </xsl:text>
157 <span class="field">SPF: </span>
158 <xsl:apply-templates select="aspf"/>
159 <xsl:text>; </xsl:text>
160 <span class="field">policy published: </span>
161 <xsl:value-of select="p"/>
162 <xsl:text> </xsl:text>
163 <xsl:value-of select="sp"/>
164 <xsl:text> </xsl:text>
165 <xsl:value-of select="pct"/>
166 </xsl:template>
167 <xsl:template match="adkim|aspf">
168 <xsl:variable name="alignment">
169 <xsl:value-of select="."/>
170 </xsl:variable>
171 <xsl:choose>
172 <xsl:when test="$alignment='r'">
173 <xsl:text>relaxed</xsl:text>
174 </xsl:when>
175 <xsl:when test="$alignment='s'">
176 <xsl:text>strict</xsl:text>
177 </xsl:when>
178 <xsl:otherwise>
179 <xsl:text>{$alignment}</xsl:text>
180 </xsl:otherwise>
181 </xsl:choose>
182 </xsl:template>
183 <xsl:template match="report_metadata">
184 <span class="field">Id: </span>
185 <xsl:value-of select="report_id"/>
186 <xsl:text>; </xsl:text>
187 <span class="field">begin: </span>
188 <xsl:call-template name="date-range">
189 <xsl:with-param name="utime" select="date_range/begin"/>
190 </xsl:call-template>
191 <xsl:text>; </xsl:text>
192 <span class="field">end: </span>
193 <xsl:call-template name="date-range">
194 <xsl:with-param name="utime" select="date_range/end"/>
195 </xsl:call-template>
196 <xsl:for-each select="error">
197 <xsl:if test="position()=1">
198 <br/>
199 <span class="field">Error: </span>
200 </xsl:if>
201 <span class="error">
202 <xsl:value-of select="."/>
203 </span>
204 <xsl:if test="not(position()=last())">
205 <br/>
206 </xsl:if>
207 </xsl:for-each>
208 </xsl:template>
209 <xsl:template name="date-range">
210 <xsl:param name="utime" select="0"/>
211 <xsl:choose>
212 <xsl:when test="function-available('date:add')">
213 <xsl:value-of
214 select="date:add('1970-01-01T00:00:00', date:duration($utime))"/>
215 </xsl:when>
216 <xsl:otherwise>
217 <xsl:value-of select="$utime"/>
218 </xsl:otherwise>
219 </xsl:choose>
220 </xsl:template>
221 <xsl:template match="record">
222 <tr>
223 <xsl:apply-templates select="row"/>
224 <xsl:apply-templates select="identifiers|identities"/>
225 <xsl:apply-templates select="auth_results"/>
226 </tr>
227 <xsl:text>
228 </xsl:text>
229 </xsl:template>
230 <xsl:template match="row">
231 <td>
232 <a>
233 <xsl:attribute name="href">
234 <xsl:value-of select="$source_ip_href"/>
235 <xsl:value-of select="source_ip"/>
236 </xsl:attribute>
237 <xsl:value-of select="source_ip"/>
238 </a>
239 </td>
240 <td align="right">
241 <xsl:value-of select="count"/>
242 </td>
243 <td>
244 <xsl:attribute name="class">
245 <xsl:variable name="disposition">
246 <xsl:value-of select="policy_evaluated/disposition"/>
247 </xsl:variable>
248 <xsl:choose>
249 <xsl:when test="$disposition='reject'">
250 <xsl:text>reject</xsl:text>
251 </xsl:when>
252 <xsl:when test="$disposition='quarantine'">
253 <xsl:text>quarantine</xsl:text>
254 </xsl:when>
255 <xsl:otherwise>
256 <xsl:text>normal</xsl:text>
257 </xsl:otherwise>
258 </xsl:choose>
259 </xsl:attribute>
260 <xsl:for-each select="policy_evaluated/reason">
261 <xsl:value-of select="type"/>
262 <xsl:text> </xsl:text>
263 <xsl:value-of select="comment"/>
264 <br/>
265 </xsl:for-each>
266 </td>
267 </xsl:template>
268 <xsl:template match="identifiers|identities">
269 <td>
270 <xsl:value-of select="header_from"/>
271 <xsl:if test="count(envelope_to) &gt; 0">
272 <br/>
273 <xsl:value-of select="envelope_to"/>
274 </xsl:if>
275 </td>
276 </xsl:template>
277 <xsl:template match="auth_results">
278 <xsl:apply-templates select="spf"/><!-- one -->
279 <xsl:apply-templates select="dkim"/><!-- zero or more -->
280 </xsl:template>
281 <xsl:template name="class_attribute">
282 <xsl:attribute name="class">
283 <xsl:variable name="result">
284 <xsl:value-of select="result"/>
285 </xsl:variable>
286 <xsl:choose>
287 <xsl:when test="$result='pass'">
288 <xsl:text>pass</xsl:text>
289 </xsl:when>
290 <xsl:when test="$result='fail' or $result='hardfail'">
291 <xsl:text>fail</xsl:text>
292 </xsl:when>
293 <xsl:when test="$result='temperror' or $result='permerror'">
294 <xsl:text>error</xsl:text>
295 </xsl:when>
296 <xsl:when test="$result='policy'">
297 <xsl:text>dkimpolicy</xsl:text>
298 </xsl:when>
299 <xsl:when test="$result='softfail'">
300 <xsl:text>softfail</xsl:text>
301 </xsl:when>
302 <xsl:otherwise>
303 <xsl:text>normal</xsl:text>
304 </xsl:otherwise>
305 </xsl:choose>
306 </xsl:attribute>
307 </xsl:template>
308 <xsl:template match="spf">
309 <td>
310 <xsl:call-template name="class_attribute" />
311 <xsl:value-of select="result"/>
312 <br/>
313 <xsl:value-of select="domain"/>
314 <br/>
315 <xsl:value-of select="scope"/>
316 <br/>
317 <xsl:value-of select="human_result"/>
318 </td>
319 </xsl:template>
320 <xsl:template match="dkim">
321 <td>
322 <xsl:call-template name="class_attribute" />
323 <xsl:value-of select="result"/>
324 <br/>
325 <xsl:value-of select="domain"/>
326 <br/>
327 <xsl:value-of select="selector"/>
328 <br/>
329 <xsl:value-of select="human_result"/>
330 </td>
331 </xsl:template>
332 </xsl:stylesheet>
333