From 63a968ccaedfab7764592297442d9254502c9370 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 13 Jul 2011 23:00:05 +0300 Subject: [PATCH] * some more guile scripting stuff --- src/mu-msg.c | 5 ++-- toys/muile/mu-stats.scm | 63 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/mu-msg.c b/src/mu-msg.c index 67e7a66e..7d380e49 100644 --- a/src/mu-msg.c +++ b/src/mu-msg.c @@ -583,8 +583,9 @@ mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func, {GMIME_RECIPIENT_TYPE_BCC, MU_MSG_CONTACT_TYPE_BCC}, }; - g_return_if_fail (func && msg); - + g_return_if_fail (msg && msg->_file); + g_return_if_fail (func); + /* first, get the from address(es) */ get_contacts_from (msg, func, user_data); diff --git a/toys/muile/mu-stats.scm b/toys/muile/mu-stats.scm index fd1cf6d5..7f1b158b 100644 --- a/toys/muile/mu-stats.scm +++ b/toys/muile/mu-stats.scm @@ -11,11 +11,11 @@ ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; + ;; You should have received a copy of the GNU General Public License ;; along with this program; if not, write to the Free Software Foundation, ;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -;; -;; + ;; some guile/scheme functions to get various statistics of my mu ;; message store. @@ -28,16 +28,67 @@ provided, only count the messages that match it.\n" (mu:store:foreach (lambda(msg) #f) EXPR)) -(define (mu:stats:average-size EXPR) - "Count the total number of messages. If the optional EXPR is -provided, only count the messages that match it.\n" +(define (mu:stats:average FUNC EXPR) + "Count the average of the result of applying FUNC on all +messages. If the optional EXPR is provided, only consider the messages +that match it.\n" (let* ((sum 0) (n (mu:store:foreach - (lambda(msg) (set! sum (+ sum (mu:msg:size msg)))) EXPR))) + (lambda(msg) (set! sum (+ sum (FUNC msg)))) EXPR))) (if (= n 0) 0 (exact->inexact (/ sum n))))) +(define (mu:stats:average-size EXPR) + "Calculate the average message size. If the optional EXPR is +provided, only consider the messages that match it.\n" + (mu:stats:average (lambda(msg) (mu:msg:size msg)) EXPR)) +(define (mu:stats:average-recipient-number EXPR) + "Calculate the average number of recipients (To: + CC: + Bcc:). If +the optional EXPR is provided, only consider the messages that match +it.\n" + (mu:stats:average (lambda(msg) + (+(length (mu:msg:to msg)) + (length (mu:msg:cc msg)) + (length (mu:msg:bcc msg)))) EXPR)) +(define (mu:stats:frequency FUNC EXPR) + "FUNC is a function that takes a Msg and returns some number between +0 and