Print common headers when printing messages

This commit is contained in:
Alex Henrie 2018-09-22 09:48:51 -06:00
parent b6312810c5
commit 2b2c587e6c
5 changed files with 64 additions and 3 deletions

View file

@ -805,9 +805,6 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
}
private void print() {
// XXX This isn't anywhere near good enough - headers aren't
// being printed.
Gtk.Window? window = get_toplevel() as Gtk.Window;
WebKit.PrintOperation op = new WebKit.PrintOperation(
this.primary_message.web_view

View file

@ -482,6 +482,13 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
}
load_cancelled.cancelled.connect(() => { web_view.stop_loading(); });
this.web_view.set_print_headers(
this.message.from != null ? this.message.from.to_string() : null,
this.message.to != null ? this.message.to.to_string() : null,
this.message.cc != null ? this.message.cc.to_string() : null,
this.message.bcc != null ? this.message.bcc.to_string() : null,
this.message.date != null ? this.message.date.to_string() : null,
this.message.subject != null ? this.message.subject.to_string() : null);
this.web_view.load_html(body_text ?? "");
}

View file

@ -54,6 +54,18 @@ public class ConversationWebView : ClientWebView {
);
}
public void set_print_headers(string? from, string? to, string? cc, string? bcc, string? date, string? subject) {
StringBuilder js = new StringBuilder("var gearyEmailHeaders = {");
if (from != null) js.append(_("'From:':'") + from.replace("'", "\\'") + "',");
if (to != null) js.append(_("'To:':'") + to.replace("'", "\\'") + "',");
if (cc != null) js.append(_("'CC:':'") + cc.replace("'", "\\'") + "',");
if (bcc != null) js.append(_("'BCC:':'") + bcc.replace("'", "\\'") + "',");
if (date != null) js.append(_("'Date:':'") + date.replace("'", "\\'") + "',");
if (subject != null) js.append(_("'Subject:':'") + subject.replace("'", "\\'") + "',");
js.append("};");
this.run_javascript(js.str, null);
}
/** Emitted when the user clicks on a link with deceptive text. */
public signal void deceptive_link_clicked(

View file

@ -193,8 +193,17 @@ pre {
}
}
#geary-message-headers {
display: none;
}
@media print {
.geary-button {
display: none;
}
#geary-message-headers {
all: initial;
display: block;
}
}

View file

@ -314,3 +314,39 @@ ConversationPageState.isDescendantOf = function(node, ancestorTag) {
};
var geary = new ConversationPageState();
/**
* Add email headers for printing
*/
document.addEventListener('DOMContentLoaded', () => {
let headerBlock = document.createElement('div');
headerBlock.id = 'geary-message-headers';
let shadowRoot = headerBlock.attachShadow({mode: 'closed'});
let shadowStyle = document.createElement('style');
shadowStyle.textContent = "\
table, tr, th, td, hr { all:initial; }\
table { display:table; }\
tr { display:table-row; }\
td, th { display:table-cell; line-height:1.5em; }\
th { font-weight:bold; padding-right:2ex; }\
hr { display:block; border-style:inset; border-width:1px; margin-top:0.5em; margin-bottom:0.5em; }";
shadowRoot.appendChild(shadowStyle);
let headerTable = document.createElement('table');
shadowRoot.appendChild(headerTable);
for (header in gearyEmailHeaders) {
let row = headerTable.appendChild(document.createElement('tr'));
let name = row.appendChild(document.createElement('th'));
let value = row.appendChild(document.createElement('td'));
name.textContent = header;
value.textContent = gearyEmailHeaders[header];
}
shadowRoot.appendChild(document.createElement('hr'));
document.body.insertBefore(headerBlock, document.body.firstChild);
});