Display To:, From:, and Subject: in message viewer: #3812
Fields added. However, it would be nice to use formatting to separate them from the body of the message. This is not easy with Gtk.TextView/Gtk.TextBuffer; see https://bugzilla.gnome.org/show_bug.cgi?id=59390. This may push us to move to Webkit earlier rather than later.
This commit is contained in:
parent
d1fa42fc13
commit
9792780edb
4 changed files with 58 additions and 13 deletions
|
|
@ -237,13 +237,10 @@ public class MainWindow : Gtk.Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void on_message_selected(Geary.Email? email) {
|
private void on_message_selected(Geary.Email? email) {
|
||||||
if (email == null) {
|
message_buffer.clear();
|
||||||
message_buffer.set_text("");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
do_select_message.begin(email, on_select_message_completed);
|
if (email != null)
|
||||||
|
do_select_message.begin(email, on_select_message_completed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void do_select_message(Geary.Email email) throws Error {
|
private async void do_select_message(Geary.Email email) throws Error {
|
||||||
|
|
@ -253,13 +250,10 @@ public class MainWindow : Gtk.Window {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Geary.Email full = yield current_folder.fetch_email_async(email.location.position,
|
Geary.Email for_buffer = yield current_folder.fetch_email_async(email.location.position,
|
||||||
Geary.Email.Field.HEADER | Geary.Email.Field.BODY);
|
MessageBuffer.REQUIRED_FIELDS);
|
||||||
|
|
||||||
Geary.Memory.AbstractBuffer buffer = full.get_message().get_first_mime_part_of_content_type(
|
message_buffer.display_email(for_buffer);
|
||||||
"text/plain");
|
|
||||||
|
|
||||||
message_buffer.set_text(buffer.to_utf8());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void on_select_message_completed(Object? source, AsyncResult result) {
|
private void on_select_message_completed(Object? source, AsyncResult result) {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,54 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class MessageBuffer : Gtk.TextBuffer {
|
public class MessageBuffer : Gtk.TextBuffer {
|
||||||
|
public const Geary.Email.Field REQUIRED_FIELDS =
|
||||||
|
Geary.Email.Field.HEADER
|
||||||
|
| Geary.Email.Field.BODY
|
||||||
|
| Geary.Email.Field.ORIGINATORS
|
||||||
|
| Geary.Email.Field.RECEIVERS
|
||||||
|
| Geary.Email.Field.SUBJECT;
|
||||||
|
|
||||||
public MessageBuffer() {
|
public MessageBuffer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
set_text("");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Would very much like to use Pango markup to format the text, however, it's not supported
|
||||||
|
// in Gtk.TextBuffer/Gtk.TextView by default, meaning the implementor has to devise their own
|
||||||
|
// markup language, parse the buffer, and so on. See:
|
||||||
|
// https://bugzilla.gnome.org/show_bug.cgi?id=59390
|
||||||
|
public void display_email(Geary.Email email) throws Error {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
// From:
|
||||||
|
if (email.from != null && email.from.size > 0)
|
||||||
|
builder.append_printf(_("From: %s\n"), email.from.to_string());
|
||||||
|
else if (email.sender != null && email.sender.size > 0)
|
||||||
|
builder.append_printf(_("Sender: %s\n"), email.sender.to_string());
|
||||||
|
|
||||||
|
// To:
|
||||||
|
if (email.to != null && email.to.size > 0)
|
||||||
|
builder.append_printf(_("To: %s\n"), email.to.to_string());
|
||||||
|
|
||||||
|
if (email.cc != null && email.cc.size > 0)
|
||||||
|
builder.append_printf(_("Cc: %s\n"), email.cc.to_string());
|
||||||
|
|
||||||
|
if (email.bcc != null && email.bcc.size > 0)
|
||||||
|
builder.append_printf(_("Bcc: %s"), email.bcc.to_string());
|
||||||
|
|
||||||
|
// Subject:
|
||||||
|
if (email.subject != null)
|
||||||
|
builder.append_printf(_("Subject: %s\n"), email.subject.value);
|
||||||
|
|
||||||
|
// Message body
|
||||||
|
Geary.Memory.AbstractBuffer buffer = email.get_message().get_first_mime_part_of_content_type(
|
||||||
|
"text/plain");
|
||||||
|
builder.append("\n");
|
||||||
|
builder.append(buffer.to_utf8());
|
||||||
|
|
||||||
|
set_text(builder.str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,10 @@ public class Geary.Email : Object {
|
||||||
fields |= Field.PROPERTIES;
|
fields |= Field.PROPERTIES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method requires Geary.Email.Field.HEADER and Geary.Email.Field.BODY be present.
|
||||||
|
* If not, EngineError.INCOMPLETE_MESSAGE is thrown.
|
||||||
|
*/
|
||||||
public Geary.RFC822.Message get_message() throws EngineError, RFC822.Error {
|
public Geary.RFC822.Message get_message() throws EngineError, RFC822.Error {
|
||||||
if (message != null)
|
if (message != null)
|
||||||
return message;
|
return message;
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,7 @@ public class Geary.Sqlite.Folder : Geary.AbstractFolder, Geary.LocalFolder {
|
||||||
to_string());
|
to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!message_row.fields.is_set(required_fields)) {
|
if (!message_row.fields.fulfills(required_fields)) {
|
||||||
throw new EngineError.INCOMPLETE_MESSAGE(
|
throw new EngineError.INCOMPLETE_MESSAGE(
|
||||||
"Message at position %d in folder %s only fulfills %Xh fields", position, to_string(),
|
"Message at position %d in folder %s only fulfills %Xh fields", position, to_string(),
|
||||||
message_row.fields);
|
message_row.fields);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue