[Xfce4-commits] <postler:master> Implement 'Import Archived Mailbox' context menu on folders
Christian Dywan
noreply at xfce.org
Sun Jul 18 15:40:07 CEST 2010
Updating branch refs/heads/master
to 409d7cd46f49e9ede06b5ee2b1adb658d3335d28 (commit)
from b510eb83c069e94a9ac89b412ffa94f9cb04c277 (commit)
commit 409d7cd46f49e9ede06b5ee2b1adb658d3335d28
Author: Christian Dywan <christian at twotoasts.de>
Date: Sat Jul 10 22:11:29 2010 +0200
Implement 'Import Archived Mailbox' context menu on folders
postler/postler-folders.vala | 52 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/postler/postler-folders.vala b/postler/postler-folders.vala
index 1a46e1c..b4e5134 100644
--- a/postler/postler-folders.vala
+++ b/postler/postler-folders.vala
@@ -225,6 +225,51 @@ public class Postler.Folders : Gtk.TreeView {
messages.clear ();
}
+ void import_folder (Gtk.TreeIter iter) {
+ var dialog = new Gtk.FileChooserDialog (_("Import Archived Mailbox"),
+ get_toplevel () as Gtk.Window, Gtk.FileChooserAction.OPEN);
+ dialog.add_buttons (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
+ Gtk.STOCK_OPEN, Gtk.ResponseType.OK);
+ dialog.set_default_response (Gtk.ResponseType.OK);
+ int response = dialog.run ();
+ var mailbox_archive = dialog.get_file ();
+ dialog.destroy ();
+ if (response != Gtk.ResponseType.OK)
+ return;
+
+ string location;
+ store.get (iter, Columns.LOCATION, out location);
+ try {
+ string path = location + "/cur/";
+ var stream = new DataInputStream (mailbox_archive.read (null));
+ GLib.StringBuilder body = new GLib.StringBuilder ();
+ string line;
+ while ((line = stream.read_line (null, null)) != null) {
+ if (line.has_prefix ("From ")) {
+ if (body.len == 0)
+ continue;
+
+ string filename = path +
+ Postler.Messages.generate_maildir_filename ("S");
+ FileUtils.set_contents (filename, body.str, -1);
+ FileUtils.chmod (filename, 0700);
+ body = new GLib.StringBuilder ();
+ }
+ body.append (line + "\n");
+ }
+ if (body.len != 0) {
+ string filename = path +
+ Postler.Messages.generate_maildir_filename ("S");
+ FileUtils.set_contents (filename, body.str, -1);
+ FileUtils.chmod (filename, 0700);
+ }
+ messages.populate (location);
+ } catch (GLib.Error error) {
+ GLib.critical (_("Failed to empty folder \"%s\": %s"),
+ location, error.message);
+ }
+ }
+
void empty_folder (Gtk.TreeIter iter) {
string location;
store.get (iter, Columns.LOCATION, out location);
@@ -289,6 +334,13 @@ public class Postler.Folders : Gtk.TreeView {
}
});
menu.append (menuitem);
+ menuitem = new Gtk.MenuItem.with_mnemonic (_("_Import Archived Mailbox"));
+ menuitem.activate.connect ((menuitem) => {
+ Gtk.TreeIter iter;
+ if (get_selection ().get_selected (null, out iter))
+ import_folder (iter);
+ });
+ menu.append (menuitem);
menuitem = new Gtk.MenuItem.with_mnemonic (_("_Empty Folder"));
menuitem.activate.connect ((menuitem) => {
Gtk.TreeIter iter;
More information about the Xfce4-commits
mailing list