[Xfce4-commits] <postler:master> Guess sender names based on other messages sent
Christian Dywan
noreply at xfce.org
Sat Jun 4 14:30:10 CEST 2011
Updating branch refs/heads/master
to ef85546fc0daf33d7acc6acbdcedb0367ebdf2c4 (commit)
from 18fed6282bf95a83a03c2d331b58074e23aa99ee (commit)
commit ef85546fc0daf33d7acc6acbdcedb0367ebdf2c4
Author: Christian Dywan <christian at twotoasts.de>
Date: Fri Jun 3 23:25:48 2011 +0200
Guess sender names based on other messages sent
postler/postler-index.vala | 24 ++++++++++++++++++++++++
postler/postler-message.vala | 2 +-
2 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/postler/postler-index.vala b/postler/postler-index.vala
index 1c5d62c..5f04dc6 100644
--- a/postler/postler-index.vala
+++ b/postler/postler-index.vala
@@ -18,6 +18,7 @@ namespace Postler {
static Sqlite.Statement? statement_count = null;
static Sqlite.Statement? statement_remove = null;
static Sqlite.Statement? statement_unread = null;
+ static Sqlite.Statement? statement_guess = null;
static int64 startup_timestamp = new DateTime.now_utc ().to_unix ();
bool row_or_done (int result) {
@@ -182,6 +183,7 @@ namespace Postler {
throw new GLib.FileError.FAILED (_("Failed to get message: %s"), database.errmsg ());
}
var message = new Message.from_statement (id, statement_get);
+ message.sender = guess_name (message.sender);
statement_get.reset ();
return message;
}
@@ -210,6 +212,28 @@ namespace Postler {
statement_list.reset ();
return ids;
}
+
+ public string guess_name (string address) throws GLib.Error {
+ if (statement_guess == null) {
+ if (database.prepare_v2 ("""
+ SELECT sender FROM messages WHERE sender LIKE ?1
+ GROUP BY sender ORDER BY COUNT (sender) DESC LIMIT 1
+ """,
+ -1, out statement_guess) != Sqlite.OK)
+ throw new GLib.FileError.FAILED (_("Failed to list messages: %s"), database.errmsg ());
+ }
+ bool success =
+ statement_guess.bind_text (1, "%" + address + ">", -1) == Sqlite.OK;
+ int result = statement_guess.step ();
+ success = success && row_or_done (result);
+ if (!success) {
+ statement_guess.reset ();
+ throw new GLib.FileError.FAILED (_("Failed to guess name: %s"), database.errmsg ());
+ }
+ string find = result == Sqlite.ROW ? statement_guess.column_text (0) : address;
+ statement_guess.reset ();
+ return find;
+ }
}
}
diff --git a/postler/postler-message.vala b/postler/postler-message.vala
index 925ef99..2d1c593 100644
--- a/postler/postler-message.vala
+++ b/postler/postler-message.vala
@@ -29,7 +29,7 @@ namespace Postler {
public GLib.DateTime? date { public get; set; }
public int64 get_timestamp () { return date != null ? date.to_unix () : 0; }
public string? subject { public get; set; }
- public string? sender { public get; set; }
+ public string? sender { public get; internal set; }
public string? recipients { public get; set; }
public string? reply_to { public get; set; }
public bool unread { public get; set; }
More information about the Xfce4-commits
mailing list