[Xfce4-commits] <postler:master> Recognize key files as search folder descriptions
Christian Dywan
noreply at xfce.org
Thu Jun 3 23:26:03 CEST 2010
Updating branch refs/heads/master
to b773e4b372dabfd3000494362ff3164bf34fd79e (commit)
from 371ddde676b07313106b0396aa459a0c0734aacd (commit)
commit b773e4b372dabfd3000494362ff3164bf34fd79e
Author: Christian Dywan <christian at twotoasts.de>
Date: Thu Jun 3 17:40:59 2010 +0200
Recognize key files as search folder descriptions
postler/postler-app.vala | 2 ++
postler/postler-folders.vala | 16 +++++++++++++---
postler/postler-messages.vala | 34 ++++++++++++++++++++++++++++++----
3 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/postler/postler-app.vala b/postler/postler-app.vala
index 081de1b..2373c1d 100644
--- a/postler/postler-app.vala
+++ b/postler/postler-app.vala
@@ -18,6 +18,7 @@ namespace Postler {
const string STOCK_FACE_GRIN = "face-grin";
const string STOCK_FACE_SAD = "face-sad";
const string STOCK_FACE_WINK = "face-wink";
+ const string STOCK_FOLDER_SAVED_SEARCH = "folder-saved-search";
const string STOCK_INTERNET_MAIL = "internet-mail";
const string STOCK_MAIL_ATTACHMENT = "mail-attachment";
const string STOCK_MAIL_FORWARD = "mail-forward";
@@ -51,6 +52,7 @@ public class Postler.App : Unique.App {
{ STOCK_FACE_GRIN },
{ STOCK_FACE_SAD },
{ STOCK_FACE_WINK },
+ { STOCK_FOLDER_SAVED_SEARCH },
{ STOCK_MAIL_ATTACHMENT, null, 0, 0, "stock_attach" },
{ STOCK_MAIL_FORWARD, N_("_Forward") },
{ STOCK_MAIL_MESSAGE_NEW, N_("New _Message") },
diff --git a/postler/postler-folders.vala b/postler/postler-folders.vala
index ba75d31..4d1959b 100644
--- a/postler/postler-folders.vala
+++ b/postler/postler-folders.vala
@@ -67,22 +67,32 @@ public class Postler.Folders : Gtk.TreeView {
/* FIXME: Scan for toplevel, then sublevel */
var account_dir = File.new_for_path (toplevel);
var account_enumerator = account_dir.enumerate_children (
- FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
+ FILE_ATTRIBUTE_STANDARD_NAME + "," +
+ FILE_ATTRIBUTE_STANDARD_TYPE, 0, null);
GLib.FileInfo info;
while ((info = account_enumerator.next_file (null)) != null) {
+ string account_name = info.get_name ();
+ string location = toplevel + "/" + account_name;
+
+ if (info.get_file_type () == FileType.REGULAR) {
+ store.insert_with_values (null, null, -1,
+ Columns.ICON, STOCK_FOLDER_SAVED_SEARCH,
+ Columns.NAME, info.get_name (),
+ Columns.LOCATION, location, -1);
+ continue;
+ }
+
Gtk.TreeIter account_iter;
store.insert_with_values (out account_iter, null, -1,
Columns.ICON, Gtk.STOCK_DIRECTORY,
Columns.NAME, info.get_name (),
Columns.LOCATION, null, -1);
- string account_name = info.get_name ();
var folder_dir = account_dir.resolve_relative_path (account_name);
var folder_enumerator = folder_dir.enumerate_children (
FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
while ((info = folder_enumerator.next_file (null)) != null) {
Gtk.TreeIter folder_iter;
string name = info.get_name ();
- string location = toplevel + "/" + account_name;
if (name == "INBOX") {
var msg_dir = folder_dir.resolve_relative_path (
location + "/" + name + "/new");
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index abd038e..622a4ff 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -219,9 +219,29 @@ public class Postler.Messages : Gtk.TreeView {
var now = GLib.Date ();
now.set_time_val (GLib.TimeVal ());
try {
- string[] folders = { "cur", "new" };
+ string filter_header = "subject";
+ string real_filter = "";
+ string[] folders = {};
+
+ try {
+ var keyfile = new KeyFile ();
+ keyfile.load_from_file (location, 0);
+ filter_header = keyfile.get_string ("search", "header");
+ real_filter = keyfile.get_string ("search", "filter").down ();
+ string search_account = keyfile.get_string ("search", "account");
+ string toplevel = Environment.get_variable ("MAILDIR");
+ if (toplevel == null || toplevel == "")
+ toplevel = Environment.get_home_dir () + "/Mail";
+ folders += toplevel + "/" + search_account + "/INBOX/cur";
+ folders += toplevel + "/" + search_account + "/INBOX/new";
+ } catch (GLib.KeyFileError keyfile_error) {
+ real_filter = last_filter;
+ folders += location + "/cur";
+ folders += location + "/new";
+ }
+
foreach (var folder in folders) {
- var folder_dir = File.new_for_path (location + "/" + folder);
+ var folder_dir = File.new_for_path (folder);
var folder_enumerator = folder_dir.enumerate_children (
FILE_ATTRIBUTE_STANDARD_NAME + "," +
FILE_ATTRIBUTE_STANDARD_SIZE, 0, null);
@@ -276,6 +296,7 @@ public class Postler.Messages : Gtk.TreeView {
var contents = folder_dir.resolve_relative_path (name);
try {
var stream = new DataInputStream (contents.read (null));
+ bool skip = false;
string line;
while ((line = stream.read_line (null, null)) != null) {
if (line == "")
@@ -284,6 +305,11 @@ public class Postler.Messages : Gtk.TreeView {
if (parts == null || parts[0] == null)
continue;
string field = parts[0].down ();
+ if (real_filter != "" && filter_header == field &&
+ !(real_filter in parts[1].down ())) {
+ skip = true;
+ break;
+ }
if (field == "subject")
subject = parts[1].strip ();
else if (field == "from") {
@@ -293,6 +319,8 @@ public class Postler.Messages : Gtk.TreeView {
else if (field == "date")
date = format_date (parts[1], now, out timestamp);
}
+ if (skip)
+ continue;
} catch (GLib.Error contents_error) {
GLib.critical (_("Failed to read message \"%s\": %s"),
contents.get_path (), contents_error.message);
@@ -301,8 +329,6 @@ public class Postler.Messages : Gtk.TreeView {
string charset = null;
string real_subject = parse_encoded (subject, out charset);
real_subject = GLib.Markup.escape_text (real_subject);
- if (last_filter != "" && !(last_filter in real_subject.down ()))
- continue;
if (rich_rows) {
store.insert_with_values (out account_iter, null, -1,
More information about the Xfce4-commits
mailing list