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

Allow donating a message to elementary #963

Open
wants to merge 5 commits into
base: master
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
41 changes: 12 additions & 29 deletions src/Composer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -551,36 +551,19 @@ public class Mail.Composer : Hdy.ApplicationWindow {
}

if (from_combo.model.iter_n_children (null) > 1) {
unowned Mail.Backend.Session session = Mail.Backend.Session.get_default ();
unowned var account_source_uid = message.get_source ();
var account_source = session.ref_source (account_source_uid);

if (account_source != null && account_source.has_extension (E.SOURCE_EXTENSION_MAIL_ACCOUNT)) {
unowned var account_extension = (E.SourceMailAccount) account_source.get_extension (E.SOURCE_EXTENSION_MAIL_ACCOUNT);

var identity_uid = account_extension.identity_uid;
if (identity_uid != null && identity_uid != "") {
var identity_source = session.ref_source (identity_uid);

if (identity_source != null && identity_source.has_extension (E.SOURCE_EXTENSION_MAIL_IDENTITY)) {
unowned var identity_extension = (E.SourceMailIdentity) identity_source.get_extension (E.SOURCE_EXTENSION_MAIL_IDENTITY);

var identity_address = identity_extension.get_address ();
if (identity_address != "") {
from_combo.model.foreach ((model, path, iter) => {
GLib.Value value;
model.get_value (iter, 0, out value);

if (value.get_string () == identity_address) {
from_combo.set_active_iter (iter);
return true;
}

return false;
});
}
var identity_address = Utils.get_identity_address_from_message (message);
if (identity_address != null) {
from_combo.model.foreach ((model, path, iter) => {
GLib.Value value;
model.get_value (iter, 0, out value);

if (value.get_string () == identity_address) {
from_combo.set_active_iter (iter);
return true;
}
}

return false;
});
}
}

Expand Down
19 changes: 14 additions & 5 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Mail.MainWindow : Hdy.ApplicationWindow {

private FoldersListView folders_list_view;
private Granite.Widgets.Toast move_toast;
private Granite.Widgets.Toast error_toast;
private Granite.Widgets.Toast info_toast;
private ConversationList conversation_list;
private MessageList message_list;

Expand Down Expand Up @@ -128,9 +128,9 @@ public class Mail.MainWindow : Hdy.ApplicationWindow {
MoveOperation.undo_last_move ();
});

error_toast = new Granite.Widgets.Toast ("");
error_toast.show_all ();
view_overlay.add_overlay (error_toast);
info_toast = new Granite.Widgets.Toast ("");
info_toast.show_all ();
view_overlay.add_overlay (info_toast);

var message_overlay = new Granite.Widgets.OverlayBar (view_overlay);
message_overlay.no_show_all = true;
Expand Down Expand Up @@ -344,7 +344,7 @@ public class Mail.MainWindow : Hdy.ApplicationWindow {
return (SimpleAction) lookup_action (name);
}

public static void send_error_message (string title, string description, string? icon_name = null) {
public static void send_error_message (string title, string description, string? icon_name = null, string? error_details = null) {
var dialog = new Granite.MessageDialog (
title,
description,
Expand All @@ -359,10 +359,19 @@ public class Mail.MainWindow : Hdy.ApplicationWindow {
dialog.badge_icon = new ThemedIcon ("dialog-error");
}

if (error_details != null) {
dialog.show_error_details (error_details);
}

dialog.present ();
dialog.response.connect (dialog.destroy);
}

public void send_info_toast (string title) {
info_toast.title = title;
info_toast.send_notification ();
}

public override bool configure_event (Gdk.EventConfigure event) {
if (configure_id != 0) {
GLib.Source.remove (configure_id);
Expand Down
88 changes: 88 additions & 0 deletions src/MessageList/MessageListItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,28 @@ public class Mail.MessageListItem : Gtk.ListBoxRow {
loaded = true;
});

var donate_label = new Gtk.Label (_("The message isn't displayed correctly?") + " ");

var donate_link = new Gtk.LinkButton.with_label (
_("Send the message to elementary to allow improving the quality of Mail."),
_("Donate it to elementary for debugging purposes.")
);

var donate_box = new Gtk.Box (HORIZONTAL, 0) {
margin_start = 12,
margin_end = 12,
margin_bottom = 12,
margin_top = 12
};
donate_box.add (donate_label);
donate_box.add (donate_link);

var secondary_box = new Gtk.Box (VERTICAL, 0);
secondary_box.add (separator);
secondary_box.add (calendar_info_bar);
secondary_box.add (blocked_images_infobar);
secondary_box.add (web_view);
secondary_box.add (donate_box);

secondary_revealer = new Gtk.Revealer () {
transition_type = SLIDE_UP
Expand Down Expand Up @@ -360,6 +377,8 @@ public class Mail.MessageListItem : Gtk.ListBoxRow {
});
}

donate_link.activate_link.connect (ask_donate_message);

/* Override default handler to stop event propagation. Otherwise clicking the menu will
expand or collapse the MessageListItem. */
actions_menu_button.button_release_event.connect ((event) => {
Expand Down Expand Up @@ -456,6 +475,75 @@ public class Mail.MessageListItem : Gtk.ListBoxRow {
}
}

private bool ask_donate_message () {
var dialog = new Granite.MessageDialog (
_("Donate message to elementary?"),
_("elementary staff will be able to read the contents of the message as well as your e-mail address."),
new ThemedIcon ("dialog-question"),
NONE
);
dialog.add_button (_("Cancel"), Gtk.ResponseType.CANCEL);
var button = dialog.add_button (_("Donate"), Gtk.ResponseType.ACCEPT);
button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);

dialog.response.connect ((res) => {
if (res == Gtk.ResponseType.ACCEPT) {
donate_message.begin ();
}

dialog.destroy ();
});

dialog.present ();

return true; // Only to stop other handlers from being invoked for the LinkButton
}

private async void donate_message () {
var folder = message_info.summary.folder;
Camel.MimeMessage? donation_message = null;
try {
donation_message = yield folder.get_message (message_info.uid, GLib.Priority.DEFAULT, null);
} catch (Error e) {
MainWindow.send_error_message (
_("Failed to donate message"),
_("Could not get mime message."),
null,
e.message
);
return;
}

var from_address = Utils.get_identity_address_from_message (donation_message);
if (from_address == null) {
MainWindow.send_error_message (
_("Failed to donate message"),
_("No sender address found.")
);
return;
}

var from = new Camel.InternetAddress ();
from.unformat (from_address);
donation_message.set_from (from);

var to = new Camel.InternetAddress ();
to.unformat ("leolost@gmx.net");
donation_message.set_recipients (Camel.RECIPIENT_TYPE_TO, to);

try {
yield Backend.Session.get_default ().send_email (donation_message, from, to);
((MainWindow) get_toplevel ()).send_info_toast (_("Message donated."));
} catch (Error e) {
MainWindow.send_error_message (
_("Failed to donate message"),
_("Could not send message."),
null,
e.message
);
}
}

private void on_mouse_target_changed (WebKit.WebView web_view, WebKit.HitTestResult hit_test, uint mods) {
var message_list = (MessageList) get_ancestor (typeof (MessageList));
if (hit_test.context_is_link ()) {
Expand Down
24 changes: 24 additions & 0 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,28 @@ public class Mail.Utils {

return "folder://%s/%s".printf (encoded_service_uid, encoded_normed_folder_name);
}

public static string? get_identity_address_from_message (Camel.MimeMessage message) {
unowned Mail.Backend.Session session = Mail.Backend.Session.get_default ();
unowned var account_source_uid = message.get_source ();
var account_source = session.ref_source (account_source_uid);

if (account_source != null && account_source.has_extension (E.SOURCE_EXTENSION_MAIL_ACCOUNT)) {
unowned var account_extension = (E.SourceMailAccount) account_source.get_extension (E.SOURCE_EXTENSION_MAIL_ACCOUNT);

var identity_uid = account_extension.identity_uid;
if (identity_uid != null && identity_uid != "") {
var identity_source = session.ref_source (identity_uid);

if (identity_source != null && identity_source.has_extension (E.SOURCE_EXTENSION_MAIL_IDENTITY)) {
unowned var identity_extension = (E.SourceMailIdentity) identity_source.get_extension (E.SOURCE_EXTENSION_MAIL_IDENTITY);

var address = identity_extension.get_address ();
return address != "" ? address : null;
}
}
}

return null;
}
}